Blame SOURCES/kvm-QMP-Forward-port-__com.redhat_drive_add-from-RHEL-6.patch

0a122b
From 75ad257a1d23dcbde364ad736770d1bd01f157b6 Mon Sep 17 00:00:00 2001
0a122b
Message-Id: <75ad257a1d23dcbde364ad736770d1bd01f157b6.1387385974.git.minovotn@redhat.com>
0a122b
In-Reply-To: <7cba796b16325e96d01e65bd265b4073ab103157.1387385974.git.minovotn@redhat.com>
0a122b
References: <7cba796b16325e96d01e65bd265b4073ab103157.1387385974.git.minovotn@redhat.com>
0a122b
From: Markus Armbruster <armbru@redhat.com>
0a122b
Date: Tue, 17 Dec 2013 06:46:36 +0100
0a122b
Subject: [PATCH 2/5] QMP: Forward-port __com.redhat_drive_add from RHEL-6
0a122b
0a122b
RH-Author: Markus Armbruster <armbru@redhat.com>
0a122b
Message-id: <1387262799-10350-4-git-send-email-armbru@redhat.com>
0a122b
Patchwork-id: 56294
0a122b
O-Subject: [PATCH v2 3/6] QMP: Forward-port __com.redhat_drive_add from RHEL-6
0a122b
Bugzilla: 889051
0a122b
RH-Acked-by: Fam Zheng <famz@redhat.com>
0a122b
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
0a122b
RH-Acked-by: Luiz Capitulino <lcapitulino@redhat.com>
0a122b
0a122b
From: Markus Armbruster <armbru@redhat.com>
0a122b
0a122b
Code taken from RHEL-6 as of qemu-kvm-0.12.1.2-2.418.el6, backported
0a122b
and fixed up as follows:
0a122b
0a122b
* Update simple_drive_add() for commit 4e89978 "qemu-option:
0a122b
  qemu_opts_from_qdict(): use error_set()".
0a122b
0a122b
* Update simple_drive_add() for commit 2d0d283 "Support default block
0a122b
  interfaces per QEMUMachine".
0a122b
0a122b
* Add comment explaining drive_init() error reporting hacks to
0a122b
  simple_drive_add().
0a122b
0a122b
* qemu-monitor.hx has been split into qmp-commands.hx and
0a122b
  hmp-commands.hx.  Copy the QMP parts to qmp-commands.hx.  Clean up
0a122b
  second example slightly.
0a122b
0a122b
* Trailing whitespace cleaned up.
0a122b
0a122b
Signed-off-by: Markus Armbruster <armbru@redhat.com>
0a122b
---
0a122b
 device-hotplug.c          | 73 +++++++++++++++++++++++++++++++++++++++++++++++
0a122b
 include/sysemu/blockdev.h |  2 ++
0a122b
 qmp-commands.hx           | 46 +++++++++++++++++++++++++++++
0a122b
 3 files changed, 121 insertions(+)
0a122b
0a122b
Signed-off-by: Michal Novotny <minovotn@redhat.com>
0a122b
---
0a122b
 device-hotplug.c          | 73 +++++++++++++++++++++++++++++++++++++++++++++++
0a122b
 include/sysemu/blockdev.h |  2 ++
0a122b
 qmp-commands.hx           | 46 +++++++++++++++++++++++++++++
0a122b
 3 files changed, 121 insertions(+)
0a122b
0a122b
diff --git a/device-hotplug.c b/device-hotplug.c
0a122b
index 103d34a..20f6b7f 100644
0a122b
--- a/device-hotplug.c
0a122b
+++ b/device-hotplug.c
0a122b
@@ -77,3 +77,76 @@ err:
0a122b
         drive_put_ref(dinfo);
0a122b
     }
0a122b
 }
0a122b
+
0a122b
+static void check_parm(const char *key, QObject *obj, void *opaque)
0a122b
+{
0a122b
+    static const char *valid_keys[] = {
0a122b
+        "id", "cyls", "heads", "secs", "trans", "media", "snapshot",
0a122b
+        "file", "cache", "aio", "format", "serial", "rerror", "werror",
0a122b
+        "readonly", "copy-on-read",
0a122b
+#ifdef CONFIG_BLOCK_IO_THROTTLING
0a122b
+        "bps", "bps_rd", "bps_wr", "iops", "iops_rd", "iops_wr",
0a122b
+#endif
0a122b
+        NULL
0a122b
+
0a122b
+    };
0a122b
+    int *stopped = opaque;
0a122b
+    const char **p;
0a122b
+
0a122b
+    if (*stopped) {
0a122b
+        return;
0a122b
+    }
0a122b
+
0a122b
+    for (p = valid_keys; *p; p++) {
0a122b
+        if (!strcmp(key, *p)) {
0a122b
+            return;
0a122b
+        }
0a122b
+    }
0a122b
+
0a122b
+    qerror_report(QERR_INVALID_PARAMETER, key);
0a122b
+    *stopped = 1;
0a122b
+}
0a122b
+
0a122b
+int simple_drive_add(Monitor *mon, const QDict *qdict, QObject **ret_data)
0a122b
+{
0a122b
+    int stopped;
0a122b
+    Error *local_err = NULL;
0a122b
+    QemuOpts *opts;
0a122b
+    DriveInfo *dinfo;
0a122b
+
0a122b
+    if (!qdict_haskey(qdict, "id")) {
0a122b
+        qerror_report(QERR_MISSING_PARAMETER, "id");
0a122b
+        return -1;
0a122b
+    }
0a122b
+
0a122b
+    stopped = 0;
0a122b
+    qdict_iter(qdict, check_parm, &stopped);
0a122b
+    if (stopped) {
0a122b
+        return -1;
0a122b
+    }
0a122b
+
0a122b
+    opts = qemu_opts_from_qdict(&qemu_drive_opts, qdict, &local_err);
0a122b
+    if (!opts) {
0a122b
+        qerror_report_err(local_err);
0a122b
+        error_free(local_err);
0a122b
+        return -1;
0a122b
+    }
0a122b
+    qemu_opt_set(opts, "if", "none");
0a122b
+    dinfo = drive_init(opts, current_machine->block_default_type);
0a122b
+    if (!dinfo) {
0a122b
+        /*
0a122b
+         * drive_init() reports some errors with qerror_report_err(),
0a122b
+         * and some with error_report().  The latter vanish without
0a122b
+         * trace in monitor_vprintf().  See also the rather optimistic
0a122b
+         * upstream commit 74ee59a.  Emit a generic error here.  If a
0a122b
+         * prior error from qerror_report_err() is pending, it'll get
0a122b
+         * ignored.
0a122b
+         */
0a122b
+        qerror_report(QERR_DEVICE_INIT_FAILED,
0a122b
+                      qemu_opts_id(opts));
0a122b
+        qemu_opts_del(opts);
0a122b
+        return -1;
0a122b
+    }
0a122b
+
0a122b
+    return 0;
0a122b
+}
0a122b
diff --git a/include/sysemu/blockdev.h b/include/sysemu/blockdev.h
0a122b
index 1082091..74e1cea 100644
0a122b
--- a/include/sysemu/blockdev.h
0a122b
+++ b/include/sysemu/blockdev.h
0a122b
@@ -67,4 +67,6 @@ void qmp_change_blockdev(const char *device, const char *filename,
0a122b
                          bool has_format, const char *format, Error **errp);
0a122b
 void do_commit(Monitor *mon, const QDict *qdict);
0a122b
 int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data);
0a122b
+
0a122b
+int simple_drive_add(Monitor *mon, const QDict *qdict, QObject **ret_data);
0a122b
 #endif
0a122b
diff --git a/qmp-commands.hx b/qmp-commands.hx
0a122b
index 0ae9204..9e742d5 100644
0a122b
--- a/qmp-commands.hx
0a122b
+++ b/qmp-commands.hx
0a122b
@@ -106,6 +106,52 @@ Example:
0a122b
 Note: The "force" argument defaults to false.
0a122b
 
0a122b
 EQMP
0a122b
+    {
0a122b
+        .name       = RFQDN_REDHAT "drive_add",
0a122b
+        .args_type  = "simple-drive:O",
0a122b
+        .params     = "id=name,[file=file][,format=f][,media=d]...",
0a122b
+        .help       = "Create a drive similar to -device if=none.",
0a122b
+	.user_print = monitor_user_noop,
0a122b
+        .mhandler.cmd_new = simple_drive_add,
0a122b
+    },
0a122b
+
0a122b
+SQMP
0a122b
+__com.redhat_drive_add
0a122b
+----------------------
0a122b
+
0a122b
+Create a drive similar to -device if=none.
0a122b
+
0a122b
+Arguments:
0a122b
+
0a122b
+- "id": Drive ID, must be unique (json-string)
0a122b
+- "file": Disk image (json-string, optional)
0a122b
+- "format": Disk format (json-string, optional)
0a122b
+- "aio": How to perform asynchronous disk I/O (json-string, optional)
0a122b
+- "cache": Host cache use policy (json-string, optional)
0a122b
+- "cyls", "heads", "secs": Disk geometry (json-int, optional)
0a122b
+- "trans": BIOS translation mode (json-string, optional)
0a122b
+- "media": Media type (json-string, optional)
0a122b
+- "readonly": Open image read-only (json-bool, optional)
0a122b
+- "rerror": What to do on read error (json-string, optional)
0a122b
+- "werror": What to do on write error (json-string, optional)
0a122b
+- "serial": Drive serial number (json-string, optional)
0a122b
+- "snapshot": Enable snapshot mode (json-bool, optional)
0a122b
+- "copy-on-read": Enable copy-on-read mode (json-bool, optional)
0a122b
+
0a122b
+Example:
0a122b
+
0a122b
+1. Add a drive without medium:
0a122b
+
0a122b
+-> { "execute": "__com.redhat_drive_add", "arguments": { "id": "foo" } }
0a122b
+<- {"return": {}}
0a122b
+
0a122b
+2. Add a drive with medium:
0a122b
+
0a122b
+-> { "execute": "__com.redhat_drive_add",
0a122b
+     "arguments": { "id": "bar", "file": "tmp.qcow2", "format": "qcow2" } }
0a122b
+<- {"return": {}}
0a122b
+
0a122b
+EQMP
0a122b
 
0a122b
     {
0a122b
         .name       = RFQDN_REDHAT "drive_del",
0a122b
-- 
0a122b
1.7.11.7
0a122b