提交 a03e2d3a 编写于 作者: P Peter Krempa

qemu: Connect to guest agent after channel hotplug

If a user hot-attaches the guest agent channel libvirt would ignore it
until the restart of libvirtd or shutdown/destroy and start of the VM
itself.

This patch adds code that opens or closes the guest agent connection
according to the state of the guest agent channel according to
connect/disconnect events.

To allow opening the channel from the event handler qemuConnectAgent
needed to be exported.
上级 e1c04108
......@@ -4468,6 +4468,8 @@ processSerialChangedEvent(virQEMUDriverPtr driver,
virDomainChrDeviceState newstate;
virObjectEventPtr event = NULL;
virDomainDeviceDef dev;
qemuDomainObjPrivatePtr priv = vm->privateData;
int rc;
if (connected)
newstate = VIR_DOMAIN_CHR_DEVICE_STATE_CONNECTED;
......@@ -4494,10 +4496,35 @@ processSerialChangedEvent(virQEMUDriverPtr driver,
dev.data.chr->targetType != VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO)
goto endjob;
if (STREQ_NULLABLE(dev.data.chr->target.name, "org.qemu.guest_agent.0") &&
(event = virDomainEventAgentLifecycleNewFromObj(vm, newstate,
VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_CHANNEL)))
qemuDomainEventQueue(driver, event);
if (STREQ_NULLABLE(dev.data.chr->target.name, "org.qemu.guest_agent.0")) {
switch (newstate) {
case VIR_DOMAIN_CHR_DEVICE_STATE_CONNECTED:
if (!priv->agent) {
if ((rc = qemuConnectAgent(driver, vm)) == -2)
goto endjob;
if (rc < 0)
priv->agentError = true;
}
break;
case VIR_DOMAIN_CHR_DEVICE_STATE_DISCONNECTED:
if (priv->agent) {
qemuAgentClose(priv->agent);
priv->agent = NULL;
priv->agentError = false;
}
break;
case VIR_DOMAIN_CHR_DEVICE_STATE_DEFAULT:
case VIR_DOMAIN_CHR_DEVICE_STATE_LAST:
break;
};
if ((event = virDomainEventAgentLifecycleNewFromObj(vm, newstate,
VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_CHANNEL)))
qemuDomainEventQueue(driver, event);
}
dev.data.chr->state = newstate;
......
......@@ -202,7 +202,7 @@ static qemuAgentCallbacks agentCallbacks = {
};
static int
int
qemuConnectAgent(virQEMUDriverPtr driver, virDomainObjPtr vm)
{
qemuDomainObjPrivatePtr priv = vm->privateData;
......
......@@ -113,4 +113,6 @@ int qemuProcessSPICEAllocatePorts(virQEMUDriverPtr driver,
virDomainDiskDefPtr qemuProcessFindDomainDiskByAlias(virDomainObjPtr vm,
const char *alias);
int qemuConnectAgent(virQEMUDriverPtr driver, virDomainObjPtr vm);
#endif /* __QEMU_PROCESS_H__ */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册