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

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