Skip to contentSkip to conversation

qmp hmp balloon: Cleanups around error reporting

PATCH Superseded Markus Armbruster 4 participants 22 messages Jan 13, 2015 – Feb 11, 2015

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover qmp hmp balloon: Cleanups around error reporting

I'm including balloon patches in the hope that they too can go through Luiz's tree.

Markus Armbruster (9):
qmp hmp: Factor out common "using spice" test
qmp hmp: Improve error messages when SPICE is not in use
hmp: Compile hmp_info_spice() only with CONFIG_SPICE
qmp: Clean up qmp_query_spice() #ifndef !CONFIG_SPICE dummy
qmp: Simplify recognition of capability negotiation command
qmp: Eliminate silly QERR_COMMAND_NOT_FOUND macro
balloon: Inline qemu_balloon(), qemu_balloon_status()
balloon: Factor out common "is balloon active" test
balloon: Eliminate silly QERR_ macros

 balloon.c                 | 59 ++++++++++++++++++-----------------------------
 hmp.c                     |  2 ++
 include/qapi/qmp/qerror.h |  9 --------
 include/ui/qemu-spice.h   | 10 ++++++++
 monitor.c                 | 19 +++++++--------
 qapi/qmp-dispatch.c       |  3 ++-
 qmp.c                     | 27 +++++++++++-----------
 7 files changed, 58 insertions(+), 71 deletions(-)
Signature · 1 line
1.9.3
#1 lore raw

PATCH 1/9 qmp hmp: Factor out common "using spice" test

Into qemu_using_spice(). For want of a better place, put it next the existing monitor command handler dummies in qemu-spice.h.

---
 include/ui/qemu-spice.h | 10 ++++++++++
 monitor.c               |  5 +++--
 qmp.c                   | 11 +++--------
 3 files changed, 16 insertions(+), 10 deletions(-)
include/ui/qemu-spice.h +10 -0
index a93b4b2..b3f2679 100644
@@ -88,4 +88,14 @@ static inline int qemu_spice_display_add_client(int csock, int skipauth,
 
 #endif /* CONFIG_SPICE */
 
+static inline int qemu_using_spice(Error **errp)
+{
+    if (!using_spice) {
+        /* correct one? spice isn't a device ,,, */
+        error_set(errp, QERR_DEVICE_NOT_ACTIVE, "spice");
+        return 0;
+    }
+    return 1;
+}
+
 #endif /* QEMU_SPICE_H */
monitor.c +3 -2
index 1808e41..cd81289 100644
@@ -1095,11 +1095,12 @@ static int client_migrate_info(Monitor *mon, const QDict *qdict,
     const char *subject  = qdict_get_try_str(qdict, "cert-subject");
     int port             = qdict_get_try_int(qdict, "port", -1);
     int tls_port         = qdict_get_try_int(qdict, "tls-port", -1);
+    Error *err;
     int ret;
 
     if (strcmp(protocol, "spice") == 0) {
-        if (!using_spice) {
-            qerror_report(QERR_DEVICE_NOT_ACTIVE, "spice");
+        if (!qemu_using_spice(&err)) {
+            qerror_report_err(err);
             return -1;
         }
 
qmp.c +3 -8
index 0b4f131..f01ae7d 100644
@@ -287,9 +287,7 @@ void qmp_set_password(const char *protocol, const char *password,
     }
 
     if (strcmp(protocol, "spice") == 0) {
-        if (!using_spice) {
-            /* correct one? spice isn't a device ,,, */
-            error_set(errp, QERR_DEVICE_NOT_ACTIVE, "spice");
+        if (!qemu_using_spice(errp)) {
             return;
         }
         rc = qemu_spice_set_passwd(password, fail_if_connected,
@@ -335,9 +333,7 @@ void qmp_expire_password(const char *protocol, const char *whenstr,
     }
 
     if (strcmp(protocol, "spice") == 0) {
-        if (!using_spice) {
-            /* correct one? spice isn't a device ,,, */
-            error_set(errp, QERR_DEVICE_NOT_ACTIVE, "spice");
+        if (!qemu_using_spice(errp)) {
             return;
         }
         rc = qemu_spice_set_pw_expire(when);
@@ -562,8 +558,7 @@ void qmp_add_client(const char *protocol, const char *fdname,
     }
 
     if (strcmp(protocol, "spice") == 0) {
-        if (!using_spice) {
-            error_set(errp, QERR_DEVICE_NOT_ACTIVE, "spice");
+        if (!qemu_using_spice(errp)) {
             close(fd);
             return;
         }
Signature · 1 line
1.9.3
Reviewed-by on v1 1/9
#2 lore raw

Re: [Qemu-devel] [PATCH 1/9] qmp hmp: Factor out common "using spice" test

Quoted 15 lines · Markus Armbruster

Into qemu_using_spice(). For want of a better place, put it next the existing monitor command handler dummies in qemu-spice.h.

---
 include/ui/qemu-spice.h | 10 ++++++++++
 monitor.c               |  5 +++--
 qmp.c                   | 11 +++--------
 3 files changed, 16 insertions(+), 10 deletions(-)
include/ui/qemu-spice.h +0 -0
index a93b4b2..b3f2679 100644

include/ui/qemu-spice.h static inline int qemu_spice_display_add_client(int csock, int skipauth, · line 91

Quoted 4 lines
include/ui/qemu-spice.h +1 -0
@@ -88,4 +88,14 @@ static inline int qemu_spice_display_add_client(int csock, int skipauth,
 
 #endif /* CONFIG_SPICE */
 
+static inline int qemu_using_spice(Error **errp)

Why not s/int/bool/

include/ui/qemu-spice.h static inline int qemu_spice_display_add_client(int csock, int skipauth, · line 98

Quoted 7 lines
include/ui/qemu-spice.h +7 -0
+{
+    if (!using_spice) {
+        /* correct one? spice isn't a device ,,, */
+        error_set(errp, QERR_DEVICE_NOT_ACTIVE, "spice");
+        return 0;
+    }
+    return 1;

and use true/false here? All callers use it only in a boolean context.

Either way,

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#3 lore raw

Re: [Qemu-devel] [PATCH 1/9] qmp hmp: Factor out common "using spice" test

Quoted 32 lines · Eric Blake
Quoted 15 lines · Markus Armbruster

Into qemu_using_spice(). For want of a better place, put it next the existing monitor command handler dummies in qemu-spice.h.

---
 include/ui/qemu-spice.h | 10 ++++++++++
 monitor.c               |  5 +++--
 qmp.c                   | 11 +++--------
 3 files changed, 16 insertions(+), 10 deletions(-)
include/ui/qemu-spice.h +0 -0
index a93b4b2..b3f2679 100644

include/ui/qemu-spice.h static inline int · line 92

Quoted 5 lines
include/ui/qemu-spice.h +1 -0
@@ -88,4 +88,14 @@ static inline int
 qemu_spice_display_add_client(int csock, int skipauth,
 
 #endif /* CONFIG_SPICE */
 
+static inline int qemu_using_spice(Error **errp)

Why not s/int/bool/

include/ui/qemu-spice.h static inline int qemu_spice_display_add_client(int csock, int skipauth, · line 98

Quoted 7 lines
include/ui/qemu-spice.h +7 -0
+{
+    if (!using_spice) {
+        /* correct one? spice isn't a device ,,, */
+        error_set(errp, QERR_DEVICE_NOT_ACTIVE, "spice");
+        return 0;
+    }
+    return 1;
Quoted 1 line

and use true/false here? All callers use it only in a boolean context.

I wrapped around using_spice, which is int, and didn't think of switching to bool. Old habits die hard...

Luiz, would you be willing to fix this up on commit?

Quoted 2 lines

Either way,

Thanks!

#4 lore raw

PATCH 2/9 qmp hmp: Improve error messages when SPICE is not in use

In reply to Markus Armbruster

Commit 7572150 adopted QERR_DEVICE_NOT_ACTIVE for the purpose, probably because adding another error seemed cumbersome overkill. Produces "No spice device has been activated", which is awkward.

We've since abandoned our quest for "rich" error objects. Time to undo the damage to this error message. Replace it by "SPICE is not in use".

Keep the stupid DeviceNotActive ErrorClass for compatibility, even though Libvirt doesn't use it.

---
 include/ui/qemu-spice.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/ui/qemu-spice.h +2 -2
index b3f2679..99bb622 100644
@@ -91,8 +91,8 @@ static inline int qemu_spice_display_add_client(int csock, int skipauth,
 static inline int qemu_using_spice(Error **errp)
 {
     if (!using_spice) {
-        /* correct one? spice isn't a device ,,, */
-        error_set(errp, QERR_DEVICE_NOT_ACTIVE, "spice");
+        error_set(errp, ERROR_CLASS_DEVICE_NOT_ACTIVE,
+                  "SPICE is not in use");
         return 0;
     }
     return 1;
Signature · 1 line
1.9.3
Reviewed-by on v1 2/9
#5 lore raw

Re: [Qemu-devel] [PATCH 2/9] qmp hmp: Improve error messages when SPICE is not in use

Quoted 10 lines · Markus Armbruster

Commit 7572150 adopted QERR_DEVICE_NOT_ACTIVE for the purpose, probably because adding another error seemed cumbersome overkill. Produces "No spice device has been activated", which is awkward.

We've since abandoned our quest for "rich" error objects. Time to undo the damage to this error message. Replace it by "SPICE is not in use".

Keep the stupid DeviceNotActive ErrorClass for compatibility, even though Libvirt doesn't use it.

Libvirt has a few places that look explicitly for "DeviceNotActive" when deciding how to handle failure reporting; I didn't audit closely enough to see if it actually changes behavior if the class were to disappear. Your approach in this patch is safest, at any rate.

Quoted 5 lines
---
 include/ui/qemu-spice.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#6 lore raw

Re: [Qemu-devel] [PATCH 2/9] qmp hmp: Improve error messages when SPICE is not in use

Quoted 9 lines · Eric Blake
Quoted 8 lines · Markus Armbruster

Commit 7572150 adopted QERR_DEVICE_NOT_ACTIVE for the purpose, probably because adding another error seemed cumbersome overkill. Produces "No spice device has been activated", which is awkward.

We've since abandoned our quest for "rich" error objects. Time to undo the damage to this error message. Replace it by "SPICE is not in use".

Quoted 6 lines
Quoted 2 lines

Keep the stupid DeviceNotActive ErrorClass for compatibility, even though Libvirt doesn't use it.

Libvirt has a few places that look explicitly for "DeviceNotActive" when deciding how to handle failure reporting; I didn't audit closely enough to see if it actually changes behavior if the class were to disappear.

I studied libvirt's use of error classes other than GenericError before my Christmas break. My findings:

* CommandNotFound: used; libvirt could perhaps rely on query-commands instead

* DeviceEncrypted: not used (surprise, surprise)

* DeviceNotActive: used with balloon and block jobs, not used with spice

* DeviceNotFound: used to detect active commit support, with device-list-properties and with qom-list (which isn't about devices at all)

* KVMMissingCap: used; occurs only with balloon, and it shandled just like DeviceNotActive

Quoted 1 line

Your approach in this patch is safest, at any rate.

I'm resigned to keeping these error classes around. I'm still fighting their proliferation to new code.

Quoted 6 lines
Quoted 4 lines
---
 include/ui/qemu-spice.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Thanks!

#7 lore raw

PATCH 3/9 hmp: Compile hmp_info_spice() only with CONFIG_SPICE

In reply to Markus Armbruster

It's dead code when CONFIG_SPICE is off. If it wasn't, it would crash dereferencing the null pointer returned by the qmp_query_spice() dummy in qmp.c.

---
 hmp.c | 2 ++
 1 file changed, 2 insertions(+)
hmp.c +2 -0
index 481be80..a42c5c0 100644
@@ -535,6 +535,7 @@ out:
     qapi_free_VncInfo(info);
 }
 
+#ifdef CONFIG_SPICE
 void hmp_info_spice(Monitor *mon, const QDict *qdict)
 {
     SpiceChannelList *chan;
@@ -581,6 +582,7 @@ void hmp_info_spice(Monitor *mon, const QDict *qdict)
 out:
     qapi_free_SpiceInfo(info);
 }
+#endif
 
 void hmp_info_balloon(Monitor *mon, const QDict *qdict)
 {
Signature · 1 line
1.9.3
#8 lore raw

PATCH 4/9 qmp: Clean up qmp_query_spice() #ifndef !CONFIG_SPICE dummy

In reply to Markus Armbruster

QMP command query-spice exists only #ifdef CONFIG_SPICE. Due to QAPI limitations, we need a dummy function anyway, but it's unreachable.

Our current dummy function goes out of its way to produce the exact same error as the QMP core does for unknown commands. Cute, but both unclean and unnecessary. Replace by straight abort().

---
 qmp.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
qmp.c +10 -6
index f01ae7d..54624ef 100644
@@ -137,14 +137,18 @@ VncInfo *qmp_query_vnc(Error **errp)
 #endif
 
 #ifndef CONFIG_SPICE
-/* If SPICE support is enabled, the "true" query-spice command is
-   defined in the SPICE subsystem. Also note that we use a small
-   trick to maintain query-spice's original behavior, which is not
-   to be available in the namespace if SPICE is not compiled in */
+/*
+ * qmp-commands.hx ensures that QMP command query-spice exists only
+ * #ifdef CONFIG_SPICE.  Necessary for an accurate query-commands
+ * result.  However, the QAPI schema is blissfully unaware of that,
+ * and the QAPI code generator happily generates a dead
+ * qmp_marshal_input_query_spice() that calls qmp_query_spice().
+ * Provide it one, or else linking fails.
+ * FIXME Educate the QAPI schema on CONFIG_SPICE.
+ */
 SpiceInfo *qmp_query_spice(Error **errp)
 {
-    error_set(errp, QERR_COMMAND_NOT_FOUND, "query-spice");
-    return NULL;
+    abort();
 };
 #endif
 
Signature · 1 line
1.9.3
Reviewed-by on v1 4/9
#9 lore raw

Re: [Qemu-devel] [PATCH 4/9] qmp: Clean up qmp_query_spice() #ifndef !CONFIG_SPICE dummy

Quoted 10 lines · Markus Armbruster

QMP command query-spice exists only #ifdef CONFIG_SPICE. Due to QAPI limitations, we need a dummy function anyway, but it's unreachable.

Our current dummy function goes out of its way to produce the exact same error as the QMP core does for unknown commands. Cute, but both unclean and unnecessary. Replace by straight abort().

---

Quoted 7 lines

+ * qmp-commands.hx ensures that QMP command query-spice exists only
+ * #ifdef CONFIG_SPICE. Necessary for an accurate query-commands
+ * result. However, the QAPI schema is blissfully unaware of that,
+ * and the QAPI code generator happily generates a dead
+ * qmp_marshal_input_query_spice() that calls qmp_query_spice().
+ * Provide it one, or else linking fails.
+ * FIXME Educate the QAPI schema on CONFIG_SPICE.

There's probably several commands that are only conditionally compiled in qmp-commands.hx, but where the qapi has no way to express that they are conditional on how the binary was compiled. I'm not sure if it would help the user to document that a command listed in the .json might not actually exist, but if enhancing the qapi code generator to understand conditionals made for less maintenance, then that alone would be worth cleaning up this FIXME.

In the meantime, your patch is just fine.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#10 lore raw

PATCH 5/9 qmp: Simplify recognition of capability negotiation command

In reply to Markus Armbruster
---
 monitor.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
monitor.c +3 -8
index cd81289..f8497b6 100644
@@ -4783,9 +4783,9 @@ static int monitor_can_read(void *opaque)
     return (mon->suspend_cnt == 0) ? 1 : 0;
 }
 
-static int invalid_qmp_mode(const Monitor *mon, const char *cmd_name)
+static int invalid_qmp_mode(const Monitor *mon, const mon_cmd_t *cmd)
 {
-    int is_cap = compare_cmd(cmd_name, "qmp_capabilities");
+    int is_cap = cmd->mhandler.cmd_new == do_qmp_capabilities;
     return (qmp_cmd_mode(mon) ? is_cap : !is_cap);
 }
 
@@ -5079,13 +5079,8 @@ static void handle_qmp_command(JSONMessageParser *parser, QList *tokens)
 
     cmd_name = qdict_get_str(input, "execute");
     trace_handle_qmp_command(mon, cmd_name);
-    if (invalid_qmp_mode(mon, cmd_name)) {
-        qerror_report(QERR_COMMAND_NOT_FOUND, cmd_name);
-        goto err_out;
-    }
-
     cmd = qmp_find_cmd(cmd_name);
-    if (!cmd) {
+    if (!cmd || invalid_qmp_mode(mon, cmd)) {
         qerror_report(QERR_COMMAND_NOT_FOUND, cmd_name);
         goto err_out;
     }
Signature · 1 line
1.9.3
#11 lore raw

PATCH 6/9 qmp: Eliminate silly QERR_COMMAND_NOT_FOUND macro

In reply to Markus Armbruster

The QERR_ macros are leftovers from the days of "rich" error objects. They're used with error_set() and qerror_report(), and expand into the first *two* arguments. This trickiness has become pointless. Clean this one up.

---
 include/qapi/qmp/qerror.h | 3 ---
 monitor.c                 | 3 ++-
 qapi/qmp-dispatch.c       | 3 ++-
 3 files changed, 4 insertions(+), 5 deletions(-)
include/qapi/qmp/qerror.h +0 -3
index 0ca6cbd..28f980e 100644
@@ -52,9 +52,6 @@ void qerror_report_err(Error *err);
 #define QERR_BUS_NOT_FOUND \
     ERROR_CLASS_GENERIC_ERROR, "Bus '%s' not found"
 
-#define QERR_COMMAND_NOT_FOUND \
-    ERROR_CLASS_COMMAND_NOT_FOUND, "The command %s has not been found"
-
 #define QERR_DEVICE_ENCRYPTED \
     ERROR_CLASS_DEVICE_ENCRYPTED, "'%s' (%s) is encrypted"
 
monitor.c +2 -1
index f8497b6..0293769 100644
@@ -5081,7 +5081,8 @@ static void handle_qmp_command(JSONMessageParser *parser, QList *tokens)
     trace_handle_qmp_command(mon, cmd_name);
     cmd = qmp_find_cmd(cmd_name);
     if (!cmd || invalid_qmp_mode(mon, cmd)) {
-        qerror_report(QERR_COMMAND_NOT_FOUND, cmd_name);
+        qerror_report(ERROR_CLASS_COMMAND_NOT_FOUND,
+                      "The command %s has not been found", cmd_name);
         goto err_out;
     }
 
qapi/qmp-dispatch.c +2 -1
index 168b083..2227420 100644
@@ -76,7 +76,8 @@ static QObject *do_qmp_dispatch(QObject *request, Error **errp)
     command = qdict_get_str(dict, "execute");
     cmd = qmp_find_command(command);
     if (cmd == NULL) {
-        error_set(errp, QERR_COMMAND_NOT_FOUND, command);
+        error_set(errp, ERROR_CLASS_COMMAND_NOT_FOUND,
+                  "The command %s has not been found", command);
         return NULL;
     }
     if (!cmd->enabled) {
Signature · 1 line
1.9.3
#12 lore raw

PATCH 7/9 balloon: Inline qemu_balloon(), qemu_balloon_status()

In reply to Markus Armbruster

... and simplify a bit. Permits factoring out common error checks in the next commit.

---
 balloon.c | 42 +++++++++++++-----------------------------
 1 file changed, 13 insertions(+), 29 deletions(-)
balloon.c +13 -29
index b70da4f..2884c2d 100644
@@ -62,25 +62,6 @@ void qemu_remove_balloon_handler(void *opaque)
     balloon_opaque = NULL;
 }
 
-static int qemu_balloon(ram_addr_t target)
-{
-    if (!balloon_event_fn) {
-        return 0;
-    }
-    trace_balloon_event(balloon_opaque, target);
-    balloon_event_fn(balloon_opaque, target);
-    return 1;
-}
-
-static int qemu_balloon_status(BalloonInfo *info)
-{
-    if (!balloon_stat_fn) {
-        return 0;
-    }
-    balloon_stat_fn(balloon_opaque, info);
-    return 1;
-}
-
 BalloonInfo *qmp_query_balloon(Error **errp)
 {
     BalloonInfo *info;
@@ -90,30 +71,33 @@ BalloonInfo *qmp_query_balloon(Error **errp)
         return NULL;
     }
 
+    if (!balloon_stat_fn) {
+        error_set(errp, QERR_DEVICE_NOT_ACTIVE, "balloon");
+        return NULL;
+    }
+
     info = g_malloc0(sizeof(*info));
-
-    if (qemu_balloon_status(info) == 0) {
-        error_set(errp, QERR_DEVICE_NOT_ACTIVE, "balloon");
-        qapi_free_BalloonInfo(info);
-        return NULL;
-    }
-
+    balloon_stat_fn(balloon_opaque, info);
     return info;
 }
 
-void qmp_balloon(int64_t value, Error **errp)
+void qmp_balloon(int64_t target, Error **errp)
 {
     if (kvm_enabled() && !kvm_has_sync_mmu()) {
         error_set(errp, QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon");
         return;
     }
 
-    if (value <= 0) {
+    if (target <= 0) {
         error_set(errp, QERR_INVALID_PARAMETER_VALUE, "target", "a size");
         return;
     }
     
-    if (qemu_balloon(value) == 0) {
+    if (!balloon_event_fn) {
         error_set(errp, QERR_DEVICE_NOT_ACTIVE, "balloon");
+        return;
     }
+
+    trace_balloon_event(balloon_opaque, target);
+    balloon_event_fn(balloon_opaque, target);
 }
Signature · 1 line
1.9.3
#13 lore raw

PATCH 8/9 balloon: Factor out common "is balloon active" test

In reply to Markus Armbruster
---
 balloon.c | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)
balloon.c +15 -14
index 2884c2d..aa30617 100644
@@ -36,6 +36,19 @@ static QEMUBalloonEvent *balloon_event_fn;
 static QEMUBalloonStatus *balloon_stat_fn;
 static void *balloon_opaque;
 
+static int have_ballon(Error **errp)
+{
+    if (kvm_enabled() && !kvm_has_sync_mmu()) {
+        error_set(errp, QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon");
+        return 0;
+    }
+    if (!balloon_event_fn) {
+        error_set(errp, QERR_DEVICE_NOT_ACTIVE, "balloon");
+        return 0;
+    }
+    return 1;
+}
+
 int qemu_add_balloon_handler(QEMUBalloonEvent *event_func,
                              QEMUBalloonStatus *stat_func, void *opaque)
 {
@@ -66,13 +79,7 @@ BalloonInfo *qmp_query_balloon(Error **errp)
 {
     BalloonInfo *info;
 
-    if (kvm_enabled() && !kvm_has_sync_mmu()) {
-        error_set(errp, QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon");
-        return NULL;
-    }
-
-    if (!balloon_stat_fn) {
-        error_set(errp, QERR_DEVICE_NOT_ACTIVE, "balloon");
+    if (!have_ballon(errp)) {
         return NULL;
     }
 
@@ -83,8 +90,7 @@ BalloonInfo *qmp_query_balloon(Error **errp)
 
 void qmp_balloon(int64_t target, Error **errp)
 {
-    if (kvm_enabled() && !kvm_has_sync_mmu()) {
-        error_set(errp, QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon");
+    if (!have_ballon(errp)) {
         return;
     }
 
@@ -92,11 +98,6 @@ void qmp_balloon(int64_t target, Error **errp)
         error_set(errp, QERR_INVALID_PARAMETER_VALUE, "target", "a size");
         return;
     }
-    
-    if (!balloon_event_fn) {
-        error_set(errp, QERR_DEVICE_NOT_ACTIVE, "balloon");
-        return;
-    }
 
     trace_balloon_event(balloon_opaque, target);
     balloon_event_fn(balloon_opaque, target);
Signature · 1 line
1.9.3
Reviewed-by on v1 8/9
#14 lore raw

Re: [Qemu-devel] [PATCH 8/9] balloon: Factor out common "is balloon active" test

Quoted 14 lines · Markus Armbruster
---
 balloon.c | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)
balloon.c +1 -0
index 2884c2d..aa30617 100644
@@ -36,6 +36,19 @@ static QEMUBalloonEvent *balloon_event_fn;
 static QEMUBalloonStatus *balloon_stat_fn;
 static void *balloon_opaque;
 
+static int have_ballon(Error **errp)

balloon.c static QEMUBalloonEvent *balloon_event_fn; · line 49

Quoted 10 lines
balloon.c +10 -0
+{
+    if (kvm_enabled() && !kvm_has_sync_mmu()) {
+        error_set(errp, QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon");
+        return 0;
+    }
+    if (!balloon_event_fn) {
+        error_set(errp, QERR_DEVICE_NOT_ACTIVE, "balloon");
+        return 0;
+    }
+    return 1;

Another case where I would have used bool, true, false.

Either way,

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#15 lore raw

Re: [Qemu-devel] [PATCH 8/9] balloon: Factor out common "is balloon active" test

Quoted 14 lines · Eric Blake
Quoted 13 lines · Markus Armbruster
---
 balloon.c | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)
balloon.c +0 -0
index 2884c2d..aa30617 100644
@@ -36,6 +36,19 @@ static QEMUBalloonEvent *balloon_event_fn;
 static QEMUBalloonStatus *balloon_stat_fn;
 static void *balloon_opaque;
 
Quoted 13 lines

balloon.c static QEMUBalloonEvent *balloon_event_fn; · line 49

Quoted 11 lines
balloon.c +11 -0
+static int have_ballon(Error **errp)
+{
+    if (kvm_enabled() && !kvm_has_sync_mmu()) {
+        error_set(errp, QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon");
+        return 0;
+    }
+    if (!balloon_event_fn) {
+        error_set(errp, QERR_DEVICE_NOT_ACTIVE, "balloon");
+        return 0;
+    }
+    return 1;

Another case where I would have used bool, true, false.

Me too now that you mention it %-)

Quoted 2 lines

Either way,

Thanks!

#16 lore raw

Re: [Qemu-devel] [PATCH 8/9] balloon: Factor out common "is balloon active" test

In reply to Markus Armbruster
Quoted 10 lines · * Markus Armbruster ([email protected]) wrote:
---
 balloon.c | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)
balloon.c +0 -0
index 2884c2d..aa30617 100644

balloon.c static QEMUBalloonEvent *balloon_event_fn; · line 39

Quoted 4 lines
balloon.c +1 -0
@@ -36,6 +36,19 @@ static QEMUBalloonEvent *balloon_event_fn;
 static QEMUBalloonStatus *balloon_stat_fn;
 static void *balloon_opaque;
 
+static int have_ballon(Error **errp)
                       ^

An 'o' escaped from your balloon.

Dave

Quoted 56 lines
balloon.c +14 -14
+{
+    if (kvm_enabled() && !kvm_has_sync_mmu()) {
+        error_set(errp, QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon");
+        return 0;
+    }
+    if (!balloon_event_fn) {
+        error_set(errp, QERR_DEVICE_NOT_ACTIVE, "balloon");
+        return 0;
+    }
+    return 1;
+}
+
 int qemu_add_balloon_handler(QEMUBalloonEvent *event_func,
                              QEMUBalloonStatus *stat_func, void *opaque)
 {
@@ -66,13 +79,7 @@ BalloonInfo *qmp_query_balloon(Error **errp)
 {
     BalloonInfo *info;
 
-    if (kvm_enabled() && !kvm_has_sync_mmu()) {
-        error_set(errp, QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon");
-        return NULL;
-    }
-
-    if (!balloon_stat_fn) {
-        error_set(errp, QERR_DEVICE_NOT_ACTIVE, "balloon");
+    if (!have_ballon(errp)) {
         return NULL;
     }
 
@@ -83,8 +90,7 @@ BalloonInfo *qmp_query_balloon(Error **errp)
 
 void qmp_balloon(int64_t target, Error **errp)
 {
-    if (kvm_enabled() && !kvm_has_sync_mmu()) {
-        error_set(errp, QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon");
+    if (!have_ballon(errp)) {
         return;
     }
 
@@ -92,11 +98,6 @@ void qmp_balloon(int64_t target, Error **errp)
         error_set(errp, QERR_INVALID_PARAMETER_VALUE, "target", "a size");
         return;
     }
-    
-    if (!balloon_event_fn) {
-        error_set(errp, QERR_DEVICE_NOT_ACTIVE, "balloon");
-        return;
-    }
 
     trace_balloon_event(balloon_opaque, target);
     balloon_event_fn(balloon_opaque, target);
Signature · 1 line
1.9.3

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#17 lore raw

Re: [Qemu-devel] [PATCH 8/9] balloon: Factor out common "is balloon active" test

Quoted 14 lines · Dr. David Alan Gilbert
Quoted 13 lines · * Markus Armbruster ([email protected]) wrote:
---
 balloon.c | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)
balloon.c +0 -0
index 2884c2d..aa30617 100644
@@ -36,6 +36,19 @@ static QEMUBalloonEvent *balloon_event_fn;
 static QEMUBalloonStatus *balloon_stat_fn;
 static void *balloon_opaque;
 
Quoted 5 lines

balloon.c static QEMUBalloonEvent *balloon_event_fn; · line 39

Quoted 1 line
balloon.c +1 -0
+static int have_ballon(Error **errp)
                       ^

An 'o' escaped from your balloon.

Oops - it also escaped from my R-b. I've sent the obvious patch, as penance for my "deflated ego" :)

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#18 lore raw

Re: [Qemu-devel] [PATCH 8/9] balloon: Factor out common "is balloon active" test

Quoted 15 lines · Eric Blake
Quoted 14 lines · Dr. David Alan Gilbert
Quoted 13 lines · * Markus Armbruster ([email protected]) wrote:
---
 balloon.c | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)
balloon.c +0 -0
index 2884c2d..aa30617 100644
@@ -36,6 +36,19 @@ static QEMUBalloonEvent *balloon_event_fn;
 static QEMUBalloonStatus *balloon_stat_fn;
 static void *balloon_opaque;
 
Quoted 8 lines
Quoted 5 lines

balloon.c static QEMUBalloonEvent *balloon_event_fn; · line 39

Quoted 1 line
balloon.c +1 -0
+static int have_ballon(Error **errp)
                       ^

An 'o' escaped from your balloon.

Oops - it also escaped from my R-b. I've sent the obvious patch, as penance for my "deflated ego" :)

Thank you both!

#19 lore raw

PATCH 9/9 balloon: Eliminate silly QERR_ macros

In reply to Markus Armbruster

The QERR_ macros are leftovers from the days of "rich" error objects. They're used with error_set() and qerror_report(), and expand into the first *two* arguments. This trickiness has become pointless. Clean up.

---
 balloon.c                 | 6 ++++--
 include/qapi/qmp/qerror.h | 6 ------
 2 files changed, 4 insertions(+), 8 deletions(-)
balloon.c +4 -2
index aa30617..dcf5b9c 100644
@@ -39,11 +39,13 @@ static void *balloon_opaque;
 static int have_ballon(Error **errp)
 {
     if (kvm_enabled() && !kvm_has_sync_mmu()) {
-        error_set(errp, QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon");
+        error_set(errp, ERROR_CLASS_KVM_MISSING_CAP,
+                  "Using KVM without synchronous MMU, balloon unavailable");
         return 0;
     }
     if (!balloon_event_fn) {
-        error_set(errp, QERR_DEVICE_NOT_ACTIVE, "balloon");
+        error_set(errp, ERROR_CLASS_DEVICE_NOT_ACTIVE,
+                  "No balloon device has been activated");
         return 0;
     }
     return 1;
include/qapi/qmp/qerror.h +0 -6
index 28f980e..eeaf0cb 100644
@@ -70,9 +70,6 @@ void qerror_report_err(Error *err);
 #define QERR_DEVICE_NO_HOTPLUG \
     ERROR_CLASS_GENERIC_ERROR, "Device '%s' does not support hotplugging"
 
-#define QERR_DEVICE_NOT_ACTIVE \
-    ERROR_CLASS_DEVICE_NOT_ACTIVE, "No %s device has been activated"
-
 #define QERR_DEVICE_NOT_ENCRYPTED \
     ERROR_CLASS_GENERIC_ERROR, "Device '%s' is not encrypted"
 
@@ -109,9 +106,6 @@ void qerror_report_err(Error *err);
 #define QERR_JSON_PARSING \
     ERROR_CLASS_GENERIC_ERROR, "Invalid JSON syntax"
 
-#define QERR_KVM_MISSING_CAP \
-    ERROR_CLASS_KVM_MISSING_CAP, "Using KVM without %s, %s unavailable"
-
 #define QERR_MIGRATION_ACTIVE \
     ERROR_CLASS_GENERIC_ERROR, "There's a migration process in progress"
 
Signature · 1 line
1.9.3
Reviewed-by on v1 9/9
#20 lore raw

Re: [Qemu-devel] [PATCH 9/9] balloon: Eliminate silly QERR_ macros

Quoted 4 lines · Markus Armbruster

The QERR_ macros are leftovers from the days of "rich" error objects. They're used with error_set() and qerror_report(), and expand into the first *two* arguments. This trickiness has become pointless. Clean up.

I like your wording in 6/9 better ("Clean this one up"), as it is more obvious that you are only fixing a subset and not eliminating all such macros.

Quoted 7 lines
---
 balloon.c                 | 6 ++++--
 include/qapi/qmp/qerror.h | 6 ------
 2 files changed, 4 insertions(+), 8 deletions(-)

For this patch, and for all others in the series where I did not explicitly reply,

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org