From e1afab6e28a65e462acff3711ba52690e93e2ae6 Mon Sep 17 00:00:00 2001 From: Mira Limbeck Date: Thu, 16 May 2019 15:08:50 +0200 Subject: [PATCH] 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 '.' 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 --- PVE/QemuServer.pm | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index 9d560ec3..d6e065ef 100644 --- a/PVE/QemuServer.pm +++ b/PVE/QemuServer.pm @@ -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));