1 # Copyright (c) 2008-2012 Zmanda, Inc. All Rights Reserved.
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful, but
9 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 # You should have received a copy of the GNU General Public License along
14 # with this program; if not, write to the Free Software Foundation, Inc.,
15 # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
18 # Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
20 package Amanda::Changer::single;
26 @ISA = qw( Amanda::Changer );
28 use File::Glob qw( :glob );
30 use Amanda::Config qw( :getconf );
34 use Amanda::Device qw( :constants );
38 Amanda::Changer::single
42 This changer represents a single drive as a changer. It may eventually morph
43 into something similar to the old C<chg-manual>.
45 Whatever you load, you get the volume in the drive. The volume's either
46 reserved or not. All pretty straightforward.
48 See the amanda-changers(7) manpage for usage information.
54 my ($config, $tpchanger) = @_;
55 my ($device_name) = ($tpchanger =~ /chg-single:(.*)/);
57 # check that $device_name is an honest-to-goodness device
58 my $tmpdev = Amanda::Device->new($device_name);
59 if ($tmpdev->status() != $DEVICE_STATUS_SUCCESS) {
60 return Amanda::Changer->make_error("fatal", undef,
61 message => "chg-single: error opening device '$device_name': " .
62 $tmpdev->error_or_status());
67 device_name => $device_name,
71 bless ($self, $class);
78 $self->validate_params('load', \%params);
80 return if $self->check_error($params{'res_cb'});
82 confess "no res_cb supplied" unless (exists $params{'res_cb'});
84 if ($self->{'reserved'}) {
85 return $self->make_error("failed", $params{'res_cb'},
87 message => "'$self->{device_name}' is already reserved");
90 if (keys %{$params{'except_slots'}} > 0) {
91 return $self->make_error("failed", $params{'res_cb'},
93 message => "all slots have been loaded");
96 my $device = Amanda::Device->new($self->{'device_name'});
97 if ($device->status() != $DEVICE_STATUS_SUCCESS) {
98 return $self->make_error("fatal", $params{'res_cb'},
99 message => "error opening device '$self->{device_name}': " . $device->error_or_status());
102 if (my $msg = $self->{'config'}->configure_device($device)) {
103 # a failure to configure a device is fatal, since it's probably
104 # a user configuration error (and thus unlikely to work for the
105 # next device, either)
106 return $self->make_error("fatal", $params{'res_cb'},
110 my $res = Amanda::Changer::single::Reservation->new($self, $device);
111 $device->read_label();
112 $params{'res_cb'}->(undef, $res);
122 device_status => undef,
127 $params{'inventory_cb'}->(undef, \@inventory);
132 my ($key, %params) = @_;
135 return if $self->check_error($params{'info_cb'});
137 if ($key eq 'num_slots') {
139 } elsif ($key eq 'fast_search') {
140 # (asking the user for a specific label is faster than asking
141 # for each "slot" in a sequential scan, so search is "fast")
145 $params{'info_cb'}->(undef, %results) if $params{'info_cb'};
148 package Amanda::Changer::single::Reservation;
150 @ISA = qw( Amanda::Changer::Reservation );
154 my ($chg, $device) = @_;
155 my $self = Amanda::Changer::Reservation::new($class);
157 $self->{'chg'} = $chg;
159 $self->{'device'} = $device;
161 $self->{'this_slot'} = '1';
162 $chg->{'reserved'} = 1;
171 $self->{'device'}->eject() if (exists $self->{'device'} and
172 exists $params{'eject'} and
175 $self->{'chg'}->{'reserved'} = 0;
177 # unref the device, for good measure
178 $self->{'device'} = undef;
180 $params{'finished_cb'}->(undef) if $params{'finished_cb'};