9ae3a8
From 0c82774abd19c0f11b5cca29be188176d6f447ef Mon Sep 17 00:00:00 2001
9ae3a8
From: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Date: Tue, 5 Nov 2013 14:09:12 +0100
9ae3a8
Subject: [PATCH 59/87] blockdev: Remove 'media' parameter from blockdev_init()
9ae3a8
9ae3a8
RH-Author: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Message-id: <1383660558-32096-19-git-send-email-kwolf@redhat.com>
9ae3a8
Patchwork-id: 55396
9ae3a8
O-Subject: [RHEL-7.0 qemu-kvm PATCH 18/24] blockdev: Remove 'media' parameter from blockdev_init()
9ae3a8
Bugzilla: 978402
9ae3a8
RH-Acked-by: Fam Zheng <famz@redhat.com>
9ae3a8
RH-Acked-by: Max Reitz <mreitz@redhat.com>
9ae3a8
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
9ae3a8
9ae3a8
The remaining users shouldn't be there with blockdev-add and are easy to
9ae3a8
move to drive_init().
9ae3a8
9ae3a8
Bonus bug fix: As a side effect, CD-ROM drives can now use block drivers
9ae3a8
on the read-only whitelist without explicitly specifying read-only=on,
9ae3a8
even if a format is explicitly specified.
9ae3a8
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Reviewed-by: Max Reitz <mreitz@redhat.com>
9ae3a8
Reviewed-by: Eric Blake <eblake@redhat.com>
9ae3a8
(cherry picked from commit e34ef046412431acf5b4e30762390b4048187bb8)
9ae3a8
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
---
9ae3a8
 blockdev.c | 40 +++++++++++++++-------------------------
9ae3a8
 1 file changed, 15 insertions(+), 25 deletions(-)
9ae3a8
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 blockdev.c |   40 +++++++++++++++-------------------------
9ae3a8
 1 files changed, 15 insertions(+), 25 deletions(-)
9ae3a8
9ae3a8
diff --git a/blockdev.c b/blockdev.c
9ae3a8
index 680ba22..d4b18c5 100644
9ae3a8
--- a/blockdev.c
9ae3a8
+++ b/blockdev.c
9ae3a8
@@ -328,8 +328,7 @@ typedef enum { MEDIA_DISK, MEDIA_CDROM } DriveMediaType;
9ae3a8
 
9ae3a8
 /* Takes the ownership of bs_opts */
9ae3a8
 static DriveInfo *blockdev_init(QDict *bs_opts,
9ae3a8
-                                BlockInterfaceType type,
9ae3a8
-                                DriveMediaType media)
9ae3a8
+                                BlockInterfaceType type)
9ae3a8
 {
9ae3a8
     const char *buf;
9ae3a8
     const char *file = NULL;
9ae3a8
@@ -489,22 +488,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
9ae3a8
     /* disk I/O throttling */
9ae3a8
     bdrv_set_io_limits(dinfo->bdrv, &io_limits);
9ae3a8
 
9ae3a8
-    switch(type) {
9ae3a8
-    case IF_IDE:
9ae3a8
-    case IF_SCSI:
9ae3a8
-    case IF_XEN:
9ae3a8
-    case IF_NONE:
9ae3a8
-        dinfo->media_cd = media == MEDIA_CDROM;
9ae3a8
-        break;
9ae3a8
-    case IF_SD:
9ae3a8
-    case IF_FLOPPY:
9ae3a8
-    case IF_PFLASH:
9ae3a8
-    case IF_MTD:
9ae3a8
-    case IF_VIRTIO:
9ae3a8
-        break;
9ae3a8
-    default:
9ae3a8
-        abort();
9ae3a8
-    }
9ae3a8
     if (!file || !*file) {
9ae3a8
         if (has_driver_specific_opts) {
9ae3a8
             file = NULL;
9ae3a8
@@ -526,11 +509,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
9ae3a8
         bdrv_flags |= BDRV_O_INCOMING;
9ae3a8
     }
9ae3a8
 
9ae3a8
-    if (media == MEDIA_CDROM) {
9ae3a8
-        /* CDROM is fine for any interface, don't check.  */
9ae3a8
-        ro = 1;
9ae3a8
-    }
9ae3a8
-
9ae3a8
     bdrv_flags |= ro ? 0 : BDRV_O_RDWR;
9ae3a8
 
9ae3a8
     if (ro && copy_on_read) {
9ae3a8
@@ -703,6 +681,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
9ae3a8
             media = MEDIA_DISK;
9ae3a8
         } else if (!strcmp(value, "cdrom")) {
9ae3a8
             media = MEDIA_CDROM;
9ae3a8
+            qdict_put(bs_opts, "read-only", qstring_from_str("on"));
9ae3a8
         } else {
9ae3a8
             error_report("'%s' invalid media", value);
9ae3a8
             goto fail;
9ae3a8
@@ -850,7 +829,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
9ae3a8
     }
9ae3a8
 
9ae3a8
     /* Actual block device init: Functionality shared with blockdev-add */
9ae3a8
-    dinfo = blockdev_init(bs_opts, type, media);
9ae3a8
+    dinfo = blockdev_init(bs_opts, type);
9ae3a8
     if (dinfo == NULL) {
9ae3a8
         goto fail;
9ae3a8
     }
9ae3a8
@@ -868,6 +847,17 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
9ae3a8
     dinfo->unit = unit_id;
9ae3a8
     dinfo->devaddr = devaddr;
9ae3a8
 
9ae3a8
+    switch(type) {
9ae3a8
+    case IF_IDE:
9ae3a8
+    case IF_SCSI:
9ae3a8
+    case IF_XEN:
9ae3a8
+    case IF_NONE:
9ae3a8
+        dinfo->media_cd = media == MEDIA_CDROM;
9ae3a8
+        break;
9ae3a8
+    default:
9ae3a8
+        break;
9ae3a8
+    }
9ae3a8
+
9ae3a8
 fail:
9ae3a8
     qemu_opts_del(legacy_opts);
9ae3a8
     return dinfo;
9ae3a8
@@ -1766,7 +1756,7 @@ void qmp_blockdev_add(BlockdevOptions *options, Error **errp)
9ae3a8
 
9ae3a8
     qdict_flatten(qdict);
9ae3a8
 
9ae3a8
-    dinfo = blockdev_init(qdict, IF_NONE, MEDIA_DISK);
9ae3a8
+    dinfo = blockdev_init(qdict, IF_NONE);
9ae3a8
     if (!dinfo) {
9ae3a8
         error_setg(errp, "Could not open image");
9ae3a8
         goto fail;
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8