Blame SOURCES/kvm-blockdev-Move-parsing-of-media-option-to-drive_init.patch

218e99
From 90321b7139eb0c078f2dffa2d78a121852389e40 Mon Sep 17 00:00:00 2001
218e99
From: Kevin Wolf <kwolf@redhat.com>
218e99
Date: Tue, 5 Nov 2013 14:09:04 +0100
218e99
Subject: [PATCH 51/87] blockdev: Move parsing of 'media' option to drive_init
218e99
218e99
RH-Author: Kevin Wolf <kwolf@redhat.com>
218e99
Message-id: <1383660558-32096-11-git-send-email-kwolf@redhat.com>
218e99
Patchwork-id: 55389
218e99
O-Subject: [RHEL-7.0 qemu-kvm PATCH 10/24] blockdev: Move parsing of 'media' option to drive_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
This moves as much as possible of the processing of the 'media' option
218e99
to drive_init so that it can only be accessed using legacy functions,
218e99
but never with anything blockdev-add related.
218e99
218e99
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
218e99
Reviewed-by: Benoit Canet <benoit@irqsave.net>
218e99
Reviewed-by: Eric Blake <eblake@redhat.com>
218e99
(cherry picked from commit 33cb7dc8b7a26ccdff2f054056d3f2e487cbb4cd)
218e99
218e99
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
218e99
---
218e99
 blockdev.c | 73 ++++++++++++++++++++++++++++++++++++++++++--------------------
218e99
 1 file changed, 50 insertions(+), 23 deletions(-)
218e99
218e99
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
218e99
---
218e99
 blockdev.c |   73 +++++++++++++++++++++++++++++++++++++++++-------------------
218e99
 1 files changed, 50 insertions(+), 23 deletions(-)
218e99
218e99
diff --git a/blockdev.c b/blockdev.c
218e99
index 8dd9fd7..e6d3c15 100644
218e99
--- a/blockdev.c
218e99
+++ b/blockdev.c
218e99
@@ -324,16 +324,18 @@ static bool do_check_io_limits(BlockIOLimit *io_limits, Error **errp)
218e99
     return true;
218e99
 }
218e99
 
218e99
+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 block_default_type)
218e99
+                                BlockInterfaceType block_default_type,
218e99
+                                DriveMediaType media)
218e99
 {
218e99
     const char *buf;
218e99
     const char *file = NULL;
218e99
     const char *serial;
218e99
     const char *mediastr = "";
218e99
     BlockInterfaceType type;
218e99
-    enum { MEDIA_DISK, MEDIA_CDROM } media;
218e99
     int bus_id, unit_id;
218e99
     int cyls, heads, secs, translation;
218e99
     int max_devs;
218e99
@@ -354,7 +356,6 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
218e99
     BlockDriver *drv = NULL;
218e99
 
218e99
     translation = BIOS_ATA_TRANSLATION_AUTO;
218e99
-    media = MEDIA_DISK;
218e99
 
218e99
     /* Check common options by copying from bs_opts to opts, all other options
218e99
      * stay in bs_opts for processing by bdrv_open(). */
218e99
@@ -441,19 +442,11 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
218e99
 	}
218e99
     }
218e99
 
218e99
-    if ((buf = qemu_opt_get(opts, "media")) != NULL) {
218e99
-        if (!strcmp(buf, "disk")) {
218e99
-	    media = MEDIA_DISK;
218e99
-	} else if (!strcmp(buf, "cdrom")) {
218e99
-            if (cyls || secs || heads) {
218e99
-                error_report("CHS can't be set with media=%s", buf);
218e99
-	        return NULL;
218e99
-            }
218e99
-	    media = MEDIA_CDROM;
218e99
-	} else {
218e99
-	    error_report("'%s' invalid media", buf);
218e99
-	    return NULL;
218e99
-	}
218e99
+    if (media == MEDIA_CDROM) {
218e99
+        if (cyls || secs || heads) {
218e99
+            error_report("CHS can't be set with media=cdrom");
218e99
+            return NULL;
218e99
+        }
218e99
     }
218e99
 
218e99
     if ((buf = qemu_opt_get(opts, "discard")) != NULL) {
218e99
@@ -752,11 +745,27 @@ static void qemu_opt_rename(QemuOpts *opts, const char *from, const char *to)
218e99
     }
218e99
 }
218e99
 
218e99
+QemuOptsList qemu_legacy_drive_opts = {
218e99
+    .name = "drive",
218e99
+    .head = QTAILQ_HEAD_INITIALIZER(qemu_legacy_drive_opts.head),
218e99
+    .desc = {
218e99
+        {
218e99
+            .name = "media",
218e99
+            .type = QEMU_OPT_STRING,
218e99
+            .help = "media type (disk, cdrom)",
218e99
+        },
218e99
+        { /* end of list */ }
218e99
+    },
218e99
+};
218e99
+
218e99
 DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
218e99
 {
218e99
     const char *value;
218e99
-    DriveInfo *dinfo;
218e99
+    DriveInfo *dinfo = NULL;
218e99
     QDict *bs_opts;
218e99
+    QemuOpts *legacy_opts;
218e99
+    DriveMediaType media = MEDIA_DISK;
218e99
+    Error *local_err = NULL;
218e99
 
218e99
     /* Change legacy command line options into QMP ones */
218e99
     qemu_opt_rename(all_opts, "iops", "throttling.iops-total");
218e99
@@ -798,8 +807,29 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
218e99
     bs_opts = qdict_new();
218e99
     qemu_opts_to_qdict(all_opts, bs_opts);
218e99
 
218e99
+    legacy_opts = qemu_opts_create_nofail(&qemu_legacy_drive_opts);
218e99
+    qemu_opts_absorb_qdict(legacy_opts, bs_opts, &local_err);
218e99
+    if (error_is_set(&local_err)) {
218e99
+        qerror_report_err(local_err);
218e99
+        error_free(local_err);
218e99
+        goto fail;
218e99
+    }
218e99
+
218e99
+    /* Media type */
218e99
+    value = qemu_opt_get(legacy_opts, "media");
218e99
+    if (value) {
218e99
+        if (!strcmp(value, "disk")) {
218e99
+            media = MEDIA_DISK;
218e99
+        } else if (!strcmp(value, "cdrom")) {
218e99
+            media = MEDIA_CDROM;
218e99
+        } else {
218e99
+            error_report("'%s' invalid media", value);
218e99
+            goto fail;
218e99
+        }
218e99
+    }
218e99
+
218e99
     /* Actual block device init: Functionality shared with blockdev-add */
218e99
-    dinfo = blockdev_init(bs_opts, block_default_type);
218e99
+    dinfo = blockdev_init(bs_opts, block_default_type, media);
218e99
     if (dinfo == NULL) {
218e99
         goto fail;
218e99
     }
218e99
@@ -809,6 +839,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
218e99
     dinfo->opts = all_opts;
218e99
 
218e99
 fail:
218e99
+    qemu_opts_del(legacy_opts);
218e99
     return dinfo;
218e99
 }
218e99
 
218e99
@@ -1705,7 +1736,7 @@ void qmp_blockdev_add(BlockdevOptions *options, Error **errp)
218e99
 
218e99
     qdict_flatten(qdict);
218e99
 
218e99
-    dinfo = blockdev_init(qdict, IF_NONE);
218e99
+    dinfo = blockdev_init(qdict, IF_NONE, MEDIA_DISK);
218e99
     if (!dinfo) {
218e99
         error_setg(errp, "Could not open image");
218e99
         goto fail;
218e99
@@ -1774,10 +1805,6 @@ QemuOptsList qemu_common_drive_opts = {
218e99
             .type = QEMU_OPT_STRING,
218e99
             .help = "chs translation (auto, lba. none)",
218e99
         },{
218e99
-            .name = "media",
218e99
-            .type = QEMU_OPT_STRING,
218e99
-            .help = "media type (disk, cdrom)",
218e99
-        },{
218e99
             .name = "snapshot",
218e99
             .type = QEMU_OPT_BOOL,
218e99
             .help = "enable/disable snapshot mode",
218e99
-- 
218e99
1.7.1
218e99