diff mbox series

[net-next,1/2] net: introduce a helper to move notifier block to different namespace

Message ID 20221107145213.913178-2-jiri@resnulli.us (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series net: devlink: move netdev notifier block to dest namespace during reload | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next, async
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit fail Errors and warnings before: 4343 this patch: 4345
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang fail Errors and warnings before: 1046 this patch: 1048
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn fail Errors and warnings before: 4530 this patch: 4532
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 42 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Jiri Pirko Nov. 7, 2022, 2:52 p.m. UTC
From: Jiri Pirko <jiri@nvidia.com>

Currently, net_dev() netdev notifier variant follows the netdev with
per-net notifier from namespace to namespace. This is implemented
by move_netdevice_notifiers_dev_net() helper.

For devlink it is needed to re-register per-net notifier during
devlink reload. Introduce a new helper called
move_netdevice_notifier_net() and share the unregister/register code
with existing move_netdevice_notifiers_dev_net() helper.

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
---
 include/linux/netdevice.h |  2 ++
 net/core/dev.c            | 22 ++++++++++++++++++----
 2 files changed, 20 insertions(+), 4 deletions(-)

Comments

Jakub Kicinski Nov. 8, 2022, 4:29 a.m. UTC | #1
On Mon,  7 Nov 2022 15:52:12 +0100 Jiri Pirko wrote:
> +void __move_netdevice_notifier_net(struct net *src_net, struct net *dst_net,
> +				   struct notifier_block *nb)
> +{
> +	__unregister_netdevice_notifier_net(src_net, nb);
> +	__register_netdevice_notifier_net(dst_net, nb, true);
> +}

'static' missing

> +void move_netdevice_notifier_net(struct net *src_net, struct net *dst_net,
> +				 struct notifier_block *nb)
> +{
> +	rtnl_lock();
> +	__move_netdevice_notifier_net(src_net, dst_net, nb);
> +	rtnl_unlock();
> +}
> +EXPORT_SYMBOL(move_netdevice_notifier_net);

Do we need to export this?  Maybe let's wait for a module user?
Jiri Pirko Nov. 8, 2022, 6:53 a.m. UTC | #2
Tue, Nov 08, 2022 at 05:29:37AM CET, kuba@kernel.org wrote:
>On Mon,  7 Nov 2022 15:52:12 +0100 Jiri Pirko wrote:
>> +void __move_netdevice_notifier_net(struct net *src_net, struct net *dst_net,
>> +				   struct notifier_block *nb)
>> +{
>> +	__unregister_netdevice_notifier_net(src_net, nb);
>> +	__register_netdevice_notifier_net(dst_net, nb, true);
>> +}
>
>'static' missing

Yep.

>
>> +void move_netdevice_notifier_net(struct net *src_net, struct net *dst_net,
>> +				 struct notifier_block *nb)
>> +{
>> +	rtnl_lock();
>> +	__move_netdevice_notifier_net(src_net, dst_net, nb);
>> +	rtnl_unlock();
>> +}
>> +EXPORT_SYMBOL(move_netdevice_notifier_net);
>
>Do we need to export this?  Maybe let's wait for a module user?

Ah, right.
diff mbox series

Patch

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index d45713a06568..6be93b59cfea 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -2828,6 +2828,8 @@  int unregister_netdevice_notifier(struct notifier_block *nb);
 int register_netdevice_notifier_net(struct net *net, struct notifier_block *nb);
 int unregister_netdevice_notifier_net(struct net *net,
 				      struct notifier_block *nb);
+void move_netdevice_notifier_net(struct net *src_net, struct net *dst_net,
+				 struct notifier_block *nb);
 int register_netdevice_notifier_dev_net(struct net_device *dev,
 					struct notifier_block *nb,
 					struct netdev_net_notifier *nn);
diff --git a/net/core/dev.c b/net/core/dev.c
index 3bacee3bee78..762d7255065d 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -1876,6 +1876,22 @@  int unregister_netdevice_notifier_net(struct net *net,
 }
 EXPORT_SYMBOL(unregister_netdevice_notifier_net);
 
+void __move_netdevice_notifier_net(struct net *src_net, struct net *dst_net,
+				   struct notifier_block *nb)
+{
+	__unregister_netdevice_notifier_net(src_net, nb);
+	__register_netdevice_notifier_net(dst_net, nb, true);
+}
+
+void move_netdevice_notifier_net(struct net *src_net, struct net *dst_net,
+				 struct notifier_block *nb)
+{
+	rtnl_lock();
+	__move_netdevice_notifier_net(src_net, dst_net, nb);
+	rtnl_unlock();
+}
+EXPORT_SYMBOL(move_netdevice_notifier_net);
+
 int register_netdevice_notifier_dev_net(struct net_device *dev,
 					struct notifier_block *nb,
 					struct netdev_net_notifier *nn)
@@ -1912,10 +1928,8 @@  static void move_netdevice_notifiers_dev_net(struct net_device *dev,
 {
 	struct netdev_net_notifier *nn;
 
-	list_for_each_entry(nn, &dev->net_notifier_list, list) {
-		__unregister_netdevice_notifier_net(dev_net(dev), nn->nb);
-		__register_netdevice_notifier_net(net, nn->nb, true);
-	}
+	list_for_each_entry(nn, &dev->net_notifier_list, list)
+		__move_netdevice_notifier_net(dev_net(dev), net, nn->nb);
 }
 
 /**