提交 f85238ad 编写于 作者: M Martin Kletzander

qemu: make sure agent returns error when required data are missing

Commit 5b3492fa aimed to fix this and caught one error but exposed
another one.  When agent command is being executed and the thread
waiting for the reply is woken up by an event (e.g. EOF in case of
shutdown), the command finishes with no data (rxObject == NULL), but
no error is reported, since this might be desired by the caller
(e.g. suspend through agent).  However, in other situations, when the
data are required (e.g. getting vCPUs), we proceed to getting desired
data out of the reply, but none of the virJSON*() functions works well
with NULLs.  I chose the way of a new parameter for qemuAgentCommand()
function that specifies whether reply is required and behaves
according to that.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1058149Signed-off-by: NMartin Kletzander <mkletzan@redhat.com>
(cherry picked from commit 736e017e)
上级 143eb968
...@@ -1076,6 +1076,7 @@ static int ...@@ -1076,6 +1076,7 @@ static int
qemuAgentCommand(qemuAgentPtr mon, qemuAgentCommand(qemuAgentPtr mon,
virJSONValuePtr cmd, virJSONValuePtr cmd,
virJSONValuePtr *reply, virJSONValuePtr *reply,
bool needReply,
int seconds) int seconds)
{ {
int ret = -1; int ret = -1;
...@@ -1107,7 +1108,7 @@ qemuAgentCommand(qemuAgentPtr mon, ...@@ -1107,7 +1108,7 @@ qemuAgentCommand(qemuAgentPtr mon,
/* If we haven't obtained any reply but we wait for an /* If we haven't obtained any reply but we wait for an
* event, then don't report this as error */ * event, then don't report this as error */
if (!msg.rxObject) { if (!msg.rxObject) {
if (await_event) { if (await_event && !needReply) {
VIR_DEBUG("Woken up by event %d", await_event); VIR_DEBUG("Woken up by event %d", await_event);
} else { } else {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
...@@ -1271,7 +1272,7 @@ int qemuAgentShutdown(qemuAgentPtr mon, ...@@ -1271,7 +1272,7 @@ int qemuAgentShutdown(qemuAgentPtr mon,
mon->await_event = QEMU_AGENT_EVENT_RESET; mon->await_event = QEMU_AGENT_EVENT_RESET;
else else
mon->await_event = QEMU_AGENT_EVENT_SHUTDOWN; mon->await_event = QEMU_AGENT_EVENT_SHUTDOWN;
ret = qemuAgentCommand(mon, cmd, &reply, ret = qemuAgentCommand(mon, cmd, &reply, false,
VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK); VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK);
virJSONValueFree(cmd); virJSONValueFree(cmd);
...@@ -1301,7 +1302,7 @@ int qemuAgentFSFreeze(qemuAgentPtr mon) ...@@ -1301,7 +1302,7 @@ int qemuAgentFSFreeze(qemuAgentPtr mon)
if (!cmd) if (!cmd)
return -1; return -1;
if (qemuAgentCommand(mon, cmd, &reply, if (qemuAgentCommand(mon, cmd, &reply, true,
VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK) < 0) VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK) < 0)
goto cleanup; goto cleanup;
...@@ -1338,7 +1339,7 @@ int qemuAgentFSThaw(qemuAgentPtr mon) ...@@ -1338,7 +1339,7 @@ int qemuAgentFSThaw(qemuAgentPtr mon)
if (!cmd) if (!cmd)
return -1; return -1;
if (qemuAgentCommand(mon, cmd, &reply, if (qemuAgentCommand(mon, cmd, &reply, true,
VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK) < 0) VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK) < 0)
goto cleanup; goto cleanup;
...@@ -1375,7 +1376,7 @@ qemuAgentSuspend(qemuAgentPtr mon, ...@@ -1375,7 +1376,7 @@ qemuAgentSuspend(qemuAgentPtr mon,
return -1; return -1;
mon->await_event = QEMU_AGENT_EVENT_SUSPEND; mon->await_event = QEMU_AGENT_EVENT_SUSPEND;
ret = qemuAgentCommand(mon, cmd, &reply, ret = qemuAgentCommand(mon, cmd, &reply, false,
VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK); VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK);
virJSONValueFree(cmd); virJSONValueFree(cmd);
...@@ -1405,7 +1406,7 @@ qemuAgentArbitraryCommand(qemuAgentPtr mon, ...@@ -1405,7 +1406,7 @@ qemuAgentArbitraryCommand(qemuAgentPtr mon,
if (!(cmd = virJSONValueFromString(cmd_str))) if (!(cmd = virJSONValueFromString(cmd_str)))
goto cleanup; goto cleanup;
if ((ret = qemuAgentCommand(mon, cmd, &reply, timeout)) < 0) if ((ret = qemuAgentCommand(mon, cmd, &reply, true, timeout)) < 0)
goto cleanup; goto cleanup;
if (!(*result = virJSONValueToString(reply, false))) if (!(*result = virJSONValueToString(reply, false)))
...@@ -1432,7 +1433,7 @@ qemuAgentFSTrim(qemuAgentPtr mon, ...@@ -1432,7 +1433,7 @@ qemuAgentFSTrim(qemuAgentPtr mon,
if (!cmd) if (!cmd)
return ret; return ret;
ret = qemuAgentCommand(mon, cmd, &reply, ret = qemuAgentCommand(mon, cmd, &reply, false,
VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK); VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK);
virJSONValueFree(cmd); virJSONValueFree(cmd);
...@@ -1454,7 +1455,7 @@ qemuAgentGetVCPUs(qemuAgentPtr mon, ...@@ -1454,7 +1455,7 @@ qemuAgentGetVCPUs(qemuAgentPtr mon,
if (!(cmd = qemuAgentMakeCommand("guest-get-vcpus", NULL))) if (!(cmd = qemuAgentMakeCommand("guest-get-vcpus", NULL)))
return -1; return -1;
if (qemuAgentCommand(mon, cmd, &reply, if (qemuAgentCommand(mon, cmd, &reply, true,
VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK) < 0) VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK) < 0)
goto cleanup; goto cleanup;
...@@ -1562,7 +1563,7 @@ qemuAgentSetVCPUs(qemuAgentPtr mon, ...@@ -1562,7 +1563,7 @@ qemuAgentSetVCPUs(qemuAgentPtr mon,
cpus = NULL; cpus = NULL;
if (qemuAgentCommand(mon, cmd, &reply, if (qemuAgentCommand(mon, cmd, &reply, true,
VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK) < 0) VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK) < 0)
goto cleanup; goto cleanup;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册