On 2014/11/19 18:23, Peter Krempa wrote: > New qemu added a new event that is emitted when a virtio serial channel > is opened in the guest OS. This allows us to update the state of the > port in the output-only XML element. > > This patch implements the monitor callbacks and necessary handlers to > update the state in the definition. > --- > src/qemu/qemu_domain.h | 1 + > src/qemu/qemu_driver.c | 57 ++++++++++++++++++++++++++++++++++++++++++++ > src/qemu/qemu_monitor.c | 14 +++++++++++ > src/qemu/qemu_monitor.h | 10 ++++++++ > src/qemu/qemu_monitor_json.c | 23 ++++++++++++++++++ > src/qemu/qemu_process.c | 44 ++++++++++++++++++++++++++++++++++ > 6 files changed, 149 insertions(+) > > diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h > index ad45a66..e4ea4ce 100644 > --- a/src/qemu/qemu_domain.h > +++ b/src/qemu/qemu_domain.h > @@ -196,6 +196,7 @@ typedef enum { > QEMU_PROCESS_EVENT_GUESTPANIC, > QEMU_PROCESS_EVENT_DEVICE_DELETED, > QEMU_PROCESS_EVENT_NIC_RX_FILTER_CHANGED, > + QEMU_PROCESS_EVENT_SERIAL_CHANGED, > > QEMU_PROCESS_EVENT_LAST > } qemuProcessEventType; > diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c > index a84fd47..31bf6bb 100644 > --- a/src/qemu/qemu_driver.c > +++ b/src/qemu/qemu_driver.c > @@ -4334,6 +4334,60 @@ processNicRxFilterChangedEvent(virQEMUDriverPtr driver, > } > > > +static void > +processSerialChangedEvent(virQEMUDriverPtr driver, > + virDomainObjPtr vm, > + char *devAlias, > + bool connected) > +{ > + virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); > + virDomainChrDeviceState newstate; > + virDomainDeviceDef dev; > + > + if (connected) > + newstate = VIR_DOMAIN_CHR_DEVICE_STATE_CONNECTED; > + else > + newstate = VIR_DOMAIN_CHR_DEVICE_STATE_DISCONNECTED; > + > + VIR_DEBUG("Changing serial port state %s in domain %p %s", > + devAlias, vm, vm->def->name); > + > + if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) > + goto cleanup; > + > + if (!virDomainObjIsActive(vm)) { > + VIR_DEBUG("Domain is not running"); > + goto endjob; > + } > + > + if (virDomainDefFindDevice(vm->def, devAlias, &dev, true) < 0) > + goto endjob; > + > + /* we care only about certain devices */ > + if (dev.type != VIR_DOMAIN_DEVICE_CHR || > + dev.data.chr->deviceType != VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL || > + dev.data.chr->targetType != VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO) > + goto endjob; > + > + dev.data.chr->state = newstate; > + > + if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0) > + VIR_WARN("unable to save domain status after removing device %s", > + devAlias); > + Hi, Peter IIUC, QEMU emitted the event and libvirt saved the state for the next time being queryed. 'the output-only XML element' and 'SaveStatus' means the state is not saved persistently. In case of libvirtd being restarted after state is saved, we'll lose it. Could we handle this case? -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list