Skip to contentSkip to conversation

: Monitor queue

GIT PULL New Luiz Capitulino 2 participants 25 messages Oct 1, 2010 – Oct 5, 2010 Kbuild

lore
Share & tools
lore
#0 lore raw

Hi Anthony,

The following patches have been sent to the list and look good to me, I've also tested them.

The changes (since 2c50e26efdb7e405ecacf89e6a57a60179226dd8) are available in the following repository:

git://repo.or.cz/qemu/qmp-unstable.git for-anthony

Daniel P. Berrange (2):
Add support for JSON pretty printing
Add option to turn on JSON pretty printing in monitor

Eduardo Habkost (1):
disable guest-provided stats on "info balloon" command

Luiz Capitulino (20):
Monitor: Introduce search_dispatch_table()
QMP: handle_qmp_command(): Move 'cmd' sanity check
QMP: Don't use do_info()
Monitor: Drop QMP bits from do_info()
Monitor: Drop is_async_return()
Monitor: Convert do_info() back to HMP
Monitor: Introduce the qmp-commands.hx file
QMP: Introduce qmp_find_cmd()
QMP: Introduce command dispatch table
QMP: Introduce query commands dispatch table
QMP: Simplify do_info_commands()
QMP: Small cleanup in handle_qmp_command()
Monitor: Drop QMP info from the qemu-monitor.hx file
Monitor: Drop monitor_cmd_user_only()
Monitor: Rename monitor_handler_ported()
Monitor: Rename monitor_handler_is_async()
Monitor: Directly call QObject handlers
QMP: Introduce qmp_call_cmd()
Monitor: Rename the qemu-monitor.hx file QMP/README: Update QMP homepage address

 Makefile            |    4 +-
 Makefile.target     |    9 +-
 QMP/README          |    4 +-
 hmp-commands.hx     | 1216 ++++++++++++++++++++++++
 hw/virtio-balloon.c |    8 +-
 monitor.c           |  366 +++++---
 monitor.h           |    2 +-
 qemu-config.c       |    3 +
 qemu-monitor.hx     | 2575 ---------------------------------------------------
 qjson.c             |   55 +-
 qjson.h             |    1 +
 qmp-commands.hx     | 1541 ++++++++++++++++++++++++++++++
 vl.c                |    3 +
 13 files changed, 3061 insertions(+), 2726 deletions(-)
#1 lore raw

PATCH 1/23 Add support for JSON pretty printing

From: Daniel P. Berrange <[email protected]>

The monitor does not pretty-print JSON output, so that everything will be on a single line reply. When JSON docs get large this is quite unpleasant to read. For the future command line capabilities query ability, huge JSON docs will be available. This needs the ability to pretty-print.

This introduces a new API qobject_to_json_pretty() that does a minimal indentation of list and dict members. As an example, this makes

{"QMP": {"version": {"micro": 50, "minor": 12, "package": "", "major": 0}, "capabilities": []}}

Output as

  {
      "QMP": {
          "version": {
              "micro": 50,
              "minor": 12,
              "package": "",
              "major": 0
          },
          "capabilities": [
          ]
      }
  }

NB: this is not turned on for the QMP monitor.

---
 qjson.c |   55 +++++++++++++++++++++++++++++++++++++++++++++++--------
 qjson.h |    1 +
 2 files changed, 48 insertions(+), 8 deletions(-)
qjson.c +47 -8
index e4ee433..f9c8e77 100644
@@ -72,43 +72,57 @@ QObject *qobject_from_jsonf(const char *string, ...)
 
 typedef struct ToJsonIterState
 {
+    int indent;
+    int pretty;
     int count;
     QString *str;
 } ToJsonIterState;
 
-static void to_json(const QObject *obj, QString *str);
+static void to_json(const QObject *obj, QString *str, int pretty, int indent);
 
 static void to_json_dict_iter(const char *key, QObject *obj, void *opaque)
 {
     ToJsonIterState *s = opaque;
     QString *qkey;
+    int j;
 
-    if (s->count) {
+    if (s->count)
         qstring_append(s->str, ", ");
+
+    if (s->pretty) {
+        qstring_append(s->str, "\n");
+        for (j = 0 ; j < s->indent ; j++)
+            qstring_append(s->str, "    ");
     }
 
     qkey = qstring_from_str(key);
-    to_json(QOBJECT(qkey), s->str);
+    to_json(QOBJECT(qkey), s->str, s->pretty, s->indent);
     QDECREF(qkey);
 
     qstring_append(s->str, ": ");
-    to_json(obj, s->str);
+    to_json(obj, s->str, s->pretty, s->indent);
     s->count++;
 }
 
 static void to_json_list_iter(QObject *obj, void *opaque)
 {
     ToJsonIterState *s = opaque;
+    int j;
 
-    if (s->count) {
+    if (s->count)
         qstring_append(s->str, ", ");
+
+    if (s->pretty) {
+        qstring_append(s->str, "\n");
+        for (j = 0 ; j < s->indent ; j++)
+            qstring_append(s->str, "    ");
     }
 
-    to_json(obj, s->str);
+    to_json(obj, s->str, s->pretty, s->indent);
     s->count++;
 }
 
-static void to_json(const QObject *obj, QString *str)
+static void to_json(const QObject *obj, QString *str, int pretty, int indent)
 {
     switch (qobject_type(obj)) {
     case QTYPE_QINT: {
@@ -193,8 +207,16 @@ static void to_json(const QObject *obj, QString *str)
 
         s.count = 0;
         s.str = str;
+        s.indent = indent + 1;
+        s.pretty = pretty;
         qstring_append(str, "{");
         qdict_iter(val, to_json_dict_iter, &s);
+        if (pretty) {
+            int j;
+            qstring_append(str, "\n");
+            for (j = 0 ; j < indent ; j++)
+                qstring_append(str, "    ");
+        }
         qstring_append(str, "}");
         break;
     }
@@ -204,8 +226,16 @@ static void to_json(const QObject *obj, QString *str)
 
         s.count = 0;
         s.str = str;
+        s.indent = indent + 1;
+        s.pretty = pretty;
         qstring_append(str, "[");
         qlist_iter(val, (void *)to_json_list_iter, &s);
+        if (pretty) {
+            int j;
+            qstring_append(str, "\n");
+            for (j = 0 ; j < indent ; j++)
+                qstring_append(str, "    ");
+        }
         qstring_append(str, "]");
         break;
     }
@@ -249,7 +279,16 @@ QString *qobject_to_json(const QObject *obj)
 {
     QString *str = qstring_new();
 
-    to_json(obj, str);
+    to_json(obj, str, 0, 0);
+
+    return str;
+}
+
+QString *qobject_to_json_pretty(const QObject *obj)
+{
+    QString *str = qstring_new();
+
+    to_json(obj, str, 1, 0);
 
     return str;
 }
qjson.h +1 -0
index 7afec2e..cd60e0b 100644
@@ -24,5 +24,6 @@ QObject *qobject_from_jsonf(const char *string, ...)
 QObject *qobject_from_jsonv(const char *string, va_list *ap);
 
 QString *qobject_to_json(const QObject *obj);
+QString *qobject_to_json_pretty(const QObject *obj);
 
 #endif /* QJSON_H */
Signature · 1 line
1.7.3.1.50.g1e633
#2 lore raw

PATCH 2/23 Add option to turn on JSON pretty printing in monitor

In reply to Luiz Capitulino

From: Daniel P. Berrange <[email protected]>

Expaned '-mon' arg to allow a 'pretty=on' flag. This makes the monitor pretty print its replies to easy human debugging / reading

---
 monitor.c     |    5 ++++-
 monitor.h     |    1 +
 qemu-config.c |    3 +++
 vl.c          |    3 +++
 4 files changed, 11 insertions(+), 1 deletions(-)
monitor.c +4 -1
index e602480..a33cdc2 100644
@@ -351,7 +351,10 @@ static void monitor_json_emitter(Monitor *mon, const QObject *data)
 {
     QString *json;
 
-    json = qobject_to_json(data);
+    if (mon->flags & MONITOR_USE_PRETTY)
+	json = qobject_to_json_pretty(data);
+    else
+	json = qobject_to_json(data);
     assert(json != NULL);
 
     qstring_append_chr(json, '\n');
monitor.h +1 -0
index 38b22a4..f2122b5 100644
@@ -14,6 +14,7 @@ extern Monitor *default_mon;
 #define MONITOR_IS_DEFAULT    0x01
 #define MONITOR_USE_READLINE  0x02
 #define MONITOR_USE_CONTROL   0x04
+#define MONITOR_USE_PRETTY    0x08
 
 /* flags for monitor commands */
 #define MONITOR_CMD_ASYNC       0x0001
qemu-config.c +3 -0
index e3b746c..6052a28 100644
@@ -283,6 +283,9 @@ static QemuOptsList qemu_mon_opts = {
         },{
             .name = "default",
             .type = QEMU_OPT_BOOL,
+        },{
+            .name = "pretty",
+            .type = QEMU_OPT_BOOL,
         },
         { /* end of list */ }
     },
vl.c +3 -0
index d352d18..939ee87 100644
@@ -1562,6 +1562,9 @@ static int mon_init_func(QemuOpts *opts, void *opaque)
         exit(1);
     }
 
+    if (qemu_opt_get_bool(opts, "pretty", 0))
+        flags |= MONITOR_USE_PRETTY;
+
     if (qemu_opt_get_bool(opts, "default", 0))
         flags |= MONITOR_IS_DEFAULT;
 
Signature · 1 line
1.7.3.1.50.g1e633
#3 lore raw

PATCH 3/23 disable guest-provided stats on "info balloon" command

In reply to Luiz Capitulino

From: Eduardo Habkost <[email protected]>

The addition of memory stats reporting to the virtio balloon causes the 'info balloon' command to become asynchronous. This is a regression because in some cases it can hang the user monitor.

This is an alternative to Adam Litke's patch. Adam's patch disabled the corresponding (guest-visible) virtio feature bit, causing issues for migration. Original discussion is available at:
http://marc.info/?l=qemu-devel&m=128448124328314&w=2

---
 hw/virtio-balloon.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
hw/virtio-balloon.c +7 -1
index 1e74674..8adddea 100644
@@ -29,6 +29,10 @@
 #include <sys/mman.h>
 #endif
 
+/* Disable guest-provided stats by now (https://bugzilla.redhat.com/show_bug.cgi?id=623903) */
+#define ENABLE_GUEST_STATS   0
+
+
 typedef struct VirtIOBalloon
 {
     VirtIODevice vdev;
@@ -83,12 +87,14 @@ static QObject *get_stats_qobject(VirtIOBalloon *dev)
                                   VIRTIO_BALLOON_PFN_SHIFT);
 
     stat_put(dict, "actual", actual);
+#if ENABLE_GUEST_STATS
     stat_put(dict, "mem_swapped_in", dev->stats[VIRTIO_BALLOON_S_SWAP_IN]);
     stat_put(dict, "mem_swapped_out", dev->stats[VIRTIO_BALLOON_S_SWAP_OUT]);
     stat_put(dict, "major_page_faults", dev->stats[VIRTIO_BALLOON_S_MAJFLT]);
     stat_put(dict, "minor_page_faults", dev->stats[VIRTIO_BALLOON_S_MINFLT]);
     stat_put(dict, "free_mem", dev->stats[VIRTIO_BALLOON_S_MEMFREE]);
     stat_put(dict, "total_mem", dev->stats[VIRTIO_BALLOON_S_MEMTOT]);
+#endif
 
     return QOBJECT(dict);
 }
@@ -214,7 +220,7 @@ static void virtio_balloon_to_target(void *opaque, ram_addr_t target,
         }
         dev->stats_callback = cb;
         dev->stats_opaque_callback_data = cb_data; 
-        if (dev->vdev.guest_features & (1 << VIRTIO_BALLOON_F_STATS_VQ)) {
+        if (ENABLE_GUEST_STATS && (dev->vdev.guest_features & (1 << VIRTIO_BALLOON_F_STATS_VQ))) {
             virtqueue_push(dev->svq, &dev->stats_vq_elem, dev->stats_vq_offset);
             virtio_notify(&dev->vdev, dev->svq);
         } else {
Signature · 1 line
1.7.3.1.50.g1e633
#4 lore raw

PATCH 4/23 Monitor: Introduce search_dispatch_table()

In reply to Luiz Capitulino

It's a generic version of monitor_find_command() which searches the dispatch table passed as an argument.

Future commits will introduce new dispatch tables, so we need common code to search them.

---
 monitor.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)
monitor.c +8 -2
index a33cdc2..da76eab 100644
@@ -3371,11 +3371,12 @@ static int is_valid_option(const char *c, const char *typestr)
     return (typestr != NULL);
 }
 
-static const mon_cmd_t *monitor_find_command(const char *cmdname)
+static const mon_cmd_t *search_dispatch_table(const mon_cmd_t *disp_table,
+                                              const char *cmdname)
 {
     const mon_cmd_t *cmd;
 
-    for (cmd = mon_cmds; cmd->name != NULL; cmd++) {
+    for (cmd = disp_table; cmd->name != NULL; cmd++) {
         if (compare_cmd(cmdname, cmd->name)) {
             return cmd;
         }
@@ -3384,6 +3385,11 @@ static const mon_cmd_t *monitor_find_command(const char *cmdname)
     return NULL;
 }
 
+static const mon_cmd_t *monitor_find_command(const char *cmdname)
+{
+    return search_dispatch_table(mon_cmds, cmdname);
+}
+
 static const mon_cmd_t *monitor_parse_command(Monitor *mon,
                                               const char *cmdline,
                                               QDict *qdict)
Signature · 1 line
1.7.3.1.50.g1e633
#5 lore raw

PATCH 5/23 QMP: handle_qmp_command(): Move 'cmd' sanity check

In reply to Luiz Capitulino

Next commit will change how query commands are handled in a way that the 'cmd' sanity check is also going to be needed for query commands handling.

Let's move it out of the else body then.

---
 monitor.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
monitor.c +5 -5
index da76eab..2efff8a 100644
@@ -4375,11 +4375,11 @@ static void handle_qmp_command(JSONMessageParser *parser, QList *tokens)
                       qobject_from_jsonf("{ 'item': %s }", info_item));
     } else {
         cmd = monitor_find_command(cmd_name);
-        if (!cmd || !monitor_handler_ported(cmd)
-            || monitor_cmd_user_only(cmd)) {
-            qerror_report(QERR_COMMAND_NOT_FOUND, cmd_name);
-            goto err_out;
-        }
+    }
+
+    if (!cmd || !monitor_handler_ported(cmd) || monitor_cmd_user_only(cmd)) {
+        qerror_report(QERR_COMMAND_NOT_FOUND, cmd_name);
+        goto err_out;
     }
 
     obj = qdict_get(input, "arguments");
Signature · 1 line
1.7.3.1.50.g1e633
#6 lore raw

PATCH 6/23 QMP: Don't use do_info()

In reply to Luiz Capitulino

Since its inception, QMP has been using HMP's do_info() function to run query commands.

This was a bad choice, as it made do_info() more complex and contributed to couple QMP and HMP.

This commit fixes that by doing the following changes:

1. Introduce qmp_find_query_cmd() and use it to directly lookup the info_cmds table

2. Introduce qmp_call_query_cmd() so that QMP code is able to call query handlers without using do_info()

3. Drop do_info() usage (via monitor_find_command("info"))

We need all the three changes in one shot so that we don't break the calling of query commands in QMP.

---
 monitor.c |   39 +++++++++++++++++++++++++++++++--------
 1 files changed, 31 insertions(+), 8 deletions(-)
monitor.c +31 -8
index 2efff8a..ff65f38 100644
@@ -3390,6 +3390,11 @@ static const mon_cmd_t *monitor_find_command(const char *cmdname)
     return search_dispatch_table(mon_cmds, cmdname);
 }
 
+static const mon_cmd_t *qmp_find_query_cmd(const char *info_item)
+{
+    return search_dispatch_table(info_cmds, info_item);
+}
+
 static const mon_cmd_t *monitor_parse_command(Monitor *mon,
                                               const char *cmdline,
                                               QDict *qdict)
@@ -4329,6 +4334,24 @@ static QDict *qmp_check_input_obj(QObject *input_obj)
     return input_dict;
 }
 
+static void qmp_call_query_cmd(Monitor *mon, const mon_cmd_t *cmd)
+{
+    QObject *ret_data = NULL;
+
+    if (monitor_handler_is_async(cmd)) {
+        qmp_async_info_handler(mon, cmd);
+        if (monitor_has_error(mon)) {
+            monitor_protocol_emitter(mon, NULL);
+        }
+    } else {
+        cmd->mhandler.info_new(mon, &ret_data);
+        if (ret_data) {
+            monitor_protocol_emitter(mon, ret_data);
+            qobject_decref(ret_data);
+        }
+    }
+}
+
 static void handle_qmp_command(JSONMessageParser *parser, QList *tokens)
 {
     int err;
@@ -4336,8 +4359,9 @@ static void handle_qmp_command(JSONMessageParser *parser, QList *tokens)
     QDict *input, *args;
     const mon_cmd_t *cmd;
     Monitor *mon = cur_mon;
-    const char *cmd_name, *info_item;
+    const char *cmd_name, *query_cmd;
 
+    query_cmd = NULL;
     args = input = NULL;
 
     obj = json_parser_parse(tokens, NULL);
@@ -4363,16 +4387,13 @@ static void handle_qmp_command(JSONMessageParser *parser, QList *tokens)
     }
 
     /*
-     * XXX: We need this special case until we get info handlers
-     * converted into 'query-' commands
+     * XXX: We need this special case until QMP has its own dispatch table
      */
     if (compare_cmd(cmd_name, "info")) {
         qerror_report(QERR_COMMAND_NOT_FOUND, cmd_name);
         goto err_out;
-    } else if (strstart(cmd_name, "query-", &info_item)) {
-        cmd = monitor_find_command("info");
-        qdict_put_obj(input, "arguments",
-                      qobject_from_jsonf("{ 'item': %s }", info_item));
+    } else if (strstart(cmd_name, "query-", &query_cmd)) {
+        cmd = qmp_find_query_cmd(query_cmd);
     } else {
         cmd = monitor_find_command(cmd_name);
     }
@@ -4395,7 +4416,9 @@ static void handle_qmp_command(JSONMessageParser *parser, QList *tokens)
         goto err_out;
     }
 
-    if (monitor_handler_is_async(cmd)) {
+    if (query_cmd) {
+        qmp_call_query_cmd(mon, cmd);
+    } else if (monitor_handler_is_async(cmd)) {
         err = qmp_async_cmd_handler(mon, cmd, args);
         if (err) {
             /* emit the error response */
Signature · 1 line
1.7.3.1.50.g1e633
#7 lore raw

PATCH 7/23 Monitor: Drop QMP bits from do_info()

In reply to Luiz Capitulino

As of last commit, QMP doesn't use do_info() anymore. Simplify it.

---
 monitor.c |   39 ++++++++-------------------------------
 1 files changed, 8 insertions(+), 31 deletions(-)
monitor.c +7 -30
index ff65f38..4fc0ad3 100644
@@ -642,7 +642,6 @@ static int do_info(Monitor *mon, const QDict *qdict, QObject **ret_data)
     const char *item = qdict_get_try_str(qdict, "item");
 
     if (!item) {
-        assert(monitor_ctrl_mode(mon) == 0);
         goto help;
     }
 
@@ -652,24 +651,11 @@ static int do_info(Monitor *mon, const QDict *qdict, QObject **ret_data)
     }
 
     if (cmd->name == NULL) {
-        if (monitor_ctrl_mode(mon)) {
-            qerror_report(QERR_COMMAND_NOT_FOUND, item);
-            return -1;
-        }
         goto help;
     }
 
-    if (monitor_ctrl_mode(mon) && monitor_cmd_user_only(cmd)) {
-        qerror_report(QERR_COMMAND_NOT_FOUND, item);
-        return -1;
-    }
-
     if (monitor_handler_is_async(cmd)) {
-        if (monitor_ctrl_mode(mon)) {
-            qmp_async_info_handler(mon, cmd);
-        } else {
-            user_async_info_handler(mon, cmd);
-        }
+        user_async_info_handler(mon, cmd);
         /*
          * Indicate that this command is asynchronous and will not return any
          * data (not even empty).  Instead, the data will be returned via a
@@ -677,24 +663,15 @@ static int do_info(Monitor *mon, const QDict *qdict, QObject **ret_data)
          */
         *ret_data = qobject_from_jsonf("{ '__mon_async': 'return' }");
     } else if (monitor_handler_ported(cmd)) {
-        cmd->mhandler.info_new(mon, ret_data);
+        QObject *info_data = NULL;
 
-        if (!monitor_ctrl_mode(mon)) {
-            /*
-             * User Protocol function is called here, Monitor Protocol is
-             * handled by monitor_call_handler()
-             */
-            if (*ret_data)
-                cmd->user_print(mon, *ret_data);
+        cmd->mhandler.info_new(mon, &info_data);
+        if (info_data) {
+            cmd->user_print(mon, info_data);
+            qobject_decref(info_data);
         }
     } else {
-        if (monitor_ctrl_mode(mon)) {
-            /* handler not converted yet */
-            qerror_report(QERR_COMMAND_NOT_FOUND, item);
-            return -1;
-        } else {
-            cmd->mhandler.info(mon);
-        }
+        cmd->mhandler.info(mon);
     }
 
     return 0;
Signature · 1 line
1.7.3.1.50.g1e633
#8 lore raw

PATCH 8/23 Monitor: Drop is_async_return()

In reply to Luiz Capitulino

If I understood it correcty, the is_async_return() logic was only used to prevent QMP from issuing duplicated success responses for asynchronous handlers.

However, QMP doesn't use do_info() anymore so this is dead logic and (hopefully) can be safely dropped.

---
 monitor.c |   25 +------------------------
 1 files changed, 1 insertions(+), 24 deletions(-)
monitor.c +1 -24
index 4fc0ad3..7f2af49 100644
@@ -656,12 +656,6 @@ static int do_info(Monitor *mon, const QDict *qdict, QObject **ret_data)
 
     if (monitor_handler_is_async(cmd)) {
         user_async_info_handler(mon, cmd);
-        /*
-         * Indicate that this command is asynchronous and will not return any
-         * data (not even empty).  Instead, the data will be returned via a
-         * completion callback.
-         */
-        *ret_data = qobject_from_jsonf("{ '__mon_async': 'return' }");
     } else if (monitor_handler_ported(cmd)) {
         QObject *info_data = NULL;
 
@@ -3720,15 +3714,6 @@ void monitor_set_error(Monitor *mon, QError *qerror)
     }
 }
 
-static int is_async_return(const QObject *data)
-{
-    if (data && qobject_type(data) == QTYPE_QDICT) {
-        return qdict_haskey(qobject_to_qdict(data), "__mon_async");
-    }
-
-    return 0;
-}
-
 static void handler_audit(Monitor *mon, const mon_cmd_t *cmd, int ret)
 {
     if (monitor_ctrl_mode(mon)) {
@@ -3787,15 +3772,7 @@ static void monitor_call_handler(Monitor *mon, const mon_cmd_t *cmd,
     ret = cmd->mhandler.cmd_new(mon, params, &data);
     handler_audit(mon, cmd, ret);
 
-    if (is_async_return(data)) {
-        /*
-         * Asynchronous commands have no initial return data but they can
-         * generate errors.  Data is returned via the async completion handler.
-         */
-        if (monitor_ctrl_mode(mon) && monitor_has_error(mon)) {
-            monitor_protocol_emitter(mon, NULL);
-        }
-    } else if (monitor_ctrl_mode(mon)) {
+    if (monitor_ctrl_mode(mon)) {
         /* Monitor Protocol */
         monitor_protocol_emitter(mon, data);
     } else {
Signature · 1 line
1.7.3.1.50.g1e633
#9 lore raw

PATCH 9/23 Monitor: Convert do_info() back to HMP

In reply to Luiz Capitulino

This is a HMP specific handler, it makes no sense to have it under QMP.

---
 monitor.c       |    5 ++---
 qemu-monitor.hx |    3 +--
 2 files changed, 3 insertions(+), 5 deletions(-)
monitor.c +2 -3
index 7f2af49..f0854c4 100644
@@ -636,7 +636,7 @@ static void user_async_info_handler(Monitor *mon, const mon_cmd_t *cmd)
     }
 }
 
-static int do_info(Monitor *mon, const QDict *qdict, QObject **ret_data)
+static void do_info(Monitor *mon, const QDict *qdict)
 {
     const mon_cmd_t *cmd;
     const char *item = qdict_get_try_str(qdict, "item");
@@ -668,11 +668,10 @@ static int do_info(Monitor *mon, const QDict *qdict, QObject **ret_data)
         cmd->mhandler.info(mon);
     }
 
-    return 0;
+    return;
 
 help:
     help_cmd(mon, "info");
-    return 0;
 }
 
 static void do_info_version_print(Monitor *mon, const QObject *data)
qemu-monitor.hx +1 -2
index 49bcd8d..57d28ac 100644
@@ -1654,8 +1654,7 @@ EQMP
         .args_type  = "item:s?",
         .params     = "[subcommand]",
         .help       = "show various information about the system state",
-        .user_print = monitor_user_noop,
-        .mhandler.cmd_new = do_info,
+        .mhandler.cmd = do_info,
     },
 
 STEXI
Signature · 1 line
1.7.3.1.50.g1e633
#10 lore raw

PATCH 10/23 Monitor: Introduce the qmp-commands.hx file

In reply to Luiz Capitulino

This file contains a copy of the following information from the qemu-monitor.hx file:

o QObject handlers entries
o QMP documentation (all SQMP/EQMP sections)

Right now it's only used to generate the QMP docs in QMP/, but next commits will turn this into QMP's command dispatch table.

It's important to note that QObject handlers entries are going to get duplicated: they will exist in both QMP's and HMP's dispatch tables.

This will be fixed in the near future, when we add a proper QMP call interface and HMP is converted to use it. This way we can completely drop QObject handlers entries from HMP's tables.

NOTE: HMP specific constructions, like "q|quit", have been dropped.

---
 Makefile        |    2 +-
 QMP/README      |    2 +-
 qmp-commands.hx | 1541 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 1543 insertions(+), 2 deletions(-)
 create mode 100644 qmp-commands.hx
Makefile +1 -1
index fca1e7a..938d88b 100644
@@ -252,7 +252,7 @@ qemu-options.texi: $(SRC_PATH)/qemu-options.hx
 qemu-monitor.texi: $(SRC_PATH)/qemu-monitor.hx
 	$(call quiet-command,sh $(SRC_PATH)/hxtool -t < $< > $@,"  GEN   $@")
 
-QMP/qmp-commands.txt: $(SRC_PATH)/qemu-monitor.hx
+QMP/qmp-commands.txt: $(SRC_PATH)/qmp-commands.hx
 	$(call quiet-command,sh $(SRC_PATH)/hxtool -q < $< > $@,"  GEN   $@")
 
 qemu-img-cmds.texi: $(SRC_PATH)/qemu-img-cmds.hx
QMP/README +1 -1
index 948d445..7e2b51a 100644
@@ -82,7 +82,7 @@ doing any code change. This is so because:
   2. Review can improve your interface.  Letting that happen before
      you implement it can save you work.
 
-* The qmp-commands.txt file is generated from the qemu-monitor.hx one, which
+* The qmp-commands.txt file is generated from the qmp-commands.hx one, which
   is the file that should be edited.
 
 Homepage
qmp-commands.hx new file +1541 -0

1,541 lines not on this page · raw message

Signature · 1 line
1.7.3.1.50.g1e633
#11 lore raw

PATCH 11/23 QMP: Introduce qmp_find_cmd()

In reply to Luiz Capitulino

Next commit needs this new function: it will introduce the the QMP's command dispatch table and qmp_find_cmd() will be used to search on it.

---
 monitor.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
monitor.c +6 -1
index f0854c4..f62c34a 100644
@@ -3365,6 +3365,11 @@ static const mon_cmd_t *qmp_find_query_cmd(const char *info_item)
     return search_dispatch_table(info_cmds, info_item);
 }
 
+static const mon_cmd_t *qmp_find_cmd(const char *cmdname)
+{
+    return search_dispatch_table(mon_cmds, cmdname);
+}
+
 static const mon_cmd_t *monitor_parse_command(Monitor *mon,
                                               const char *cmdline,
                                               QDict *qdict)
@@ -4348,7 +4353,7 @@ static void handle_qmp_command(JSONMessageParser *parser, QList *tokens)
     } else if (strstart(cmd_name, "query-", &query_cmd)) {
         cmd = qmp_find_query_cmd(query_cmd);
     } else {
-        cmd = monitor_find_command(cmd_name);
+        cmd = qmp_find_cmd(cmd_name);
     }
 
     if (!cmd || !monitor_handler_ported(cmd) || monitor_cmd_user_only(cmd)) {
Signature · 1 line
1.7.3.1.50.g1e633
#12 lore raw

PATCH 12/23 QMP: Introduce command dispatch table

In reply to Luiz Capitulino

Also update QMP functions to use it. The table is generated from the qmp-commands.hx file.

Quoted 1 line

From now on, QMP and HMP have different command dispatch

tables.

---
 Makefile.target |    7 +++++--
 monitor.c       |   11 +++++++++--
 2 files changed, 14 insertions(+), 4 deletions(-)
Makefile.target +5 -2
index 91d0381..3a1fa7e 100644
@@ -307,7 +307,7 @@ obj-alpha-y = alpha_palcode.o
 
 main.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
 
-monitor.o: qemu-monitor.h
+monitor.o: qemu-monitor.h qmp-commands.h
 
 $(obj-y) $(obj-$(TARGET_BASE_ARCH)-y): $(GENERATED_HEADERS)
 
@@ -331,10 +331,13 @@ gdbstub-xml.c: $(TARGET_XML_FILES) $(SRC_PATH)/feature_to_c.sh
 qemu-monitor.h: $(SRC_PATH)/qemu-monitor.hx
 	$(call quiet-command,sh $(SRC_PATH)/hxtool -h < $< > $@,"  GEN   $(TARGET_DIR)$@")
 
+qmp-commands.h: $(SRC_PATH)/qmp-commands.hx
+	$(call quiet-command,sh $(SRC_PATH)/hxtool -h < $< > $@,"  GEN   $(TARGET_DIR)$@")
+
 clean:
 	rm -f *.o *.a *~ $(PROGS) nwfpe/*.o fpu/*.o
 	rm -f *.d */*.d tcg/*.o ide/*.o
-	rm -f qemu-monitor.h gdbstub-xml.c
+	rm -f qemu-monitor.h qmp-commands.h gdbstub-xml.c
 
 install: all
 ifneq ($(PROGS),)
monitor.c +9 -2
index f62c34a..06141a5 100644
@@ -189,6 +189,8 @@ static QLIST_HEAD(mon_list, Monitor) mon_list;
 static const mon_cmd_t mon_cmds[];
 static const mon_cmd_t info_cmds[];
 
+static const mon_cmd_t qmp_cmds[];
+
 Monitor *cur_mon;
 Monitor *default_mon;
 
@@ -745,7 +747,7 @@ static void do_info_commands(Monitor *mon, QObject **ret_data)
 
     cmd_list = qlist_new();
 
-    for (cmd = mon_cmds; cmd->name != NULL; cmd++) {
+    for (cmd = qmp_cmds; cmd->name != NULL; cmd++) {
         if (monitor_handler_ported(cmd) && !monitor_cmd_user_only(cmd) &&
             !compare_cmd(cmd->name, "info")) {
             qlist_append_obj(cmd_list, get_cmd_dict(cmd->name));
@@ -2635,6 +2637,11 @@ static const mon_cmd_t info_cmds[] = {
     },
 };
 
+static const mon_cmd_t qmp_cmds[] = {
+#include "qmp-commands.h"
+    { /* NULL */ },
+};
+
 /*******************************************************************/
 
 static const char *pch;
@@ -3367,7 +3374,7 @@ static const mon_cmd_t *qmp_find_query_cmd(const char *info_item)
 
 static const mon_cmd_t *qmp_find_cmd(const char *cmdname)
 {
-    return search_dispatch_table(mon_cmds, cmdname);
+    return search_dispatch_table(qmp_cmds, cmdname);
 }
 
 static const mon_cmd_t *monitor_parse_command(Monitor *mon,
Signature · 1 line
1.7.3.1.50.g1e633
#13 lore raw

PATCH 13/23 QMP: Introduce query commands dispatch table

In reply to Luiz Capitulino

The new table is a copy of HMP's table, containing only QObject handlers.

In the near future HMP will be making QMP calls and then we will be able to drop QObject handlers from HMP's table.

Quoted 1 line

From now on, QMP and HMP have different query command dispatch

tables.

---
 monitor.c |  130 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 128 insertions(+), 2 deletions(-)
monitor.c +128 -2
index 06141a5..bf5da50 100644
@@ -190,6 +190,7 @@ static const mon_cmd_t mon_cmds[];
 static const mon_cmd_t info_cmds[];
 
 static const mon_cmd_t qmp_cmds[];
+static const mon_cmd_t qmp_query_cmds[];
 
 Monitor *cur_mon;
 Monitor *default_mon;
@@ -754,7 +755,7 @@ static void do_info_commands(Monitor *mon, QObject **ret_data)
         }
     }
 
-    for (cmd = info_cmds; cmd->name != NULL; cmd++) {
+    for (cmd = qmp_query_cmds; cmd->name != NULL; cmd++) {
         if (monitor_handler_ported(cmd) && !monitor_cmd_user_only(cmd)) {
             char buf[128];
             snprintf(buf, sizeof(buf), "query-%s", cmd->name);
@@ -2642,6 +2643,131 @@ static const mon_cmd_t qmp_cmds[] = {
     { /* NULL */ },
 };
 
+static const mon_cmd_t qmp_query_cmds[] = {
+    {
+        .name       = "version",
+        .args_type  = "",
+        .params     = "",
+        .help       = "show the version of QEMU",
+        .user_print = do_info_version_print,
+        .mhandler.info_new = do_info_version,
+    },
+    {
+        .name       = "commands",
+        .args_type  = "",
+        .params     = "",
+        .help       = "list QMP available commands",
+        .user_print = monitor_user_noop,
+        .mhandler.info_new = do_info_commands,
+    },
+    {
+        .name       = "chardev",
+        .args_type  = "",
+        .params     = "",
+        .help       = "show the character devices",
+        .user_print = qemu_chr_info_print,
+        .mhandler.info_new = qemu_chr_info,
+    },
+    {
+        .name       = "block",
+        .args_type  = "",
+        .params     = "",
+        .help       = "show the block devices",
+        .user_print = bdrv_info_print,
+        .mhandler.info_new = bdrv_info,
+    },
+    {
+        .name       = "blockstats",
+        .args_type  = "",
+        .params     = "",
+        .help       = "show block device statistics",
+        .user_print = bdrv_stats_print,
+        .mhandler.info_new = bdrv_info_stats,
+    },
+    {
+        .name       = "cpus",
+        .args_type  = "",
+        .params     = "",
+        .help       = "show infos for each CPU",
+        .user_print = monitor_print_cpus,
+        .mhandler.info_new = do_info_cpus,
+    },
+    {
+        .name       = "pci",
+        .args_type  = "",
+        .params     = "",
+        .help       = "show PCI info",
+        .user_print = do_pci_info_print,
+        .mhandler.info_new = do_pci_info,
+    },
+    {
+        .name       = "kvm",
+        .args_type  = "",
+        .params     = "",
+        .help       = "show KVM information",
+        .user_print = do_info_kvm_print,
+        .mhandler.info_new = do_info_kvm,
+    },
+    {
+        .name       = "status",
+        .args_type  = "",
+        .params     = "",
+        .help       = "show the current VM status (running|paused)",
+        .user_print = do_info_status_print,
+        .mhandler.info_new = do_info_status,
+    },
+    {
+        .name       = "mice",
+        .args_type  = "",
+        .params     = "",
+        .help       = "show which guest mouse is receiving events",
+        .user_print = do_info_mice_print,
+        .mhandler.info_new = do_info_mice,
+    },
+    {
+        .name       = "vnc",
+        .args_type  = "",
+        .params     = "",
+        .help       = "show the vnc server status",
+        .user_print = do_info_vnc_print,
+        .mhandler.info_new = do_info_vnc,
+    },
+    {
+        .name       = "name",
+        .args_type  = "",
+        .params     = "",
+        .help       = "show the current VM name",
+        .user_print = do_info_name_print,
+        .mhandler.info_new = do_info_name,
+    },
+    {
+        .name       = "uuid",
+        .args_type  = "",
+        .params     = "",
+        .help       = "show the current VM UUID",
+        .user_print = do_info_uuid_print,
+        .mhandler.info_new = do_info_uuid,
+    },
+    {
+        .name       = "migrate",
+        .args_type  = "",
+        .params     = "",
+        .help       = "show migration status",
+        .user_print = do_info_migrate_print,
+        .mhandler.info_new = do_info_migrate,
+    },
+    {
+        .name       = "balloon",
+        .args_type  = "",
+        .params     = "",
+        .help       = "show balloon information",
+        .user_print = monitor_print_balloon,
+        .mhandler.info_async = do_info_balloon,
+        .flags      = MONITOR_CMD_ASYNC,
+    },
+    { /* NULL */ },
+};
+
 /*******************************************************************/
 
 static const char *pch;
@@ -3369,7 +3495,7 @@ static const mon_cmd_t *monitor_find_command(const char *cmdname)
 
 static const mon_cmd_t *qmp_find_query_cmd(const char *info_item)
 {
-    return search_dispatch_table(info_cmds, info_item);
+    return search_dispatch_table(qmp_query_cmds, info_item);
 }
 
 static const mon_cmd_t *qmp_find_cmd(const char *cmdname)
Signature · 1 line
1.7.3.1.50.g1e633
#14 lore raw

PATCH 14/23 QMP: Simplify do_info_commands()

In reply to Luiz Capitulino

We now iterate over QMP's dispatch tables, no need to check for QMP-only handlers anymore.

---
 monitor.c |   13 ++++---------
 1 files changed, 4 insertions(+), 9 deletions(-)
monitor.c +4 -9
index bf5da50..612ee56 100644
@@ -749,18 +749,13 @@ static void do_info_commands(Monitor *mon, QObject **ret_data)
     cmd_list = qlist_new();
 
     for (cmd = qmp_cmds; cmd->name != NULL; cmd++) {
-        if (monitor_handler_ported(cmd) && !monitor_cmd_user_only(cmd) &&
-            !compare_cmd(cmd->name, "info")) {
-            qlist_append_obj(cmd_list, get_cmd_dict(cmd->name));
-        }
+        qlist_append_obj(cmd_list, get_cmd_dict(cmd->name));
     }
 
     for (cmd = qmp_query_cmds; cmd->name != NULL; cmd++) {
-        if (monitor_handler_ported(cmd) && !monitor_cmd_user_only(cmd)) {
-            char buf[128];
-            snprintf(buf, sizeof(buf), "query-%s", cmd->name);
-            qlist_append_obj(cmd_list, get_cmd_dict(buf));
-        }
+        char buf[128];
+        snprintf(buf, sizeof(buf), "query-%s", cmd->name);
+        qlist_append_obj(cmd_list, get_cmd_dict(buf));
     }
 
     *ret_data = QOBJECT(cmd_list);
Signature · 1 line
1.7.3.1.50.g1e633
#15 lore raw

PATCH 15/23 QMP: Small cleanup in handle_qmp_command()

In reply to Luiz Capitulino

QMP has its own dispatch tables, we can now drop the following checks:

o 'info' command: this command doesn't exist in QMP's dispatch table, the right thing will happen when it's issued by a client (ie. command not found error)

o monitor_handler_ported(): all QMP handlers are 'ported', no need to check for that

o monitor_cmd_user_only(): no HMP handler will exist in QMP's dispatch tables, that's why we have split them after all :-)

---
 monitor.c |   10 ++--------
 1 files changed, 2 insertions(+), 8 deletions(-)
monitor.c +2 -8
index 612ee56..6e62643 100644
@@ -4472,19 +4472,13 @@ static void handle_qmp_command(JSONMessageParser *parser, QList *tokens)
         goto err_out;
     }
 
-    /*
-     * XXX: We need this special case until QMP has its own dispatch table
-     */
-    if (compare_cmd(cmd_name, "info")) {
-        qerror_report(QERR_COMMAND_NOT_FOUND, cmd_name);
-        goto err_out;
-    } else if (strstart(cmd_name, "query-", &query_cmd)) {
+    if (strstart(cmd_name, "query-", &query_cmd)) {
         cmd = qmp_find_query_cmd(query_cmd);
     } else {
         cmd = qmp_find_cmd(cmd_name);
     }
 
-    if (!cmd || !monitor_handler_ported(cmd) || monitor_cmd_user_only(cmd)) {
+    if (!cmd) {
         qerror_report(QERR_COMMAND_NOT_FOUND, cmd_name);
         goto err_out;
     }
Signature · 1 line
1.7.3.1.50.g1e633
#16 lore raw

PATCH 16/23 Monitor: Drop QMP info from the qemu-monitor.hx file

In reply to Luiz Capitulino

QMP has its own dispatch table and documentation file (qmp-commands.hx), we can now drop the following QMP specific info from qemu-monitor.hx:

o SQMP/EQMP sections
o The qmp_capabilities command
o The query-commands command

However, note that QObject handlers entries are not being removed. This will only happen when we introduce a proper QMP call interface.

---
 monitor.c       |    8 -
 qemu-monitor.hx | 1358 -------------------------------------------------------
 2 files changed, 0 insertions(+), 1366 deletions(-)
monitor.c +0 -8
index 6e62643..b43277e 100644
@@ -2352,14 +2352,6 @@ static const mon_cmd_t info_cmds[] = {
         .mhandler.info_new = do_info_version,
     },
     {
-        .name       = "commands",
-        .args_type  = "",
-        .params     = "",
-        .help       = "list QMP available commands",
-        .user_print = monitor_user_noop,
-        .mhandler.info_new = do_info_commands,
-    },
-    {
         .name       = "network",
         .args_type  = "",
         .params     = "",
qemu-monitor.hx +0 -1358

1,582 lines not on this page · raw message

Signature · 1 line
1.7.3.1.50.g1e633
#17 lore raw

PATCH 17/23 Monitor: Drop monitor_cmd_user_only()

In reply to Luiz Capitulino

This function was only needed when QMP and HMP were sharing dispatch tables, this is no longer true so just drop it.

---
 monitor.c |    5 -----
 monitor.h |    1 -
 2 files changed, 0 insertions(+), 6 deletions(-)
monitor.c +0 -5
index b43277e..8f90250 100644
@@ -340,11 +340,6 @@ static inline bool monitor_handler_is_async(const mon_cmd_t *cmd)
     return cmd->flags & MONITOR_CMD_ASYNC;
 }
 
-static inline bool monitor_cmd_user_only(const mon_cmd_t *cmd)
-{
-    return (cmd->flags & MONITOR_CMD_USER_ONLY);
-}
-
 static inline int monitor_has_error(const Monitor *mon)
 {
     return mon->error != NULL;
monitor.h +0 -1
index f2122b5..44c3625 100644
@@ -18,7 +18,6 @@ extern Monitor *default_mon;
 
 /* flags for monitor commands */
 #define MONITOR_CMD_ASYNC       0x0001
-#define MONITOR_CMD_USER_ONLY   0x0002
 
 /* QMP events */
 typedef enum MonitorEvent {
Signature · 1 line
1.7.3.1.50.g1e633
#18 lore raw

PATCH 18/23 Monitor: Rename monitor_handler_ported()

In reply to Luiz Capitulino

That name makes no sense anymore, as dispatch tables have been split, a better name is handler_is_qobject(), which really communicates the handler's type.

---
 monitor.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
monitor.c +3 -3
index 8f90250..b9dab78 100644
@@ -330,7 +330,7 @@ static int monitor_fprintf(FILE *stream, const char *fmt, ...)
 
 static void monitor_user_noop(Monitor *mon, const QObject *data) { }
 
-static inline int monitor_handler_ported(const mon_cmd_t *cmd)
+static inline int handler_is_qobject(const mon_cmd_t *cmd)
 {
     return cmd->user_print != NULL;
 }
@@ -654,7 +654,7 @@ static void do_info(Monitor *mon, const QDict *qdict)
 
     if (monitor_handler_is_async(cmd)) {
         user_async_info_handler(mon, cmd);
-    } else if (monitor_handler_ported(cmd)) {
+    } else if (handler_is_qobject(cmd)) {
         QObject *info_data = NULL;
 
         cmd->mhandler.info_new(mon, &info_data);
@@ -3916,7 +3916,7 @@ static void handle_user_command(Monitor *mon, const char *cmdline)
 
     if (monitor_handler_is_async(cmd)) {
         user_async_cmd_handler(mon, cmd, qdict);
-    } else if (monitor_handler_ported(cmd)) {
+    } else if (handler_is_qobject(cmd)) {
         monitor_call_handler(mon, cmd, qdict);
     } else {
         cmd->mhandler.cmd(mon, qdict);
Signature · 1 line
1.7.3.1.50.g1e633
#19 lore raw

PATCH 19/23 Monitor: Rename monitor_handler_is_async()

In reply to Luiz Capitulino

Let's follow the convention introduced by the previous commit and call it handler_is_async().

---
 monitor.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
monitor.c +5 -5
index b9dab78..7959504 100644
@@ -335,7 +335,7 @@ static inline int handler_is_qobject(const mon_cmd_t *cmd)
     return cmd->user_print != NULL;
 }
 
-static inline bool monitor_handler_is_async(const mon_cmd_t *cmd)
+static inline bool handler_is_async(const mon_cmd_t *cmd)
 {
     return cmd->flags & MONITOR_CMD_ASYNC;
 }
@@ -652,7 +652,7 @@ static void do_info(Monitor *mon, const QDict *qdict)
         goto help;
     }
 
-    if (monitor_handler_is_async(cmd)) {
+    if (handler_is_async(cmd)) {
         user_async_info_handler(mon, cmd);
     } else if (handler_is_qobject(cmd)) {
         QObject *info_data = NULL;
@@ -3914,7 +3914,7 @@ static void handle_user_command(Monitor *mon, const char *cmdline)
     if (!cmd)
         goto out;
 
-    if (monitor_handler_is_async(cmd)) {
+    if (handler_is_async(cmd)) {
         user_async_cmd_handler(mon, cmd, qdict);
     } else if (handler_is_qobject(cmd)) {
         monitor_call_handler(mon, cmd, qdict);
@@ -4411,7 +4411,7 @@ static void qmp_call_query_cmd(Monitor *mon, const mon_cmd_t *cmd)
 {
     QObject *ret_data = NULL;
 
-    if (monitor_handler_is_async(cmd)) {
+    if (handler_is_async(cmd)) {
         qmp_async_info_handler(mon, cmd);
         if (monitor_has_error(mon)) {
             monitor_protocol_emitter(mon, NULL);
@@ -4485,7 +4485,7 @@ static void handle_qmp_command(JSONMessageParser *parser, QList *tokens)
 
     if (query_cmd) {
         qmp_call_query_cmd(mon, cmd);
-    } else if (monitor_handler_is_async(cmd)) {
+    } else if (handler_is_async(cmd)) {
         err = qmp_async_cmd_handler(mon, cmd, args);
         if (err) {
             /* emit the error response */
Signature · 1 line
1.7.3.1.50.g1e633
#20 lore raw

PATCH 20/23 Monitor: Directly call QObject handlers

In reply to Luiz Capitulino

This avoids handle_user_command() calling monitor_call_handler(), which is currently shared with QMP.

---
 monitor.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)
monitor.c +9 -1
index 7959504..03f3c18 100644
@@ -3917,7 +3917,15 @@ static void handle_user_command(Monitor *mon, const char *cmdline)
     if (handler_is_async(cmd)) {
         user_async_cmd_handler(mon, cmd, qdict);
     } else if (handler_is_qobject(cmd)) {
-        monitor_call_handler(mon, cmd, qdict);
+        QObject *data = NULL;
+
+        /* XXX: ignores the error code */
+        cmd->mhandler.cmd_new(mon, qdict, &data);
+        assert(!monitor_has_error(mon));
+        if (data) {
+            cmd->user_print(mon, data);
+            qobject_decref(data);
+        }
     } else {
         cmd->mhandler.cmd(mon, qdict);
     }
Signature · 1 line
1.7.3.1.50.g1e633
#21 lore raw

PATCH 21/23 QMP: Introduce qmp_call_cmd()

In reply to Luiz Capitulino

Calls a QObject handler and emits the QMP response, also drops monitor_call_handler() which is now unused.

---
 monitor.c |   39 +++++++++++++++------------------------
 1 files changed, 15 insertions(+), 24 deletions(-)
monitor.c +15 -24
index 03f3c18..3f3c9bf 100644
@@ -3880,29 +3880,6 @@ static void handler_audit(Monitor *mon, const mon_cmd_t *cmd, int ret)
     }
 }
 
-static void monitor_call_handler(Monitor *mon, const mon_cmd_t *cmd,
-                                 const QDict *params)
-{
-    int ret;
-    QObject *data = NULL;
-
-    mon_print_count_init(mon);
-
-    ret = cmd->mhandler.cmd_new(mon, params, &data);
-    handler_audit(mon, cmd, ret);
-
-    if (monitor_ctrl_mode(mon)) {
-        /* Monitor Protocol */
-        monitor_protocol_emitter(mon, data);
-    } else {
-        /* User Protocol */
-         if (data)
-            cmd->user_print(mon, data);
-    }
-
-    qobject_decref(data);
-}
-
 static void handle_user_command(Monitor *mon, const char *cmdline)
 {
     QDict *qdict;
@@ -4433,6 +4410,20 @@ static void qmp_call_query_cmd(Monitor *mon, const mon_cmd_t *cmd)
     }
 }
 
+static void qmp_call_cmd(Monitor *mon, const mon_cmd_t *cmd,
+                         const QDict *params)
+{
+    int ret;
+    QObject *data = NULL;
+
+    mon_print_count_init(mon);
+
+    ret = cmd->mhandler.cmd_new(mon, params, &data);
+    handler_audit(mon, cmd, ret);
+    monitor_protocol_emitter(mon, data);
+    qobject_decref(data);
+}
+
 static void handle_qmp_command(JSONMessageParser *parser, QList *tokens)
 {
     int err;
@@ -4500,7 +4491,7 @@ static void handle_qmp_command(JSONMessageParser *parser, QList *tokens)
             goto err_out;
         }
     } else {
-        monitor_call_handler(mon, cmd, args);
+        qmp_call_cmd(mon, cmd, args);
     }
 
     goto out;
Signature · 1 line
1.7.3.1.50.g1e633
#22 lore raw

PATCH 22/23 Monitor: Rename the qemu-monitor.hx file

In reply to Luiz Capitulino

Let's be consistent and call it hmp-commands.hx, so that we have qmp-commands.hx for QMP and hmp-commands.hx for HMP.

Please, note that this commit doesn't touch qemu-monitor.texi. All texi files have the qemu- prefix and I don't think it's worth changing that.

---
 Makefile        |    2 +-
 Makefile.target |    6 +-
 hmp-commands.hx | 1216 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 monitor.c       |    4 +-
 qemu-monitor.hx | 1216 -------------------------------------------------------
 5 files changed, 1222 insertions(+), 1222 deletions(-)
 create mode 100644 hmp-commands.hx
 delete mode 100644 qemu-monitor.hx
Makefile +1 -1
index 938d88b..3f42fe2 100644
@@ -249,7 +249,7 @@ TEXIFLAG=$(if $(V),,--quiet)
 qemu-options.texi: $(SRC_PATH)/qemu-options.hx
 	$(call quiet-command,sh $(SRC_PATH)/hxtool -t < $< > $@,"  GEN   $@")
 
-qemu-monitor.texi: $(SRC_PATH)/qemu-monitor.hx
+qemu-monitor.texi: $(SRC_PATH)/hmp-commands.hx
 	$(call quiet-command,sh $(SRC_PATH)/hxtool -t < $< > $@,"  GEN   $@")
 
 QMP/qmp-commands.txt: $(SRC_PATH)/qmp-commands.hx
Makefile.target +3 -3
index 3a1fa7e..518ea27 100644
@@ -307,7 +307,7 @@ obj-alpha-y = alpha_palcode.o
 
 main.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
 
-monitor.o: qemu-monitor.h qmp-commands.h
+monitor.o: hmp-commands.h qmp-commands.h
 
 $(obj-y) $(obj-$(TARGET_BASE_ARCH)-y): $(GENERATED_HEADERS)
 
@@ -328,7 +328,7 @@ $(QEMU_PROG): $(obj-y) $(obj-$(TARGET_BASE_ARCH)-y)
 gdbstub-xml.c: $(TARGET_XML_FILES) $(SRC_PATH)/feature_to_c.sh
 	$(call quiet-command,rm -f $@ && $(SHELL) $(SRC_PATH)/feature_to_c.sh $@ $(TARGET_XML_FILES),"  GEN   $(TARGET_DIR)$@")
 
-qemu-monitor.h: $(SRC_PATH)/qemu-monitor.hx
+hmp-commands.h: $(SRC_PATH)/hmp-commands.hx
 	$(call quiet-command,sh $(SRC_PATH)/hxtool -h < $< > $@,"  GEN   $(TARGET_DIR)$@")
 
 qmp-commands.h: $(SRC_PATH)/qmp-commands.hx
@@ -337,7 +337,7 @@ qmp-commands.h: $(SRC_PATH)/qmp-commands.hx
 clean:
 	rm -f *.o *.a *~ $(PROGS) nwfpe/*.o fpu/*.o
 	rm -f *.d */*.d tcg/*.o ide/*.o
-	rm -f qemu-monitor.h qmp-commands.h gdbstub-xml.c
+	rm -f hmp-commands.h qmp-commands.h gdbstub-xml.c
 
 install: all
 ifneq ($(PROGS),)
hmp-commands.hx new file +1216 -0

1,216 lines not on this page · raw message

monitor.c +2 -2
index 3f3c9bf..4148dd9 100644
@@ -2332,11 +2332,11 @@ int monitor_get_fd(Monitor *mon, const char *fdname)
 }
 
 static const mon_cmd_t mon_cmds[] = {
-#include "qemu-monitor.h"
+#include "hmp-commands.h"
     { NULL, NULL, },
 };
 
-/* Please update qemu-monitor.hx when adding or changing commands */
+/* Please update hmp-commands.hx when adding or changing commands */
 static const mon_cmd_t info_cmds[] = {
     {
         .name       = "version",
qemu-monitor.hx deleted +0 -1216

1,216 lines not on this page · raw message

Signature · 1 line
1.7.3.1.50.g1e633
#23 lore raw

PATCH 23/23 QMP/README: Update QMP homepage address

In reply to Luiz Capitulino
---
 QMP/README |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
QMP/README +1 -1
index 7e2b51a..80503f2 100644
@@ -88,4 +88,4 @@ doing any code change. This is so because:
 Homepage
 --------
 
-http://www.linux-kvm.org/page/MonitorProtocol
+http://wiki.qemu.org/QMP
Signature · 1 line
1.7.3.1.50.g1e633
#24 lore raw
In reply to Luiz Capitulino
Quoted 10 lines · Luiz Capitulino

Hi Anthony,

The following patches have been sent to the list and look good to me, I've also tested them.

The changes (since 2c50e26efdb7e405ecacf89e6a57a60179226dd8) are available in the following repository:

git://repo.or.cz/qemu/qmp-unstable.git for-anthony

Pulled. Thanks.

Regards,

Anthony Liguori

Quoted 46 lines

Daniel P. Berrange (2):
Add support for JSON pretty printing
Add option to turn on JSON pretty printing in monitor

Eduardo Habkost (1):
disable guest-provided stats on "info balloon" command

Luiz Capitulino (20):
Monitor: Introduce search_dispatch_table()
QMP: handle_qmp_command(): Move 'cmd' sanity check
QMP: Don't use do_info()
Monitor: Drop QMP bits from do_info()
Monitor: Drop is_async_return()
Monitor: Convert do_info() back to HMP
Monitor: Introduce the qmp-commands.hx file
QMP: Introduce qmp_find_cmd()
QMP: Introduce command dispatch table
QMP: Introduce query commands dispatch table
QMP: Simplify do_info_commands()
QMP: Small cleanup in handle_qmp_command()
Monitor: Drop QMP info from the qemu-monitor.hx file
Monitor: Drop monitor_cmd_user_only()
Monitor: Rename monitor_handler_ported()
Monitor: Rename monitor_handler_is_async()
Monitor: Directly call QObject handlers
QMP: Introduce qmp_call_cmd()
Monitor: Rename the qemu-monitor.hx file QMP/README: Update QMP homepage address

  Makefile            |    4 +-
  Makefile.target     |    9 +-
  QMP/README          |    4 +-
  hmp-commands.hx     | 1216 ++++++++++++++++++++++++
  hw/virtio-balloon.c |    8 +-
  monitor.c           |  366 +++++---
  monitor.h           |    2 +-
  qemu-config.c       |    3 +
  qemu-monitor.hx     | 2575 ---------------------------------------------------
  qjson.c             |   55 +-
  qjson.h             |    1 +
  qmp-commands.hx     | 1541 ++++++++++++++++++++++++++++++
  vl.c                |    3 +
  13 files changed, 3061 insertions(+), 2726 deletions(-)