提交 b47e3b9b 编写于 作者: N Nikolay Shirokovskiy 提交者: Michal Privoznik

qemu: agent: sync once if qemu has serial port event

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: NNikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
Reviewed-by: NMichal Privoznik <mprivozn@redhat.com>
上级 a30078cb
...@@ -108,6 +108,8 @@ struct _qemuAgent { ...@@ -108,6 +108,8 @@ struct _qemuAgent {
GSource *watch; GSource *watch;
bool running; bool running;
bool singleSync;
bool inSync;
virDomainObjPtr vm; virDomainObjPtr vm;
...@@ -673,7 +675,8 @@ qemuAgentPtr ...@@ -673,7 +675,8 @@ qemuAgentPtr
qemuAgentOpen(virDomainObjPtr vm, qemuAgentOpen(virDomainObjPtr vm,
const virDomainChrSourceDef *config, const virDomainChrSourceDef *config,
GMainContext *context, GMainContext *context,
qemuAgentCallbacksPtr cb) qemuAgentCallbacksPtr cb,
bool singleSync)
{ {
qemuAgentPtr agent; qemuAgentPtr agent;
g_autoptr(GError) gerr = NULL; g_autoptr(GError) gerr = NULL;
...@@ -700,6 +703,7 @@ qemuAgentOpen(virDomainObjPtr vm, ...@@ -700,6 +703,7 @@ qemuAgentOpen(virDomainObjPtr vm,
} }
agent->vm = vm; agent->vm = vm;
agent->cb = cb; agent->cb = cb;
agent->singleSync = singleSync;
if (config->type != VIR_DOMAIN_CHR_TYPE_UNIX) { if (config->type != VIR_DOMAIN_CHR_TYPE_UNIX) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
...@@ -853,6 +857,7 @@ static int qemuAgentSend(qemuAgentPtr agent, ...@@ -853,6 +857,7 @@ static int qemuAgentSend(qemuAgentPtr agent,
_("Unable to wait on agent socket " _("Unable to wait on agent socket "
"condition")); "condition"));
} }
agent->inSync = false;
goto cleanup; goto cleanup;
} }
} }
...@@ -894,6 +899,9 @@ qemuAgentGuestSync(qemuAgentPtr agent) ...@@ -894,6 +899,9 @@ qemuAgentGuestSync(qemuAgentPtr agent)
qemuAgentMessage sync_msg; qemuAgentMessage sync_msg;
int timeout = VIR_DOMAIN_QEMU_AGENT_COMMAND_DEFAULT; int timeout = VIR_DOMAIN_QEMU_AGENT_COMMAND_DEFAULT;
if (agent->singleSync && agent->inSync)
return 0;
/* if user specified a custom agent timeout that is lower than the /* if user specified a custom agent timeout that is lower than the
* default timeout, use the shorter timeout instead */ * default timeout, use the shorter timeout instead */
if ((agent->timeout >= 0) && (agent->timeout < timeout)) if ((agent->timeout >= 0) && (agent->timeout < timeout))
...@@ -939,6 +947,9 @@ qemuAgentGuestSync(qemuAgentPtr agent) ...@@ -939,6 +947,9 @@ qemuAgentGuestSync(qemuAgentPtr agent)
} }
} }
if (agent->singleSync)
agent->inSync = true;
ret = 0; ret = 0;
cleanup: cleanup:
......
...@@ -42,7 +42,8 @@ struct _qemuAgentCallbacks { ...@@ -42,7 +42,8 @@ struct _qemuAgentCallbacks {
qemuAgentPtr qemuAgentOpen(virDomainObjPtr vm, qemuAgentPtr qemuAgentOpen(virDomainObjPtr vm,
const virDomainChrSourceDef *config, const virDomainChrSourceDef *config,
GMainContext *context, GMainContext *context,
qemuAgentCallbacksPtr cb); qemuAgentCallbacksPtr cb,
bool singleSync);
void qemuAgentClose(qemuAgentPtr mon); void qemuAgentClose(qemuAgentPtr mon);
......
...@@ -238,7 +238,8 @@ qemuConnectAgent(virQEMUDriverPtr driver, virDomainObjPtr vm) ...@@ -238,7 +238,8 @@ qemuConnectAgent(virQEMUDriverPtr driver, virDomainObjPtr vm)
agent = qemuAgentOpen(vm, agent = qemuAgentOpen(vm,
config->source, config->source,
virEventThreadGetContext(priv->eventThread), virEventThreadGetContext(priv->eventThread),
&agentCallbacks); &agentCallbacks,
virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_VSERPORT_CHANGE));
virObjectLock(vm); virObjectLock(vm);
......
...@@ -1407,7 +1407,8 @@ qemuMonitorTestNewAgent(virDomainXMLOptionPtr xmlopt) ...@@ -1407,7 +1407,8 @@ qemuMonitorTestNewAgent(virDomainXMLOptionPtr xmlopt)
if (!(test->agent = qemuAgentOpen(test->vm, if (!(test->agent = qemuAgentOpen(test->vm,
&src, &src,
virEventThreadGetContext(test->eventThread), virEventThreadGetContext(test->eventThread),
&qemuMonitorTestAgentCallbacks))) &qemuMonitorTestAgentCallbacks,
false)))
goto error; goto error;
virObjectLock(test->agent); virObjectLock(test->agent);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册