From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 2143A60A15 for ; Thu, 3 Sep 2020 10:59:38 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id E2E5816E70 for ; Thu, 3 Sep 2020 10:59:07 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 0F96416E00 for ; Thu, 3 Sep 2020 10:59:04 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id CD800449EC for ; Thu, 3 Sep 2020 10:59:03 +0200 (CEST) From: Stefan Reiter To: pve-devel@lists.proxmox.com Date: Thu, 3 Sep 2020 10:58:50 +0200 Message-Id: <20200903085851.5073-7-s.reiter@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200903085851.5073-1-s.reiter@proxmox.com> References: <20200903085851.5073-1-s.reiter@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.053 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [qemuserver.pm] Subject: [pve-devel] [PATCH qemu-server 6/7] fix vm_resume and allow vm_start with QMP status 'shutdown' X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Sep 2020 08:59:38 -0000 When the VM is in status 'shutdown', i.e. after the guest issues a powerdown while a backup is running, QEMU requires a 'system_reset' to be issued before 'cont' can boot the guest again. Additionally, when the VM has been powered down during a backup, the logically correct call would be a 'vm_start', so automatically vm_resume from vm_start in case this situation occurs. This also means the GUI can cope with this almost unchanged. Signed-off-by: Stefan Reiter --- PVE/QemuServer.pm | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index a5ff16f..982d0a4 100644 --- a/PVE/QemuServer.pm +++ b/PVE/QemuServer.pm @@ -4850,13 +4850,22 @@ sub vm_start { if !$params->{skiptemplate} && PVE::QemuConfig->is_template($conf); my $has_suspended_lock = PVE::QemuConfig->has_lock($conf, 'suspended'); + my $has_backup_lock = PVE::QemuConfig->has_lock($conf, 'backup'); + + my $running = check_running($vmid, undef, $migrate_opts->{migratedfrom}); + + if ($has_backup_lock && $running) { + # a backup is currently running, attempt to start the guest in the + # existing QEMU instance + return vm_resume($vmid); + } PVE::QemuConfig->check_lock($conf) if !($params->{skiplock} || $has_suspended_lock); $params->{resume} = $has_suspended_lock || defined($conf->{vmstate}); - die "VM $vmid already running\n" if check_running($vmid, undef, $migrate_opts->{migratedfrom}); + die "VM $vmid already running\n" if $running; if (my $storagemap = $migrate_opts->{storagemap}) { my $replicated = $migrate_opts->{replicated_volumes}; @@ -5536,9 +5545,12 @@ sub vm_resume { PVE::QemuConfig->lock_config($vmid, sub { my $res = mon_cmd($vmid, 'query-status'); my $resume_cmd = 'cont'; + my $reset = 0; - if ($res->{status} && $res->{status} eq 'suspended') { - $resume_cmd = 'system_wakeup'; + if ($res->{status}) { + return if $res->{status} eq 'running'; # job done, go home + $resume_cmd = 'system_wakeup' if $res->{status} eq 'suspended'; + $reset = 1 if $res->{status} eq 'shutdown'; } if (!$nocheck) { @@ -5549,6 +5561,11 @@ sub vm_resume { if !($skiplock || PVE::QemuConfig->has_lock($conf, 'backup')); } + if ($reset) { + # required if a VM shuts down during a backup and we get a resume + # request before the backup finishes for example + mon_cmd($vmid, "system_reset"); + } mon_cmd($vmid, $resume_cmd); }); } -- 2.20.1