9ae3a8
From 3cae2bf94bf3ef300facbd31214dbeae7b2ad7b7 Mon Sep 17 00:00:00 2001
9ae3a8
From: Max Reitz <mreitz@redhat.com>
9ae3a8
Date: Mon, 4 Nov 2013 22:31:57 +0100
9ae3a8
Subject: [PATCH 04/87] block: Bugfix 'format' and 'snapshot' used in drive option
9ae3a8
9ae3a8
RH-Author: Max Reitz <mreitz@redhat.com>
9ae3a8
Message-id: <1383604354-12743-7-git-send-email-mreitz@redhat.com>
9ae3a8
Patchwork-id: 55306
9ae3a8
O-Subject: [RHEL-7.0 qemu-kvm PATCH 06/43] block: Bugfix 'format' and 'snapshot' used in drive option
9ae3a8
Bugzilla: 1026524
9ae3a8
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
9ae3a8
RH-Acked-by: Fam Zheng <famz@redhat.com>
9ae3a8
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
9ae3a8
From: Mike Qiu <qiudayu@linux.vnet.ibm.com>
9ae3a8
9ae3a8
BZ: 1026524
9ae3a8
9ae3a8
When use -drive file='xxx',format=qcow2,snapshot=on the error
9ae3a8
message "Can't use snapshot=on with driver-specific options"
9ae3a8
can be show, and fail to start the qemu.
9ae3a8
9ae3a8
This should not be happened, and there is no file.driver option
9ae3a8
in qemu command line.
9ae3a8
9ae3a8
It is because the commit 74fe54f2a1b5c4f4498a8fe521e1dfc936656cd4,
9ae3a8
it puts 'driver' option if the command line use 'format' option.
9ae3a8
9ae3a8
This patch is to solve this bug.
9ae3a8
9ae3a8
Signed-off-by: Mike Qiu <qiudayu@linux.vnet.ibm.com>
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
(cherry picked from commit 6db5f5d68e2ffc430ba0511e23fc36c7363510f1)
9ae3a8
9ae3a8
Signed-off-by: Max Reitz <mreitz@redhat.com>
9ae3a8
---
9ae3a8
 blockdev.c | 12 +++++++++---
9ae3a8
 1 file changed, 9 insertions(+), 3 deletions(-)
9ae3a8
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 blockdev.c |   12 +++++++++---
9ae3a8
 1 files changed, 9 insertions(+), 3 deletions(-)
9ae3a8
9ae3a8
diff --git a/blockdev.c b/blockdev.c
9ae3a8
index 6710f61..a6563fa 100644
9ae3a8
--- a/blockdev.c
9ae3a8
+++ b/blockdev.c
9ae3a8
@@ -342,6 +342,7 @@ static DriveInfo *blockdev_init(QemuOpts *all_opts,
9ae3a8
     QDict *bs_opts;
9ae3a8
     const char *id;
9ae3a8
     bool has_driver_specific_opts;
9ae3a8
+    BlockDriver *drv = NULL;
9ae3a8
 
9ae3a8
     translation = BIOS_ATA_TRANSLATION_AUTO;
9ae3a8
     media = MEDIA_DISK;
9ae3a8
@@ -487,7 +488,11 @@ static DriveInfo *blockdev_init(QemuOpts *all_opts,
9ae3a8
             return NULL;
9ae3a8
         }
9ae3a8
 
9ae3a8
-        qdict_put(bs_opts, "driver", qstring_from_str(buf));
9ae3a8
+        drv = bdrv_find_whitelisted_format(buf, ro);
9ae3a8
+        if (!drv) {
9ae3a8
+            error_report("'%s' invalid format", buf);
9ae3a8
+            return NULL;
9ae3a8
+        }
9ae3a8
     }
9ae3a8
 
9ae3a8
     /* disk I/O throttling */
9ae3a8
@@ -702,12 +707,13 @@ static DriveInfo *blockdev_init(QemuOpts *all_opts,
9ae3a8
     }
9ae3a8
 
9ae3a8
     QINCREF(bs_opts);
9ae3a8
-    ret = bdrv_open(dinfo->bdrv, file, bs_opts, bdrv_flags, NULL);
9ae3a8
+    ret = bdrv_open(dinfo->bdrv, file, bs_opts, bdrv_flags, drv);
9ae3a8
 
9ae3a8
     if (ret < 0) {
9ae3a8
         if (ret == -EMEDIUMTYPE) {
9ae3a8
             error_report("could not open disk image %s: not in %s format",
9ae3a8
-                         file ?: dinfo->id, qdict_get_str(bs_opts, "driver"));
9ae3a8
+                         file ?: dinfo->id, drv ? drv->format_name :
9ae3a8
+                         qdict_get_str(bs_opts, "driver"));
9ae3a8
         } else {
9ae3a8
             error_report("could not open disk image %s: %s",
9ae3a8
                          file ?: dinfo->id, strerror(-ret));
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8