Pass the generic error message from qemu to the event so that users can
possibly use the information. As documented the error is prefixed with
"other: " to prevent collisions with already documented values in our
API.

Signed-off-by: Peter Krempa <pkre...@redhat.com>
---
 src/qemu/qemu_monitor_json.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 9f417d27c6..6de34b03bb 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -695,7 +695,7 @@ qemuMonitorJSONHandleIOError(qemuMonitor *mon, virJSONValue 
*data)
     const char *device;
     const char *nodename;
     const char *action;
-    const char *reason = "";
+    g_autofree char *reason = NULL;
     bool nospc = false;
     int actionID;

@@ -713,14 +713,27 @@ qemuMonitorJSONHandleIOError(qemuMonitor *mon, 
virJSONValue *data)

     nodename = virJSONValueObjectGetString(data, "node-name");

-    if (virJSONValueObjectGetBoolean(data, "nospace", &nospc) == 0 && nospc)
-        reason = "enospc";
+    if (virJSONValueObjectGetBoolean(data, "nospace", &nospc) == 0 && nospc) {
+        reason = g_strdup("enospc");
+    } else {
+        /* For any unknown error we prefix the qemu-originating error with 
'other: '
+         * so that applications can use that to filter them from errors we
+         * define in our API */
+        const char *qemureason;
+
+        if ((qemureason = virJSONValueObjectGetString(data, "reason"))) {
+            reason = g_strdup_printf("other: %s", qemureason);
+        }
+    }

     if ((actionID = qemuMonitorIOErrorActionTypeFromString(action)) < 0) {
         VIR_WARN("unknown disk io error action '%s'", action);
         actionID = VIR_DOMAIN_EVENT_IO_ERROR_NONE;
     }

+    if (!reason)
+        reason = g_strdup("");
+
     qemuMonitorEmitIOError(mon, device, nodename, actionID, reason);
 }

-- 
2.48.1

Reply via email to