Skip to contentSkip to conversation

Monitor: split HMP and QMP dispatch tables

PATCH Superseded Luiz Capitulino 4 participants 30 messages Sep 16, 2010 – Sep 29, 2010 Kbuild

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Monitor: split HMP and QMP dispatch tables

The subject says it all: with this series applied we'll get different dispatch tables for HMP and QMP, which has the side effect of making QMP commands (such as qmp_capabilities) disappear from HMP's scope.

This is also the beginning of the Monitor's redesign, which aims to separate QMP, HMP and common code.

There's a penalty, though. We're going to get a bit of duplication during the process, like duplicated handlers entries in the dispatch tables.

We'll need more separation and a proper internal QMP interface to solve that...

---
 Makefile            |    2 +-
 Makefile.target     |    7 +-
 monitor.c           |  357 ++++++++-----
 monitor.h           |    1 -
 qemu-monitor-qmp.hx | 1541 +++++++++++++++++++++++++++++++++++++++++++++++++++
 qemu-monitor.hx     | 1361 +---------------------------------------------
 6 files changed, 1774 insertions(+), 1495 deletions(-)
#1 lore raw

PATCH 1/18 Monitor: Introduce find_dispatch_table()

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 e602480..98fc57a 100644
@@ -3368,11 +3368,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 *find_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;
         }
@@ -3381,6 +3382,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 find_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.rc2.dirty
#2 lore raw

Re: [Qemu-devel] [PATCH 01/18] Monitor: Introduce find_dispatch_table()

Quoted 16 lines · 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 +0 -0
index e602480..98fc57a 100644

monitor.c static int is_valid_option(const char *c, const char *typestr) · line 3372

Quoted 6 lines
monitor.c +2 -1
@@ -3368,11 +3368,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 *find_dispatch_table(const mon_cmd_t *disp_table,
+                                            const char *cmdname)

find_dispatch_table() suggests it's searching for a dispatch table. What about search_dispatch_table() or lookup_command()?

Quoted 20 lines
monitor.c +6 -1
 {
     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;
         }
@@ -3381,6 +3382,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 find_dispatch_table(mon_cmds, cmdname);
+}
+
 static const mon_cmd_t *monitor_parse_command(Monitor *mon,
                                               const char *cmdline,
                                               QDict *qdict)
#3 lore raw

PATCH 2/18 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 98fc57a..b2d8a2d 100644
@@ -4372,11 +4372,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.rc2.dirty
#4 lore raw

PATCH 3/18 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

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 b2d8a2d..0ddc826 100644
@@ -3387,6 +3387,11 @@ static const mon_cmd_t *monitor_find_command(const char *cmdname)
     return find_dispatch_table(mon_cmds, cmdname);
 }
 
+static const mon_cmd_t *qmp_find_query_cmd(const char *info_item)
+{
+    return find_dispatch_table(info_cmds, info_item);
+}
+
 static const mon_cmd_t *monitor_parse_command(Monitor *mon,
                                               const char *cmdline,
                                               QDict *qdict)
@@ -4326,6 +4331,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;
@@ -4333,8 +4356,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);
@@ -4360,16 +4384,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);
     }
@@ -4392,7 +4413,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.rc2.dirty
#5 lore raw

Re: [Qemu-devel] [PATCH 03/18] QMP: Don't use do_info()

Quoted 8 lines · 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:

Quoted 7 lines

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

The use via monitor_find_command("info").

Quoted 2 lines

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

[...]

#6 lore raw

PATCH 4/18 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 0ddc826..b76e227 100644
@@ -639,7 +639,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;
     }
 
@@ -649,24 +648,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
@@ -674,24 +660,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.rc2.dirty
#7 lore raw

PATCH 5/18 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 b76e227..1d52362 100644
@@ -653,12 +653,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;
 
@@ -3717,15 +3711,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)) {
@@ -3784,15 +3769,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.rc2.dirty
#8 lore raw

Re: [Qemu-devel] [PATCH 05/18] Monitor: Drop is_async_return()

Quoted 6 lines · 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.

Looks like it.

Does anybody understand this async monitor stuff? It's used only for "info balloon" and "balloon". It keeps getting in the way. I'm sorely tempted to rip it out and reimplement it after we're done refactoring the monitor.

#9 lore raw

Re: [Qemu-devel] [PATCH 05/18] Monitor: Drop is_async_return()

Quoted 6 lines · On Wed, 29 Sep 2010 13:21:08 +0200 Markus Armbruster <[email protected]> wrote:
Quoted 4 lines · 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.

Quoted 6 lines
Quoted 2 lines

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

Looks like it.

Does anybody understand this async monitor stuff?

I guess I do, but every now and then it surprises me someway.

Quoted 4 lines

It's used only for
"info balloon" and "balloon". It keeps getting in the way. I'm sorely tempted to rip it out and reimplement it after we're done refactoring the monitor.

I've considered doing that, but then I realized that it's actually a good interface with two serious problems:

1. It's half done. A true async interface would provide a way to list and cancel requests (at the API level and in QMP/HMP)

2. It got too complex, and that's so because of the current state of the Monitor code

My optimistic side is telling me that both problems can be solved during the refactoring process: Monitor code will be simplified and the current async interface could be used as the basis for the internal QMP API (which should be async-only, but that's another discussion).

#10 lore raw

Re: [Qemu-devel] [PATCH 05/18] Monitor: Drop is_async_return()

Quoted 32 lines · Luiz Capitulino
Quoted 7 lines · On Wed, 29 Sep 2010 13:21:08 +0200 Markus Armbruster<[email protected]> wrote:
Quoted 4 lines · 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.

Quoted 7 lines
Quoted 3 lines

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

Looks like it.

Does anybody understand this async monitor stuff?

I guess I do, but every now and then it surprises me someway.

Quoted 5 lines

It's used only for
"info balloon" and "balloon". It keeps getting in the way. I'm sorely tempted to rip it out and reimplement it after we're done refactoring the monitor.

I've considered doing that, but then I realized that it's actually a good interface with two serious problems:

1. It's half done. A true async interface would provide a way to list and cancel requests (at the API level and in QMP/HMP)

Quoted 8 lines

2. It got too complex, and that's so because of the current state of the Monitor code

My optimistic side is telling me that both problems can be solved during the refactoring process: Monitor code will be simplified and the current async interface could be used as the basis for the internal QMP API (which should be async-only, but that's another discussion).

I think one of the ugly bits of QMP as a protocol is capabilities negotiation because it implies that QMP has stateful sessions.

Capabilities doesn't have to imply a stateful session but some of the things we've discussed in the past would (like event notification masking).

When you look at other RPCs like XML-RPC, REST, or even JSON-RPC over HTTP, in order to be used over HTTP it's important that the actual RPC session has no state because HTTP is stateless.

The reason this discussion matters is because today we have a Monitor object that all commands operate on and could potentially use to store state.

An alternative model would be to do away with the Monitor object used by the commands which means the commands have no way to store session state. The human monitor needs state because it's stateful but it's not clear that we need to do this with QMP.

I think the vast majority of the complexity of async is based on the fact that we have a session object and we make the session object globally available. I don't think this is really something we've ever considered with QMP though.

Regards,

Anthony Liguori

Regards,

Anthony Liguori

#11 lore raw

Re: [Qemu-devel] [PATCH 05/18] Monitor: Drop is_async_return()

In reply to Luiz Capitulino
Quoted 32 lines · Luiz Capitulino
Quoted 7 lines · On Wed, 29 Sep 2010 13:21:08 +0200 Markus Armbruster<[email protected]> wrote:
Quoted 4 lines · 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.

Quoted 7 lines
Quoted 3 lines

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

Looks like it.

Does anybody understand this async monitor stuff?

I guess I do, but every now and then it surprises me someway.

Quoted 5 lines

It's used only for
"info balloon" and "balloon". It keeps getting in the way. I'm sorely tempted to rip it out and reimplement it after we're done refactoring the monitor.

I've considered doing that, but then I realized that it's actually a good interface with two serious problems:

1. It's half done. A true async interface would provide a way to list and cancel requests (at the API level and in QMP/HMP)

Quoted 8 lines

2. It got too complex, and that's so because of the current state of the Monitor code

My optimistic side is telling me that both problems can be solved during the refactoring process: Monitor code will be simplified and the current async interface could be used as the basis for the internal QMP API (which should be async-only, but that's another discussion).

I think one of the ugly bits of QMP as a protocol is capabilities negotiation because it implies that QMP has stateful sessions.

Capabilities doesn't have to imply a stateful session but some of the things we've discussed in the past would (like event notification masking).

When you look at other RPCs like XML-RPC, REST, or even JSON-RPC over HTTP, in order to be used over HTTP it's important that the actual RPC session has no state because HTTP is stateless.

The reason this discussion matters is because today we have a Monitor object that all commands operate on and could potentially use to store state.

An alternative model would be to do away with the Monitor object used by the commands which means the commands have no way to store session state. The human monitor needs state because it's stateful but it's not clear that we need to do this with QMP.

I think the vast majority of the complexity of async is based on the fact that we have a session object and we make the session object globally available. I don't think this is really something we've ever considered with QMP though.

Regards,

Anthony Liguori

Regards,

Anthony Liguori

#12 lore raw

PATCH 6/18 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 1d52362..ea66ac3 100644
@@ -633,7 +633,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");
@@ -665,11 +665,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.rc2.dirty
#13 lore raw

PATCH 7/18 Monitor: Introduce the qemu-monitor-qmp.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 from HMP's tables.

NOTE: HMP specific constructions, like "q|quit", have been
dropped from the qemu-monitor-qmp.hx file.

---
 Makefile            |    2 +-
 qemu-monitor-qmp.hx | 1541 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 1542 insertions(+), 1 deletions(-)
 create mode 100644 qemu-monitor-qmp.hx
Makefile +1 -1
index ab91d42..7e8b062 100644
@@ -248,7 +248,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)/qemu-monitor-qmp.hx
 	$(call quiet-command,sh $(SRC_PATH)/hxtool -q < $< > $@,"  GEN   $@")
 
 qemu-img-cmds.texi: $(SRC_PATH)/qemu-img-cmds.hx
qemu-monitor-qmp.hx new file +1541 -0

1,541 lines not on this page · raw message

Signature · 1 line
1.7.3.rc2.dirty
#14 lore raw

PATCH 8/18 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 ea66ac3..7b699db 100644
@@ -3362,6 +3362,11 @@ static const mon_cmd_t *qmp_find_query_cmd(const char *info_item)
     return find_dispatch_table(info_cmds, info_item);
 }
 
+static const mon_cmd_t *qmp_find_cmd(const char *cmdname)
+{
+    return find_dispatch_table(mon_cmds, cmdname);
+}
+
 static const mon_cmd_t *monitor_parse_command(Monitor *mon,
                                               const char *cmdline,
                                               QDict *qdict)
@@ -4345,7 +4350,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.rc2.dirty
#15 lore raw

PATCH 9/18 QMP: Introduce command dispatch table

In reply to Luiz Capitulino

Also update QMP functions to use it. The table is generated from the qemu-monitor-qmp.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 a4e80b1..7fab81b 100644
@@ -299,7 +299,7 @@ obj-alpha-y = alpha_palcode.o
 
 main.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
 
-monitor.o: qemu-monitor.h
+monitor.o: qemu-monitor.h qemu-monitor-qmp.h
 
 $(obj-y) $(obj-$(TARGET_BASE_ARCH)-y): $(GENERATED_HEADERS)
 
@@ -323,10 +323,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)$@")
 
+qemu-monitor-qmp.h: $(SRC_PATH)/qemu-monitor-qmp.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-monitor-qmp.h gdbstub-xml.c
 
 install: all
 ifneq ($(PROGS),)
monitor.c +9 -2
index 7b699db..fe1a29a 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;
 
@@ -742,7 +744,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));
@@ -2632,6 +2634,11 @@ static const mon_cmd_t info_cmds[] = {
     },
 };
 
+static const mon_cmd_t qmp_cmds[] = {
+#include "qemu-monitor-qmp.h"
+    { /* NULL */ },
+};
+
 /*******************************************************************/
 
 static const char *pch;
@@ -3364,7 +3371,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 find_dispatch_table(mon_cmds, cmdname);
+    return find_dispatch_table(qmp_cmds, cmdname);
 }
 
 static const mon_cmd_t *monitor_parse_command(Monitor *mon,
Signature · 1 line
1.7.3.rc2.dirty
#16 lore raw

Re: [Qemu-devel] [PATCH 09/18] QMP: Introduce command dispatch table

Quoted 27 lines · Luiz Capitulino

Also update QMP functions to use it. The table is generated from the qemu-monitor-qmp.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 +1 -1
index a4e80b1..7fab81b 100644
@@ -299,7 +299,7 @@ obj-alpha-y = alpha_palcode.o
 
 main.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
 
-monitor.o: qemu-monitor.h
+monitor.o: qemu-monitor.h qemu-monitor-qmp.h
 
 $(obj-y) $(obj-$(TARGET_BASE_ARCH)-y): $(GENERATED_HEADERS)
 
@@ -323,10 +323,13 @@ gdbstub-xml.c: $(TARGET_XML_FILES) $(SRC_PATH)/feature_to_c.sh
 qemu-monitor.h: $(SRC_PATH)/qemu-monitor.hx

Makefile.target gdbstub-xml.c: $(TARGET_XML_FILES) $(SRC_PATH)/feature_to_c.sh · line 332

Quoted 10 lines
Makefile.target +4 -1
 	$(call quiet-command,sh $(SRC_PATH)/hxtool -h < $< > $@,"  GEN   $(TARGET_DIR)$@")
 
+qemu-monitor-qmp.h: $(SRC_PATH)/qemu-monitor-qmp.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-monitor-qmp.h gdbstub-xml.c

Typo: qmp-monitor-qmp.h instead of qemu-monitor-qmp.h.

I'm not thrilled about qemu-monitor-qmp; because if I expand the abbreviation, I get "QEMU monitor QEMU Monitor Protocol".

What about just qmp?

[...]

Quoted 16 lines
Makefile.target +0 -0
 install: all
 ifneq ($(PROGS),)
monitor.c +2 -0
index 7b699db..fe1a29a 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;
 

monitor.c static void do_info_commands(Monitor *mon, QObject **ret_data) · line 750

Quoted 8 lines
monitor.c +1 -1
@@ -742,7 +744,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));

We need to switch here, because "info commands" is about QMP commands, not about HMP commands. Curious, isn't it?

Quoted 21 lines
monitor.c +6 -1
@@ -2632,6 +2634,11 @@ static const mon_cmd_t info_cmds[] = {
     },
 };
 
+static const mon_cmd_t qmp_cmds[] = {
+#include "qemu-monitor-qmp.h"
+    { /* NULL */ },
+};
+
 /*******************************************************************/
 
 static const char *pch;
@@ -3364,7 +3371,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 find_dispatch_table(mon_cmds, cmdname);
+    return find_dispatch_table(qmp_cmds, cmdname);
 }
 
 static const mon_cmd_t *monitor_parse_command(Monitor *mon,
#17 lore raw

Re: [Qemu-devel] [PATCH 09/18] QMP: Introduce command dispatch table

Quoted 42 lines · On Wed, 29 Sep 2010 13:31:13 +0200 Markus Armbruster <[email protected]> wrote:
Quoted 27 lines · Luiz Capitulino

Also update QMP functions to use it. The table is generated from the qemu-monitor-qmp.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 +1 -1
index a4e80b1..7fab81b 100644
@@ -299,7 +299,7 @@ obj-alpha-y = alpha_palcode.o
 
 main.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
 
-monitor.o: qemu-monitor.h
+monitor.o: qemu-monitor.h qemu-monitor-qmp.h
 
 $(obj-y) $(obj-$(TARGET_BASE_ARCH)-y): $(GENERATED_HEADERS)
 
@@ -323,10 +323,13 @@ gdbstub-xml.c: $(TARGET_XML_FILES) $(SRC_PATH)/feature_to_c.sh
 qemu-monitor.h: $(SRC_PATH)/qemu-monitor.hx

Makefile.target gdbstub-xml.c: $(TARGET_XML_FILES) $(SRC_PATH)/feature_to_c.sh · line 332

Quoted 10 lines
Makefile.target +4 -1
 	$(call quiet-command,sh $(SRC_PATH)/hxtool -h < $< > $@,"  GEN   $(TARGET_DIR)$@")
 
+qemu-monitor-qmp.h: $(SRC_PATH)/qemu-monitor-qmp.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-monitor-qmp.h gdbstub-xml.c

Typo: qmp-monitor-qmp.h instead of qemu-monitor-qmp.h.

Quoted 4 lines

I'm not thrilled about qemu-monitor-qmp; because if I expand the abbreviation, I get "QEMU monitor QEMU Monitor Protocol".

What about just qmp?

I think qmp-commands is better, but then I'll also change qemu-monitor.hx to hmp-commands.hx.

Objections?

Quoted 20 lines

[...]

Quoted 19 lines

install: all
ifneq ($(PROGS),)

monitor.c +2 -0
index 7b699db..fe1a29a 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;
 
@@ -742,7 +744,7 @@ static void do_info_commands(Monitor *mon, QObject **ret_data)
 
     cmd_list = qlist_new();
 
Quoted 8 lines

monitor.c static void do_info_commands(Monitor *mon, QObject **ret_data) · line 750

Quoted 5 lines
monitor.c +1 -1
-    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));

We need to switch here, because "info commands" is about QMP commands, not about HMP commands. Curious, isn't it?

Drop the compare_cmd() and change the function's name, you mean?

Quoted 22 lines
Quoted 21 lines
monitor.c +6 -1
@@ -2632,6 +2634,11 @@ static const mon_cmd_t info_cmds[] = {
     },
 };
 
+static const mon_cmd_t qmp_cmds[] = {
+#include "qemu-monitor-qmp.h"
+    { /* NULL */ },
+};
+
 /*******************************************************************/
 
 static const char *pch;
@@ -3364,7 +3371,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 find_dispatch_table(mon_cmds, cmdname);
+    return find_dispatch_table(qmp_cmds, cmdname);
 }
 
 static const mon_cmd_t *monitor_parse_command(Monitor *mon,
#18 lore raw

Re: [Qemu-devel] [PATCH 09/18] QMP: Introduce command dispatch table

Quoted 48 lines · Luiz Capitulino
Quoted 45 lines · On Wed, 29 Sep 2010 13:31:13 +0200 Markus Armbruster <[email protected]> wrote:
Quoted 27 lines · Luiz Capitulino

Also update QMP functions to use it. The table is generated from the qemu-monitor-qmp.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 +1 -1
index a4e80b1..7fab81b 100644
@@ -299,7 +299,7 @@ obj-alpha-y = alpha_palcode.o
 
 main.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
 
-monitor.o: qemu-monitor.h
+monitor.o: qemu-monitor.h qemu-monitor-qmp.h
 
 $(obj-y) $(obj-$(TARGET_BASE_ARCH)-y): $(GENERATED_HEADERS)
 
@@ -323,10 +323,13 @@ gdbstub-xml.c: $(TARGET_XML_FILES) $(SRC_PATH)/feature_to_c.sh
 qemu-monitor.h: $(SRC_PATH)/qemu-monitor.hx

Makefile.target gdbstub-xml.c: $(TARGET_XML_FILES) $(SRC_PATH)/feature_to_c.sh · line 332

Quoted 10 lines
Makefile.target +4 -1
 	$(call quiet-command,sh $(SRC_PATH)/hxtool -h < $< > $@,"  GEN   $(TARGET_DIR)$@")
 
+qemu-monitor-qmp.h: $(SRC_PATH)/qemu-monitor-qmp.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-monitor-qmp.h gdbstub-xml.c

Typo: qmp-monitor-qmp.h instead of qemu-monitor-qmp.h.

I'm not thrilled about qemu-monitor-qmp; because if I expand the abbreviation, I get "QEMU monitor QEMU Monitor Protocol".

Quoted 6 lines
Quoted 1 line

What about just qmp?

I think qmp-commands is better, but then I'll also change qemu-monitor.hx to hmp-commands.hx.

Objections?

Fine with me.

Quoted 29 lines
Quoted 20 lines

[...]

Quoted 19 lines

install: all
ifneq ($(PROGS),)

monitor.c +2 -0
index 7b699db..fe1a29a 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;
 
@@ -742,7 +744,7 @@ static void do_info_commands(Monitor *mon, QObject **ret_data)
 
     cmd_list = qlist_new();
 
Quoted 8 lines

monitor.c static void do_info_commands(Monitor *mon, QObject **ret_data) · line 750

Quoted 5 lines
monitor.c +1 -1
-    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));

We need to switch here, because "info commands" is about QMP commands, not about HMP commands. Curious, isn't it?

Quoted 1 line

Drop the compare_cmd() and change the function's name, you mean?

No. The reason for this change wasn't obvious to me, so I wrote it down, in case it's not obvious to others, either. I didn't mean to suggest you change anything here.

[...]

#19 lore raw

PATCH 10/18 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 fe1a29a..53f8665 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;
@@ -751,7 +752,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);
@@ -2639,6 +2640,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;
@@ -3366,7 +3492,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 find_dispatch_table(info_cmds, info_item);
+    return find_dispatch_table(qmp_query_cmds, info_item);
 }
 
 static const mon_cmd_t *qmp_find_cmd(const char *cmdname)
Signature · 1 line
1.7.3.rc2.dirty
#20 lore raw

PATCH 11/18 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 53f8665..6998b3f 100644
@@ -746,18 +746,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.rc2.dirty
#21 lore raw

PATCH 12/18 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 6998b3f..8cf50ce 100644
@@ -4469,19 +4469,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.rc2.dirty
#22 lore raw

PATCH 13/18 Monitor: Drop QMP info from the qemu-monitor.hx file

In reply to Luiz Capitulino

QMP has its own dispatch table and documentation file (qemu-monitor-qmp.hx), we can now drop the following QMP specific 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 HMP is able of making QMP calls.

---
 monitor.c       |    8 -
 qemu-monitor.hx | 1358 -------------------------------------------------------
 2 files changed, 0 insertions(+), 1366 deletions(-)
monitor.c +0 -8
index 8cf50ce..ce3e5b5 100644
@@ -2349,14 +2349,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.rc2.dirty
#23 lore raw

PATCH 14/18 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 ce3e5b5..3193b93 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 38b22a4..9582b9c 100644
@@ -17,7 +17,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.rc2.dirty
#24 lore raw

PATCH 15/18 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 3193b93..e599e4d 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;
 }
@@ -651,7 +651,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);
@@ -3913,7 +3913,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.rc2.dirty
#25 lore raw

PATCH 16/18 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 e599e4d..d77eb4c 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;
 }
@@ -649,7 +649,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;
@@ -3911,7 +3911,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);
@@ -4408,7 +4408,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);
@@ -4482,7 +4482,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.rc2.dirty
#26 lore raw

PATCH 17/18 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 d77eb4c..c332e06 100644
@@ -3914,7 +3914,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.rc2.dirty
#27 lore raw

PATCH 18/18 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 c332e06..1da65ab 100644
@@ -3877,29 +3877,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;
@@ -4430,6 +4407,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;
@@ -4497,7 +4488,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.rc2.dirty
Acked-by on the v1 series
#28 lore raw
In reply to Luiz Capitulino
Quoted 7 lines · Luiz Capitulino

The subject says it all: with this series applied we'll get different dispatch tables for HMP and QMP, which has the side effect of making QMP commands (such as qmp_capabilities) disappear from HMP's scope.

This is also the beginning of the Monitor's redesign, which aims to separate QMP, HMP and common code.

Quoted 7 lines

There's a penalty, though. We're going to get a bit of duplication during the process, like duplicated handlers entries in the dispatch tables.

We'll need more separation and a proper internal QMP interface to solve that...

It all looks pretty straight forward. Nice work!

Regards,

Anthony Liguori

Quoted 10 lines
---
  Makefile            |    2 +-
  Makefile.target     |    7 +-
  monitor.c           |  357 ++++++++-----
  monitor.h           |    1 -
  qemu-monitor-qmp.hx | 1541 +++++++++++++++++++++++++++++++++++++++++++++++++++
  qemu-monitor.hx     | 1361 +---------------------------------------------
  6 files changed, 1774 insertions(+), 1495 deletions(-)
#29 lore raw
Quoted 12 lines · Anthony Liguori
Quoted 11 lines · Luiz Capitulino

The subject says it all: with this series applied we'll get different dispatch tables for HMP and QMP, which has the side effect of making QMP commands (such as qmp_capabilities) disappear from HMP's scope.

This is also the beginning of the Monitor's redesign, which aims to separate QMP, HMP and common code.

There's a penalty, though. We're going to get a bit of duplication during the process, like duplicated handlers entries in the dispatch tables.

Quoted 7 lines
Quoted 3 lines

We'll need more separation and a proper internal QMP interface to solve that...

It all looks pretty straight forward. Nice work!

Agree.