[pve-devel] [PATCH qemu-server v3 03/12] fix #5284: api: update-vm: assert content type support for cloudinit images
Daniel Kral
d.kral at proxmox.com
Tue Apr 15 15:50:25 CEST 2025
Asserts whether the target storage supports storing cloudinit images,
i.e. VM images, before creating a cloudinit image on the target storage.
Without the check in place, a cloudinit image can be created on the
storage, which does not support VM images, but won't be able to start
since any attached volume must be stored on a supported storage.
This enforces that allocating a new cloudinit image requires the user to
have the `Datastore.AllocateSpace` permission, which was not required
before. This does not change the behavior for re-generating them.
Signed-off-by: Daniel Kral <d.kral at proxmox.com>
---
changes since v2:
* rebase untop changes of last patch
* ignore cloudinit images for $isCDROM in drive_is_cdrom(...)
* the above change fixes that cloudinit images created with
',media=cdrom' appended are also checked with the new_disk branch
* make check a little more readable
PVE/API2/Qemu.pm | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 693667d5..3bdbcfab 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -153,20 +153,21 @@ my $check_storage_access = sub {
$foreach_volume_with_alloc->($settings, sub {
my ($ds, $drive) = @_;
- my $isCDROM = PVE::QemuServer::drive_is_cdrom($drive);
+ my $isCDROM = PVE::QemuServer::drive_is_cdrom($drive, 1);
my $volid = $drive->{file};
my ($storeid, $volname) = PVE::Storage::parse_volume_id($volid, 1);
+ my $is_cloudinit = defined($volname) && $volname eq 'cloudinit';
my $is_new_disk = $volid =~ $PVE::QemuServer::Drive::NEW_DISK_RE;
# the NEW_DISK_RE captures the correct storeid of the new disk
$storeid = $2 if $is_new_disk;
- if (!$volid || ($volid eq 'none' || (defined($volname) && $volname eq 'cloudinit'))) {
+ if (!$volid || $volid eq 'none') {
# nothing to check
} elsif ($isCDROM && ($volid eq 'cdrom')) {
$rpcenv->check($authuser, "/", ['Sys.Console']);
- } elsif (!$isCDROM && $is_new_disk) {
+ } elsif (!$isCDROM && ($is_new_disk || $is_cloudinit)) {
$rpcenv->check($authuser, "/storage/$storeid", ['Datastore.AllocateSpace']);
my $scfg = PVE::Storage::storage_config($storecfg, $storeid);
raise_param_exc({ storage => "storage '$storeid' does not support vm images"})
--
2.39.5
More information about the pve-devel
mailing list