From 6acb632a548f5cfe9fbfe13a3fd2184d53175b22 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Thu, 18 Aug 2016 09:35:00 +0200 Subject: [PATCH] vzdump: set task mode early to fix a warning when a vzdump script is set and the backup fails early (eg. when exceeding the number of backups) run_hook_script() showed an uninitialized value error trying to use $task->{mode} which is set only after prepare() was called. This sets $task->{mode} early, still updated later to $stop if !$running, and changes the condition for whether cleanup() should be called to not use $task->{mode} (which makes no real sense anyway) to using the $cleanup hash like the rest of the code. --- PVE/VZDump.pm | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/PVE/VZDump.pm b/PVE/VZDump.pm index 43d238d9..5f77b548 100644 --- a/PVE/VZDump.pm +++ b/PVE/VZDump.pm @@ -861,7 +861,7 @@ sub exec_backup_task { # prepare - my $mode = $running ? $opts->{mode} : 'stop'; + my $mode = $running ? $task->{mode} : 'stop'; if ($mode eq 'snapshot') { my %saved_task = %$task; @@ -875,6 +875,8 @@ sub exec_backup_task { } } + $cleanup->{prepared} = 1; + $task->{mode} = $mode; debugmsg ('info', "backup mode: $mode", $logfd); @@ -1013,7 +1015,7 @@ sub exec_backup_task { warn $@ if $@; } - if (defined($task->{mode})) { + if ($cleanup->{prepared}) { # only call cleanup when necessary (when prepare was executed) eval { $plugin->cleanup ($task, $vmid) }; warn $@ if $@; @@ -1096,7 +1098,7 @@ sub exec_backup { foreach my $vmid (sort @$vmlist) { next if grep { $_ eq $vmid } @{$opts->{exclude}}; next if !$rpcenv->check($authuser, "/vms/$vmid", [ 'VM.Backup' ], 1); - push @$tasklist, { vmid => $vmid, state => 'todo', plugin => $plugin }; + push @$tasklist, { vmid => $vmid, state => 'todo', plugin => $plugin, mode => $opts->{mode} }; } } } else { @@ -1110,7 +1112,7 @@ sub exec_backup { } } $rpcenv->check($authuser, "/vms/$vmid", [ 'VM.Backup' ]); - push @$tasklist, { vmid => $vmid, state => 'todo', plugin => $plugin }; + push @$tasklist, { vmid => $vmid, state => 'todo', plugin => $plugin, mode => $opts->{mode} }; } }