]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Fix guest-sync response time in qga command
authorray <honglei.wang@smartx.com>
Wed, 21 Feb 2024 14:45:36 +0000 (06:45 -0800)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 22 Feb 2024 08:51:23 +0000 (09:51 +0100)
The current implementation sets the guest-sync timeout to the
smaller value between the default value (QEMU_AGENT_WAIT_TIME)
and agent->timeout, without considering the timeout passed
via the qga command.

This patch enhances the guest-sync timeout logic to use the
minimum value among the default value, agent->timeout, and
the timeout passed via the qga command.

Resolves: https://gitlab.com/libvirt/libvirt/-/issues/590
Signed-off-by: ray <honglei.wang@smartx.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/qemu/qemu_agent.c

index f9bcf38dfb2fdea0ada319a664fc69c924b9ea76..22359f85186138d0d1f3213a2640e87d57d77410 100644 (file)
@@ -835,6 +835,7 @@ qemuAgentGuestSyncSend(qemuAgent *agent,
 /**
  * qemuAgentGuestSync:
  * @agent: agent object
+ * @seconds: qemu agent command timeout value
  *
  * Send guest-sync with unique ID
  * and wait for reply. If we get one, check if
@@ -844,9 +845,10 @@ qemuAgentGuestSyncSend(qemuAgent *agent,
  *          -1 otherwise
  */
 static int
-qemuAgentGuestSync(qemuAgent *agent)
+qemuAgentGuestSync(qemuAgent *agent,
+                   int seconds)
 {
-    int timeout = VIR_DOMAIN_QEMU_AGENT_COMMAND_DEFAULT;
+    int timeout = QEMU_AGENT_WAIT_TIME;
     int rc;
 
     if (agent->inSync)
@@ -854,9 +856,15 @@ qemuAgentGuestSync(qemuAgent *agent)
 
     /* if user specified a custom agent timeout that is lower than the
      * default timeout, use the shorter timeout instead */
-    if ((agent->timeout >= 0) && (agent->timeout < QEMU_AGENT_WAIT_TIME))
+    if ((agent->timeout >= 0) && (agent->timeout < timeout))
         timeout = agent->timeout;
 
+    /* If user specified a timeout parameter smaller than both default
+     * value and agent->timeout in qga APIs(such as qemu-agent-command),
+     * use the parameter timeout value */
+    if ((seconds >= 0) && (seconds < timeout))
+        timeout = seconds;
+
     if ((rc = qemuAgentGuestSyncSend(agent, timeout, true)) < 0)
         return -1;
 
@@ -1022,7 +1030,7 @@ qemuAgentCommandFull(qemuAgent *agent,
         goto cleanup;
     }
 
-    if (qemuAgentGuestSync(agent) < 0)
+    if (qemuAgentGuestSync(agent, seconds) < 0)
         goto cleanup;
 
     if (!(cmdstr = virJSONValueToString(cmd, false)))