Subject: Re: [RFC PATCH net-next 1/5] netns: allocate netns ids

From: Nicolas Dichtel <[email-masked]>
Date: Wed, 02 Jul 2014 15:57:32 +0200

Le 02/07/2014 15:33, Sergei Shtylyov a écrit :
> Hello.
>
> On 07/02/2014 03:59 PM, Nicolas Dichtel wrote:
>
>> With this patch, netns allocates ids for all netns. Each netns has its own list
>> of ids, it means that the id is valid only in the current netns.
>
>> For homogeneity, an id is also allocated for the netns owner itself.
>
>> Signed-off-by: Nicolas Dichtel <[email-masked]>
> [...]
>
>> diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
>> index 85b62691f4f2..2976864cef13 100644
>> --- a/net/core/net_namespace.c
>> +++ b/net/core/net_namespace.c
>> @@ -144,6 +144,30 @@ static void ops_free_list(const struct pernet_operations
>> *ops,
>>       }
>>   }
>>
>> +static int net_eq_idr(int id, void *net, void *peer)
>> +{
>> +    return net_eq(net, peer) ? id : 0;
>> +}
>> +
>> +int net2id(struct net *net, struct net *peer)
>> +{
>> +    ASSERT_RTNL();
>> +    return idr_for_each(&(net)->netns_ids, net_eq_idr, (peer)) ? : -ENOENT;
>
>     I don't think the inner parens are needed, this is not a macro body...
Right!
In fact, it was a macro at the beginning ;-)

>
>> +}
>> +
>> +struct net *get_net_from_netnsid(struct net *net, int id)
>> +{
>> +    struct net *peer;
>> +
>> +    rcu_read_lock();
>> +    peer = idr_find(&(net)->netns_ids, id);
>
>     Same here.
Same.

Thank you,
Nicolas