All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next] xen-netback: get rid of old udev related code
@ 2019-12-12 13:54 ` Paul Durrant
  0 siblings, 0 replies; 24+ messages in thread
From: Paul Durrant @ 2019-12-12 13:54 UTC (permalink / raw)
  To: xen-devel, netdev, linux-kernel; +Cc: Paul Durrant, Wei Liu, David S. Miller

In the past it used to be the case that the Xen toolstack relied upon
udev to execute backend hotplug scripts. However this has not been the
case for many releases now and removal of the associated code in
xen-netback shortens the source by more than 100 lines, and removes much
complexity in the interaction with the xenstore backend state.

NOTE: xen-netback is the only xenbus driver to have a functional uevent()
      method. The only other driver to have a method at all is
      pvcalls-back, and currently pvcalls_back_uevent() simply returns 0.
      Hence this patch also facilitates further cleanup.

Signed-off-by: Paul Durrant <pdurrant@amazon.com>
---
Cc: Wei Liu <wei.liu@kernel.org>
Cc: "David S. Miller" <davem@davemloft.net>
---
 drivers/net/xen-netback/common.h |  11 ---
 drivers/net/xen-netback/xenbus.c | 125 ++++---------------------------
 2 files changed, 14 insertions(+), 122 deletions(-)

diff --git a/drivers/net/xen-netback/common.h b/drivers/net/xen-netback/common.h
index 05847eb91a1b..e48da004c1a3 100644
--- a/drivers/net/xen-netback/common.h
+++ b/drivers/net/xen-netback/common.h
@@ -251,17 +251,6 @@ struct xenvif_hash {
 struct backend_info {
 	struct xenbus_device *dev;
 	struct xenvif *vif;
-
-	/* This is the state that will be reflected in xenstore when any
-	 * active hotplug script completes.
-	 */
-	enum xenbus_state state;
-
-	enum xenbus_state frontend_state;
-	struct xenbus_watch hotplug_status_watch;
-	u8 have_hotplug_status_watch:1;
-
-	const char *hotplug_script;
 };
 
 struct xenvif {
diff --git a/drivers/net/xen-netback/xenbus.c b/drivers/net/xen-netback/xenbus.c
index f533b7372d59..4e89393d5dd8 100644
--- a/drivers/net/xen-netback/xenbus.c
+++ b/drivers/net/xen-netback/xenbus.c
@@ -15,7 +15,6 @@ static int connect_data_rings(struct backend_info *be,
 static void connect(struct backend_info *be);
 static int read_xenbus_vif_flags(struct backend_info *be);
 static int backend_create_xenvif(struct backend_info *be);
-static void unregister_hotplug_status_watch(struct backend_info *be);
 static void xen_unregister_watchers(struct xenvif *vif);
 static void set_backend_state(struct backend_info *be,
 			      enum xenbus_state state);
@@ -199,17 +198,11 @@ static int netback_remove(struct xenbus_device *dev)
 {
 	struct backend_info *be = dev_get_drvdata(&dev->dev);
 
-	set_backend_state(be, XenbusStateClosed);
-
-	unregister_hotplug_status_watch(be);
 	if (be->vif) {
-		kobject_uevent(&dev->dev.kobj, KOBJ_OFFLINE);
 		xen_unregister_watchers(be->vif);
-		xenbus_rm(XBT_NIL, dev->nodename, "hotplug-status");
 		xenvif_free(be->vif);
 		be->vif = NULL;
 	}
-	kfree(be->hotplug_script);
 	kfree(be);
 	dev_set_drvdata(&dev->dev, NULL);
 	return 0;
@@ -227,7 +220,6 @@ static int netback_probe(struct xenbus_device *dev,
 	struct xenbus_transaction xbt;
 	int err;
 	int sg;
-	const char *script;
 	struct backend_info *be = kzalloc(sizeof(struct backend_info),
 					  GFP_KERNEL);
 	if (!be) {
@@ -239,7 +231,6 @@ static int netback_probe(struct xenbus_device *dev,
 	be->dev = dev;
 	dev_set_drvdata(&dev->dev, be);
 
-	be->state = XenbusStateInitialising;
 	err = xenbus_switch_state(dev, XenbusStateInitialising);
 	if (err)
 		goto fail;
@@ -347,21 +338,12 @@ static int netback_probe(struct xenbus_device *dev,
 	if (err)
 		pr_debug("Error writing feature-ctrl-ring\n");
 
-	script = xenbus_read(XBT_NIL, dev->nodename, "script", NULL);
-	if (IS_ERR(script)) {
-		err = PTR_ERR(script);
-		xenbus_dev_fatal(dev, err, "reading script");
-		goto fail;
-	}
-
-	be->hotplug_script = script;
-
-
-	/* This kicks hotplug scripts, so do it immediately. */
 	err = backend_create_xenvif(be);
 	if (err)
 		goto fail;
 
+	set_backend_state(be, XenbusStateInitWait);
+
 	return 0;
 
 abort_transaction:
@@ -374,29 +356,6 @@ static int netback_probe(struct xenbus_device *dev,
 }
 
 
-/*
- * Handle the creation of the hotplug script environment.  We add the script
- * and vif variables to the environment, for the benefit of the vif-* hotplug
- * scripts.
- */
-static int netback_uevent(struct xenbus_device *xdev,
-			  struct kobj_uevent_env *env)
-{
-	struct backend_info *be = dev_get_drvdata(&xdev->dev);
-
-	if (!be)
-		return 0;
-
-	if (add_uevent_var(env, "script=%s", be->hotplug_script))
-		return -ENOMEM;
-
-	if (!be->vif)
-		return 0;
-
-	return add_uevent_var(env, "vif=%s", be->vif->dev->name);
-}
-
-
 static int backend_create_xenvif(struct backend_info *be)
 {
 	int err;
@@ -422,7 +381,6 @@ static int backend_create_xenvif(struct backend_info *be)
 	be->vif = vif;
 	vif->be = be;
 
-	kobject_uevent(&dev->dev.kobj, KOBJ_ONLINE);
 	return 0;
 }
 
@@ -462,21 +420,6 @@ static void backend_connect(struct backend_info *be)
 		connect(be);
 }
 
-static inline void backend_switch_state(struct backend_info *be,
-					enum xenbus_state state)
-{
-	struct xenbus_device *dev = be->dev;
-
-	pr_debug("%s -> %s\n", dev->nodename, xenbus_strstate(state));
-	be->state = state;
-
-	/* If we are waiting for a hotplug script then defer the
-	 * actual xenbus state change.
-	 */
-	if (!be->have_hotplug_status_watch)
-		xenbus_switch_state(dev, state);
-}
-
 /* Handle backend state transitions:
  *
  * The backend state starts in Initialising and the following transitions are
@@ -500,17 +443,19 @@ static inline void backend_switch_state(struct backend_info *be,
 static void set_backend_state(struct backend_info *be,
 			      enum xenbus_state state)
 {
-	while (be->state != state) {
-		switch (be->state) {
+	struct xenbus_device *dev = be->dev;
+
+	while (dev->state != state) {
+		switch (dev->state) {
 		case XenbusStateInitialising:
 			switch (state) {
 			case XenbusStateInitWait:
 			case XenbusStateConnected:
 			case XenbusStateClosing:
-				backend_switch_state(be, XenbusStateInitWait);
+				xenbus_switch_state(dev, XenbusStateInitWait);
 				break;
 			case XenbusStateClosed:
-				backend_switch_state(be, XenbusStateClosed);
+				xenbus_switch_state(dev, XenbusStateClosed);
 				break;
 			default:
 				BUG();
@@ -520,10 +465,10 @@ static void set_backend_state(struct backend_info *be,
 			switch (state) {
 			case XenbusStateInitWait:
 			case XenbusStateConnected:
-				backend_switch_state(be, XenbusStateInitWait);
+				xenbus_switch_state(dev, XenbusStateInitWait);
 				break;
 			case XenbusStateClosing:
-				backend_switch_state(be, XenbusStateClosing);
+				xenbus_switch_state(dev, XenbusStateClosing);
 				break;
 			default:
 				BUG();
@@ -533,11 +478,11 @@ static void set_backend_state(struct backend_info *be,
 			switch (state) {
 			case XenbusStateConnected:
 				backend_connect(be);
-				backend_switch_state(be, XenbusStateConnected);
+				xenbus_switch_state(dev, XenbusStateConnected);
 				break;
 			case XenbusStateClosing:
 			case XenbusStateClosed:
-				backend_switch_state(be, XenbusStateClosing);
+				xenbus_switch_state(dev, XenbusStateClosing);
 				break;
 			default:
 				BUG();
@@ -549,7 +494,7 @@ static void set_backend_state(struct backend_info *be,
 			case XenbusStateClosing:
 			case XenbusStateClosed:
 				backend_disconnect(be);
-				backend_switch_state(be, XenbusStateClosing);
+				xenbus_switch_state(dev, XenbusStateClosing);
 				break;
 			default:
 				BUG();
@@ -560,7 +505,7 @@ static void set_backend_state(struct backend_info *be,
 			case XenbusStateInitWait:
 			case XenbusStateConnected:
 			case XenbusStateClosed:
-				backend_switch_state(be, XenbusStateClosed);
+				xenbus_switch_state(dev, XenbusStateClosed);
 				break;
 			default:
 				BUG();
@@ -582,8 +527,6 @@ static void frontend_changed(struct xenbus_device *dev,
 
 	pr_debug("%s -> %s\n", dev->otherend, xenbus_strstate(frontend_state));
 
-	be->frontend_state = frontend_state;
-
 	switch (frontend_state) {
 	case XenbusStateInitialising:
 		set_backend_state(be, XenbusStateInitWait);
@@ -799,38 +742,6 @@ static void xen_unregister_watchers(struct xenvif *vif)
 	xen_unregister_credit_watch(vif);
 }
 
-static void unregister_hotplug_status_watch(struct backend_info *be)
-{
-	if (be->have_hotplug_status_watch) {
-		unregister_xenbus_watch(&be->hotplug_status_watch);
-		kfree(be->hotplug_status_watch.node);
-	}
-	be->have_hotplug_status_watch = 0;
-}
-
-static void hotplug_status_changed(struct xenbus_watch *watch,
-				   const char *path,
-				   const char *token)
-{
-	struct backend_info *be = container_of(watch,
-					       struct backend_info,
-					       hotplug_status_watch);
-	char *str;
-	unsigned int len;
-
-	str = xenbus_read(XBT_NIL, be->dev->nodename, "hotplug-status", &len);
-	if (IS_ERR(str))
-		return;
-	if (len == sizeof("connected")-1 && !memcmp(str, "connected", len)) {
-		/* Complete any pending state change */
-		xenbus_switch_state(be->dev, be->state);
-
-		/* Not interested in this watch anymore. */
-		unregister_hotplug_status_watch(be);
-	}
-	kfree(str);
-}
-
 static int connect_ctrl_ring(struct backend_info *be)
 {
 	struct xenbus_device *dev = be->dev;
@@ -974,13 +885,6 @@ static void connect(struct backend_info *be)
 
 	xenvif_carrier_on(be->vif);
 
-	unregister_hotplug_status_watch(be);
-	err = xenbus_watch_pathfmt(dev, &be->hotplug_status_watch,
-				   hotplug_status_changed,
-				   "%s/%s", dev->nodename, "hotplug-status");
-	if (!err)
-		be->have_hotplug_status_watch = 1;
-
 	netif_tx_wake_all_queues(be->vif->dev);
 
 	return;
@@ -1137,7 +1041,6 @@ static struct xenbus_driver netback_driver = {
 	.ids = netback_ids,
 	.probe = netback_probe,
 	.remove = netback_remove,
-	.uevent = netback_uevent,
 	.otherend_changed = frontend_changed,
 };
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2020-01-09 13:56 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-12 13:54 [PATCH net-next] xen-netback: get rid of old udev related code Paul Durrant
2019-12-12 13:54 ` [Xen-devel] " Paul Durrant
2019-12-12 16:31 ` Jason Andryuk
2019-12-12 16:31   ` Jason Andryuk
2019-12-12 16:45   ` Durrant, Paul
2019-12-12 16:45     ` Durrant, Paul
2019-12-12 19:05 ` David Miller
2019-12-12 19:05   ` [Xen-devel] " David Miller
2019-12-13  5:40   ` Jürgen Groß
2019-12-13  5:40     ` Jürgen Groß
2019-12-13  9:24     ` Durrant, Paul
2019-12-13  9:24       ` Durrant, Paul
2019-12-13 10:02       ` Jürgen Groß
2019-12-13 10:02         ` Jürgen Groß
2019-12-13 10:12         ` Durrant, Paul
2019-12-13 10:12           ` Durrant, Paul
2019-12-16  8:10           ` Jürgen Groß
2019-12-16  8:10             ` Jürgen Groß
2019-12-16  8:18             ` Durrant, Paul
2019-12-16  8:18               ` Durrant, Paul
2019-12-16  8:29               ` Jürgen Groß
2019-12-16  8:29                 ` Jürgen Groß
2020-01-09 13:55                 ` Rich Persaud
2020-01-09 13:55                   ` Rich Persaud

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.