Commit ef319d4f authored by David S. Miller's avatar David S. Miller

Merge branch 'net-sysfs-related-cleanups'

Stephen Hemminger says:

====================
net: sysfs related cleanups

Network sysfs infrastructure changes. Mostly related to using ro_after_init
to make function tables immutable.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 01d300c5 6648c65e
...@@ -2376,7 +2376,7 @@ static int init_vqs(struct virtnet_info *vi) ...@@ -2376,7 +2376,7 @@ static int init_vqs(struct virtnet_info *vi)
#ifdef CONFIG_SYSFS #ifdef CONFIG_SYSFS
static ssize_t mergeable_rx_buffer_size_show(struct netdev_rx_queue *queue, static ssize_t mergeable_rx_buffer_size_show(struct netdev_rx_queue *queue,
struct rx_queue_attribute *attribute, char *buf) char *buf)
{ {
struct virtnet_info *vi = netdev_priv(queue->dev); struct virtnet_info *vi = netdev_priv(queue->dev);
unsigned int queue_index = get_netdev_rx_queue_index(queue); unsigned int queue_index = get_netdev_rx_queue_index(queue);
......
...@@ -694,10 +694,9 @@ struct netdev_rx_queue { ...@@ -694,10 +694,9 @@ struct netdev_rx_queue {
*/ */
struct rx_queue_attribute { struct rx_queue_attribute {
struct attribute attr; struct attribute attr;
ssize_t (*show)(struct netdev_rx_queue *queue, ssize_t (*show)(struct netdev_rx_queue *queue, char *buf);
struct rx_queue_attribute *attr, char *buf);
ssize_t (*store)(struct netdev_rx_queue *queue, ssize_t (*store)(struct netdev_rx_queue *queue,
struct rx_queue_attribute *attr, const char *buf, size_t len); const char *buf, size_t len);
}; };
#ifdef CONFIG_XPS #ifdef CONFIG_XPS
...@@ -4013,22 +4012,22 @@ static inline netdev_tx_t netdev_start_xmit(struct sk_buff *skb, struct net_devi ...@@ -4013,22 +4012,22 @@ static inline netdev_tx_t netdev_start_xmit(struct sk_buff *skb, struct net_devi
return rc; return rc;
} }
int netdev_class_create_file_ns(struct class_attribute *class_attr, int netdev_class_create_file_ns(const struct class_attribute *class_attr,
const void *ns); const void *ns);
void netdev_class_remove_file_ns(struct class_attribute *class_attr, void netdev_class_remove_file_ns(const struct class_attribute *class_attr,
const void *ns); const void *ns);
static inline int netdev_class_create_file(struct class_attribute *class_attr) static inline int netdev_class_create_file(const struct class_attribute *class_attr)
{ {
return netdev_class_create_file_ns(class_attr, NULL); return netdev_class_create_file_ns(class_attr, NULL);
} }
static inline void netdev_class_remove_file(struct class_attribute *class_attr) static inline void netdev_class_remove_file(const struct class_attribute *class_attr)
{ {
netdev_class_remove_file_ns(class_attr, NULL); netdev_class_remove_file_ns(class_attr, NULL);
} }
extern struct kobj_ns_type_operations net_ns_type_operations; extern const struct kobj_ns_type_operations net_ns_type_operations;
const char *netdev_drivername(const struct net_device *dev); const char *netdev_drivername(const struct net_device *dev);
......
...@@ -97,7 +97,8 @@ static ssize_t netdev_store(struct device *dev, struct device_attribute *attr, ...@@ -97,7 +97,8 @@ static ssize_t netdev_store(struct device *dev, struct device_attribute *attr,
return restart_syscall(); return restart_syscall();
if (dev_isalive(netdev)) { if (dev_isalive(netdev)) {
if ((ret = (*set)(netdev, new)) == 0) ret = (*set)(netdev, new);
if (ret == 0)
ret = len; ret = len;
} }
rtnl_unlock(); rtnl_unlock();
...@@ -160,6 +161,7 @@ static ssize_t broadcast_show(struct device *dev, ...@@ -160,6 +161,7 @@ static ssize_t broadcast_show(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct net_device *ndev = to_net_dev(dev); struct net_device *ndev = to_net_dev(dev);
if (dev_isalive(ndev)) if (dev_isalive(ndev))
return sysfs_format_mac(buf, ndev->broadcast, ndev->addr_len); return sysfs_format_mac(buf, ndev->broadcast, ndev->addr_len);
return -EINVAL; return -EINVAL;
...@@ -170,7 +172,7 @@ static int change_carrier(struct net_device *dev, unsigned long new_carrier) ...@@ -170,7 +172,7 @@ static int change_carrier(struct net_device *dev, unsigned long new_carrier)
{ {
if (!netif_running(dev)) if (!netif_running(dev))
return -EINVAL; return -EINVAL;
return dev_change_carrier(dev, (bool) new_carrier); return dev_change_carrier(dev, (bool)new_carrier);
} }
static ssize_t carrier_store(struct device *dev, struct device_attribute *attr, static ssize_t carrier_store(struct device *dev, struct device_attribute *attr,
...@@ -183,9 +185,10 @@ static ssize_t carrier_show(struct device *dev, ...@@ -183,9 +185,10 @@ static ssize_t carrier_show(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct net_device *netdev = to_net_dev(dev); struct net_device *netdev = to_net_dev(dev);
if (netif_running(netdev)) {
if (netif_running(netdev))
return sprintf(buf, fmt_dec, !!netif_carrier_ok(netdev)); return sprintf(buf, fmt_dec, !!netif_carrier_ok(netdev));
}
return -EINVAL; return -EINVAL;
} }
static DEVICE_ATTR_RW(carrier); static DEVICE_ATTR_RW(carrier);
...@@ -290,6 +293,7 @@ static ssize_t carrier_changes_show(struct device *dev, ...@@ -290,6 +293,7 @@ static ssize_t carrier_changes_show(struct device *dev,
char *buf) char *buf)
{ {
struct net_device *netdev = to_net_dev(dev); struct net_device *netdev = to_net_dev(dev);
return sprintf(buf, fmt_dec, return sprintf(buf, fmt_dec,
atomic_read(&netdev->carrier_changes)); atomic_read(&netdev->carrier_changes));
} }
...@@ -299,7 +303,7 @@ static DEVICE_ATTR_RO(carrier_changes); ...@@ -299,7 +303,7 @@ static DEVICE_ATTR_RO(carrier_changes);
static int change_mtu(struct net_device *dev, unsigned long new_mtu) static int change_mtu(struct net_device *dev, unsigned long new_mtu)
{ {
return dev_set_mtu(dev, (int) new_mtu); return dev_set_mtu(dev, (int)new_mtu);
} }
static ssize_t mtu_store(struct device *dev, struct device_attribute *attr, static ssize_t mtu_store(struct device *dev, struct device_attribute *attr,
...@@ -311,7 +315,7 @@ NETDEVICE_SHOW_RW(mtu, fmt_dec); ...@@ -311,7 +315,7 @@ NETDEVICE_SHOW_RW(mtu, fmt_dec);
static int change_flags(struct net_device *dev, unsigned long new_flags) static int change_flags(struct net_device *dev, unsigned long new_flags)
{ {
return dev_change_flags(dev, (unsigned int) new_flags); return dev_change_flags(dev, (unsigned int)new_flags);
} }
static ssize_t flags_store(struct device *dev, struct device_attribute *attr, static ssize_t flags_store(struct device *dev, struct device_attribute *attr,
...@@ -362,8 +366,8 @@ static int change_gro_flush_timeout(struct net_device *dev, unsigned long val) ...@@ -362,8 +366,8 @@ static int change_gro_flush_timeout(struct net_device *dev, unsigned long val)
} }
static ssize_t gro_flush_timeout_store(struct device *dev, static ssize_t gro_flush_timeout_store(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr,
const char *buf, size_t len) const char *buf, size_t len)
{ {
if (!capable(CAP_NET_ADMIN)) if (!capable(CAP_NET_ADMIN))
return -EPERM; return -EPERM;
...@@ -412,7 +416,7 @@ static DEVICE_ATTR_RW(ifalias); ...@@ -412,7 +416,7 @@ static DEVICE_ATTR_RW(ifalias);
static int change_group(struct net_device *dev, unsigned long new_group) static int change_group(struct net_device *dev, unsigned long new_group)
{ {
dev_set_group(dev, (int) new_group); dev_set_group(dev, (int)new_group);
return 0; return 0;
} }
...@@ -426,7 +430,7 @@ static DEVICE_ATTR(netdev_group, S_IRUGO | S_IWUSR, group_show, group_store); ...@@ -426,7 +430,7 @@ static DEVICE_ATTR(netdev_group, S_IRUGO | S_IWUSR, group_show, group_store);
static int change_proto_down(struct net_device *dev, unsigned long proto_down) static int change_proto_down(struct net_device *dev, unsigned long proto_down)
{ {
return dev_change_proto_down(dev, (bool) proto_down); return dev_change_proto_down(dev, (bool)proto_down);
} }
static ssize_t proto_down_store(struct device *dev, static ssize_t proto_down_store(struct device *dev,
...@@ -508,7 +512,7 @@ static ssize_t phys_switch_id_show(struct device *dev, ...@@ -508,7 +512,7 @@ static ssize_t phys_switch_id_show(struct device *dev,
} }
static DEVICE_ATTR_RO(phys_switch_id); static DEVICE_ATTR_RO(phys_switch_id);
static struct attribute *net_class_attrs[] = { static struct attribute *net_class_attrs[] __ro_after_init = {
&dev_attr_netdev_group.attr, &dev_attr_netdev_group.attr,
&dev_attr_type.attr, &dev_attr_type.attr,
&dev_attr_dev_id.attr, &dev_attr_dev_id.attr,
...@@ -549,14 +553,14 @@ static ssize_t netstat_show(const struct device *d, ...@@ -549,14 +553,14 @@ static ssize_t netstat_show(const struct device *d,
ssize_t ret = -EINVAL; ssize_t ret = -EINVAL;
WARN_ON(offset > sizeof(struct rtnl_link_stats64) || WARN_ON(offset > sizeof(struct rtnl_link_stats64) ||
offset % sizeof(u64) != 0); offset % sizeof(u64) != 0);
read_lock(&dev_base_lock); read_lock(&dev_base_lock);
if (dev_isalive(dev)) { if (dev_isalive(dev)) {
struct rtnl_link_stats64 temp; struct rtnl_link_stats64 temp;
const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp); const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
ret = sprintf(buf, fmt_u64, *(u64 *)(((u8 *) stats) + offset)); ret = sprintf(buf, fmt_u64, *(u64 *)(((u8 *)stats) + offset));
} }
read_unlock(&dev_base_lock); read_unlock(&dev_base_lock);
return ret; return ret;
...@@ -565,7 +569,7 @@ static ssize_t netstat_show(const struct device *d, ...@@ -565,7 +569,7 @@ static ssize_t netstat_show(const struct device *d,
/* generate a read-only statistics attribute */ /* generate a read-only statistics attribute */
#define NETSTAT_ENTRY(name) \ #define NETSTAT_ENTRY(name) \
static ssize_t name##_show(struct device *d, \ static ssize_t name##_show(struct device *d, \
struct device_attribute *attr, char *buf) \ struct device_attribute *attr, char *buf) \
{ \ { \
return netstat_show(d, attr, buf, \ return netstat_show(d, attr, buf, \
offsetof(struct rtnl_link_stats64, name)); \ offsetof(struct rtnl_link_stats64, name)); \
...@@ -597,7 +601,7 @@ NETSTAT_ENTRY(rx_compressed); ...@@ -597,7 +601,7 @@ NETSTAT_ENTRY(rx_compressed);
NETSTAT_ENTRY(tx_compressed); NETSTAT_ENTRY(tx_compressed);
NETSTAT_ENTRY(rx_nohandler); NETSTAT_ENTRY(rx_nohandler);
static struct attribute *netstat_attrs[] = { static struct attribute *netstat_attrs[] __ro_after_init = {
&dev_attr_rx_packets.attr, &dev_attr_rx_packets.attr,
&dev_attr_tx_packets.attr, &dev_attr_tx_packets.attr,
&dev_attr_rx_bytes.attr, &dev_attr_rx_bytes.attr,
...@@ -625,7 +629,6 @@ static struct attribute *netstat_attrs[] = { ...@@ -625,7 +629,6 @@ static struct attribute *netstat_attrs[] = {
NULL NULL
}; };
static const struct attribute_group netstat_group = { static const struct attribute_group netstat_group = {
.name = "statistics", .name = "statistics",
.attrs = netstat_attrs, .attrs = netstat_attrs,
...@@ -647,33 +650,33 @@ static const struct attribute_group wireless_group = { ...@@ -647,33 +650,33 @@ static const struct attribute_group wireless_group = {
#endif /* CONFIG_SYSFS */ #endif /* CONFIG_SYSFS */
#ifdef CONFIG_SYSFS #ifdef CONFIG_SYSFS
#define to_rx_queue_attr(_attr) container_of(_attr, \ #define to_rx_queue_attr(_attr) \
struct rx_queue_attribute, attr) container_of(_attr, struct rx_queue_attribute, attr)
#define to_rx_queue(obj) container_of(obj, struct netdev_rx_queue, kobj) #define to_rx_queue(obj) container_of(obj, struct netdev_rx_queue, kobj)
static ssize_t rx_queue_attr_show(struct kobject *kobj, struct attribute *attr, static ssize_t rx_queue_attr_show(struct kobject *kobj, struct attribute *attr,
char *buf) char *buf)
{ {
struct rx_queue_attribute *attribute = to_rx_queue_attr(attr); const struct rx_queue_attribute *attribute = to_rx_queue_attr(attr);
struct netdev_rx_queue *queue = to_rx_queue(kobj); struct netdev_rx_queue *queue = to_rx_queue(kobj);
if (!attribute->show) if (!attribute->show)
return -EIO; return -EIO;
return attribute->show(queue, attribute, buf); return attribute->show(queue, buf);
} }
static ssize_t rx_queue_attr_store(struct kobject *kobj, struct attribute *attr, static ssize_t rx_queue_attr_store(struct kobject *kobj, struct attribute *attr,
const char *buf, size_t count) const char *buf, size_t count)
{ {
struct rx_queue_attribute *attribute = to_rx_queue_attr(attr); const struct rx_queue_attribute *attribute = to_rx_queue_attr(attr);
struct netdev_rx_queue *queue = to_rx_queue(kobj); struct netdev_rx_queue *queue = to_rx_queue(kobj);
if (!attribute->store) if (!attribute->store)
return -EIO; return -EIO;
return attribute->store(queue, attribute, buf, count); return attribute->store(queue, buf, count);
} }
static const struct sysfs_ops rx_queue_sysfs_ops = { static const struct sysfs_ops rx_queue_sysfs_ops = {
...@@ -682,8 +685,7 @@ static const struct sysfs_ops rx_queue_sysfs_ops = { ...@@ -682,8 +685,7 @@ static const struct sysfs_ops rx_queue_sysfs_ops = {
}; };
#ifdef CONFIG_RPS #ifdef CONFIG_RPS
static ssize_t show_rps_map(struct netdev_rx_queue *queue, static ssize_t show_rps_map(struct netdev_rx_queue *queue, char *buf)
struct rx_queue_attribute *attribute, char *buf)
{ {
struct rps_map *map; struct rps_map *map;
cpumask_var_t mask; cpumask_var_t mask;
...@@ -706,8 +708,7 @@ static ssize_t show_rps_map(struct netdev_rx_queue *queue, ...@@ -706,8 +708,7 @@ static ssize_t show_rps_map(struct netdev_rx_queue *queue,
} }
static ssize_t store_rps_map(struct netdev_rx_queue *queue, static ssize_t store_rps_map(struct netdev_rx_queue *queue,
struct rx_queue_attribute *attribute, const char *buf, size_t len)
const char *buf, size_t len)
{ {
struct rps_map *old_map, *map; struct rps_map *old_map, *map;
cpumask_var_t mask; cpumask_var_t mask;
...@@ -727,8 +728,8 @@ static ssize_t store_rps_map(struct netdev_rx_queue *queue, ...@@ -727,8 +728,8 @@ static ssize_t store_rps_map(struct netdev_rx_queue *queue,
} }
map = kzalloc(max_t(unsigned int, map = kzalloc(max_t(unsigned int,
RPS_MAP_SIZE(cpumask_weight(mask)), L1_CACHE_BYTES), RPS_MAP_SIZE(cpumask_weight(mask)), L1_CACHE_BYTES),
GFP_KERNEL); GFP_KERNEL);
if (!map) { if (!map) {
free_cpumask_var(mask); free_cpumask_var(mask);
return -ENOMEM; return -ENOMEM;
...@@ -738,9 +739,9 @@ static ssize_t store_rps_map(struct netdev_rx_queue *queue, ...@@ -738,9 +739,9 @@ static ssize_t store_rps_map(struct netdev_rx_queue *queue,
for_each_cpu_and(cpu, mask, cpu_online_mask) for_each_cpu_and(cpu, mask, cpu_online_mask)
map->cpus[i++] = cpu; map->cpus[i++] = cpu;
if (i) if (i) {
map->len = i; map->len = i;
else { } else {
kfree(map); kfree(map);
map = NULL; map = NULL;
} }
...@@ -765,7 +766,6 @@ static ssize_t store_rps_map(struct netdev_rx_queue *queue, ...@@ -765,7 +766,6 @@ static ssize_t store_rps_map(struct netdev_rx_queue *queue,
} }
static ssize_t show_rps_dev_flow_table_cnt(struct netdev_rx_queue *queue, static ssize_t show_rps_dev_flow_table_cnt(struct netdev_rx_queue *queue,
struct rx_queue_attribute *attr,
char *buf) char *buf)
{ {
struct rps_dev_flow_table *flow_table; struct rps_dev_flow_table *flow_table;
...@@ -788,8 +788,7 @@ static void rps_dev_flow_table_release(struct rcu_head *rcu) ...@@ -788,8 +788,7 @@ static void rps_dev_flow_table_release(struct rcu_head *rcu)
} }
static ssize_t store_rps_dev_flow_table_cnt(struct netdev_rx_queue *queue, static ssize_t store_rps_dev_flow_table_cnt(struct netdev_rx_queue *queue,
struct rx_queue_attribute *attr, const char *buf, size_t len)
const char *buf, size_t len)
{ {
unsigned long mask, count; unsigned long mask, count;
struct rps_dev_flow_table *table, *old_table; struct rps_dev_flow_table *table, *old_table;
...@@ -831,8 +830,9 @@ static ssize_t store_rps_dev_flow_table_cnt(struct netdev_rx_queue *queue, ...@@ -831,8 +830,9 @@ static ssize_t store_rps_dev_flow_table_cnt(struct netdev_rx_queue *queue,
table->mask = mask; table->mask = mask;
for (count = 0; count <= mask; count++) for (count = 0; count <= mask; count++)
table->flows[count].cpu = RPS_NO_CPU; table->flows[count].cpu = RPS_NO_CPU;
} else } else {
table = NULL; table = NULL;
}
spin_lock(&rps_dev_flow_lock); spin_lock(&rps_dev_flow_lock);
old_table = rcu_dereference_protected(queue->rps_flow_table, old_table = rcu_dereference_protected(queue->rps_flow_table,
...@@ -846,16 +846,15 @@ static ssize_t store_rps_dev_flow_table_cnt(struct netdev_rx_queue *queue, ...@@ -846,16 +846,15 @@ static ssize_t store_rps_dev_flow_table_cnt(struct netdev_rx_queue *queue,
return len; return len;
} }
static struct rx_queue_attribute rps_cpus_attribute = static struct rx_queue_attribute rps_cpus_attribute __ro_after_init
__ATTR(rps_cpus, S_IRUGO | S_IWUSR, show_rps_map, store_rps_map); = __ATTR(rps_cpus, S_IRUGO | S_IWUSR, show_rps_map, store_rps_map);
static struct rx_queue_attribute rps_dev_flow_table_cnt_attribute = static struct rx_queue_attribute rps_dev_flow_table_cnt_attribute __ro_after_init
__ATTR(rps_flow_cnt, S_IRUGO | S_IWUSR, = __ATTR(rps_flow_cnt, S_IRUGO | S_IWUSR,
show_rps_dev_flow_table_cnt, store_rps_dev_flow_table_cnt); show_rps_dev_flow_table_cnt, store_rps_dev_flow_table_cnt);
#endif /* CONFIG_RPS */ #endif /* CONFIG_RPS */
static struct attribute *rx_queue_default_attrs[] = { static struct attribute *rx_queue_default_attrs[] __ro_after_init = {
#ifdef CONFIG_RPS #ifdef CONFIG_RPS
&rps_cpus_attribute.attr, &rps_cpus_attribute.attr,
&rps_dev_flow_table_cnt_attribute.attr, &rps_dev_flow_table_cnt_attribute.attr,
...@@ -870,7 +869,6 @@ static void rx_queue_release(struct kobject *kobj) ...@@ -870,7 +869,6 @@ static void rx_queue_release(struct kobject *kobj)
struct rps_map *map; struct rps_map *map;
struct rps_dev_flow_table *flow_table; struct rps_dev_flow_table *flow_table;
map = rcu_dereference_protected(queue->rps_map, 1); map = rcu_dereference_protected(queue->rps_map, 1);
if (map) { if (map) {
RCU_INIT_POINTER(queue->rps_map, NULL); RCU_INIT_POINTER(queue->rps_map, NULL);
...@@ -900,7 +898,7 @@ static const void *rx_queue_namespace(struct kobject *kobj) ...@@ -900,7 +898,7 @@ static const void *rx_queue_namespace(struct kobject *kobj)
return ns; return ns;
} }
static struct kobj_type rx_queue_ktype = { static struct kobj_type rx_queue_ktype __ro_after_init = {
.sysfs_ops = &rx_queue_sysfs_ops, .sysfs_ops = &rx_queue_sysfs_ops,
.release = rx_queue_release, .release = rx_queue_release,
.default_attrs = rx_queue_default_attrs, .default_attrs = rx_queue_default_attrs,
...@@ -915,22 +913,21 @@ static int rx_queue_add_kobject(struct net_device *dev, int index) ...@@ -915,22 +913,21 @@ static int rx_queue_add_kobject(struct net_device *dev, int index)
kobj->kset = dev->queues_kset; kobj->kset = dev->queues_kset;
error = kobject_init_and_add(kobj, &rx_queue_ktype, NULL, error = kobject_init_and_add(kobj, &rx_queue_ktype, NULL,
"rx-%u", index); "rx-%u", index);
if (error) if (error)
goto exit; return error;
if (dev->sysfs_rx_queue_group) { if (dev->sysfs_rx_queue_group) {
error = sysfs_create_group(kobj, dev->sysfs_rx_queue_group); error = sysfs_create_group(kobj, dev->sysfs_rx_queue_group);
if (error) if (error) {
goto exit; kobject_put(kobj);
return error;
}
} }
kobject_uevent(kobj, KOBJ_ADD); kobject_uevent(kobj, KOBJ_ADD);
dev_hold(queue->dev); dev_hold(queue->dev);
return error;
exit:
kobject_put(kobj);
return error; return error;
} }
#endif /* CONFIG_SYSFS */ #endif /* CONFIG_SYSFS */
...@@ -976,39 +973,40 @@ net_rx_queue_update_kobjects(struct net_device *dev, int old_num, int new_num) ...@@ -976,39 +973,40 @@ net_rx_queue_update_kobjects(struct net_device *dev, int old_num, int new_num)
*/ */
struct netdev_queue_attribute { struct netdev_queue_attribute {
struct attribute attr; struct attribute attr;
ssize_t (*show)(struct netdev_queue *queue, ssize_t (*show)(struct netdev_queue *queue, char *buf);
struct netdev_queue_attribute *attr, char *buf);
ssize_t (*store)(struct netdev_queue *queue, ssize_t (*store)(struct netdev_queue *queue,
struct netdev_queue_attribute *attr, const char *buf, size_t len); const char *buf, size_t len);
}; };
#define to_netdev_queue_attr(_attr) container_of(_attr, \ #define to_netdev_queue_attr(_attr) \
struct netdev_queue_attribute, attr) container_of(_attr, struct netdev_queue_attribute, attr)
#define to_netdev_queue(obj) container_of(obj, struct netdev_queue, kobj) #define to_netdev_queue(obj) container_of(obj, struct netdev_queue, kobj)
static ssize_t netdev_queue_attr_show(struct kobject *kobj, static ssize_t netdev_queue_attr_show(struct kobject *kobj,
struct attribute *attr, char *buf) struct attribute *attr, char *buf)
{ {
struct netdev_queue_attribute *attribute = to_netdev_queue_attr(attr); const struct netdev_queue_attribute *attribute
= to_netdev_queue_attr(attr);
struct netdev_queue *queue = to_netdev_queue(kobj); struct netdev_queue *queue = to_netdev_queue(kobj);
if (!attribute->show) if (!attribute->show)
return -EIO; return -EIO;
return attribute->show(queue, attribute, buf); return attribute->show(queue, buf);
} }
static ssize_t netdev_queue_attr_store(struct kobject *kobj, static ssize_t netdev_queue_attr_store(struct kobject *kobj,
struct attribute *attr, struct attribute *attr,
const char *buf, size_t count) const char *buf, size_t count)
{ {
struct netdev_queue_attribute *attribute = to_netdev_queue_attr(attr); const struct netdev_queue_attribute *attribute
= to_netdev_queue_attr(attr);
struct netdev_queue *queue = to_netdev_queue(kobj); struct netdev_queue *queue = to_netdev_queue(kobj);
if (!attribute->store) if (!attribute->store)
return -EIO; return -EIO;
return attribute->store(queue, attribute, buf, count); return attribute->store(queue, buf, count);
} }
static const struct sysfs_ops netdev_queue_sysfs_ops = { static const struct sysfs_ops netdev_queue_sysfs_ops = {
...@@ -1016,9 +1014,7 @@ static const struct sysfs_ops netdev_queue_sysfs_ops = { ...@@ -1016,9 +1014,7 @@ static const struct sysfs_ops netdev_queue_sysfs_ops = {
.store = netdev_queue_attr_store, .store = netdev_queue_attr_store,
}; };
static ssize_t show_trans_timeout(struct netdev_queue *queue, static ssize_t tx_timeout_show(struct netdev_queue *queue, char *buf)
struct netdev_queue_attribute *attribute,
char *buf)
{ {
unsigned long trans_timeout; unsigned long trans_timeout;
...@@ -1040,8 +1036,7 @@ static unsigned int get_netdev_queue_index(struct netdev_queue *queue) ...@@ -1040,8 +1036,7 @@ static unsigned int get_netdev_queue_index(struct netdev_queue *queue)
return i; return i;
} }
static ssize_t show_traffic_class(struct netdev_queue *queue, static ssize_t traffic_class_show(struct netdev_queue *queue,
struct netdev_queue_attribute *attribute,
char *buf) char *buf)
{ {
struct net_device *dev = queue->dev; struct net_device *dev = queue->dev;
...@@ -1055,16 +1050,14 @@ static ssize_t show_traffic_class(struct netdev_queue *queue, ...@@ -1055,16 +1050,14 @@ static ssize_t show_traffic_class(struct netdev_queue *queue,
} }
#ifdef CONFIG_XPS #ifdef CONFIG_XPS
static ssize_t show_tx_maxrate(struct netdev_queue *queue, static ssize_t tx_maxrate_show(struct netdev_queue *queue,
struct netdev_queue_attribute *attribute,
char *buf) char *buf)
{ {
return sprintf(buf, "%lu\n", queue->tx_maxrate); return sprintf(buf, "%lu\n", queue->tx_maxrate);
} }
static ssize_t set_tx_maxrate(struct netdev_queue *queue, static ssize_t tx_maxrate_store(struct netdev_queue *queue,
struct netdev_queue_attribute *attribute, const char *buf, size_t len)
const char *buf, size_t len)
{ {
struct net_device *dev = queue->dev; struct net_device *dev = queue->dev;
int err, index = get_netdev_queue_index(queue); int err, index = get_netdev_queue_index(queue);
...@@ -1089,16 +1082,15 @@ static ssize_t set_tx_maxrate(struct netdev_queue *queue, ...@@ -1089,16 +1082,15 @@ static ssize_t set_tx_maxrate(struct netdev_queue *queue,
return err; return err;
} }
static struct netdev_queue_attribute queue_tx_maxrate = static struct netdev_queue_attribute queue_tx_maxrate __ro_after_init
__ATTR(tx_maxrate, S_IRUGO | S_IWUSR, = __ATTR_RW(tx_maxrate);
show_tx_maxrate, set_tx_maxrate);
#endif #endif
static struct netdev_queue_attribute queue_trans_timeout = static struct netdev_queue_attribute queue_trans_timeout __ro_after_init
__ATTR(tx_timeout, S_IRUGO, show_trans_timeout, NULL); = __ATTR_RO(tx_timeout);
static struct netdev_queue_attribute queue_traffic_class = static struct netdev_queue_attribute queue_traffic_class __ro_after_init
__ATTR(traffic_class, S_IRUGO, show_traffic_class, NULL); = __ATTR_RO(traffic_class);
#ifdef CONFIG_BQL #ifdef CONFIG_BQL
/* /*
...@@ -1115,9 +1107,9 @@ static ssize_t bql_set(const char *buf, const size_t count, ...@@ -1115,9 +1107,9 @@ static ssize_t bql_set(const char *buf, const size_t count,
unsigned int value; unsigned int value;
int err; int err;
if (!strcmp(buf, "max") || !strcmp(buf, "max\n")) if (!strcmp(buf, "max") || !strcmp(buf, "max\n")) {
value = DQL_MAX_LIMIT; value = DQL_MAX_LIMIT;
else { } else {
err = kstrtouint(buf, 10, &value); err = kstrtouint(buf, 10, &value);
if (err < 0) if (err < 0)
return err; return err;
...@@ -1131,7 +1123,6 @@ static ssize_t bql_set(const char *buf, const size_t count, ...@@ -1131,7 +1123,6 @@ static ssize_t bql_set(const char *buf, const size_t count,
} }
static ssize_t bql_show_hold_time(struct netdev_queue *queue, static ssize_t bql_show_hold_time(struct netdev_queue *queue,
struct netdev_queue_attribute *attr,
char *buf) char *buf)
{ {
struct dql *dql = &queue->dql; struct dql *dql = &queue->dql;
...@@ -1140,7 +1131,6 @@ static ssize_t bql_show_hold_time(struct netdev_queue *queue, ...@@ -1140,7 +1131,6 @@ static ssize_t bql_show_hold_time(struct netdev_queue *queue,
} }
static ssize_t bql_set_hold_time(struct netdev_queue *queue, static ssize_t bql_set_hold_time(struct netdev_queue *queue,
struct netdev_queue_attribute *attribute,
const char *buf, size_t len) const char *buf, size_t len)
{ {
struct dql *dql = &queue->dql; struct dql *dql = &queue->dql;
...@@ -1156,12 +1146,11 @@ static ssize_t bql_set_hold_time(struct netdev_queue *queue, ...@@ -1156,12 +1146,11 @@ static ssize_t bql_set_hold_time(struct netdev_queue *queue,
return len; return len;
} }
static struct netdev_queue_attribute bql_hold_time_attribute = static struct netdev_queue_attribute bql_hold_time_attribute __ro_after_init
__ATTR(hold_time, S_IRUGO | S_IWUSR, bql_show_hold_time, = __ATTR(hold_time, S_IRUGO | S_IWUSR,
bql_set_hold_time); bql_show_hold_time, bql_set_hold_time);
static ssize_t bql_show_inflight(struct netdev_queue *queue, static ssize_t bql_show_inflight(struct netdev_queue *queue,
struct netdev_queue_attribute *attr,
char *buf) char *buf)
{ {
struct dql *dql = &queue->dql; struct dql *dql = &queue->dql;
...@@ -1169,33 +1158,31 @@ static ssize_t bql_show_inflight(struct netdev_queue *queue, ...@@ -1169,33 +1158,31 @@ static ssize_t bql_show_inflight(struct netdev_queue *queue,
return sprintf(buf, "%u\n", dql->num_queued - dql->num_completed); return sprintf(buf, "%u\n", dql->num_queued - dql->num_completed);
} }
static struct netdev_queue_attribute bql_inflight_attribute = static struct netdev_queue_attribute bql_inflight_attribute __ro_after_init =
__ATTR(inflight, S_IRUGO, bql_show_inflight, NULL); __ATTR(inflight, S_IRUGO, bql_show_inflight, NULL);
#define BQL_ATTR(NAME, FIELD) \ #define BQL_ATTR(NAME, FIELD) \
static ssize_t bql_show_ ## NAME(struct netdev_queue *queue, \ static ssize_t bql_show_ ## NAME(struct netdev_queue *queue, \
struct netdev_queue_attribute *attr, \
char *buf) \ char *buf) \
{ \ { \
return bql_show(buf, queue->dql.FIELD); \ return bql_show(buf, queue->dql.FIELD); \
} \ } \
\ \
static ssize_t bql_set_ ## NAME(struct netdev_queue *queue, \ static ssize_t bql_set_ ## NAME(struct netdev_queue *queue, \
struct netdev_queue_attribute *attr, \
const char *buf, size_t len) \ const char *buf, size_t len) \
{ \ { \
return bql_set(buf, len, &queue->dql.FIELD); \ return bql_set(buf, len, &queue->dql.FIELD); \
} \ } \
\ \
static struct netdev_queue_attribute bql_ ## NAME ## _attribute = \ static struct netdev_queue_attribute bql_ ## NAME ## _attribute __ro_after_init \
__ATTR(NAME, S_IRUGO | S_IWUSR, bql_show_ ## NAME, \ = __ATTR(NAME, S_IRUGO | S_IWUSR, \
bql_set_ ## NAME); bql_show_ ## NAME, bql_set_ ## NAME)
BQL_ATTR(limit, limit) BQL_ATTR(limit, limit);
BQL_ATTR(limit_max, max_limit) BQL_ATTR(limit_max, max_limit);
BQL_ATTR(limit_min, min_limit) BQL_ATTR(limit_min, min_limit);
static struct attribute *dql_attrs[] = { static struct attribute *dql_attrs[] __ro_after_init = {
&bql_limit_attribute.attr, &bql_limit_attribute.attr,
&bql_limit_max_attribute.attr, &bql_limit_max_attribute.attr,
&bql_limit_min_attribute.attr, &bql_limit_min_attribute.attr,
...@@ -1211,8 +1198,8 @@ static const struct attribute_group dql_group = { ...@@ -1211,8 +1198,8 @@ static const struct attribute_group dql_group = {
#endif /* CONFIG_BQL */ #endif /* CONFIG_BQL */
#ifdef CONFIG_XPS #ifdef CONFIG_XPS
static ssize_t show_xps_map(struct netdev_queue *queue, static ssize_t xps_cpus_show(struct netdev_queue *queue,
struct netdev_queue_attribute *attribute, char *buf) char *buf)
{ {
struct net_device *dev = queue->dev; struct net_device *dev = queue->dev;
int cpu, len, num_tc = 1, tc = 0; int cpu, len, num_tc = 1, tc = 0;
...@@ -1258,9 +1245,8 @@ static ssize_t show_xps_map(struct netdev_queue *queue, ...@@ -1258,9 +1245,8 @@ static ssize_t show_xps_map(struct netdev_queue *queue,
return len < PAGE_SIZE ? len : -EINVAL; return len < PAGE_SIZE ? len : -EINVAL;
} }
static ssize_t store_xps_map(struct netdev_queue *queue, static ssize_t xps_cpus_store(struct netdev_queue *queue,
struct netdev_queue_attribute *attribute, const char *buf, size_t len)
const char *buf, size_t len)
{ {
struct net_device *dev = queue->dev; struct net_device *dev = queue->dev;
unsigned long index; unsigned long index;
...@@ -1288,11 +1274,11 @@ static ssize_t store_xps_map(struct netdev_queue *queue, ...@@ -1288,11 +1274,11 @@ static ssize_t store_xps_map(struct netdev_queue *queue,
return err ? : len; return err ? : len;
} }
static struct netdev_queue_attribute xps_cpus_attribute = static struct netdev_queue_attribute xps_cpus_attribute __ro_after_init
__ATTR(xps_cpus, S_IRUGO | S_IWUSR, show_xps_map, store_xps_map); = __ATTR_RW(xps_cpus);
#endif /* CONFIG_XPS */ #endif /* CONFIG_XPS */
static struct attribute *netdev_queue_default_attrs[] = { static struct attribute *netdev_queue_default_attrs[] __ro_after_init = {
&queue_trans_timeout.attr, &queue_trans_timeout.attr,
&queue_traffic_class.attr, &queue_traffic_class.attr,
#ifdef CONFIG_XPS #ifdef CONFIG_XPS
...@@ -1322,7 +1308,7 @@ static const void *netdev_queue_namespace(struct kobject *kobj) ...@@ -1322,7 +1308,7 @@ static const void *netdev_queue_namespace(struct kobject *kobj)
return ns; return ns;
} }
static struct kobj_type netdev_queue_ktype = { static struct kobj_type netdev_queue_ktype __ro_after_init = {
.sysfs_ops = &netdev_queue_sysfs_ops, .sysfs_ops = &netdev_queue_sysfs_ops,
.release = netdev_queue_release, .release = netdev_queue_release,
.default_attrs = netdev_queue_default_attrs, .default_attrs = netdev_queue_default_attrs,
...@@ -1337,23 +1323,22 @@ static int netdev_queue_add_kobject(struct net_device *dev, int index) ...@@ -1337,23 +1323,22 @@ static int netdev_queue_add_kobject(struct net_device *dev, int index)
kobj->kset = dev->queues_kset; kobj->kset = dev->queues_kset;
error = kobject_init_and_add(kobj, &netdev_queue_ktype, NULL, error = kobject_init_and_add(kobj, &netdev_queue_ktype, NULL,
"tx-%u", index); "tx-%u", index);
if (error) if (error)
goto exit; return error;
#ifdef CONFIG_BQL #ifdef CONFIG_BQL
error = sysfs_create_group(kobj, &dql_group); error = sysfs_create_group(kobj, &dql_group);
if (error) if (error) {
goto exit; kobject_put(kobj);
return error;
}
#endif #endif
kobject_uevent(kobj, KOBJ_ADD); kobject_uevent(kobj, KOBJ_ADD);
dev_hold(queue->dev); dev_hold(queue->dev);
return 0; return 0;
exit:
kobject_put(kobj);
return error;
} }
#endif /* CONFIG_SYSFS */ #endif /* CONFIG_SYSFS */
...@@ -1395,7 +1380,7 @@ static int register_queue_kobjects(struct net_device *dev) ...@@ -1395,7 +1380,7 @@ static int register_queue_kobjects(struct net_device *dev)
#ifdef CONFIG_SYSFS #ifdef CONFIG_SYSFS
dev->queues_kset = kset_create_and_add("queues", dev->queues_kset = kset_create_and_add("queues",
NULL, &dev->dev.kobj); NULL, &dev->dev.kobj);
if (!dev->queues_kset) if (!dev->queues_kset)
return -ENOMEM; return -ENOMEM;
real_rx = dev->real_num_rx_queues; real_rx = dev->real_num_rx_queues;
...@@ -1463,7 +1448,7 @@ static const void *net_netlink_ns(struct sock *sk) ...@@ -1463,7 +1448,7 @@ static const void *net_netlink_ns(struct sock *sk)
return sock_net(sk); return sock_net(sk);
} }
struct kobj_ns_type_operations net_ns_type_operations = { const struct kobj_ns_type_operations net_ns_type_operations = {
.type = KOBJ_NS_TYPE_NET, .type = KOBJ_NS_TYPE_NET,
.current_may_mount = net_current_may_mount, .current_may_mount = net_current_may_mount,
.grab_current_ns = net_grab_current_ns, .grab_current_ns = net_grab_current_ns,
...@@ -1485,7 +1470,8 @@ static int netdev_uevent(struct device *d, struct kobj_uevent_env *env) ...@@ -1485,7 +1470,8 @@ static int netdev_uevent(struct device *d, struct kobj_uevent_env *env)
/* pass ifindex to uevent. /* pass ifindex to uevent.
* ifindex is useful as it won't change (interface name may change) * ifindex is useful as it won't change (interface name may change)
* and is what RtNetlink uses natively. */ * and is what RtNetlink uses natively.
*/
retval = add_uevent_var(env, "IFINDEX=%d", dev->ifindex); retval = add_uevent_var(env, "IFINDEX=%d", dev->ifindex);
exit: exit:
...@@ -1513,7 +1499,7 @@ static const void *net_namespace(struct device *d) ...@@ -1513,7 +1499,7 @@ static const void *net_namespace(struct device *d)
return dev_net(dev); return dev_net(dev);
} }
static struct class net_class = { static struct class net_class __ro_after_init = {
.name = "net", .name = "net",
.dev_release = netdev_release, .dev_release = netdev_release,
.dev_groups = net_class_groups, .dev_groups = net_class_groups,
...@@ -1560,7 +1546,7 @@ EXPORT_SYMBOL(of_find_net_device_by_node); ...@@ -1560,7 +1546,7 @@ EXPORT_SYMBOL(of_find_net_device_by_node);
*/ */
void netdev_unregister_kobject(struct net_device *ndev) void netdev_unregister_kobject(struct net_device *ndev)
{ {
struct device *dev = &(ndev->dev); struct device *dev = &ndev->dev;
if (!atomic_read(&dev_net(ndev)->count)) if (!atomic_read(&dev_net(ndev)->count))
dev_set_uevent_suppress(dev, 1); dev_set_uevent_suppress(dev, 1);
...@@ -1577,7 +1563,7 @@ void netdev_unregister_kobject(struct net_device *ndev) ...@@ -1577,7 +1563,7 @@ void netdev_unregister_kobject(struct net_device *ndev)
/* Create sysfs entries for network device. */ /* Create sysfs entries for network device. */
int netdev_register_kobject(struct net_device *ndev) int netdev_register_kobject(struct net_device *ndev)
{ {
struct device *dev = &(ndev->dev); struct device *dev = &ndev->dev;
const struct attribute_group **groups = ndev->sysfs_groups; const struct attribute_group **groups = ndev->sysfs_groups;
int error = 0; int error = 0;
...@@ -1620,14 +1606,14 @@ int netdev_register_kobject(struct net_device *ndev) ...@@ -1620,14 +1606,14 @@ int netdev_register_kobject(struct net_device *ndev)
return error; return error;
} }
int netdev_class_create_file_ns(struct class_attribute *class_attr, int netdev_class_create_file_ns(const struct class_attribute *class_attr,
const void *ns) const void *ns)
{ {
return class_create_file_ns(&net_class, class_attr, ns); return class_create_file_ns(&net_class, class_attr, ns);
} }
EXPORT_SYMBOL(netdev_class_create_file_ns); EXPORT_SYMBOL(netdev_class_create_file_ns);
void netdev_class_remove_file_ns(struct class_attribute *class_attr, void netdev_class_remove_file_ns(const struct class_attribute *class_attr,
const void *ns) const void *ns)
{ {
class_remove_file_ns(&net_class, class_attr, ns); class_remove_file_ns(&net_class, class_attr, ns);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment