[pve-devel] [PATCH qemu-server 4/4] add special case for clearing suspended state

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


Sometimes, a user wants to remove the 'suspended' state without resuming
the vm from that state. Since the vm is locked with 'suspended',
this was not possible without help from root at pam

This patch allows to delete the vmstate and the suspended lock and
related config entries with it. The user still has to have the right
priviliges and the vm cannot be 'protected' for this to work

also, the lock will only be skipped, if the deletion of the vmstate
is the only thing that is done

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 PVE/API2/Qemu.pm | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index a466121..d3fbbfd 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -1091,7 +1091,20 @@ my $update_vm_api  = sub {
 	die "checksum missmatch (file change by other user?)\n"
 	    if $digest && $digest ne $conf->{digest};
 
-	PVE::QemuConfig->check_lock($conf) if !$skiplock;
+	my $clear_suspend = 0;
+	# special case for removing vmstate
+	# if the only thing we want to delete is the vmstate, we skip the
+	#'suspended' lock and remove it as well as the running machine and vmstate
+	if (scalar(@delete) == 1 && $delete[0] eq 'vmstate' &&
+	    !scalar(keys %$param) && !scalar(keys %$revert) &&
+	    defined($conf->{lock}) && $conf->{lock} eq 'suspended')
+	{
+	    $clear_suspend = 1;
+	    push @delete, 'lock';
+	    push @delete, 'runningmachine' if $conf->{runningmachine};
+	}
+
+	PVE::QemuConfig->check_lock($conf) if !$skiplock && !$clear_suspend;
 
 	foreach my $opt (keys %$revert) {
 	    if (defined($conf->{$opt})) {
-- 
2.20.1





More information about the pve-devel mailing list