From 18846dee1a795b4345ac0bd10b70a3a46fd14287 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Tue, 29 Jun 2010 16:58:30 +0200 Subject: block: Catch attempt to attach multiple devices to a blockdev 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. Signed-off-by: Markus Armbruster Signed-off-by: Kevin Wolf --- hw/scsi-bus.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'hw/scsi-bus.c') diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c index 2c58aca..b84b9b9 100644 --- a/hw/scsi-bus.c +++ b/hw/scsi-bus.c @@ -91,7 +91,10 @@ 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) { + qdev_free(dev); + return NULL; + } if (qdev_init(dev) < 0) return NULL; return DO_UPCAST(SCSIDevice, qdev, dev); -- cgit v1.1