Blame SOURCES/kvm-block-Allow-driver-option-on-the-top-level.patch

218e99
From c9489944db197e5c1b4086dc92a41f6c364976b0 Mon Sep 17 00:00:00 2001
218e99
From: Kevin Wolf <kwolf@redhat.com>
218e99
Date: Mon, 9 Sep 2013 14:28:17 +0200
218e99
Subject: [PATCH 26/38] block: Allow "driver" option on the top level
218e99
218e99
RH-Author: Kevin Wolf <kwolf@redhat.com>
218e99
Message-id: <1378736903-18489-27-git-send-email-kwolf@redhat.com>
218e99
Patchwork-id: 54213
218e99
O-Subject: [RHEL-7.0 qemu-kvm PATCH 26/32] block: Allow "driver" option on the top level
218e99
Bugzilla: 1005818
218e99
RH-Acked-by: Fam Zheng <famz@redhat.com>
218e99
RH-Acked-by: Max Reitz <mreitz@redhat.com>
218e99
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
218e99
218e99
Bugzilla: 1005818
218e99
218e99
This is traditionally -drive format=..., which is now translated into
218e99
the new driver option. This gives us a more consistent way to select the
218e99
driver of BlockDriverStates that can be used in QMP context, too.
218e99
218e99
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
218e99
Reviewed-by: Eric Blake <eblake@redhat.com>
218e99
(cherry picked from commit 74fe54f2a1b5c4f4498a8fe521e1dfc936656cd4)
218e99
218e99
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
218e99
---
218e99
 block.c    |  7 +++++++
218e99
 blockdev.c | 20 ++++++++++----------
218e99
 2 files changed, 17 insertions(+), 10 deletions(-)
218e99
218e99
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
218e99
---
218e99
 block.c    |    7 +++++++
218e99
 blockdev.c |   20 ++++++++++----------
218e99
 2 files changed, 17 insertions(+), 10 deletions(-)
218e99
218e99
diff --git a/block.c b/block.c
218e99
index 20820fa..f4a89b9 100644
218e99
--- a/block.c
218e99
+++ b/block.c
218e99
@@ -972,6 +972,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
218e99
     char tmp_filename[PATH_MAX + 1];
218e99
     BlockDriverState *file = NULL;
218e99
     QDict *file_options = NULL;
218e99
+    const char *drvname;
218e99
 
218e99
     /* NULL means an empty set of options */
218e99
     if (options == NULL) {
218e99
@@ -1061,6 +1062,12 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
218e99
     }
218e99
 
218e99
     /* Find the right image format driver */
218e99
+    drvname = qdict_get_try_str(options, "driver");
218e99
+    if (drvname) {
218e99
+        drv = bdrv_find_whitelisted_format(drvname, !(flags & BDRV_O_RDWR));
218e99
+        qdict_del(options, "driver");
218e99
+    }
218e99
+
218e99
     if (!drv) {
218e99
         ret = find_image_format(file, filename, &drv);
218e99
     }
218e99
diff --git a/blockdev.c b/blockdev.c
218e99
index bd33c17..1c9ca4d 100644
218e99
--- a/blockdev.c
218e99
+++ b/blockdev.c
218e99
@@ -322,7 +322,6 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
218e99
     enum { MEDIA_DISK, MEDIA_CDROM } media;
218e99
     int bus_id, unit_id;
218e99
     int cyls, heads, secs, translation;
218e99
-    BlockDriver *drv = NULL;
218e99
     int max_devs;
218e99
     int index;
218e99
     int ro = 0;
218e99
@@ -338,6 +337,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
218e99
     QemuOpts *opts;
218e99
     QDict *bs_opts;
218e99
     const char *id;
218e99
+    bool has_driver_specific_opts;
218e99
 
218e99
     translation = BIOS_ATA_TRANSLATION_AUTO;
218e99
     media = MEDIA_DISK;
218e99
@@ -365,6 +365,8 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
218e99
         qdict_del(bs_opts, "id");
218e99
     }
218e99
 
218e99
+    has_driver_specific_opts = !!qdict_size(bs_opts);
218e99
+
218e99
     /* extract parameters */
218e99
     bus_id  = qemu_opt_get_number(opts, "bus", 0);
218e99
     unit_id = qemu_opt_get_number(opts, "unit", -1);
218e99
@@ -477,11 +479,8 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
218e99
             error_printf("\n");
218e99
             return NULL;
218e99
         }
218e99
-        drv = bdrv_find_whitelisted_format(buf, ro);
218e99
-        if (!drv) {
218e99
-            error_report("'%s' invalid format", buf);
218e99
-            return NULL;
218e99
-        }
218e99
+
218e99
+        qdict_put(bs_opts, "driver", qstring_from_str(buf));
218e99
     }
218e99
 
218e99
     /* disk I/O throttling */
218e99
@@ -658,7 +657,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
218e99
         abort();
218e99
     }
218e99
     if (!file || !*file) {
218e99
-        if (qdict_size(bs_opts)) {
218e99
+        if (has_driver_specific_opts) {
218e99
             file = NULL;
218e99
         } else {
218e99
             return dinfo;
218e99
@@ -695,13 +694,13 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
218e99
         error_report("warning: disabling copy_on_read on readonly drive");
218e99
     }
218e99
 
218e99
-    ret = bdrv_open(dinfo->bdrv, file, bs_opts, bdrv_flags, drv);
218e99
-    bs_opts = NULL;
218e99
+    QINCREF(bs_opts);
218e99
+    ret = bdrv_open(dinfo->bdrv, file, bs_opts, bdrv_flags, NULL);
218e99
 
218e99
     if (ret < 0) {
218e99
         if (ret == -EMEDIUMTYPE) {
218e99
             error_report("could not open disk image %s: not in %s format",
218e99
-                         file ?: dinfo->id, drv->format_name);
218e99
+                         file ?: dinfo->id, qdict_get_str(bs_opts, "driver"));
218e99
         } else {
218e99
             error_report("could not open disk image %s: %s",
218e99
                          file ?: dinfo->id, strerror(-ret));
218e99
@@ -712,6 +711,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
218e99
     if (bdrv_key_required(dinfo->bdrv))
218e99
         autostart = 0;
218e99
 
218e99
+    QDECREF(bs_opts);
218e99
     qemu_opts_del(opts);
218e99
 
218e99
     return dinfo;
218e99
-- 
218e99
1.7.1
218e99