X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=perl%2FAmanda%2FTaper%2FScan.pm;fp=perl%2FAmanda%2FTaper%2FScan.pm;h=238c44f8fbb9cf41e0b47a8ed96d6eeddd0d7652;hb=fd48f3e498442f0cbff5f3606c7c403d0566150e;hp=0000000000000000000000000000000000000000;hpb=96f35b20267e8b1a1c846d476f27fcd330e0b018;p=debian%2Famanda diff --git a/perl/Amanda/Taper/Scan.pm b/perl/Amanda/Taper/Scan.pm new file mode 100644 index 0000000..238c44f --- /dev/null +++ b/perl/Amanda/Taper/Scan.pm @@ -0,0 +1,333 @@ +# Copyright (c) 2010 Zmanda, Inc. All Rights Reserved. +# +# This library is free software; you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License version 2.1 as +# published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +# License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this library; if not, write to the Free Software Foundation, +# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +# +# Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300 +# Sunnyvale, CA 94086, USA, or: http://www.zmanda.com + +package Amanda::Taper::Scan; + +=head1 NAME + +Amanda::Taper::Scan + +=head1 SYNOPSIS + +This is an abstract base class for taperscan algorithms. + + # open the taperscan algorithm specified in the config + my $taperscan = Amanda::Taperscan->new( + changer => $changer); + + my $result_cb = make_cb(result_cb => sub { + my ($err, $reservation, $label, $access_mode, $is_new) = @_; + 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) + # .. + }); + my $user_msg_fn = sub { + print "$_[0]\n"; + }; + $taperscan->scan(result_cb => $result_cb, user_msg_fn => $user_msg_fn); + +=head1 OVERVIEW + +C subclasses represent algorithms used by +C (see L) to scan for and select +volumes for writing. + +Call Cnew()> to create a new taperscan +algorithm. The constructor takes the following keyword arguments: + + changer Amanda::Changer object to use (required) + algorithm Taperscan algorithm to instantiate + tapelist_filename + tapecycle + labelstr + autolabel + +The changer object must always be provided, but C may be omitted, in +which case the class specified by the user in the Amanda configuration file is +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. + +Subclasses must implement a single method: C. It takes only one mandatory +parameter, C: + + $taperscan->scan( + result_cb => $my_result_cb, + user_msg_fn => $fn, + ); + +If C is specified, then it is called with user-oriented messages to +indicate the progress of the scan. + +The C takes the following positional parameters: + + $error an error message, or undef on success + $reservation Amanda::Changer::Reservation object + $label label to apply to the volume + $access_mode access mode with which to start the volume + +The error message can be a simple string or an C object +(see L). The C<$label> and C<$access_mode> specify parameters +for starting the device contained in C<$reservation>. + +=head1 SUBCLASS UTILITIES + +There are a few common tasks for subclasses that are implemented as methods in +the parent class. Note that this class assumes subclasses will be implemented +as blessed hashrefs, and sets keys corresponding to the constructor arguments. + +To read the tapelist, call C. This method caches the result in +C<< $self->{'tapelist'} >>, which will be used by the other functions here. In +general, call C at most once per C invocation. + +To see if a volume is reusable, call the C method. This takes +several keyword parameters: + + $self->is_reusable_volume( + label => $label, # label to check + new_label_ok => $nlo, # count newly labeled vols as reusable? + ); + +Similarly, to calculate the oldest reusable volume, call +C: + + $self->oldest_reusable_volume( + new_label_ok => $nlo, # count newly labeled vols as reusable? + ); + +Finally, to devise a new name for a volume, call C, +passing a tapelist, a labelstr, and a template. This will return C +if no label could be created. + + $label = $self->make_new_tape_label( + labelstr => "foo-[0-9]+", + template => "foo-%%%%", + ); + +If no C