]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Properly report guest agent errors on command passthrough
authorPeter Krempa <pkrempa@redhat.com>
Mon, 3 Jun 2013 13:58:31 +0000 (15:58 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 3 Jun 2013 15:25:27 +0000 (17:25 +0200)
The code for arbitrary guest agent passthrough was horribly broken since
introduction. Fix it to correctly report errors.

src/qemu/qemu_agent.c
src/qemu/qemu_driver.c

index c7a9681502ddcd87357655b06e7638892dd5efbb..00fe13f598b1afbbdebe50660445d2c7f335311b 100644 (file)
@@ -1408,25 +1408,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;
+    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;
+    }
 
-    cmd = virJSONValueFromString(cmd_str);
-    if (!cmd)
-        return ret;
+    if (!(cmd = virJSONValueFromString(cmd_str)))
+        goto cleanup;
+
+    if ((ret = qemuAgentCommand(mon, cmd, &reply, timeout)) < 0)
+        goto cleanup;
 
-    ret = qemuAgentCommand(mon, cmd, &reply, timeout);
+    if ((ret = qemuAgentCheckError(cmd, reply)) < 0)
+        goto cleanup;
 
-    if (ret == 0) {
-        ret = qemuAgentCheckError(cmd, reply);
-        if (!(*result = virJSONValueToString(reply, false)))
-            ret = -1;
-    }
+    if (!(*result = virJSONValueToString(reply, false)))
+        ret = -1;
 
+
+cleanup:
     virJSONValueFree(cmd);
     virJSONValueFree(reply);
     return ret;
index 5ca0fd4a1eb741783c058b2326c46d1536a99d08..9d3f63272616751c1a0506610865f2653bfbf2b7 100644 (file)
@@ -14881,16 +14881,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)