Patchwork [16/22] vl: add a new -qmp2 option to expose experimental QMP server

login
register
mail settings
Submitter Anthony Liguori
Date March 7, 2011, 1:22 a.m.
Message ID <1299460984-15849-17-git-send-email-aliguori@us.ibm.com>
Download mbox | patch
Permalink /patch/85624/
State New
Headers show

Comments

Anthony Liguori - March 7, 2011, 1:22 a.m.
This is temporary until we implement all QMP commands.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>

Patch

diff --git a/qemu-options.hx b/qemu-options.hx
index badb730..957d935 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -1881,6 +1881,9 @@  serial port).
 The default device is @code{vc} in graphical mode and @code{stdio} in
 non graphical mode.
 ETEXI
+DEF("qmp2", HAS_ARG, QEMU_OPTION_qmp2, \
+    "-qmp2 chardev   experimental QMP server\n",
+    QEMU_ARCH_ALL)
 DEF("qmp", HAS_ARG, QEMU_OPTION_qmp, \
     "-qmp dev        like -monitor but opens in 'control' mode\n",
     QEMU_ARCH_ALL)
diff --git a/vl.c b/vl.c
index 68c6715..d1d0197 100644
--- a/vl.c
+++ b/vl.c
@@ -162,6 +162,7 @@  int main(int argc, char **argv)
 #include "qemu-queue.h"
 #include "cpus.h"
 #include "arch_init.h"
+#include "qmp-core.h"
 
 #include "ui/qemu-spice.h"
 
@@ -1917,6 +1918,8 @@  static const QEMUOption *lookup_opt(int argc, char **argv,
     return popt;
 }
 
+#define MAX_QMP_CHARDEVS 16
+
 int main(int argc, char **argv, char **envp)
 {
     const char *gdbstub_dev = NULL;
@@ -1941,6 +1944,8 @@  int main(int argc, char **argv, char **envp)
     const char *incoming = NULL;
     int show_vnc_port = 0;
     int defconfig = 1;
+    int nb_qmp_chardevs = 0;
+    const char *qmp_chardevs[MAX_QMP_CHARDEVS];
 
 #ifdef CONFIG_SIMPLE_TRACE
     const char *trace_file = NULL;
@@ -2391,6 +2396,13 @@  int main(int argc, char **argv, char **envp)
                 monitor_parse(optarg, "control");
                 default_monitor = 0;
                 break;
+            case QEMU_OPTION_qmp2:
+                if (nb_qmp_chardevs == MAX_QMP_CHARDEVS) {
+                    fprintf(stderr, "-qmp: too many QMP chardevs\n");
+                    exit(1);
+                }
+                qmp_chardevs[nb_qmp_chardevs++] = optarg;
+                break;
             case QEMU_OPTION_mon:
                 opts = qemu_opts_parse(qemu_find_opts("mon"), optarg, 1);
                 if (!opts) {
@@ -3092,6 +3104,15 @@  int main(int argc, char **argv, char **envp)
     }
 #endif
 
+    for (i = 0; i < nb_qmp_chardevs; i++) {
+        CharDriverState *chr = qemu_chr_find(qmp_chardevs[i]);
+        if (chr == NULL) {
+            fprintf(stderr, "-qmp: unknown chardev `%s'\n", qmp_chardevs[i]);
+            exit(1);
+        }
+        qmp_init_chardev(chr);
+    }
+
     /* display setup */
     dpy_resize(ds);
     dcl = ds->listeners;