qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 2/2] QMP: Introduce Human Monitor passthrough comman


From: Luiz Capitulino
Subject: [Qemu-devel] [PATCH 2/2] QMP: Introduce Human Monitor passthrough command
Date: Mon, 25 Oct 2010 18:06:44 -0200

This command allows QMP clients to execute HMP commands, please
check its documentation in the hmp-commands.hx file for usage
information.

Please, also note that not all HMP commands can be executed this
way, in special commands that:

 o need to store monitor related data (eg. getfd)
 o read data from the user (eg. cont when the block device is
   encrypted)

TODO: Create a blacklist for those bad commands or just let
      them fail? (assuming they won't blowup, of course)
TODO: Maybe a command like 'cpu' requires a blacklist

Signed-off-by: Luiz Capitulino <address@hidden>
---
 monitor.c       |   34 ++++++++++++++++++++++++++++++++++
 qmp-commands.hx |   32 ++++++++++++++++++++++++++++++++
 2 files changed, 66 insertions(+), 0 deletions(-)

diff --git a/monitor.c b/monitor.c
index 260cc02..a0df098 100644
--- a/monitor.c
+++ b/monitor.c
@@ -490,6 +490,40 @@ static int do_qmp_capabilities(Monitor *mon, const QDict 
*params,
     return 0;
 }
 
+static void handle_user_command(Monitor *mon, const char *cmdline);
+
+static void hmp_call(Monitor *mon, const char *cmdline)
+{
+    Monitor *old_mon = cur_mon;
+
+    cur_mon = mon;
+    handle_user_command(mon, cmdline);
+    cur_mon = old_mon;
+}
+
+static int do_hmp_passthrough(Monitor *mon, const QDict *params,
+                              QObject **ret_data)
+{
+    QString *qs;
+    Monitor hmp;
+    CharDriverState bufchr;
+
+    memset(&hmp, 0, sizeof(hmp));
+    hmp.chr = &bufchr;
+    qemu_chr_init_buffered(hmp.chr);
+
+    hmp_call(&hmp, qdict_get_str(params, "command-line"));
+
+    qs = qemu_chr_buffered_to_qs(hmp.chr);
+    if (qs) {
+        *ret_data = QOBJECT(qs);
+    }
+
+    qemu_chr_close_buffered(hmp.chr);
+
+    return 0;
+}
+
 static int compare_cmd(const char *name, const char *list)
 {
     const char *p, *pstart;
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 793cf1c..29a6048 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -761,6 +761,38 @@ Example:
 
 Note: This command must be issued before issuing any other command.
 
+EQMP
+
+    {
+        .name       = "hmp_passthrough",
+        .args_type  = "command-line:s",
+        .params     = "",
+        .help       = "",
+        .user_print = monitor_user_noop,
+        .mhandler.cmd_new = do_hmp_passthrough,
+    },
+
+SQMP
+hmp_passthrough
+---------------
+
+Execute a Human Monitor command.
+
+Arguments: 
+
+- command-line: the command name and its arguments, just like the
+                Human Monitor's shell (json-string)
+
+Example:
+
+-> { "execute": "hmp_passthrough", "arguments": { "command-line": "info 
version" } }
+<- { "return": "0.13.50\r\n" }
+
+Note: The Human Monitor is NOT a stable interface, this means that command
+      names, arguments and responses can change or be removed at ANY time.
+      Applications that rely on long term stability guarantees should NOT
+      use this command.
+
 3. Query Commands
 =================
 
-- 
1.7.3.2.90.gd4c43




reply via email to

[Prev in Thread] Current Thread [Next in Thread]