fix clone_disk with formats other than raw/qcow2

with commit 64d1a6a it's now possible to specify a format other than raw
or qcow2 when creating VMs. This can lead to an error when cloning the
VMs and a cloudinit disk with a different format is attached (e.g.
vmdk).

We use QEMU_FORMAT_RE in drive_is_cloudinit and according to the
QEMU_FORMAT_RE we support 7 different formats.

With this change we add any format other than 'raw' as '.<format>' to the
name and no longer die on any other format. Cloudinit disks with invalid
format are not cloned as the drive is recognized as cdrom, not cloudinit.

Signed-off-by: Mira Limbeck <m.limbeck@proxmox.com>
This commit is contained in:
Mira Limbeck 2019-05-16 15:08:50 +02:00 committed by Thomas Lamprecht
parent 5cda6c69e3
commit e1afab6e28

View File

@ -6925,11 +6925,11 @@ sub clone_disk {
if (drive_is_cloudinit($drive)) {
$name = "vm-$newvmid-cloudinit";
$snapname = undef;
# cloudinit only supports raw and qcow2 atm:
if ($dst_format eq 'qcow2') {
$name .= '.qcow2';
} elsif ($dst_format ne 'raw') {
die "clone: unhandled format for cloudinit image\n";
# accept any format when cloning that's supported by QEMU_FORMAT_RE
# if it is not supported by QEMU_FORMAT_RE we do not reach here as
# it is recognized as cdrom, not cloudinit
if ($dst_format ne 'raw') {
$name .= ".$dst_format";
}
}
$newvolid = PVE::Storage::vdisk_alloc($storecfg, $storeid, $newvmid, $dst_format, $name, ($size/1024));