• J
    disk: Disallow duplicated target 'dev' values · e0e29055
    John Ferlan 提交于
    https://bugzilla.redhat.com/show_bug.cgi?id=1142631
    
    This patch resolves a situation where the same "<target dev='$name'...>"
    can be used for multiple disks in the domain.
    
    While the $name is "mostly" advisory regarding the expected order that
    the disk is added to the domain and not guaranteed to map to the device
    name in the guest OS, it still should be unique enough such that other
    domblk* type operations can be performed.
    
    Without the patch, the domblklist will list the same Target twice:
    
    $ virsh domblklist $dom
    Target     Source
    ------------------------------------------------
    sda        /var/lib/libvirt/images/file.qcow2
    sda        /var/lib/libvirt/images/file.img
    
    Additionally, getting domblkstat, domblkerror, domblkinfo, and other block*
    type calls will not be able to reference the second target.
    
    Fortunately, hotplug disallows adding a "third" sda value:
    
    $ qemu-img create -f raw /var/lib/libvirt/images/file2.img 10M
    $ virsh attach-disk $dom /var/lib/libvirt/images/file2.img sda
    error: Failed to attach disk
    error: operation failed: target sda already exists
    
    $
    
    BUT, it since 'sdb' doesn't exist one would get the following on the same
    hotplug attempt, but changing to use 'sdb' instead of 'sda'
    
    $ virsh attach-disk $dom /var/lib/libvirt/images/file2.img sdb
    error: Failed to attach disk
    error: internal error: unable to execute QEMU command 'device_add': Duplicate ID 'scsi0-0-1' for device
    
    $
    
    Since we cannot fix this issue at parsing time, the best that can be done so
    as to not "lose" a domain is to make the check prior to starting the guest
    with the results as follows:
    
    $ virsh start $dom
    error: Failed to start domain $dom
    error: XML error: target 'sda' duplicated for disk sources '/var/lib/libvirt/images/file.qcow2' and '/var/lib/libvirt/images/file.img'
    
    $
    
    Running 'make check' found a few more instances in the tests where this
    duplicated target dev value was being used. These also exhibited some
    duplicated 'id=' values (negating the uniqueness argument of aliases) in
    the corresponding .args file and of course the *xmlout version of a few
    input XML files.
    e0e29055
libvirt_private.syms 52.5 KB