Skip to contentSkip to conversation

xen-netback: windows frontend compatibility fixes

PATCH Superseded Paul Durrant 2 participants 9 messages Sep 25, 2013 – Sep 26, 2013

Subsystems (3)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#1 lore raw

PATCH v5 1/1 xen-netback: Handle backend state transitions in a more robust way

In reply to Paul Durrant

When the frontend state changes netback now specifies its desired state to a new function, set_backend_state(), which transitions through any necessary intermediate states.
This fixes an issue observed with some old Windows frontend drivers where they failed to transition through the Closing state and netback would not behave correctly.

Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
Cc David Vrabel <[email protected]>
---
 drivers/net/xen-netback/xenbus.c |  143 ++++++++++++++++++++++++++++++--------
 1 file changed, 113 insertions(+), 30 deletions(-)
drivers/net/xen-netback/xenbus.c +113 -30
index a53782e..01329b2 100644
@@ -24,6 +24,7 @@
 struct backend_info {
 	struct xenbus_device *dev;
 	struct xenvif *vif;
+	enum xenbus_state state;
 	enum xenbus_state frontend_state;
 	struct xenbus_watch hotplug_status_watch;
 	u8 have_hotplug_status_watch:1;
@@ -136,6 +137,8 @@ static int netback_probe(struct xenbus_device *dev,
 	if (err)
 		goto fail;
 
+	be->state = XenbusStateInitWait;
+
 	/* This kicks hotplug scripts, so do it immediately. */
 	backend_create_xenvif(be);
 
@@ -208,24 +211,113 @@ static void backend_create_xenvif(struct backend_info *be)
 	kobject_uevent(&dev->dev.kobj, KOBJ_ONLINE);
 }
 
-
-static void disconnect_backend(struct xenbus_device *dev)
+static void backend_disconnect(struct backend_info *be)
 {
-	struct backend_info *be = dev_get_drvdata(&dev->dev);
-
 	if (be->vif)
 		xenvif_disconnect(be->vif);
 }
 
-static void destroy_backend(struct xenbus_device *dev)
+static void backend_connect(struct backend_info *be)
 {
-	struct backend_info *be = dev_get_drvdata(&dev->dev);
+	if (be->vif)
+		connect(be);
+}
 
-	if (be->vif) {
-		kobject_uevent(&dev->dev.kobj, KOBJ_OFFLINE);
-		xenbus_rm(XBT_NIL, dev->nodename, "hotplug-status");
-		xenvif_free(be->vif);
-		be->vif = NULL;
+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 InitWait and the following transitions are
+ * allowed.
+ *
+ * InitWait -> Connected
+ *
+ *    ^    \         |
+ *    |     \        |
+ *    |      \       |
+ *    |       \      |
+ *    |        \     |
+ *    |         \    |
+ *    |          V   V
+ *
+ *  Closed  <-> Closing
+ *
+ * The state argument specifies the eventual state of the backend and the
+ * function transitions to that state via the shortest path.
+ */
+static void set_backend_state(struct backend_info *be,
+			      enum xenbus_state state)
+{
+	while (be->state != state) {
+		switch (be->state) {
+		case XenbusStateClosed:
+			switch (state) {
+			case XenbusStateInitWait:
+			case XenbusStateConnected:
+				pr_info("%s: prepare for reconnect\n",
+					be->dev->nodename);
+				backend_switch_state(be, XenbusStateInitWait);
+				break;
+			case XenbusStateClosing:
+				backend_switch_state(be, XenbusStateClosing);
+				break;
+			default:
+				BUG();
+			}
+			break;
+		case XenbusStateInitWait:
+			switch (state) {
+			case XenbusStateConnected:
+				backend_connect(be);
+				backend_switch_state(be, XenbusStateConnected);
+				break;
+			case XenbusStateClosing:
+			case XenbusStateClosed:
+				backend_switch_state(be, XenbusStateClosing);
+				break;
+			default:
+				BUG();
+			}
+			break;
+		case XenbusStateConnected:
+			switch (state) {
+			case XenbusStateInitWait:
+			case XenbusStateClosing:
+			case XenbusStateClosed:
+				backend_disconnect(be);
+				backend_switch_state(be, XenbusStateClosing);
+				break;
+			default:
+				BUG();
+			}
+			break;
+		case XenbusStateClosing:
+			switch (state) {
+			case XenbusStateInitWait:
+			case XenbusStateConnected:
+			case XenbusStateClosed:
+				backend_switch_state(be, XenbusStateClosed);
+				break;
+			default:
+				BUG();
+			}
+			break;
+		default:
+			BUG();
+		}
 	}
 }
 
@@ -237,40 +329,33 @@ static void frontend_changed(struct xenbus_device *dev,
 {
 	struct backend_info *be = dev_get_drvdata(&dev->dev);
 
-	pr_debug("frontend state %s\n", xenbus_strstate(frontend_state));
+	pr_debug("%s -> %s\n", dev->otherend, xenbus_strstate(frontend_state));
 
 	be->frontend_state = frontend_state;
 
 	switch (frontend_state) {
 	case XenbusStateInitialising:
-		if (dev->state == XenbusStateClosed) {
-			pr_info("%s: prepare for reconnect\n", dev->nodename);
-			xenbus_switch_state(dev, XenbusStateInitWait);
-		}
+		set_backend_state(be, XenbusStateInitWait);
 		break;
 
 	case XenbusStateInitialised:
 		break;
 
 	case XenbusStateConnected:
-		if (dev->state == XenbusStateConnected)
-			break;
-		if (be->vif)
-			connect(be);
+		set_backend_state(be, XenbusStateConnected);
 		break;
 
 	case XenbusStateClosing:
-		disconnect_backend(dev);
-		xenbus_switch_state(dev, XenbusStateClosing);
+		set_backend_state(be, XenbusStateClosing);
 		break;
 
 	case XenbusStateClosed:
-		xenbus_switch_state(dev, XenbusStateClosed);
+		set_backend_state(be, XenbusStateClosed);
 		if (xenbus_dev_is_online(dev))
 			break;
-		destroy_backend(dev);
 		/* fall through if not online */
 	case XenbusStateUnknown:
+		set_backend_state(be, XenbusStateClosed);
 		device_unregister(&dev->dev);
 		break;
 
@@ -363,7 +448,9 @@ static void hotplug_status_changed(struct xenbus_watch *watch,
 	if (IS_ERR(str))
 		return;
 	if (len == sizeof("connected")-1 && !memcmp(str, "connected", len)) {
-		xenbus_switch_state(be->dev, XenbusStateConnected);
+		/* Complete any pending state change */
+		xenbus_switch_state(be->dev, be->state);
+
 		/* Not interested in this watch anymore. */
 		unregister_hotplug_status_watch(be);
 	}
@@ -393,12 +480,8 @@ static void connect(struct backend_info *be)
 	err = xenbus_watch_pathfmt(dev, &be->hotplug_status_watch,
 				   hotplug_status_changed,
 				   "%s/%s", dev->nodename, "hotplug-status");
-	if (err) {
-		/* Switch now, since we can't do a watch. */
-		xenbus_switch_state(dev, XenbusStateConnected);
-	} else {
+	if (!err)
 		be->have_hotplug_status_watch = 1;
-	}
 
 	netif_wake_queue(be->vif->dev);
 }
Signature · 1 line
1.7.10.4
#0 lore raw

v5 cover xen-netback: windows frontend compatibility fixes

The following patches fix a couple more issues found when testing with Windows frontends.

v5:
- Fix typos pointed out by Wei Liu

v4:
- Fix problem with hotplug failure noticed by Wei Liu

v3:
- Collapse both v2 patches into a single patch that introduces a new function to handle backend state transtions. By doing this we ensure that we always transition through intermediate states and that we don't attempt repeated connects or disconnects.

v2:
- Add comment in 2/2 to note that state transitions from Connected to Closed are incorrect.

#2 lore raw

PATCH v5 1/1 xen-netback: Handle backend state transitions in a more robust way

When the frontend state changes netback now specifies its desired state to a new function, set_backend_state(), which transitions through any necessary intermediate states.
This fixes an issue observed with some old Windows frontend drivers where they failed to transition through the Closing state and netback would not behave correctly.

Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
Cc David Vrabel <[email protected]>
---
 drivers/net/xen-netback/xenbus.c |  143 ++++++++++++++++++++++++++++++--------
 1 file changed, 113 insertions(+), 30 deletions(-)
drivers/net/xen-netback/xenbus.c +113 -30
index a53782e..01329b2 100644
@@ -24,6 +24,7 @@
 struct backend_info {
 	struct xenbus_device *dev;
 	struct xenvif *vif;
+	enum xenbus_state state;
 	enum xenbus_state frontend_state;
 	struct xenbus_watch hotplug_status_watch;
 	u8 have_hotplug_status_watch:1;
@@ -136,6 +137,8 @@ static int netback_probe(struct xenbus_device *dev,
 	if (err)
 		goto fail;
 
+	be->state = XenbusStateInitWait;
+
 	/* This kicks hotplug scripts, so do it immediately. */
 	backend_create_xenvif(be);
 
@@ -208,24 +211,113 @@ static void backend_create_xenvif(struct backend_info *be)
 	kobject_uevent(&dev->dev.kobj, KOBJ_ONLINE);
 }
 
-
-static void disconnect_backend(struct xenbus_device *dev)
+static void backend_disconnect(struct backend_info *be)
 {
-	struct backend_info *be = dev_get_drvdata(&dev->dev);
-
 	if (be->vif)
 		xenvif_disconnect(be->vif);
 }
 
-static void destroy_backend(struct xenbus_device *dev)
+static void backend_connect(struct backend_info *be)
 {
-	struct backend_info *be = dev_get_drvdata(&dev->dev);
+	if (be->vif)
+		connect(be);
+}
 
-	if (be->vif) {
-		kobject_uevent(&dev->dev.kobj, KOBJ_OFFLINE);
-		xenbus_rm(XBT_NIL, dev->nodename, "hotplug-status");
-		xenvif_free(be->vif);
-		be->vif = NULL;
+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 InitWait and the following transitions are
+ * allowed.
+ *
+ * InitWait -> Connected
+ *
+ *    ^    \         |
+ *    |     \        |
+ *    |      \       |
+ *    |       \      |
+ *    |        \     |
+ *    |         \    |
+ *    |          V   V
+ *
+ *  Closed  <-> Closing
+ *
+ * The state argument specifies the eventual state of the backend and the
+ * function transitions to that state via the shortest path.
+ */
+static void set_backend_state(struct backend_info *be,
+			      enum xenbus_state state)
+{
+	while (be->state != state) {
+		switch (be->state) {
+		case XenbusStateClosed:
+			switch (state) {
+			case XenbusStateInitWait:
+			case XenbusStateConnected:
+				pr_info("%s: prepare for reconnect\n",
+					be->dev->nodename);
+				backend_switch_state(be, XenbusStateInitWait);
+				break;
+			case XenbusStateClosing:
+				backend_switch_state(be, XenbusStateClosing);
+				break;
+			default:
+				BUG();
+			}
+			break;
+		case XenbusStateInitWait:
+			switch (state) {
+			case XenbusStateConnected:
+				backend_connect(be);
+				backend_switch_state(be, XenbusStateConnected);
+				break;
+			case XenbusStateClosing:
+			case XenbusStateClosed:
+				backend_switch_state(be, XenbusStateClosing);
+				break;
+			default:
+				BUG();
+			}
+			break;
+		case XenbusStateConnected:
+			switch (state) {
+			case XenbusStateInitWait:
+			case XenbusStateClosing:
+			case XenbusStateClosed:
+				backend_disconnect(be);
+				backend_switch_state(be, XenbusStateClosing);
+				break;
+			default:
+				BUG();
+			}
+			break;
+		case XenbusStateClosing:
+			switch (state) {
+			case XenbusStateInitWait:
+			case XenbusStateConnected:
+			case XenbusStateClosed:
+				backend_switch_state(be, XenbusStateClosed);
+				break;
+			default:
+				BUG();
+			}
+			break;
+		default:
+			BUG();
+		}
 	}
 }
 
@@ -237,40 +329,33 @@ static void frontend_changed(struct xenbus_device *dev,
 {
 	struct backend_info *be = dev_get_drvdata(&dev->dev);
 
-	pr_debug("frontend state %s\n", xenbus_strstate(frontend_state));
+	pr_debug("%s -> %s\n", dev->otherend, xenbus_strstate(frontend_state));
 
 	be->frontend_state = frontend_state;
 
 	switch (frontend_state) {
 	case XenbusStateInitialising:
-		if (dev->state == XenbusStateClosed) {
-			pr_info("%s: prepare for reconnect\n", dev->nodename);
-			xenbus_switch_state(dev, XenbusStateInitWait);
-		}
+		set_backend_state(be, XenbusStateInitWait);
 		break;
 
 	case XenbusStateInitialised:
 		break;
 
 	case XenbusStateConnected:
-		if (dev->state == XenbusStateConnected)
-			break;
-		if (be->vif)
-			connect(be);
+		set_backend_state(be, XenbusStateConnected);
 		break;
 
 	case XenbusStateClosing:
-		disconnect_backend(dev);
-		xenbus_switch_state(dev, XenbusStateClosing);
+		set_backend_state(be, XenbusStateClosing);
 		break;
 
 	case XenbusStateClosed:
-		xenbus_switch_state(dev, XenbusStateClosed);
+		set_backend_state(be, XenbusStateClosed);
 		if (xenbus_dev_is_online(dev))
 			break;
-		destroy_backend(dev);
 		/* fall through if not online */
 	case XenbusStateUnknown:
+		set_backend_state(be, XenbusStateClosed);
 		device_unregister(&dev->dev);
 		break;
 
@@ -363,7 +448,9 @@ static void hotplug_status_changed(struct xenbus_watch *watch,
 	if (IS_ERR(str))
 		return;
 	if (len == sizeof("connected")-1 && !memcmp(str, "connected", len)) {
-		xenbus_switch_state(be->dev, XenbusStateConnected);
+		/* Complete any pending state change */
+		xenbus_switch_state(be->dev, be->state);
+
 		/* Not interested in this watch anymore. */
 		unregister_hotplug_status_watch(be);
 	}
@@ -393,12 +480,8 @@ static void connect(struct backend_info *be)
 	err = xenbus_watch_pathfmt(dev, &be->hotplug_status_watch,
 				   hotplug_status_changed,
 				   "%s/%s", dev->nodename, "hotplug-status");
-	if (err) {
-		/* Switch now, since we can't do a watch. */
-		xenbus_switch_state(dev, XenbusStateConnected);
-	} else {
+	if (!err)
 		be->have_hotplug_status_watch = 1;
-	}
 
 	netif_wake_queue(be->vif->dev);
 }
Signature · 1 line
1.7.10.4
#3 lore raw

Re: [PATCH net v5 1/1] xen-netback: Handle backend state transitions in a more robust way

Quoted 6 lines · Paul Durrant

When the frontend state changes netback now specifies its desired state to a new function, set_backend_state(), which transitions through any necessary intermediate states.
This fixes an issue observed with some old Windows frontend drivers where they failed to transition through the Closing state and netback would not behave correctly.

I'm somewhat terrified of breaking compatibility with some old or obscure frontend here. I don't think it is reasonable to try and test all of those so I guess we'll just have to deal with that when it happens...

Quoted 13 lines
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
Cc David Vrabel <[email protected]>
---
 drivers/net/xen-netback/xenbus.c |  143 ++++++++++++++++++++++++++++++--------
 1 file changed, 113 insertions(+), 30 deletions(-)
drivers/net/xen-netback/xenbus.c +0 -0
index a53782e..01329b2 100644

drivers/net/xen-netback/xenbus.c line 27

Quoted 4 lines
drivers/net/xen-netback/xenbus.c +1 -0
@@ -24,6 +24,7 @@
 struct backend_info {
 	struct xenbus_device *dev;
 	struct xenvif *vif;
+	enum xenbus_state state;

This cannot just be read from xenstore because of the wait-for-hotplug-script deferral stuff, right?

I'm not sure it is worth clarifying that, either by a comment or by naming it deferred_state_change or something?

drivers/net/xen-netback/xenbus.c static void backend_create_xenvif(struct backend_info *be) · line 228

Quoted 13 lines
drivers/net/xen-netback/xenbus.c +4 -7
-static void destroy_backend(struct xenbus_device *dev)
+static void backend_connect(struct backend_info *be)
 {
-	struct backend_info *be = dev_get_drvdata(&dev->dev);
+	if (be->vif)
+		connect(be);
+}
 
-	if (be->vif) {
-		kobject_uevent(&dev->dev.kobj, KOBJ_OFFLINE);
-		xenbus_rm(XBT_NIL, dev->nodename, "hotplug-status");
-		xenvif_free(be->vif);
-		be->vif = NULL;

Where did this uevent offlining functionality end up?

drivers/net/xen-netback/xenbus.c static void backend_create_xenvif(struct backend_info *be) · line 235

Quoted 10 lines
drivers/net/xen-netback/xenbus.c +10 -0
+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.

Is the right/wise regardless of the state we are moving too? Might the state change have effectively "cancelled" the need to wait for the script?

The previous code only deferred when moving to Connected. If we are now moving to Closed/Closing do we still need to wait?

Ian.

#4 lore raw

Re: [PATCH net v5 1/1] xen-netback: Handle backend state transitions in a more robust way

In reply to Paul Durrant
Quoted 6 lines · Paul Durrant

When the frontend state changes netback now specifies its desired state to a new function, set_backend_state(), which transitions through any necessary intermediate states.
This fixes an issue observed with some old Windows frontend drivers where they failed to transition through the Closing state and netback would not behave correctly.

I'm somewhat terrified of breaking compatibility with some old or obscure frontend here. I don't think it is reasonable to try and test all of those so I guess we'll just have to deal with that when it happens...

Quoted 13 lines
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
Cc David Vrabel <[email protected]>
---
 drivers/net/xen-netback/xenbus.c |  143 ++++++++++++++++++++++++++++++--------
 1 file changed, 113 insertions(+), 30 deletions(-)
drivers/net/xen-netback/xenbus.c +0 -0
index a53782e..01329b2 100644

drivers/net/xen-netback/xenbus.c line 27

Quoted 4 lines
drivers/net/xen-netback/xenbus.c +1 -0
@@ -24,6 +24,7 @@
 struct backend_info {
 	struct xenbus_device *dev;
 	struct xenvif *vif;
+	enum xenbus_state state;

This cannot just be read from xenstore because of the wait-for-hotplug-script deferral stuff, right?

I'm not sure it is worth clarifying that, either by a comment or by naming it deferred_state_change or something?

drivers/net/xen-netback/xenbus.c static void backend_create_xenvif(struct backend_info *be) · line 228

Quoted 13 lines
drivers/net/xen-netback/xenbus.c +4 -7
-static void destroy_backend(struct xenbus_device *dev)
+static void backend_connect(struct backend_info *be)
 {
-	struct backend_info *be = dev_get_drvdata(&dev->dev);
+	if (be->vif)
+		connect(be);
+}
 
-	if (be->vif) {
-		kobject_uevent(&dev->dev.kobj, KOBJ_OFFLINE);
-		xenbus_rm(XBT_NIL, dev->nodename, "hotplug-status");
-		xenvif_free(be->vif);
-		be->vif = NULL;

Where did this uevent offlining functionality end up?

drivers/net/xen-netback/xenbus.c static void backend_create_xenvif(struct backend_info *be) · line 235

Quoted 10 lines
drivers/net/xen-netback/xenbus.c +10 -0
+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.

Is the right/wise regardless of the state we are moving too? Might the state change have effectively "cancelled" the need to wait for the script?

The previous code only deferred when moving to Connected. If we are now moving to Closed/Closing do we still need to wait?

Ian.

#5 lore raw

Re: [PATCH net v5 1/1] xen-netback: Handle backend state transitions in a more robust way

Quoted 34 lines

-----Original Message-----
From: Ian Campbell
Sent: 26 September 2013 11:17
To: Paul Durrant
Cc: [email protected]; [email protected]; Wei Liu; David Vrabel
Subject: Re: [PATCH net v5 1/1] xen-netback: Handle backend state transitions in a more robust way

Quoted 1 line · Paul Durrant

When the frontend state changes netback now specifies its desired state

to

Quoted 3 lines

a new function, set_backend_state(), which transitions through any necessary intermediate states.
This fixes an issue observed with some old Windows frontend drivers

where

Quoted 2 lines

they failed to transition through the Closing state and netback would not behave correctly.

I'm somewhat terrified of breaking compatibility with some old or obscure frontend here. I don't think it is reasonable to try and test all of those so I guess we'll just have to deal with that when it happens...

Quoted 6 lines
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
Cc David Vrabel <[email protected]>
---
 drivers/net/xen-netback/xenbus.c |  143

++++++++++++++++++++++++++++++--------

drivers/net/xen-

Quoted 3 lines
 1 file changed, 113 insertions(+), 30 deletions(-)
drivers/net/xen- renamed from drivers/net/xen-netback/xenbus.c +0 -0

netback/xenbus.c

Quoted 12 lines

drivers/net/xen-netback/xenbus.c line 27

Quoted 8 lines

index a53782e..01329b2 100644

drivers/net/xen-netback/xenbus.c +1 -0
@@ -24,6 +24,7 @@
 struct backend_info {
 	struct xenbus_device *dev;
 	struct xenvif *vif;
+	enum xenbus_state state;

This cannot just be read from xenstore because of the wait-for-hotplug-script deferral stuff, right?

Yes, that's right.

Quoted 3 lines

I'm not sure it is worth clarifying that, either by a comment or by naming it deferred_state_change or something?

It’s the xenbus state that's deferred, the backend state leads so I could name it 'desired_state' or 'target_state' perhaps; probably a bit ugly so I'll add a comment above that field I think.

Quoted 8 lines
Quoted 8 lines
drivers/net/xen-netback/xenbus.c +4 -2
-static void destroy_backend(struct xenbus_device *dev)
+static void backend_connect(struct backend_info *be)
 {
-	struct backend_info *be = dev_get_drvdata(&dev->dev);
+	if (be->vif)
+		connect(be);
+}
Quoted 8 lines

drivers/net/xen-netback/xenbus.c static void backend_create_xenvif(struct backend_info *be) · line 228

Quoted 5 lines
drivers/net/xen-netback/xenbus.c +0 -5
-	if (be->vif) {
-		kobject_uevent(&dev->dev.kobj, KOBJ_OFFLINE);
-		xenbus_rm(XBT_NIL, dev->nodename, "hotplug-status");
-		xenvif_free(be->vif);
-		be->vif = NULL;

Where did this uevent offlining functionality end up?

It's done in netback_remove() .

Quoted 15 lines

drivers/net/xen-netback/xenbus.c static void backend_create_xenvif(struct backend_info *be) · line 235

Quoted 10 lines
drivers/net/xen-netback/xenbus.c +10 -0
+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.

Is the right/wise regardless of the state we are moving too? Might the state change have effectively "cancelled" the need to wait for the script?

Quoted 3 lines

The previous code only deferred when moving to Connected. If we are now moving to Closed/Closing do we still need to wait?

I debated about this; we never really dealt with this before. I think it's legitimate for the frontend to give up waiting for a backend hotplug so we should be able to go from InitWait to Closing, so in this case be->state will be Closing when the script (hopefully) finishes. Thus we move to that when the watch fires rather than to Connected. Then the frontend can move to Closed. If the hotplug script never finishes then I don't think we're any more screwed than we were before.

Paul

Quoted 2 lines

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#6 lore raw

RE: [PATCH net v5 1/1] xen-netback: Handle backend state transitions in a more robust way

In reply to Ian Campbell
Quoted 34 lines

-----Original Message-----
From: Ian Campbell
Sent: 26 September 2013 11:17
To: Paul Durrant
Cc: [email protected]; [email protected]; Wei Liu; David Vrabel
Subject: Re: [PATCH net v5 1/1] xen-netback: Handle backend state transitions in a more robust way

Quoted 1 line · Paul Durrant

When the frontend state changes netback now specifies its desired state

to

Quoted 3 lines

a new function, set_backend_state(), which transitions through any necessary intermediate states.
This fixes an issue observed with some old Windows frontend drivers

where

Quoted 2 lines

they failed to transition through the Closing state and netback would not behave correctly.

I'm somewhat terrified of breaking compatibility with some old or obscure frontend here. I don't think it is reasonable to try and test all of those so I guess we'll just have to deal with that when it happens...

Quoted 6 lines
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
Cc David Vrabel <[email protected]>
---
 drivers/net/xen-netback/xenbus.c |  143

++++++++++++++++++++++++++++++--------

drivers/net/xen-

Quoted 3 lines
 1 file changed, 113 insertions(+), 30 deletions(-)
drivers/net/xen- renamed from drivers/net/xen-netback/xenbus.c +0 -0

netback/xenbus.c

Quoted 12 lines

drivers/net/xen-netback/xenbus.c line 27

Quoted 8 lines

index a53782e..01329b2 100644

drivers/net/xen-netback/xenbus.c +1 -0
@@ -24,6 +24,7 @@
 struct backend_info {
 	struct xenbus_device *dev;
 	struct xenvif *vif;
+	enum xenbus_state state;

This cannot just be read from xenstore because of the wait-for-hotplug-script deferral stuff, right?

Yes, that's right.

Quoted 3 lines

I'm not sure it is worth clarifying that, either by a comment or by naming it deferred_state_change or something?

It’s the xenbus state that's deferred, the backend state leads so I could name it 'desired_state' or 'target_state' perhaps; probably a bit ugly so I'll add a comment above that field I think.

Quoted 8 lines
Quoted 8 lines
drivers/net/xen-netback/xenbus.c +4 -2
-static void destroy_backend(struct xenbus_device *dev)
+static void backend_connect(struct backend_info *be)
 {
-	struct backend_info *be = dev_get_drvdata(&dev->dev);
+	if (be->vif)
+		connect(be);
+}
Quoted 8 lines

drivers/net/xen-netback/xenbus.c static void backend_create_xenvif(struct backend_info *be) · line 228

Quoted 5 lines
drivers/net/xen-netback/xenbus.c +0 -5
-	if (be->vif) {
-		kobject_uevent(&dev->dev.kobj, KOBJ_OFFLINE);
-		xenbus_rm(XBT_NIL, dev->nodename, "hotplug-status");
-		xenvif_free(be->vif);
-		be->vif = NULL;

Where did this uevent offlining functionality end up?

It's done in netback_remove() .

Quoted 15 lines

drivers/net/xen-netback/xenbus.c static void backend_create_xenvif(struct backend_info *be) · line 235

Quoted 10 lines
drivers/net/xen-netback/xenbus.c +10 -0
+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.

Is the right/wise regardless of the state we are moving too? Might the state change have effectively "cancelled" the need to wait for the script?

Quoted 3 lines

The previous code only deferred when moving to Connected. If we are now moving to Closed/Closing do we still need to wait?

I debated about this; we never really dealt with this before. I think it's legitimate for the frontend to give up waiting for a backend hotplug so we should be able to go from InitWait to Closing, so in this case be->state will be Closing when the script (hopefully) finishes. Thus we move to that when the watch fires rather than to Connected. Then the frontend can move to Closed. If the hotplug script never finishes then I don't think we're any more screwed than we were before.

Paul

Quoted 2 lines

Ian.

#7 lore raw

Re: [PATCH net v5 1/1] xen-netback: Handle backend state transitions in a more robust way

Quoted 49 lines · Paul Durrant
Quoted 34 lines

-----Original Message-----
From: Ian Campbell
Sent: 26 September 2013 11:17
To: Paul Durrant
Cc: [email protected]; [email protected]; Wei Liu; David Vrabel
Subject: Re: [PATCH net v5 1/1] xen-netback: Handle backend state transitions in a more robust way

Quoted 1 line · Paul Durrant

When the frontend state changes netback now specifies its desired state

to

Quoted 3 lines

a new function, set_backend_state(), which transitions through any necessary intermediate states.
This fixes an issue observed with some old Windows frontend drivers

where

Quoted 2 lines

they failed to transition through the Closing state and netback would not behave correctly.

I'm somewhat terrified of breaking compatibility with some old or obscure frontend here. I don't think it is reasonable to try and test all of those so I guess we'll just have to deal with that when it happens...

Quoted 6 lines
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
Cc David Vrabel <[email protected]>
---
 drivers/net/xen-netback/xenbus.c |  143

++++++++++++++++++++++++++++++--------

drivers/net/xen-

Quoted 3 lines
 1 file changed, 113 insertions(+), 30 deletions(-)
drivers/net/xen- renamed from drivers/net/xen-netback/xenbus.c +0 -0

netback/xenbus.c

Quoted 12 lines

drivers/net/xen-netback/xenbus.c line 27

Quoted 8 lines

index a53782e..01329b2 100644

drivers/net/xen-netback/xenbus.c +1 -0
@@ -24,6 +24,7 @@
 struct backend_info {
 	struct xenbus_device *dev;
 	struct xenvif *vif;
+	enum xenbus_state state;

This cannot just be read from xenstore because of the wait-for-hotplug-script deferral stuff, right?

Yes, that's right.

Quoted 7 lines
Quoted 3 lines

I'm not sure it is worth clarifying that, either by a comment or by naming it deferred_state_change or something?

It’s the xenbus state that's deferred, the backend state leads so I could name it 'desired_state' or 'target_state' perhaps; probably a bit ugly so I'll add a comment above that field I think.

OK.

Quoted 39 lines
Quoted 9 lines
Quoted 9 lines
drivers/net/xen-netback/xenbus.c +4 -2
-static void destroy_backend(struct xenbus_device *dev)
+static void backend_connect(struct backend_info *be)
 {
-	struct backend_info *be = dev_get_drvdata(&dev->dev);
+	if (be->vif)
+		connect(be);
+}
Quoted 8 lines

drivers/net/xen-netback/xenbus.c static void backend_create_xenvif(struct backend_info *be) · line 228

Quoted 5 lines
drivers/net/xen-netback/xenbus.c +0 -5
-	if (be->vif) {
-		kobject_uevent(&dev->dev.kobj, KOBJ_OFFLINE);
-		xenbus_rm(XBT_NIL, dev->nodename, "hotplug-status");
-		xenvif_free(be->vif);
-		be->vif = NULL;

Where did this uevent offlining functionality end up?

It's done in netback_remove() .

Quoted 15 lines

drivers/net/xen-netback/xenbus.c static void backend_create_xenvif(struct backend_info *be) · line 235

Quoted 10 lines
drivers/net/xen-netback/xenbus.c +10 -0
+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.

Is the right/wise regardless of the state we are moving too? Might the state change have effectively "cancelled" the need to wait for the script?

Quoted 3 lines

The previous code only deferred when moving to Connected. If we are now moving to Closed/Closing do we still need to wait?

Quoted 8 lines

I debated about this; we never really dealt with this before. I think it's legitimate for the frontend to give up waiting for a backend hotplug so we should be able to go from InitWait to Closing, so in this case be->state will be Closing when the script (hopefully) finishes. Thus we move to that when the watch fires rather than to Connected. Then the frontend can move to Closed. If the hotplug script never finishes then I don't think we're any more screwed than we were before.

OK.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#8 lore raw

Re: [PATCH net v5 1/1] xen-netback: Handle backend state transitions in a more robust way

In reply to Paul Durrant
Quoted 49 lines · Paul Durrant
Quoted 34 lines

-----Original Message-----
From: Ian Campbell
Sent: 26 September 2013 11:17
To: Paul Durrant
Cc: [email protected]; [email protected]; Wei Liu; David Vrabel
Subject: Re: [PATCH net v5 1/1] xen-netback: Handle backend state transitions in a more robust way

Quoted 1 line · Paul Durrant

When the frontend state changes netback now specifies its desired state

to

Quoted 3 lines

a new function, set_backend_state(), which transitions through any necessary intermediate states.
This fixes an issue observed with some old Windows frontend drivers

where

Quoted 2 lines

they failed to transition through the Closing state and netback would not behave correctly.

I'm somewhat terrified of breaking compatibility with some old or obscure frontend here. I don't think it is reasonable to try and test all of those so I guess we'll just have to deal with that when it happens...

Quoted 6 lines
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
Cc David Vrabel <[email protected]>
---
 drivers/net/xen-netback/xenbus.c |  143

++++++++++++++++++++++++++++++--------

drivers/net/xen-

Quoted 3 lines
 1 file changed, 113 insertions(+), 30 deletions(-)
drivers/net/xen- renamed from drivers/net/xen-netback/xenbus.c +0 -0

netback/xenbus.c

Quoted 12 lines

drivers/net/xen-netback/xenbus.c line 27

Quoted 8 lines

index a53782e..01329b2 100644

drivers/net/xen-netback/xenbus.c +1 -0
@@ -24,6 +24,7 @@
 struct backend_info {
 	struct xenbus_device *dev;
 	struct xenvif *vif;
+	enum xenbus_state state;

This cannot just be read from xenstore because of the wait-for-hotplug-script deferral stuff, right?

Yes, that's right.

Quoted 7 lines
Quoted 3 lines

I'm not sure it is worth clarifying that, either by a comment or by naming it deferred_state_change or something?

It’s the xenbus state that's deferred, the backend state leads so I could name it 'desired_state' or 'target_state' perhaps; probably a bit ugly so I'll add a comment above that field I think.

OK.

Quoted 39 lines
Quoted 9 lines
Quoted 9 lines
drivers/net/xen-netback/xenbus.c +4 -2
-static void destroy_backend(struct xenbus_device *dev)
+static void backend_connect(struct backend_info *be)
 {
-	struct backend_info *be = dev_get_drvdata(&dev->dev);
+	if (be->vif)
+		connect(be);
+}
Quoted 8 lines

drivers/net/xen-netback/xenbus.c static void backend_create_xenvif(struct backend_info *be) · line 228

Quoted 5 lines
drivers/net/xen-netback/xenbus.c +0 -5
-	if (be->vif) {
-		kobject_uevent(&dev->dev.kobj, KOBJ_OFFLINE);
-		xenbus_rm(XBT_NIL, dev->nodename, "hotplug-status");
-		xenvif_free(be->vif);
-		be->vif = NULL;

Where did this uevent offlining functionality end up?

It's done in netback_remove() .

Quoted 15 lines

drivers/net/xen-netback/xenbus.c static void backend_create_xenvif(struct backend_info *be) · line 235

Quoted 10 lines
drivers/net/xen-netback/xenbus.c +10 -0
+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.

Is the right/wise regardless of the state we are moving too? Might the state change have effectively "cancelled" the need to wait for the script?

Quoted 3 lines

The previous code only deferred when moving to Connected. If we are now moving to Closed/Closing do we still need to wait?

Quoted 8 lines

I debated about this; we never really dealt with this before. I think it's legitimate for the frontend to give up waiting for a backend hotplug so we should be able to go from InitWait to Closing, so in this case be->state will be Closing when the script (hopefully) finishes. Thus we move to that when the watch fires rather than to Connected. Then the frontend can move to Closed. If the hotplug script never finishes then I don't think we're any more screwed than we were before.

OK.