]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuMonitorJSONHandleMemoryFailure: Simplify error case and value extraction
authorPeter Krempa <pkrempa@redhat.com>
Wed, 4 Feb 2026 10:41:50 +0000 (11:41 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 12 Feb 2026 15:45:34 +0000 (16:45 +0100)
Report missing 'recipient' and 'action' together with the warning about
unknown value. Use the actual name of the event.

Additional booleans can be extracted without extra variables.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_monitor_json.c

index 825508e8f5a211751474403f150448c46ffa5188..328e32533ded710c4ccc037fba94c2cb363d5038 100644 (file)
@@ -1243,41 +1243,29 @@ qemuMonitorJSONHandleMemoryFailure(qemuMonitor *mon,
     const char *str;
     int recipient;
     int action;
-    bool ar = false;
-    bool recursive = false;
     qemuMonitorEventMemoryFailure mf = {0};
 
-    if (!(str = virJSONValueObjectGetString(data, "recipient"))) {
-        VIR_WARN("missing recipient in memory failure event");
-        return;
-    }
-
-    recipient = qemuMonitorMemoryFailureRecipientTypeFromString(str);
-    if (recipient < 0) {
-        VIR_WARN("unknown recipient '%s' in memory_failure event", str);
-        return;
-    }
-
-    if (!(str = virJSONValueObjectGetString(data, "action"))) {
-        VIR_WARN("missing action in memory failure event");
+    if (!(str = virJSONValueObjectGetString(data, "recipient")) ||
+       (recipient = qemuMonitorMemoryFailureRecipientTypeFromString(str)) < 0) {
+        VIR_WARN("missing or unknown value '%s' of 'recipient' field in 'MEMORY_FAILURE' event",
+                 NULLSTR(str));
         return;
     }
 
-    action = qemuMonitorMemoryFailureActionTypeFromString(str);
-    if (action < 0) {
-        VIR_WARN("unknown action '%s' in memory_failure event", str);
+    if (!(str = virJSONValueObjectGetString(data, "action")) ||
+        (action = qemuMonitorMemoryFailureActionTypeFromString(str)) < 0) {
+        VIR_WARN("missing or unknown value '%s' of 'action' field in 'MEMORY_FAILURE' event",
+                 NULLSTR(str));
         return;
     }
 
     if (flagsjson) {
-        virJSONValueObjectGetBoolean(flagsjson, "action-required", &ar);
-        virJSONValueObjectGetBoolean(flagsjson, "recursive", &recursive);
+        virJSONValueObjectGetBoolean(flagsjson, "action-required", &mf.action_required);
+        virJSONValueObjectGetBoolean(flagsjson, "recursive", &mf.recursive);
     }
 
     mf.recipient = recipient;
     mf.action = action;
-    mf.action_required = ar;
-    mf.recursive = recursive;
     qemuMonitorEmitMemoryFailure(mon, &mf);
 }