Skip to contentSkip to conversation

Monitor handlers convertion to QObject

RFC In review Luiz Capitulino 4 participants 12 messages Sep 3, 2009 – Sep 23, 2009

lore
Share & tools
lore
#0 lore raw

cover Monitor handlers convertion to QObject

Hi There,

This is a RFC for the next phase of the QEMU Monitor Protocol project,
in this phase handlers will get fully "structurized".

I was waiting for the first phase to be merged before sending this, but
as it's already in staging and as this is just a RFC, I've decided to send.

This series adds the infrastructure needed to accommodate the new style
handlers and ports do_info_balloon() and do_balloon() to QObject style.

Please, note that I've chosen to stay simple. I already have patches for
QList and advanced stuff (like the 'ninja action' suggested by Anthony) but for now let's concentrate on design decisions that will impact the protocol format.

Besides the 'user_print' approach, it's very important to discuss the
following:

1. Return data
--------------

For do_info_balloon() I'm always returning a QString. The 'actual' info
could be something else (QDict?), but I think QString is good, because it's simple.

Choosing the best set of data types to return is an issue and I don't
think we can have a general rule for this, the solution will be to review *each* command handler port and be sure we are doing the right thing.

I hope people don't get bored in reviewing.

2. Return code
--------------

All handlers will have a return code. For this series they return 0
for success and -1 for error.

My current plan is that the procotol will *always* emit something like:

{ "__result__": 0, "__data__": { ... } }

Where the standard keys 'result' and 'data' will be pushed by common
code (monitor_handle_command(), in this case).

Some people have suggested us to define errors codes, but I dislike this
because I have the impression we will end up defining errors per-handlers, which is a lot of work and more protocol definitions to maintain.

Another issue in this subject is that sometimes we will have to do
a not so small refactor to get the proper error code. I mean, sometimes the functions which the handlers call return void, and those functions in turn call other functions which also return void. This seem to be the case of do_balloon(), for example.

A possible solution is to only return error when it's easy, otherwise we
could always return 0 (which is what we have today), the problem though is that changing this in the future will cause trouble.

Suggestions?

#1 lore raw

PATCH 1/5 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.

Additionally, it will also serve as a flag to say if a given handler has already been ported to support the machine protocol.

---
 monitor.c       |   69 +++++++++++++++---------------
 qemu-monitor.hx |  124 ++++++++++++++++++++++++++++--------------------------
 2 files changed, 99 insertions(+), 94 deletions(-)
monitor.c +35 -34
index a242b4b..b43a287 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;
@@ -1807,80 +1808,80 @@ 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,
+    { "version", "", do_info_version, NULL,
       "", "show the version of QEMU" },
-    { "network", "", do_info_network,
+    { "network", "", do_info_network, NULL,
       "", "show the network state" },
-    { "chardev", "", qemu_chr_info,
+    { "chardev", "", qemu_chr_info, NULL,
       "", "show the character devices" },
-    { "block", "", bdrv_info,
+    { "block", "", bdrv_info, NULL,
       "", "show the block devices" },
-    { "blockstats", "", bdrv_info_stats,
+    { "blockstats", "", bdrv_info_stats, NULL,
       "", "show block device statistics" },
-    { "registers", "", do_info_registers,
+    { "registers", "", do_info_registers, NULL,
       "", "show the cpu registers" },
-    { "cpus", "", do_info_cpus,
+    { "cpus", "", do_info_cpus, NULL,
       "", "show infos for each CPU" },
-    { "history", "", do_info_history,
+    { "history", "", do_info_history, NULL,
       "", "show the command line history", },
-    { "irq", "", irq_info,
+    { "irq", "", irq_info, NULL,
       "", "show the interrupts statistics (if available)", },
-    { "pic", "", pic_info,
+    { "pic", "", pic_info, NULL,
       "", "show i8259 (PIC) state", },
-    { "pci", "", pci_info,
+    { "pci", "", pci_info, NULL,
       "", "show PCI info", },
 #if defined(TARGET_I386) || defined(TARGET_SH4)
-    { "tlb", "", tlb_info,
+    { "tlb", "", tlb_info, NULL,
       "", "show virtual to physical memory mappings", },
 #endif
 #if defined(TARGET_I386)
-    { "mem", "", mem_info,
+    { "mem", "", mem_info, NULL,
       "", "show the active virtual memory mappings", },
-    { "hpet", "", do_info_hpet,
+    { "hpet", "", do_info_hpet, NULL,
       "", "show state of HPET", },
 #endif
-    { "jit", "", do_info_jit,
+    { "jit", "", do_info_jit, NULL,
       "", "show dynamic compiler info", },
-    { "kvm", "", do_info_kvm,
+    { "kvm", "", do_info_kvm, NULL,
       "", "show KVM information", },
-    { "numa", "", do_info_numa,
+    { "numa", "", do_info_numa, NULL,
       "", "show NUMA information", },
-    { "usb", "", usb_info,
+    { "usb", "", usb_info, NULL,
       "", "show guest USB devices", },
-    { "usbhost", "", usb_host_info,
+    { "usbhost", "", usb_host_info, NULL,
       "", "show host USB devices", },
-    { "profile", "", do_info_profile,
+    { "profile", "", do_info_profile, NULL,
       "", "show profiling information", },
-    { "capture", "", do_info_capture,
+    { "capture", "", do_info_capture, NULL,
       "", "show capture information" },
-    { "snapshots", "", do_info_snapshots,
+    { "snapshots", "", do_info_snapshots, NULL,
       "", "show the currently saved VM snapshots" },
-    { "status", "", do_info_status,
+    { "status", "", do_info_status, NULL,
       "", "show the current VM status (running|paused)" },
-    { "pcmcia", "", pcmcia_info,
+    { "pcmcia", "", pcmcia_info, NULL,
       "", "show guest PCMCIA status" },
-    { "mice", "", do_info_mice,
+    { "mice", "", do_info_mice, NULL,
       "", "show which guest mouse is receiving events" },
-    { "vnc", "", do_info_vnc,
+    { "vnc", "", do_info_vnc, NULL,
       "", "show the vnc server status"},
-    { "name", "", do_info_name,
+    { "name", "", do_info_name, NULL,
       "", "show the current VM name" },
-    { "uuid", "", do_info_uuid,
+    { "uuid", "", do_info_uuid, NULL,
       "", "show the current VM UUID" },
 #if defined(TARGET_PPC)
-    { "cpustats", "", do_info_cpu_stats,
+    { "cpustats", "", do_info_cpu_stats, NULL,
       "", "show CPU statistics", },
 #endif
 #if defined(CONFIG_SLIRP)
-    { "usernet", "", do_info_usernet,
+    { "usernet", "", do_info_usernet, NULL,
       "", "show user network stack connection states", },
 #endif
-    { "migrate", "", do_info_migrate, "", "show migration status" },
-    { "balloon", "", do_info_balloon,
+    { "migrate", "", do_info_migrate, NULL, "", "show migration status" },
+    { "balloon", "", do_info_balloon, NULL,
       "", "show balloon information" },
-    { "qtree", "", do_info_qtree,
+    { "qtree", "", do_info_qtree, NULL,
       "", "show device tree" },
-    { "qdm", "", do_info_qdm,
+    { "qdm", "", do_info_qdm, NULL,
       "", "show qdev device model list" },
     { NULL, NULL, },
 };
qemu-monitor.hx +64 -60

471 lines not on this page · raw message

Signature · 1 line
1.6.4.2.253.g0b1fac
#2 lore raw

[Qemu-devel] Re: [PATCH 1/5] monitor: Add user_print() to mon_cmd_t

Quoted 25 lines · Luiz Capitulino

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

Additionally, it will also serve as a flag to say if a given handler has already been ported to support the machine protocol.

---
 monitor.c       |   69 +++++++++++++++---------------
 qemu-monitor.hx |  124 ++++++++++++++++++++++++++++--------------------------
 2 files changed, 99 insertions(+), 94 deletions(-)
monitor.c +1 -0
index a242b4b..b43a287 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;

monitor.c static const mon_cmd_t mon_cmds[] = { · line 1810

Quoted 3 lines
monitor.c +0 -0
@@ -1807,80 +1808,80 @@ static const mon_cmd_t mon_cmds[] = {
 
 /* Please update qemu-monitor.hx when adding or changing commands */
 static const mon_cmd_t info_cmds[] = {

Once that your are changing all of them, could you use c99 initializers, that way it is easier to see what the action is.

monitor.c static const mon_cmd_t mon_cmds[] = { · line 1812

Quoted 3 lines
monitor.c +1 -1
-    { "version", "", do_info_version,
+    { "version", "", do_info_version, NULL,
       "", "show the version of QEMU" },

Later, Juan.

#3 lore raw

[Qemu-devel] Re: [PATCH 1/5] monitor: Add user_print() to mon_cmd_t

Quoted 27 lines · On Thu, 03 Sep 2009 20:55:51 +0200 Juan Quintela <[email protected]> wrote:
Quoted 26 lines · Luiz Capitulino

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

Additionally, it will also serve as a flag to say if a given handler has already been ported to support the machine protocol.

---
 monitor.c       |   69 +++++++++++++++---------------
 qemu-monitor.hx |  124 ++++++++++++++++++++++++++++--------------------------
 2 files changed, 99 insertions(+), 94 deletions(-)
monitor.c +1 -0
index a242b4b..b43a287 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;
@@ -1807,80 +1808,80 @@ static const mon_cmd_t mon_cmds[] = {
 
Quoted 5 lines

monitor.c static const mon_cmd_t mon_cmds[] = { · line 1810

Quoted 2 lines
monitor.c +0 -0
 /* Please update qemu-monitor.hx when adding or changing commands */
 static const mon_cmd_t info_cmds[] = {

Once that your are changing all of them, could you use c99 initializers, that way it is easier to see what the action is.

Yeah, I will do that for the real submission.

#4 lore raw

PATCH 2/5 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).

Ported 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 ported yet, nothing changes for them.

---
 monitor.c |   27 +++++++++++++++++++++------
 1 files changed, 21 insertions(+), 6 deletions(-)
monitor.c +21 -6
index b43a287..9886bb0 100644
@@ -2827,17 +2827,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);
 
-        handler = cmd->handler;
-        handler(mon, qdict);
+    if (cmd->user_print) {
+        QObject *data = NULL;
+        int (*handler_new)(Monitor *mon, const QDict *params,
+                           QObject **ret_data);
 
-        qemu_errors_to_previous();
+        handler_new = cmd->handler;
+        handler_new(mon, qdict, &data);
+
+        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.4.2.253.g0b1fac
#5 lore raw

PATCH 3/5 monitor: Port do_info() to QObject

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 ports do_info() to call info handlers according to the new QObject style.

It's important to note that:

1. the return value of do_info() will be the same of the called handler
2. monitor_print_nothing() will be used by handlers to... print nothing :)

---
 monitor.c       |   45 +++++++++++++++++++++++++++++++++------------
 qemu-monitor.hx |    2 +-
 2 files changed, 34 insertions(+), 13 deletions(-)
monitor.c +33 -12
index 9886bb0..f9f3cbd 100644
@@ -208,6 +208,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 compare_cmd(const char *name, const char *list)
 {
     const char *p, *pstart;
@@ -277,24 +282,40 @@ 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;
     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;
+
+    ret = 0;
+    if (cmd->user_print) {
+        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 *);
+        handler_old = cmd->handler;
+        handler_old(mon);
+    }
+
+    return ret;
 }
 
 static void do_info_version(Monitor *mon)
qemu-monitor.hx +1 -1
index a6d0f2e..44402c5 100644
@@ -22,7 +22,7 @@ STEXI
 Commit changes to the disk images (if -snapshot is used) or backing files.
 ETEXI
 
-    { "info", "item:s?", do_info, NULL,
+    { "info", "item:s?", do_info, monitor_print_nothing,
       "[subcommand]", "show various information about the system state" },
 STEXI
 @item info @var{subcommand}
Signature · 1 line
1.6.4.2.253.g0b1fac
#6 lore raw

PATCH 4/5 monitor: Port do_info_balloon() to QObject

In reply to Luiz Capitulino

do_info_balloon() returns 0 on success or -1 when the 'balloon' value could not be queried.

The returned data is always a QString.

This also introduces monitor_print_qobject(), which can be used as a standard way to print QObjects in the user protocol format.

---
 monitor.c |   41 +++++++++++++++++++++++++++++++++--------
 1 files changed, 33 insertions(+), 8 deletions(-)
monitor.c +33 -8
index f9f3cbd..545833d 100644
@@ -213,6 +213,22 @@ static void monitor_print_nothing(Monitor *mon, const QObject *data)
     return;
 }
 
+static void monitor_print_qobject(Monitor *mon, const QObject *data)
+{
+    switch (qobject_type(data)) {
+        case QTYPE_QSTRING:
+            monitor_printf(mon, "%s",qstring_get_str(qobject_to_qstring(data)));
+            break;
+        case QTYPE_QINT:
+            monitor_printf(mon, "%lu", qint_get_int(qobject_to_qint(data)));
+            break;
+        default:
+            monitor_printf(mon, "ERROR: unsupported type: %d\n",
+                                                        qobject_type(data));
+            break;
+    }
+}
+
 static int compare_cmd(const char *name, const char *list)
 {
     const char *p, *pstart;
@@ -1586,18 +1602,27 @@ static void do_balloon(Monitor *mon, const QDict *qdict)
     qemu_balloon(target << 20);
 }
 
-static void do_info_balloon(Monitor *mon)
+static int do_info_balloon(Monitor *mon, QObject **ret_data)
 {
+    QString *qs;
     ram_addr_t actual;
+    int ret = -1;
 
     actual = qemu_balloon_status();
-    if (kvm_enabled() && !kvm_has_sync_mmu())
-        monitor_printf(mon, "Using KVM without synchronous MMU, "
+    if (kvm_enabled() && !kvm_has_sync_mmu()) {
+        qs = qstring_from_str("Using KVM without synchronous MMU, "
                        "ballooning disabled\n");
-    else if (actual == 0)
-        monitor_printf(mon, "Ballooning not activated in VM\n");
-    else
-        monitor_printf(mon, "balloon: actual=%d\n", (int)(actual >> 20));
+    } else if (actual == 0) {
+        qs = qstring_from_str("Ballooning not activated in VM\n");
+    } else {
+        char buf[128];
+        sprintf(buf, "balloon: actual=%d\n", (int)(actual >> 20));
+        qs = qstring_from_str(buf);
+        ret = 0;
+    }
+
+    *ret_data = QOBJECT(qs);
+    return ret;
 }
 
 static qemu_acl *find_acl(Monitor *mon, const char *name)
@@ -1898,7 +1923,7 @@ static const mon_cmd_t info_cmds[] = {
       "", "show user network stack connection states", },
 #endif
     { "migrate", "", do_info_migrate, NULL, "", "show migration status" },
-    { "balloon", "", do_info_balloon, NULL,
+    { "balloon", "", do_info_balloon, monitor_print_qobject,
       "", "show balloon information" },
     { "qtree", "", do_info_qtree, NULL,
       "", "show device tree" },
Signature · 1 line
1.6.4.2.253.g0b1fac
#7 lore raw

Re: [Qemu-devel] [PATCH 4/5] monitor: Port do_info_balloon() to QObject

Quoted 18 lines · Luiz Capitulino

do_info_balloon() returns 0 on success or -1 when the 'balloon' value could not be queried.

The returned data is always a QString.

This also introduces monitor_print_qobject(), which can be used as a standard way to print QObjects in the user protocol format.

---
 monitor.c |   41 +++++++++++++++++++++++++++++++++--------
 1 files changed, 33 insertions(+), 8 deletions(-)
monitor.c +0 -0
index f9f3cbd..545833d 100644

[...]

Quoted 18 lines
monitor.c +5 -4
@@ -1586,18 +1602,27 @@ static void do_balloon(Monitor *mon, const QDict *qdict)
     qemu_balloon(target << 20);
 }
 
-static void do_info_balloon(Monitor *mon)
+static int do_info_balloon(Monitor *mon, QObject **ret_data)
 {
+    QString *qs;
     ram_addr_t actual;
+    int ret = -1;
 
     actual = qemu_balloon_status();
-    if (kvm_enabled() && !kvm_has_sync_mmu())
-        monitor_printf(mon, "Using KVM without synchronous MMU, "
+    if (kvm_enabled() && !kvm_has_sync_mmu()) {
+        qs = qstring_from_str("Using KVM without synchronous MMU, "
                        "ballooning disabled\n");
-    else if (actual == 0)

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

Quoted 10 lines
monitor.c +7 -3
-        monitor_printf(mon, "Ballooning not activated in VM\n");
-    else
-        monitor_printf(mon, "balloon: actual=%d\n", (int)(actual >> 20));
+    } else if (actual == 0) {
+        qs = qstring_from_str("Ballooning not activated in VM\n");
+    } else {
+        char buf[128];
+        sprintf(buf, "balloon: actual=%d\n", (int)(actual >> 20));
+        qs = qstring_from_str(buf);
+        ret = 0;

If this pattern turns out to be common, let's create qstring_printf() to print to a new qstring.

Quoted 16 lines
monitor.c +5 -1
+    }
+
+    *ret_data = QOBJECT(qs);
+    return ret;
 }
 
 static qemu_acl *find_acl(Monitor *mon, const char *name)
@@ -1898,7 +1923,7 @@ static const mon_cmd_t info_cmds[] = {
       "", "show user network stack connection states", },
 #endif
     { "migrate", "", do_info_migrate, NULL, "", "show migration status" },
-    { "balloon", "", do_info_balloon, NULL,
+    { "balloon", "", do_info_balloon, monitor_print_qobject,
       "", "show balloon information" },
     { "qtree", "", do_info_qtree, NULL,
       "", "show device tree" },
#8 lore raw

Re: [Qemu-devel] [PATCH 4/5] monitor: Port do_info_balloon() to QObject

Quoted 44 lines · On Wed, 23 Sep 2009 17:49:42 +0200 Markus Armbruster <[email protected]> wrote:
Quoted 18 lines · Luiz Capitulino

do_info_balloon() returns 0 on success or -1 when the 'balloon' value could not be queried.

The returned data is always a QString.

This also introduces monitor_print_qobject(), which can be used as a standard way to print QObjects in the user protocol format.

---
 monitor.c |   41 +++++++++++++++++++++++++++++++++--------
 1 files changed, 33 insertions(+), 8 deletions(-)
monitor.c +0 -0
index f9f3cbd..545833d 100644

[...]

Quoted 23 lines
monitor.c +7 -7
@@ -1586,18 +1602,27 @@ static void do_balloon(Monitor *mon, const QDict *qdict)
     qemu_balloon(target << 20);
 }
 
-static void do_info_balloon(Monitor *mon)
+static int do_info_balloon(Monitor *mon, QObject **ret_data)
 {
+    QString *qs;
     ram_addr_t actual;
+    int ret = -1;
 
     actual = qemu_balloon_status();
-    if (kvm_enabled() && !kvm_has_sync_mmu())
-        monitor_printf(mon, "Using KVM without synchronous MMU, "
+    if (kvm_enabled() && !kvm_has_sync_mmu()) {
+        qs = qstring_from_str("Using KVM without synchronous MMU, "
                        "ballooning disabled\n");
-    else if (actual == 0)
-        monitor_printf(mon, "Ballooning not activated in VM\n");
-    else
-        monitor_printf(mon, "balloon: actual=%d\n", (int)(actual >> 20));
+    } else if (actual == 0) {
+        qs = qstring_from_str("Ballooning not activated in VM\n");
Quoted 8 lines

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

Quoted 5 lines
monitor.c +5 -0
+    } else {
+        char buf[128];
+        sprintf(buf, "balloon: actual=%d\n", (int)(actual >> 20));
+        qs = qstring_from_str(buf);
+        ret = 0;

If this pattern turns out to be common, let's create qstring_printf() to print to a new qstring.

Yes, I already have it in my tree, but do_info_balloon() is a bit
different now.

This is my RFC series, right? Things change fast on QMP buggy world. :)

#9 lore raw

PATCH 5/5 monitor: Port do_balloon() to QObject

In reply to Luiz Capitulino
---
 monitor.c       |    3 ++-
 qemu-monitor.hx |    2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)
monitor.c +2 -1
index 545833d..71aef60 100644
@@ -1595,11 +1595,12 @@ static void do_info_status(Monitor *mon)
 }
 
 
-static void do_balloon(Monitor *mon, const QDict *qdict)
+static int do_balloon(Monitor *mon, const QDict *qdict, QObject **ret_data)
 {
     int value = qdict_get_int(qdict, "value");
     ram_addr_t target = value;
     qemu_balloon(target << 20);
+    return 0;
 }
 
 static int do_info_balloon(Monitor *mon, QObject **ret_data)
qemu-monitor.hx +1 -1
index 44402c5..eec6731 100644
@@ -552,7 +552,7 @@ STEXI
 Redirect TCP or UDP connections from host to guest (requires -net user).
 ETEXI
 
-    { "balloon", "value:i", do_balloon, NULL,
+    { "balloon", "value:i", do_balloon, monitor_print_nothing,
       "target", "request VM to change it's memory allocation (in MB)" },
 STEXI
 @item balloon @var{value}
Signature · 1 line
1.6.4.2.253.g0b1fac
#10 lore raw
In reply to Luiz Capitulino

Hi,

Quoted 3 lines

Some people have suggested us to define errors codes, but I dislike this
because I have the impression we will end up defining errors per-handlers, which is a lot of work and more protocol definitions to maintain.

What about error messages?

I've recently added some infrastructure for error messages: qemu_error() + friends. Intention is to direct error messages to the correct place, especially for code which can be called from multiple paths. Device creation for example can be triggered by command line (errors should go to stderr) or via hotplug monitor commands (errors should go to the monitor).

You might want to add a third error sink which stuffs error messages into a Qstring, so you can pass them along as Qobject without the code emitting the error message knowing anything about it.

Quoted 5 lines

Another issue in this subject is that sometimes we will have to do
a not so small refactor to get the proper error code. I mean, sometimes the functions which the handlers call return void, and those functions in turn call other functions which also return void. This seem to be the case of do_balloon(), for example.

There are also a few places which call exit(1) on error. Which is ok when something goes wrong while creating the virtual machine, but not when some monitor command failed ...

Quoted 3 lines

A possible solution is to only return error when it's easy, otherwise we
could always return 0 (which is what we have today), the problem though is that changing this in the future will cause trouble.

Serious code audit is more work initially, but I think we well be very happy we did it in the long run ...

cheers,
Gerd

#11 lore raw
Quoted 7 lines · On Thu, 03 Sep 2009 22:30:08 +0200 Gerd Hoffmann <[email protected]> wrote:
   Hi,
Quoted 3 lines

Some people have suggested us to define errors codes, but I dislike this
because I have the impression we will end up defining errors per-handlers, which is a lot of work and more protocol definitions to maintain.

What about error messages?

Yes, I had error messages in mind.

Handlers that handle errors today already print error messages,
this way the additional effort would be with the ones which don't handle errors.

However, my initial argument is not very strong. We already have
per-handlers errors today and will also have them with strings.

Quoted 10 lines

I've recently added some infrastructure for error messages:
qemu_error() + friends. Intention is to direct error messages to the correct place, especially for code which can be called from multiple paths. Device creation for example can be triggered by command line (errors should go to stderr) or via hotplug monitor commands (errors should go to the monitor).

You might want to add a third error sink which stuffs error messages into a Qstring, so you can pass them along as Qobject without the code emitting the error message knowing anything about it.

Ok, I will review qemu_error() and consider your suggestion.

Quoted 10 lines
Quoted 6 lines

Another issue in this subject is that sometimes we will have to do
a not so small refactor to get the proper error code. I mean, sometimes the functions which the handlers call return void, and those functions in turn call other functions which also return void. This seem to be the case of do_balloon(), for example.

There are also a few places which call exit(1) on error. Which is ok when something goes wrong while creating the virtual machine, but not when some monitor command failed ...

Right.

Quoted 7 lines
Quoted 4 lines

A possible solution is to only return error when it's easy, otherwise we
could always return 0 (which is what we have today), the problem though is that changing this in the future will cause trouble.

Serious code audit is more work initially, but I think we well be very happy we did it in the long run ...

That's right.

I'm doing my best to have the protocol working ASAP, but it's
unfortunate that sometimes the Right Thing takes more time.