From patchwork Thu May 7 09:02:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Dichtel X-Patchwork-Id: 469355 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id B22FF1402A0 for ; Thu, 7 May 2015 19:04:15 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751743AbbEGJEL (ORCPT ); Thu, 7 May 2015 05:04:11 -0400 Received: from 33.106-14-84.ripe.coltfrance.com ([84.14.106.33]:43493 "EHLO proxy.6wind.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751348AbbEGJDE (ORCPT ); Thu, 7 May 2015 05:03:04 -0400 Received: from schnaps.dev.6wind.com (unknown [10.16.0.249]) by proxy.6wind.com (Postfix) with ESMTPS id 53003282B5; Thu, 7 May 2015 11:03:02 +0200 (CEST) Received: from root by schnaps.dev.6wind.com with local (Exim 4.80) (envelope-from ) id 1YqHht-0001EV-9w; Thu, 07 May 2015 11:03:01 +0200 From: Nicolas Dichtel To: netdev@vger.kernel.org Cc: tgraf@suug.ch, davem@davemloft.net, ebiederm@xmission.com, Nicolas Dichtel Subject: [PATCH net-next v2 2/7] netns: always provide the id to rtnl_net_fill() Date: Thu, 7 May 2015 11:02:48 +0200 Message-Id: <1430989373-4515-3-git-send-email-nicolas.dichtel@6wind.com> X-Mailer: git-send-email 2.2.2 In-Reply-To: <1430989373-4515-1-git-send-email-nicolas.dichtel@6wind.com> References: <1430906288-5108-1-git-send-email-nicolas.dichtel@6wind.com> <1430989373-4515-1-git-send-email-nicolas.dichtel@6wind.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The goal of this commit is to prepare the rework of the locking of nsnid protection. After this patch, rtnl_net_notifyid() will not call anymore __peernet2id(), ie no idr_* operation into this function. Signed-off-by: Nicolas Dichtel Acked-by: Thomas Graf --- v2: no change net/core/net_namespace.c | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c index 294d38742e2a..37c68bb72db3 100644 --- a/net/core/net_namespace.c +++ b/net/core/net_namespace.c @@ -147,8 +147,7 @@ static void ops_free_list(const struct pernet_operations *ops, } } -static void rtnl_net_notifyid(struct net *net, struct net *peer, int cmd, - int id); +static void rtnl_net_notifyid(struct net *net, int cmd, int id); static int alloc_netid(struct net *net, struct net *peer, int reqid) { int min = 0, max = 0, id; @@ -162,7 +161,7 @@ static int alloc_netid(struct net *net, struct net *peer, int reqid) id = idr_alloc(&net->netns_ids, peer, min, max, GFP_KERNEL); if (id >= 0) - rtnl_net_notifyid(net, peer, RTM_NEWNSID, id); + rtnl_net_notifyid(net, RTM_NEWNSID, id); return id; } @@ -365,7 +364,7 @@ static void cleanup_net(struct work_struct *work) int id = __peernet2id(tmp, net, false); if (id >= 0) { - rtnl_net_notifyid(tmp, net, RTM_DELNSID, id); + rtnl_net_notifyid(tmp, RTM_DELNSID, id); idr_remove(&tmp->netns_ids, id); } } @@ -538,14 +537,10 @@ static int rtnl_net_get_size(void) } static int rtnl_net_fill(struct sk_buff *skb, u32 portid, u32 seq, int flags, - int cmd, struct net *net, struct net *peer, - int nsid) + int cmd, struct net *net, int nsid) { struct nlmsghdr *nlh; struct rtgenmsg *rth; - int id; - - ASSERT_RTNL(); nlh = nlmsg_put(skb, portid, seq, cmd, sizeof(*rth), flags); if (!nlh) @@ -554,11 +549,7 @@ static int rtnl_net_fill(struct sk_buff *skb, u32 portid, u32 seq, int flags, rth = nlmsg_data(nlh); rth->rtgen_family = AF_UNSPEC; - if (nsid >= 0) - id = nsid; - else - id = __peernet2id(net, peer, false); - if (nla_put_s32(skb, NETNSA_NSID, id)) + if (nla_put_s32(skb, NETNSA_NSID, nsid)) goto nla_put_failure; nlmsg_end(skb, nlh); @@ -575,7 +566,7 @@ static int rtnl_net_getid(struct sk_buff *skb, struct nlmsghdr *nlh) struct nlattr *tb[NETNSA_MAX + 1]; struct sk_buff *msg; struct net *peer; - int err; + int err, id; err = nlmsg_parse(nlh, sizeof(struct rtgenmsg), tb, NETNSA_MAX, rtnl_net_policy); @@ -597,8 +588,9 @@ static int rtnl_net_getid(struct sk_buff *skb, struct nlmsghdr *nlh) goto out; } + id = __peernet2id(net, peer, false); err = rtnl_net_fill(msg, NETLINK_CB(skb).portid, nlh->nlmsg_seq, 0, - RTM_GETNSID, net, peer, -1); + RTM_GETNSID, net, id); if (err < 0) goto err_out; @@ -630,7 +622,7 @@ static int rtnl_net_dumpid_one(int id, void *peer, void *data) ret = rtnl_net_fill(net_cb->skb, NETLINK_CB(net_cb->cb->skb).portid, net_cb->cb->nlh->nlmsg_seq, NLM_F_MULTI, - RTM_NEWNSID, net_cb->net, peer, id); + RTM_NEWNSID, net_cb->net, id); if (ret < 0) return ret; @@ -658,8 +650,7 @@ static int rtnl_net_dumpid(struct sk_buff *skb, struct netlink_callback *cb) return skb->len; } -static void rtnl_net_notifyid(struct net *net, struct net *peer, int cmd, - int id) +static void rtnl_net_notifyid(struct net *net, int cmd, int id) { struct sk_buff *msg; int err = -ENOMEM; @@ -668,7 +659,7 @@ static void rtnl_net_notifyid(struct net *net, struct net *peer, int cmd, if (!msg) goto out; - err = rtnl_net_fill(msg, 0, 0, 0, cmd, net, peer, id); + err = rtnl_net_fill(msg, 0, 0, 0, cmd, net, id); if (err < 0) goto err_out;