Imported Upstream version 3.3.0
[debian/amanda] / perl / Amanda / Recovery / Scan.pm
1 # Copyright (c) 2010 Zmanda, Inc.  All Rights Reserved.
2 #
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.
6 #
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
10 # for more details.
11 #
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
15 #
16 # Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
17 # Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
18
19 package Amanda::Recovery::Scan;
20
21 use strict;
22 use warnings;
23 use Carp;
24 use POSIX ();
25 use Data::Dumper;
26 use vars qw( @ISA );
27 use base qw(Exporter);
28 our @EXPORT_OK = qw($DEFAULT_CHANGER);
29
30 use Amanda::Paths;
31 use Amanda::Util;
32 use Amanda::Device qw( :constants );
33 use Amanda::Debug qw( debug );
34 use Amanda::Changer;
35 use Amanda::MainLoop;
36 use Amanda::Interactivity;
37
38 use constant SCAN_ASK  => 1;     # call Amanda::Interactivity module
39 use constant SCAN_POLL => 2;     # wait 'poll_delay' and retry the scan.
40 use constant SCAN_FAIL => 3;     # abort
41 use constant SCAN_CONTINUE => 4; # continue to the next step
42 use constant SCAN_ASK_POLL => 5; # call Amanda::Interactivity module and
43                                  # poll at the same time.
44
45 =head1 NAME
46
47 Amanda::Recovery::Scan -- interface to scan algorithm
48
49 =head1 SYNOPSIS
50
51     use Amanda::Recovey::Scan;
52
53     # scan the default changer with no interactivity
54     my $scan = Amanda::Recovery::Scan->new();
55     # ..or scan the changer $chg, using $interactivity for interactivity
56     $scan = Amanda::Recovery::Scan->new(chg => $chg,
57                                         interactivity => $interactivity);
58
59     $scan->find_volume(
60         label => "TAPE-012",
61         res_cb => sub {
62             my ($err, $reservation) = @_;
63             if ($err) {
64                 die "$err";
65             }
66             $dev = $reservation->{device};
67             # use device..
68         });
69
70     # later..
71     $reservation->release(finished_cb => $start_next_volume);
72
73     # later..
74     $scan->quit(); # also quit the changer
75
76     
77 =head1 OVERVIEW
78
79 This package provides a way for programs that need to read data from volumes
80 (loosely called "recovery" programs) to find the volumes they need in a
81 configurable way.  It takes care of prompting for volumes when they are not
82 available, juggling multiple changers, and any other unpredictabilities.
83
84 =head1 INTERFACE
85
86 Like L<Amanda::Changer>, this package operates asynchronously, and thus
87 requires that the caller use L<Amanda::MainLoop> to poll for events.
88
89 A new Scan object is created with the C<new> function as follows:
90
91   my $scan = Amanda::Recovery::Scan->new(scan_conf     => $scan_conf,
92                                          chg           => $chg,
93                                          interactivity => $interactivity);
94
95 C<scan_conf> is the configuration for the scan, which at this point should be
96 omitted, as configuration is not yet supported.  The C<chg> parameter specifies
97 the changer to start the scan with. The default changer is used if C<chg> is
98 omitted. The C<interactivity> parameter gives an C<Amanda::Interactivity> object.
99
100 =head2 CALLBACKS
101
102 Many of the callbacks used by this package are identical to the callbacks of
103 the same name in L<Amanda::Changer>.
104
105 When a callback is called with an error, it is an object of type
106 C<Amanda::Changer::Error>.  The C<volinuse> reason has a different meaning: it
107 means that the volume with that label is present in the changer, but is in use
108 by another program.
109
110 =head2 Scan object
111
112 =head3 find_volume
113
114   $scan->find_volume(label       => $label,
115                      res_cb      => $res_cb,
116                      user_msg_fn => $user_msg_fn,
117                      set_current => 0)
118
119 Find the volume labelled C<$label> and call C<$res_cb>.  C<$user_msg_fn> is
120 used to send progress information, The argumnet it takes are describe in
121 the next section.  As with the C<load> method
122 of the changer API, C<set_current> should be set to 1 if you want the scan to
123 set the current slot.
124
125 =head3 quit
126
127   $scan->quit()
128
129 The cleanly terminate a scan objet, the changer quit is also called.
130
131 =head3 user_msg_fn
132
133 The user_msg_fn take various arguments
134
135 Initiate the scan of the slot $slot:
136   $self->user_msg_fn(scan_slot => 1,
137                      slot      => $slot);
138
139 Initiate the scan of the slot $slot which should have the label $label:
140   $self->user_msg_fn(scan_slot => 1,
141                      slot      => $slot,
142                      label     => $label);   
143
144 The result of scanning slot $slot:
145   $self->user_msg_fn(slot_result => 1,
146                      slot        => $slot,
147                      err         => $err,
148                      res         => $res);
149
150 Other options can be added at any time.  The function can ignore them.
151
152 =cut
153
154 our $DEFAULT_CHANGER = {};
155
156 sub new {
157     my $class = shift;
158     my %params = @_;
159     my $scan_conf = $params{'scan_conf'};
160     my $chg = $params{'chg'};
161     my $interactivity = $params{'interactivity'};
162
163     #until we have a config for it.
164     $scan_conf = Amanda::Recovery::Scan::Config->new();
165     $chg = Amanda::Changer->new() if !defined $chg;
166
167     my $self = {
168         initial_chg   => $chg,
169         chg           => $chg,
170         scan_conf     => $scan_conf,
171         interactivity => $interactivity,
172     };
173     return bless ($self, $class);
174 }
175
176 sub DESTROY {
177     my $self = shift;
178
179     die("Recovery::Scan detroyed without quit") if defined $self->{'scan_conf'};
180 }
181
182 sub quit {
183     my $self = shift;
184
185     $self->{'chg'}->quit() if defined $self->{'chg'};
186
187     foreach (keys %$self) {
188         delete $self->{$_};
189     }
190
191 }
192
193 sub find_volume {
194     my $self = shift;
195     my %params = @_;
196
197     my $label = $params{'label'};
198     my $user_msg_fn = $params{'user_msg_fn'} || \&_user_msg_fn;
199     my $res;
200     my %seen = ();
201     my $inventory;
202     my $current;
203     my $new_slot;
204     my $poll_src;
205     my $scan_running = 0;
206     my $interactivity_running = 0;
207     my $restart_scan = 0;
208     my $abort_scan = undef;
209     my $last_err = undef; # keep the last meaningful error, the one reported
210                           # to the user, most scan end with the notfound error,
211                           # it's more interesting to report an error from the
212                           # device or ...
213     my $slot_scanned;
214     my $remove_undef_state = 0;
215     my $load_for_label = 0; # 1 = Try to load the slot with the correct label
216                             # 0 = Load a slot with an unknown label
217
218     my $steps = define_steps
219         cb_ref => \$params{'res_cb'};
220
221     step get_first_inventory => sub {
222         Amanda::Debug::debug("find_volume labeled '$label'");
223
224         $scan_running = 1;
225         $self->{'chg'}->inventory(inventory_cb => $steps->{'got_first_inventory'});
226     };
227
228     step got_first_inventory => sub {
229         (my $err, $inventory) = @_;
230
231         if ($err && $err->notimpl) {
232             #inventory not implemented
233             return $self->_find_volume_no_inventory(%params);
234         } elsif ($err) {
235             #inventory fail
236             return $steps->{'call_res_cb'}->($err, undef);
237         }
238
239         # find current slot and keep a private copy of the value
240         for my $i (0..(scalar(@$inventory)-1)) {
241             if ($inventory->[$i]->{current}) {
242                 $current = $inventory->[$i]->{slot};
243                 last;
244             }
245         }
246
247         if (!defined $current) {
248             if (scalar(@$inventory) == 0) {
249                 $current = 0;
250             } else {
251                 $current = $inventory->[0]->{slot};
252             }
253         }
254
255         # continue parsing the inventory
256         $steps->{'parse_inventory'}->($err, $inventory);
257     };
258
259     step restart_scan => sub {
260         $restart_scan = 0;
261         return $steps->{'get_inventory'}->();
262     };
263
264     step get_inventory => sub {
265         $self->{'chg'}->inventory(inventory_cb => $steps->{'parse_inventory'});
266     };
267
268     step parse_inventory => sub {
269         (my $err, $inventory) = @_;
270
271         if ($err && $err->notimpl) {
272             #inventory not implemented
273             return $self->_find_volume_no_inventory(%params);
274         }
275         return $steps->{'handle_error'}->($err, undef) if $err;
276
277         # throw out the inventory result and move on if the situation has
278         # changed while we were waiting
279         return $steps->{'abort_scan'}->() if $abort_scan;
280         return $steps->{'restart_scan'}->() if $restart_scan;
281
282         # check if label is in the inventory
283         for my $i (0..(scalar(@$inventory)-1)) {
284             my $sl = $inventory->[$i];
285             if (defined $sl->{'label'} &&
286                 $sl->{'label'} eq $label) {
287                 $slot_scanned = $sl->{'slot'};
288                 if ($sl->{'reserved'}) {
289                     return $steps->{'handle_error'}->(
290                             Amanda::Changer::Error->new('failed',
291                                 reason => 'volinuse',
292                                 message => "Volume '$label' in slot $slot_scanned is reserved"),
293                             undef);
294                 }
295                 Amanda::Debug::debug("parse_inventory: load slot $slot_scanned with label '$label'");
296                 $user_msg_fn->(scan_slot => 1,
297                                slot      => $slot_scanned,
298                                label     => $label);
299                 $seen{$slot_scanned} = { device_status => $sl->{'device_status'},
300                                          f_type        => $sl->{'f_type'},
301                                          label         => $sl->{'label'} };
302                 $load_for_label = 1;
303                 return $self->{'chg'}->load(slot => $slot_scanned,
304                                   res_cb => $steps->{'slot_loaded'},
305                                   set_current => $params{'set_current'});
306             }
307         }
308
309         # Remove from seen all slot that have state == SLOT_UNKNOWN
310         # It is done when as scan is restarted from interactivity object.
311         if ($remove_undef_state) {
312             for my $i (0..(scalar(@$inventory)-1)) {
313                 my $slot = $inventory->[$i]->{slot};
314                 if (exists($seen{$slot}) &&
315                     !defined($inventory->[$i]->{state})) {
316                     delete $seen{$slot}
317                 }
318             }
319             $remove_undef_state = 0;
320         }
321
322         # remove any slots where the state has changed from the list of seen slots
323         for my $i (0..(scalar(@$inventory)-1)) {
324             my $sl = $inventory->[$i];
325             my $slot = $sl->{slot};
326             if ($seen{$slot} &&
327                 defined($sl->{'state'}) &&
328                 (($seen{$slot}->{'device_status'} != $sl->{'device_status'}) ||
329                  (defined $seen{$slot}->{'device_status'} &&
330                   $seen{$slot}->{'device_status'} == $DEVICE_STATUS_SUCCESS &&
331                   $seen{$slot}->{'f_type'} != $sl->{'f_type'}) ||
332                  (defined $seen{$slot}->{'device_status'} &&
333                   $seen{$slot}->{'device_status'} == $DEVICE_STATUS_SUCCESS &&
334                   defined $seen{$slot}->{'f_type'} &&
335                   $seen{$slot}->{'f_type'} == $Amanda::Header::F_TAPESTART &&
336                   $seen{$slot}->{'label'} ne $sl->{'label'}))) {
337                 delete $seen{$slot};
338             }
339         }
340
341         # scan any unseen slot already in a drive, if configured to do so
342         if ($self->{'scan_conf'}->{'scan_drive'}) {
343             for my $sl (@$inventory) {
344                 my $slot = $sl->{'slot'};
345                 if (defined $sl->{'loaded_in'} &&
346                     !$sl->{'reserved'} &&
347                     !$seen{$slot}) {
348                     $slot_scanned = $slot;
349                     $user_msg_fn->(scan_slot => 1, slot => $slot_scanned);
350                     $seen{$slot_scanned} = { device_status => $sl->{'device_status'},
351                                              f_type        => $sl->{'f_type'},
352                                              label         => $sl->{'label'} };
353                     $load_for_label = 0;
354                     return $self->{'chg'}->load(slot => $slot_scanned,
355                                       res_cb => $steps->{'slot_loaded'},
356                                       set_current => $params{'set_current'});
357                 }
358             }
359         }
360
361         # scan slot
362         if ($self->{'scan_conf'}->{'scan_unknown_slot'}) {
363             #find index for current slot
364             my $current_index = undef;
365             for my $i (0..(scalar(@$inventory)-1)) {
366                 my $slot = $inventory->[$i]->{slot};
367                 if ($slot eq $current) {
368                     $current_index = $i;
369                 }
370             }
371
372             #scan next slot to scan
373             $current_index = 0 if !defined $current_index;
374             for my $i ($current_index..(scalar(@$inventory)-1), 0..($current_index-1)) {
375                 my $sl = $inventory->[$i];
376                 my $slot = $sl->{slot};
377                 # skip slots we've seen
378                 next if defined($seen{$slot});
379                 # skip slots that are empty
380                 next if defined $sl->{'state'} &&
381                         $sl->{'state'} == Amanda::Changer::SLOT_EMPTY;
382                 # skip slots for which we have a known label, since it's not the
383                 # one we want
384                 next if defined $sl->{'f_type'} &&
385                         $sl->{'f_type'} == $Amanda::Header::F_TAPESTART;
386                 next if defined $sl->{'label'};
387
388                 # found a slot to check - reset our current slot
389                 $current = $slot;
390                 $slot_scanned = $current;
391                 Amanda::Debug::debug("parse_inventory: load slot $current");
392                 $user_msg_fn->(scan_slot => 1, slot => $slot_scanned);
393                 $seen{$slot_scanned} = { device_status => $sl->{'device_status'},
394                                          f_type        => $sl->{'f_type'},
395                                          label         => $sl->{'label'} };
396                 $load_for_label = 0;
397                 return $self->{'chg'}->load(slot => $slot_scanned,
398                                 res_cb => $steps->{'slot_loaded'},
399                                 set_current => $params{'set_current'});
400             }
401         }
402
403         #All slots are seen or empty.
404         if ($last_err) {
405             return $steps->{'handle_error'}->($last_err, undef);
406         } else {
407             return $steps->{'handle_error'}->(
408                     Amanda::Changer::Error->new('failed',
409                             reason => 'notfound',
410                             message => "Volume '$label' not found"),
411                     undef);
412         }
413     };
414
415     step slot_loaded => sub {
416         (my $err, $res) = @_;
417
418         # we don't responsd to abort_scan or restart_scan here, since we
419         # have an open reservation that we should deal with.
420
421         $user_msg_fn->(slot_result => 1,
422                        slot => $slot_scanned,
423                        err  => $err,
424                        res  => $res);
425         if ($res) {
426             if ($res->{device}->status == $DEVICE_STATUS_SUCCESS &&
427                 $res->{device}->volume_label &&
428                 $res->{device}->volume_label eq $label) {
429                 my $volume_label = $res->{device}->volume_label;
430                 return $steps->{'call_res_cb'}->(undef, $res);
431             }
432             my $f_type;
433             if (defined $res->{device}->volume_header) {
434                 $f_type = $res->{device}->volume_header->{type};
435             } else {
436                 $f_type = undef;
437             }
438
439             # The slot did not contain the volume we wanted, so mark it
440             # as seen and try again.
441             $seen{$slot_scanned} = {
442                         device_status => $res->{device}->status,
443                         f_type => $f_type,
444                         label  => $res->{device}->volume_label
445             };
446
447             # notify the user
448             if ($res->{device}->status == $DEVICE_STATUS_SUCCESS) {
449                 $last_err = undef;
450             } else {
451                 $last_err = Amanda::Changer::Error->new('fatal',
452                                 message => $res->{device}->error_or_status());
453             }
454             return $res->release(finished_cb => $steps->{'load_released'});
455         } else {
456             if ($load_for_label == 0 && $err->volinuse) {
457                 # Scan semantics for volinuse is different than changer.
458                 # If a slot with unknown label is loaded then we map
459                 # volinuse to driveinuse.
460                 $err->{reason} = "driveinuse";
461             }
462             $last_err = $err if $err->fatal || !$err->notfound;
463             if ($load_for_label == 1 && $err->failed && $err->volinuse) {
464                 # volinuse is an error
465                 return $steps->{'handle_error'}->($err, $steps->{'load_released'});
466             }
467             return $steps->{'load_released'}->();
468         }
469     };
470
471     step load_released => sub {
472         my ($err) = @_;
473
474         # TODO: handle error
475
476         $res = undef;
477
478         # throw out the inventory result and move on if the situation has
479         # changed while we were loading a volume
480         return $steps->{'abort_scan'}->() if $abort_scan;
481         return $steps->{'restart_scan'}->() if $restart_scan;
482
483         $new_slot = $current;
484         $steps->{'get_inventory'}->();
485     };
486
487     step handle_error => sub {
488         my ($err, $continue_cb) = @_;
489
490         my $scan_method = undef;
491         $scan_running = 0;
492         my $message;
493
494
495         $poll_src->remove() if defined $poll_src;
496         $poll_src = undef;
497
498         # prefer to use scan method for $last_err, if present
499         if ($last_err && $err->failed && $err->notfound) {
500             $message = "$last_err";
501         
502             if ($last_err->isa("Amanda::Changer::Error")) {
503                 if ($last_err->fatal) {
504                     $scan_method = $self->{'scan_conf'}->{'fatal'};
505                 } else {
506                     $scan_method = $self->{'scan_conf'}->{$last_err->{'reason'}};
507                 }
508             } elsif ($continue_cb) {
509                 $scan_method = SCAN_CONTINUE;
510             }
511         }
512
513         #use scan method for $err
514         if (!defined $scan_method) {
515             if ($err) {
516                 $message = "$err" if !defined $message;
517                 if ($err->fatal) {
518                     $scan_method = $self->{'scan_conf'}->{'fatal'};
519                 } else {
520                     $scan_method = $self->{'scan_conf'}->{$err->{'reason'}};
521                 }
522             } else {
523                 die("error not defined");
524                 $scan_method = SCAN_ASK_POLL;
525             }
526         }
527
528         ## implement the desired scan method
529
530         if ($scan_method == SCAN_CONTINUE && !defined $continue_cb) {
531             $scan_method = $self->{'scan_conf'}->{'notfound'};
532             if ($scan_method == SCAN_CONTINUE) {
533                 $scan_method = SCAN_FAIL;
534             }
535         }
536
537         if ($scan_method == SCAN_ASK && !defined $self->{'interactivity'}) {
538             $scan_method = SCAN_FAIL;
539         }
540
541         if ($scan_method == SCAN_ASK_POLL && !defined $self->{'interactivity'}) {
542             $scan_method = SCAN_FAIL;
543         }
544
545         if ($scan_method == SCAN_ASK) {
546             return $steps->{'scan_interactivity'}->("$message");
547         } elsif ($scan_method == SCAN_POLL) {
548             $poll_src = Amanda::MainLoop::call_after(
549                                 $self->{'scan_conf'}->{'poll_delay'},
550                                 $steps->{'after_poll'});
551             return;
552         } elsif ($scan_method == SCAN_ASK_POLL) {
553             $steps->{'scan_interactivity'}->("$message\n");
554             $poll_src = Amanda::MainLoop::call_after(
555                                 $self->{'scan_conf'}->{'poll_delay'},
556                                 $steps->{'after_poll'});
557             return;
558         } elsif ($scan_method == SCAN_FAIL) {
559             return $steps->{'call_res_cb'}->($err, undef);
560         } elsif ($scan_method == SCAN_CONTINUE) {
561             return $continue_cb->($err, undef);
562         } else {
563             die("Invalid SCAN_* value:$err:$err->{'reason'}:$scan_method");
564         }
565     };
566
567     step after_poll => sub {
568         $poll_src->remove() if defined $poll_src;
569         $poll_src = undef;
570         return $steps->{'restart_scan'}->();
571     };
572
573     step scan_interactivity => sub {
574         my ($err_message) = @_;
575         if (!$interactivity_running) {
576             $interactivity_running = 1;
577             my $message = "$err_message\nInsert volume labeled '$label' in changer and type <enter>\nor type \"^D\" to abort\n";
578             $self->{'interactivity'}->user_request(
579                                 message     => $message,
580                                 label       => $label,
581                                 err         => "$err_message",
582                                 chg_name    => $self->{'chg'}->{'chg_name'},
583                                 request_cb  => $steps->{'scan_interactivity_cb'});
584         }
585         return;
586     };
587
588     step scan_interactivity_cb => sub {
589         my ($err, $message) = @_;
590         $interactivity_running = 0;
591         $poll_src->remove() if defined $poll_src;
592         $poll_src = undef;
593         $last_err = undef;
594
595         if ($err) {
596             if ($scan_running) {
597                 $abort_scan = $err;
598                 return;
599             } else {
600                 return $steps->{'call_res_cb'}->($err, undef);
601             }
602         }
603
604         if ($message ne '') {
605             # use a new changer
606             my $new_chg;
607             if (ref($message) eq 'HASH' and $message == $DEFAULT_CHANGER) {
608                 $new_chg = Amanda::Changer->new();
609             } else {
610                 $new_chg = Amanda::Changer->new($message);
611             }
612             if ($new_chg->isa("Amanda::Changer::Error")) {
613                 return $steps->{'scan_interactivity'}->("$new_chg");
614             }
615             $self->{'chg'}->quit();
616             $self->{'chg'} = $new_chg;
617             %seen = ();
618         } else {
619             $remove_undef_state = 1;
620         }
621
622         if ($scan_running) {
623             $restart_scan = 1;
624             return;
625         } else {
626             return $steps->{'restart_scan'}->();
627         }
628     };
629
630     step abort_scan => sub {
631         $steps->{'call_res_cb'}->($abort_scan, undef);
632     };
633
634     step call_res_cb => sub {
635         (my $err, $res) = @_;
636
637         # TODO: what happens if the search was aborted or
638         # restarted in the interim?
639
640         $abort_scan = undef;
641         $poll_src->remove() if defined $poll_src;
642         $poll_src = undef;
643         $interactivity_running = 0;
644         $self->{'interactivity'}->abort() if defined $self->{'interactivity'};
645         $params{'res_cb'}->($err, $res);
646     };
647 }
648
649 #
650 sub _find_volume_no_inventory {
651     my $self = shift;
652     my %params = @_;
653
654     my $label = $params{'label'};
655     my $res;
656     my %seen_slots = ();
657     my $inventory;
658     my $current;
659     my $new_slot;
660     my $last_slot;
661
662     my $steps = define_steps
663         cb_ref => \$params{'res_cb'};
664
665     step load_label => sub {
666         return $self->{'chg'}->load(relative_slot => "current",
667                                     res_cb => $steps->{'load_label_cb'});
668     };
669
670     step load_label_cb => sub {
671         (my $err, $res) = @_;
672
673         if ($err) {
674             if ($err->failed && $err->notfound) {
675                 if ($err->{'message'} eq "all slots have been loaded") {
676                     $err->{'message'} = "label '$label' not found";
677                 }
678                 return $params{'res_cb'}->($err, undef);
679             } elsif ($err->failed && $err->volinuse and defined $err->{'slot'}) {
680                 $last_slot = $err->{'slot'};
681             } else {
682                 #no interactivity yet.
683                 return $params{'res_cb'}->($err, undef);
684             }
685         } else {
686             $last_slot = $res->{'this_slot'}
687         }
688
689         $seen_slots{$last_slot} = 1 if defined $last_slot;
690         if ($res) {
691             my $dev = $res->{'device'};
692             if (defined $dev->volume_label && $dev->volume_label eq $label) {
693                 return $params{'res_cb'}->(undef, $res);
694             }
695             return $res->release(finished_cb => $steps->{'released'});
696         } else {
697             return $steps->{'released'}->()
698         }
699     };
700
701     step released => sub {
702         $self->{'chg'}->load(relative_slot => "next",
703                    except_slots => \%seen_slots,
704                    res_cb => $steps->{'load_label_cb'},
705                    set_current => 1);
706     };
707 }
708
709 sub _user_msg_fn {
710     my %params = @_;
711 }
712
713 package Amanda::Recovery::Scan::Config;
714
715 sub new {
716     my $class = shift;
717     my ($cc) = @_;
718
719     my $self = bless {}, $class;
720
721     $self->{'scan_drive'} = 0;
722     $self->{'scan_unknown_slot'} = 1;
723     $self->{'poll_delay'} = 10000; #10 seconds
724
725     $self->{'fatal'} = Amanda::Recovery::Scan::SCAN_CONTINUE;
726     $self->{'driveinuse'} = Amanda::Recovery::Scan::SCAN_ASK_POLL;
727     $self->{'volinuse'} = Amanda::Recovery::Scan::SCAN_ASK_POLL;
728     $self->{'notfound'} = Amanda::Recovery::Scan::SCAN_ASK_POLL;
729     $self->{'unknown'} = Amanda::Recovery::Scan::SCAN_FAIL;
730     $self->{'notimpl'} = Amanda::Recovery::Scan::SCAN_FAIL;
731     $self->{'invalid'} = Amanda::Recovery::Scan::SCAN_CONTINUE;
732
733     return $self;
734 }
735
736 1;