Skip to contentSkip to conversation

: Initial QObject conversion

PATCH In review Luiz Capitulino 3 participants 14 messages Sep 16, 2009 – Sep 23, 2009

lore
Share & tools
lore
#0 lore raw

cover : Initial QObject conversion

Hi there,

Here goes the first series for Monitor handlers conversion to QObjects.

The first patches introduce infrastructure needed to support incremental
conversion, that is, functions which call handlers will have to deal with the current calling style and the new one.

The remaining patches convert very simple handlers.

Thanks.

#1 lore raw

PATCH 1/7 monitor: Add user_print() to mon_cmd_t

This new struct member will store a pointer to a function that should be used to output data in the user protocol format.

It will also serve as a flag to say if a given handler has already been converted to the new QObject style.

Additionally, this commit converts mon_cmd_t static initializations to the C99 way.

---
 monitor.c       |  349 +++++++++++++++++++++++++------
 qemu-monitor.hx |  615 ++++++++++++++++++++++++++++++++++++++++++++-----------
 2 files changed, 774 insertions(+), 190 deletions(-)
monitor.c +281 -68
index 18bcc92..fe604d8 100644
@@ -71,6 +71,7 @@ typedef struct mon_cmd_t {
     const char *name;
     const char *args_type;
     void *handler;
+    void (*user_print)(Monitor *mon, const QObject *data);
     const char *params;
     const char *help;
 } mon_cmd_t;
@@ -1809,82 +1810,294 @@ static const mon_cmd_t mon_cmds[] = {
 
 /* Please update qemu-monitor.hx when adding or changing commands */
 static const mon_cmd_t info_cmds[] = {
-    { "version", "", do_info_version,
-      "", "show the version of QEMU" },
-    { "network", "", do_info_network,
-      "", "show the network state" },
-    { "chardev", "", qemu_chr_info,
-      "", "show the character devices" },
-    { "block", "", bdrv_info,
-      "", "show the block devices" },
-    { "blockstats", "", bdrv_info_stats,
-      "", "show block device statistics" },
-    { "registers", "", do_info_registers,
-      "", "show the cpu registers" },
-    { "cpus", "", do_info_cpus,
-      "", "show infos for each CPU" },
-    { "history", "", do_info_history,
-      "", "show the command line history", },
-    { "irq", "", irq_info,
-      "", "show the interrupts statistics (if available)", },
-    { "pic", "", pic_info,
-      "", "show i8259 (PIC) state", },
-    { "pci", "", pci_info,
-      "", "show PCI info", },
+    {
+        .name       = "version",
+        .args_type  = "",
+        .handler    = do_info_version,
+        .user_print = NULL,
+        .params     = "",
+        .help       = "show the version of QEMU"
+    },
+    {
+        .name       = "network",
+        .args_type  = "",
+        .handler    = do_info_network,
+        .user_print = NULL,
+        .params     = "",
+        .help       = "show the network state"
+    },
+    {
+        .name       = "chardev",
+        .args_type  = "",
+        .handler    = qemu_chr_info,
+        .user_print = NULL,
+        .params     = "",
+        .help       = "show the character devices"
+    },
+    {
+        .name       = "block",
+        .args_type  = "",
+        .handler    = bdrv_info,
+        .user_print = NULL,
+        .params     = "",
+        .help       = "show the block devices"
+    },
+    {
+        .name       = "blockstats",
+        .args_type  = "",
+        .handler    = bdrv_info_stats,
+        .user_print = NULL,
+        .params     = "",
+        .help       = "show block device statistics"
+    },
+    {
+        .name       = "registers",
+        .args_type  = "",
+        .handler    = do_info_registers,
+        .user_print = NULL,
+        .params     = "",
+        .help       = "show the cpu registers"
+    },
+    {
+        .name       = "cpus",
+        .args_type  = "",
+        .handler    = do_info_cpus,
+        .user_print = NULL,
+        .params     = "",
+        .help       = "show infos for each CPU"
+    },
+    {
+        .name       = "history",
+        .args_type  = "",
+        .handler    = do_info_history,
+        .user_print = NULL,
+        .params     = "",
+        .help       = "show the command line history"
+    },
+    {
+        .name       = "irq",
+        .args_type  = "",
+        .handler    = irq_info,
+        .user_print = NULL,
+        .params     = "",
+        .help       = "show the interrupts statistics (if available)"
+    },
+    {
+        .name       = "pic",
+        .args_type  = "",
+        .handler    = pic_info,
+        .user_print = NULL,
+        .params     = "",
+        .help       = "show i8259 (PIC) state"
+    },
+    {
+        .name       = "pci",
+        .args_type  = "",
+        .handler    = pci_info,
+        .user_print = NULL,
+        .params     = "",
+        .help       = "show PCI info"
+    },
 #if defined(TARGET_I386) || defined(TARGET_SH4)
-    { "tlb", "", tlb_info,
-      "", "show virtual to physical memory mappings", },
+    {
+        .name       = "tlb",
+        .args_type  = "",
+        .handler    = tlb_info,
+        .user_print = NULL,
+        .params     = "",
+        .help       = "show virtual to physical memory mappings"
+    },
 #endif
 #if defined(TARGET_I386)
-    { "mem", "", mem_info,
-      "", "show the active virtual memory mappings", },
-    { "hpet", "", do_info_hpet,
-      "", "show state of HPET", },
+    {
+        .name       = "mem",
+        .args_type  = "",
+        .handler    = mem_info,
+        .user_print = NULL,
+        .params     = "",
+        .help       = "show the active virtual memory mappings"
+    },
+    {
+        .name       = "hpet",
+        .args_type  = "",
+        .handler    = do_info_hpet,
+        .user_print = NULL,
+        .params     = "",
+        .help       = "show state of HPET"
+    },
 #endif
-    { "jit", "", do_info_jit,
-      "", "show dynamic compiler info", },
-    { "kvm", "", do_info_kvm,
-      "", "show KVM information", },
-    { "numa", "", do_info_numa,
-      "", "show NUMA information", },
-    { "usb", "", usb_info,
-      "", "show guest USB devices", },
-    { "usbhost", "", usb_host_info,
-      "", "show host USB devices", },
-    { "profile", "", do_info_profile,
-      "", "show profiling information", },
-    { "capture", "", do_info_capture,
-      "", "show capture information" },
-    { "snapshots", "", do_info_snapshots,
-      "", "show the currently saved VM snapshots" },
-    { "status", "", do_info_status,
-      "", "show the current VM status (running|paused)" },
-    { "pcmcia", "", pcmcia_info,
-      "", "show guest PCMCIA status" },
-    { "mice", "", do_info_mice,
-      "", "show which guest mouse is receiving events" },
-    { "vnc", "", do_info_vnc,
-      "", "show the vnc server status"},
-    { "name", "", do_info_name,
-      "", "show the current VM name" },
-    { "uuid", "", do_info_uuid,
-      "", "show the current VM UUID" },
+    {
+        .name       = "jit",
+        .args_type  = "",
+        .handler    = do_info_jit,
+        .user_print = NULL,
+        .params     = "",
+        .help       = "show dynamic compiler info"
+    },
+    {
+        .name       = "kvm",
+        .args_type  = "",
+        .handler    = do_info_kvm,
+        .user_print = NULL,
+        .params     = "",
+        .help       = "show KVM information"
+    },
+    {
+        .name       = "numa",
+        .args_type  = "",
+        .handler    = do_info_numa,
+        .user_print = NULL,
+        .params     = "",
+        .help       = "show NUMA information"
+    },
+    {
+        .name       = "usb",
+        .args_type  = "",
+        .handler    = usb_info,
+        .user_print = NULL,
+        .params     = "",
+        .help       = "show guest USB devices"
+    },
+    {
+        .name       = "usbhost",
+        .args_type  = "",
+        .handler    = usb_host_info,
+        .user_print = NULL,
+        .params     = "",
+        .help       = "show host USB devices"
+    },
+    {
+        .name       = "profile",
+        .args_type  = "",
+        .handler    = do_info_profile,
+        .user_print = NULL,
+        .params     = "",
+        .help       = "show profiling information"
+    },
+    {
+        .name       = "capture",
+        .args_type  = "",
+        .handler    = do_info_capture,
+        .user_print = NULL,
+        .params     = "",
+        .help       = "show capture information"
+    },
+    {
+        .name       = "snapshots",
+        .args_type  = "",
+        .handler    = do_info_snapshots,
+        .user_print = NULL,
+        .params     = "",
+        .help       = "show the currently saved VM snapshots"
+    },
+    {
+        .name       = "status",
+        .args_type  = "",
+        .handler    = do_info_status,
+        .user_print = NULL,
+        .params     = "",
+        .help       = "show the current VM status (running|paused)"
+    },
+    {
+        .name       = "pcmcia",
+        .args_type  = "",
+        .handler    = pcmcia_info,
+        .user_print = NULL,
+        .params     = "",
+        .help       = "show guest PCMCIA status"
+    },
+    {
+        .name       = "mice",
+        .args_type  = "",
+        .handler    = do_info_mice,
+        .user_print = NULL,
+        .params     = "",
+        .help       = "show which guest mouse is receiving events"
+    },
+    {
+        .name       = "vnc",
+        .args_type  = "",
+        .handler    = do_info_vnc,
+        .user_print = NULL,
+        .params     = "",
+        .help       = "show the vnc server status"
+    },
+    {
+        .name       = "name",
+        .args_type  = "",
+        .handler    = do_info_name,
+        .user_print = NULL,
+        .params     = "",
+        .help       = "show the current VM name"
+    },
+    {
+        .name       = "uuid",
+        .args_type  = "",
+        .handler    = do_info_uuid,
+        .user_print = NULL,
+        .params     = "",
+        .help       = "show the current VM UUID"
+    },
 #if defined(TARGET_PPC)
-    { "cpustats", "", do_info_cpu_stats,
-      "", "show CPU statistics", },
+    {
+        .name       = "cpustats",
+        .args_type  = "",
+        .handler    = do_info_cpu_stats,
+        .user_print = NULL,
+        .params     = "",
+        .help       = "show CPU statistics"
+    },
 #endif
 #if defined(CONFIG_SLIRP)
-    { "usernet", "", do_info_usernet,
-      "", "show user network stack connection states", },
+    {
+        .name       = "usernet",
+        .args_type  = "",
+        .handler    = do_info_usernet,
+        .user_print = NULL,
+        .params     = "",
+        .help       = "show user network stack connection states"
+    },
 #endif
-    { "migrate", "", do_info_migrate, "", "show migration status" },
-    { "balloon", "", do_info_balloon,
-      "", "show balloon information" },
-    { "qtree", "", do_info_qtree,
-      "", "show device tree" },
-    { "qdm", "", do_info_qdm,
-      "", "show qdev device model list" },
-    { NULL, NULL, },
+    {
+        .name       = "migrate",
+        .args_type  = "",
+        .handler    = do_info_migrate,
+        .user_print = NULL,
+        .params     = "",
+        .help       = "show migration status"
+    },
+    {
+        .name       = "balloon",
+        .args_type  = "",
+        .handler    = do_info_balloon,
+        .user_print = NULL,
+        .params     = "",
+        .help       = "show balloon information"
+    },
+    {
+        .name       = "qtree",
+        .args_type  = "",
+        .handler    = do_info_qtree,
+        .user_print = NULL,
+        .params     = "",
+        .help       = "show device tree"
+    },
+    {
+        .name       = "qdm",
+        .args_type  = "",
+        .handler    = do_info_qdm,
+        .user_print = NULL,
+        .params     = "",
+        .help       = "show qdev device model list"
+    },
+    {
+        .name       = NULL,
+        .args_type  = NULL,
+        .handler    = NULL,
+        .user_print = NULL,
+        .params     = NULL,
+        .help       = NULL
+    },
 };
 
 /*******************************************************************/
qemu-monitor.hx +493 -122

936 lines not on this page · raw message

Signature · 1 line
1.6.5.rc0
#2 lore raw

PATCH 2/7 monitor: Handle new and old style handlers

In reply to Luiz Capitulino

This commit changes monitor_handle_command() to support old style and new style handlers.

New style handlers are protocol independent, they return their data to the Monitor, which in turn decides how to print them (ie. user protocol vs. machine protocol).

Converted handlers will use the 'user_print' member of 'mon_cmd_t' to define its user protocol function, which will be called to print data in the user protocol format.

Handlers which don't have 'user_print' defined are not converted.

---
 monitor.c |   32 ++++++++++++++++++++++++++------
 1 files changed, 26 insertions(+), 6 deletions(-)
monitor.c +26 -6
index fe604d8..17754fb 100644
@@ -210,6 +210,11 @@ static int monitor_fprintf(FILE *stream, const char *fmt, ...)
     return 0;
 }
 
+static int monitor_handler_ported(const mon_cmd_t *cmd)
+{
+    return (cmd->user_print == NULL ? 0 : 1);
+}
+
 static int compare_cmd(const char *name, const char *list)
 {
     const char *p, *pstart;
@@ -3041,17 +3046,32 @@ static void monitor_handle_command(Monitor *mon, const char *cmdline)
     qdict = qdict_new();
 
     cmd = monitor_parse_command(mon, cmdline, qdict);
-    if (cmd) {
-        void (*handler)(Monitor *mon, const QDict *qdict);
+    if (!cmd)
+        goto out;
+
+    qemu_errors_to_mon(mon);
 
-        qemu_errors_to_mon(mon);
+    if (monitor_handler_ported(cmd)) {
+        QObject *data = NULL;
+        int (*handler_new)(Monitor *mon,
+                           const QDict *params, QObject **ret_data);
 
-        handler = cmd->handler;
-        handler(mon, qdict);
+        handler_new = cmd->handler;
+        handler_new(mon, qdict, &data);
 
-        qemu_errors_to_previous();
+        cmd->user_print(mon, data);
+
+        if (data)
+            qobject_decref(data);
+    } else {
+        void (*handler_old)(Monitor *mon, const QDict *qdict);
+        handler_old = cmd->handler;
+        handler_old(mon, qdict);
     }
 
+   qemu_errors_to_previous();
+
+out:
     QDECREF(qdict);
 }
 
Signature · 1 line
1.6.5.rc0
#3 lore raw

[Qemu-devel] Re: [PATCH 2/7] monitor: Handle new and old style handlers

Quoted 1 line · Luiz Capitulino

+ return (cmd->user_print == NULL ? 0 : 1);

cmd->user_print != NULL.

I would actually inline it at the use point. Also, calling a function with an extra argument is fine, so while keeping the void* handler you can do:

+ QObject *data = NULL;
+ int (*handler_new)(Monitor *mon,
+ const QDict *params, QObject **ret_data);

+ handler_new = cmd->handler;
+ handler_new(mon, qdict, &data);

+ if (cmd->user_print)
+ cmd->user_print(mon, data);
+ if (data)
+ qobject_decref(data);

If you do not like calling the function with the "wrong" number of arguments, you can mass-convert the functions to the new prototype new and leave anyway user_print == NULL.

What are the plans for the return code of handler_new?

Paolo

#4 lore raw

[Qemu-devel] Re: [PATCH 2/7] monitor: Handle new and old style handlers

Quoted 4 lines · On Thu, 17 Sep 2009 08:39:25 +0200 Paolo Bonzini <[email protected]> wrote:
Quoted 1 line · Luiz Capitulino

+ return (cmd->user_print == NULL ? 0 : 1);

cmd->user_print != NULL.

Right.

Quoted 16 lines

I would actually inline it at the use point. Also, calling a function with an extra argument is fine, so while keeping the void* handler you can do:

monitor.c +9 -0
+        QObject *data = NULL;
+        int (*handler_new)(Monitor *mon,
+                           const QDict *params, QObject **ret_data);
 
+        handler_new = cmd->handler;
+        handler_new(mon, qdict, &data);
 
+        if (cmd->user_print)
+                cmd->user_print(mon, data);
+        if (data)
+                qobject_decref(data);
Quoted 3 lines

If you do not like calling the function with the "wrong" number of arguments, you can mass-convert the functions to the new prototype new and leave anyway user_print == NULL.

The problem is that the monitor_handler_ported() branch can
have additional code in the future (eg. protocol emission code), so different branches makes things easier to understand.

Quoted 1 line

What are the plans for the return code of handler_new?

The protocol emission code will use it to emit 'error' or
'success' messages.

#5 lore raw

[Qemu-devel] Re: [PATCH 2/7] monitor: Handle new and old style handlers

Quoted 4 lines

The problem is that the monitor_handler_ported() branch can
have additional code in the future (eg. protocol emission code), so different branches makes things easier to understand.

Well, you don't know... It may end up in different functions, like

void print_cmd_result_user (Monitor *mon, MonitorCmd *cmd, int result,
QObject *data)

{
	if (result)
		...
	else if (cmd->user_print)
		cmd->user_print (mon, data);
}

void print_cmd_result_json (Monitor *mon, MonitorCmd *cmd, int result,
QObject *data)

{
	... make qdict with result and data ...
	qdict_print_json (mon->something, output_dict);
	qobject_decref (output_dict);
}

or it may end up not being a branch (but an indirect function call) for example:

	result = handler_new (mon, qdict, &data);
	mon->print_cmd_result (mon, cmd, result, data);
	if (data)
		qobject_decref (data);

I'd stay with the simplest thing for now. I'm not going to argue, especially if I'm overridden by other reviewers, of course.

Paolo

Paolo

#6 lore raw

[Qemu-devel] Re: [PATCH 2/7] monitor: Handle new and old style handlers

Quoted 6 lines · On Thu, 17 Sep 2009 15:28:32 +0200 Paolo Bonzini <[email protected]> wrote:
Quoted 4 lines

The problem is that the monitor_handler_ported() branch can
have additional code in the future (eg. protocol emission code), so different branches makes things easier to understand.

Well, you don't know... It may end up in different functions, like

Actually, I already have this code and will post shortly (for review,
not for inclusion).

#7 lore raw

PATCH 3/7 monitor: do_info(): handle new and old info handlers

In reply to Luiz Capitulino

do_info() is special, its job is to call 'info handlers'. This is similar to what monitor_handle_command() does, therefore do_info() also has to distinguish among new and old style info handlers.

This commit converts do_info() to the new QObject style and makes the appropriate changes so that it can handle both info handlers styles.

In the future, when all handlers are converted to QObject's style, it will be possible to share more code with monitor_handle_command().

Also note that this commit adds a new function called monitor_print_nothing(), which will be used by converted handlers that don't have data to print in the user protocol.

---
 monitor.c       |   44 ++++++++++++++++++++++++++++++++------------
 qemu-monitor.hx |    2 +-
 2 files changed, 33 insertions(+), 13 deletions(-)
monitor.c +32 -12
index 17754fb..cfbedf8 100644
@@ -210,6 +210,11 @@ static int monitor_fprintf(FILE *stream, const char *fmt, ...)
     return 0;
 }
 
+static void monitor_print_nothing(Monitor *mon, const QObject *data)
+{
+    return;
+}
+
 static int monitor_handler_ported(const mon_cmd_t *cmd)
 {
     return (cmd->user_print == NULL ? 0 : 1);
@@ -284,24 +289,39 @@ static void do_commit(Monitor *mon, const QDict *qdict)
     }
 }
 
-static void do_info(Monitor *mon, const QDict *qdict)
+static int do_info(Monitor *mon, const QDict *qdict, QObject **ret_data)
 {
+    int ret = 0;
     const mon_cmd_t *cmd;
     const char *item = qdict_get_try_str(qdict, "item");
-    void (*handler)(Monitor *);
 
-    if (!item)
-        goto help;
-    for(cmd = info_cmds; cmd->name != NULL; cmd++) {
+    if (!item) {
+        help_cmd(mon, "info");
+        return 0;
+    }
+
+    for (cmd = info_cmds; cmd->name != NULL; cmd++) {
         if (compare_cmd(item, cmd->name))
-            goto found;
+            break;
     }
- help:
-    help_cmd(mon, "info");
-    return;
- found:
-    handler = cmd->handler;
-    handler(mon);
+
+    if (cmd->name == NULL)
+        return -1;
+
+    if (monitor_handler_ported(cmd)) {
+        int (*handler_new)(Monitor *mon, QObject **ret_data);
+
+        handler_new = cmd->handler;
+        ret = handler_new(mon, ret_data);
+
+        cmd->user_print(mon, *ret_data);
+    } else {
+        void (*handler_old)(Monitor *mon);
+        handler_old = cmd->handler;
+        handler_old(mon);
+    }
+
+    return ret;
 }
 
 static void do_info_version(Monitor *mon)
qemu-monitor.hx +1 -1
index 400d2bd..b7217f3 100644
@@ -40,7 +40,7 @@ ETEXI
         .name       = "info",
         .args_type  = "item:s?",
         .handler    = do_info,
-        .user_print = NULL,
+        .user_print = monitor_print_nothing,
         .params     = "[subcommand]",
         .help       = "show various information about the system state"
     },
Signature · 1 line
1.6.5.rc0
#8 lore raw

Re: [Qemu-devel] [PATCH 3/7] monitor: do_info(): handle new and old info handlers

Quoted 27 lines · Luiz Capitulino

do_info() is special, its job is to call 'info handlers'. This is similar to what monitor_handle_command() does, therefore do_info() also has to distinguish among new and old style info handlers.

This commit converts do_info() to the new QObject style and makes the appropriate changes so that it can handle both info handlers styles.

In the future, when all handlers are converted to QObject's style, it will be possible to share more code with monitor_handle_command().

Also note that this commit adds a new function called monitor_print_nothing(), which will be used by converted handlers that don't have data to print in the user protocol.

---
 monitor.c       |   44 ++++++++++++++++++++++++++++++++------------
 qemu-monitor.hx |    2 +-
 2 files changed, 33 insertions(+), 13 deletions(-)
monitor.c +0 -0
index 17754fb..cfbedf8 100644

[...]

Quoted 42 lines
monitor.c +20 -12
@@ -284,24 +289,39 @@ static void do_commit(Monitor *mon, const QDict *qdict)
     }
 }
 
-static void do_info(Monitor *mon, const QDict *qdict)
+static int do_info(Monitor *mon, const QDict *qdict, QObject **ret_data)
 {
+    int ret = 0;
     const mon_cmd_t *cmd;
     const char *item = qdict_get_try_str(qdict, "item");
-    void (*handler)(Monitor *);
 
-    if (!item)
-        goto help;
-    for(cmd = info_cmds; cmd->name != NULL; cmd++) {
+    if (!item) {
+        help_cmd(mon, "info");
+        return 0;
+    }
+
+    for (cmd = info_cmds; cmd->name != NULL; cmd++) {
         if (compare_cmd(item, cmd->name))
-            goto found;
+            break;
     }
- help:
-    help_cmd(mon, "info");
-    return;
- found:
-    handler = cmd->handler;
-    handler(mon);
+
+    if (cmd->name == NULL)
+        return -1;
+
+    if (monitor_handler_ported(cmd)) {
+        int (*handler_new)(Monitor *mon, QObject **ret_data);
+
+        handler_new = cmd->handler;
+        ret = handler_new(mon, ret_data);
+
+        cmd->user_print(mon, *ret_data);

monitor.c static void do_commit(Monitor *mon, const QDict *qdict) · line 327

Quoted 10 lines
monitor.c +7 -0
+    } else {
+        void (*handler_old)(Monitor *mon);
+        handler_old = cmd->handler;
+        handler_old(mon);
+    }
+
+    return ret;
 }
 
 static void do_info_version(Monitor *mon)

Looks like this changes do_info() to fail without printing help when the "item" argument is not recognized. Fine with me, just mention it in the commit message, please.

[...]

#9 lore raw

Re: [Qemu-devel] [PATCH 3/7] monitor: do_info(): handle new and old info handlers

Quoted 81 lines · On Wed, 23 Sep 2009 17:46:47 +0200 Markus Armbruster <[email protected]> wrote:
Quoted 27 lines · Luiz Capitulino

do_info() is special, its job is to call 'info handlers'. This is similar to what monitor_handle_command() does, therefore do_info() also has to distinguish among new and old style info handlers.

This commit converts do_info() to the new QObject style and makes the appropriate changes so that it can handle both info handlers styles.

In the future, when all handlers are converted to QObject's style, it will be possible to share more code with monitor_handle_command().

Also note that this commit adds a new function called monitor_print_nothing(), which will be used by converted handlers that don't have data to print in the user protocol.

---
 monitor.c       |   44 ++++++++++++++++++++++++++++++++------------
 qemu-monitor.hx |    2 +-
 2 files changed, 33 insertions(+), 13 deletions(-)
monitor.c +0 -0
index 17754fb..cfbedf8 100644

[...]

Quoted 51 lines
monitor.c +27 -12
@@ -284,24 +289,39 @@ static void do_commit(Monitor *mon, const QDict *qdict)
     }
 }
 
-static void do_info(Monitor *mon, const QDict *qdict)
+static int do_info(Monitor *mon, const QDict *qdict, QObject **ret_data)
 {
+    int ret = 0;
     const mon_cmd_t *cmd;
     const char *item = qdict_get_try_str(qdict, "item");
-    void (*handler)(Monitor *);
 
-    if (!item)
-        goto help;
-    for(cmd = info_cmds; cmd->name != NULL; cmd++) {
+    if (!item) {
+        help_cmd(mon, "info");
+        return 0;
+    }
+
+    for (cmd = info_cmds; cmd->name != NULL; cmd++) {
         if (compare_cmd(item, cmd->name))
-            goto found;
+            break;
     }
- help:
-    help_cmd(mon, "info");
-    return;
- found:
-    handler = cmd->handler;
-    handler(mon);
+
+    if (cmd->name == NULL)
+        return -1;
+
+    if (monitor_handler_ported(cmd)) {
+        int (*handler_new)(Monitor *mon, QObject **ret_data);
+
+        handler_new = cmd->handler;
+        ret = handler_new(mon, ret_data);
+
+        cmd->user_print(mon, *ret_data);
+    } else {
+        void (*handler_old)(Monitor *mon);
+        handler_old = cmd->handler;
+        handler_old(mon);
+    }
+
+    return ret;
 }
 
Quoted 5 lines

monitor.c static void do_commit(Monitor *mon, const QDict *qdict) · line 327

Quoted 1 line
monitor.c +0 -0
 static void do_info_version(Monitor *mon)

Looks like this changes do_info() to fail without printing help when the "item" argument is not recognized. Fine with me, just mention it in the commit message, please.

Actually, it has to maintain compatibility with the current
code, so this is a well spotted bug.

Will fix, thanks.

#10 lore raw

PATCH 4/7 monitor: Convert do_quit() do QObject

In reply to Luiz Capitulino
---
 monitor.c       |    8 +++++++-
 qemu-monitor.hx |    2 +-
 2 files changed, 8 insertions(+), 2 deletions(-)
monitor.c +7 -1
index cfbedf8..b324538 100644
@@ -459,9 +459,15 @@ static void do_info_cpu_stats(Monitor *mon)
 }
 #endif
 
-static void do_quit(Monitor *mon, const QDict *qdict)
+/**
+ * do_quit(): Quit QEMU execution
+ *
+ * return always succeed.
+ */
+static int do_quit(Monitor *mon, const QDict *qdict, QObject **ret_data)
 {
     exit(0);
+    return 0;
 }
 
 static int eject_device(Monitor *mon, BlockDriverState *bs, int force)
qemu-monitor.hx +1 -1
index b7217f3..401d5c5 100644
@@ -118,7 +118,7 @@ ETEXI
         .name       = "q|quit",
         .args_type  = "",
         .handler    = do_quit,
-        .user_print = NULL,
+        .user_print = monitor_print_nothing,
         .params     = "",
         .help       = "quit the emulator"
     },
Signature · 1 line
1.6.5.rc0
#11 lore raw

PATCH 5/7 monitor: Convert do_stop() to QObject

In reply to Luiz Capitulino
---
 monitor.c       |    8 +++++++-
 qemu-monitor.hx |    2 +-
 2 files changed, 8 insertions(+), 2 deletions(-)
monitor.c +7 -1
index b324538..9ef9108 100644
@@ -604,9 +604,15 @@ static void do_singlestep(Monitor *mon, const QDict *qdict)
     }
 }
 
-static void do_stop(Monitor *mon, const QDict *qdict)
+/**
+ * do_stop(): Stop VM execution
+ *
+ * return always succeed.
+ */
+static int do_stop(Monitor *mon, const QDict *qdict, QObject **ret_data)
 {
     vm_stop(EXCP_INTERRUPT);
+    return 0;
 }
 
 static void encrypted_bdrv_it(void *opaque, BlockDriverState *bs);
qemu-monitor.hx +1 -1
index 401d5c5..f6c9911 100644
@@ -285,7 +285,7 @@ ETEXI
         .name       = "stop",
         .args_type  = "",
         .handler    = do_stop,
-        .user_print = NULL,
+        .user_print = monitor_print_nothing,
         .params     = "",
         .help       = "stop emulation",
     },
Signature · 1 line
1.6.5.rc0
#12 lore raw

PATCH 6/7 monitor: Convert do_system_reset() to QObject

In reply to Luiz Capitulino
---
 monitor.c       |    8 +++++++-
 qemu-monitor.hx |    2 +-
 2 files changed, 8 insertions(+), 2 deletions(-)
monitor.c +7 -1
index 9ef9108..ef2d8c1 100644
@@ -1300,9 +1300,15 @@ static void do_boot_set(Monitor *mon, const QDict *qdict)
     }
 }
 
-static void do_system_reset(Monitor *mon, const QDict *qdict)
+/**
+ * do_system_reset(): Issue a machine reset
+ *
+ * return always succeed.
+ */
+static int do_system_reset(Monitor *mon, const QDict *qdict, QObject **ret_data)
 {
     qemu_system_reset_request();
+    return 0;
 }
 
 static void do_system_powerdown(Monitor *mon, const QDict *qdict)
qemu-monitor.hx +1 -1
index f6c9911..5b3f84f 100644
@@ -464,7 +464,7 @@ ETEXI
         .name       = "system_reset",
         .args_type  = "",
         .handler    = do_system_reset,
-        .user_print = NULL,
+        .user_print = monitor_print_nothing,
         .params     = "",
         .help       = "reset the system"
     },
Signature · 1 line
1.6.5.rc0
#13 lore raw

PATCH 7/7 monitor: Convert do_system_powerdown() to QObject

In reply to Luiz Capitulino
---
 monitor.c       |    9 ++++++++-
 qemu-monitor.hx |    2 +-
 2 files changed, 9 insertions(+), 2 deletions(-)
monitor.c +8 -1
index ef2d8c1..db73642 100644
@@ -1311,9 +1311,16 @@ static int do_system_reset(Monitor *mon, const QDict *qdict, QObject **ret_data)
     return 0;
 }
 
-static void do_system_powerdown(Monitor *mon, const QDict *qdict)
+/**
+ * do_system_powerdown(): Issue a machine powerdown
+ *
+ * return always succeed.
+ */
+static int do_system_powerdown(Monitor *mon, const QDict *qdict,
+                               QObject **ret_data)
 {
     qemu_system_powerdown_request();
+    return 0;
 }
 
 #if defined(TARGET_I386)
qemu-monitor.hx +1 -1
index 5b3f84f..1159686 100644
@@ -478,7 +478,7 @@ ETEXI
         .name       = "system_powerdown",
         .args_type  = "",
         .handler    = do_system_powerdown,
-        .user_print = NULL,
+        .user_print = monitor_print_nothing,
         .params     = "",
         .help       = "send system power down event"
     },
Signature · 1 line
1.6.5.rc0