I have noticed a behavior I am hoping someone can help me understand.
Consider the following scenario:
1.) Start a test dummy qemu-kvm instance with no OS via virsh named "no_os".
2.) Attach a device to it;
[root@host ~]# virsh attach-device no_os /root/hotplug_device_b.xml
Device attached successfully
[root@host ~]#
3.) Now detach the same device;
[root@host ~]# virsh detach-device no_os /root/hotplug_device_b.xml
Device detached successfully
[root@host ~]#
4.) Now re-attach the same device;
[root@host ~]# virsh attach-device no_os /root/hotplug_device_b.xml
error: Failed to attach device from /root/hotplug_device_b.xml
error: internal error unable to execute QEMU command 'device_add':
Duplicate ID 'virtio-disk1' for device
[root@host ~]#
Is this expected behavior? If so, why does my detach-device call in step
3 appear to not free the device, leading to the duplicate ID error in
step 4?
Libvirt XML's used:
/root/hotplug_device_b.xml:
<disk type='block' device='disk'>
<driver name='qemu' cache='none'/>
<source dev="/dev/syseng/hotplug_test_b"/>
<target dev="vdb" bus="virtio"/>
</disk>
I started the "no_os" instance with this:
<domain type="kvm">
<name>no_os</name>
<uuid>E605BE96-6BC9-11E2-976C-EDA8DB8AEF42</uuid>
<memory>524288</memory>
<currentMemory>524288</currentMemory>
<vcpu>1</vcpu>
<os>
<type arch="x86_64" machine="pc-1.1">hvm</type>
<boot dev="hd"/>
</os>
<features>
<acpi/>
<apic/>
<pae/>
</features>
<clock offset="utc"/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>
<devices>
<emulator>/opt/kvm-stack-1/libexec/qemu-kvm-wrapper</emulator>
<disk type="block" device="disk">
<driver name="qemu" cache="none"/>
<source dev="/dev/LVM/no_os"/>
<target dev="vda" bus="virtio"/>
</disk>
<disk type="file" device="cdrom">
<target dev="hdc" bus="ide"/>
<readonly/>
</disk>
<serial type="pty">
<target port="0"/>
</serial>
<console type="pty">
<target port="0"/>
</console>
<input type="mouse" bus="ps2"/>
<graphics type="vnc" port="-1" autoport="yes"
keymap="en-us"/>
<interface type="bridge">
<mac address="52:54:00:87:14:3d"/>
<source bridge="virbr0"/>
<target dev="no_os_0"/>
<model type="virtio"/>
</interface></devices>
</domain>