From mboxrd@z Thu Jan 1 00:00:00 1970 From: Roopa Prabhu Subject: [PATCH net-next] net-sysfs: trigger netlink notification on ifalias change via sysfs Date: Mon, 13 Nov 2017 23:21:36 -0800 Message-ID: <1510644096-36796-1-git-send-email-roopa@cumulusnetworks.com> Cc: netdev@vger.kernel.org, dsa@cumulusnetworks.com, nikolay@cumulusnetworks.com To: davem@davemloft.net Return-path: Received: from mail-pf0-f195.google.com ([209.85.192.195]:50163 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752644AbdKNHWI (ORCPT ); Tue, 14 Nov 2017 02:22:08 -0500 Received: by mail-pf0-f195.google.com with SMTP id l24so1353744pfj.6 for ; Mon, 13 Nov 2017 23:22:08 -0800 (PST) Sender: netdev-owner@vger.kernel.org List-ID: From: Roopa Prabhu This patch adds netlink notifications on iflias changes via sysfs. makes it consistent with the netlink path which also calls netdev_state_change. Also makes it consistent with other sysfs netdev_store operations. Signed-off-by: Roopa Prabhu --- net/core/net-sysfs.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index 51d5836..799b752 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -382,7 +382,7 @@ static ssize_t ifalias_store(struct device *dev, struct device_attribute *attr, struct net_device *netdev = to_net_dev(dev); struct net *net = dev_net(netdev); size_t count = len; - ssize_t ret; + ssize_t ret = 0; if (!ns_capable(net->user_ns, CAP_NET_ADMIN)) return -EPERM; @@ -391,9 +391,20 @@ static ssize_t ifalias_store(struct device *dev, struct device_attribute *attr, if (len > 0 && buf[len - 1] == '\n') --count; - ret = dev_set_alias(netdev, buf, count); + if (!rtnl_trylock()) + return restart_syscall(); + + if (dev_isalive(netdev)) { + ret = dev_set_alias(netdev, buf, count); + if (ret < 0) + goto err; + ret = len; + netdev_state_change(netdev); + } +err: + rtnl_unlock(); - return ret < 0 ? ret : len; + return ret; } static ssize_t ifalias_show(struct device *dev, -- 2.1.4