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