X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=server-src%2Famtape.pl;h=bb290014808ccca54956d6ba4ad41cc1e6097bfd;hb=c6f0a88c567f8536c498f554285aed1f8150da18;hp=4c8cd36c46c3d11cb1f1300ebc8f05fd20478e14;hpb=cd0b924f27312d57bd42f6c4fae2b795139e2d0b;p=debian%2Famanda diff --git a/server-src/amtape.pl b/server-src/amtape.pl index 4c8cd36..bb29001 100644 --- a/server-src/amtape.pl +++ b/server-src/amtape.pl @@ -148,17 +148,39 @@ sub { }); }); -subcommand("show", "show", "scan all slots in the changer, starting with the current slot", +subcommand("show", "show []", "scan all slots (or listed slots) in the changer, starting with the current slot", sub { my ($finished_cb, @args) = @_; my $last_slot; my %seen_slots; my $chg; - if (@args != 0) { + if (@args > 1) { return usage($finished_cb); } + my $what = $args[0]; + my @slots; + + if (defined $what) { + my @what1 = split /,/, $what; + foreach my $what1 (@what1) { + if ($what1 =~ /^(\d*)-(\d*)$/) { + my $begin = $1; + my $end = $2; + $end = $begin if $begin > $end; + while ($begin <= $end) { + push @slots, $begin; + $begin++; + } + } else { + push @slots, $what1; + } + } + } + + my $use_slots = @slots > 0; + $chg = load_changer($finished_cb) or return; my $steps = define_steps @@ -173,13 +195,19 @@ sub { my ($err, %info) = @_; return failure($err, $finished_cb) if $err; - print STDERR "amtape: scanning all $info{num_slots} slots in changer:\n"; + if ($use_slots) { + my $slot = shift @slots; + $chg->load(slot => $slot, + mode => "read", + res_cb => $steps->{'loaded'}); - $steps->{'load_current'}->(); - }; + } else { + print STDERR "amtape: scanning all $info{num_slots} slots in changer:\n"; - step load_current => sub { - $chg->load(relative_slot => 'current', mode => "read", res_cb => $steps->{'loaded'}); + $chg->load(relative_slot => 'current', + mode => "read", + res_cb => $steps->{'loaded'}); + } }; step loaded => sub { @@ -224,8 +252,19 @@ sub { }; step released => sub { - $chg->load(relative_slot => 'next', slot => $last_slot, - except_slots => { %seen_slots }, res_cb => $steps->{'loaded'}); + if ($use_slots) { + return $finished_cb->() if @slots == 0; + my $slot = shift @slots; + $chg->load(slot => $slot, + mode => "read", + res_cb => $steps->{'loaded'}); + + } else { + $chg->load(relative_slot => 'next', + slot => $last_slot, + except_slots => { %seen_slots }, + res_cb => $steps->{'loaded'}); + } }; }); @@ -274,7 +313,11 @@ sub { } elsif ($sl->{'device_status'} == $DEVICE_STATUS_VOLUME_UNLABELED) { $line .= " blank"; } elsif ($sl->{'device_status'} != $DEVICE_STATUS_SUCCESS) { - $line .= "device error"; + if (defined $sl->{'device_error'}) { + $line .= " " . $sl->{'device_error'}; + } else { + $line .= "device error"; + } } elsif ($sl->{'f_type'} != $Amanda::Header::F_TAPESTART) { $line .= " blank"; } else { @@ -534,13 +577,25 @@ sub { my $result_cb = make_cb(result_cb => sub { my ($err, $res, $label, $mode) = @_; if ($err) { - $taperscan->quit() if defined $taperscan; - return failure($err, $finished_cb); + if ($res) { + $res->release(finished_cb => sub { + $taperscan->quit() if defined $taperscan; + return failure($err, $finished_cb); + }); + return; + } else { + $taperscan->quit() if defined $taperscan; + return failure($err, $finished_cb); + } } my $modestr = ($mode == $ACCESS_APPEND)? "append" : "write"; my $slot = $res->{'this_slot'}; - print STDERR "Will $modestr to volume $label in slot $slot.\n"; + if (defined $res->{'device'} and defined $res->{'device'}->volume_label()) { + print STDERR "Will $modestr to volume '$label' in slot $slot.\n"; + } else { + print STDERR "Will $modestr label '$label' to new volume in slot $slot.\n"; + } $res->release(finished_cb => sub { my ($err) = @_; die "$err" if $err; @@ -572,10 +627,10 @@ sub { }, finished_cb => sub { my ($err) = @_; + $chg->quit(); return failure($err, $finished_cb) if $err; print STDERR "update complete\n"; - $chg->quit(); $finished_cb->(); }); }); @@ -620,8 +675,10 @@ Amanda::Util::setup_application("amtape", "server", $CONTEXT_CMDLINE); my $config_overrides = new_config_overrides($#ARGV+1); +debug("Arguments: " . join(' ', @ARGV)); Getopt::Long::Configure(qw(bundling)); GetOptions( + 'version' => \&Amanda::Util::version_opt, 'help|usage|?' => \&usage, 'o=s' => sub { add_config_override_opt($config_overrides, $_[1]); }, ) or usage();