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. --- src/qemu/qemu_driver.c | 35 +++++++++++++++++++++++++++++++---- src/qemu/qemu_process.c | 2 +- src/qemu/qemu_process.h | 2 ++ 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index ce38e36..28e27f2 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -4419,6 +4419,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; @@ -4445,10 +4447,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; diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 7ce8fa5..3105101 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -202,7 +202,7 @@ static qemuAgentCallbacks agentCallbacks = { }; -static int +int qemuConnectAgent(virQEMUDriverPtr driver, virDomainObjPtr vm) { qemuDomainObjPrivatePtr priv = vm->privateData; diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h index c67b0cb..d40f68d 100644 --- a/src/qemu/qemu_process.h +++ b/src/qemu/qemu_process.h @@ -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__ */ -- 2.3.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list