From 6afb67947726771dec44f2753465e6188b06784c Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Fri, 29 Nov 2019 11:06:48 +0100 Subject: [PATCH] implement removal of vmstate via api we did not actually delete the state if we deleted the 'vmstate' config, leaving stray vmstates on the disks actually implement the removal, requiring 'VM.Config.Disk' and 'VM.PowerMgmt' privs Signed-off-by: Dominik Csapak --- PVE/API2/Qemu.pm | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm index 1811795b..a466121c 100644 --- a/PVE/API2/Qemu.pm +++ b/PVE/API2/Qemu.pm @@ -315,6 +315,7 @@ my $check_vm_modify_config_perm = sub { # some checks (e.g., disk, serial port, usb) need to be done somewhere # else, as there the permission can be value dependend next if PVE::QemuServer::is_valid_drivename($opt); + next if $opt eq 'vmstate'; next if $opt eq 'cdrom'; next if $opt =~ m/^(?:unused|serial|usb)\d+$/; @@ -1140,6 +1141,14 @@ my $update_vm_api = sub { delete $conf->{$opt}; PVE::QemuConfig->write_config($vmid, $conf); } + } elsif ($opt eq 'vmstate') { + PVE::QemuConfig->check_protection($conf, "can't remove vmstate '$val'"); + # the user needs Disk and PowerMgmt privileges to remove the vmstate + $rpcenv->check_vm_perm($authuser, $vmid, undef, ['VM.Config.Disk', 'VM.PowerMgmt' ]); + if (PVE::QemuServer::try_deallocate_drive($storecfg, $vmid, $conf, $opt, { file => $val }, $rpcenv, $authuser, 1)) { + delete $conf->{$opt}; + PVE::QemuConfig->write_config($vmid, $conf); + } } elsif (PVE::QemuServer::is_valid_drivename($opt)) { PVE::QemuConfig->check_protection($conf, "can't remove drive '$opt'"); $rpcenv->check_vm_perm($authuser, $vmid, undef, ['VM.Config.Disk']);