Sync was introduced in [1] to check for ga presence. This
check is racy but in the era before serial events are available
there was not better solution I guess.
In case we have the events the sync function is different. It allows us
to flush stateless ga channel from remnants of previous communications.
But we need to do it only once. Until we get timeout on issued command
channel state is ok.
[1] qemu_agent: Issue guest-sync prior to every command
Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy(a)virtuozzo.com>
---
src/qemu/qemu_agent.c | 13 ++++++++++++-
src/qemu/qemu_agent.h | 3 ++-
src/qemu/qemu_process.c | 3 ++-
tests/qemumonitortestutils.c | 3 ++-
4 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
index cd25ef6cd3..2de53efb7a 100644
--- a/src/qemu/qemu_agent.c
+++ b/src/qemu/qemu_agent.c
@@ -104,6 +104,8 @@ struct _qemuAgent {
int watch;
bool running;
+ bool singleSync;
+ bool inSync;
virDomainObjPtr vm;
@@ -679,7 +681,8 @@ qemuAgentIO(int watch, int fd, int events, void *opaque)
qemuAgentPtr
qemuAgentOpen(virDomainObjPtr vm,
const virDomainChrSourceDef *config,
- qemuAgentCallbacksPtr cb)
+ qemuAgentCallbacksPtr cb,
+ bool singleSync)
{
qemuAgentPtr mon;
@@ -705,6 +708,7 @@ qemuAgentOpen(virDomainObjPtr vm,
}
mon->vm = vm;
mon->cb = cb;
+ mon->singleSync = singleSync;
switch (config->type) {
case VIR_DOMAIN_CHR_TYPE_UNIX:
@@ -869,6 +873,7 @@ static int qemuAgentSend(qemuAgentPtr mon,
_("Unable to wait on agent monitor "
"condition"));
}
+ mon->inSync = false;
goto cleanup;
}
}
@@ -910,6 +915,9 @@ qemuAgentGuestSync(qemuAgentPtr mon)
qemuAgentMessage sync_msg;
int timeout = VIR_DOMAIN_QEMU_AGENT_COMMAND_DEFAULT;
+ if (mon->singleSync && mon->inSync)
+ return 0;
+
/* if user specified a custom agent timeout that is lower than the
* default timeout, use the shorter timeout instead */
if ((mon->timeout >= 0) && (mon->timeout < timeout))
@@ -955,6 +963,9 @@ qemuAgentGuestSync(qemuAgentPtr mon)
}
}
+ if (mon->singleSync)
+ mon->inSync = true;
+
ret = 0;
cleanup:
diff --git a/src/qemu/qemu_agent.h b/src/qemu/qemu_agent.h
index 5656fe60ff..f9f75cee25 100644
--- a/src/qemu/qemu_agent.h
+++ b/src/qemu/qemu_agent.h
@@ -41,7 +41,8 @@ struct _qemuAgentCallbacks {
qemuAgentPtr qemuAgentOpen(virDomainObjPtr vm,
const virDomainChrSourceDef *config,
- qemuAgentCallbacksPtr cb);
+ qemuAgentCallbacksPtr cb,
+ bool singleSync);
void qemuAgentClose(qemuAgentPtr mon);
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 36fbffd7b8..a910afc307 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -237,7 +237,8 @@ qemuConnectAgent(virQEMUDriverPtr driver, virDomainObjPtr vm)
agent = qemuAgentOpen(vm,
config->source,
- &agentCallbacks);
+ &agentCallbacks,
+ virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_VSERPORT_CHANGE));
virObjectLock(vm);
diff --git a/tests/qemumonitortestutils.c b/tests/qemumonitortestutils.c
index 00f5b49439..c3e4d86dd6 100644
--- a/tests/qemumonitortestutils.c
+++ b/tests/qemumonitortestutils.c
@@ -1393,7 +1393,8 @@ qemuMonitorTestNewAgent(virDomainXMLOptionPtr xmlopt)
if (!(test->agent = qemuAgentOpen(test->vm,
&src,
- &qemuMonitorTestAgentCallbacks)))
+ &qemuMonitorTestAgentCallbacks,
+ false)))
goto error;
virObjectLock(test->agent);
--
2.23.0