| 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 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Exporter (); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use AutoLoader qw(AUTOLOAD); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $AUTOLOAD); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 15 | 1 | $VERSION = do { my @r=(q$Revision: 1.3 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r }; | |||||||||||||||||||||||||||||||
| 16 | 1 | @ISA = qw(); | |||||||||||||||||||||||||||||||
| 17 | 1 | @EXPORT = qw(); | |||||||||||||||||||||||||||||||
| 18 | 1 | @EXPORT_OK = qw(); | |||||||||||||||||||||||||||||||
| 19 | 1 | %EXPORT_TAGS = qw(); | |||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||
| 22 | # | ||||||||||||||||||||||||||||||||
| 23 | # Disk storage unit paths are unique to a media manager only | ||||||||||||||||||||||||||||||||
| 24 | 1 | my %pathIndexPool; | |||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 27 | 0 | my $proto = shift; | |||||||||||||||||||||||||||||||
| 28 | 0 | my $path = {}; | |||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||
| 30 | 0 | bless $path, $proto; | |||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 33 | 0 | my $fp = shift; | |||||||||||||||||||||||||||||||
| 34 | 0 | $path->{FP} = $fp; | |||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||
| 36 | 0 | my $mmHost = shift; | |||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | if (!defined($mmHost)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub type { | ||||||||||||||||||||||||||||||
|
Subroutine
type: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 51 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||
| 53 | 0 | return 1; | |||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | sub byFP { | ||||||||||||||||||||||||||||||
|
Subroutine
byFP: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 57 | 0 | my $proto = shift; | |||||||||||||||||||||||||||||||
| 58 | 0 | my $fp = shift; | |||||||||||||||||||||||||||||||
| 59 | 0 | my $mmHost = shift; | |||||||||||||||||||||||||||||||
| 60 | 0 | my $path; | |||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | if (!defined($mmHost)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 63 | 0 | $mmHost = NBU::Host->new("localhost"); | |||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | if (defined($fp) && !($path = $pathIndexPool{$mmHost->name.":".$fp})) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $fp and not $path = $pathIndexPool{$mmHost->name . ':' . $fp}
MC/DC0%0/2
defined $fp and not $path = $pathIndexPool{$mmHost->name . ':' . $fp}
defined $fp
not $path = $pathIndexPool{$mmHost->name . ':' . $fp}
Truth table0%0/3
A and not(B)
A= defined $fpB= not $path = $pathIndexPool{$mmHost->name . ':' . $fp}
| |||||||||||||||||||||||||||||||||
| 67 | 0 | $path = NBU::Path->new($fp, $mmHost); | |||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||
| 69 | 0 | return $path; | |||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | sub pool { | ||||||||||||||||||||||||||||||
|
Subroutine
pool: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 73 | 0 | my $proto = shift; | |||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||
| 75 | 0 | return (values %pathIndexPool); | |||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | sub fp { | ||||||||||||||||||||||||||||||
|
Subroutine
fp: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 79 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||
| 81 | 0 | return $self->id(@_); | |||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | sub id { | ||||||||||||||||||||||||||||||
|
Subroutine
id: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 85 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 88 | 0 | my $fp = shift; | |||||||||||||||||||||||||||||||
| 89 | 0 | $self->{FP} = $fp; | |||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||
| 91 | 0 | my $mmHost = shift; | |||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | if (!defined($mmHost)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub host { | ||||||||||||||||||||||||||||||
|
Subroutine
host: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 102 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||
| 104 | 0 | return $self->{HOST}; | |||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | sub busy { | ||||||||||||||||||||||||||||||
|
Subroutine
busy: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 108 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||
| 110 | 0 | return $self->{INUSE}; | |||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | sub use { | ||||||||||||||||||||||||||||||
|
Subroutine
use: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 114 | 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 | 0 | ▶ | sub mount { | ||||||||||||||||||||||||||||||
|
Subroutine
mount: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 131 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||
| 133 | # | ||||||||||||||||||||||||||||||||
| 134 | # This should really return a list of *ALL* active mounts! | ||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | if ($self->busy) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub free { | ||||||||||||||||||||||||||||||
|
Subroutine
free: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 145 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 146 | 0 | my $tm = shift; | |||||||||||||||||||||||||||||||
| 147 | 0 | my $use = shift; | |||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | if (!$self->{INUSE}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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 | ▶ | if (!defined($use)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub lastUsed { | ||||||||||||||||||||||||||||||
|
Subroutine
lastUsed: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 172 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||
| 174 | 0 | my $uses = $self->usage; | |||||||||||||||||||||||||||||||
| 175 | 0 | ▶ | if (my $use = pop @$uses) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 176 | 0 | return $$use{'START'}; | |||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||
| 178 | else { | ||||||||||||||||||||||||||||||||
| 179 | 0 | return 0; | |||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | sub usage { | ||||||||||||||||||||||||||||||
|
Subroutine
usage: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 184 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | if (!$self->{USES}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 187 | 0 | $self->{USES} = []; | |||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||
| 190 | 0 | return $self->{USES}; | |||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||
| 193 | 0 | ▶ | sub busyStats { | ||||||||||||||||||||||||||||||
|
Subroutine
busyStats: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 194 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 195 | 0 | my $asOf = shift; | |||||||||||||||||||||||||||||||
| 196 | 0 | my $endOfPeriod = shift; | |||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||
| 198 | 0 | my $stepSize = 5 * 60; | |||||||||||||||||||||||||||||||
| 199 | 0 | ▶ | $stepSize = shift if (@_); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 211 | 0 | ▶ | if (!defined($use) || ($step < $$use{START})) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
not defined $use or $step < $use->{"START"}
MC/DC0%0/2
not defined $use or $step < $use->{"START"}
not defined $use
$step < $use->{"START"}
Truth table0%0/3
not(A) or B
A= not defined $useB= $step < $use->{"START"}
| |||||||||||||||||||||||||||||||||
| 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 | ▶ | if (defined($use) && defined($mount = $$use{MOUNT})) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $use and defined($mount = $use->{"MOUNT"})
MC/DC0%0/2
defined $use and defined($mount = $use->{"MOUNT"})
defined $use
defined($mount = $use->{"MOUNT"})
Truth table0%0/3
A and B
A= defined $useB= 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 | 1; | |||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||
| 235 | __END__ | ||||||||||||||||||||||||||||||||