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
This commit is contained in:
Roger Pau Monné 2016-06-03 11:39:35 +00:00
parent de0bad0001
commit 3e0522bc8f

View File

@ -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 -----------------------------*/
@ -3419,8 +3418,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");
@ -3477,7 +3476,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 ----------------------------*/