From 5003b7c7986c11b6a061ddb62945094194054428 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Mon, 3 Jun 2013 15:58:31 +0200 Subject: [PATCH] qemu: Properly report guest agent errors on command passthrough The code for arbitrary guest agent passthrough was horribly broken since introduction. Fix it to correctly report errors. (cherry picked from commit 6e5b36d5d2fbe3c207651ab653b552dcae6af888) --- src/qemu/qemu_agent.c | 35 +++++++++++++++++++++-------------- src/qemu/qemu_driver.c | 10 +++------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index 8c8c38bab0..ad50479c7d 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -1407,25 +1407,32 @@ qemuAgentArbitraryCommand(qemuAgentPtr mon, int timeout) { int ret = -1; - virJSONValuePtr cmd; + virJSONValuePtr cmd = NULL; virJSONValuePtr reply = NULL; *result = NULL; - if (timeout < VIR_DOMAIN_QEMU_AGENT_COMMAND_MIN) - return ret; - - cmd = virJSONValueFromString(cmd_str); - if (!cmd) - return ret; - - ret = qemuAgentCommand(mon, cmd, &reply, timeout); - - if (ret == 0) { - ret = qemuAgentCheckError(cmd, reply); - if (!(*result = virJSONValueToString(reply, false))) - ret = -1; + if (timeout < VIR_DOMAIN_QEMU_AGENT_COMMAND_MIN) { + virReportError(VIR_ERR_INVALID_ARG, + _("guest agent timeout '%d' is " + "less than the minimum '%d'"), + timeout, VIR_DOMAIN_QEMU_AGENT_COMMAND_MIN); + goto cleanup; } + if (!(cmd = virJSONValueFromString(cmd_str))) + goto cleanup; + + if ((ret = qemuAgentCommand(mon, cmd, &reply, timeout)) < 0) + goto cleanup; + + if ((ret = qemuAgentCheckError(cmd, reply)) < 0) + goto cleanup; + + if (!(*result = virJSONValueToString(reply, false))) + ret = -1; + + +cleanup: virJSONValueFree(cmd); virJSONValueFree(reply); return ret; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index e9408f2b69..270e175073 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -14611,16 +14611,12 @@ qemuDomainQemuAgentCommand(virDomainPtr domain, qemuDomainObjEnterAgent(vm); ret = qemuAgentArbitraryCommand(priv->agent, cmd, &result, timeout); qemuDomainObjExitAgent(vm); - if (ret < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Failed to execute agent command")); - goto endjob; - } + if (ret < 0) + VIR_FREE(result); endjob: - if (qemuDomainObjEndJob(driver, vm) == 0) { + if (qemuDomainObjEndJob(driver, vm) == 0) vm = NULL; - } cleanup: if (vm)