]> git.proxmox.com Git - pve-ha-manager.git/commitdiff
fix #1073: do not count backup-suspended VMs as running
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 23 Aug 2017 08:15:49 +0000 (10:15 +0200)
committerFabian Grünbichler <f.gruenbichler@proxmox.com>
Wed, 23 Aug 2017 08:29:33 +0000 (10:29 +0200)
when a stopped VM managed by HA got backuped the HA stack
continuously tried to shut it down as check_running returns only if a
PID for the VM exists.
As the VM was locked the shutdown tries were blocked, but still a lot
of annoying messages and task spawns happened during the backup
period.

As querying the VM status through the vm monitor is not cheap, check
if the VM is locked with the backup lock first, the config is cached
and so this is quite cheap, only then query the VMs status over qmp,
and check if the VM is in the 'prelaunch' state.
This state gets only set if KVM was started with the `-S` option and
has not yet continued guest operation.

Some performance results, I repeated each check 1000 times, first
number is the total time spent just with the check, second time is
the the time per single check:

old check (vm runs):            87.117 ms/total =>  87.117 us/loop
new check (runs, no backup):   107.744 ms/total => 107.744 us/loop
new check (runs, backup):      760.337 ms/total => 760.337 us/loop

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/PVE/HA/Resources/PVEVM.pm

index 529d8fb50ea5d6144524b888f963054b2a44ea79..c5276dcee4f0f8f842f306930752f53644882401 100644 (file)
@@ -120,7 +120,18 @@ sub check_running {
 
     my $nodename = $haenv->nodename();
 
-    return PVE::QemuServer::check_running($vmid, 1, $nodename);
+    if (PVE::QemuServer::check_running($vmid, 1, $nodename)) {
+       # do not count VMs which are suspended for a backup job as running
+       my $conf = PVE::QemuConfig->load_config($vmid, $nodename);
+       if (defined($conf->{lock}) && $conf->{lock} eq 'backup') {
+           my $qmpstatus = PVE::QemuServer::vm_qmp_command($vmid, {execute => 'query-status'});
+           return 0 if $qmpstatus->{status} eq 'prelaunch';
+       }
+
+       return 1;
+    } else {
+       return 0;
+    }
 }
 
 sub remove_locks {