1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-01-27 18:03:50 +03:00

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.
This commit is contained in:
Peter Krempa 2015-04-24 16:48:26 +02:00
parent e1c04108d7
commit a03e2d3a99
3 changed files with 34 additions and 5 deletions

View File

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

View File

@ -202,7 +202,7 @@ static qemuAgentCallbacks agentCallbacks = {
};
static int
int
qemuConnectAgent(virQEMUDriverPtr driver, virDomainObjPtr vm)
{
qemuDomainObjPrivatePtr priv = vm->privateData;

View File

@ -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__ */