From 7dede85815ddc703d8096a6181996deff40a995e Mon Sep 17 00:00:00 2001 From: Fiona Ebner Date: Fri, 6 Dec 2024 17:25:34 +0100 Subject: [PATCH] api: create disks: prohibit format option mismatch for managed volume Since commit "print drive commandline: improve format detection" such mismatches will lead to being unable to start the VM, so catch the issue early. Suggested-by: Dominik Csapak Signed-off-by: Fiona Ebner --- PVE/API2/Qemu.pm | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm index 7d1cd0ef..75c81eb9 100644 --- a/PVE/API2/Qemu.pm +++ b/PVE/API2/Qemu.pm @@ -29,7 +29,7 @@ use PVE::QemuConfig; use PVE::QemuServer; use PVE::QemuServer::Cloudinit; use PVE::QemuServer::CPUConfig; -use PVE::QemuServer::Drive; +use PVE::QemuServer::Drive qw(checked_parse_volname); use PVE::QemuServer::Helpers; use PVE::QemuServer::ImportDisk; use PVE::QemuServer::Monitor qw(mon_cmd); @@ -568,10 +568,17 @@ my sub create_disks : prototype($$$$$$$$$$$) { } else { PVE::Storage::check_volume_access($rpcenv, $authuser, $storecfg, $vmid, $volid); if ($storeid) { - my ($vtype) = PVE::Storage::parse_volname($storecfg, $volid); + my ($vtype, $volume_format) = (checked_parse_volname($storecfg, $volid))[0,6]; + die "cannot use volume $volid - content type needs to be 'images' or 'iso'" if $vtype ne 'images' && $vtype ne 'iso'; + # TODO PVE 9 - consider disallowing setting an explicit format for managed volumes. + if ($disk->{format} && $disk->{format} ne $volume_format) { + die "drive '$ds' - volume '$volid' - 'format=$disk->{format}' option different" + ." from storage format '$volume_format'\n"; + } + if (PVE::QemuServer::Drive::drive_is_cloudinit($disk)) { if ( my $ci_key = PVE::QemuConfig->has_cloudinit($conf, $ds)