line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# Copyright (c) 2004 Paul Winkeler. All Rights Reserved. |
3
|
|
|
|
|
|
|
# This program is free software; you may redistribute it and/or modify it under |
4
|
|
|
|
|
|
|
# the same terms as Perl itself. |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
package NBU::Path; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
45
|
|
9
|
1
|
|
|
1
|
|
7
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
78
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
BEGIN { |
12
|
1
|
|
|
1
|
|
7
|
use Exporter (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
13
|
1
|
|
|
1
|
|
7
|
use AutoLoader qw(AUTOLOAD); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
14
|
1
|
|
|
1
|
|
42
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $AUTOLOAD); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
241
|
|
15
|
1
|
|
|
1
|
|
1451
|
$VERSION = do { my @r=(q$Revision: 1.3 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r }; |
|
1
|
|
|
|
|
12
|
|
|
1
|
|
|
|
|
11
|
|
16
|
1
|
|
|
|
|
13
|
@ISA = qw(); |
17
|
1
|
|
|
|
|
3
|
@EXPORT = qw(); |
18
|
1
|
|
|
|
|
2
|
@EXPORT_OK = qw(); |
19
|
1
|
|
|
|
|
976
|
%EXPORT_TAGS = qw(); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# |
23
|
|
|
|
|
|
|
# Disk storage unit paths are unique to a media manager only |
24
|
|
|
|
|
|
|
my %pathIndexPool; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub new { |
27
|
0
|
|
|
0
|
0
|
|
my $proto = shift; |
28
|
0
|
|
|
|
|
|
my $path = {}; |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
bless $path, $proto; |
31
|
|
|
|
|
|
|
|
32
|
0
|
0
|
|
|
|
|
if (@_) { |
33
|
0
|
|
|
|
|
|
my $fp = shift; |
34
|
0
|
|
|
|
|
|
$path->{FP} = $fp; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
my $mmHost = shift; |
37
|
0
|
0
|
|
|
|
|
if (!defined($mmHost)) { |
38
|
0
|
|
|
|
|
|
$mmHost = NBU::Host->new("localhost"); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
$pathIndexPool{$mmHost->name.":".$fp} = $path; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
} |
44
|
0
|
|
|
|
|
|
$path->{INUSE} = 0; |
45
|
0
|
|
|
|
|
|
return $path; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# |
49
|
|
|
|
|
|
|
# Path objects return 1, just as Disk storage units do |
50
|
|
|
|
|
|
|
sub type { |
51
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
return 1; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub byFP { |
57
|
0
|
|
|
0
|
0
|
|
my $proto = shift; |
58
|
0
|
|
|
|
|
|
my $fp = shift; |
59
|
0
|
|
|
|
|
|
my $mmHost = shift; |
60
|
0
|
|
|
|
|
|
my $path; |
61
|
|
|
|
|
|
|
|
62
|
0
|
0
|
|
|
|
|
if (!defined($mmHost)) { |
63
|
0
|
|
|
|
|
|
$mmHost = NBU::Host->new("localhost"); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
0
|
0
|
0
|
|
|
|
if (defined($fp) && !($path = $pathIndexPool{$mmHost->name.":".$fp})) { |
67
|
0
|
|
|
|
|
|
$path = NBU::Path->new($fp, $mmHost); |
68
|
|
|
|
|
|
|
} |
69
|
0
|
|
|
|
|
|
return $path; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub pool { |
73
|
0
|
|
|
0
|
0
|
|
my $proto = shift; |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
return (values %pathIndexPool); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub fp { |
79
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
return $self->id(@_); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub id { |
85
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
86
|
|
|
|
|
|
|
|
87
|
0
|
0
|
|
|
|
|
if (@_) { |
88
|
0
|
|
|
|
|
|
my $fp = shift; |
89
|
0
|
|
|
|
|
|
$self->{FP} = $fp; |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
my $mmHost = shift; |
92
|
0
|
0
|
|
|
|
|
if (!defined($mmHost)) { |
93
|
0
|
|
|
|
|
|
$mmHost = NBU::Host->new("localhost"); |
94
|
|
|
|
|
|
|
} |
95
|
0
|
|
|
|
|
|
$pathIndexPool{$mmHost->name.":".$fp} = $self; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
return $self->{FP}; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub host { |
102
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
return $self->{HOST}; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub busy { |
108
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
109
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
return $self->{INUSE}; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub use { |
114
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
115
|
0
|
|
|
|
|
|
my ($mount, $tm) = @_; |
116
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
|
my $uses = $self->usage; |
118
|
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
|
my %use; |
120
|
0
|
|
|
|
|
|
$use{'MOUNT'} = $mount; |
121
|
0
|
|
|
|
|
|
$mount->usedBy(\%use); |
122
|
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
$self->{INUSE} += 1; |
124
|
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
$use{'START'} = $tm; |
126
|
0
|
|
|
|
|
|
push @$uses, \%use; |
127
|
0
|
|
|
|
|
|
return $self; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub mount { |
131
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
# |
134
|
|
|
|
|
|
|
# This should really return a list of *ALL* active mounts! |
135
|
0
|
0
|
|
|
|
|
if ($self->busy) { |
136
|
0
|
|
|
|
|
|
my $uses = $self->usage; |
137
|
0
|
|
|
|
|
|
my $use = $$uses[@$uses - 1]; |
138
|
0
|
|
|
|
|
|
return $$use{'MOUNT'}; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
0
|
|
|
|
|
|
return undef; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub free { |
145
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
146
|
0
|
|
|
|
|
|
my $tm = shift; |
147
|
0
|
|
|
|
|
|
my $use = shift; |
148
|
|
|
|
|
|
|
|
149
|
0
|
0
|
|
|
|
|
if (!$self->{INUSE}) { |
150
|
|
|
|
|
|
|
# it is quite common for a mount to inform the drive it is no |
151
|
|
|
|
|
|
|
# longer using the drive sometime after the drive has been put |
152
|
|
|
|
|
|
|
# to new use already. Hence ignore this event. |
153
|
|
|
|
|
|
|
# print "Drive ".$self->id." already free!\n"; |
154
|
|
|
|
|
|
|
# exit(0); |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
else { |
157
|
0
|
|
|
|
|
|
$self->{INUSE} -= 1; |
158
|
|
|
|
|
|
|
|
159
|
0
|
0
|
|
|
|
|
if (!defined($use)) { |
160
|
0
|
|
|
|
|
|
my $uses = $self->usage; |
161
|
0
|
|
|
|
|
|
$use = pop @$uses; |
162
|
0
|
|
|
|
|
|
push @$uses, $use; |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
0
|
|
|
|
|
|
$$use{'STOP'} = $tm; |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
0
|
|
|
|
|
|
return $self; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
sub lastUsed { |
172
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
173
|
|
|
|
|
|
|
|
174
|
0
|
|
|
|
|
|
my $uses = $self->usage; |
175
|
0
|
0
|
|
|
|
|
if (my $use = pop @$uses) { |
176
|
0
|
|
|
|
|
|
return $$use{'START'}; |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
else { |
179
|
0
|
|
|
|
|
|
return 0; |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
sub usage { |
184
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
185
|
|
|
|
|
|
|
|
186
|
0
|
0
|
|
|
|
|
if (!$self->{USES}) { |
187
|
0
|
|
|
|
|
|
$self->{USES} = []; |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
0
|
|
|
|
|
|
return $self->{USES}; |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
sub busyStats { |
194
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
195
|
0
|
|
|
|
|
|
my $asOf = shift; |
196
|
0
|
|
|
|
|
|
my $endOfPeriod = shift; |
197
|
|
|
|
|
|
|
|
198
|
0
|
|
|
|
|
|
my $stepSize = 5 * 60; |
199
|
0
|
0
|
|
|
|
|
$stepSize = shift if (@_); |
200
|
|
|
|
|
|
|
|
201
|
0
|
|
|
|
|
|
my $usage = $self->usage; |
202
|
|
|
|
|
|
|
|
203
|
0
|
|
|
|
|
|
my $step = $asOf; |
204
|
0
|
|
|
|
|
|
my $use = shift @$usage; |
205
|
0
|
|
|
|
|
|
my $mount = $$use{MOUNT}; |
206
|
0
|
|
|
|
|
|
my $job = $mount->job; |
207
|
0
|
|
|
|
|
|
my $du = 1; |
208
|
|
|
|
|
|
|
|
209
|
0
|
|
|
|
|
|
my @driveInUse; |
210
|
0
|
|
|
|
|
|
while ($step < $endOfPeriod) { |
211
|
0
|
0
|
0
|
|
|
|
if (!defined($use) || ($step < $$use{START})) { |
|
|
0
|
|
|
|
|
|
212
|
0
|
|
|
|
|
|
push @driveInUse, 0; |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
elsif ($step < $$use{STOP}) { |
215
|
0
|
|
|
|
|
|
push @driveInUse, $du; |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
else { |
218
|
0
|
|
|
|
|
|
$use = shift @$usage; |
219
|
0
|
0
|
0
|
|
|
|
if (defined($use) && defined($mount = $$use{MOUNT})) { |
220
|
0
|
|
|
|
|
|
$du = 1; |
221
|
|
|
|
|
|
|
} |
222
|
|
|
|
|
|
|
else { |
223
|
0
|
|
|
|
|
|
$du = 0; |
224
|
|
|
|
|
|
|
} |
225
|
0
|
|
|
|
|
|
next; |
226
|
|
|
|
|
|
|
} |
227
|
0
|
|
|
|
|
|
$step += $stepSize; |
228
|
|
|
|
|
|
|
} |
229
|
|
|
|
|
|
|
|
230
|
0
|
|
|
|
|
|
return ($asOf, $endOfPeriod, $stepSize, @driveInUse); |
231
|
|
|
|
|
|
|
} |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
1; |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
__END__ |