[pve-devel] [PATCH manager 2/2] remove backup locks when starting all VMs on boot

Thomas Lamprecht t.lamprecht at proxmox.com
Wed Mar 15 16:47:42 CET 2017


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 d78f49c..03f97bf 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 $@;
     }
@@ -1286,6 +1287,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', 
@@ -1337,6 +1358,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.1.4





More information about the pve-devel mailing list