Add @seconds variable to qemuAgentSend().
When @tiemout is true, @seconds controls how long to wait for a response
(if @seconds is VIR_DOMAIN_QEMU_AGENT_COMMAND_DEFAULT, default to
QEMU_AGENT_WAIT_TIME).
If @timeout is false, @seconds is ignored.
Signed-off-by: MATSUDA Daiki <matsudadik(a)intellilink.co.jp>
---
include/libvirt/libvirt-qemu.h | 6 ++++++
src/qemu/qemu_agent.c | 30 ++++++++++++++++++++----------
2 files changed, 26 insertions(+), 10 deletions(-)
diff --git a/include/libvirt/libvirt-qemu.h b/include/libvirt/libvirt-qemu.h
index a37f897..013ed5a 100644
--- a/include/libvirt/libvirt-qemu.h
+++ b/include/libvirt/libvirt-qemu.h
@@ -44,6 +44,12 @@ virDomainPtr virDomainQemuAttach(virConnectPtr domain,
unsigned int pid_value,
unsigned int flags);
+typedef enum {
+ VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK = -2,
+ VIR_DOMAIN_QEMU_AGENT_COMMAND_DEFAULT = -1,
+ VIR_DOMAIN_QEMU_AGENT_COMMAND_NOWAIT = 0,
+} virDomainQemuAgentCommandTimeoutValues;
+
# ifdef __cplusplus
}
# endif
diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
index 15af758..26c2726 100644
--- a/src/qemu/qemu_agent.c
+++ b/src/qemu/qemu_agent.c
@@ -837,6 +837,8 @@ void qemuAgentClose(qemuAgentPtr mon)
* @mon: Monitor
* @msg: Message
* @timeout: use timeout?
+ * @seconds: timeout seconds. if VIR_DOMAIN_QEMU_AGENT_COMMAND_DEFAULT and
+ * @timeout is true, use default value.
*
* Send @msg to agent @mon.
* Wait max QEMU_AGENT_WAIT_TIME for agent
@@ -848,7 +850,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 +867,8 @@ static int qemuAgentSend(qemuAgentPtr mon,
if (timeout) {
if (virTimeMillisNow(&now) < 0)
return -1;
- then = now + QEMU_AGENT_WAIT_TIME;
+ then = now + (seconds == VIR_DOMAIN_QEMU_AGENT_COMMAND_DEFAULT ?
+ QEMU_AGENT_WAIT_TIME : seconds * 1000ull);
}
mon->msg = msg;
@@ -937,7 +941,8 @@ 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,
+ VIR_DOMAIN_QEMU_AGENT_COMMAND_DEFAULT);
VIR_DEBUG("qemuAgentSend returned: %d", send_ret);
@@ -977,7 +982,8 @@ cleanup:
static int
qemuAgentCommand(qemuAgentPtr mon,
virJSONValuePtr cmd,
- virJSONValuePtr *reply)
+ virJSONValuePtr *reply,
+ int seconds)
{
int ret = -1;
qemuAgentMessage msg;
@@ -1003,9 +1009,9 @@ qemuAgentCommand(qemuAgentPtr mon,
}
msg.txLength = strlen(msg.txBuffer);
- VIR_DEBUG("Send command '%s' for write", cmdstr);
+ VIR_DEBUG("Send command '%s' for write, seconds = %d", cmdstr,
seconds);
- ret = qemuAgentSend(mon, &msg, false);
+ ret = qemuAgentSend(mon, &msg, seconds < -1 ? false : true, seconds);
VIR_DEBUG("Receive command reply ret=%d rxObject=%p",
ret, msg.rxObject);
@@ -1283,7 +1289,8 @@ int qemuAgentShutdown(qemuAgentPtr mon,
return -1;
mon->await_event = QEMU_AGENT_EVENT_SHUTDOWN;
- ret = qemuAgentCommand(mon, cmd, &reply);
+ ret = qemuAgentCommand(mon, cmd, &reply,
+ VIR_DOMAIN_QEMU_AGENT_COMMAND_DEFAULT);
if (reply && ret == 0)
ret = qemuAgentCheckError(cmd, reply);
@@ -1315,7 +1322,8 @@ int qemuAgentFSFreeze(qemuAgentPtr mon)
if (!cmd)
return -1;
- if (qemuAgentCommand(mon, cmd, &reply) < 0 ||
+ if (qemuAgentCommand(mon, cmd, &reply,
+ VIR_DOMAIN_QEMU_AGENT_COMMAND_DEFAULT) < 0 ||
qemuAgentCheckError(cmd, reply) < 0)
goto cleanup;
@@ -1352,7 +1360,8 @@ int qemuAgentFSThaw(qemuAgentPtr mon)
if (!cmd)
return -1;
- if (qemuAgentCommand(mon, cmd, &reply) < 0 ||
+ if (qemuAgentCommand(mon, cmd, &reply,
+ VIR_DOMAIN_QEMU_AGENT_COMMAND_DEFAULT) < 0 ||
qemuAgentCheckError(cmd, reply) < 0)
goto cleanup;
@@ -1389,7 +1398,8 @@ qemuAgentSuspend(qemuAgentPtr mon,
return -1;
mon->await_event = QEMU_AGENT_EVENT_SUSPEND;
- ret = qemuAgentCommand(mon, cmd, &reply);
+ ret = qemuAgentCommand(mon, cmd, &reply,
+ VIR_DOMAIN_QEMU_AGENT_COMMAND_DEFAULT);
if (reply && ret == 0)
ret = qemuAgentCheckError(cmd, reply);
--
1.7.1