From 51f0d529cfd713d74fb6390263dfd4de520724ca Mon Sep 17 00:00:00 2001 From: Roger Pau Monne Date: Tue, 26 May 2015 16:49:15 +0200 Subject: [PATCH 2/2] xen-blkback: fix error path on failed attach The current error path in case of failure during attach/initialization is not correct and leaves blkback in a stuck state. This is due to blkback waiting for blkfront to switch to state XenbusStateClosed, but if blkfront never attached (because the guest is not even started) it cannot possibly make it to that state. Instead just wait for the frontend to be in a state different than XenbusStateConnected in order to proceed with the shutdown. Also, it is wrong to call xbb_detach directly because it destroys the lock which can still be used by xbb_frontend_changed. Sponsored by: Citrix Systems R&D --- sys/dev/xen/blkback/blkback.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sys/dev/xen/blkback/blkback.c b/sys/dev/xen/blkback/blkback.c index a2efa42..876806a 100644 --- a/sys/dev/xen/blkback/blkback.c +++ b/sys/dev/xen/blkback/blkback.c @@ -172,7 +172,6 @@ struct xbb_xen_req; static void xbb_attach_failed(struct xbb_softc *xbb, int err, const char *fmt, ...) __attribute__((format(printf, 3, 4))); static int xbb_shutdown(struct xbb_softc *xbb); -static int xbb_detach(device_t dev); /*------------------------------ Data Structures -----------------------------*/ @@ -3423,8 +3422,8 @@ xbb_shutdown(struct xbb_softc *xbb) mtx_lock(&xbb->lock); xbb->flags &= ~XBBF_IN_SHUTDOWN; - /* The front can submit I/O until entering the closed state. */ - if (frontState < XenbusStateClosed) + /* Wait for the frontend to disconnect (if it's connected). */ + if (frontState == XenbusStateConnected) return (EAGAIN); DPRINTF("\n"); @@ -3481,7 +3480,9 @@ xbb_attach_failed(struct xbb_softc *xbb, int err, const char *fmt, ...) xs_printf(XST_NIL, xenbus_get_node(xbb->dev), "online", "0"); - xbb_detach(xbb->dev); + mtx_lock(&xbb->lock); + xbb_shutdown(xbb); + mtx_unlock(&xbb->lock); } /*---------------------------- NewBus Entrypoints ----------------------------*/ -- 2.5.4 (Apple Git-61)