cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
218e99
From 615669f863855880e3adfcc8046e34cdc6d7e8d6 Mon Sep 17 00:00:00 2001
218e99
From: Kevin Wolf <kwolf@redhat.com>
218e99
Date: Tue, 5 Nov 2013 14:09:03 +0100
218e99
Subject: [PATCH 50/87] blockdev: Pass QDict to blockdev_init()
218e99
218e99
RH-Author: Kevin Wolf <kwolf@redhat.com>
218e99
Message-id: <1383660558-32096-10-git-send-email-kwolf@redhat.com>
218e99
Patchwork-id: 55388
218e99
O-Subject: [RHEL-7.0 qemu-kvm PATCH 09/24] blockdev: Pass QDict to blockdev_init()
218e99
Bugzilla: 978402
218e99
RH-Acked-by: Fam Zheng <famz@redhat.com>
218e99
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
218e99
RH-Acked-by: Max Reitz <mreitz@redhat.com>
218e99
218e99
Working on a QDict instead of a QemuOpts that accepts anything is more
218e99
in line with bdrv_open(). A QDict is what qmp_blockdev_add() already has
218e99
anyway, so this saves additional conversions. And last, but not least,
218e99
it allows later patches to easily extract legacy options into a
218e99
separate, typed QemuOpts for drive_init() (the untyped QemuOpts that
218e99
drive_init already has doesn't allow access to numbers, only strings,
218e99
and is therefore useless without conversion).
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 f298d071662af6cf5dc221ee3e3bd0154035e570)
218e99
218e99
Conflicts:
218e99
	blockdev.c
218e99
218e99
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
218e99
---
218e99
 blockdev.c | 34 +++++++++++++++++-----------------
218e99
 1 file changed, 17 insertions(+), 17 deletions(-)
218e99
218e99
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
218e99
---
218e99
 blockdev.c |   34 +++++++++++++++++-----------------
218e99
 1 files changed, 17 insertions(+), 17 deletions(-)
218e99
218e99
diff --git a/blockdev.c b/blockdev.c
218e99
index 03ee554..8dd9fd7 100644
218e99
--- a/blockdev.c
218e99
+++ b/blockdev.c
218e99
@@ -217,7 +217,10 @@ static void bdrv_format_print(void *opaque, const char *name)
218e99
 
218e99
 static void drive_uninit(DriveInfo *dinfo)
218e99
 {
218e99
-    qemu_opts_del(dinfo->opts);
218e99
+    if (dinfo->opts) {
218e99
+        qemu_opts_del(dinfo->opts);
218e99
+    }
218e99
+
218e99
     bdrv_delete(dinfo->bdrv);
218e99
     g_free(dinfo->id);
218e99
     QTAILQ_REMOVE(&drives, dinfo, next);
218e99
@@ -321,7 +324,8 @@ static bool do_check_io_limits(BlockIOLimit *io_limits, Error **errp)
218e99
     return true;
218e99
 }
218e99
 
218e99
-static DriveInfo *blockdev_init(QemuOpts *all_opts,
218e99
+/* Takes the ownership of bs_opts */
218e99
+static DriveInfo *blockdev_init(QDict *bs_opts,
218e99
                                 BlockInterfaceType block_default_type)
218e99
 {
218e99
     const char *buf;
218e99
@@ -345,7 +349,6 @@ static DriveInfo *blockdev_init(QemuOpts *all_opts,
218e99
     int ret;
218e99
     Error *error = NULL;
218e99
     QemuOpts *opts;
218e99
-    QDict *bs_opts;
218e99
     const char *id;
218e99
     bool has_driver_specific_opts;
218e99
     BlockDriver *drv = NULL;
218e99
@@ -353,9 +356,9 @@ static DriveInfo *blockdev_init(QemuOpts *all_opts,
218e99
     translation = BIOS_ATA_TRANSLATION_AUTO;
218e99
     media = MEDIA_DISK;
218e99
 
218e99
-    /* Check common options by copying from all_opts to opts, all other options
218e99
-     * are stored in bs_opts. */
218e99
-    id = qemu_opts_id(all_opts);
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
+    id = qdict_get_try_str(bs_opts, "id");
218e99
     opts = qemu_opts_create(&qemu_common_drive_opts, id, 1, &error);
218e99
     if (error_is_set(&error)) {
218e99
         qerror_report_err(error);
218e99
@@ -363,8 +366,6 @@ static DriveInfo *blockdev_init(QemuOpts *all_opts,
218e99
         return NULL;
218e99
     }
218e99
 
218e99
-    bs_opts = qdict_new();
218e99
-    qemu_opts_to_qdict(all_opts, bs_opts);
218e99
     qemu_opts_absorb_qdict(opts, bs_opts, &error);
218e99
     if (error_is_set(&error)) {
218e99
         qerror_report_err(error);
218e99
@@ -634,7 +635,6 @@ static DriveInfo *blockdev_init(QemuOpts *all_opts,
218e99
     dinfo->heads = heads;
218e99
     dinfo->secs = secs;
218e99
     dinfo->trans = translation;
218e99
-    dinfo->opts = all_opts;
218e99
     dinfo->refcount = 1;
218e99
     if (serial != NULL) {
218e99
         dinfo->serial = g_strdup(serial);
218e99
@@ -756,6 +756,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
218e99
 {
218e99
     const char *value;
218e99
     DriveInfo *dinfo;
218e99
+    QDict *bs_opts;
218e99
 
218e99
     /* Change legacy command line options into QMP ones */
218e99
     qemu_opt_rename(all_opts, "iops", "throttling.iops-total");
218e99
@@ -793,14 +794,19 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
218e99
         qemu_opt_unset(all_opts, "cache");
218e99
     }
218e99
 
218e99
+    /* Get a QDict for processing the options */
218e99
+    bs_opts = qdict_new();
218e99
+    qemu_opts_to_qdict(all_opts, bs_opts);
218e99
+
218e99
     /* Actual block device init: Functionality shared with blockdev-add */
218e99
-    dinfo = blockdev_init(all_opts, block_default_type);
218e99
+    dinfo = blockdev_init(bs_opts, block_default_type);
218e99
     if (dinfo == NULL) {
218e99
         goto fail;
218e99
     }
218e99
 
218e99
     /* Set legacy DriveInfo fields */
218e99
     dinfo->enable_auto_del = true;
218e99
+    dinfo->opts = all_opts;
218e99
 
218e99
 fail:
218e99
     return dinfo;
218e99
@@ -1699,13 +1705,7 @@ void qmp_blockdev_add(BlockdevOptions *options, Error **errp)
218e99
 
218e99
     qdict_flatten(qdict);
218e99
 
218e99
-    QemuOpts *opts = qemu_opts_from_qdict(&qemu_drive_opts, qdict, &local_err);
218e99
-    if (error_is_set(&local_err)) {
218e99
-        error_propagate(errp, local_err);
218e99
-        goto fail;
218e99
-    }
218e99
-
218e99
-    dinfo = blockdev_init(opts, IF_NONE);
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