mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-10 23:07:44 +00:00
qemu: Emit the guest agent lifecycle event
Add code to emit the event on change of the channel state and reconnect to the qemu process.
This commit is contained in:
parent
4ca2744e8b
commit
b29f2436ac
@ -4342,6 +4342,7 @@ processSerialChangedEvent(virQEMUDriverPtr driver,
|
|||||||
{
|
{
|
||||||
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
|
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
|
||||||
virDomainChrDeviceState newstate;
|
virDomainChrDeviceState newstate;
|
||||||
|
virObjectEventPtr event = NULL;
|
||||||
virDomainDeviceDef dev;
|
virDomainDeviceDef dev;
|
||||||
|
|
||||||
if (connected)
|
if (connected)
|
||||||
@ -4369,6 +4370,11 @@ processSerialChangedEvent(virQEMUDriverPtr driver,
|
|||||||
dev.data.chr->targetType != VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO)
|
dev.data.chr->targetType != VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO)
|
||||||
goto endjob;
|
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);
|
||||||
|
|
||||||
dev.data.chr->state = newstate;
|
dev.data.chr->state = newstate;
|
||||||
|
|
||||||
if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0)
|
if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0)
|
||||||
|
@ -2069,13 +2069,20 @@ qemuProcessFindCharDevicePTYs(virDomainObjPtr vm,
|
|||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
qemuProcessRefreshChannelVirtioState(virDomainObjPtr vm,
|
qemuProcessRefreshChannelVirtioState(virQEMUDriverPtr driver,
|
||||||
virHashTablePtr info)
|
virDomainObjPtr vm,
|
||||||
|
virHashTablePtr info,
|
||||||
|
int booted)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
int agentReason = VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_CHANNEL;
|
||||||
qemuMonitorChardevInfoPtr entry;
|
qemuMonitorChardevInfoPtr entry;
|
||||||
|
virObjectEventPtr event = NULL;
|
||||||
char id[32];
|
char id[32];
|
||||||
|
|
||||||
|
if (booted)
|
||||||
|
agentReason = VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_DOMAIN_STARTED;
|
||||||
|
|
||||||
for (i = 0; i < vm->def->nchannels; i++) {
|
for (i = 0; i < vm->def->nchannels; i++) {
|
||||||
virDomainChrDefPtr chr = vm->def->channels[i];
|
virDomainChrDefPtr chr = vm->def->channels[i];
|
||||||
if (chr->targetType == VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO) {
|
if (chr->targetType == VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO) {
|
||||||
@ -2092,6 +2099,12 @@ qemuProcessRefreshChannelVirtioState(virDomainObjPtr vm,
|
|||||||
!entry->state)
|
!entry->state)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if (entry->state != VIR_DOMAIN_CHR_DEVICE_STATE_DEFAULT &&
|
||||||
|
STREQ_NULLABLE(chr->target.name, "org.qemu.guest_agent.0") &&
|
||||||
|
(event = virDomainEventAgentLifecycleNewFromObj(vm, entry->state,
|
||||||
|
agentReason)))
|
||||||
|
qemuDomainEventQueue(driver, event);
|
||||||
|
|
||||||
chr->state = entry->state;
|
chr->state = entry->state;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2115,7 +2128,7 @@ qemuProcessReconnectRefreshChannelVirtioState(virQEMUDriverPtr driver,
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
ret = qemuProcessRefreshChannelVirtioState(vm, info);
|
ret = qemuProcessRefreshChannelVirtioState(driver, vm, info, false);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virHashFree(info);
|
virHashFree(info);
|
||||||
@ -2171,7 +2184,8 @@ qemuProcessWaitForMonitor(virQEMUDriverPtr driver,
|
|||||||
info)) < 0)
|
info)) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if ((ret = qemuProcessRefreshChannelVirtioState(vm, info)) < 0)
|
if ((ret = qemuProcessRefreshChannelVirtioState(driver, vm, info,
|
||||||
|
true)) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user