Re: [PATCH net-next 5/6] netns: use a spin_lock to protect nsid management
From: Nicolas Dichtel <hidden>
Date: 2015-05-06 13:40:33
From: Nicolas Dichtel <hidden>
Date: 2015-05-06 13:40:33
Le 06/05/2015 14:23, Thomas Graf a écrit :
On 05/06/15 at 11:58am, Nicolas Dichtel wrote:quoted
+/* Should be called with nsid_lock held. If a new id is assigned, the bool alloc + * is set to true, thus the caller knows that the new id must be notified via + * rtnl. + */ static int __peernet2id(struct net *net, struct net *peer, bool *alloc) { int id = idr_for_each(&net->netns_ids, net_eq_idr, peer); bool alloc_it = *alloc; - ASSERT_RTNL(); - *alloc = false; /* Magic value for id 0. */If split into __peernet2id() and __peernet2id_alloc() then this could live with RCU protection I guess so we only take the lock when we actually allocate.
The description of idr_for_each says: "The caller must serialize idr_for_each() vs idr_get_new() and idr_remove()." So, if I understand well, the lock is always needed.