[PATCH 2/2] qemu: remove redundant needReply argument of qemuAgentCommand

Nikolay Shirokovskiy nshirokovskiy at virtuozzo.com
Thu Mar 5 14:47:02 UTC 2020


needReply added in [1] looks redundant. Indeed it is set to false only
when mon->await_event is set too (the only exception qemuAgentFSTrim
which is mistaken).

However it fixes the issue when qemuAgentCommand exits on error path and
mon->await_event is not reset. Let's instead reset mon->await_event properly.

Also remove "Woken up by event" debug message as it can be misleading.
We can get it also if monitor is closed due to serial changed event
currently. Anyway both qemuAgentClose and qemuAgentNotifyEvent log
itself.

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

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy at virtuozzo.com>
---
 src/qemu/qemu_agent.c | 47 ++++++++++++++++++++-----------------------
 1 file changed, 22 insertions(+), 25 deletions(-)

diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
index 2de53efb7a..605c9f563e 100644
--- a/src/qemu/qemu_agent.c
+++ b/src/qemu/qemu_agent.c
@@ -1112,7 +1112,6 @@ static int
 qemuAgentCommand(qemuAgentPtr mon,
                  virJSONValuePtr cmd,
                  virJSONValuePtr *reply,
-                 bool needReply,
                  int seconds)
 {
     int ret = -1;
@@ -1121,17 +1120,16 @@ qemuAgentCommand(qemuAgentPtr mon,
     int await_event = mon->await_event;
 
     *reply = NULL;
+    memset(&msg, 0, sizeof(msg));
 
     if (!mon->running) {
         virReportError(VIR_ERR_AGENT_UNRESPONSIVE, "%s",
                        _("Guest agent disappeared while executing command"));
-        return -1;
+        goto cleanup;
     }
 
     if (qemuAgentGuestSync(mon) < 0)
-        return -1;
-
-    memset(&msg, 0, sizeof(msg));
+        goto cleanup;
 
     if (!(cmdstr = virJSONValueToString(cmd, false)))
         goto cleanup;
@@ -1149,9 +1147,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 && !needReply) {
-                VIR_DEBUG("Woken up by event %d", await_event);
-            } else {
+            if (!await_event) {
                 if (mon->running)
                     virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                                    _("Missing monitor reply object"));
@@ -1169,6 +1165,7 @@ qemuAgentCommand(qemuAgentPtr mon,
  cleanup:
     VIR_FREE(cmdstr);
     VIR_FREE(msg.txBuffer);
+    mon->await_event = QEMU_AGENT_EVENT_NONE;
 
     return ret;
 }
@@ -1269,7 +1266,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, false,
+    ret = qemuAgentCommand(mon, cmd, &reply,
                            VIR_DOMAIN_QEMU_AGENT_COMMAND_SHUTDOWN);
 
     virJSONValueFree(cmd);
@@ -1312,7 +1309,7 @@ int qemuAgentFSFreeze(qemuAgentPtr mon, const char **mountpoints,
     if (!cmd)
         goto cleanup;
 
-    if (qemuAgentCommand(mon, cmd, &reply, true, mon->timeout) < 0)
+    if (qemuAgentCommand(mon, cmd, &reply, mon->timeout) < 0)
         goto cleanup;
 
     if (virJSONValueObjectGetNumberInt(reply, "return", &ret) < 0) {
@@ -1349,7 +1346,7 @@ int qemuAgentFSThaw(qemuAgentPtr mon)
     if (!cmd)
         return -1;
 
-    if (qemuAgentCommand(mon, cmd, &reply, true, mon->timeout) < 0)
+    if (qemuAgentCommand(mon, cmd, &reply, mon->timeout) < 0)
         goto cleanup;
 
     if (virJSONValueObjectGetNumberInt(reply, "return", &ret) < 0) {
@@ -1386,7 +1383,7 @@ qemuAgentSuspend(qemuAgentPtr mon,
         return -1;
 
     mon->await_event = QEMU_AGENT_EVENT_SUSPEND;
-    ret = qemuAgentCommand(mon, cmd, &reply, false, mon->timeout);
+    ret = qemuAgentCommand(mon, cmd, &reply, mon->timeout);
 
     virJSONValueFree(cmd);
     virJSONValueFree(reply);
@@ -1415,7 +1412,7 @@ qemuAgentArbitraryCommand(qemuAgentPtr mon,
     if (!(cmd = virJSONValueFromString(cmd_str)))
         goto cleanup;
 
-    if ((ret = qemuAgentCommand(mon, cmd, &reply, true, timeout)) < 0)
+    if ((ret = qemuAgentCommand(mon, cmd, &reply, timeout)) < 0)
         goto cleanup;
 
     if (!(*result = virJSONValueToString(reply, false)))
@@ -1442,7 +1439,7 @@ qemuAgentFSTrim(qemuAgentPtr mon,
     if (!cmd)
         return ret;
 
-    ret = qemuAgentCommand(mon, cmd, &reply, false, mon->timeout);
+    ret = qemuAgentCommand(mon, cmd, &reply, mon->timeout);
 
     virJSONValueFree(cmd);
     virJSONValueFree(reply);
@@ -1463,7 +1460,7 @@ qemuAgentGetVCPUs(qemuAgentPtr mon,
     if (!(cmd = qemuAgentMakeCommand("guest-get-vcpus", NULL)))
         return -1;
 
-    if (qemuAgentCommand(mon, cmd, &reply, true, mon->timeout) < 0)
+    if (qemuAgentCommand(mon, cmd, &reply, mon->timeout) < 0)
         goto cleanup;
 
     if (!(data = virJSONValueObjectGetArray(reply, "return"))) {
@@ -1576,7 +1573,7 @@ qemuAgentSetVCPUsCommand(qemuAgentPtr mon,
                                      NULL)))
         goto cleanup;
 
-    if (qemuAgentCommand(mon, cmd, &reply, true, mon->timeout) < 0)
+    if (qemuAgentCommand(mon, cmd, &reply, mon->timeout) < 0)
         goto cleanup;
 
     /* All negative values are invalid. Return of 0 is bogus since we wouldn't
@@ -1731,7 +1728,7 @@ qemuAgentGetHostname(qemuAgentPtr mon,
     if (!cmd)
         return ret;
 
-    if (qemuAgentCommand(mon, cmd, &reply, true, mon->timeout) < 0) {
+    if (qemuAgentCommand(mon, cmd, &reply, mon->timeout) < 0) {
         if (qemuAgentErrorCommandUnsupported(reply))
             ret = -2;
         goto cleanup;
@@ -1775,7 +1772,7 @@ qemuAgentGetTime(qemuAgentPtr mon,
     if (!cmd)
         return ret;
 
-    if (qemuAgentCommand(mon, cmd, &reply, true, mon->timeout) < 0)
+    if (qemuAgentCommand(mon, cmd, &reply, mon->timeout) < 0)
         goto cleanup;
 
     if (virJSONValueObjectGetNumberUlong(reply, "return", &json_time) < 0) {
@@ -1840,7 +1837,7 @@ qemuAgentSetTime(qemuAgentPtr mon,
     if (!cmd)
         return ret;
 
-    if (qemuAgentCommand(mon, cmd, &reply, true, mon->timeout) < 0)
+    if (qemuAgentCommand(mon, cmd, &reply, mon->timeout) < 0)
         goto cleanup;
 
     ret = 0;
@@ -1977,7 +1974,7 @@ qemuAgentGetFSInfo(qemuAgentPtr mon,
     if (!cmd)
         return ret;
 
-    if (qemuAgentCommand(mon, cmd, &reply, true, mon->timeout) < 0) {
+    if (qemuAgentCommand(mon, cmd, &reply, mon->timeout) < 0) {
         if (qemuAgentErrorCommandUnsupported(reply))
             ret = -2;
         goto cleanup;
@@ -2128,7 +2125,7 @@ qemuAgentGetInterfaces(qemuAgentPtr mon,
     if (!(cmd = qemuAgentMakeCommand("guest-network-get-interfaces", NULL)))
         goto cleanup;
 
-    if (qemuAgentCommand(mon, cmd, &reply, true, mon->timeout) < 0)
+    if (qemuAgentCommand(mon, cmd, &reply, mon->timeout) < 0)
         goto cleanup;
 
     if (!(ret_array = virJSONValueObjectGet(reply, "return"))) {
@@ -2305,7 +2302,7 @@ qemuAgentSetUserPassword(qemuAgentPtr mon,
                                      NULL)))
         goto cleanup;
 
-    if (qemuAgentCommand(mon, cmd, &reply, true, mon->timeout) < 0)
+    if (qemuAgentCommand(mon, cmd, &reply, mon->timeout) < 0)
         goto cleanup;
 
     ret = 0;
@@ -2336,7 +2333,7 @@ qemuAgentGetUsers(qemuAgentPtr mon,
     if (!(cmd = qemuAgentMakeCommand("guest-get-users", NULL)))
         return -1;
 
-    if (qemuAgentCommand(mon, cmd, &reply, true, mon->timeout) < 0) {
+    if (qemuAgentCommand(mon, cmd, &reply, mon->timeout) < 0) {
         if (qemuAgentErrorCommandUnsupported(reply))
             return -2;
         return -1;
@@ -2425,7 +2422,7 @@ qemuAgentGetOSInfo(qemuAgentPtr mon,
     if (!(cmd = qemuAgentMakeCommand("guest-get-osinfo", NULL)))
         return -1;
 
-    if (qemuAgentCommand(mon, cmd, &reply, true, mon->timeout) < 0) {
+    if (qemuAgentCommand(mon, cmd, &reply, mon->timeout) < 0) {
         if (qemuAgentErrorCommandUnsupported(reply))
             return -2;
         return -1;
@@ -2480,7 +2477,7 @@ qemuAgentGetTimezone(qemuAgentPtr mon,
     if (!(cmd = qemuAgentMakeCommand("guest-get-timezone", NULL)))
         return -1;
 
-    if (qemuAgentCommand(mon, cmd, &reply, true, mon->timeout) < 0) {
+    if (qemuAgentCommand(mon, cmd, &reply, mon->timeout) < 0) {
         if (qemuAgentErrorCommandUnsupported(reply))
             return -2;
         return -1;
-- 
2.23.0





More information about the libvir-list mailing list