diff options
-rw-r--r-- | sys/dev/xen/blkback/blkback.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/sys/dev/xen/blkback/blkback.c b/sys/dev/xen/blkback/blkback.c index 9c9735e..98d07b5 100644 --- a/sys/dev/xen/blkback/blkback.c +++ b/sys/dev/xen/blkback/blkback.c @@ -804,6 +804,9 @@ struct xbb_softc { /** Watch to wait for hotplug script execution */ struct xs_watch hotplug_watch; + + /** Got the needed data from hotplug scripts? */ + bool hotplug_done; }; /*---------------------------- Request Processing ----------------------------*/ @@ -3308,10 +3311,9 @@ xbb_connect(struct xbb_softc *xbb) { int error; - if (xenbus_get_state(xbb->dev) != XenbusStateInitialised) - return; - - if (xbb_collect_frontend_info(xbb) != 0) + if (!xbb->hotplug_done || + (xenbus_get_state(xbb->dev) != XenbusStateInitWait) || + (xbb_collect_frontend_info(xbb) != 0)) return; xbb->flags &= ~XBBF_SHUTDOWN; @@ -3410,6 +3412,7 @@ xbb_shutdown(struct xbb_softc *xbb) free(xbb->hotplug_watch.node, M_XENBLOCKBACK); xbb->hotplug_watch.node = NULL; } + xbb->hotplug_done = false; if (xenbus_get_state(xbb->dev) < XenbusStateClosing) xenbus_set_state(xbb->dev, XenbusStateClosing); @@ -3690,8 +3693,11 @@ xbb_attach_disk(struct xs_watch *watch, const char **vec, unsigned int len) return; } - /* Tell the front end that we are ready to connect. */ - xenbus_set_state(dev, XenbusStateInitialised); + xbb->hotplug_done = true; + + /* The front end might be waiting for the backend, attach if so. */ + if (xenbus_get_otherend_state(xbb->dev) == XenbusStateInitialised) + xbb_connect(xbb); } /** @@ -3755,6 +3761,7 @@ xbb_attach(device_t dev) * We need to wait for hotplug script execution before * moving forward. */ + KASSERT(!xbb->hotplug_done, ("Hotplug scripts already executed")); watch_path = xs_join(xenbus_get_node(xbb->dev), "physical-device-path"); xbb->hotplug_watch.callback_data = (uintptr_t)dev; xbb->hotplug_watch.callback = xbb_attach_disk; |