cryptospore / rpms / qemu-kvm

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