Commit 1f637703 authored by Jiri Pirko's avatar Jiri Pirko Committed by David S. Miller

net: push code from net notifier reg/unreg into helpers

Push the code which is done under rtnl lock in net notifier register and
unregister function into separate helpers.
Signed-off-by: default avatarJiri Pirko <jiri@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 48b3a137
...@@ -1784,6 +1784,42 @@ int unregister_netdevice_notifier(struct notifier_block *nb) ...@@ -1784,6 +1784,42 @@ int unregister_netdevice_notifier(struct notifier_block *nb)
} }
EXPORT_SYMBOL(unregister_netdevice_notifier); EXPORT_SYMBOL(unregister_netdevice_notifier);
static int __register_netdevice_notifier_net(struct net *net,
struct notifier_block *nb,
bool ignore_call_fail)
{
int err;
err = raw_notifier_chain_register(&net->netdev_chain, nb);
if (err)
return err;
if (dev_boot_phase)
return 0;
err = call_netdevice_register_net_notifiers(nb, net);
if (err && !ignore_call_fail)
goto chain_unregister;
return 0;
chain_unregister:
raw_notifier_chain_unregister(&net->netdev_chain, nb);
return err;
}
static int __unregister_netdevice_notifier_net(struct net *net,
struct notifier_block *nb)
{
int err;
err = raw_notifier_chain_unregister(&net->netdev_chain, nb);
if (err)
return err;
call_netdevice_unregister_net_notifiers(nb, net);
return 0;
}
/** /**
* register_netdevice_notifier_net - register a per-netns network notifier block * register_netdevice_notifier_net - register a per-netns network notifier block
* @net: network namespace * @net: network namespace
...@@ -1804,23 +1840,9 @@ int register_netdevice_notifier_net(struct net *net, struct notifier_block *nb) ...@@ -1804,23 +1840,9 @@ int register_netdevice_notifier_net(struct net *net, struct notifier_block *nb)
int err; int err;
rtnl_lock(); rtnl_lock();
err = raw_notifier_chain_register(&net->netdev_chain, nb); err = __register_netdevice_notifier_net(net, nb, false);
if (err)
goto unlock;
if (dev_boot_phase)
goto unlock;
err = call_netdevice_register_net_notifiers(nb, net);
if (err)
goto chain_unregister;
unlock:
rtnl_unlock(); rtnl_unlock();
return err; return err;
chain_unregister:
raw_notifier_chain_unregister(&netdev_chain, nb);
goto unlock;
} }
EXPORT_SYMBOL(register_netdevice_notifier_net); EXPORT_SYMBOL(register_netdevice_notifier_net);
...@@ -1846,13 +1868,7 @@ int unregister_netdevice_notifier_net(struct net *net, ...@@ -1846,13 +1868,7 @@ int unregister_netdevice_notifier_net(struct net *net,
int err; int err;
rtnl_lock(); rtnl_lock();
err = raw_notifier_chain_unregister(&net->netdev_chain, nb); err = __unregister_netdevice_notifier_net(net, nb);
if (err)
goto unlock;
call_netdevice_unregister_net_notifiers(nb, net);
unlock:
rtnl_unlock(); rtnl_unlock();
return err; return err;
} }
......
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