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

4a2fec
From 5d293a214ca093a133011d0edc9039b1e71b4219 Mon Sep 17 00:00:00 2001
4a2fec
From: Markus Armbruster <armbru@redhat.com>
4a2fec
Date: Tue, 14 Mar 2017 14:16:45 +0100
4a2fec
Subject: QMP: Forward-port __com.redhat_drive_add from RHEL-6
4a2fec
4a2fec
RH-Author: Markus Armbruster <armbru@redhat.com>
4a2fec
Message-id: <1387262799-10350-4-git-send-email-armbru@redhat.com>
4a2fec
Patchwork-id: 56294
4a2fec
O-Subject: [PATCH v2 3/6] QMP: Forward-port __com.redhat_drive_add from RHEL-6
4a2fec
Bugzilla: 889051
4a2fec
RH-Acked-by: Fam Zheng <famz@redhat.com>
4a2fec
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
4a2fec
RH-Acked-by: Luiz Capitulino <lcapitulino@redhat.com>
4a2fec
4a2fec
From: Markus Armbruster <armbru@redhat.com>
4a2fec
4a2fec
Code taken from RHEL-6 as of qemu-kvm-0.12.1.2-2.418.el6, backported
4a2fec
and fixed up as follows:
4a2fec
4a2fec
* Update simple_drive_add() for commit 4e89978 "qemu-option:
4a2fec
  qemu_opts_from_qdict(): use error_set()".
4a2fec
4a2fec
* Update simple_drive_add() for commit 2d0d283 "Support default block
4a2fec
  interfaces per QEMUMachine".
4a2fec
4a2fec
* Add comment explaining drive_init() error reporting hacks to
4a2fec
  simple_drive_add().
4a2fec
4a2fec
* qemu-monitor.hx has been split into qmp-commands.hx and
4a2fec
  hmp-commands.hx.  Copy the QMP parts to qmp-commands.hx.  Clean up
4a2fec
  second example slightly.
4a2fec
4a2fec
* Trailing whitespace cleaned up.
4a2fec
4a2fec
Signed-off-by: Markus Armbruster <armbru@redhat.com>
4a2fec
4a2fec
Rebase notes (2.9.0):
4a2fec
- documentation moved from docs/qmp-commands.txt to qapi/block.json
4a2fec
- added argument to qmp_register_command
4a2fec
- explicit argument listing for correct documentation checking
4a2fec
4a2fec
Rebase notes (2.8.0):
4a2fec
- qmp-commands.hx replaced by docs/qmp-commands.txt (commit bd6092e)
4a2fec
4a2fec
Rebase notes (2.6.0):
4a2fec
- Added qapi/error.h to device-hotplug.c
4a2fec
4a2fec
Rebase notes (2.4.0):
4a2fec
- removed qerror_report
4a2fec
- removed user_print
4a2fec
4a2fec
Merged patches (2.9.0):
4a2fec
- 599ec5f QMP: Fix forward port of __com.redhat_drive_add
4a2fec
4a2fec
Merged patches (2.7.0):
4a2fec
- 20af75a QMP: Relax __com.redhat_drive_add parameter checking
4a2fec
4a2fec
(cherry picked from commit 6b8c0495aa317dfc5caa6d204373140811880d1a)
4a2fec
---
4a2fec
 device-hotplug.c          | 64 +++++++++++++++++++++++++++++++++++++++++++++++
4a2fec
 include/sysemu/blockdev.h |  2 ++
4a2fec
 monitor.c                 |  2 ++
4a2fec
 qapi/block.json           | 45 +++++++++++++++++++++++++++++++++
4a2fec
 4 files changed, 113 insertions(+)
4a2fec
4a2fec
diff --git a/device-hotplug.c b/device-hotplug.c
4a2fec
index 126f73c..12c17e5 100644
4a2fec
--- a/device-hotplug.c
4a2fec
+++ b/device-hotplug.c
4a2fec
@@ -31,6 +31,10 @@
4a2fec
 #include "sysemu/sysemu.h"
4a2fec
 #include "monitor/monitor.h"
4a2fec
 #include "block/block_int.h"
4a2fec
+#include "qemu/error-report.h"
4a2fec
+#include "qapi/qmp/qerror.h"
4a2fec
+#include "qapi/error.h"
4a2fec
+
4a2fec
 
4a2fec
 static DriveInfo *add_init_drive(const char *optstr)
4a2fec
 {
4a2fec
@@ -89,3 +93,63 @@ err:
4a2fec
         blk_unref(blk);
4a2fec
     }
4a2fec
 }
4a2fec
+
4a2fec
+static void check_parm(const char *key, QObject *obj, void *opaque)
4a2fec
+{
4a2fec
+    static const char *unwanted_keys[] = {
4a2fec
+        "bus", "unit", "index", "if", "boot", "addr",
4a2fec
+        NULL
4a2fec
+
4a2fec
+    };
4a2fec
+    int *stopped = opaque;
4a2fec
+    const char **p;
4a2fec
+
4a2fec
+    if (*stopped) {
4a2fec
+        return;
4a2fec
+    }
4a2fec
+
4a2fec
+    for (p = unwanted_keys; *p; p++) {
4a2fec
+        if (!strcmp(key, *p)) {
4a2fec
+            error_report(QERR_INVALID_PARAMETER, key);
4a2fec
+            *stopped = 1;
4a2fec
+            return;
4a2fec
+        }
4a2fec
+    }
4a2fec
+}
4a2fec
+
4a2fec
+void simple_drive_add(QDict *qdict, QObject **ret_data, Error **errp)
4a2fec
+{
4a2fec
+    int stopped;
4a2fec
+    Error *local_err = NULL;
4a2fec
+    QemuOpts *opts;
4a2fec
+    DriveInfo *dinfo;
4a2fec
+    MachineClass *mc;
4a2fec
+
4a2fec
+    if (!qdict_haskey(qdict, "id")) {
4a2fec
+        error_setg(errp, QERR_MISSING_PARAMETER, "id");
4a2fec
+        return;
4a2fec
+    }
4a2fec
+
4a2fec
+    stopped = 0;
4a2fec
+    qdict_iter(qdict, check_parm, &stopped);
4a2fec
+    if (stopped) {
4a2fec
+        return;
4a2fec
+    }
4a2fec
+
4a2fec
+    opts = qemu_opts_from_qdict(&qemu_drive_opts, qdict, &local_err);
4a2fec
+    if (!opts) {
4a2fec
+        error_propagate(errp, local_err);
4a2fec
+        return;
4a2fec
+    }
4a2fec
+    qemu_opt_set(opts, "if", "none", &error_abort);
4a2fec
+    mc = MACHINE_GET_CLASS(current_machine);
4a2fec
+    dinfo = drive_new(opts, mc->block_default_type);
4a2fec
+    if (!dinfo) {
4a2fec
+        error_report(QERR_DEVICE_INIT_FAILED,
4a2fec
+                      qemu_opts_id(opts));
4a2fec
+        qemu_opts_del(opts);
4a2fec
+        return;
4a2fec
+    }
4a2fec
+
4a2fec
+    return;
4a2fec
+}
4a2fec
diff --git a/include/sysemu/blockdev.h b/include/sysemu/blockdev.h
4a2fec
index ac22f2a..3bda14c 100644
4a2fec
--- a/include/sysemu/blockdev.h
4a2fec
+++ b/include/sysemu/blockdev.h
4a2fec
@@ -63,4 +63,6 @@ DriveInfo *drive_new(QemuOpts *arg, BlockInterfaceType block_default_type);
4a2fec
 
4a2fec
 void hmp_commit(Monitor *mon, const QDict *qdict);
4a2fec
 void hmp_drive_del(Monitor *mon, const QDict *qdict);
4a2fec
+
4a2fec
+void simple_drive_add(QDict *qdict, QObject **ret_data, Error **errp);
4a2fec
 #endif
4a2fec
diff --git a/monitor.c b/monitor.c
4a2fec
index de0a70e..76b8605 100644
4a2fec
--- a/monitor.c
4a2fec
+++ b/monitor.c
4a2fec
@@ -1034,6 +1034,8 @@ void monitor_init_qmp_commands(void)
4a2fec
                          QCO_NO_OPTIONS);
4a2fec
     qmp_register_command(&qmp_commands, "netdev_add", qmp_netdev_add,
4a2fec
                          QCO_NO_OPTIONS);
4a2fec
+    qmp_register_command(&qmp_commands, "__com.redhat_drive_add", simple_drive_add,
4a2fec
+                         QCO_NO_OPTIONS);
4a2fec
 
4a2fec
     qmp_unregister_commands_hack();
4a2fec
 
4a2fec
diff --git a/qapi/block.json b/qapi/block.json
4a2fec
index 03115d3..2083bc7 100644
4a2fec
--- a/qapi/block.json
4a2fec
+++ b/qapi/block.json
4a2fec
@@ -212,6 +212,51 @@
4a2fec
   'data': { 'id': 'str' } }
4a2fec
 
4a2fec
 ##
4a2fec
+# @__com.redhat_drive_add:
4a2fec
+#
4a2fec
+# Create a drive similar to -drive if=none.
4a2fec
+#
4a2fec
+# @id: Drive ID, must be unique
4a2fec
+# @file: Disk image
4a2fec
+# @format: Disk format
4a2fec
+# @aio: How to perform asynchronous disk I/O
4a2fec
+# @cache: Host cache use policy
4a2fec
+# @cyls, "heads", "secs": Disk geometry
4a2fec
+# @trans: BIOS translation mode
4a2fec
+# @media: Media type
4a2fec
+# @readonly: Open image read-only
4a2fec
+# @rerror: What to do on read error
4a2fec
+# @werror: What to do on write error
4a2fec
+# @serial: Drive serial number
4a2fec
+# @snapshot: Enable snapshot mode
4a2fec
+# @copy-on-read: Enable copy-on-read mode
4a2fec
+#
4a2fec
+# Example:
4a2fec
+#
4a2fec
+# 1. Add a drive without medium:
4a2fec
+#
4a2fec
+# -> { "execute": "__com.redhat_drive_add", "arguments": { "id": "foo" } }
4a2fec
+# <- {"return": {}}
4a2fec
+#
4a2fec
+# 2. Add a drive with medium:
4a2fec
+#
4a2fec
+# -> { "execute": "__com.redhat_drive_add",
4a2fec
+#      "arguments": { "id": "bar", "file": "tmp.qcow2", "format": "qcow2" } }
4a2fec
+# <- {"return": {}}
4a2fec
+#
4a2fec
+##
4a2fec
+{ 'command': '__com.redhat_drive_add',
4a2fec
+  'data': { 'id': 'str', '*file': 'str', '*format': 'str',
4a2fec
+            '*aio': 'BlockdevAioOptions',
4a2fec
+            '*cache': 'BlockdevCacheOptions',
4a2fec
+            '*cyls': 'int', '*heads': 'int', '*secs': 'int',
4a2fec
+            '*trans': 'str', '*media': 'str',
4a2fec
+            '*readonly': 'bool', '*snapshot': 'bool',
4a2fec
+            '*rerror': 'str', '*werror': 'str',
4a2fec
+            '*copy-on-read': 'bool', '*serial': 'str' },
4a2fec
+  'gen': false }                # just to minimize porting churn
4a2fec
+
4a2fec
+##
4a2fec
 # @nbd-server-start:
4a2fec
 #
4a2fec
 # Start an NBD server listening on the given host and port.  Block
4a2fec
-- 
4a2fec
1.8.3.1
4a2fec