Commit b17a7c17 authored by Stephen Hemminger's avatar Stephen Hemminger Committed by David S. Miller

[NET]: Do sysfs registration as part of register_netdevice.

The last step of netdevice registration was being done by a delayed
call, but because it was delayed, it was impossible to return any error
code if the class_device registration failed.

Side effects:
 * one state in registration process is unnecessary.
 * register_netdevice can sleep inside class_device registration/hotplug
 * code in netdev_run_todo only does unregistration so it is simpler.
Signed-off-by: default avatarStephen Hemminger <shemminger@osdl.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent a50bb7b9
...@@ -433,8 +433,7 @@ struct net_device ...@@ -433,8 +433,7 @@ struct net_device
/* register/unregister state machine */ /* register/unregister state machine */
enum { NETREG_UNINITIALIZED=0, enum { NETREG_UNINITIALIZED=0,
NETREG_REGISTERING, /* called register_netdevice */ NETREG_REGISTERED, /* completed register_netdevice */
NETREG_REGISTERED, /* completed register todo */
NETREG_UNREGISTERING, /* called unregister_netdevice */ NETREG_UNREGISTERING, /* called unregister_netdevice */
NETREG_UNREGISTERED, /* completed unregister todo */ NETREG_UNREGISTERED, /* completed unregister todo */
NETREG_RELEASED, /* called free_netdev */ NETREG_RELEASED, /* called free_netdev */
......
...@@ -2777,6 +2777,8 @@ int register_netdevice(struct net_device *dev) ...@@ -2777,6 +2777,8 @@ int register_netdevice(struct net_device *dev)
BUG_ON(dev_boot_phase); BUG_ON(dev_boot_phase);
ASSERT_RTNL(); ASSERT_RTNL();
might_sleep();
/* When net_device's are persistent, this will be fatal. */ /* When net_device's are persistent, this will be fatal. */
BUG_ON(dev->reg_state != NETREG_UNINITIALIZED); BUG_ON(dev->reg_state != NETREG_UNINITIALIZED);
...@@ -2863,6 +2865,11 @@ int register_netdevice(struct net_device *dev) ...@@ -2863,6 +2865,11 @@ int register_netdevice(struct net_device *dev)
if (!dev->rebuild_header) if (!dev->rebuild_header)
dev->rebuild_header = default_rebuild_header; dev->rebuild_header = default_rebuild_header;
ret = netdev_register_sysfs(dev);
if (ret)
goto out_err;
dev->reg_state = NETREG_REGISTERED;
/* /*
* Default initial state at registry is that the * Default initial state at registry is that the
* device is present. * device is present.
...@@ -2878,14 +2885,11 @@ int register_netdevice(struct net_device *dev) ...@@ -2878,14 +2885,11 @@ int register_netdevice(struct net_device *dev)
hlist_add_head(&dev->name_hlist, head); hlist_add_head(&dev->name_hlist, head);
hlist_add_head(&dev->index_hlist, dev_index_hash(dev->ifindex)); hlist_add_head(&dev->index_hlist, dev_index_hash(dev->ifindex));
dev_hold(dev); dev_hold(dev);
dev->reg_state = NETREG_REGISTERING;
write_unlock_bh(&dev_base_lock); write_unlock_bh(&dev_base_lock);
/* Notify protocols, that a new device appeared. */ /* Notify protocols, that a new device appeared. */
raw_notifier_call_chain(&netdev_chain, NETDEV_REGISTER, dev); raw_notifier_call_chain(&netdev_chain, NETDEV_REGISTER, dev);
/* Finish registration after unlock */
net_set_todo(dev);
ret = 0; ret = 0;
out: out:
...@@ -3008,7 +3012,7 @@ static void netdev_wait_allrefs(struct net_device *dev) ...@@ -3008,7 +3012,7 @@ static void netdev_wait_allrefs(struct net_device *dev)
* *
* We are invoked by rtnl_unlock() after it drops the semaphore. * We are invoked by rtnl_unlock() after it drops the semaphore.
* This allows us to deal with problems: * This allows us to deal with problems:
* 1) We can create/delete sysfs objects which invoke hotplug * 1) We can delete sysfs objects which invoke hotplug
* without deadlocking with linkwatch via keventd. * without deadlocking with linkwatch via keventd.
* 2) Since we run with the RTNL semaphore not held, we can sleep * 2) Since we run with the RTNL semaphore not held, we can sleep
* safely in order to wait for the netdev refcnt to drop to zero. * safely in order to wait for the netdev refcnt to drop to zero.
...@@ -3017,8 +3021,6 @@ static DEFINE_MUTEX(net_todo_run_mutex); ...@@ -3017,8 +3021,6 @@ static DEFINE_MUTEX(net_todo_run_mutex);
void netdev_run_todo(void) void netdev_run_todo(void)
{ {
struct list_head list = LIST_HEAD_INIT(list); struct list_head list = LIST_HEAD_INIT(list);
int err;
/* Need to guard against multiple cpu's getting out of order. */ /* Need to guard against multiple cpu's getting out of order. */
mutex_lock(&net_todo_run_mutex); mutex_lock(&net_todo_run_mutex);
...@@ -3041,40 +3043,29 @@ void netdev_run_todo(void) ...@@ -3041,40 +3043,29 @@ void netdev_run_todo(void)
= list_entry(list.next, struct net_device, todo_list); = list_entry(list.next, struct net_device, todo_list);
list_del(&dev->todo_list); list_del(&dev->todo_list);
switch(dev->reg_state) { if (unlikely(dev->reg_state != NETREG_UNREGISTERING)) {
case NETREG_REGISTERING: printk(KERN_ERR "network todo '%s' but state %d\n",
err = netdev_register_sysfs(dev); dev->name, dev->reg_state);
if (err) dump_stack();
printk(KERN_ERR "%s: failed sysfs registration (%d)\n", continue;
dev->name, err); }
dev->reg_state = NETREG_REGISTERED;
break;
case NETREG_UNREGISTERING:
netdev_unregister_sysfs(dev);
dev->reg_state = NETREG_UNREGISTERED;
netdev_wait_allrefs(dev);
/* paranoia */ netdev_unregister_sysfs(dev);
BUG_ON(atomic_read(&dev->refcnt)); dev->reg_state = NETREG_UNREGISTERED;
BUG_TRAP(!dev->ip_ptr);
BUG_TRAP(!dev->ip6_ptr);
BUG_TRAP(!dev->dn_ptr);
netdev_wait_allrefs(dev);
/* It must be the very last action, /* paranoia */
* after this 'dev' may point to freed up memory. BUG_ON(atomic_read(&dev->refcnt));
*/ BUG_TRAP(!dev->ip_ptr);
if (dev->destructor) BUG_TRAP(!dev->ip6_ptr);
dev->destructor(dev); BUG_TRAP(!dev->dn_ptr);
break;
default: /* It must be the very last action,
printk(KERN_ERR "network todo '%s' but state %d\n", * after this 'dev' may point to freed up memory.
dev->name, dev->reg_state); */
break; if (dev->destructor)
} dev->destructor(dev);
} }
out: out:
......
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