public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Daniel Tschlatscher <d.tschlatscher@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH qemu-server v4 5/6] make the timeout value editable when the VM is locked
Date: Thu,  5 Jan 2023 11:08:36 +0100	[thread overview]
Message-ID: <20230105100837.195520-6-d.tschlatscher@proxmox.com> (raw)
In-Reply-To: <20230105100837.195520-1-d.tschlatscher@proxmox.com>

In some cases the VM could no longer start when the timeout value was
set and afterwards, for example, hibernated. In this case the VM is
soft locked in the GUI, because the API would not allow changing the
timeout value anymore. (The only way out here would be to change the
value manually in the config)

To avoid unwanted side effects, it is possible to change the value for
the new 'startoptions' parameter, only if the VM is currently locked
with lock 'suspended'.

Signed-off-by: Daniel Tschlatscher <d.tschlatscher@proxmox.com>
---
No changes from v3

 PVE/API2/Qemu.pm | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 9a6b431..ce5f92b 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -11,6 +11,7 @@ use JSON;
 use URI::Escape;
 use Crypt::OpenSSL::Random;
 use Socket qw(SOCK_STREAM);
+use List::Util qw(first);
 
 use PVE::APIClient::LWP;
 use PVE::CGroup;
@@ -650,6 +651,28 @@ my $check_vm_modify_config_perm = sub {
     return 1;
 };
 
+# Certain parameter fields should still be editable and deletable when the VM is locked
+# Returns true only if all parameter fields to be edited or deleted are defined in @allowed
+sub skiplock_for_allowed_fields {
+    my ($param, @deleted) = @_;
+
+    my @allowed = qw"startoptions";
+    my $skiplock = 1;
+
+    my @to_check = @deleted;
+    for (keys %$param) {
+	push(@to_check, $_);
+    }
+
+    my $idx = 0;
+    while ($skiplock && $idx < keys @to_check) {
+	$skiplock &= defined(first { $_ eq $to_check[$idx] } @allowed);
+	$idx++;
+    }
+
+    return $skiplock;
+}
+
 __PACKAGE__->register_method({
     name => 'vmlist',
     path => '',
@@ -1598,6 +1621,8 @@ my $update_vm_api  = sub {
 	    push @delete, 'runningcpu' if $conf->{runningcpu};
 	}
 
+	$skiplock |= $conf->{lock} eq "suspended" && skiplock_for_allowed_fields($param, @delete);
+
 	PVE::QemuConfig->check_lock($conf) if !$skiplock;
 
 	foreach my $opt (keys %$revert) {
-- 
2.30.2





  parent reply	other threads:[~2023-01-05 10:09 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-05 10:08 [pve-devel] [PATCH common/qemu-server/manager v4] fix #3502: VM start timeout config parameter Daniel Tschlatscher
2023-01-05 10:08 ` [pve-devel] [PATCH common v4 1/6] VM start timeout config parameter in backend Daniel Tschlatscher
2023-01-16 15:38   ` Thomas Lamprecht
2023-01-05 10:08 ` [pve-devel] [PATCH qemu-server v4 2/6] expose VM start timeout config setting in API Daniel Tschlatscher
2023-01-05 10:08 ` [pve-devel] [PATCH qemu-server v4 3/6] await and kill lingering KVM thread when VM start reaches timeout Daniel Tschlatscher
2023-01-05 10:08 ` [pve-devel] [PATCH qemu-server v4 4/6] re-check if VM is running and PID for KILL after timeout Daniel Tschlatscher
2023-01-05 10:08 ` Daniel Tschlatscher [this message]
2023-01-05 10:08 ` [pve-devel] [PATCH manager v4 6/6] VM start Timeout "Options" parameter in the GUI Daniel Tschlatscher

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230105100837.195520-6-d.tschlatscher@proxmox.com \
    --to=d.tschlatscher@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal