From patchwork Mon Jul 18 06:56:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: kan.liang@intel.com X-Patchwork-Id: 649704 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rtWPr6VGyz9s5J for ; Tue, 19 Jul 2016 04:08:32 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 571C130E84; Mon, 18 Jul 2016 18:08:31 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id g++ZCWo7wLRB; Mon, 18 Jul 2016 18:08:27 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by silver.osuosl.org (Postfix) with ESMTP id 122F930ED4; Mon, 18 Jul 2016 18:07:59 +0000 (UTC) X-Original-To: intel-wired-lan@lists.osuosl.org Delivered-To: intel-wired-lan@lists.osuosl.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by ash.osuosl.org (Postfix) with ESMTP id 08B5F1C22B9 for ; Mon, 18 Jul 2016 14:23:30 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 028938AB91 for ; Mon, 18 Jul 2016 14:23:30 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id JcJLmyOQSYT2 for ; Mon, 18 Jul 2016 14:23:26 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by whitealder.osuosl.org (Postfix) with ESMTP id 1D72B8AE81 for ; Mon, 18 Jul 2016 14:23:26 +0000 (UTC) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP; 18 Jul 2016 07:23:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.28,384,1464678000"; d="scan'208"; a="1009027587" Received: from otc-grantly-02.jf.intel.com ([10.54.39.33]) by fmsmga001.fm.intel.com with ESMTP; 18 Jul 2016 07:23:26 -0700 From: kan.liang@intel.com To: davem@davemloft.net, linux-kernel@vger.kernel.org, intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org Date: Sun, 17 Jul 2016 23:56:10 -0700 Message-Id: <1468824984-65318-17-git-send-email-kan.liang@intel.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1468824984-65318-1-git-send-email-kan.liang@intel.com> References: <1468824984-65318-1-git-send-email-kan.liang@intel.com> X-Mailman-Approved-At: Mon, 18 Jul 2016 18:07:53 +0000 Cc: decot@googlers.com, aduyck@mirantis.com, andi@firstfloor.org, keescook@chromium.org, peterz@infradead.org, Kan Liang , jmorris@namei.org, yoshfuji@linux-ipv6.org, mingo@redhat.com, john.stultz@linaro.org, gorcunov@openvz.org, kuznet@ms2.inr.ac.ru, akpm@linux-foundation.org, ben@decadent.org.uk, kaber@trash.net, viro@zeniv.linux.org.uk Subject: [Intel-wired-lan] [RFC PATCH 16/30] net/netpolicy: net device hotplug X-BeenThere: intel-wired-lan@lists.osuosl.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Intel Wired Ethernet Linux Kernel Driver Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-wired-lan-bounces@lists.osuosl.org Sender: "Intel-wired-lan" From: Kan Liang Support net device up/down/namechange in the netpolicy code. Signed-off-by: Kan Liang --- net/core/netpolicy.c | 66 +++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 58 insertions(+), 8 deletions(-) diff --git a/net/core/netpolicy.c b/net/core/netpolicy.c index 8336106..2a04fcf 100644 --- a/net/core/netpolicy.c +++ b/net/core/netpolicy.c @@ -684,6 +684,9 @@ static const struct file_operations proc_net_policy_operations = { static int netpolicy_proc_dev_init(struct net *net, struct net_device *dev) { + if (dev->proc_dev) + proc_remove(dev->proc_dev); + dev->proc_dev = proc_net_mkdir(net, dev->name, net->proc_netpolicy); if (!dev->proc_dev) return -ENOMEM; @@ -750,6 +753,19 @@ void uninit_netpolicy(struct net_device *dev) spin_unlock(&dev->np_lock); } +static void netpolicy_dev_init(struct net *net, + struct net_device *dev) +{ + if (!init_netpolicy(dev)) { +#ifdef CONFIG_PROC_FS + if (netpolicy_proc_dev_init(net, dev)) + uninit_netpolicy(dev); + else +#endif /* CONFIG_PROC_FS */ + pr_info("NETPOLICY: Init net policy for %s\n", dev->name); + } +} + static int __net_init netpolicy_net_init(struct net *net) { struct net_device *dev, *aux; @@ -762,14 +778,7 @@ static int __net_init netpolicy_net_init(struct net *net) #endif /* CONFIG_PROC_FS */ for_each_netdev_safe(net, dev, aux) { - if (!init_netpolicy(dev)) { -#ifdef CONFIG_PROC_FS - if (netpolicy_proc_dev_init(net, dev)) - uninit_netpolicy(dev); - else -#endif /* CONFIG_PROC_FS */ - pr_info("NETPOLICY: Init net policy for %s\n", dev->name); - } + netpolicy_dev_init(net, dev); } return 0; @@ -791,17 +800,58 @@ static struct pernet_operations netpolicy_net_ops = { .exit = netpolicy_net_exit, }; +static int netpolicy_notify(struct notifier_block *this, + unsigned long event, + void *ptr) +{ + struct net_device *dev = netdev_notifier_info_to_dev(ptr); + + switch (event) { + case NETDEV_CHANGENAME: +#ifdef CONFIG_PROC_FS + if (dev->proc_dev) { + proc_remove(dev->proc_dev); + if ((netpolicy_proc_dev_init(dev_net(dev), dev) < 0) && + dev->proc_dev) { + proc_remove(dev->proc_dev); + dev->proc_dev = NULL; + } + } +#endif + break; + case NETDEV_UP: + netpolicy_dev_init(dev_net(dev), dev); + break; + case NETDEV_GOING_DOWN: + uninit_netpolicy(dev); +#ifdef CONFIG_PROC_FS + proc_remove(dev->proc_dev); + dev->proc_dev = NULL; +#endif + break; + } + + return NOTIFY_OK; +} + +static struct notifier_block netpolicy_dev_notf = { + .notifier_call = netpolicy_notify, +}; + static int __init netpolicy_init(void) { int ret; ret = register_pernet_subsys(&netpolicy_net_ops); + if (!ret) + register_netdevice_notifier(&netpolicy_dev_notf); return ret; } static void __exit netpolicy_exit(void) { + unregister_netdevice_notifier(&netpolicy_dev_notf); unregister_pernet_subsys(&netpolicy_net_ops); }