aboutsummaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2017-07-11 14:04:08 +0200
committerKevin Wolf <kwolf@redhat.com>2017-07-18 15:14:36 +0200
commit83b4fe0ed5c27dfe181c7c746456ba33e4f7ef2b (patch)
tree8e108282a66ad4f35d8cba7c73738303046534c0 /hw
parent947231ad3b479de82d8f5ec185e2d00f3c96edcd (diff)
downloadqemu-83b4fe0ed5c27dfe181c7c746456ba33e4f7ef2b.zip
qemu-83b4fe0ed5c27dfe181c7c746456ba33e4f7ef2b.tar.gz
qemu-83b4fe0ed5c27dfe181c7c746456ba33e4f7ef2b.tar.bz2
scsi-disk: bdrv_attach_dev() for empty CD-ROM
If no drive=... option is passed (for an empty drive), we don't only lack the BlockBackend normally created by parse_drive(), but we also need to manually call blk_attach_dev(). This fixes at least a segfault when unplugging such devices, the bug that they didn't show up in query-block, and probably some more problems. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: John Snow <jsnow@redhat.com>
Diffstat (limited to 'hw')
-rw-r--r--hw/scsi/scsi-disk.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
index a53f058..5f1e5e8 100644
--- a/hw/scsi/scsi-disk.c
+++ b/hw/scsi/scsi-disk.c
@@ -2384,9 +2384,14 @@ static void scsi_hd_realize(SCSIDevice *dev, Error **errp)
static void scsi_cd_realize(SCSIDevice *dev, Error **errp)
{
SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev);
+ int ret;
if (!dev->conf.blk) {
+ /* Anonymous BlockBackend for an empty drive. As we put it into
+ * dev->conf, qdev takes care of detaching on unplug. */
dev->conf.blk = blk_new(0, BLK_PERM_ALL);
+ ret = blk_attach_dev(dev->conf.blk, &dev->qdev);
+ assert(ret == 0);
}
s->qdev.blocksize = 2048;