Skip to content

Commit 6a643dd

Browse files
congwangdavem330
authored andcommitted
net: introduce helper dev_change_tx_queue_len()
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 <[email protected]> Signed-off-by: Cong Wang <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 4cd8795 commit 6a643dd

File tree

4 files changed

+35
-37
lines changed

4 files changed

+35
-37
lines changed

include/linux/netdevice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3331,6 +3331,7 @@ int dev_get_alias(const struct net_device *, char *, size_t);
33313331
int dev_change_net_namespace(struct net_device *, struct net *, const char *);
33323332
int __dev_set_mtu(struct net_device *, int);
33333333
int dev_set_mtu(struct net_device *, int);
3334+
int dev_change_tx_queue_len(struct net_device *, unsigned long);
33343335
void dev_set_group(struct net_device *, int);
33353336
int dev_set_mac_address(struct net_device *, struct sockaddr *);
33363337
int dev_change_carrier(struct net_device *, bool new_carrier);

net/core/dev.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7047,6 +7047,34 @@ int dev_set_mtu(struct net_device *dev, int new_mtu)
70477047
}
70487048
EXPORT_SYMBOL(dev_set_mtu);
70497049

7050+
/**
7051+
* dev_change_tx_queue_len - Change TX queue length of a netdevice
7052+
* @dev: device
7053+
* @new_len: new tx queue length
7054+
*/
7055+
int dev_change_tx_queue_len(struct net_device *dev, unsigned long new_len)
7056+
{
7057+
unsigned int orig_len = dev->tx_queue_len;
7058+
int res;
7059+
7060+
if (new_len != (unsigned int)new_len)
7061+
return -ERANGE;
7062+
7063+
if (new_len != orig_len) {
7064+
dev->tx_queue_len = new_len;
7065+
res = call_netdevice_notifiers(NETDEV_CHANGE_TX_QUEUE_LEN, dev);
7066+
res = notifier_to_errno(res);
7067+
if (res) {
7068+
netdev_err(dev,
7069+
"refused to change device tx_queue_len\n");
7070+
dev->tx_queue_len = orig_len;
7071+
return res;
7072+
}
7073+
}
7074+
7075+
return 0;
7076+
}
7077+
70507078
/**
70517079
* dev_set_group - Change group this device belongs to
70527080
* @dev: device

net/core/net-sysfs.c

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -346,37 +346,14 @@ static ssize_t flags_store(struct device *dev, struct device_attribute *attr,
346346
}
347347
NETDEVICE_SHOW_RW(flags, fmt_hex);
348348

349-
static int change_tx_queue_len(struct net_device *dev, unsigned long new_len)
350-
{
351-
unsigned int orig_len = dev->tx_queue_len;
352-
int res;
353-
354-
if (new_len != (unsigned int)new_len)
355-
return -ERANGE;
356-
357-
if (new_len != orig_len) {
358-
dev->tx_queue_len = new_len;
359-
res = call_netdevice_notifiers(NETDEV_CHANGE_TX_QUEUE_LEN, dev);
360-
res = notifier_to_errno(res);
361-
if (res) {
362-
netdev_err(dev,
363-
"refused to change device tx_queue_len\n");
364-
dev->tx_queue_len = orig_len;
365-
return -EFAULT;
366-
}
367-
}
368-
369-
return 0;
370-
}
371-
372349
static ssize_t tx_queue_len_store(struct device *dev,
373350
struct device_attribute *attr,
374351
const char *buf, size_t len)
375352
{
376353
if (!capable(CAP_NET_ADMIN))
377354
return -EPERM;
378355

379-
return netdev_store(dev, attr, buf, len, change_tx_queue_len);
356+
return netdev_store(dev, attr, buf, len, dev_change_tx_queue_len);
380357
}
381358
NETDEVICE_SHOW_RW(tx_queue_len, fmt_dec);
382359

net/core/rtnetlink.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2337,19 +2337,11 @@ static int do_setlink(const struct sk_buff *skb,
23372337

23382338
if (tb[IFLA_TXQLEN]) {
23392339
unsigned int value = nla_get_u32(tb[IFLA_TXQLEN]);
2340-
unsigned int orig_len = dev->tx_queue_len;
2341-
2342-
if (dev->tx_queue_len ^ value) {
2343-
dev->tx_queue_len = value;
2344-
err = call_netdevice_notifiers(
2345-
NETDEV_CHANGE_TX_QUEUE_LEN, dev);
2346-
err = notifier_to_errno(err);
2347-
if (err) {
2348-
dev->tx_queue_len = orig_len;
2349-
goto errout;
2350-
}
2351-
status |= DO_SETLINK_MODIFIED;
2352-
}
2340+
2341+
err = dev_change_tx_queue_len(dev, value);
2342+
if (err)
2343+
goto errout;
2344+
status |= DO_SETLINK_MODIFIED;
23532345
}
23542346

23552347
if (tb[IFLA_GSO_MAX_SIZE]) {

0 commit comments

Comments
 (0)