summaryrefslogtreecommitdiff
blob: b169c8ae6472019fd81a55fc6a6a7eeb8e388161 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
diff --git a/installcheck/Amanda_Rest_Storages.pl b/installcheck/Amanda_Rest_Storages.pl
index f3c699b..3e4e889 100644
--- a/installcheck/Amanda_Rest_Storages.pl
+++ b/installcheck/Amanda_Rest_Storages.pl
@@ -308,6 +308,7 @@ is_deeply (Installcheck::Rest::remove_source_line($reply),
 		'inventory' => [
 				 {'current' => 1,
 				  'label' => "DISKFLAT-001",
+				  'label_match' => '1',
 				  'device_status' => '0',
 				  'reserved' => 0,
 				  'f_type' => '1',
@@ -467,6 +468,7 @@ is_deeply (Installcheck::Rest::remove_source_line($reply),
 		'label' => 'DISKFLAT-001',
 		'datestamp' => '20140509113436',
 		'write_protected' => '',
+		'label_match' => '1',
 		'process' => 'Amanda::Rest::Storages',
 		'running_on' => 'amanda-server',
 		'component' => 'rest-server',
diff --git a/installcheck/amtape.pl b/installcheck/amtape.pl
index 1a3527f..700c5a2 100644
--- a/installcheck/amtape.pl
+++ b/installcheck/amtape.pl
@@ -177,13 +177,13 @@ like($Installcheck::Run::stderr,
 ok(run('amtape', 'TESTCONF', 'show'),
     "'amtape TESTCONF show'");
 like($Installcheck::Run::stderr,
-    qr/slot +2:.*label MyTape\nslot +3/,
+    qr/slot +2:.*label MyTape \(label do not match labelstr\)\nslot +3/,
     "'amtape TESTCONF show' ..result correct");
 
 ok(run('amtape', 'TESTCONF', 'show', '2'),
     "'amtape TESTCONF show'");
 like($Installcheck::Run::stderr,
-    qr/^slot +2:.*label MyTape$/,
+    qr/^slot +2:.*label MyTape \(label do not match labelstr\)$/,
     "'amtape TESTCONF show 2' ..result correct");
 
 ok(run('amtape', 'TESTCONF', 'show', '1,3'),
@@ -252,13 +252,13 @@ like(run_err('amtape', 'TESTCONF', 'update'),
 ok(run('amtape', 'TESTCONF', 'show'),
     "'amtape TESTCONF show'");
 like($Installcheck::Run::stderr,
-    qr/slot +2:.*label MyTape\nslot +3/,
+    qr/slot +2:.*label MyTape \(label do not match labelstr\)\nslot +3/,
     "..result correct");
 
 ok(run('amtape', 'TESTCONF', 'inventory'),
     "'amtape TESTCONF inventory'");
 like($Installcheck::Run::stdout,
-    qr/slot +1: blank\nslot +2: label MyTape \(current\)\nslot +3/,
+    qr/slot +1: blank\nslot +2: label MyTape \(current\) \(label do not match labelstr\)\nslot +3/,
     "..result correct");
 
 ok(run('amtape', 'TESTCONF', 'taper'),
diff --git a/perl/Amanda/Changer.pm b/perl/Amanda/Changer.pm
index 92ed9b6..4b4aad4 100644
--- a/perl/Amanda/Changer.pm
+++ b/perl/Amanda/Changer.pm
@@ -60,9 +60,10 @@ sub local_message {
     } elsif ($self->{'code'} == 1100014) {
 	return "$self->{'err'}";
     } elsif ($self->{'code'} == 1100015) {
-	return sprintf("slot %3s: date %-14s label %s%s", $self->{'slot'},
+	return sprintf("slot %3s: date %-14s label %s%s%s", $self->{'slot'},
 			$self->{'datestamp'}, $self->{'label'},
-			$self->{'write_protected'}?" (Write protected)":"");
+			$self->{'write_protected'}?" (Write protected)":"",
+			$self->{'label_match'}?"":" (label do not match labelstr)");
     } elsif ($self->{'code'} == 1100016) {
 	return sprintf("slot %3s: unlabeled volume%s", $self->{'slot'},
 			 $self->{'write_protected'}?" (Write protected)":"");
@@ -2014,6 +2015,13 @@ sub show {
 	    my $st = $dev->read_label();
 	    my $write_protected = !$dev->check_writable();
 	    if ($st == $DEVICE_STATUS_SUCCESS) {
+		my $label_match = match_labelstr(
+					$self->{'storage'}->{'labelstr'},
+					$self->{'storage'}->{'autolabel'},
+					$dev->volume_label(),
+					$res->{'barcode'},
+					$res->{'meta'},
+					$self->{'storage'}->{'storage_name'});
 		$params{'user_msg'}->(Amanda::Changer::Message->new(
 					source_filename => __FILE__,
 					source_line => __LINE__,
@@ -2022,7 +2030,8 @@ sub show {
 					slot   => $last_slot,
 					datestamp  => $dev->volume_time(),
 					label  => $dev->volume_label(),
-					write_protected => $write_protected));
+					write_protected => $write_protected,
+					label_match => $label_match));
 	    } elsif ($st == $DEVICE_STATUS_VOLUME_UNLABELED) {
 		$params{'user_msg'}->(Amanda::Changer::Message->new(
 					source_filename => __FILE__,
diff --git a/perl/Amanda/Rest/Storages.pm b/perl/Amanda/Rest/Storages.pm
index 680115b..b1b59d2 100644
--- a/perl/Amanda/Rest/Storages.pm
+++ b/perl/Amanda/Rest/Storages.pm
@@ -436,6 +436,17 @@ sub inventory {
 		    $inv->{'retention_type'} = $tl->get_retention_name($retention_type);
 		}
 	    }
+	    for my $inv (@$inventory) {
+		if ($inv->{label}) {
+		    $inv->{'label_match'} = Amanda::Util::match_labelstr(
+				$storage->{'labelstr'},
+				$storage->{'autolabel'},
+				$inv->{'label'},
+				$inv->{'barcode'},
+				$inv->{'metae'},
+				$storage->{'storage_name'});
+		}
+	    }
 	    push @result_messages, Amanda::Changer::Message->new(
 				source_filename => __FILE__,
 				source_line     => __LINE__,
diff --git a/server-src/amtape.pl b/server-src/amtape.pl
index b63607e..d06eefe 100644
--- a/server-src/amtape.pl
+++ b/server-src/amtape.pl
@@ -30,7 +30,7 @@ use Text::Wrap;
 use Amanda::Device qw( :constants );
 use Amanda::Debug qw( :logging );
 use Amanda::Config qw( :init :getconf config_dir_relative );
-use Amanda::Util qw( :constants );
+use Amanda::Util qw( :constants match_labelstr );
 use Amanda::Storage;
 use Amanda::Changer;
 use Amanda::Constants;
@@ -219,6 +219,7 @@ sub {
 	for my $sl (@$inv) {
 	    my $line = "slot $sl->{slot}:";
 	    my $tle;
+	    my $meta;
 	    if ($sl->{'state'} == Amanda::Changer::SLOT_EMPTY) {
 		$line .= " empty";
 	    } elsif (!defined($sl->{device_status}) && !defined($sl->{label})) {
@@ -230,6 +231,7 @@ sub {
 		    if (defined $tle) {
 			if ($tle->{'meta'}) {
 				$line .= " ($tle->{'meta'})";
+				$meta = $tle->{'meta'};
 			}
 		    }
 		} elsif ($sl->{'device_status'} == $DEVICE_STATUS_VOLUME_UNLABELED) {
@@ -263,6 +265,15 @@ sub {
 		    $line .= " [device error]";
 		}
 	    }
+	    if ($sl->{'label'}) {
+		if (!match_labelstr($storage->{'labelstr'},
+				    $storage->{'autolabel'},
+				    $sl->{label},
+				    $sl->{'barcode'}, $meta,
+				    $storage->{'storage_name'})) {
+		    $line .= " (label do not match labelstr)";
+		}
+	    }
 	    if (defined $tle) {
 		my $retention_type = Amanda::Tapelist::get_retention_type($tle->{pool}, $tle->{label});
 		$line .= " [" . $tl->get_retention_name($retention_type) . "]";