[PATCH 1/5] add timeout seconds to qemuAgentSend()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



    Add @seconds valuable to qemuAgentSend().
    It points timeout seconds on @timeout true.
    If @seconds is 0 on @timeout true, use default timeout value (QEMU_AGENT_WAIT_TIME).
    If @timeout is false, @seconds is meanless.

 qemu_agent.c |   21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
index 15af758..7699042 100644
--- a/src/qemu/qemu_agent.c
+++ b/src/qemu/qemu_agent.c
@@ -837,6 +837,7 @@ void qemuAgentClose(qemuAgentPtr mon)
  * @mon: Monitor
  * @msg: Message
  * @timeout: use timeout?
+ * @seconds: timeout seconds. if 0 on @timeout true, use default value
  *
  * Send @msg to agent @mon.
  * Wait max QEMU_AGENT_WAIT_TIME for agent
@@ -848,7 +849,8 @@ void qemuAgentClose(qemuAgentPtr mon)
  */
 static int qemuAgentSend(qemuAgentPtr mon,
                          qemuAgentMessagePtr msg,
-                         bool timeout)
+                         bool timeout,
+                         int seconds)
 {
     int ret = -1;
     unsigned long long now, then = 0;
@@ -864,7 +866,7 @@ static int qemuAgentSend(qemuAgentPtr mon,
     if (timeout) {
         if (virTimeMillisNow(&now) < 0)
             return -1;
-        then = now + QEMU_AGENT_WAIT_TIME;
+        then = now + (seconds == 0 ? QEMU_AGENT_WAIT_TIME : seconds * 1000);
     }

     mon->msg = msg;
@@ -937,7 +939,7 @@ qemuAgentGuestSync(qemuAgentPtr mon)

     VIR_DEBUG("Sending guest-sync command with ID: %llu", id);

-    send_ret = qemuAgentSend(mon, &sync_msg, true);
+    send_ret = qemuAgentSend(mon, &sync_msg, true, 0);

     VIR_DEBUG("qemuAgentSend returned: %d", send_ret);

@@ -977,7 +979,8 @@ cleanup:
 static int
 qemuAgentCommand(qemuAgentPtr mon,
                  virJSONValuePtr cmd,
-                 virJSONValuePtr *reply)
+                 virJSONValuePtr *reply,
+                 int timeout)
 {
     int ret = -1;
     qemuAgentMessage msg;
@@ -1005,7 +1008,7 @@ qemuAgentCommand(qemuAgentPtr mon,

     VIR_DEBUG("Send command '%s' for write", cmdstr);

-    ret = qemuAgentSend(mon, &msg, false);
+    ret = qemuAgentSend(mon, &msg, (timeout > 0 ? true : false), timeout);

     VIR_DEBUG("Receive command reply ret=%d rxObject=%p",
               ret, msg.rxObject);
@@ -1283,7 +1286,7 @@ int qemuAgentShutdown(qemuAgentPtr mon,
         return -1;

     mon->await_event = QEMU_AGENT_EVENT_SHUTDOWN;
-    ret = qemuAgentCommand(mon, cmd, &reply);
+    ret = qemuAgentCommand(mon, cmd, &reply, 0);

     if (reply && ret == 0)
         ret = qemuAgentCheckError(cmd, reply);
@@ -1315,7 +1318,7 @@ int qemuAgentFSFreeze(qemuAgentPtr mon)
     if (!cmd)
         return -1;

-    if (qemuAgentCommand(mon, cmd, &reply) < 0 ||
+    if (qemuAgentCommand(mon, cmd, &reply, 0) < 0 ||
         qemuAgentCheckError(cmd, reply) < 0)
         goto cleanup;

@@ -1352,7 +1355,7 @@ int qemuAgentFSThaw(qemuAgentPtr mon)
     if (!cmd)
         return -1;

-    if (qemuAgentCommand(mon, cmd, &reply) < 0 ||
+    if (qemuAgentCommand(mon, cmd, &reply, 0) < 0 ||
         qemuAgentCheckError(cmd, reply) < 0)
         goto cleanup;

@@ -1389,7 +1392,7 @@ qemuAgentSuspend(qemuAgentPtr mon,
         return -1;

     mon->await_event = QEMU_AGENT_EVENT_SUSPEND;
-    ret = qemuAgentCommand(mon, cmd, &reply);
+    ret = qemuAgentCommand(mon, cmd, &reply, 0);

     if (reply && ret == 0)
         ret = qemuAgentCheckError(cmd, reply);

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]