1 # Copyright (c) 2008-2012 Zmanda, Inc. All Rights Reserved.
3 # This program is free software; you can redistribute it and/or modify it
4 # under the terms of the GNU General Public License version 2 as published
5 # by the Free Software Foundation.
7 # This program is distributed in the hope that it will be useful, but
8 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
9 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 # You should have received a copy of the GNU General Public License along
13 # with this program; if not, write to the Free Software Foundation, Inc.,
14 # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 # Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
17 # Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
19 package Amanda::Changer::single;
25 @ISA = qw( Amanda::Changer );
27 use File::Glob qw( :glob );
29 use Amanda::Config qw( :getconf );
33 use Amanda::Device qw( :constants );
37 Amanda::Changer::single
41 This changer represents a single drive as a changer. It may eventually morph
42 into something similar to the old C<chg-manual>.
44 Whatever you load, you get the volume in the drive. The volume's either
45 reserved or not. All pretty straightforward.
47 See the amanda-changers(7) manpage for usage information.
53 my ($config, $tpchanger) = @_;
54 my ($device_name) = ($tpchanger =~ /chg-single:(.*)/);
56 # check that $device_name is an honest-to-goodness device
57 my $tmpdev = Amanda::Device->new($device_name);
58 if ($tmpdev->status() != $DEVICE_STATUS_SUCCESS) {
59 return Amanda::Changer->make_error("fatal", undef,
60 message => "chg-single: error opening device '$device_name': " .
61 $tmpdev->error_or_status());
66 device_name => $device_name,
70 bless ($self, $class);
77 $self->validate_params('load', \%params);
79 return if $self->check_error($params{'res_cb'});
81 confess "no res_cb supplied" unless (exists $params{'res_cb'});
83 if ($self->{'reserved'}) {
84 return $self->make_error("failed", $params{'res_cb'},
86 message => "'$self->{device_name}' is already reserved");
89 if (keys %{$params{'except_slots'}} > 0) {
90 return $self->make_error("failed", $params{'res_cb'},
92 message => "all slots have been loaded");
95 my $device = Amanda::Device->new($self->{'device_name'});
96 if ($device->status() != $DEVICE_STATUS_SUCCESS) {
97 return $self->make_error("fatal", $params{'res_cb'},
98 message => "error opening device '$self->{device_name}': " . $device->error_or_status());
101 if (my $msg = $self->{'config'}->configure_device($device)) {
102 # a failure to configure a device is fatal, since it's probably
103 # a user configuration error (and thus unlikely to work for the
104 # next device, either)
105 return $self->make_error("fatal", $params{'res_cb'},
109 my $res = Amanda::Changer::single::Reservation->new($self, $device);
110 $device->read_label();
111 $params{'res_cb'}->(undef, $res);
121 device_status => undef,
126 $params{'inventory_cb'}->(undef, \@inventory);
131 my ($key, %params) = @_;
134 return if $self->check_error($params{'info_cb'});
136 if ($key eq 'num_slots') {
138 } elsif ($key eq 'fast_search') {
139 # (asking the user for a specific label is faster than asking
140 # for each "slot" in a sequential scan, so search is "fast")
144 $params{'info_cb'}->(undef, %results) if $params{'info_cb'};
147 package Amanda::Changer::single::Reservation;
149 @ISA = qw( Amanda::Changer::Reservation );
153 my ($chg, $device) = @_;
154 my $self = Amanda::Changer::Reservation::new($class);
156 $self->{'chg'} = $chg;
158 $self->{'device'} = $device;
160 $self->{'this_slot'} = '1';
161 $chg->{'reserved'} = 1;
170 $self->{'device'}->eject() if (exists $self->{'device'} and
171 exists $params{'eject'} and
174 $self->{'chg'}->{'reserved'} = 0;
176 # unref the device, for good measure
177 $self->{'device'} = undef;
179 $params{'finished_cb'}->(undef) if $params{'finished_cb'};