X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=perl%2FAmanda%2FTaper%2FScan.pm;h=26c5a6d4c03cf9211f95a72bbd74ee8c6f2c037e;hb=refs%2Ftags%2Fupstream%2F3.2.0;hp=238c44f8fbb9cf41e0b47a8ed96d6eeddd0d7652;hpb=fd48f3e498442f0cbff5f3606c7c403d0566150e;p=debian%2Famanda diff --git a/perl/Amanda/Taper/Scan.pm b/perl/Amanda/Taper/Scan.pm index 238c44f..26c5a6d 100644 --- a/perl/Amanda/Taper/Scan.pm +++ b/perl/Amanda/Taper/Scan.pm @@ -35,6 +35,7 @@ This is an abstract base class for taperscan algorithms. die $err if $err; # write to $reservation->{'device'}, using label $label, and opening # the device with $access_mode (one of $ACCESS_WRITE or $ACCESS_APPEND) + # $is_new is set to 1 if the volume is not already labeled. # .. }); my $user_msg_fn = sub { @@ -48,7 +49,7 @@ C subclasses represent algorithms used by C (see L) to scan for and select volumes for writing. -Call Cnew()> to create a new taperscan +Call C<< Amanda::Taperscan->new() >> to create a new taperscan algorithm. The constructor takes the following keyword arguments: changer Amanda::Changer object to use (required) @@ -64,6 +65,9 @@ instantiated. The remaining options will be taken from the configuration file if not specified. Default values for all of these options are applied before a subclass's constructor is called. +The autolabel option should look like the C hash - see +L. + Subclasses must implement a single method: C. It takes only one mandatory parameter, C: @@ -191,6 +195,7 @@ scan was looking for. use strict; use warnings; use Amanda::Config qw( :getconf ); +use Amanda::Tapelist; sub new { my $class = shift; @@ -236,6 +241,7 @@ sub new { $self->{'tapelist_filename'} = $params{'tapelist_filename'}; $self->{'labelstr'} = $params{'labelstr'}; $self->{'autolabel'} = $params{'autolabel'}; + $self->{'tapelist'} = Amanda::Tapelist->new($self->{'tapelist_filename'}); return $self; } @@ -250,8 +256,7 @@ sub scan { sub read_tapelist { my $self = shift; - $self->{'tapelist'} = Amanda::Tapelist::read_tapelist($self->{'tapelist_filename'}); - return $self->{'tapelist'}; + $self->{'tapelist'}->reload(); } sub oldest_reusable_volume { @@ -260,7 +265,7 @@ sub oldest_reusable_volume { my $best = undef; my $num_acceptable = 0; - for my $tle (@{$self->{'tapelist'}}) { + for my $tle (@{$self->{'tapelist'}->{'tles'}}) { next unless $tle->{'reuse'}; next if $tle->{'datestamp'} eq '0' and !$params{'new_label_ok'}; $num_acceptable++; @@ -286,7 +291,7 @@ sub is_reusable_volume { } # see if it's in the collection of reusable volumes - my @tapelist = @{$self->{'tapelist'}}; + my @tapelist = @{$self->{'tapelist'}->{'tles'}}; my @reusable = @tapelist[$self->{'tapecycle'}-1 .. $#tapelist]; for my $tle (@reusable) { return 1 if $tle eq $vol_tle; @@ -299,6 +304,8 @@ sub is_reusable_volume { sub make_new_tape_label { my $self = shift; my %params = @_; + + my $tl = exists $params{'tapelist'}? $params{'tapelist'} : $self->{'tapelist'}; my $template = exists $params{'template'}? $params{'template'} : $self->{'autolabel'}->{'template'}; my $labelstr = exists $params{'labelstr'}? $params{'labelstr'} : $self->{'labelstr'}; @@ -311,7 +318,7 @@ sub make_new_tape_label { $template) =~ s/(%+)/"%0" . length($1) . "d"/e; my %existing_labels = - map { $_->{'label'} => 1 } @{$self->{'tapelist'}}; + map { $_->{'label'} => 1 } @{$tl->{'tles'}}; my ($i, $label); for ($i = 1; $i < $nlabels; $i++) {