From e5d27b37e39b4478c8df094a6ef50272f0c84988 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Date: Fri, 19 May 2017 08:11:15 +0000 Subject: [PATCH] xen/blkfront: correctly detach a disk with active users Call disk_gone when the backend switches to the "Closing" state and blkfront still has pending users. This allows the disk to be detached, and will call into xbd_closing by itself when the geom layout cleanup has finished. Reported by: bapt Tested by: manu Reviewed by: bapt Sponsored by: Citrix Systems R&D MFC after: 1 week Differential revision: https://reviews.freebsd.org/D10772 --- sys/dev/xen/blkfront/blkfront.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/sys/dev/xen/blkfront/blkfront.c b/sys/dev/xen/blkfront/blkfront.c index d76fc01a4bd..3473b64f8e8 100644 --- a/sys/dev/xen/blkfront/blkfront.c +++ b/sys/dev/xen/blkfront/blkfront.c @@ -1578,11 +1578,14 @@ xbd_backend_changed(device_t dev, XenbusState backend_state) break; case XenbusStateClosing: - if (sc->xbd_users > 0) - xenbus_dev_error(dev, -EBUSY, - "Device in use; refusing to close"); - else + if (sc->xbd_users > 0) { + device_printf(dev, "detaching with pending users\n"); + KASSERT(sc->xbd_disk != NULL, + ("NULL disk with pending users\n")); + disk_gone(sc->xbd_disk); + } else { xbd_closing(dev); + } break; } }