提交 ca437d06 编写于 作者: P Pavel Mores 提交者: Michal Privoznik

qemu: Refuse partitions in disk targets

The way in which the qemu driver generates aliases for disks involves
ignoring the partition number part of a target dev name.  This means that
all partitions of a block device and the device itself all end up with the
same alias.  If multiple such disks are specified in XML, the resulting
name clash makes qemu invocation fail.

Since attaching partitions to qemu VMs doesn't seem to make much sense
anyway, disallow partitions in target specifications altogether.

https://bugzilla.redhat.com/show_bug.cgi?id=1346265Signed-off-by: NPavel Mores <pmores@redhat.com>
Reviewed-by: NDaniel P. Berrangé <berrange@redhat.com>
Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
Reviewed-by: NMichal Privoznik <mprivozn@redhat.com>
上级 509a1d9d
...@@ -5883,6 +5883,8 @@ qemuDomainDeviceDefValidateDisk(const virDomainDiskDef *disk, ...@@ -5883,6 +5883,8 @@ qemuDomainDeviceDefValidateDisk(const virDomainDiskDef *disk,
{ {
const char *driverName = virDomainDiskGetDriver(disk); const char *driverName = virDomainDiskGetDriver(disk);
virStorageSourcePtr n; virStorageSourcePtr n;
int idx;
int partition;
if (disk->src->shared && !disk->src->readonly && if (disk->src->shared && !disk->src->readonly &&
!qemuBlockStorageSourceSupportsConcurrentAccess(disk->src)) { !qemuBlockStorageSourceSupportsConcurrentAccess(disk->src)) {
...@@ -5951,6 +5953,19 @@ qemuDomainDeviceDefValidateDisk(const virDomainDiskDef *disk, ...@@ -5951,6 +5953,19 @@ qemuDomainDeviceDefValidateDisk(const virDomainDiskDef *disk,
return -1; return -1;
} }
if (virDiskNameParse(disk->dst, &idx, &partition) < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("invalid disk target '%s'"), disk->dst);
return -1;
}
if (partition != 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("invalid disk target '%s', partitions can't appear in disk targets"),
disk->dst);
return -1;
}
for (n = disk->src; virStorageSourceIsBacking(n); n = n->backingStore) { for (n = disk->src; virStorageSourceIsBacking(n); n = n->backingStore) {
if (qemuDomainValidateStorageSource(n, qemuCaps) < 0) if (qemuDomainValidateStorageSource(n, qemuCaps) < 0)
return -1; return -1;
......
<domain type='qemu'>
<name>QEMUGuest1</name>
<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
<memory unit='KiB'>219100</memory>
<currentMemory unit='KiB'>219100</currentMemory>
<vcpu placement='static'>1</vcpu>
<os>
<type arch='i686' machine='pc'>hvm</type>
<boot dev='hd'/>
</os>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/bin/qemu-system-i686</emulator>
<disk type='file' device='disk'>
<driver name='qemu' type='raw'/>
<source file='/export/vmimages/1.raw'/>
<target dev='vdb1' bus='virtio'/>
</disk>
<controller type='usb' index='0'/>
<controller type='ide' index='0'/>
<controller type='pci' index='0' model='pci-root'/>
<memballoon model='virtio'/>
</devices>
</domain>
...@@ -1107,6 +1107,7 @@ mymain(void) ...@@ -1107,6 +1107,7 @@ mymain(void)
DO_TEST("disk-no-boot", NONE); DO_TEST("disk-no-boot", NONE);
DO_TEST_PARSE_ERROR("disk-device-lun-type-invalid", DO_TEST_PARSE_ERROR("disk-device-lun-type-invalid",
QEMU_CAPS_VIRTIO_SCSI); QEMU_CAPS_VIRTIO_SCSI);
DO_TEST_CAPS_LATEST_PARSE_ERROR("disk-attaching-partition-nosupport");
DO_TEST_FAILURE("disk-usb-nosupport", NONE); DO_TEST_FAILURE("disk-usb-nosupport", NONE);
DO_TEST("disk-usb-device", DO_TEST("disk-usb-device",
QEMU_CAPS_DEVICE_USB_STORAGE); QEMU_CAPS_DEVICE_USB_STORAGE);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册