[pve-devel] [PATCH manager] vzdump: set task mode early to fix a warning
Fabian Grünbichler
f.gruenbichler at proxmox.com
Fri Aug 19 14:13:47 CEST 2016
applied
On Thu, Aug 18, 2016 at 09:35:00AM +0200, Wolfgang Bumiller wrote:
> 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 43d238d..5f77b54 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} };
> }
> }
>
> --
> 2.1.4
>
>
> _______________________________________________
> pve-devel mailing list
> pve-devel at pve.proxmox.com
> http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
More information about the pve-devel
mailing list