[pve-devel] [PATCH manager] vzdump: allow plugins to set guest resume time

Thomas Lamprecht t.lamprecht at proxmox.com
Wed May 8 19:32:36 CEST 2019


This refactors things a bit to avoid having the same two lines in 3
places and allows the plugin to set the "guest was resumed" time
stamp at the point it really was resumed, not only once the backup
completed (see #503). Further, if a plugin prints it's own
"resumed/running after X seconds" message, it can unset the vmstop
time and thus avoid printing the message twice.

related to a fix for #503

Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
 PVE/VZDump.pm | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/PVE/VZDump.pm b/PVE/VZDump.pm
index 6508c833..0a35eea7 100644
--- a/PVE/VZDump.pm
+++ b/PVE/VZDump.pm
@@ -750,7 +750,12 @@ sub exec_backup_task {
 
     my $cleanup = {};
 
-    my $vmstoptime = 0;
+    my $log_vm_online_again = sub {
+	return if !defined($task->{vmstoptime});
+	$task->{vmconttime} //= time();
+	my $delay = $task->{vmconttime} - $task->{vmstoptime};
+	debugmsg ('info', "guest is online again after $delay seconds", $logfd);
+    };
 
     eval {
 	die "unable to find VM '$vmid'\n" if !$plugin;
@@ -877,7 +882,7 @@ sub exec_backup_task {
 
 	    if ($running) {
 		debugmsg ('info', "stopping vm", $logfd);
-		$vmstoptime = time ();
+		$task->{vmstoptime} = time();
 		$self->run_hook_script ('pre-stop', $task, $logfd);
 		$plugin->stop_vm ($task, $vmid);
 		$cleanup->{restart} = 1;
@@ -896,7 +901,7 @@ sub exec_backup_task {
 	    }
 
 	    debugmsg ('info', "suspend vm", $logfd);
-	    $vmstoptime = time ();
+	    $task->{vmstoptime} = time ();
 	    $self->run_hook_script ('pre-stop', $task, $logfd);
 	    $plugin->suspend_vm ($task, $vmid);
 	    $cleanup->{resume} = 1;
@@ -910,8 +915,7 @@ sub exec_backup_task {
 		$self->run_hook_script('pre-restart', $task, $logfd);
 		$plugin->resume_vm($task, $vmid);
 		$self->run_hook_script('post-restart', $task, $logfd);
-		my $delay = time () - $vmstoptime;
-		debugmsg('info', "vm is online again after $delay seconds", $logfd);
+		$log_vm_online_again->();
 	    }
 	    
 	} elsif ($mode eq 'snapshot') {
@@ -924,7 +928,7 @@ sub exec_backup_task {
 
 	    if ($snapshot_count > 1) {
 		debugmsg ('info', "suspend vm to make snapshot", $logfd);
-		$vmstoptime = time ();
+		$task->{vmstoptime} = time ();
 		$plugin->suspend_vm ($task, $vmid);
 		$cleanup->{resume} = 1;
 	    }
@@ -937,8 +941,7 @@ sub exec_backup_task {
 		debugmsg ('info', "resume vm", $logfd);
 		$cleanup->{resume} = 0;
 		$plugin->resume_vm ($task, $vmid);
-		my $delay = time () - $vmstoptime;
-		debugmsg ('info', "vm is online again after $delay seconds", $logfd);
+		$log_vm_online_again->();
 	    }
 
 	    $self->run_hook_script ('post-restart', $task, $logfd);
@@ -1026,8 +1029,7 @@ sub exec_backup_task {
 	    if ($err) {
 		warn $err;
 	    } else {
-		my $delay = time () - $vmstoptime;
-		debugmsg ('info', "vm is online again after $delay seconds", $logfd);
+		$log_vm_online_again->();
 	    }
 	}
     }
-- 
2.20.1





More information about the pve-devel mailing list