From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40221) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XSt3r-00024Z-7B for qemu-devel@nongnu.org; Sat, 13 Sep 2014 15:32:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XSt3k-0008BL-VT for qemu-devel@nongnu.org; Sat, 13 Sep 2014 15:32:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51133) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XSt3k-0008BB-Nl for qemu-devel@nongnu.org; Sat, 13 Sep 2014 15:32:36 -0400 Message-ID: <54149BCA.9090808@redhat.com> Date: Sat, 13 Sep 2014 21:32:26 +0200 From: Max Reitz MIME-Version: 1.0 References: <1410549984-16110-1-git-send-email-armbru@redhat.com> <1410549984-16110-3-git-send-email-armbru@redhat.com> In-Reply-To: <1410549984-16110-3-git-send-email-armbru@redhat.com> Content-Type: text/plain; charset=iso-8859-15; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 2/4] block: Keep DriveInfo alive until BlockDriverState dies List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster , qemu-devel@nongnu.org Cc: kwolf@redhat.com, benoit.canet@irqsave.net, stefanha@redhat.com On 12.09.2014 21:26, Markus Armbruster wrote: > If the BDS's refcnt > 0, drive_del() destroys the DriveInfo, but not > the BDS. This can happen in three places: > > * Device model destruction during unplug: blockdev_auto_del() > > * Xen IDE unplug: pci_piix3_xen_ide_unplug() > > * drive_del command when no device model is attached: do_drive_del() > > The other callers of drive_del are on error paths where refcnt == 1. > > If the user somehow manages to plug in a device model using a BDS that > has gone through drive_del(), the legacy configuration passed in > DriveInfo doesn't reach the device model, and automatic deletion on > unplug doesn't work. Worse, some device models such as scsi-disk > crash when DriveInfo doesn't exist. > > This is theoretical; I didn't research an actual reproducer. > > Fix by keeping DriveInfo alive until its BDS dies. > > This affects qemu_drive_opts: now you can't reuse the same ID for new > drive options until the BDS dies. Before, you could, but since the > code always attempts to create a BDS with the same ID next, the > enclosing operation "create a new drive" failed anyway. Different > error path, same result. > > Unfortunately, the fix involves use of blockdev.c stuff from block.c, > which is a layering violation. Fortunately, my forthcoming > BlockBackend work will get rid of it again. > > Signed-off-by: Markus Armbruster > --- > block.c | 2 ++ > blockdev.c | 13 ++++++++----- > include/sysemu/blockdev.h | 1 + > stubs/Makefile.objs | 1 + > stubs/blockdev.c | 12 ++++++++++++ > 5 files changed, 24 insertions(+), 5 deletions(-) > create mode 100644 stubs/blockdev.c Seems reasonable. Reviewed-by: Max Reitz