Hi Qi Chen, (CCing virt-tools-list@xxxxxxxxxx in case I say something wrong) On 7/6/22 01:14, 陈奇 wrote:
Dear Developer： How does Virt-Manager persistently attach and detach the virtio disks when a VM is started and shutdown ? Which interface of libvirt does virt-Manager call?
I'm not following whether you asked about attach/detach live (when the VM is running) or offline (with the VM shutdown). For the latter it's trivial: virt-manager will simply edit the domain XML with any extra virtio disks you want. For the live case, in virtManager/addhardware.py: try: if controller is not None: self.vm.attach_device(controller) self.vm.attach_device(dev) attach_device() is defined here, in virtManager/object/domain.py: def attach_device(self, devobj): """ Hotplug device to running guest """ if not self.is_active(): return devxml = devobj.get_xml() log.debug("attach_device with xml=\n%s", devxml) self._backend.attachDevice(devxml) attachDevice() is a libvirt python binding to virDomainAttachDevice, which is defined here: https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainAttachDevice The behavior is hypervisor dependent. For QEMU, this function is implemented in libvirt at src/qemu/qemu_driver.c, qemuDomainAttachDevice(). Note that, for the QEMU driver, since virt-manager does not use the API that passes the CONFIG flag, hotplugged devices will not persist when the VM is shutdown. If you're working with any other hypervisor, grep libvirt code for 'domainAttachDevice' and see the matches with the files that belongs to the hypervisor driver you're using. Hope this answers your question. I also encourage you to subscribe to the virt-manager mailing list in case you have more questions about virt-manager APIs and so on: https://listman.redhat.com/mailman/listinfo/virt-tools-list You'll have more success in getting answers by asking the mailing list than asking individual developers. Thanks, Daniel
Looking forward to your reply，thanks. Qi Chen