diff options
author | Stephen Hemminger <shemminger@osdl.org> | 2006-05-10 16:21:17 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2006-05-10 16:21:17 -0400 |
commit | b17a7c179dd3ce7d04373fddf660eda21efc9db9 (patch) | |
tree | 9f141fc2919a0aab95237812f48fa3cd0a169806 /net | |
parent | a50bb7b9af9a7c39b2aba15678eb686ae428718c (diff) |
[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: Stephen Hemminger <shemminger@osdl.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r-- | net/core/dev.c | 63 |
1 files changed, 27 insertions, 36 deletions
diff --git a/net/core/dev.c b/net/core/dev.c index ced57430f6d8..2dce673a039b 100644 --- a/net/core/dev.c +++ b/net/core/dev.c | |||
@@ -2777,6 +2777,8 @@ int register_netdevice(struct net_device *dev) | |||
2777 | BUG_ON(dev_boot_phase); | 2777 | BUG_ON(dev_boot_phase); |
2778 | ASSERT_RTNL(); | 2778 | ASSERT_RTNL(); |
2779 | 2779 | ||
2780 | might_sleep(); | ||
2781 | |||
2780 | /* When net_device's are persistent, this will be fatal. */ | 2782 | /* When net_device's are persistent, this will be fatal. */ |
2781 | BUG_ON(dev->reg_state != NETREG_UNINITIALIZED); | 2783 | BUG_ON(dev->reg_state != NETREG_UNINITIALIZED); |
2782 | 2784 | ||
@@ -2863,6 +2865,11 @@ int register_netdevice(struct net_device *dev) | |||
2863 | if (!dev->rebuild_header) | 2865 | if (!dev->rebuild_header) |
2864 | dev->rebuild_header = default_rebuild_header; | 2866 | dev->rebuild_header = default_rebuild_header; |
2865 | 2867 | ||
2868 | ret = netdev_register_sysfs(dev); | ||
2869 | if (ret) | ||
2870 | goto out_err; | ||
2871 | dev->reg_state = NETREG_REGISTERED; | ||
2872 | |||
2866 | /* | 2873 | /* |
2867 | * Default initial state at registry is that the | 2874 | * Default initial state at registry is that the |
2868 | * device is present. | 2875 | * device is present. |
@@ -2878,14 +2885,11 @@ int register_netdevice(struct net_device *dev) | |||
2878 | hlist_add_head(&dev->name_hlist, head); | 2885 | hlist_add_head(&dev->name_hlist, head); |
2879 | hlist_add_head(&dev->index_hlist, dev_index_hash(dev->ifindex)); | 2886 | hlist_add_head(&dev->index_hlist, dev_index_hash(dev->ifindex)); |
2880 | dev_hold(dev); | 2887 | dev_hold(dev); |
2881 | dev->reg_state = NETREG_REGISTERING; | ||
2882 | write_unlock_bh(&dev_base_lock); | 2888 | write_unlock_bh(&dev_base_lock); |
2883 | 2889 | ||
2884 | /* Notify protocols, that a new device appeared. */ | 2890 | /* Notify protocols, that a new device appeared. */ |
2885 | raw_notifier_call_chain(&netdev_chain, NETDEV_REGISTER, dev); | 2891 | raw_notifier_call_chain(&netdev_chain, NETDEV_REGISTER, dev); |
2886 | 2892 | ||
2887 | /* Finish registration after unlock */ | ||
2888 | net_set_todo(dev); | ||
2889 | ret = 0; | 2893 | ret = 0; |
2890 | 2894 | ||
2891 | out: | 2895 | out: |
@@ -3008,7 +3012,7 @@ static void netdev_wait_allrefs(struct net_device *dev) | |||
3008 | * | 3012 | * |
3009 | * We are invoked by rtnl_unlock() after it drops the semaphore. | 3013 | * We are invoked by rtnl_unlock() after it drops the semaphore. |
3010 | * This allows us to deal with problems: | 3014 | * This allows us to deal with problems: |
3011 | * 1) We can create/delete sysfs objects which invoke hotplug | 3015 | * 1) We can delete sysfs objects which invoke hotplug |
3012 | * without deadlocking with linkwatch via keventd. | 3016 | * without deadlocking with linkwatch via keventd. |
3013 | * 2) Since we run with the RTNL semaphore not held, we can sleep | 3017 | * 2) Since we run with the RTNL semaphore not held, we can sleep |
3014 | * safely in order to wait for the netdev refcnt to drop to zero. | 3018 | * 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 | void netdev_run_todo(void) | 3021 | void netdev_run_todo(void) |
3018 | { | 3022 | { |
3019 | struct list_head list = LIST_HEAD_INIT(list); | 3023 | struct list_head list = LIST_HEAD_INIT(list); |
3020 | int err; | ||
3021 | |||
3022 | 3024 | ||
3023 | /* Need to guard against multiple cpu's getting out of order. */ | 3025 | /* Need to guard against multiple cpu's getting out of order. */ |
3024 | mutex_lock(&net_todo_run_mutex); | 3026 | mutex_lock(&net_todo_run_mutex); |
@@ -3041,40 +3043,29 @@ void netdev_run_todo(void) | |||
3041 | = list_entry(list.next, struct net_device, todo_list); | 3043 | = list_entry(list.next, struct net_device, todo_list); |
3042 | list_del(&dev->todo_list); | 3044 | list_del(&dev->todo_list); |
3043 | 3045 | ||
3044 | switch(dev->reg_state) { | 3046 | if (unlikely(dev->reg_state != NETREG_UNREGISTERING)) { |
3045 | case NETREG_REGISTERING: | 3047 | printk(KERN_ERR "network todo '%s' but state %d\n", |
3046 | err = netdev_register_sysfs(dev); | 3048 | dev->name, dev->reg_state); |
3047 | if (err) | 3049 | dump_stack(); |
3048 | printk(KERN_ERR "%s: failed sysfs registration (%d)\n", | 3050 | continue; |
3049 | dev->name, err); | 3051 | } |
3050 | dev->reg_state = NETREG_REGISTERED; | ||
3051 | break; | ||
3052 | |||
3053 | case NETREG_UNREGISTERING: | ||
3054 | netdev_unregister_sysfs(dev); | ||
3055 | dev->reg_state = NETREG_UNREGISTERED; | ||
3056 | |||
3057 | netdev_wait_allrefs(dev); | ||
3058 | 3052 | ||
3059 | /* paranoia */ | 3053 | netdev_unregister_sysfs(dev); |
3060 | BUG_ON(atomic_read(&dev->refcnt)); | 3054 | dev->reg_state = NETREG_UNREGISTERED; |
3061 | BUG_TRAP(!dev->ip_ptr); | ||
3062 | BUG_TRAP(!dev->ip6_ptr); | ||
3063 | BUG_TRAP(!dev->dn_ptr); | ||
3064 | 3055 | ||
3056 | netdev_wait_allrefs(dev); | ||
3065 | 3057 | ||
3066 | /* It must be the very last action, | 3058 | /* paranoia */ |
3067 | * after this 'dev' may point to freed up memory. | 3059 | BUG_ON(atomic_read(&dev->refcnt)); |
3068 | */ | 3060 | BUG_TRAP(!dev->ip_ptr); |
3069 | if (dev->destructor) | 3061 | BUG_TRAP(!dev->ip6_ptr); |
3070 | dev->destructor(dev); | 3062 | BUG_TRAP(!dev->dn_ptr); |
3071 | break; | ||
3072 | 3063 | ||
3073 | default: | 3064 | /* It must be the very last action, |
3074 | printk(KERN_ERR "network todo '%s' but state %d\n", | 3065 | * after this 'dev' may point to freed up memory. |
3075 | dev->name, dev->reg_state); | 3066 | */ |
3076 | break; | 3067 | if (dev->destructor) |
3077 | } | 3068 | dev->destructor(dev); |
3078 | } | 3069 | } |
3079 | 3070 | ||
3080 | out: | 3071 | out: |