]> xenbits.xensource.com Git - libvirt.git/commit
disk: Disallow duplicated target 'dev' values
authorJohn Ferlan <jferlan@redhat.com>
Thu, 26 Feb 2015 17:20:01 +0000 (12:20 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Tue, 3 Mar 2015 03:38:36 +0000 (22:38 -0500)
commite0e290552bbbbd449399c9144b6b5b442b973de7
tree0aca439983cd57038ff110216e1bf2757bf90b6b
parent09aec2a456db8f9464edde61af673648d07d5b80
disk: Disallow duplicated target 'dev' values

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.
15 files changed:
src/conf/domain_conf.c
src/conf/domain_conf.h
src/libvirt_private.syms
src/qemu/qemu_command.c
tests/qemuxml2argvdata/qemuxml2argv-disk-scsi-disk-split.xml
tests/qemuxml2argvdata/qemuxml2argv-disk-scsi-lun-passthrough-sgio.xml
tests/qemuxml2argvdata/qemuxml2argv-disk-scsi-lun-passthrough.xml
tests/qemuxml2argvdata/qemuxml2argv-disk-source-pool-mode.xml
tests/qemuxml2argvdata/qemuxml2argv-disk-source-pool.xml
tests/qemuxml2argvdata/qemuxml2argv-pci-bridge-many-disks.args
tests/qemuxml2argvdata/qemuxml2argv-pci-bridge-many-disks.xml
tests/qemuxml2argvdata/qemuxml2argv-pci-many.args
tests/qemuxml2argvdata/qemuxml2argv-pci-many.xml
tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-source-pool.xml
tests/qemuxml2xmloutdata/qemuxml2xmlout-pci-bridge-many-disks.xml