[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20221201164608.209537-3-jiri@resnulli.us>
Date: Thu, 1 Dec 2022 17:46:03 +0100
From: Jiri Pirko <jiri@...nulli.us>
To: netdev@...r.kernel.org
Cc: davem@...emloft.net, kuba@...nel.org, pabeni@...hat.com,
edumazet@...gle.com, yangyingliang@...wei.com, leon@...nel.org
Subject: [patch net-next RFC 2/7] netdevsim: Reorder devl_port_register/unregister() calls to be done when devlink is registered
From: Jiri Pirko <jiri@...dia.com>
Move the code so devl_port_register/unregister() are called only
then devlink is registered.
Signed-off-by: Jiri Pirko <jiri@...dia.com>
---
drivers/net/netdevsim/dev.c | 31 +++++++++++++++++++++++++------
1 file changed, 25 insertions(+), 6 deletions(-)
diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c
index b962fc8e1397..8ed235ac986f 100644
--- a/drivers/net/netdevsim/dev.c
+++ b/drivers/net/netdevsim/dev.c
@@ -949,6 +949,7 @@ static void nsim_dev_traps_exit(struct devlink *devlink)
static int nsim_dev_reload_create(struct nsim_dev *nsim_dev,
struct netlink_ext_ack *extack);
+static void nsim_dev_reload_ports_destroy(struct nsim_dev *nsim_dev);
static void nsim_dev_reload_destroy(struct nsim_dev *nsim_dev);
static int nsim_dev_reload_down(struct devlink *devlink, bool netns_change,
@@ -965,6 +966,7 @@ static int nsim_dev_reload_down(struct devlink *devlink, bool netns_change,
return -EOPNOTSUPP;
}
+ nsim_dev_reload_ports_destroy(nsim_dev);
nsim_dev_reload_destroy(nsim_dev);
return 0;
}
@@ -1600,17 +1602,22 @@ int nsim_drv_probe(struct nsim_bus_dev *nsim_bus_dev)
if (err)
goto err_psample_exit;
- err = nsim_dev_port_add_all(nsim_dev, nsim_bus_dev->port_count);
- if (err)
- goto err_hwstats_exit;
-
nsim_dev->esw_mode = DEVLINK_ESWITCH_MODE_LEGACY;
devlink_set_features(devlink, DEVLINK_F_RELOAD);
devl_unlock(devlink);
devlink_register(devlink);
+
+ devl_lock(devlink);
+ err = nsim_dev_port_add_all(nsim_dev, nsim_bus_dev->port_count);
+ devl_unlock(devlink);
+ if (err)
+ goto err_devlink_unregister;
+
return 0;
-err_hwstats_exit:
+err_devlink_unregister:
+ devlink_unregister(devlink);
+ devl_lock(devlink);
nsim_dev_hwstats_exit(nsim_dev);
err_psample_exit:
nsim_dev_psample_exit(nsim_dev);
@@ -1640,6 +1647,15 @@ int nsim_drv_probe(struct nsim_bus_dev *nsim_bus_dev)
return err;
}
+static void nsim_dev_reload_ports_destroy(struct nsim_dev *nsim_dev)
+{
+ struct devlink *devlink = priv_to_devlink(nsim_dev);
+
+ if (devlink_is_reload_failed(devlink))
+ return;
+ nsim_dev_port_del_all(nsim_dev);
+}
+
static void nsim_dev_reload_destroy(struct nsim_dev *nsim_dev)
{
struct devlink *devlink = priv_to_devlink(nsim_dev);
@@ -1654,7 +1670,6 @@ static void nsim_dev_reload_destroy(struct nsim_dev *nsim_dev)
nsim_esw_legacy_enable(nsim_dev, NULL);
}
- nsim_dev_port_del_all(nsim_dev);
nsim_dev_hwstats_exit(nsim_dev);
nsim_dev_psample_exit(nsim_dev);
nsim_dev_health_exit(nsim_dev);
@@ -1668,6 +1683,10 @@ void nsim_drv_remove(struct nsim_bus_dev *nsim_bus_dev)
struct nsim_dev *nsim_dev = dev_get_drvdata(&nsim_bus_dev->dev);
struct devlink *devlink = priv_to_devlink(nsim_dev);
+ devl_lock(devlink);
+ nsim_dev_reload_ports_destroy(nsim_dev);
+ devl_unlock(devlink);
+
devlink_unregister(devlink);
devl_lock(devlink);
nsim_dev_reload_destroy(nsim_dev);
--
2.37.3
Powered by blists - more mailing lists