Description: When COLD PLUG multiple scsi hostdevs to an ACTIVE vm, their addresses will be duplicated. Versions: libvirt-3.9.0-14.el7_5.1.x86_64 Steps: 1. Having a running vm ## virsh list Id Name State ---------------------------------------------------- 2 avocado-vt-vm1 running 2. prepare 2 scsi hostdev xml ## cat h1.xml <hostdev mode='subsystem' type='scsi' managed='no'> <source> <adapter name='scsi_host12'/> <address bus='0' target='0' unit='0'/> </source> </hostdev> ## cat h2.xml <hostdev mode='subsystem' type='scsi' managed='no'> <source> <adapter name='scsi_host13'/> <address bus='0' target='0' unit='0'/> </source> </hostdev> 3. attach 2 hostdev to vm with 'attach-device --config' ## virsh attach-device avocado-vt-vm1 h1.xml --config Device attached successfully ## virsh attach-device avocado-vt-vm1 h2.xml --config Device attached successfully 4. Check the vm's xml with 'dumpxml --inactive' ## virsh dumpxml avocado-vt-vm1 --inactive ... <hostdev mode='subsystem' type='scsi' managed='no'> <source> <adapter name='scsi_host12'/> <address bus='0' target='0' unit='0'/> </source> <address type='drive' controller='0' bus='0' target='0' unit='0'/> </hostdev> <hostdev mode='subsystem' type='scsi' managed='no'> <source> <adapter name='scsi_host13'/> <address bus='0' target='0' unit='0'/> </source> <address type='drive' controller='0' bus='0' target='0' unit='0'/> </hostdev> ... Actual result: As step 4 shows, 2 hostdev xml have exactly same '<address type='drive' controller='0' bus='0' target='0' unit='0'/>' This will cause vm starting failure next time. ## virsh destroy avocado-vt-vm1; virsh start avocado-vt-vm1 Domain avocado-vt-vm1 destroyed error: Failed to start domain avocado-vt-vm1 error: Unsupport configuration:SCSI host address controller='0' bus='0' target='0' unit='0' in use by another SCSI host device Expected result: Libvirt should assign different addresses for different scsi hostdevs
Patch posted upstream to resolve: https://www.redhat.com/archives/libvir-list/2018-June/msg00465.html
Turns out the patch was somewhat incomplete - it fixed the symptom, not the cause. Updated series at: https://www.redhat.com/archives/libvir-list/2018-June/msg00965.html
A v3 of the above series was generated, with patch 3/3 being the necessary piece: https://www.redhat.com/archives/libvir-list/2018-July/msg01017.html this is now pushed upstream: commit 55ce65646348884656fd7bf3f109ebf8f7603494 Author: John Ferlan <jferlan> Date: Tue Jun 12 08:44:21 2018 -0400 qemu: Use the correct vm def on cold attach ... When attaching a device to the domain we need to be sure to use the correct domain definition (vm->def or vm->newDef) when calling virDomainDeviceDefParse because the post parse processing algorithms that may assign an address for the device will use whatever domain definition was passed in. Additionally, some devices (SCSI hostdev and SCSI disk) use algorithms that rely on knowing what already exists of the other type when generating the new device's address. Using the wrong VM definition could result in duplicated addresses. In the case of the bz, two hostdev's with no domain address provided were added to the running domain's config only. However, the parsing algorithm used the live domain in order to figure out the host device address resulting in the same address being used and a subsequent start failing due to duplicate address. Fix this by separating the checks/code into CONFIG and LIVE processing using the correct definition for each block and performing cleanup for both options as necessary. Signed-off-by: John Ferlan <jferlan> ACKed-by: Michal Privoznik <mprivozn> $ git describe git describe 55ce65646348884656fd7bf3f109ebf8f7603494 v4.5.0-288-g55ce656463 $
Verified at: libvirt-5.0.0-10.virtcov.el8.x86_64 Steps: Scenario 1:Cold attach scsi to guest 1. Having a running vm ## virsh list Id Name State ---------------------- │~ 1 rhel running 2. prepare 2 scsi hostdev xml ## cat h1.xml <hostdev mode='subsystem' type='scsi' managed='no'> <source> <adapter name='scsi_host7'/> <address bus='0' target='0' unit='0'/> </source> </hostdev> ## cat h2.xml <hostdev mode='subsystem' type='scsi' managed='no'> <source> <adapter name='scsi_host8'/> <address bus='0' target='0' unit='0'/> </source> </hostdev> 3. attach 2 hostdev to vm with 'attach-device --config' ## virsh attach-device rhel h1.xml --config Device attached successfully ## virsh attach-device rhel h2.xml --config Device attached successfully 4. Check the vm's xml with 'dumpxml --inactive' ## virsh dumpxml rhel --inactive ... <hostdev mode='subsystem' type='scsi' managed='no'> <source> <adapter name='scsi_host7'/> <address bus='0' target='0' unit='0'/> </source> <address type='drive' controller='0' bus='0' target='0' unit='0'/> </hostdev> <hostdev mode='subsystem' type='scsi' managed='no'> <source> <adapter name='scsi_host8'/> <address bus='0' target='0' unit='0'/> </source> <address type='drive' controller='0' bus='0' target='0' unit='1'/> </hostdev> ... Scenario 2:hot attach scsi to guest 1.Prepare two iscsi disk: # iscsiadm -m session tcp: [1] 10.66.4.119:3260,1 iqn.2016-03.com.virttest:logical-pool.target (non-flash) tcp: [2] 10.66.4.119:3260,1 iqn.2016-03.com.virttest:logical-pool.target 1 (non-flash) 2. attach 2 hostdev to vm with 'attach-device' ## virsh attach-device rhel h1.xml Device attached successfully ## virsh attach-device rhel h2.xml Device attached successfully 3. Check the vm's xml with 'dumpxml' ## virsh dumpxml rhel ... <hostdev mode='subsystem' type='scsi' managed='no'> <source> <adapter name='scsi_host7'/> <address bus='0' target='0' unit='0'/> </source> <alias name='hostdev0'/> <address type='drive' controller='0' bus='0' target='0' unit='0'/> </hostdev> <hostdev mode='subsystem' type='scsi' managed='no'> <source> <adapter name='scsi_host8'/> <address bus='0' target='0' unit='0'/> </source> <alias name='hostdev1'/> <address type='drive' controller='0' bus='0' target='0' unit='1'/> </hostdev> ... Unit numbers are different,work as expected.
Created attachment 1588209 [details] Code coverage 100%
This patch leads to a problem which were fixed in commit 1e0534a7702.
NB: I filed Bug 1783411 for the problem with differing MAC addresses that is cause by the fix for this bug, and sent a patch upstream. Any branch that has this patch should also get that other patch (as soon as it is pushed).
This was verified and shipped long ago. Closing the bug report.