Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752468AbdGDQ7d (ORCPT ); Tue, 4 Jul 2017 12:59:33 -0400 Received: from smtp.ctxuk.citrix.com ([185.25.65.24]:30330 "EHLO SMTP.EU.CITRIX.COM" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752374AbdGDQ7c (ORCPT ); Tue, 4 Jul 2017 12:59:32 -0400 X-IronPort-AV: E=Sophos;i="5.40,309,1496102400"; d="scan'208";a="48815022" Date: Tue, 4 Jul 2017 17:59:27 +0100 From: Roger Pau =?iso-8859-1?Q?Monn=E9?= To: Vincent Legout CC: Boris Ostrovsky , Juergen Gross , Konrad Rzeszutek Wilk , , Subject: Re: [PATCH] xen-blkfront: emit KOBJ_OFFLINE uevent when detaching device Message-ID: <20170704165927.c6dgitftm4v3xk7w@dhcp-3-128.uk.xensource.com> References: <20170704114823.pvk6323gfebioikl@bres.gandi.net> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20170704114823.pvk6323gfebioikl@bres.gandi.net> User-Agent: NeoMutt/20170609 (1.8.3) X-ClientProxiedBy: AMSPEX02CAS01.citrite.net (10.69.22.112) To AMSPEX02CL03.citrite.net (10.69.22.127) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2647 Lines: 63 On Tue, Jul 04, 2017 at 01:48:32PM +0200, Vincent Legout wrote: > Devices are not unmounted inside a domU after a xl block-detach. > > After xl block-detach, blkfront_closing() is called with state == > XenbusStateConnected, it detects that the device is still in use and > only switches state to XenbusStateClosing. blkfront_closing() is called > a second time but returns immediately because state == > XenbusStateClosing. Thus the device keeps being mounted inside the domU. > > To fix this, emit a KOBJ_OFFLINE uevent even if the device has users. > > With this patch, inside domU, udev has: > > KERNEL[16994.526789] offline /devices/vbd-51728/block/xvdb (block) > KERNEL[16994.796197] remove /devices/virtual/bdi/202:16 (bdi) > KERNEL[16994.797167] remove /devices/vbd-51728/block/xvdb (block) > UDEV [16994.798035] remove /devices/virtual/bdi/202:16 (bdi) > UDEV [16994.809429] offline /devices/vbd-51728/block/xvdb (block) > UDEV [16994.842365] remove /devices/vbd-51728/block/xvdb (block) > KERNEL[16995.461991] remove /devices/vbd-51728 (xen) > UDEV [16995.462549] remove /devices/vbd-51728 (xen) I'm not an expect on udev, but aren't those messages duplicated? You seem to get one message from udev and another one from the kernel. > While without, it had: > > KERNEL[30.862764] remove /devices/vbd-51728 (xen) > UDEV [30.867838] remove /devices/vbd-51728 (xen) > > Signed-off-by: Pascal Bouchareine > Signed-off-by: Fatih Acar > Signed-off-by: Vincent Legout > > drivers/block/xen-blkfront.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c > index 39459631667c..da0b0444ee1f 100644 > --- a/drivers/block/xen-blkfront.c > +++ b/drivers/block/xen-blkfront.c > @@ -2185,8 +2185,10 @@ static void blkfront_closing(struct blkfront_info *info) > mutex_lock(&bdev->bd_mutex); > > if (bdev->bd_openers) { > - xenbus_dev_error(xbdev, -EBUSY, > - "Device in use; refusing to close"); > + dev_warn(disk_to_dev(info->gd), > + "detaching %s with pending users\n", > + xbdev->nodename); > + kobject_uevent(&disk_to_dev(info->gd)->kobj, KOBJ_OFFLINE); What happens if you simply remove the xenbus_dev_error but don't add the kobject_uevent? I'm asking because I don't see any other block device calling directly kobject_uevent, and I'm sure this should be pretty similar to what virtio or USB do when a block device is hot-unplugged. For example blk_unregister_queue already contains a call to trigger a kobject_uevent. Thanks, Roger.