提交 3b7f11eb 编写于 作者: P Peter Krempa

qemu: monitor: Separate probing for active block commit

Extract the code used to probe for the functionality so that it does not
litter the code used for actual work.
Signed-off-by: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NJohn Ferlan <jferlan@redhat.com>
上级 ee06cd36
......@@ -3302,7 +3302,7 @@ qemuMonitorSupportsActiveCommit(qemuMonitorPtr mon)
if (!mon || !mon->json)
return false;
return qemuMonitorJSONBlockCommit(mon, "bogus", NULL, NULL, NULL, 0) == -2;
return qemuMonitorJSONSupportsActiveCommit(mon);
}
......
......@@ -4366,14 +4366,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,
......@@ -4396,22 +4424,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;
......
......@@ -270,6 +270,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,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册