* @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
*/
static int qemuAgentSend(qemuAgentPtr mon,
qemuAgentMessagePtr msg,
- bool timeout)
+ bool timeout,
+ int seconds)
{
int ret = -1;
unsigned long long now, then = 0;
if (timeout) {
if (virTimeMillisNow(&now) < 0)
return -1;
- then = now + QEMU_AGENT_WAIT_TIME;
+ if (!(seconds >= 0 || seconds == VIR_DOMAIN_QEMU_AGENT_COMMAND_DEFAULT))
+ return -1;
+ then = now + (seconds == VIR_DOMAIN_QEMU_AGENT_COMMAND_DEFAULT ?
+ QEMU_AGENT_WAIT_TIME : seconds * 1000ull);
}
mon->msg = msg;
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);
static int
qemuAgentCommand(qemuAgentPtr mon,
virJSONValuePtr cmd,
- virJSONValuePtr *reply)
+ virJSONValuePtr *reply,
+ int seconds)
{
int ret = -1;
qemuAgentMessage msg;
}
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);
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);
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;
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;
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);