Received: from [140.186.70.92] (port=45467 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OTcHO-0005y1-Pk for qemu-devel@nongnu.org; Tue, 29 Jun 2010 10:59:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OTcHE-0003B6-FE for qemu-devel@nongnu.org; Tue, 29 Jun 2010 10:59:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:25573) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OTcHE-0003At-6S for qemu-devel@nongnu.org; Tue, 29 Jun 2010 10:59:08 -0400 From: Markus Armbruster References: <1277484812-22012-1-git-send-email-armbru@redhat.com> <1277484812-22012-9-git-send-email-armbru@redhat.com> <4C29F608.5000104@redhat.com> Date: Tue, 29 Jun 2010 16:29:29 +0200 In-Reply-To: <4C29F608.5000104@redhat.com> (Kevin Wolf's message of "Tue, 29 Jun 2010 15:32:56 +0200") Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Subject: [Qemu-devel] Re: [PATCH 08/12] block: Catch attempt to attach multiple devices to a blockdev List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf Cc: hch@lst.de, qemu-devel@nongnu.org, kraxel@redhat.com Kevin Wolf writes: > Am 25.06.2010 18:53, schrieb Markus Armbruster: >> For instance, -device scsi-disk,drive=foo -device scsi-disk,drive=foo >> happily creates two SCSI disks connected to the same block device. >> It's all downhill from there. >> >> Device usb-storage deliberately attaches twice to the same blockdev, >> which fails with the fix in place. Detach before the second attach >> there. >> >> Also catch attempt to delete while a guest device model is attached. [...] >> diff --git a/hw/pci-hotplug.c b/hw/pci-hotplug.c >> index d743192..b47e01e 100644 >> --- a/hw/pci-hotplug.c >> +++ b/hw/pci-hotplug.c >> @@ -214,7 +214,10 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon, >> return NULL; >> } >> dev = pci_create(bus, devfn, "virtio-blk-pci"); >> - qdev_prop_set_drive(&dev->qdev, "drive", dinfo->bdrv); >> + if (qdev_prop_set_drive(&dev->qdev, "drive", dinfo->bdrv) < 0) { >> + dev = NULL; >> + break; >> + } > > I think in error cases we'll leak dev. Correct. >> if (qdev_init(&dev->qdev) < 0) >> dev = NULL; >> break; [...] >> diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c >> index 2c58aca..9678328 100644 >> --- a/hw/scsi-bus.c >> +++ b/hw/scsi-bus.c >> @@ -91,7 +91,9 @@ SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv, int >> driver = bdrv_is_sg(bdrv) ? "scsi-generic" : "scsi-disk"; >> dev = qdev_create(&bus->qbus, driver); >> qdev_prop_set_uint32(dev, "scsi-id", unit); >> - qdev_prop_set_drive(dev, "drive", bdrv); >> + if (qdev_prop_set_drive(dev, "drive", bdrv) < 0) { >> + return NULL; >> + } > > As we do here. Yes. >> if (qdev_init(dev) < 0) >> return NULL; >> return DO_UPCAST(SCSIDevice, qdev, dev); >> diff --git a/hw/usb-msd.c b/hw/usb-msd.c >> index 19a14b4..008cc0f 100644 >> --- a/hw/usb-msd.c >> +++ b/hw/usb-msd.c >> @@ -532,12 +532,13 @@ static int usb_msd_initfn(USBDevice *dev) >> /* >> * Hack alert: this pretends to be a block device, but it's really >> * a SCSI bus that can serve only a single device, which it >> - * creates automatically. Two drive properties pointing to the >> - * same drive is not good: free_drive() dies for the second one. >> - * Zap the one we're not going to use. >> + * creates automatically. But first it needs to detach from its >> + * blockdev, or else scsi_bus_legacy_add_drive() dies when it >> + * attaches again. >> * >> * The hack is probably a bad idea. >> */ >> + bdrv_detach(bs, &s->dev.qdev); >> s->conf.bs = NULL; >> >> s->dev.speed = USB_SPEED_FULL; >> @@ -609,7 +610,9 @@ static USBDevice *usb_msd_init(const char *filename) >> if (!dev) { >> return NULL; >> } >> - qdev_prop_set_drive(&dev->qdev, "drive", dinfo->bdrv); >> + if (qdev_prop_set_drive(&dev->qdev, "drive", dinfo->bdrv) < 0) { >> + return NULL; >> + } >> if (qdev_init(&dev->qdev) < 0) >> return NULL; > > And here. Yes. I double-checked the entire patch series, and could not find further leaks. Thanks a lot!