34b321
From 6b7e23d3e8ff46e638c9dcd769681b2e1b9da08e Mon Sep 17 00:00:00 2001
34b321
From: John Snow <jsnow@redhat.com>
34b321
Date: Mon, 23 Nov 2015 17:38:35 +0100
34b321
Subject: [PATCH 16/27] Make qemu-io commands available in HMP
34b321
34b321
RH-Author: John Snow <jsnow@redhat.com>
34b321
Message-id: <1448300320-7772-17-git-send-email-jsnow@redhat.com>
34b321
Patchwork-id: 68443
34b321
O-Subject: [RHEL-7.3 qemu-kvm PATCH v2 16/21] Make qemu-io commands available in HMP
34b321
Bugzilla: 1272523
34b321
RH-Acked-by: Thomas Huth <thuth@redhat.com>
34b321
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
34b321
RH-Acked-by: Max Reitz <mreitz@redhat.com>
34b321
34b321
From: Kevin Wolf <kwolf@redhat.com>
34b321
34b321
It was decided to not make this command available in QMP in order to
34b321
make clear that this is not supposed to be a stable API and should be
34b321
used only for testing and debugging purposes.
34b321
34b321
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
34b321
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
34b321
(cherry picked from commit 587da2c39c9ace168f4d01fa446a54ae998a2553)
34b321
Signed-off-by: John Snow <jsnow@redhat.com>
34b321
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
34b321
---
34b321
 Makefile        |  2 +-
34b321
 Makefile.objs   |  1 +
34b321
 hmp-commands.hx | 16 ++++++++++++++++
34b321
 hmp.c           | 18 ++++++++++++++++++
34b321
 hmp.h           |  1 +
34b321
 5 files changed, 37 insertions(+), 1 deletion(-)
34b321
34b321
diff --git a/Makefile b/Makefile
34b321
index f403057..76eb694 100644
34b321
--- a/Makefile
34b321
+++ b/Makefile
34b321
@@ -205,7 +205,7 @@ qemu-img.o: qemu-img-cmds.h
34b321
 
34b321
 qemu-img$(EXESUF): qemu-img.o $(block-obj-y) libqemuutil.a libqemustub.a
34b321
 qemu-nbd$(EXESUF): qemu-nbd.o $(block-obj-y) libqemuutil.a libqemustub.a
34b321
-qemu-io$(EXESUF): qemu-io.o qemu-io-cmds.o $(block-obj-y) libqemuutil.a libqemustub.a
34b321
+qemu-io$(EXESUF): qemu-io.o $(block-obj-y) libqemuutil.a libqemustub.a
34b321
 
34b321
 qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o
34b321
 
34b321
diff --git a/Makefile.objs b/Makefile.objs
34b321
index f83a5b2..74f722e 100644
34b321
--- a/Makefile.objs
34b321
+++ b/Makefile.objs
34b321
@@ -13,6 +13,7 @@ block-obj-$(CONFIG_POSIX) += aio-posix.o
34b321
 block-obj-$(CONFIG_WIN32) += aio-win32.o
34b321
 block-obj-y += block/
34b321
 block-obj-y += qapi-types.o qapi-visit.o
34b321
+block-obj-y += qemu-io-cmds.o
34b321
 
34b321
 block-obj-y += qemu-coroutine.o qemu-coroutine-lock.o qemu-coroutine-io.o
34b321
 block-obj-y += qemu-coroutine-sleep.o
34b321
diff --git a/hmp-commands.hx b/hmp-commands.hx
34b321
index 58498f7..7e1855a 100644
34b321
--- a/hmp-commands.hx
34b321
+++ b/hmp-commands.hx
34b321
@@ -1592,6 +1592,22 @@ Removes the chardev @var{id}.
34b321
 ETEXI
34b321
 
34b321
     {
34b321
+        .name       = "qemu-io",
34b321
+        .args_type  = "device:B,command:s",
34b321
+        .params     = "[device] \"[command]\"",
34b321
+        .help       = "run a qemu-io command on a block device",
34b321
+        .mhandler.cmd = hmp_qemu_io,
34b321
+    },
34b321
+
34b321
+STEXI
34b321
+@item qemu-io @var{device} @var{command}
34b321
+@findex qemu-io
34b321
+
34b321
+Executes a qemu-io command on the given block device.
34b321
+
34b321
+ETEXI
34b321
+
34b321
+    {
34b321
         .name       = "info",
34b321
         .args_type  = "item:s?",
34b321
         .params     = "[subcommand]",
34b321
diff --git a/hmp.c b/hmp.c
34b321
index 1805926..e1d92f4 100644
34b321
--- a/hmp.c
34b321
+++ b/hmp.c
34b321
@@ -22,6 +22,7 @@
34b321
 #include "qemu/sockets.h"
34b321
 #include "monitor/monitor.h"
34b321
 #include "ui/console.h"
34b321
+#include "qemu-io.h"
34b321
 
34b321
 static void hmp_handle_error(Monitor *mon, Error **errp)
34b321
 {
34b321
@@ -1448,3 +1449,20 @@ void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
34b321
     qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
34b321
     hmp_handle_error(mon, &local_err);
34b321
 }
34b321
+
34b321
+void hmp_qemu_io(Monitor *mon, const QDict *qdict)
34b321
+{
34b321
+    BlockDriverState *bs;
34b321
+    const char* device = qdict_get_str(qdict, "device");
34b321
+    const char* command = qdict_get_str(qdict, "command");
34b321
+    Error *err = NULL;
34b321
+
34b321
+    bs = bdrv_find(device);
34b321
+    if (bs) {
34b321
+        qemuio_command(bs, command);
34b321
+    } else {
34b321
+        error_set(&err, QERR_DEVICE_NOT_FOUND, device);
34b321
+    }
34b321
+
34b321
+    hmp_handle_error(mon, &err;;
34b321
+}
34b321
diff --git a/hmp.h b/hmp.h
34b321
index 9b2c9ce..b27ef3d 100644
34b321
--- a/hmp.h
34b321
+++ b/hmp.h
34b321
@@ -86,5 +86,6 @@ void hmp_nbd_server_add(Monitor *mon, const QDict *qdict);
34b321
 void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict);
34b321
 void hmp_chardev_add(Monitor *mon, const QDict *qdict);
34b321
 void hmp_chardev_remove(Monitor *mon, const QDict *qdict);
34b321
+void hmp_qemu_io(Monitor *mon, const QDict *qdict);
34b321
 
34b321
 #endif
34b321
-- 
34b321
1.8.3.1
34b321