forked from mirrors/linux
		
	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 <john.fastabend@gmail.com> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
		
							parent
							
								
									4cd879515d
								
							
						
					
					
						commit
						6a643ddb56
					
				
					 4 changed files with 34 additions and 36 deletions
				
			
		|  | @ -3331,6 +3331,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_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_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); | void dev_set_group(struct net_device *, int); | ||||||
| int dev_set_mac_address(struct net_device *, struct sockaddr *); | int dev_set_mac_address(struct net_device *, struct sockaddr *); | ||||||
| int dev_change_carrier(struct net_device *, bool new_carrier); | int dev_change_carrier(struct net_device *, bool new_carrier); | ||||||
|  |  | ||||||
|  | @ -7047,6 +7047,34 @@ int dev_set_mtu(struct net_device *dev, int new_mtu) | ||||||
| } | } | ||||||
| EXPORT_SYMBOL(dev_set_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_set_group - Change group this device belongs to | ||||||
|  *	@dev: device |  *	@dev: device | ||||||
|  |  | ||||||
|  | @ -346,29 +346,6 @@ static ssize_t flags_store(struct device *dev, struct device_attribute *attr, | ||||||
| } | } | ||||||
| NETDEVICE_SHOW_RW(flags, fmt_hex); | 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, | static ssize_t tx_queue_len_store(struct device *dev, | ||||||
| 				  struct device_attribute *attr, | 				  struct device_attribute *attr, | ||||||
| 				  const char *buf, size_t len) | 				  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)) | 	if (!capable(CAP_NET_ADMIN)) | ||||||
| 		return -EPERM; | 		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); | NETDEVICE_SHOW_RW(tx_queue_len, fmt_dec); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -2337,20 +2337,12 @@ static int do_setlink(const struct sk_buff *skb, | ||||||
| 
 | 
 | ||||||
| 	if (tb[IFLA_TXQLEN]) { | 	if (tb[IFLA_TXQLEN]) { | ||||||
| 		unsigned int value = nla_get_u32(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) { | 		err = dev_change_tx_queue_len(dev, value); | ||||||
| 			dev->tx_queue_len = value; | 		if (err) | ||||||
| 			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; | 			goto errout; | ||||||
| 			} |  | ||||||
| 		status |= DO_SETLINK_MODIFIED; | 		status |= DO_SETLINK_MODIFIED; | ||||||
| 	} | 	} | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	if (tb[IFLA_GSO_MAX_SIZE]) { | 	if (tb[IFLA_GSO_MAX_SIZE]) { | ||||||
| 		u32 max_size = nla_get_u32(tb[IFLA_GSO_MAX_SIZE]); | 		u32 max_size = nla_get_u32(tb[IFLA_GSO_MAX_SIZE]); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Cong Wang
						Cong Wang