X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=perl%2FAmanda%2FChanger.pm;fp=perl%2FAmanda%2FChanger.pm;h=8f284fc68ef41e1684b3372b648bb4e48e691a5c;hb=d28952249e392eb31bc8eecc53f6c477f30c617b;hp=419c1a0d510755522595522c3e48d288f68d3b1c;hpb=949b8910a5e23c4285d0b1aedacfc82a14dc97a5;p=debian%2Famanda diff --git a/perl/Amanda/Changer.pm b/perl/Amanda/Changer.pm index 419c1a0..8f284fc 100644 --- a/perl/Amanda/Changer.pm +++ b/perl/Amanda/Changer.pm @@ -1,8 +1,9 @@ # Copyright (c) 2007-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 @@ -186,6 +187,7 @@ has one of the following values: driveinuse All drives are in use unknown Unknown reason empty The slot is empty + device Failed to set up the device Like types, checks for particular reasons should use the methods, to avoid undetected typos: @@ -1176,6 +1178,13 @@ sub with_locked_state { my ($statefile, $cb, $sub) = @_; my ($filelock, $STATE); my $poll = 0; # first delay will be 0.1s; see below + my $time; + + if (defined $self->{'lock-timeout'}) { + $time = time() + $self->{'lock-timeout'}; + } else { + $time = time() + 1000; + } my $steps = define_steps cb_ref => \$cb; @@ -1188,10 +1197,13 @@ sub with_locked_state { step lock => sub { my $rv = $filelock->lock(); - if ($rv == 1) { + if ($rv == 1 && time() < $time) { # loop until we get the lock, increasing $poll to 10s $poll += 100 unless $poll >= 10000; return Amanda::MainLoop::call_after($poll, $steps->{'lock'}); + } elsif ($rv == 1) { + return $self->make_error("fatal", $cb, + message => "Timeout trying to lock '$statefile'"); } elsif ($rv == -1) { return $self->make_error("fatal", $cb, message => "Error locking '$statefile'"); @@ -1509,6 +1521,7 @@ sub driveinuse { $_[0]->failed && $_[0]->{'reason'} eq 'driveinuse'; } sub volinuse { $_[0]->failed && $_[0]->{'reason'} eq 'volinuse'; } sub unknown { $_[0]->failed && $_[0]->{'reason'} eq 'unknown'; } sub empty { $_[0]->failed && $_[0]->{'reason'} eq 'empty'; } +sub device { $_[0]->failed && $_[0]->{'reason'} eq 'device'; } # slot accessor sub slot { $_[0]->{'slot'}; }