xen: fix xen-bus state model to allow frontend re-connection
PATCH 1/1 xen: fix xen-bus state model to allow frontend re-connection
There is a flaw in the xen-bus state model. To allow a frontend to re- connect the backend state of an online XenDevice is transitioned from Closed to InitWait, but this is currently done unilaterally which is incorrect. The backend state should remain Closed until the frontend state transitions to Initialising.
This patch removes the automatic backend state transition from xen_device_backend_state_changed() and, instead, adds an extra check in xen_device_frontend_state_changed() to determine whether a frontend is trying to re-connect to a previously Closed XenDevice. Only if this is found to be the case is the backend state transitioned from Closed to InitWait. Note that this transition will be common amongst all XenDevice classes and hence xen_device_frontend_state_changed() returns immediately afterwards without calling into the XenDeviceClass frontend_changed() method.
---
Cc: Stefano Stabellini <[email protected]>
Cc: Anthony Perard <[email protected]>
--- hw/xen/xen-bus.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-)
hw/xen/xen-bus.c +15 -12
@@ -547,20 +547,12 @@ static void xen_device_backend_changed(void *opaque) }/* -* If a backend is still 'online' then its state should be cycled -* back round to InitWait in order for a new frontend instance to -* connect. This may happen when, for example, a frontend driver is -* re-installed or updated. -* If a backend is not 'online' then the device should be destroyed. +* If a backend is still 'online' then we should leave it alone but, +* if a backend is not 'online', then the device should be destroyed +* once the state is Closed. */ -if (xendev->backend_online && +if (!xendev->backend_online && xendev->backend_state == XenbusStateClosed) { -xen_device_backend_set_state (xendev, XenbusStateInitWait); - }else if (!xendev->backend_online && - (xendev->backend_state == XenbusStateClosed || - xendev->backend_state == XenbusStateInitialising || - xendev->backend_state == XenbusStateInitWait || - xendev->backend_state == XenbusStateUnknown)) {Error *local_err =NULL ;if (!xen_backend_try_device_destroy (xendev, &local_err)) {
@@ -715,6 +707,17 @@ static void xen_device_frontend_changed(void *opaque)xen_device_frontend_set_state (xendev, state); +if (state == XenbusStateInitialising && + xendev->backend_state == XenbusStateClosed && + xendev->backend_online) { +/* +* The frontend is re-initializing so switch back to +* InitWait. +*/ +xen_device_backend_set_state (xendev, XenbusStateInitWait); +return ; + } +if (xendev_class->frontend_changed) {Error *local_err =NULL ;
Signature · 7 lines
2.20.1.2.gb21ebb6 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 25 lines
-----Original Message-----
From: Paul Durrant [mailto:[email protected]]
Sent: 22 January 2019 14:40
To: [email protected]; [email protected]
Cc: Paul Durrant <[email protected]>; Stefano Stabellini <[email protected]>; Anthony Perard <[email protected]>
Subject: [PATCH] xen: fix xen-bus state model to allow frontend re- connectionThere is a flaw in the xen-bus state model. To allow a frontend to re- connect the backend state of an online XenDevice is transitioned from Closed to InitWait, but this is currently done unilaterally which is incorrect. The backend state should remain Closed until the frontend state transitions to Initialising.
This patch removes the automatic backend state transition from
xen_device_backend_state_changed()and, instead, adds an extra check inxen_device_frontend_state_changed()to determine whether a frontend is trying to re-connect to a previously Closed XenDevice. Only if this is found to be the case is the backend state transitioned from Closed to InitWait. Note that this transition will be common amongst all XenDevice classes and hencexen_device_frontend_state_changed()returns immediately afterwards without calling into the XenDeviceClassfrontend_changed()method.
Quoted 1 line
Signed-off-by Paul Durrant <[email protected]>
Unfortunately this is still not quite right. Further testing has now shown that xl block-detach is no longer working properly. I'll send a v2 once that is fixed.
Paul
Quoted 55 lines
---
Cc: Stefano Stabellini <[email protected]>
Cc: Anthony Perard <[email protected]>--- hw/xen/xen-bus.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-)hw/xen/xen-bus.c +15
-13@@ -547,20 +547,12 @@ static void xen_device_backend_changed(void *opaque) }/* -* If a backend is still 'online' then its state should be cycled -* back round to InitWait in order for a new frontend instance to -* connect. This may happen when, for example, a frontend driver is -* re-installed or updated. -* If a backend is not 'online' then the device should be destroyed. +* If a backend is still 'online' then we should leave it alone but, +* if a backend is not 'online', then the device should be destroyed +* once the state is Closed. */ -if (xendev->backend_online && +if (!xendev->backend_online && xendev->backend_state == XenbusStateClosed) { -xen_device_backend_set_state (xendev, XenbusStateInitWait); - }else if (!xendev->backend_online && - (xendev->backend_state == XenbusStateClosed || - xendev->backend_state == XenbusStateInitialising || - xendev->backend_state == XenbusStateInitWait || - xendev->backend_state == XenbusStateUnknown)) {Error *local_err =NULL ;if (!xen_backend_try_device_destroy (xendev, &local_err)) {@@ -715,6 +707,17 @@ static void xen_device_frontend_changed(void *opaque)xen_device_frontend_set_state (xendev, state); +if (state == XenbusStateInitialising && + xendev->backend_state == XenbusStateClosed && + xendev->backend_online) { +/* +* The frontend is re-initializing so switch back to +* InitWait. +*/ +xen_device_backend_set_state (xendev, XenbusStateInitWait); +return ; + } +if (xendev_class->frontend_changed) {Error *local_err =NULL ; --
Quoted 1 line
2.20.1.2.gb21ebb6
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel