qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Luiz Capitulino <lcapitulino@redhat.com>
To: qemu-devel@nongnu.org
Cc: aliguori@us.ibm.com, armbru@redhat.com
Subject: [Qemu-devel] [PATCH 2/2] QMP: Introduce Human Monitor passthrough command
Date: Mon, 25 Oct 2010 18:06:44 -0200	[thread overview]
Message-ID: <1288037204-27768-3-git-send-email-lcapitulino@redhat.com> (raw)
In-Reply-To: <1288037204-27768-1-git-send-email-lcapitulino@redhat.com>

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 <lcapitulino@redhat.com>
---
 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

  parent reply	other threads:[~2010-10-25 20:07 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-25 20:06 [Qemu-devel] [RFC 0/2]: QMP: Human Monitor passthrough Luiz Capitulino
2010-10-25 20:06 ` [Qemu-devel] [PATCH 1/2] qemu-char: Introduce Buffered driver Luiz Capitulino
2010-11-10  9:26   ` Markus Armbruster
2010-11-10 12:32     ` Luiz Capitulino
2010-11-10 12:56       ` Markus Armbruster
2010-11-10 13:12         ` Luiz Capitulino
2010-11-10 13:33           ` Markus Armbruster
2010-11-10 13:43             ` Luiz Capitulino
2010-10-25 20:06 ` Luiz Capitulino [this message]
2010-11-10 10:03   ` [Qemu-devel] [PATCH 2/2] QMP: Introduce Human Monitor passthrough command Markus Armbruster
2010-11-10 12:42     ` Luiz Capitulino
2010-10-27 19:37 ` [Qemu-devel] [RFC 0/2]: QMP: Human Monitor passthrough Anthony Liguori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1288037204-27768-3-git-send-email-lcapitulino@redhat.com \
    --to=lcapitulino@redhat.com \
    --cc=aliguori@us.ibm.com \
    --cc=armbru@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).