Blob Blame History Raw
From 913177df4933b58f50ba55ad2e1205b03b61fc54 Mon Sep 17 00:00:00 2001
From: Markus Armbruster <armbru@redhat.com>
Date: Tue, 14 Mar 2017 14:25:44 +0100
Subject: HMP: Forward-port __com.redhat_drive_add from RHEL-6

RH-Author: Markus Armbruster <armbru@redhat.com>
Message-id: <1387262799-10350-5-git-send-email-armbru@redhat.com>
Patchwork-id: 56295
O-Subject: [PATCH v2 4/6] HMP: Forward-port __com.redhat_drive_add from RHEL-6
Bugzilla: 889051
RH-Acked-by: Fam Zheng <famz@redhat.com>
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
RH-Acked-by: Luiz Capitulino <lcapitulino@redhat.com>

From: Markus Armbruster <armbru@redhat.com>

Signed-off-by: Markus Armbruster <armbru@redhat.com>
(cherry picked from commit eb3c8d3879df5cc4e623608a3d1b03bb7a8e3a0a)

Rebase notes (2.8.0):
- qmp-commands.hx replaced by docs/qmp-commands.txt (commit bd6092e)
- mhandler.cmd attribute renamed to cmd (commit 2b9e357)

Rebase notes (2.4.0):
- removed user_print

Merged patches (2.9.0):
- 854d5bf Drop macro RFQDN_REDHAT (partially)
- 4804631 HMP: Clean up botched conflict resolution in user manual
- bb06f4 HMP: Fix documentation of __com.redhat.drive_add

Merged patches (2.7.0):
- a28dcc5 Fix crash bug in rebase of__com.redhat_drive_add

(cherry picked from commit c34a230c709de5e31b6f9e1a30ba622c5a5be1ee)
---
 blockdev.c                | 14 ++++++++++++++
 device-hotplug.c          | 12 +++++++++++-
 hmp-commands.hx           | 14 ++++++++++++++
 include/sysemu/blockdev.h |  4 +++-
 include/sysemu/sysemu.h   |  1 +
 monitor.c                 |  2 +-
 vl.c                      |  1 +
 7 files changed, 45 insertions(+), 3 deletions(-)

diff --git a/blockdev.c b/blockdev.c
index 5a1b783..dddf2e1 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -4102,3 +4102,17 @@ QemuOptsList qemu_drive_opts = {
         { /* end of list */ }
     },
 };
+
+QemuOptsList qemu_simple_drive_opts = {
+    .name = "simple-drive",
+    .implied_opt_name = "format",
+    .head = QTAILQ_HEAD_INITIALIZER(qemu_simple_drive_opts.head),
+    .desc = {
+        /*
+         * no elements => accept any
+         * sanity checking will happen later
+         * when setting device properties
+         */
+        { /* end if list */ }
+    }
+};
diff --git a/device-hotplug.c b/device-hotplug.c
index 12c17e5..218f7b3 100644
--- a/device-hotplug.c
+++ b/device-hotplug.c
@@ -117,7 +117,7 @@ static void check_parm(const char *key, QObject *obj, void *opaque)
     }
 }
 
-void simple_drive_add(QDict *qdict, QObject **ret_data, Error **errp)
+void qmp_simple_drive_add(QDict *qdict, QObject **ret_data, Error **errp)
 {
     int stopped;
     Error *local_err = NULL;
@@ -153,3 +153,13 @@ void simple_drive_add(QDict *qdict, QObject **ret_data, Error **errp)
 
     return;
 }
+
+void hmp_simple_drive_add(Monitor *mon, const QDict *qdict)
+{
+    Error *err = NULL;
+
+    qmp_simple_drive_add((QDict *)qdict, NULL, &err);
+    if (err) {
+        error_report_err(err);
+    }
+}
diff --git a/hmp-commands.hx b/hmp-commands.hx
index fbd02aa..9a9ff0f 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1253,6 +1253,20 @@ Add drive to PCI storage controller.
 ETEXI
 
     {
+        .name       = "__com.redhat_drive_add",
+        .args_type  = "simple-drive:O",
+        .params     = "id=name,[file=file][,format=f][,media=d]...",
+        .help       = "Create a drive similar to -drive if=none.",
+        .cmd = hmp_simple_drive_add,
+    },
+
+STEXI
+@item __com.redhat_drive_add
+@findex __com.redhat_drive_add
+Create a drive similar to -drive if=none.
+ETEXI
+
+    {
         .name       = "pcie_aer_inject_error",
         .args_type  = "advisory_non_fatal:-a,correctable:-c,"
 	              "id:s,error_status:s,"
diff --git a/include/sysemu/blockdev.h b/include/sysemu/blockdev.h
index 3bda14c..c19c36a 100644
--- a/include/sysemu/blockdev.h
+++ b/include/sysemu/blockdev.h
@@ -64,5 +64,7 @@ DriveInfo *drive_new(QemuOpts *arg, BlockInterfaceType block_default_type);
 void hmp_commit(Monitor *mon, const QDict *qdict);
 void hmp_drive_del(Monitor *mon, const QDict *qdict);
 
-void simple_drive_add(QDict *qdict, QObject **ret_data, Error **errp);
+void hmp_simple_drive_add(Monitor *mon, const QDict *qdict);
+void qmp_simple_drive_add(QDict *qdict, QObject **ret_data, Error **errp);
+
 #endif
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index 53a2588..22c0460 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -232,6 +232,7 @@ extern QemuOptsList qemu_legacy_drive_opts;
 extern QemuOptsList qemu_common_drive_opts;
 extern QemuOptsList qemu_drive_opts;
 extern QemuOptsList bdrv_runtime_opts;
+extern QemuOptsList qemu_simple_drive_opts;
 extern QemuOptsList qemu_chardev_opts;
 extern QemuOptsList qemu_device_opts;
 extern QemuOptsList qemu_netdev_opts;
diff --git a/monitor.c b/monitor.c
index 532bc34..fbcd058 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1014,7 +1014,7 @@ void monitor_init_qmp_commands(void)
                          QCO_NO_OPTIONS);
     qmp_register_command(&qmp_commands, "netdev_add", qmp_netdev_add,
                          QCO_NO_OPTIONS);
-    qmp_register_command(&qmp_commands, "__com.redhat_drive_add", simple_drive_add,
+    qmp_register_command(&qmp_commands, "__com.redhat_drive_add", qmp_simple_drive_add,
                          QCO_NO_OPTIONS);
 
     qmp_unregister_commands_hack();
diff --git a/vl.c b/vl.c
index 1f9a692..77af8df 100644
--- a/vl.c
+++ b/vl.c
@@ -3002,6 +3002,7 @@ int main(int argc, char **argv, char **envp)
     qemu_add_drive_opts(&qemu_common_drive_opts);
     qemu_add_drive_opts(&qemu_drive_opts);
     qemu_add_drive_opts(&bdrv_runtime_opts);
+    qemu_add_opts(&qemu_simple_drive_opts);
     qemu_add_opts(&qemu_chardev_opts);
     qemu_add_opts(&qemu_device_opts);
     qemu_add_opts(&qemu_netdev_opts);
-- 
1.8.3.1