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

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);

[Your series came through unthreaded, which makes it hard to follow - double-check your 'git send-email' settings to ensure that the patches are sent in-reply-to the cover letter. Also, these days it is better to use UTF-8 instead of ISO-2022-JP encoding for email.] On 08/07/2012 06:04 PM, MATSUDA, Daiki wrote:
Add @seconds valuable to qemuAgentSend().
s/valuable/variable/
It points timeout seconds on @timeout true. If @seconds is 0 on @timeout true, use default timeout value (QEMU_AGENT_WAIT_TIME).
Awkward wording, how about: When @timeout is true, @seconds controls how long to wait for a response (if @seconds is 0, default to QEMU_AGENT_WAIT_TIME).
If @timeout is false, @seconds is meanless.
s/meanless/ignored/
@@ -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);
Could be shortened to qemuAgentSend(mon, &msg, !!timeout, timeout) Overall seems pretty reasonable. I'll finish reviewing the series before pushing anything, though. -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
participants (2)
-
Eric Blake
-
MATSUDA, Daiki