[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <87y4n241m6.fsf@x220.int.ebiederm.org>
Date: Thu, 12 Mar 2015 11:33:21 -0500
From: ebiederm@...ssion.com (Eric W. Biederman)
To: Eric Dumazet <eric.dumazet@...il.com>
Cc: David Miller <davem@...emloft.net>, netdev@...r.kernel.org,
salo@...gle.com
Subject: Re: [PATCH net-next 2/2] net: Introduce possible_net_t
Eric Dumazet <eric.dumazet@...il.com> writes:
> On Wed, 2015-03-11 at 23:06 -0500, Eric W. Biederman wrote:
>> Having to say
>> > #ifdef CONFIG_NET_NS
>> > struct net *net;
>> > #endif
>>
>> in structures is a little bit wordy and a little bit error prone.
>>
>> Instead it is possible to say:
>> > typedef struct {
>> > #ifdef CONFIG_NET_NS
>> > struct net *net;
>> > #endif
>> > } possible_net_t;
>>
>> And then in a header say:
>>
>> > possible_net_t net;
>>
>> Which is cleaner and easier to use and easier to test, as the
>> possible_net_t is always there no matter what the compile options.
>>
>> Further this allows read_pnet and write_pnet to be functions in all
>> cases which is better at catching typos.
>>
>> This change adds possible_net_t, updates the definitions of read_pnet
>> and write_pnet, updates optional struct net * variables that
>> write_pnet uses on to have the type possible_net_t, and finally fixes
>> up the b0rked users of read_pnet and write_pnet.
>>
>> Signed-off-by: "Eric W. Biederman" <ebiederm@...ssion.com>
>> ---
>>
>> When I was testing this caught all three locations Eric Dumazet needed
>> to add write_pnet as compile errors with network namespaces enabled.
>
>
> Acked-by: Eric Dumazet <edumazet@...gle.com>
>
> Only concern is the typedef possible_net_t : It seems number of uses
> should be rather small, and we probably could use the "struct
> possible_net" instead, to please Linus ;)
possible_net_t is a machine word size type so it falls into the
exceptions for typedefs in those cases. It won't fool you about
how big it is, or how costly it is to use.
Years ago I remember passing a similar type to functions and watching
how even the function arguments boiled away at compile time, when
network namespaces were disabled.
Eric
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists