Commit fd586bac authored by Kay Sievers's avatar Kay Sievers Committed by Greg Kroah-Hartman

[PATCH] net: swich device attribute creation to default attrs

Recent udev versions don't longer cover bad sysfs timing with built-in
logic. Explicit rules are required to do that. For net devices, the
following is needed:
  ACTION=="add", SUBSYSTEM=="net", WAIT_FOR_SYSFS="address"
to handle access to net device properties from an event handler without
races.

This patch changes the main net attributes to be created by the driver
core, which is done _before_ the event is sent out and will not require
the stat() loop of the WAIT_FOR_SYSFS key.
Signed-off-by: default avatarKay Sievers <kay.sievers@suse.de>
Acked-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 1f1bf132
...@@ -84,16 +84,11 @@ static ssize_t netdev_store(struct class_device *dev, ...@@ -84,16 +84,11 @@ static ssize_t netdev_store(struct class_device *dev,
return ret; return ret;
} }
/* generate a read-only network device class attribute */ NETDEVICE_SHOW(addr_len, fmt_dec);
#define NETDEVICE_ATTR(field, format_string) \ NETDEVICE_SHOW(iflink, fmt_dec);
NETDEVICE_SHOW(field, format_string) \ NETDEVICE_SHOW(ifindex, fmt_dec);
static CLASS_DEVICE_ATTR(field, S_IRUGO, show_##field, NULL) \ NETDEVICE_SHOW(features, fmt_long_hex);
NETDEVICE_SHOW(type, fmt_dec);
NETDEVICE_ATTR(addr_len, fmt_dec);
NETDEVICE_ATTR(iflink, fmt_dec);
NETDEVICE_ATTR(ifindex, fmt_dec);
NETDEVICE_ATTR(features, fmt_long_hex);
NETDEVICE_ATTR(type, fmt_dec);
/* use same locking rules as GIFHWADDR ioctl's */ /* use same locking rules as GIFHWADDR ioctl's */
static ssize_t format_addr(char *buf, const unsigned char *addr, int len) static ssize_t format_addr(char *buf, const unsigned char *addr, int len)
...@@ -136,10 +131,6 @@ static ssize_t show_carrier(struct class_device *dev, char *buf) ...@@ -136,10 +131,6 @@ static ssize_t show_carrier(struct class_device *dev, char *buf)
return -EINVAL; return -EINVAL;
} }
static CLASS_DEVICE_ATTR(address, S_IRUGO, show_address, NULL);
static CLASS_DEVICE_ATTR(broadcast, S_IRUGO, show_broadcast, NULL);
static CLASS_DEVICE_ATTR(carrier, S_IRUGO, show_carrier, NULL);
/* read-write attributes */ /* read-write attributes */
NETDEVICE_SHOW(mtu, fmt_dec); NETDEVICE_SHOW(mtu, fmt_dec);
...@@ -153,8 +144,6 @@ static ssize_t store_mtu(struct class_device *dev, const char *buf, size_t len) ...@@ -153,8 +144,6 @@ static ssize_t store_mtu(struct class_device *dev, const char *buf, size_t len)
return netdev_store(dev, buf, len, change_mtu); return netdev_store(dev, buf, len, change_mtu);
} }
static CLASS_DEVICE_ATTR(mtu, S_IRUGO | S_IWUSR, show_mtu, store_mtu);
NETDEVICE_SHOW(flags, fmt_hex); NETDEVICE_SHOW(flags, fmt_hex);
static int change_flags(struct net_device *net, unsigned long new_flags) static int change_flags(struct net_device *net, unsigned long new_flags)
...@@ -167,8 +156,6 @@ static ssize_t store_flags(struct class_device *dev, const char *buf, size_t len ...@@ -167,8 +156,6 @@ static ssize_t store_flags(struct class_device *dev, const char *buf, size_t len
return netdev_store(dev, buf, len, change_flags); return netdev_store(dev, buf, len, change_flags);
} }
static CLASS_DEVICE_ATTR(flags, S_IRUGO | S_IWUSR, show_flags, store_flags);
NETDEVICE_SHOW(tx_queue_len, fmt_ulong); NETDEVICE_SHOW(tx_queue_len, fmt_ulong);
static int change_tx_queue_len(struct net_device *net, unsigned long new_len) static int change_tx_queue_len(struct net_device *net, unsigned long new_len)
...@@ -182,9 +169,6 @@ static ssize_t store_tx_queue_len(struct class_device *dev, const char *buf, siz ...@@ -182,9 +169,6 @@ static ssize_t store_tx_queue_len(struct class_device *dev, const char *buf, siz
return netdev_store(dev, buf, len, change_tx_queue_len); return netdev_store(dev, buf, len, change_tx_queue_len);
} }
static CLASS_DEVICE_ATTR(tx_queue_len, S_IRUGO | S_IWUSR, show_tx_queue_len,
store_tx_queue_len);
NETDEVICE_SHOW(weight, fmt_dec); NETDEVICE_SHOW(weight, fmt_dec);
static int change_weight(struct net_device *net, unsigned long new_weight) static int change_weight(struct net_device *net, unsigned long new_weight)
...@@ -198,24 +182,21 @@ static ssize_t store_weight(struct class_device *dev, const char *buf, size_t le ...@@ -198,24 +182,21 @@ static ssize_t store_weight(struct class_device *dev, const char *buf, size_t le
return netdev_store(dev, buf, len, change_weight); return netdev_store(dev, buf, len, change_weight);
} }
static CLASS_DEVICE_ATTR(weight, S_IRUGO | S_IWUSR, show_weight, static struct class_device_attribute net_class_attributes[] = {
store_weight); __ATTR(addr_len, S_IRUGO, show_addr_len, NULL),
__ATTR(iflink, S_IRUGO, show_iflink, NULL),
__ATTR(ifindex, S_IRUGO, show_ifindex, NULL),
static struct class_device_attribute *net_class_attributes[] = { __ATTR(features, S_IRUGO, show_features, NULL),
&class_device_attr_ifindex, __ATTR(type, S_IRUGO, show_type, NULL),
&class_device_attr_iflink, __ATTR(address, S_IRUGO, show_address, NULL),
&class_device_attr_addr_len, __ATTR(broadcast, S_IRUGO, show_broadcast, NULL),
&class_device_attr_tx_queue_len, __ATTR(carrier, S_IRUGO, show_carrier, NULL),
&class_device_attr_features, __ATTR(mtu, S_IRUGO | S_IWUSR, show_mtu, store_mtu),
&class_device_attr_mtu, __ATTR(flags, S_IRUGO | S_IWUSR, show_flags, store_flags),
&class_device_attr_flags, __ATTR(tx_queue_len, S_IRUGO | S_IWUSR, show_tx_queue_len,
&class_device_attr_weight, store_tx_queue_len),
&class_device_attr_type, __ATTR(weight, S_IRUGO | S_IWUSR, show_weight, store_weight),
&class_device_attr_address, {}
&class_device_attr_broadcast,
&class_device_attr_carrier,
NULL
}; };
/* Show a given an attribute in the statistics group */ /* Show a given an attribute in the statistics group */
...@@ -407,6 +388,7 @@ static void netdev_release(struct class_device *cd) ...@@ -407,6 +388,7 @@ static void netdev_release(struct class_device *cd)
static struct class net_class = { static struct class net_class = {
.name = "net", .name = "net",
.release = netdev_release, .release = netdev_release,
.class_dev_attrs = net_class_attributes,
#ifdef CONFIG_HOTPLUG #ifdef CONFIG_HOTPLUG
.uevent = netdev_uevent, .uevent = netdev_uevent,
#endif #endif
...@@ -431,8 +413,6 @@ void netdev_unregister_sysfs(struct net_device * net) ...@@ -431,8 +413,6 @@ void netdev_unregister_sysfs(struct net_device * net)
int netdev_register_sysfs(struct net_device *net) int netdev_register_sysfs(struct net_device *net)
{ {
struct class_device *class_dev = &(net->class_dev); struct class_device *class_dev = &(net->class_dev);
int i;
struct class_device_attribute *attr;
int ret; int ret;
class_dev->class = &net_class; class_dev->class = &net_class;
...@@ -442,12 +422,6 @@ int netdev_register_sysfs(struct net_device *net) ...@@ -442,12 +422,6 @@ int netdev_register_sysfs(struct net_device *net)
if ((ret = class_device_register(class_dev))) if ((ret = class_device_register(class_dev)))
goto out; goto out;
for (i = 0; (attr = net_class_attributes[i]) != NULL; i++) {
if ((ret = class_device_create_file(class_dev, attr)))
goto out_unreg;
}
if (net->get_stats && if (net->get_stats &&
(ret = sysfs_create_group(&class_dev->kobj, &netstat_group))) (ret = sysfs_create_group(&class_dev->kobj, &netstat_group)))
goto out_unreg; goto out_unreg;
......
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