Bug 1386466

Summary: Should fail to validate XML when setting two scsi/ide/sata virtual disks with duplicate address
Product: Red Hat Enterprise Linux 7 Reporter: yafu <yafu>
Component: libvirtAssignee: John Ferlan <jferlan>
Status: CLOSED ERRATA QA Contact: lijuan men <lmen>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 7.3CC: dyuan, rbalakri, xuzhang, yanyang, yisun, zpeng
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: libvirt-3.0.0-1.el7 Doc Type: No Doc Update
Doc Text:
undefined
Story Points: ---
Clone Of: Environment:
Last Closed: 2017-08-01 17:16:43 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description yafu 2016-10-19 03:23:33 UTC
Description of problem:
Should fail to validate XML when setting two scsi/ide/sata virtual disks with duplicate address

How reproducible:
100%

Version-Release number of selected component (if applicable):
libvirt-2.0.0-10.el7.x86_64

Steps to Reproduce:
Scenario 1:
1.Edit the guest xml with two scsi disk's having duplicate address:
#virsh edit rhel7.3
...
   <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/nfs-images/yafu/rhel72.qcow2'/>
      <target dev='sda' bus='scsi'/>
      <address type='drive' controller='0' bus='0' target='0' unit='3'/>
    </disk>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/nfs-images/yafu/rhel7.2.qcow2'/>
      <target dev='sdb' bus='scsi'/>
      <address type='drive' controller='0' bus='0' target='0' unit='3'/>
    </disk>
...

save the change, it can save successfully.

2.Start the guest
#virsh start rhel7.3
error: Failed to start domain rhel7.3
error: internal error: process exited while connecting to monitor: qemu-kvm: -drive file=/nfs-images/yafu/rhel7.2.qcow2,format=qcow2,if=none,id=drive-scsi0-0-0-3: Duplicate ID 'drive-scsi0-0-0-3' for drive

Scenario 2:
1.Edit the guest xml with two scsi disks, one named sda using address scsi 0-0-0-1, one named sdb without address:
 #virsh edit rhel7.3
 ...
  <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/nfs-images/yafu/rhel72.qcow2'/>
      <target dev='sda' bus='scsi'/>
      <address type='drive' controller='0' bus='0' target='0' unit='1'/>
    </disk>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/nfs-images/yafu/rhel7.2.qcow2'/>
      <target dev='sdb' bus='scsi'/>
    </disk>
  ...

save the change, it can save successfully.

2.Check the guest xml, the two scsi disk have duplicate address:
 #virsh dumpxml rhel7.3
 ...
 <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/nfs-images/yafu/rhel72.qcow2'/>
      <target dev='sda' bus='scsi'/>
      <address type='drive' controller='0' bus='0' target='0' unit='1'/>
    </disk>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/nfs-images/yafu/rhel7.2.qcow2'/>
      <target dev='sdb' bus='scsi'/>
      <address type='drive' controller='0' bus='0' target='0' unit='1'/>
    </disk>
  ...

3.Start the guest:
#virsh start rhel7.3
error: Failed to start domain rhel7.3
error: internal error: process exited while connecting to monitor: qemu-kvm: -drive file=/nfs-images/yafu/rhel7.2.qcow2,format=qcow2,if=none,id=drive-scsi0-0-0-1: Duplicate ID 'drive-scsi0-0-0-1' for drive

Actual results:
Edit the guest xml with two scsi virtual disks having duplicate address, the xml can be saved successfully.

Expected results:
Should fail to validate XML when setting two scsi virtual disk with duplicate address.

Additional info:
1.The issue also exists with two ide/sata disks;

Comment 1 Jaroslav Suchanek 2016-12-02 10:49:32 UTC
Is the fix proposal already upstream by Marc Hartmayer?
https://www.redhat.com/archives/libvir-list/2016-November/msg01471.html

Comment 2 John Ferlan 2017-01-05 12:06:43 UTC
This was resolved by an upstream contributor:

$ git show 0f2721d044ff21cbbaf6e71840290eb063657fae
commit 0f2721d044ff21cbbaf6e71840290eb063657fae
Author: Marc Hartmayer <mhartmay.ibm.com>
Date:   Wed Nov 30 12:47:04 2016 +0100

    conf: add global check for duplicate drive addresses
    
    Add a global check for duplicate drive addresses. This will fix the
    problem of duplicate disk and hostdev drive addresses.
    
    Example for duplicate drive addresses:
    <disk>
      ...
      <target name='sda'/>
    </disk>
    <disk>
      ...
      <target name='sdb'/>
      <address type='drive' controller=0 bus=0 target=0 unit=0/>
    </disk>
    
    Another example:
    <hostdev mode='subsystem' type='scsi' managed='no'>
      <source>
      ...
      </source>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </hostdev>
    <hostdev mode='subsystem' type='scsi' managed='no'>
      <source>
      ...
      </source>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </hostdev>
    
    Unfortunately the fixes (1b08cc170a84077afd4d15f4639a9a2cf398e9a2,
    8d46386bfe01b84982e25e915ad9cfbae5cf4cb1) weren't enough to catch these
    cases and it isn't possible to add additional checks in
    virDomainDeviceDefPostParseInternal() for SCSI hostdevs or
    virDomainDiskDefAssignAddress() for SCSI/IDE/FDC/SATA disks without
    adding another parse flag (virDomainDefParseFlags) to disable this
    validation while updating or detaching a disk or hostdev.


$ git describe 0f2721d044ff21cbbaf6e71840290eb063657fae
v2.5.0-7-g0f2721d
$

Comment 4 lijuan men 2017-02-14 08:14:00 UTC
verify the bug 

version:
libvirt-3.0.0-1.el7.x86_64
qemu-kvm-rhev-2.8.0-3.el7.x86_64

steps:
scenario1:
1.edit a guest xml with the following info,and save it:
  <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/beifen.qcow2'/>
      <target dev='sda' bus='scsi'/>
  ***    <address type='drive' controller='0' bus='0' target='0' unit='0'/> ***
    </disk>
<disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/test.qcow2'/>
      <target dev='sdb' bus='scsi'/>
***   <address type='drive' controller='0' bus='0' target='0' unit='0'/>  ***
    </disk>

[root@localhost ~]# virsh edit qq
error: unsupported configuration: Found duplicate drive address for disk with target name 'sda' controller='0' bus='0' target='0' unit='0'
Failed. Try again? [y,n,i,f,?]: 


scenario2:
1.edit a guest xml with the following info,and save it:

 <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/beifen.qcow2'/>
      <target dev='sda' bus='scsi'/>
      <address type='drive' controller='0' bus='0' target='0' unit='1'/>
    </disk>
<disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/test.qcow2'/>
      <target dev='sdb' bus='scsi'/>
    </disk>

[root@localhost ~]# virsh edit qq
error: unsupported configuration: Found duplicate drive address for disk with target name 'sda' controller='0' bus='0' target='0' unit='0'
Failed. Try again? [y,n,i,f,?]: 



scenario3:
1.start a guest with the following xml:
[root@localhost ~]# virsh dumpxml qq | grep disk -A 8
...
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/beifen.qcow2'/>
      <backingStore/>
      <target dev='sda' bus='scsi'/>
      <alias name='scsi0-0-0-0'/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </disk>
...
2.attach a disk with the following xml:
[root@localhost ~]# cat disk.xml 
 <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/test.qcow2'/>
      <target dev='sdb' bus='scsi'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </disk>

[root@localhost ~]# virsh attach-device qq disk.xml 
error: Failed to attach device from disk.xml
error: internal error: unable to execute QEMU command 'device_add': Duplicate ID 'scsi0-0-0-0' for device


scenario4:
start guest with:
 <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/beifen.qcow2'/>
      <target dev='sda' bus='scsi'/>
      <address type='drive' controller='0' bus='0' target='0' unit='1'/>
    </disk>

cat disk.xml
 <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/test.qcow2'/>
      <target dev='sdb' bus='scsi'/>
    </disk>

[root@localhost ~]# virsh attach-device qq disk.xml 
error: Failed to attach device from disk.xml
error: internal error: unable to execute QEMU command 'device_add': Duplicate ID 'scsi0-0-0-1' for device

Comment 5 errata-xmlrpc 2017-08-01 17:16:43 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHEA-2017:1846

Comment 6 errata-xmlrpc 2017-08-01 23:57:38 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHEA-2017:1846