From patchwork Fri Jan 26 02:26:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cong Wang X-Patchwork-Id: 866122 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="kcjIbwaq"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zSN7x449Zz9sNc for ; Fri, 26 Jan 2018 13:26:37 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751559AbeAZC0e (ORCPT ); Thu, 25 Jan 2018 21:26:34 -0500 Received: from mail-pg0-f68.google.com ([74.125.83.68]:34168 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751542AbeAZC0c (ORCPT ); Thu, 25 Jan 2018 21:26:32 -0500 Received: by mail-pg0-f68.google.com with SMTP id r19so6330508pgn.1 for ; Thu, 25 Jan 2018 18:26:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=x6Q6HsD5aDiKaPsEhdvBmRe2Txi4eonh2MLfUyEHgpQ=; b=kcjIbwaqDJPbKcKhbX/cRNVGMCDCV3X6xzIiLrEuRZLK6gdIY0s7bWmN15uwkTjFDo Q71Av+197ohB0VFeYXn1Fkjp0MWRIPtf67bqtemieTDyaRbsuclH/fPEPsR+wP+rioyi CGjpFa5p8NIeVOidUPNTjaKMQwTtCLwGufZ1HLTAeMRy5qRBeF++x7n4MZsZS7brE3w0 m98wMqEbxkiBXfpi/XKgg6AJw3LuhQpshAjDRxR5s1UV040OGhVOOurCh0FjPbebd5mx NTp+E8tm8vGAI9mn18bqiLT8eC5saP8pqJRLIKn4OFaaWcl2YQMhxGbTVsz1O2vJ5qn3 YaZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=x6Q6HsD5aDiKaPsEhdvBmRe2Txi4eonh2MLfUyEHgpQ=; b=M7pFx2KsEchEKAtPrKM+31jPnX2mjAWyEvFKK6xgM9Ap2pAh7Wm5ZtfA46PKyf9eWt QGOCPufaDTu/CRyVu+DHLAVzZptMZFV5XUyrNAIBidga0o9Zo2JH+WXRiyn3wkoGqANK oUuWIve8s2UTnrOvI3SqPTHizLMoxXd/HL/wPCk29Q9t4HNNSTWLOIPBpEOwGe/TiNKQ ykzGqa5mSH0JIurbViJD0Ck7q/CfwzsEViKKilq19EDyP/ILDNoOQIHCmYmFtirsJQwd h9wpLzVn+ZZ1C/ZQnsy0UK9OC5+/VHMQD/nGvzyHryCkvvEYq17oJCDeb2X5cdN4f1Mk Zs3g== X-Gm-Message-State: AKwxytdBEKEGtEF1N25T+4+eZpM0PI8yzSFQXYd65wgd+Ymr3XxvuoGC Y2CCUsj79MEMlGmZKsT3NZYUPE4+ X-Google-Smtp-Source: AH8x225BRPj3lZaSmhlzUalhQnGPisltVzPXyJCj38nxfgO5QATQSmryCHoBNBmPPUP5aoD5v2qusw== X-Received: by 2002:a17:902:6a89:: with SMTP id n9-v6mr12876486plk.212.1516933591623; Thu, 25 Jan 2018 18:26:31 -0800 (PST) Received: from tw-172-25-30-113.office.twttr.net ([8.25.197.25]) by smtp.gmail.com with ESMTPSA id u86sm16430234pfa.102.2018.01.25.18.26.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 25 Jan 2018 18:26:30 -0800 (PST) From: Cong Wang To: netdev@vger.kernel.org Cc: john.fastabend@gmail.com, Cong Wang Subject: [Patch net-next v3 1/3] net: introduce helper dev_change_tx_queue_len() Date: Thu, 25 Jan 2018 18:26:22 -0800 Message-Id: <20180126022624.20442-2-xiyou.wangcong@gmail.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20180126022624.20442-1-xiyou.wangcong@gmail.com> References: <20180126022624.20442-1-xiyou.wangcong@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This patch promotes the local change_tx_queue_len() to a core helper function, dev_change_tx_queue_len(), so that rtnetlink and net-sysfs could share the code. This also prepares for the following patch. Note, the -EFAULT in the original code doesn't make sense, we should propagate the errno from notifiers. Cc: John Fastabend Signed-off-by: Cong Wang --- include/linux/netdevice.h | 1 + net/core/dev.c | 28 ++++++++++++++++++++++++++++ net/core/net-sysfs.c | 25 +------------------------ net/core/rtnetlink.c | 18 +++++------------- 4 files changed, 35 insertions(+), 37 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 24a62d590350..0804e1d38c78 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -3330,6 +3330,7 @@ int dev_get_alias(const struct net_device *, char *, size_t); int dev_change_net_namespace(struct net_device *, struct net *, const char *); int __dev_set_mtu(struct net_device *, int); int dev_set_mtu(struct net_device *, int); +int dev_change_tx_queue_len(struct net_device *, unsigned long); void dev_set_group(struct net_device *, int); int dev_set_mac_address(struct net_device *, struct sockaddr *); int dev_change_carrier(struct net_device *, bool new_carrier); diff --git a/net/core/dev.c b/net/core/dev.c index 4670ccabe23a..e0b0c2784070 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -7048,6 +7048,34 @@ int dev_set_mtu(struct net_device *dev, int new_mtu) EXPORT_SYMBOL(dev_set_mtu); /** + * dev_change_tx_queue_len - Change TX queue length of a netdevice + * @dev: device + * @new_len: new tx queue length + */ +int dev_change_tx_queue_len(struct net_device *dev, unsigned long new_len) +{ + unsigned int orig_len = dev->tx_queue_len; + int res; + + if (new_len != (unsigned int)new_len) + return -ERANGE; + + if (new_len != orig_len) { + dev->tx_queue_len = new_len; + res = call_netdevice_notifiers(NETDEV_CHANGE_TX_QUEUE_LEN, dev); + res = notifier_to_errno(res); + if (res) { + netdev_err(dev, + "refused to change device tx_queue_len\n"); + dev->tx_queue_len = orig_len; + return res; + } + } + + return 0; +} + +/** * dev_set_group - Change group this device belongs to * @dev: device * @new_group: group this device should belong to diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index c4a28f4667b6..60a5ad2c33ee 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -346,29 +346,6 @@ static ssize_t flags_store(struct device *dev, struct device_attribute *attr, } NETDEVICE_SHOW_RW(flags, fmt_hex); -static int change_tx_queue_len(struct net_device *dev, unsigned long new_len) -{ - unsigned int orig_len = dev->tx_queue_len; - int res; - - if (new_len != (unsigned int)new_len) - return -ERANGE; - - if (new_len != orig_len) { - dev->tx_queue_len = new_len; - res = call_netdevice_notifiers(NETDEV_CHANGE_TX_QUEUE_LEN, dev); - res = notifier_to_errno(res); - if (res) { - netdev_err(dev, - "refused to change device tx_queue_len\n"); - dev->tx_queue_len = orig_len; - return -EFAULT; - } - } - - return 0; -} - static ssize_t tx_queue_len_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t len) @@ -376,7 +353,7 @@ static ssize_t tx_queue_len_store(struct device *dev, if (!capable(CAP_NET_ADMIN)) return -EPERM; - return netdev_store(dev, attr, buf, len, change_tx_queue_len); + return netdev_store(dev, attr, buf, len, dev_change_tx_queue_len); } NETDEVICE_SHOW_RW(tx_queue_len, fmt_dec); diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 97874daa1336..6fa6b9c60694 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -2291,19 +2291,11 @@ static int do_setlink(const struct sk_buff *skb, if (tb[IFLA_TXQLEN]) { unsigned int value = nla_get_u32(tb[IFLA_TXQLEN]); - unsigned int orig_len = dev->tx_queue_len; - - if (dev->tx_queue_len ^ value) { - dev->tx_queue_len = value; - err = call_netdevice_notifiers( - NETDEV_CHANGE_TX_QUEUE_LEN, dev); - err = notifier_to_errno(err); - if (err) { - dev->tx_queue_len = orig_len; - goto errout; - } - status |= DO_SETLINK_MODIFIED; - } + + err = dev_change_tx_queue_len(dev, value); + if (err) + goto errout; + status |= DO_SETLINK_MODIFIED; } if (tb[IFLA_GSO_MAX_SIZE]) {