]> git.proxmox.com Git - qemu.git/commitdiff
ide scsi virtio-blk: Reject empty drives unless media is removable
authorMarkus Armbruster <armbru@redhat.com>
Tue, 6 Jul 2010 12:37:44 +0000 (14:37 +0200)
committerKevin Wolf <kwolf@redhat.com>
Tue, 13 Jul 2010 15:48:17 +0000 (17:48 +0200)
Disks without media make no sense.  For SCSI, a Linux guest kernel
complains during boot.  I didn't try other combinations.

scsi-generic doesn't need the additional check, because it already
requires bdrv_is_sg(), which fails without media.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
hw/ide/core.c
hw/scsi-disk.c
hw/virtio-blk.c

index af52c2cb2dd89cf80a36cc51d4a833e9cb112c4f..e20f2e7cbb50cb22a9143953b1be7585275468d7 100644 (file)
@@ -2630,6 +2630,10 @@ int ide_init_drive(IDEState *s, BlockDriverState *bs,
         s->drive_kind = IDE_CD;
         bdrv_set_change_cb(bs, cdrom_change_cb, s);
     } else {
+        if (!bdrv_is_inserted(s->bs)) {
+            error_report("Device needs media, but drive is empty");
+            return -1;
+        }
         if (bdrv_is_read_only(bs)) {
             error_report("Can't use a read-only drive");
             return -1;
index c30709c5506cbafeba6eb028ac82b5df9a050b46..f43f2d097cceff9f6640e3e3be2f9662854de4f7 100644 (file)
@@ -1059,6 +1059,11 @@ static int scsi_disk_initfn(SCSIDevice *dev)
     s->bs = s->qdev.conf.bs;
     is_cd = bdrv_get_type_hint(s->bs) == BDRV_TYPE_CDROM;
 
+    if (!is_cd && !bdrv_is_inserted(s->bs)) {
+        error_report("Device needs media, but drive is empty");
+        return -1;
+    }
+
     if (bdrv_get_on_error(s->bs, 1) != BLOCK_ERR_REPORT) {
         error_report("Device doesn't support drive option rerror");
         return -1;
index 99e9dd294be8952b86847c61a364dda2020fd26b..f50069d20b05d521a8102115140b8dd95098b284 100644 (file)
@@ -495,6 +495,10 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf)
         error_report("virtio-blk-pci: drive property not set");
         return NULL;
     }
+    if (!bdrv_is_inserted(conf->bs)) {
+        error_report("Device needs media, but drive is empty");
+        return NULL;
+    }
 
     s = (VirtIOBlock *)virtio_common_init("virtio-blk", VIRTIO_ID_BLOCK,
                                           sizeof(struct virtio_blk_config),