From: Peter Krempa Date: Wed, 4 Feb 2026 10:41:50 +0000 (+0100) Subject: qemuMonitorJSONHandleMemoryFailure: Simplify error case and value extraction X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4666d196179d4c294b0f7c66cfbe46d7bc5c21e6;p=thirdparty%2Flibvirt.git qemuMonitorJSONHandleMemoryFailure: Simplify error case and value extraction 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 Reviewed-by: Ján Tomko --- diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 825508e8f5..328e32533d 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -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); }