summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Kletzander <mkletzan@redhat.com>2014-04-03 07:20:25 +0200
committerMartin Kletzander <mkletzan@redhat.com>2014-04-09 18:29:10 +0200
commitfb285a9dc2365e051acb095261d4a56d4e1f1c72 (patch)
tree0dbbcf84fd858ab149656abcae410b5fc4ae2e02
parentd9af0809b055581f837038dd80e6c69f442dfea1 (diff)
downloadlibvirt-fb285a9dc2365e051acb095261d4a56d4e1f1c72.tar.gz
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=1058149 Signed-off-by: Martin Kletzander <mkletzan@redhat.com> (cherry picked from commit 736e017e3608ce4c97ee519a293ff7faecea040d)
-rw-r--r--src/qemu/qemu_agent.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
index f6009cb8db..e9fcf76910 100644
--- a/src/qemu/qemu_agent.c
+++ b/src/qemu/qemu_agent.c
@@ -1078,6 +1078,7 @@ static int
qemuAgentCommand(qemuAgentPtr mon,
virJSONValuePtr cmd,
virJSONValuePtr *reply,
+ bool needReply,
int seconds)
{
int ret = -1;
@@ -1109,7 +1110,7 @@ qemuAgentCommand(qemuAgentPtr mon,
/* If we haven't obtained any reply but we wait for an
* event, then don't report this as error */
if (!msg.rxObject) {
- if (await_event) {
+ if (await_event && !needReply) {
VIR_DEBUG("Woken up by event %d", await_event);
} else {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -1273,7 +1274,7 @@ int qemuAgentShutdown(qemuAgentPtr mon,
mon->await_event = QEMU_AGENT_EVENT_RESET;
else
mon->await_event = QEMU_AGENT_EVENT_SHUTDOWN;
- ret = qemuAgentCommand(mon, cmd, &reply,
+ ret = qemuAgentCommand(mon, cmd, &reply, false,
VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK);
virJSONValueFree(cmd);
@@ -1303,7 +1304,7 @@ int qemuAgentFSFreeze(qemuAgentPtr mon)
if (!cmd)
return -1;
- if (qemuAgentCommand(mon, cmd, &reply,
+ if (qemuAgentCommand(mon, cmd, &reply, true,
VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK) < 0)
goto cleanup;
@@ -1340,7 +1341,7 @@ int qemuAgentFSThaw(qemuAgentPtr mon)
if (!cmd)
return -1;
- if (qemuAgentCommand(mon, cmd, &reply,
+ if (qemuAgentCommand(mon, cmd, &reply, true,
VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK) < 0)
goto cleanup;
@@ -1377,7 +1378,7 @@ qemuAgentSuspend(qemuAgentPtr mon,
return -1;
mon->await_event = QEMU_AGENT_EVENT_SUSPEND;
- ret = qemuAgentCommand(mon, cmd, &reply,
+ ret = qemuAgentCommand(mon, cmd, &reply, false,
VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK);
virJSONValueFree(cmd);
@@ -1407,7 +1408,7 @@ qemuAgentArbitraryCommand(qemuAgentPtr mon,
if (!(cmd = virJSONValueFromString(cmd_str)))
goto cleanup;
- if ((ret = qemuAgentCommand(mon, cmd, &reply, timeout)) < 0)
+ if ((ret = qemuAgentCommand(mon, cmd, &reply, true, timeout)) < 0)
goto cleanup;
if (!(*result = virJSONValueToString(reply, false)))
@@ -1434,7 +1435,7 @@ qemuAgentFSTrim(qemuAgentPtr mon,
if (!cmd)
return ret;
- ret = qemuAgentCommand(mon, cmd, &reply,
+ ret = qemuAgentCommand(mon, cmd, &reply, false,
VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK);
virJSONValueFree(cmd);
@@ -1456,7 +1457,7 @@ qemuAgentGetVCPUs(qemuAgentPtr mon,
if (!(cmd = qemuAgentMakeCommand("guest-get-vcpus", NULL)))
return -1;
- if (qemuAgentCommand(mon, cmd, &reply,
+ if (qemuAgentCommand(mon, cmd, &reply, true,
VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK) < 0)
goto cleanup;
@@ -1564,7 +1565,7 @@ qemuAgentSetVCPUs(qemuAgentPtr mon,
cpus = NULL;
- if (qemuAgentCommand(mon, cmd, &reply,
+ if (qemuAgentCommand(mon, cmd, &reply, true,
VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK) < 0)
goto cleanup;