Imported Upstream version 3.3.3
[debian/amanda] / perl / Amanda / Taper / Worker.pm
index d8802be4076ffb068e8497293d0bcbcdda53c971..74ca33287ad53155572dc9d22b495b0d827c81a6 100644 (file)
@@ -1,8 +1,9 @@
 # Copyright (c) 2009-2012 Zmanda Inc.  All Rights Reserved.
 #
-# This program is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License version 2 as published
-# by the Free Software Foundation.
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
 #
 # This program is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
@@ -222,14 +223,20 @@ sub DONE {
     my $self = shift;
     my ($msgtype, %params) = @_;
 
-    if (!defined $self->{'dumper_status'}) {
-       $self->{'dumper_status'} = "DONE";
-       $self->{'orig_kb'} = $params{'orig_kb'};
-       if (defined $self->{'result'}) {
-           $self->result_cb(undef);
-       }
-    } else {
-       # ignore the message
+    if ($params{'handle'} ne $self->{'handle'}) {
+       # ignore message for previous handle
+       return;
+    }
+
+    if (defined $self->{'dumper_status'}) {
+       # ignore duplicate message
+       return
+    }
+
+    $self->{'dumper_status'} = "DONE";
+    $self->{'orig_kb'} = $params{'orig_kb'};
+    if (defined $self->{'result'}) {
+       $self->result_cb(undef);
     }
 }
 
@@ -237,6 +244,16 @@ sub FAILED {
     my $self = shift;
     my ($msgtype, %params) = @_;
 
+    if ($params{'handle'} ne $self->{'handle'}) {
+       # ignore message for previous handle
+       return;
+    }
+
+    if (defined $self->{'dumper_status'}) {
+       # ignore duplicate message
+       return
+    }
+
     $self->{'dumper_status'} = "FAILED";
     if (defined $self->{'header_xfer'}) {
        $self->{'header_xfer'}->cancel();
@@ -270,7 +287,7 @@ sub result_cb {
     my $logtype;
 
     if ($params{'result'} eq 'DONE') {
-       if (!$self->{'doing_port_write'} or $self->{'dumper_status'} eq "DONE") {
+       if ($self->{'dumper_status'} eq "DONE") {
            $msgtype = Amanda::Taper::Protocol::DONE;
            $logtype = $L_DONE;
        } else {
@@ -346,7 +363,7 @@ sub result_cb {
        $msg_params{'taper'} = 'TAPE-ERROR';
        $msg_params{'tapererr'} = join("; ", @{$params{'device_errors'}});
     } elsif ($params{'config_denial_message'}) {
-       $msg_params{'taper'} = 'TAPE-ERROR';
+       $msg_params{'taper'} = 'TAPE-CONFIG';
        $msg_params{'tapererr'} = $params{'config_denial_message'};
     } else {
        $msg_params{'taper'} = 'TAPE-GOOD';
@@ -618,10 +635,10 @@ sub setup_and_start_dump {
     step process_args => sub {
        # extract the splitting-related parameters, stripping out empty strings
        my %splitting_args = map {
-           ($params{$_} ne '')? ($_, $params{$_}) : ()
+           (defined $params{$_} && $params{$_} ne '')? ($_, $params{$_}) : ()
        } qw(
            dle_tape_splitsize dle_split_diskbuffer dle_fallback_splitsize dle_allow_split
-           part_size part_cache_type part_cache_dir part_cache_max_size
+           part_size part_cache_type part_cache_dir part_cache_max_size data_path
        );
 
        # convert numeric values to BigInts
@@ -700,12 +717,19 @@ sub setup_and_start_dump {
            # getting the header is easy for FILE-WRITE..
            my $hdr = $self->{'header'} = Amanda::Holding::get_header($params{'filename'});
 
+           if (!defined $hdr || $hdr->{'type'} != $Amanda::Header::F_DUMPFILE) {
+               confess("Could not read header from '$params{filename}'");
+           }
+
            # stip out header fields we don't need
            $hdr->{'cont_filename'} = '';
 
-           if (!defined $hdr || $hdr->{'type'} != $Amanda::Header::F_DUMPFILE) {
-               confess("Could not read header from '$params{filename}'");
+           if ($self->{'header'}->{'is_partial'}) {
+               $self->{'dumper_status'} = "FAILED";
+           } else {
+               $self->{'dumper_status'} = "DONE";
            }
+
            $steps->{'start_dump'}->(undef);
        } else {
            # ..but quite a bit harder for PORT-WRITE; this method will send the
@@ -721,6 +745,11 @@ sub setup_and_start_dump {
         $self->_assert_in_state("getting_header") or return;
         $self->{'state'} = 'writing';
 
+       # abort if we already got a device_errors
+       if (@{$self->{'scribe'}->{'device_errors'}}) {
+           $self->{'scribe'}->abort_setup(dump_cb => $params{'dump_cb'});
+           return;
+       }
         # if $err is set, cancel the dump, treating it as a input error
         if ($err) {
            push @{$self->{'input_errors'}}, $err;