[pve-devel] [PATCH qemu-server] fix clone_disk with formats other than raw/qcow2

Mira Limbeck m.limbeck at proxmox.com
Thu May 16 15:08:50 CEST 2019


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 at proxmox.com>
---
 PVE/QemuServer.pm | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 9d560ec..d6e065e 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));
-- 
2.11.0





More information about the pve-devel mailing list