On 11/18/21 07:37, Han Han wrote: > Hi developers, > When the guest OS is booting, the event for live attachment could be > caught by libvirt, while the event for live detachment could not. > Version: > libvirt-7.9 > qemu-kvm-6.1 > > Steps: > Terminal 1: > ➜ ~ virsh event --loop --all > > Terminal 2: > ➜ ~ virsh start avocado-vt-vm1; qemu-img create /tmp/vdb 10M; virsh > attach-disk avocado-vt-vm1 /tmp/vdb vdb; virsh detach-disk > avocado-vt-vm1 vdb > > The outputs from terminal 1: > event 'agent-lifecycle' for domain 'avocado-vt-vm1': state: > 'disconnected' reason: 'domain started' > event 'lifecycle' for domain 'avocado-vt-vm1': Resumed Unpaused > event 'lifecycle' for domain 'avocado-vt-vm1': Started Booted > event 'device-added' for domain 'avocado-vt-vm1': virtio-disk1 > event 'agent-lifecycle' for domain 'avocado-vt-vm1': state: 'connected' > reason: 'channel event' > > As you can see, the device live attachment and the device detachment are > both executed when the guest OS is booting, but there is only the event > 'device-added' is recorded. > So my questions are: > 1. Is it the expected results for the results above? > 2. If so, what is the internal difference between 'device-added' and > 'device-removed'? > 3. I notice there is the DEVICE_DELETED event in qmp? Any relation > between the 'device-removed' of libvirt and the DEVICE_DELETED of qmp? Detaching a device requires the guest cooperation, while in contrast the device attach does not. So I'm guessing that your guest isn't in a state where it can satisfy the detach request. The DEVICE_REMOVED event is emitted whenever DEVICE_DELETED event appears on the monitor (may be delayed for a couple of microseconds, because libvirt needs to update its internal state first). Hope this helps. Michal