[pve-devel] [PATCH qemu-server 3/4] implement removal of vmstate via api

Dominik Csapak d.csapak at proxmox.com
Fri Nov 29 11:06:48 CET 2019


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 at proxmox.com>
---
 PVE/API2/Qemu.pm | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 1811795..a466121 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']);
-- 
2.20.1





More information about the pve-devel mailing list