cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-block-Don-t-parse-protocol-from-file.filename.patch

218e99
From 8f9ad0991d9dd978f342ff4dcc58a18d8f1a73c4 Mon Sep 17 00:00:00 2001
218e99
From: Kevin Wolf <kwolf@redhat.com>
218e99
Date: Mon, 9 Sep 2013 14:27:58 +0200
218e99
Subject: [PATCH 07/38] block: Don't parse protocol from file.filename
218e99
218e99
RH-Author: Kevin Wolf <kwolf@redhat.com>
218e99
Message-id: <1378736903-18489-8-git-send-email-kwolf@redhat.com>
218e99
Patchwork-id: 54194
218e99
O-Subject: [RHEL-7.0 qemu-kvm PATCH 07/32] block: Don't parse protocol from file.filename
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
One of the major reasons for doing something new for -blockdev and
218e99
blockdev-add was that the old block layer code parses filenames instead
218e99
of just taking them literally. So we should really leave it untouched
218e99
when it's passing using the new interfaces (like -drive
218e99
file.filename=...).
218e99
218e99
This allows opening relative file names that contain a colon.
218e99
218e99
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
218e99
Reviewed-by: Eric Blake <eblake@redhat.com>
218e99
(cherry picked from commit 98289620e0460fa595581020ab20127da4a2fc44)
218e99
218e99
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
218e99
---
218e99
 block.c                    | 17 ++++++++++++-----
218e99
 block/sheepdog.c           |  2 +-
218e99
 include/block/block.h      |  3 ++-
218e99
 qemu-img.c                 |  4 ++--
218e99
 tests/qemu-iotests/051     | 12 ++++++++++++
218e99
 tests/qemu-iotests/051.out | 14 ++++++++++++++
218e99
 6 files changed, 43 insertions(+), 9 deletions(-)
218e99
218e99
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
218e99
---
218e99
 block.c                    |   17 ++++++++++++-----
218e99
 block/sheepdog.c           |    2 +-
218e99
 include/block/block.h      |    3 ++-
218e99
 qemu-img.c                 |    4 ++--
218e99
 tests/qemu-iotests/051     |   12 ++++++++++++
218e99
 tests/qemu-iotests/051.out |   14 ++++++++++++++
218e99
 6 files changed, 43 insertions(+), 9 deletions(-)
218e99
218e99
diff --git a/block.c b/block.c
218e99
index 3c869e4..2584ec7 100644
218e99
--- a/block.c
218e99
+++ b/block.c
218e99
@@ -419,7 +419,7 @@ int bdrv_create_file(const char* filename, QEMUOptionParameter *options)
218e99
 {
218e99
     BlockDriver *drv;
218e99
 
218e99
-    drv = bdrv_find_protocol(filename);
218e99
+    drv = bdrv_find_protocol(filename, true);
218e99
     if (drv == NULL) {
218e99
         return -ENOENT;
218e99
     }
218e99
@@ -484,7 +484,8 @@ static BlockDriver *find_hdev_driver(const char *filename)
218e99
     return drv;
218e99
 }
218e99
 
218e99
-BlockDriver *bdrv_find_protocol(const char *filename)
218e99
+BlockDriver *bdrv_find_protocol(const char *filename,
218e99
+                                bool allow_protocol_prefix)
218e99
 {
218e99
     BlockDriver *drv1;
218e99
     char protocol[128];
218e99
@@ -505,9 +506,10 @@ BlockDriver *bdrv_find_protocol(const char *filename)
218e99
         return drv1;
218e99
     }
218e99
 
218e99
-    if (!path_has_protocol(filename)) {
218e99
+    if (!path_has_protocol(filename) || !allow_protocol_prefix) {
218e99
         return bdrv_find_format("file");
218e99
     }
218e99
+
218e99
     p = strchr(filename, ':');
218e99
     assert(p != NULL);
218e99
     len = p - filename;
218e99
@@ -786,6 +788,7 @@ int bdrv_file_open(BlockDriverState **pbs, const char *filename,
218e99
     BlockDriverState *bs;
218e99
     BlockDriver *drv;
218e99
     const char *drvname;
218e99
+    bool allow_protocol_prefix = false;
218e99
     int ret;
218e99
 
218e99
     /* NULL means an empty set of options */
218e99
@@ -802,6 +805,7 @@ int bdrv_file_open(BlockDriverState **pbs, const char *filename,
218e99
         filename = qdict_get_try_str(options, "filename");
218e99
     } else if (filename && !qdict_haskey(options, "filename")) {
218e99
         qdict_put(options, "filename", qstring_from_str(filename));
218e99
+        allow_protocol_prefix = true;
218e99
     } else {
218e99
         qerror_report(ERROR_CLASS_GENERIC_ERROR, "Can't specify 'file' and "
218e99
                       "'filename' options at the same time");
218e99
@@ -815,7 +819,10 @@ int bdrv_file_open(BlockDriverState **pbs, const char *filename,
218e99
         drv = bdrv_find_whitelisted_format(drvname, !(flags & BDRV_O_RDWR));
218e99
         qdict_del(options, "driver");
218e99
     } else if (filename) {
218e99
-        drv = bdrv_find_protocol(filename);
218e99
+        drv = bdrv_find_protocol(filename, allow_protocol_prefix);
218e99
+        if (!drv) {
218e99
+            qerror_report(ERROR_CLASS_GENERIC_ERROR, "Unknown protocol");
218e99
+        }
218e99
     } else {
218e99
         qerror_report(ERROR_CLASS_GENERIC_ERROR,
218e99
                       "Must specify either driver or file");
218e99
@@ -4770,7 +4777,7 @@ void bdrv_img_create(const char *filename, const char *fmt,
218e99
         return;
218e99
     }
218e99
 
218e99
-    proto_drv = bdrv_find_protocol(filename);
218e99
+    proto_drv = bdrv_find_protocol(filename, true);
218e99
     if (!proto_drv) {
218e99
         error_setg(errp, "Unknown protocol '%s'", filename);
218e99
         return;
218e99
diff --git a/block/sheepdog.c b/block/sheepdog.c
218e99
index 21a4edf..2758c26 100644
218e99
--- a/block/sheepdog.c
218e99
+++ b/block/sheepdog.c
218e99
@@ -1510,7 +1510,7 @@ static int sd_create(const char *filename, QEMUOptionParameter *options)
218e99
         BlockDriver *drv;
218e99
 
218e99
         /* Currently, only Sheepdog backing image is supported. */
218e99
-        drv = bdrv_find_protocol(backing_file);
218e99
+        drv = bdrv_find_protocol(backing_file, true);
218e99
         if (!drv || strcmp(drv->protocol_name, "sheepdog") != 0) {
218e99
             error_report("backing_file must be a sheepdog image");
218e99
             ret = -EINVAL;
218e99
diff --git a/include/block/block.h b/include/block/block.h
218e99
index db7bc4f..174295b 100644
218e99
--- a/include/block/block.h
218e99
+++ b/include/block/block.h
218e99
@@ -122,7 +122,8 @@ bool bdrv_io_limits_enabled(BlockDriverState *bs);
218e99
 
218e99
 void bdrv_init(void);
218e99
 void bdrv_init_with_whitelist(void);
218e99
-BlockDriver *bdrv_find_protocol(const char *filename);
218e99
+BlockDriver *bdrv_find_protocol(const char *filename,
218e99
+                                bool allow_protocol_prefix);
218e99
 BlockDriver *bdrv_find_format(const char *format_name);
218e99
 BlockDriver *bdrv_find_whitelisted_format(const char *format_name,
218e99
                                           bool readonly);
218e99
diff --git a/qemu-img.c b/qemu-img.c
218e99
index 673d80f..3b11414 100644
218e99
--- a/qemu-img.c
218e99
+++ b/qemu-img.c
218e99
@@ -238,7 +238,7 @@ static int print_block_option_help(const char *filename, const char *fmt)
218e99
         return 1;
218e99
     }
218e99
 
218e99
-    proto_drv = bdrv_find_protocol(filename);
218e99
+    proto_drv = bdrv_find_protocol(filename, true);
218e99
     if (!proto_drv) {
218e99
         error_report("Unknown protocol '%s'", filename);
218e99
         return 1;
218e99
@@ -1261,7 +1261,7 @@ static int img_convert(int argc, char **argv)
218e99
         goto out;
218e99
     }
218e99
 
218e99
-    proto_drv = bdrv_find_protocol(out_filename);
218e99
+    proto_drv = bdrv_find_protocol(out_filename, true);
218e99
     if (!proto_drv) {
218e99
         error_report("Unknown protocol '%s'", out_filename);
218e99
         ret = -1;
218e99
diff --git a/tests/qemu-iotests/051 b/tests/qemu-iotests/051
218e99
index 8039e23..1cf8bf7 100755
218e99
--- a/tests/qemu-iotests/051
218e99
+++ b/tests/qemu-iotests/051
218e99
@@ -149,6 +149,18 @@ echo
218e99
 run_qemu -drive file=$TEST_IMG,file.driver=file
218e99
 run_qemu -drive file=$TEST_IMG,file.driver=qcow2
218e99
 
218e99
+echo
218e99
+echo === Parsing protocol from file name ===
218e99
+echo
218e99
+
218e99
+# Protocol strings are supposed to be parsed from traditional option strings,
218e99
+# but not when using driver-specific options. We can distinguish them by the
218e99
+# error message for non-existing files.
218e99
+
218e99
+run_qemu -hda foo:bar
218e99
+run_qemu -drive file=foo:bar
218e99
+run_qemu -drive file.filename=foo:bar
218e99
+
218e99
 # success, all done
218e99
 echo "*** done"
218e99
 rm -f $seq.full
218e99
diff --git a/tests/qemu-iotests/051.out b/tests/qemu-iotests/051.out
218e99
index 3d1ac7b..6b3d636 100644
218e99
--- a/tests/qemu-iotests/051.out
218e99
+++ b/tests/qemu-iotests/051.out
218e99
@@ -169,4 +169,18 @@ Testing: -drive file=TEST_DIR/t.qcow2,file.driver=qcow2
218e99
 QEMU_PROG: -drive file=TEST_DIR/t.qcow2,file.driver=qcow2: Can't use 'qcow2' as a block driver for the protocol level
218e99
 QEMU_PROG: -drive file=TEST_DIR/t.qcow2,file.driver=qcow2: could not open disk image TEST_DIR/t.qcow2: Invalid argument
218e99
 
218e99
+
218e99
+=== Parsing protocol from file name ===
218e99
+
218e99
+Testing: -hda foo:bar
218e99
+QEMU_PROG: -hda foo:bar: Unknown protocol
218e99
+QEMU_PROG: -hda foo:bar: could not open disk image foo:bar: No such file or directory
218e99
+
218e99
+Testing: -drive file=foo:bar
218e99
+QEMU_PROG: -drive file=foo:bar: Unknown protocol
218e99
+QEMU_PROG: -drive file=foo:bar: could not open disk image foo:bar: No such file or directory
218e99
+
218e99
+Testing: -drive file.filename=foo:bar
218e99
+QEMU_PROG: -drive file.filename=foo:bar: could not open disk image ide0-hd0: No such file or directory
218e99
+
218e99
 *** done
218e99
-- 
218e99
1.7.1
218e99