Bug 1559867 - When COLD PLUG multiple scsi hostdevs to an ACTIVE vm, their addresses will be duplicated
Summary: When COLD PLUG multiple scsi hostdevs to an ACTIVE vm, their addresses will b...
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Red Hat Enterprise Linux Advanced Virtualization
Classification: Red Hat
Component: libvirt
Version: 8.0
Hardware: All
OS: Linux
medium
medium
Target Milestone: rc
: 8.0
Assignee: John Ferlan
QA Contact: gaojianan
URL:
Whiteboard:
Depends On:
Blocks: 1344899 1664324
TreeView+ depends on / blocked
 
Reported: 2018-03-23 12:49 UTC by yisun
Modified: 2020-03-11 22:32 UTC (History)
11 users (show)

Fixed In Version: libvirt-5.0.0-1.el8
Doc Type: No Doc Update
Doc Text:
undefined
Clone Of:
Environment:
Last Closed: 2020-03-11 22:32:44 UTC
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)
Code coverage 100% (4.61 KB, text/html)
2019-07-08 02:07 UTC, gaojianan
no flags Details

Description yisun 2018-03-23 12:49:02 UTC
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

Comment 2 John Ferlan 2018-06-06 14:45:40 UTC
Patch posted upstream to resolve:

https://www.redhat.com/archives/libvir-list/2018-June/msg00465.html

Comment 3 John Ferlan 2018-06-12 14:34:43 UTC
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

Comment 4 John Ferlan 2018-07-25 12:46:53 UTC
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
$

Comment 8 gaojianan 2019-07-08 02:06:56 UTC
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.

Comment 9 gaojianan 2019-07-08 02:07:58 UTC
Created attachment 1588209 [details]
Code coverage 100%

Comment 10 wujing42 2019-08-12 12:52:20 UTC
This patch leads to a problem which were fixed in commit 1e0534a7702.

Comment 14 Laine Stump 2019-12-17 17:31:13 UTC
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).

Comment 15 Jeff Nelson 2020-03-11 22:32:44 UTC
This was verified and shipped long ago. Closing the bug report.


Note You need to log in before you can comment on or make changes to this bug.