[pve-devel] [PATCH manager 2/3] remove backup locks when starting all VMs on boot
Philip Abernethy
p.abernethy at proxmox.com
Tue Sep 5 17:54:25 CEST 2017
From: Thomas Lamprecht <t.lamprecht at proxmox.com>
If on bootup one of our VMs is locked by an backup we safely can
assume that this backup job does not run anymore and that the lock
has no reason anymore and just hinders uptime of services.
As at this time we (the node) have quorum so we may safely assume
that we have a consistent view of the cluster and all our VMs really
belong to us. We just need to ensure that we do not run into an
automatic backup jobs, so execute our code with VZDumps lock or
timeout.
Log in the Task and Sys log that we removed the lock, so that an
admin easily sees that there may be need for cleaning leftovers from
an interrupted backup.
Addresses bug #1024
Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
PVE/API2/Nodes.pm | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/PVE/API2/Nodes.pm b/PVE/API2/Nodes.pm
index 101a4f40..eb1ef69b 100644
--- a/PVE/API2/Nodes.pm
+++ b/PVE/API2/Nodes.pm
@@ -1250,6 +1250,7 @@ my $get_filtered_vmlist = sub {
$res->{$vmid}->{conf} = $conf;
$res->{$vmid}->{type} = $d->{type};
+ $res->{$vmid}->{class} = $class;
};
warn $@ if $@;
}
@@ -1283,6 +1284,26 @@ my $get_start_stop_list = sub {
return $resList;
};
+my $remove_locks_on_startup = sub {
+ my ($nodename) = @_;
+
+ my $vmlist = &$get_filtered_vmlist($nodename, undef, undef, 1);
+
+ foreach my $vmid (keys %$vmlist) {
+ my $conf = $vmlist->{$vmid}->{conf};
+ my $class = $conf->{class};
+
+ eval {
+ if ($class->has_lock($conf, 'backup')) {
+ $class->remove_lock($vmid, 'backup');
+ my $msg = "removed left over backup lock from '$vmid'!";
+ warn "$msg\n"; # prints to task log
+ syslog('warning', $msg);
+ }
+ }; warn $@ if $@;
+ }
+};
+
__PACKAGE__->register_method ({
name => 'startall',
path => 'startall',
@@ -1334,6 +1355,11 @@ __PACKAGE__->register_method ({
} while (!PVE::Cluster::check_cfs_quorum(1));
print "got quorum\n";
}
+
+ eval { # remove backup locks, but avoid running into a scheduled backup job
+ PVE::Tools::lock_file('/var/run/vzdump.lock', 10, $remove_locks_on_startup, $nodename);
+ }; warn $@ if $@;
+
my $autostart = $force ? undef : 1;
my $startList = &$get_start_stop_list($nodename, $autostart, $param->{vms});
--
2.11.0
More information about the pve-devel
mailing list