From: Jiri Pirko <jiri@resnulli.us>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, jakub.kicinski@netronome.com,
saeedm@mellanox.com, leon@kernel.org, tariqt@mellanox.com,
ayal@mellanox.com, vladbu@mellanox.com, michaelgur@mellanox.com,
moshe@mellanox.com, mlxsw@mellanox.com, dsahern@gmail.com
Subject: [patch net-next v2 2/4] net: push code from net notifier reg/unreg into helpers
Date: Sat, 25 Jan 2020 12:17:07 +0100 [thread overview]
Message-ID: <20200125111709.14566-3-jiri@resnulli.us> (raw)
In-Reply-To: <20200125111709.14566-1-jiri@resnulli.us>
From: Jiri Pirko <jiri@mellanox.com>
Push the code which is done under rtnl lock in net notifier register and
unregister function into separate helpers.
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
---
v1->v2:
- fixed error path of __register_netdevice_notifier_net()
---
net/core/dev.c | 60 ++++++++++++++++++++++++++++++++------------------
1 file changed, 38 insertions(+), 22 deletions(-)
diff --git a/net/core/dev.c b/net/core/dev.c
index 3cacfb7184e8..7e5aa58ce1ea 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -1784,6 +1784,42 @@ int unregister_netdevice_notifier(struct notifier_block *nb)
}
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
* @net: network namespace
@@ -1804,23 +1840,9 @@ int register_netdevice_notifier_net(struct net *net, struct notifier_block *nb)
int err;
rtnl_lock();
- err = raw_notifier_chain_register(&net->netdev_chain, nb);
- if (err)
- goto unlock;
- if (dev_boot_phase)
- goto unlock;
-
- err = call_netdevice_register_net_notifiers(nb, net);
- if (err)
- goto chain_unregister;
-
-unlock:
+ err = __register_netdevice_notifier_net(net, nb, false);
rtnl_unlock();
return err;
-
-chain_unregister:
- raw_notifier_chain_unregister(&netdev_chain, nb);
- goto unlock;
}
EXPORT_SYMBOL(register_netdevice_notifier_net);
@@ -1846,13 +1868,7 @@ int unregister_netdevice_notifier_net(struct net *net,
int err;
rtnl_lock();
- err = raw_notifier_chain_unregister(&net->netdev_chain, nb);
- if (err)
- goto unlock;
-
- call_netdevice_unregister_net_notifiers(nb, net);
-
-unlock:
+ err = __unregister_netdevice_notifier_net(net, nb);
rtnl_unlock();
return err;
}
--
2.21.0
next prev parent reply other threads:[~2020-01-25 11:17 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-25 11:17 [patch net-next v2 0/4] net: allow per-net notifier to follow netdev into namespace Jiri Pirko
2020-01-25 11:17 ` [patch net-next v2 1/4] net: call call_netdevice_unregister_net_notifiers from unregister Jiri Pirko
2020-01-25 11:17 ` Jiri Pirko [this message]
2020-01-25 11:17 ` [patch net-next v2 3/4] net: introduce dev_net notifier register/unregister variants Jiri Pirko
2020-01-25 11:17 ` [patch net-next v2 4/4] mlx5: Use dev_net netdevice notifier registrations Jiri Pirko
2020-01-27 10:04 ` [patch net-next v2 0/4] net: allow per-net notifier to follow netdev into namespace David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200125111709.14566-3-jiri@resnulli.us \
--to=jiri@resnulli.us \
--cc=ayal@mellanox.com \
--cc=davem@davemloft.net \
--cc=dsahern@gmail.com \
--cc=jakub.kicinski@netronome.com \
--cc=leon@kernel.org \
--cc=michaelgur@mellanox.com \
--cc=mlxsw@mellanox.com \
--cc=moshe@mellanox.com \
--cc=netdev@vger.kernel.org \
--cc=saeedm@mellanox.com \
--cc=tariqt@mellanox.com \
--cc=vladbu@mellanox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.