Extract the code used to probe for the functionality so that it does not litter the code used for actual work. Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- src/qemu/qemu_monitor.c | 2 +- src/qemu/qemu_monitor_json.c | 58 ++++++++++++++++++++++++++------------------ src/qemu/qemu_monitor_json.h | 3 +++ 3 files changed, 39 insertions(+), 24 deletions(-) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 9bc7aa9ed1..a60e78d967 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -3285,7 +3285,7 @@ qemuMonitorSupportsActiveCommit(qemuMonitorPtr mon) if (!mon || !mon->json) return false; - return qemuMonitorJSONBlockCommit(mon, "bogus", NULL, NULL, NULL, 0) == -2; + return qemuMonitorJSONSupportsActiveCommit(mon); } diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 51b1fddccf..68ef9b3ae4 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -4231,14 +4231,42 @@ qemuMonitorJSONTransaction(qemuMonitorPtr mon, virJSONValuePtr *actions) return ret; } +/* Probe if active commit is supported: pass in a bogus device and NULL top + * and base. The probe return is true if active commit is detected or false + * if not supported or on any error */ +bool +qemuMonitorJSONSupportsActiveCommit(qemuMonitorPtr mon) +{ + bool ret = false; + virJSONValuePtr cmd; + virJSONValuePtr reply = NULL; + + if (!(cmd = qemuMonitorJSONMakeCommand("block-commit", "s:device", + "bogus", NULL))) + return false; + + if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) + goto cleanup; + + if (qemuMonitorJSONHasError(reply, "DeviceNotFound")) { + VIR_DEBUG("block-commit supports active commit"); + ret = true; + goto cleanup; + } + + /* This is a false negative for qemu 2.0; but probably not + * worth the additional complexity to worry about it */ + VIR_DEBUG("block-commit requires 'top' parameter, " + "assuming it lacks active commit"); + cleanup: + virJSONValueFree(cmd); + virJSONValueFree(reply); + return ret; +} + + /* speed is in bytes/sec. Returns 0 on success, -1 with error message - * emitted on failure. - * - * Additionally, can be used to probe if active commit is supported: - * pass in a bogus device and NULL top and base. The probe return is - * -2 if active commit is detected, -3 if inconclusive; with no error - * message issued. - */ + * emitted on failure. */ int qemuMonitorJSONBlockCommit(qemuMonitorPtr mon, const char *device, const char *top, const char *base, @@ -4261,22 +4289,6 @@ qemuMonitorJSONBlockCommit(qemuMonitorPtr mon, const char *device, if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) goto cleanup; - if (!top && !base) { - /* Normally we always specify top and base; but omitting them - * allows for probing whether qemu is new enough to support - * live commit. */ - if (qemuMonitorJSONHasError(reply, "DeviceNotFound")) { - VIR_DEBUG("block-commit supports active commit"); - ret = -2; - } else { - /* This is a false negative for qemu 2.0; but probably not - * worth the additional complexity to worry about it */ - VIR_DEBUG("block-commit requires 'top' parameter, " - "assuming it lacks active commit"); - ret = -3; - } - goto cleanup; - } if (qemuMonitorJSONCheckError(cmd, reply) < 0) goto cleanup; diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index 013bee3364..6930ef34c4 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -267,6 +267,9 @@ int qemuMonitorJSONDrivePivot(qemuMonitorPtr mon, const char *jobname) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); +bool qemuMonitorJSONSupportsActiveCommit(qemuMonitorPtr mon) + ATTRIBUTE_NONNULL(1); + int qemuMonitorJSONBlockCommit(qemuMonitorPtr mon, const char *device, const char *top, -- 2.16.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list