Blame SOURCES/kvm-qemu-io-Let-open-pass-options-to-block-driver.patch

0a122b
From 0ba83ccbe597ebcaca69a3363d8bc2a5dd74e0c7 Mon Sep 17 00:00:00 2001
0a122b
From: Max Reitz <mreitz@redhat.com>
0a122b
Date: Sun, 29 Dec 2013 22:06:53 +0100
0a122b
Subject: [PATCH 2/8] qemu-io: Let "open" pass options to block driver
0a122b
0a122b
RH-Author: Max Reitz <mreitz@redhat.com>
0a122b
Message-id: <1388354817-3013-2-git-send-email-mreitz@redhat.com>
0a122b
Patchwork-id: 56443
0a122b
O-Subject: [RHEL-7.0 qemu-kvm PATCH 1/5] qemu-io: Let "open" pass options to block driver
0a122b
Bugzilla: 1004347
0a122b
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
0a122b
RH-Acked-by: Fam Zheng <famz@redhat.com>
0a122b
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
0a122b
0a122b
BZ: 1004347
0a122b
0a122b
Add an option to the open command to specify runtime options for the
0a122b
block driver used.
0a122b
0a122b
Signed-off-by: Max Reitz <mreitz@redhat.com>
0a122b
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
0a122b
(cherry picked from commit b543c5cdcb818ffed90cfc97aa8e297214650d84)
0a122b
0a122b
Signed-off-by: Max Reitz <mreitz@redhat.com>
0a122b
0a122b
Conflicts:
0a122b
	qemu-io.c
0a122b
0a122b
Conflicts because 797ac58cb2093ab9192d8998a1fef85d87cc8661 has not been
0a122b
backported, which splits qemu-io-cmds.c from qemu-io.c.
0a122b
---
0a122b
 qemu-io.c | 39 +++++++++++++++++++++++++++++++--------
0a122b
 1 file changed, 31 insertions(+), 8 deletions(-)
0a122b
0a122b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
0a122b
---
0a122b
 qemu-io.c |   39 +++++++++++++++++++++++++++++++--------
0a122b
 1 files changed, 31 insertions(+), 8 deletions(-)
0a122b
0a122b
diff --git a/qemu-io.c b/qemu-io.c
0a122b
index 393c2c8..64b060c 100644
0a122b
--- a/qemu-io.c
0a122b
+++ b/qemu-io.c
0a122b
@@ -16,6 +16,8 @@
0a122b
 
0a122b
 #include "qemu-common.h"
0a122b
 #include "qemu/main-loop.h"
0a122b
+#include "qemu/option.h"
0a122b
+#include "qemu/config-file.h"
0a122b
 #include "block/block_int.h"
0a122b
 #include "block/qapi.h"
0a122b
 #include "cmd.h"
0a122b
@@ -1771,7 +1773,7 @@ static const cmdinfo_t close_cmd = {
0a122b
     .oneline    = "close the current open file",
0a122b
 };
0a122b
 
0a122b
-static int openfile(char *name, int flags, int growable)
0a122b
+static int openfile(char *name, int flags, int growable, QDict *opts)
0a122b
 {
0a122b
     Error *local_err = NULL;
0a122b
 
0a122b
@@ -1781,7 +1783,7 @@ static int openfile(char *name, int flags, int growable)
0a122b
     }
0a122b
 
0a122b
     if (growable) {
0a122b
-        if (bdrv_file_open(&bs, name, NULL, flags, &local_err)) {
0a122b
+        if (bdrv_file_open(&bs, name, opts, flags, &local_err)) {
0a122b
             fprintf(stderr, "%s: can't open device %s: %s\n", progname, name,
0a122b
                     error_get_pretty(local_err));
0a122b
             error_free(local_err);
0a122b
@@ -1790,7 +1792,7 @@ static int openfile(char *name, int flags, int growable)
0a122b
     } else {
0a122b
         bs = bdrv_new("hda");
0a122b
 
0a122b
-        if (bdrv_open(bs, name, NULL, flags, NULL, &local_err) < 0) {
0a122b
+        if (bdrv_open(bs, name, opts, flags, NULL, &local_err) < 0) {
0a122b
             fprintf(stderr, "%s: can't open device %s: %s\n", progname, name,
0a122b
                     error_get_pretty(local_err));
0a122b
             error_free(local_err);
0a122b
@@ -1816,7 +1818,8 @@ static void open_help(void)
0a122b
 " -r, -- open file read-only\n"
0a122b
 " -s, -- use snapshot file\n"
0a122b
 " -n, -- disable host cache\n"
0a122b
-" -g, -- allow file to grow (only applies to protocols)"
0a122b
+" -g, -- allow file to grow (only applies to protocols)\n"
0a122b
+" -o, -- options to be given to the block driver"
0a122b
 "\n");
0a122b
 }
0a122b
 
0a122b
@@ -1829,19 +1832,30 @@ static const cmdinfo_t open_cmd = {
0a122b
     .argmin     = 1,
0a122b
     .argmax     = -1,
0a122b
     .flags      = CMD_NOFILE_OK,
0a122b
-    .args       = "[-Crsn] [path]",
0a122b
+    .args       = "[-Crsn] [-o options] [path]",
0a122b
     .oneline    = "open the file specified by path",
0a122b
     .help       = open_help,
0a122b
 };
0a122b
 
0a122b
+static QemuOptsList empty_opts = {
0a122b
+    .name = "drive",
0a122b
+    .head = QTAILQ_HEAD_INITIALIZER(empty_opts.head),
0a122b
+    .desc = {
0a122b
+        /* no elements => accept any params */
0a122b
+        { /* end of list */ }
0a122b
+    },
0a122b
+};
0a122b
+
0a122b
 static int open_f(int argc, char **argv)
0a122b
 {
0a122b
     int flags = 0;
0a122b
     int readonly = 0;
0a122b
     int growable = 0;
0a122b
     int c;
0a122b
+    QemuOpts *qopts;
0a122b
+    QDict *opts = NULL;
0a122b
 
0a122b
-    while ((c = getopt(argc, argv, "snrg")) != EOF) {
0a122b
+    while ((c = getopt(argc, argv, "snrgo:")) != EOF) {
0a122b
         switch (c) {
0a122b
         case 's':
0a122b
             flags |= BDRV_O_SNAPSHOT;
0a122b
@@ -1855,6 +1869,15 @@ static int open_f(int argc, char **argv)
0a122b
         case 'g':
0a122b
             growable = 1;
0a122b
             break;
0a122b
+        case 'o':
0a122b
+            qopts = qemu_opts_parse(&empty_opts, optarg, 0);
0a122b
+            if (qopts == NULL) {
0a122b
+                printf("could not parse option list -- %s\n", optarg);
0a122b
+                return 0;
0a122b
+            }
0a122b
+            opts = qemu_opts_to_qdict(qopts, opts);
0a122b
+            qemu_opts_del(qopts);
0a122b
+            break;
0a122b
         default:
0a122b
             return command_usage(&open_cmd);
0a122b
         }
0a122b
@@ -1868,7 +1891,7 @@ static int open_f(int argc, char **argv)
0a122b
         return command_usage(&open_cmd);
0a122b
     }
0a122b
 
0a122b
-    return openfile(argv[optind], flags, growable);
0a122b
+    return openfile(argv[optind], flags, growable, opts);
0a122b
 }
0a122b
 
0a122b
 static int init_args_command(int index)
0a122b
@@ -2039,7 +2062,7 @@ int main(int argc, char **argv)
0a122b
     }
0a122b
 
0a122b
     if ((argc - optind) == 1) {
0a122b
-        openfile(argv[optind], flags, growable);
0a122b
+        openfile(argv[optind], flags, growable, NULL);
0a122b
     }
0a122b
     command_loop();
0a122b
 
0a122b
-- 
0a122b
1.7.1
0a122b