Subject: Re: [PATCH v3] net: #ifdef inet_bind_bucket::ib_net

From: Eric Dumazet <[email-masked]>
Date: Fri, 14 Nov 2008 05:54:26 +0100

David Miller a écrit :
> From: Eric Dumazet <[email-masked]>
> Date: Fri, 14 Nov 2008 05:36:15 +0100
> 
>> This is better because :
>>
>> 1) No #ifdef CONFIG_NET_NS
>>
>> 2) The magic about &init_net is not duplicated in ten different include files, but
>>    centralized in the right file : include/net/net_namespace.h
> 
> I %100 agree.

Speaking of those functions, what do you think of this one ?

static inline
void dev_net_set(struct net_device *dev, struct net *net)
{
#ifdef CONFIG_NET_NS
        release_net(dev->nd_net);
        dev->nd_net = hold_net(net);
#endif
}

I believe that its safer to hold a reference on "new" *before*
releasing reference on "old" object.

Also, release_net() and hold_net() can be defined to do
the use_count refcounting regardless of CONFIG_NET_NS
(Its a different NETNS_REFCNT_DEBUG #ifdef)

Yet another example where read_pnet() and write_pnet()
are the right answer : Its cleaner and fixes *bugs*.

static inline
void dev_net_set(struct net_device *dev, struct net *net)
{
	hold_net(net);
	release_net(read_pnet(&dev->nd_net);
        write_pnet(&dev->nd_net, net);
}