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 <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak 2019-11-29 11:06:48 +01:00 committed by Thomas Lamprecht
parent ad1d49f45c
commit 6afb679477

View File

@ -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']);