diff options
author | Patrick McHardy <kaber@trash.net> | 2007-07-11 22:42:13 -0400 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2007-07-11 22:45:33 -0400 |
commit | 2d85cba2b272a5201a60966a65a4f8c0bcc0bb71 (patch) | |
tree | f8dd1ca6d7c963eade714a4ecc7aec4d7751f55a /net | |
parent | 8c979c26a0f093c13290320edda799d8335e50ae (diff) |
[RTNETLINK]: rtnl_link API simplification
All drivers need to unregister their devices in the module unload function.
While doing so they must hold the rtnl and atomically unregister the
rtnl_link ops as well. This makes the rtnl_link_unregister function that
takes the rtnl itself completely useless.
Provide default newlink/dellink functions, make __rtnl_link_unregister and
rtnl_link_unregister unregister all devices with matching rtnl_link_ops and
change the existing users to take advantage of that.
Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r-- | net/8021q/vlan.c | 21 | ||||
-rw-r--r-- | net/core/rtnetlink.c | 18 |
2 files changed, 14 insertions, 25 deletions
diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c index b463ba47024d..34c1d0b241ca 100644 --- a/net/8021q/vlan.c +++ b/net/8021q/vlan.c | |||
@@ -115,26 +115,6 @@ err1: | |||
115 | return err; | 115 | return err; |
116 | } | 116 | } |
117 | 117 | ||
118 | /* Cleanup all vlan devices | ||
119 | * Note: devices that have been registered that but not | ||
120 | * brought up will exist but have no module ref count. | ||
121 | */ | ||
122 | static void __exit vlan_cleanup_devices(void) | ||
123 | { | ||
124 | struct net_device *dev, *nxt; | ||
125 | |||
126 | rtnl_lock(); | ||
127 | for_each_netdev_safe(dev, nxt) { | ||
128 | if (dev->priv_flags & IFF_802_1Q_VLAN) { | ||
129 | unregister_vlan_dev(VLAN_DEV_INFO(dev)->real_dev, | ||
130 | VLAN_DEV_INFO(dev)->vlan_id); | ||
131 | |||
132 | unregister_netdevice(dev); | ||
133 | } | ||
134 | } | ||
135 | rtnl_unlock(); | ||
136 | } | ||
137 | |||
138 | /* | 118 | /* |
139 | * Module 'remove' entry point. | 119 | * Module 'remove' entry point. |
140 | * o delete /proc/net/router directory and static entries. | 120 | * o delete /proc/net/router directory and static entries. |
@@ -150,7 +130,6 @@ static void __exit vlan_cleanup_module(void) | |||
150 | unregister_netdevice_notifier(&vlan_notifier_block); | 130 | unregister_netdevice_notifier(&vlan_notifier_block); |
151 | 131 | ||
152 | dev_remove_pack(&vlan_packet_type); | 132 | dev_remove_pack(&vlan_packet_type); |
153 | vlan_cleanup_devices(); | ||
154 | 133 | ||
155 | /* This table must be empty if there are no module | 134 | /* This table must be empty if there are no module |
156 | * references left. | 135 | * references left. |
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 54c17e4cd28f..7b6b16396745 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c | |||
@@ -270,6 +270,9 @@ static LIST_HEAD(link_ops); | |||
270 | */ | 270 | */ |
271 | int __rtnl_link_register(struct rtnl_link_ops *ops) | 271 | int __rtnl_link_register(struct rtnl_link_ops *ops) |
272 | { | 272 | { |
273 | if (!ops->dellink) | ||
274 | ops->dellink = unregister_netdevice; | ||
275 | |||
273 | list_add_tail(&ops->list, &link_ops); | 276 | list_add_tail(&ops->list, &link_ops); |
274 | return 0; | 277 | return 0; |
275 | } | 278 | } |
@@ -298,12 +301,16 @@ EXPORT_SYMBOL_GPL(rtnl_link_register); | |||
298 | * __rtnl_link_unregister - Unregister rtnl_link_ops from rtnetlink. | 301 | * __rtnl_link_unregister - Unregister rtnl_link_ops from rtnetlink. |
299 | * @ops: struct rtnl_link_ops * to unregister | 302 | * @ops: struct rtnl_link_ops * to unregister |
300 | * | 303 | * |
301 | * The caller must hold the rtnl_mutex. This function should be used | 304 | * The caller must hold the rtnl_mutex. |
302 | * by drivers that unregister devices during module unloading. It must | ||
303 | * be called after unregistering the devices. | ||
304 | */ | 305 | */ |
305 | void __rtnl_link_unregister(struct rtnl_link_ops *ops) | 306 | void __rtnl_link_unregister(struct rtnl_link_ops *ops) |
306 | { | 307 | { |
308 | struct net_device *dev, *n; | ||
309 | |||
310 | for_each_netdev_safe(dev, n) { | ||
311 | if (dev->rtnl_link_ops == ops) | ||
312 | ops->dellink(dev); | ||
313 | } | ||
307 | list_del(&ops->list); | 314 | list_del(&ops->list); |
308 | } | 315 | } |
309 | 316 | ||
@@ -1067,7 +1074,10 @@ replay: | |||
1067 | if (tb[IFLA_LINKMODE]) | 1074 | if (tb[IFLA_LINKMODE]) |
1068 | dev->link_mode = nla_get_u8(tb[IFLA_LINKMODE]); | 1075 | dev->link_mode = nla_get_u8(tb[IFLA_LINKMODE]); |
1069 | 1076 | ||
1070 | err = ops->newlink(dev, tb, data); | 1077 | if (ops->newlink) |
1078 | err = ops->newlink(dev, tb, data); | ||
1079 | else | ||
1080 | err = register_netdevice(dev); | ||
1071 | err_free: | 1081 | err_free: |
1072 | if (err < 0) | 1082 | if (err < 0) |
1073 | free_netdev(dev); | 1083 | free_netdev(dev); |