Description of problem: For a shutoff guest which has a scsi disk plug on a special scsi controller. I could detached the useful scsi controller successfully, then I want to re-attach it again, it fails to attach. And also I try to start guest after I detached the controller, at the first time it fails to start, but it will add a new scis controller automatically;then trying to start guest again, it could start successfully. Version-Release number of selected component (if applicable): libvirt-1.3.2-1.fc24_v1.3.1_51_g356e28b.x86_64 How reproducible: 100% Steps to Reproduce: 1. For a shut off guest as following, it has scsi disk sde use scis1 controller. # virsh dumpxml vm1 | grep scsi -A 5 <disk> ... <target dev='sde' bus='scsi'/> <address type='drive' controller='1' bus='0' target='0' unit='0'/> </disk> <controller type='scsi' index='0' model='virtio-scsi'> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </controller> <controller type='scsi' index='1' model='virtio-scsi'> <driver queues='3' cmd_per_lun='10' max_sectors='512' ioeventfd='on'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x0a' function='0x0'/> </controller> 2. Detach scsi controller. check domain xml scsi1 controller was detached. # cat controller/scsi-ctl-driver.xml <controller type='scsi' index='1' model='virtio-scsi'> <driver queues='3' cmd_per_lun='10' max_sectors='512' ioeventfd='on'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x0a' function='0x0'/> </controller> # virsh detach-device vm1 controller/scsi-ctl-driver.xml --config Device detached successfully # virsh dumpxml vm1 | grep scsi -A 5 <target dev='sde' bus='scsi'/> <address type='drive' controller='1' bus='0' target='0' unit='0'/> </disk> <controller type='scsi' index='0' model='virtio-scsi'> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </controller> 3. try to re-attach the scsi controller back, it fails to re-attach. # virsh attach-device vm1 controller/scsi-ctl-driver.xml --config error: Failed to attach device from controller/scsi-ctl-driver.xml error: Requested operation is not valid: Target already exists 4.check domain xml again, only one scsi controller. # virsh dumpxml vm1 |grep scsi -A 5 <target dev='sde' bus='scsi'/> <address type='drive' controller='1' bus='0' target='0' unit='0'/> </disk> <controller type='scsi' index='0' model='virtio-scsi'> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </controller> 5. try to start guest at first time # virsh start vm1 error: Failed to start domain vm1 error: internal error: Could not find scsi controller with index 1 required for device check domain xml. # virsh dumpxml vm1 |grep scsi -A 5 <target dev='sde' bus='scsi'/> <address type='drive' controller='1' bus='0' target='0' unit='0'/> </disk> <controller type='scsi' index='0' model='virtio-scsi'> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </controller> -- <controller type='scsi' index='1'/> <== add a new scsi controller. 6. try to start guest again # virsh start vm1 Domain vm1 started Actual results: As step 3 and step 5, after detach useful scsi controller, it fails to re-attach it again and fails to start guest at the first time. Expected results: Perhaps we should forbid to detach scsi controller when it's used by a disk even guest is shutoff. Additional info: It could be reproduced on rhel7.2.
There's a whole class of issues like this that stem from the fact that we don't call virDomainDefPostParse after changing the domain config... it would 'catch' this error by readding a scsi controller that's needed by the disk. Basically CONFIG hotplug/hotunplug should be made to internally work identically to the associated 'virsh edit' change