blib/lib/StorageDisplay/Collect.pm

filter: Statementstmt 80.4% 918 / 1141 Branchbran 64.9% 282 / 434 Conditioncond 45.3% 54 / 119 MC/DCmcdc 16.3% 10 / 61 Subroutinesub 81.4% 101 / 124 Podpod 10.0% 3 / 30 totaltotal 71.6% 1368 / 1909 CC 296 SCAR 31.9
CC
296
Cov
74%
__ANON__
182.0
__ANON__
72.0
collect
59.6
CRAP 24.4
« blib/lib/StorageDisplay/Data/Loop.pm ↑ Summary blib/lib/StorageDisplay/Data/FS.pm »
1 #
2 # This file is part of StorageDisplay
3 #
4 # This software is copyright (c) 2014-2023 by Vincent Danjean.
5 #
6 # This is free software; you can redistribute it and/or modify it under
7 # the same terms as the Perl 5 programming language system itself.
8 #
9 19 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 19 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # Implementation note: this file must contains all required modules
13 # required to collect data, but modules included in perl itself.
14 # This file can be sent to remote machine through SSH, this is why
15 # it must be self-contained.
16  
17 package StorageDisplay::Collect;
18 # ABSTRACT: modules required to collect data.
19 # No dependencies (but perl itself and its basic modules)
20  
21 19 our $VERSION = '2.06'; # VERSION
22  
23  
24 7 ▶sub collectors {
Subroutine collectors: called CC=1 SCAR=0.0
Pod undocumented
25 7 my $self = shift;
26 7 return @{$self->{_attr_collectors}};
27 }
28  
29 0 ▶sub collector {
Subroutine collector: not called CC=1 SCAR=6.9
Pod undocumented
30 0 my $self = shift;
31 0 my $name = shift;
32 0 return $self->{_attr_collectors_by_provide}->{$name};
33 }
34  
35 91 ▶sub registerCollector {
Subroutine registerCollector: called CC=4 SCAR=14.3
Pod undocumented
36 91 my $self = shift;
37 91 my $collector = shift;
38  
39 91 ▶ die "$collector not a StorageDisplay::Collect::Collector"
Branch: 1 branch
BranchTrueFalseTotal
unless $collector->isa("StorageDisplay::Collect::Collector") 0 91 91
40 if not $collector->isa("StorageDisplay::Collect::Collector");
41  
42 91 push @{$self->{_attr_collectors}}, $collector;
43 91 foreach my $cn ($collector->provides) {
44 112 ▶ if (exists($self->{_attr_collectors_by_provide}->{$cn})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"_attr_collectors_by_provide"}{$cn}) 0 112 112
45 die "$cn provided by both ".$collector->module." and ".
46 0 $self->{_attr_collectors_by_provide}->{$cn}->module;
47 }
48 112 $self->{_attr_collectors_by_provide}->{$cn} = $collector;
49 }
50 }
51  
52 86 ▶sub open_cmd_pipe {
Subroutine open_cmd_pipe: called CC=1 SCAR=0.0
Pod undocumented
53 86 my $self = shift;
54 86 return $self->cmdreader->open_cmd_pipe(@_);
55 }
56  
57 332 ▶sub open_cmd_pipe_root {
Subroutine open_cmd_pipe_root: called CC=1 SCAR=0.0
Pod undocumented
58 332 my $self = shift;
59 332 return $self->cmdreader->open_cmd_pipe_root(@_);
60 }
61  
62 26 ▶sub open_file {
Subroutine open_file: called CC=1 SCAR=0.0
Pod undocumented
63 26 my $self = shift;
64 26 return $self->cmdreader->open_file(@_);
65 }
66  
67 7 ▶sub has_file {
Subroutine has_file: called CC=1 SCAR=0.0
Pod undocumented
68 7 my $self = shift;
69 7 return $self->cmdreader->has_file(@_);
70 }
71  
72 465 ▶sub cmdreader {
Subroutine cmdreader: called CC=1 SCAR=0.0
Pod undocumented
73 465 my $self = shift;
74 465 return $self->{_attr_cmdreader};
75 }
76  
77 19 my @collectors;
78  
79 7 ▶sub new {
Subroutine new: called CC=4 SCAR=14.0
Pod undocumented
80 7 my $class = shift;
81 7 ▶ my $reader = shift // 'Local';
Condition50%1/2
shift() // "Local"
l!l
70
MC/DC0%0/1
shift() // "Local"
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
82  
83 7 ▶ if (ref($reader) eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $reader eq "") 7 0 7
84 7 my $fullreadername = 'StorageDisplay::Collect::CMD::'.$reader;
85 7 $reader = $fullreadername->new(@_);
86 }
87  
88 7 my $self = {
89 _attr_cmdreader => $reader,
90 _attr_collectors => [],
91 _attr_collectors_by_provide => {},
92 };
93  
94 7 bless $self, $class;
95  
96 7 foreach my $cdata (@collectors) {
97 91 my $cn = $cdata->{name};
98 91 $cn->new($cdata, $self);
99 }
100 7 return $self;
101 }
102  
103 247 ▶sub registerCollectorModule {
Subroutine registerCollectorModule: called CC=4 SCAR=13.9
Pod undocumented
104 247 my $class = shift;
105 247 my $collector = shift;
106  
107 #my $collector = caller 0;
108 #print STDERR "Registering $collector from ".(caller 0)."\n";
109 247 my $info = { name => $collector, @_ };
110 247 foreach my $entry (qw(provides requires)) {
111 494 ▶ next if not exists($info->{$entry});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $info->{$entry} 190 304 494
112 304 ▶ if (ref($info->{$entry}) eq "") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $info->{$entry} eq "") 190 114 304
113 190 $info->{$entry} = [ $info->{$entry} ];
114 }
115 }
116 247 push @collectors, $info;
117 }
118  
119 # Main collect function
120 #
121 # It will iterate on the collectors, respecting dependencies.
122 7 ▶sub collect {
Subroutine collect: called CC=2 SCAR=7.0
Pod undocumented
123 7 my $self = shift;
124 7 my $req = shift;
125 7 my $infos = {};
126  
127 7 $infos = $self->cmdreader->data_init($infos);
128  
129 # 0/undef : not computed
130 # 1 : computed
131 # 2 : computing
132 # 3 : N/A
133 7 my $collector_state = {};
134  
135 7 my $load;
136 91 ▶ $load = sub {
Subroutine __ANON__: called CC=13 SCAR=26.5
137 91 my $col = shift;
138 91 $collector_state->{$_} = 2 for $col->provides;
139 91 foreach my $cname ($col->requires) {
140 #print STDERR " preloading $cname\n";
141 56 my $state = $collector_state->{$cname};
142 56 ▶ if (not defined($state)) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $state) { } 0 56 56
elsif ($collector_state->{$cname} == 1) { } 56 0 56
143 0 my $collector = $self->collector($cname);
144 0 ▶ die "E: No $cname collector available for ".$col->module."\n"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $collector 0 0 0
145 if not defined($collector);
146 0 $load->($collector);
147 } elsif ($collector_state->{$cname} == 1) {
148 next
149 56 } else {
150 0 die "Loop in collectors requires ($cname required in $col->name)";
151 }
152 }
153 # are files present?
154 my @missing_files =
155 grep {
156 91 not $self->has_file($_);
157 } $col->depends('files');
158 91 ▶ if (scalar(@missing_files)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @missing_files) 2 89 91
159 2 print STDERR "I: skipping ", $col->module, " due to missing file(s): '",
160 join("', '", @missing_files), "'\n";
161 2 $collector_state->{$_} = 3 for $col->provides;
162 2 return;
163 }
164 89 ▶ my $opencmd = $col->depends('root') ?
Branch: 1 branch
BranchTrueFalseTotal
$col->depends('root') ? : 75 14 89
165 'open_cmd_pipe_root' : 'open_cmd_pipe';
166 # are programs present?
167 my @missing_progs =
168 grep {
169 89 my @cmd=('which', $_);
170 124 my $dh = $col->$opencmd(@cmd);
171 124 my $path = <$dh>;
172 124 close($dh);
173 124 not defined($path);
174 } $col->depends('progs');
175 89 ▶ if (scalar(@missing_progs)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @missing_progs) 15 74 89
176 15 print STDERR "I: skipping ", $col->module, " due to missing program(s): '",
177 join("', '", @missing_progs), "'\n";
178 15 $collector_state->{$_} = 3 for $col->provides;
179 15 return;
180 }
181 # collecting data while providing required data
182 my $collected_infos = $col->collect(
183 {
184 74 map { $_ => $infos->{$_} } $col->requires
185 }, $req);
186 # registering provided data
187 74 $infos->{$_} = $collected_infos->{$_} for $col->provides;
188 74 $collector_state->{$_} = 1 for $col->provides;
189 #print STDERR "loaded $cn\n";
190 7 };
191 # Be sure to collect all collectors
192 7 foreach my $col ($self->collectors) {
193 91 $load->($col);
194 }
195  
196 7 return $self->cmdreader->data_finish($infos);
197 }
198  
199 19 1;
200  
201 ###########################################################################
202 package StorageDisplay::Collect::JSON;
203  
204 19 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
205 # Mark current package as loaded;
206 # else, we cannot use 'use StorageDisplay::Collect::JSON;' latter
207 19 my $p = __PACKAGE__;
208 19 $p =~ s,::,/,g;
209 19 chomp(my $cwd = `pwd`);
210 19 $INC{$p.'.pm'} = $cwd.'/'.__FILE__;#k"current file";
211 }
212  
213 # This package contains
214 # - two public subroutines
215 # - `use_pp_parser` to know if JSON:PP makes all the work alone
216 # - `decode_json` to decode a json text with the $json_parser object
217 # - a public `new` class method that returns
218 # - a plain JSON::PP object (if boolean_values method exists)
219 # - a __PACKAGE__ object (if not) that inherit from JSON::PP
220 # - an overrided `decode` method that
221 # - calls SUPER::decode
222 # - manually transforms JSON:::PP::Boolean into plain scalar
223 # $json_parser is
224 # - either a JSON::PP object (if boolean_values method exists)
225 # - or a StorageDisplay::Collect::JSON that inherit of JSON::PP
226 # but override the decode method
227  
228 19 ▶use base 'JSON::PP';
Subroutine BEGIN: called CC=1 SCAR=0.0
229  
230 19 my $has_boolean_values;
231  
232 9 ▶sub new {
Subroutine new: called CC=3 SCAR=11.0
Pod documented
233 9 my $class = shift;
234 9 my $json_pp_parser;
235 9 ▶ if (!defined($has_boolean_values)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $has_boolean_values) 8 1 9
236 8 $json_pp_parser = JSON::PP->new;
237 8 $has_boolean_values = 0;
238 8 eval {
239 # workaround if not supported
240 8 $json_pp_parser->boolean_values(0, 1);
241 8 $has_boolean_values = 1;
242 };
243 }
244 9 my $parser;
245 9 ▶ if ($has_boolean_values) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_boolean_values) { } 9 0 9
246 9 $parser = JSON::PP->new(@_);
247 9 $parser->boolean_values(0, 1);
248 } else {
249 0 $parser = JSON::PP::new(__PACKAGE__, @_);
250 }
251 9 eval {
252 # ignore if not supported
253 9 $parser->allow_bignum;
254 };
255 9 return $parser;
256 }
257  
258 0 ▶sub decode {
Subroutine decode: not called CC=2 SCAR=17.9
Pod documented
259 0 my $self = shift;
260  
261 0 my $data = $self->SUPER::decode(@_);
262  
263 0 my %unrecognized;
264  
265 0 ▶ local *_convert_bools = sub {
Subroutine __ANON__: not called CC=13 SCAR=52.0
266 0 my $ref_type = ref($_[0]);
267 0 ▶ if (!$ref_type) {
Branch: 6 branches
BranchTrueFalseTotal
if (not $ref_type) { } 0 0 0
elsif ($ref_type eq 'HASH') { } 0 0 0
elsif ($ref_type eq 'ARRAY') { } 0 0 0
elsif ($ref_type eq 'JSON::PP::Boolean') { } 0 0 0
elsif ($ref_type eq 'Math::BigInt') { } 0 0 0
elsif ($ref_type eq 'Math::BigFloat') { } 0 0 0
268 # Nothing.
269 }
270 elsif ($ref_type eq 'HASH') {
271 0 _convert_bools($_) for values(%{ $_[0] });
272 }
273 elsif ($ref_type eq 'ARRAY') {
274 0 _convert_bools($_) for @{ $_[0] };
275 }
276 elsif ($ref_type eq 'JSON::PP::Boolean') {
277 0 ▶ $_[0] = $_[0] ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ? : 0 0 0
278 }
279 elsif ($ref_type eq 'Math::BigInt') {
280 0 ▶ if ($_[0]->beq($_[0]->numify())) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]->beq($_[0]->numify)) 0 0 0
281 # old versions of JSON::PP always use Math::Big*
282 # even if this is not required
283 0 $_[0] = $_[0]->numify();
284 }
285 }
286 elsif ($ref_type eq 'Math::BigFloat') {
287 0 ▶ if ($_[0]->is_int()
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]->is_int and $_[0]->beq($_[0]->numify)) 0 0 0
Condition0%0/3
$_[0]->is_int and $_[0]->beq($_[0]->numify)
!ll&&!rl&&r
000
MC/DC0%0/2
$_[0]->is_int and $_[0]->beq($_[0]->numify)
$_[0]->is_int $_[0]->beq($_[0]->numify)
Truth table0%0/3
A and B
A= $_[0]->is_intB= $_[0]->beq($_[0]->numify)
ABresult
0X0
100
111
288 && $_[0]->beq($_[0]->numify())) {
289 0 $_[0] = $_[0]->numify();
290 }
291 }
292 else {
293 0 ++$unrecognized{$ref_type};
294 }
295 0 };
296  
297 0 &_convert_bools($data);
298  
299 warn("Encountered an object of unrecognized type $_")
300 0 for sort values(%unrecognized);
301  
302 0 return $data;
303 }
304  
305 my $json_parser;
306  
307 68 ▶sub decode_json {
Subroutine decode_json: called CC=2 SCAR=6.9
Pod documented
308 68 ▶ if (not defined($json_parser)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $json_parser) 8 60 68
309 8 $json_parser = __PACKAGE__->new();
310 }
311  
312 68 $json_parser->decode(@_);
313 }
314  
315 2 ▶sub pp_parser_has_boolean_values {
Subroutine pp_parser_has_boolean_values: called CC=1 SCAR=0.0
Pod undocumented
316 2 return $has_boolean_values;
317 }
318  
319 25 ▶sub jsonarray2perlhash {
Subroutine jsonarray2perlhash: called CC=1 SCAR=0.0
Pod undocumented
320 25 my $json = shift;
321 25 my $root = shift;
322 25 my $key = shift;
323 my $info = {
324 326 map { $_->{$key} => $_ }
325 25 (@{decode_json($json)->{$root}})
326 };
327 25 return $info;
328 }
329  
330 19 1;
331  
332 ###########################################################################
333 package StorageDisplay::Collect::CMD;
334  
335 7 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
336 7 my $class = shift;
337 7 my $self = {};
338 7 bless $self, $class;
339 7 return $self;
340 }
341  
342 888 ▶sub cmd2str {
Subroutine cmd2str: called CC=2 SCAR=6.9
343 888 my $self = shift;
344 888 my @cmd = @_;
345 my $str = join(' ', map {
346 888 my $s = $_;
347 3676 $s =~ s/(['\\])/\\$1/g;
348 3676 ▶ if ($s !~ /^[0-9a-zA-Z_@,:\/=-]+$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($s =~ m[^[0-9a-zA-Z_\@,:/=-]+$]) 108 3568 3676
349 108 $s="'".$s."'";
350 }
351 3676 $s;
352 } @cmd);
353 888 return $str;
354 }
355  
356 7 ▶sub data_init {
Subroutine data_init: called CC=1 SCAR=0.0
357 7 my $self = shift;
358 7 my $data = shift;
359  
360 7 return $data;
361 }
362  
363 7 ▶sub data_finish {
Subroutine data_finish: called CC=1 SCAR=0.0
364 7 my $self = shift;
365 7 my $data = shift;
366  
367 7 return $data;
368 }
369  
370 26 ▶sub open_file {
Subroutine open_file: called CC=2 SCAR=10.9
371 26 my $self = shift;
372 26 my $filename = shift;
373  
374 26 return $self->open_cmd_pipe('cat', $filename);
375  
376 0 my $dh;
377 0 ▶ open($dh, '<', $filename) or die "Cannot open $filename: $!";
Branch: 1 branch
BranchTrueFalseTotal
open $dh, "<", $filename or die "Cannot open ${filename}: $!" 0 0 0
378 0 return $dh;
379 }
380  
381 0 ▶sub has_file {
Subroutine has_file: not called CC=1 SCAR=6.9
382 0 my $self = shift;
383 0 my $filename = shift;
384  
385 0 return -e $filename;
386 }
387  
388 19 1;
389  
390 ###########################################################################
391 package StorageDisplay::Collect::CMD::Local;
392  
393 19 ▶use parent -norequire => "StorageDisplay::Collect::CMD";
Subroutine BEGIN: called CC=1 SCAR=0.0
394  
395 0 ▶sub open_cmd_pipe {
Subroutine open_cmd_pipe: not called CC=2 SCAR=17.9
396 0 my $self = shift;
397 0 my @cmd = @_;
398 0 print STDERR "Running: ", $self->cmd2str(@cmd)."\n";
399 0 ▶ open(my $dh, '-|', @cmd) or
Branch: 1 branch
BranchTrueFalseTotal
open my $dh, "-|", @cmd or die 'Cannot run ' . $self->cmd2str(@cmd) . ": $!\n" 0 0 0
400 die "Cannot run ".$self->cmd2str(@cmd).": $!\n";
401 0 return $dh;
402 }
403  
404 0 ▶sub open_cmd_pipe_root {
Subroutine open_cmd_pipe_root: not called CC=2 SCAR=17.9
405 0 my $self = shift;
406 0 ▶ if ($> != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($> != 0) { } 0 0 0
407 0 return $self->open_cmd_pipe('sudo', @_);
408 } else {
409 0 return $self->open_cmd_pipe(@_);
410 }
411 }
412  
413 19 1;
414  
415 ###########################################################################
416 package StorageDisplay::Collect::CMD::LocalBySSH;
417  
418 19 ▶use parent -norequire => "StorageDisplay::Collect::CMD";
Subroutine BEGIN: called CC=1 SCAR=0.0
419  
420 0 ▶sub open_cmd_pipe {
Subroutine open_cmd_pipe: not called CC=2 SCAR=17.9
421 0 my $self = shift;
422 0 my @cmd = @_;
423 0 my $cmd = $self->cmd2str(@cmd);
424 0 $cmd =~ s/sudo password:\n/sudo password:/;
425 0 print STDERR "Running: $cmd\n";
426 0 ▶ open(my $dh, '-|', @cmd) or
Branch: 1 branch
BranchTrueFalseTotal
open my $dh, "-|", @cmd or die "Cannot run ${cmd}: $!\n" 0 0 0
427 die "Cannot run $cmd: $!\n";
428 0 return $dh;
429 }
430  
431 0 ▶sub open_cmd_pipe_root {
Subroutine open_cmd_pipe_root: not called CC=2 SCAR=17.9
432 0 my $self = shift;
433 0 ▶ if ($> != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($> != 0) { } 0 0 0
434 0 return $self->open_cmd_pipe(qw(sudo -S -p), 'sudo password:'."\n", '--', @_);
435 } else {
436 0 return $self->open_cmd_pipe(@_);
437 }
438 }
439  
440 19 1;
441  
442 ###########################################################################
443 package StorageDisplay::Collect::CMD::Proxy::Recorder;
444  
445 19 ▶use parent -norequire => "StorageDisplay::Collect::CMD";
Subroutine BEGIN: called CC=1 SCAR=0.0
446 19 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
447  
448 0 ▶sub new {
Subroutine new: not called CC=6 SCAR=37.4
449 0 my $class = shift;
450 0 my %args = ( @_ );
451 0 ▶ if (not exists($args{'recorder-reader'})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $args{"recorder-reader"}) 0 0 0
452 0 die 'recorder-reader argument required';
453 }
454 0 my $reader = $args{'recorder-reader'};
455 0 ▶ if (ref($reader) eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $reader eq "") 0 0 0
456 0 my $fullreadername = 'StorageDisplay::Collect::CMD::'.$reader;
457 0 ▶ $reader = $fullreadername->new(@_, %{$args{'recorder-args-pass'} // {}});
Condition0%0/2
$args{"recorder-args-pass"} // {}
l!l
00
MC/DC0%0/1
$args{"recorder-args-pass"} // {}
$args{"recorder-args-pass"}
Truth table0%0/2
A
A= $args{"recorder-args-pass"}
Aresult
11
00
458 }
459 0 ▶ die "Invalid reader" if not blessed($reader) or not $reader->isa("StorageDisplay::Collect::CMD");
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($reader) and $reader->isa("StorageDisplay::Collect::CMD") 0 0 0
Condition0%0/3
builtin::blessed($reader) and $reader->isa("StorageDisplay::Collect::CMD")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($reader) and $reader->isa("StorageDisplay::Collect::CMD")
builtin::blessed($reader) $reader->isa("StorageDisplay::Collect::CMD")
Truth table0%0/3
A and B
A= builtin::blessed($reader)B= $reader->isa("StorageDisplay::Collect::CMD")
ABresult
0X0
100
111
460 0 my $self = $class->SUPER::new(@_);
461 0 $self->{'_attr_reader'} = $reader;
462 0 return $self;
463 }
464  
465 0 ▶sub reader {
Subroutine reader: not called CC=1 SCAR=6.9
466 0 my $self = shift;
467 0 return $self->{_attr_reader};
468 }
469  
470 0 ▶sub data_finish {
Subroutine data_finish: not called CC=1 SCAR=6.9
471 0 my $self = shift;
472 0 my $infos = shift;
473 0 $infos = $self->SUPER::data_finish($infos);
474 0 $infos->{'recorder'} = $self->{_attr_records};
475 0 return $infos;
476 }
477  
478 0 ▶sub _record {
Subroutine _record: not called CC=2 SCAR=17.9
479 0 my $self = shift;
480 0 my $args = { @_ };
481 0 my $dh = $args->{'dh'};
482 0 delete($args->{'dh'});
483 0 my @infos = <$dh>;
484 0 @infos = map { chomp; $_ } @infos;
485 0 close($dh);
486 0 $args->{'stdout'} = \@infos;
487 0 push @{$self->{'_attr_records'}}, $args;
488 0 my $infos = join("\n", @infos);
489 0 ▶ if (scalar(@infos)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @infos) 0 0 0
490 0 $infos .= "\n";
491 }
492 0 open(my $fh, "<", \$infos);
493 0 return $fh;
494 }
495  
496 0 ▶sub open_cmd_pipe {
Subroutine open_cmd_pipe: not called CC=1 SCAR=6.9
497 0 my $self = shift;
498 0 return $self->_record(
499 'root' => 0,
500 'cmd' => [ @_ ],
501 'dh' => $self->reader->open_cmd_pipe(@_),
502 );
503 }
504  
505 0 ▶sub open_cmd_pipe_root {
Subroutine open_cmd_pipe_root: not called CC=1 SCAR=6.9
506 0 my $self = shift;
507 0 return $self->_record(
508 'root' => 1,
509 'cmd' => [ @_ ],
510 'dh' => $self->reader->open_cmd_pipe_root(@_),
511 );
512 }
513  
514 0 ▶sub has_file {
Subroutine has_file: not called CC=1 SCAR=6.9
515 0 my $self = shift;
516 0 my $filename = shift;
517 0 my $ret = $self->reader->has_file($filename);
518 0 push @{$self->{'_attr_records'}}, {
519 'filename' => $filename,
520 'value' => $ret,
521 };
522 0 return $ret;
523 }
524  
525 19 1;
526  
527 ###########################################################################
528 package is_collector;
529  
530 19 our $CALLER;
531  
532 247 ▶sub import {
Subroutine import: called CC=1 SCAR=0.0
533 247 my $class = shift;
534  
535 247 my $inheritor = caller(0);
536  
537 {
538 19 ▶ no strict 'refs'; ## no critic
Subroutine BEGIN: called CC=1 SCAR=0.0
539 247 push @{"$inheritor\::ISA"}, 'StorageDisplay::Collect::Collector'; # dies if a loop is detected
540 247 $CALLER = $inheritor;
541 247 StorageDisplay::Collect->registerCollectorModule($inheritor, @_);
542 };
543 };
544  
545 19 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
546 # Mark current package as loaded;
547 19 my $p = __PACKAGE__;
548 19 $p =~ s,::,/,g;
549 19 chomp(my $cwd = `pwd`);
550 19 $INC{$p.'.pm'} = $cwd.'/'.__FILE__;#k"current file";
551 }
552  
553 19 1;
554  
555 ###########################################################################
556 package StorageDisplay::Collect::Collector;
557  
558 19 ▶use Storable;
Subroutine BEGIN: called CC=1 SCAR=0.0
559  
560 86 ▶sub open_cmd_pipe {
Subroutine open_cmd_pipe: called CC=1 SCAR=0.0
Pod undocumented
561 86 my $self = shift;
562 86 return $self->proxy->open_cmd_pipe(@_);
563 }
564  
565 332 ▶sub open_cmd_pipe_root {
Subroutine open_cmd_pipe_root: called CC=1 SCAR=0.0
Pod undocumented
566 332 my $self = shift;
567 332 return $self->proxy->open_cmd_pipe_root(@_);
568 }
569  
570 26 ▶sub open_file {
Subroutine open_file: called CC=1 SCAR=0.0
Pod undocumented
571 26 my $self = shift;
572 26 return $self->proxy->open_file(@_);
573 }
574  
575 0 ▶sub has_file {
Subroutine has_file: not called CC=1 SCAR=6.9
Pod undocumented
576 0 my $self = shift;
577 0 return $self->proxy->has_file(@_);
578 }
579  
580 0 ▶sub collect {
Subroutine collect: not called CC=1 SCAR=6.9
Pod undocumented
581 0 my $self = shift;
582 0 print STDERR "collect must be implemented in $self\n";
583 }
584  
585 0 ▶sub names_avail {
Subroutine names_avail: not called CC=1 SCAR=6.9
Pod undocumented
586 0 my $self = shift;
587 0 print STDERR "names_avail must be implemented in $self\n";
588 }
589  
590 0 ▶sub import {
Subroutine import: not called CC=1 SCAR=6.9
591 0 print STDERR __PACKAGE__." imported from ".(caller 0)."\n";
592 }
593  
594 19 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
595 # Mark current package as loaded;
596 19 my $p = __PACKAGE__;
597 19 $p =~ s,::,/,g;
598 19 $INC{$p.'.pm'} = "current file";
599 }
600  
601 17 ▶sub module {
Subroutine module: called CC=1 SCAR=0.0
Pod undocumented
602 17 my $self = shift;
603 17 return $self->{_attr_module};
604 }
605  
606 165 ▶sub requires {
Subroutine requires: called CC=1 SCAR=0.0
Pod undocumented
607 165 my $self = shift;
608 165 return @{$self->{_attr_requires}};
609 }
610  
611 269 ▶sub depends {
Subroutine depends: called CC=3 SCAR=11.0
Pod undocumented
612 269 my $self = shift;
613 269 my $kind = shift;
614 return wantarray
615 180 ▶ ? @{$self->{_attr_depends}->{$kind} // []}
Condition100%2/2
$self->{"_attr_depends"}{$kind} // []
l!l
9684
MC/DC100%1/1
$self->{"_attr_depends"}{$kind} // []
$self->{"_attr_depends"}{$kind}
Truth table100%2/2
A
A= $self->{"_attr_depends"}{$kind}
Aresult
11
00
616 269 ▶ : $self->{_attr_depends}->{$kind};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 180 89 269
617 }
618  
619 347 ▶sub provides {
Subroutine provides: called CC=1 SCAR=0.0
Pod undocumented
620 347 my $self = shift;
621 347 return @{$self->{_attr_provides}};
622 }
623  
624 444 ▶sub proxy {
Subroutine proxy: called CC=1 SCAR=0.0
Pod undocumented
625 444 my $self = shift;
626 444 return $self->{_attr_collect};
627 }
628  
629 5 ▶sub select {
Subroutine select: called CC=2 SCAR=7.0
Pod undocumented
630 5 my $self = shift;
631 5 my $infos = shift;
632 5 ▶ my $request = shift // {};
Condition50%1/2
shift() // {}
l!l
05
MC/DC0%0/1
shift() // {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
633 5 return $self->names_avail;
634 }
635  
636 91 ▶sub new {
Subroutine new: called CC=4 SCAR=13.9
Pod undocumented
637 91 my $class = shift;
638 91 my $infos = shift;
639 91 my $collect = shift;
640  
641 91 my $self = {};
642 91 bless $self, $class;
643  
644 91 $self->{_attr_module} = $infos->{name};
645 91 $self->{_attr_collect} = $collect;
646 91 ▶ $self->{_attr_requires} = Storable::dclone($infos->{requires}//[]);
Condition100%2/2
$infos->{"requires"} // []
l!l
2170
MC/DC100%1/1
$infos->{"requires"} // []
$infos->{"requires"}
Truth table100%2/2
A
A= $infos->{"requires"}
Aresult
11
00
647 91 ▶ $self->{_attr_provides} = Storable::dclone($infos->{provides}//[]);
Condition50%1/2
$infos->{"provides"} // []
l!l
910
MC/DC0%0/1
$infos->{"provides"} // []
$infos->{"provides"}
Truth table50%1/2
A
A= $infos->{"provides"}
Aresult
11
00
648 91 ▶ $self->{_attr_depends} = Storable::dclone($infos->{depends}//{});
Condition50%1/2
$infos->{"depends"} // {}
l!l
910
MC/DC0%0/1
$infos->{"depends"} // {}
$infos->{"depends"}
Truth table50%1/2
A
A= $infos->{"depends"}
Aresult
11
00
649 91 $collect->registerCollector($self);
650  
651 91 return $self;
652 }
653  
654 19 1;
655  
656 ###########################################################################
657 ###########################################################################
658 ###########################################################################
659 ###########################################################################
660 package StorageDisplay::Collect::Host;
661  
662 use is_collector
663 19 ▶ provides => [ qw(hostname) ],
Subroutine BEGIN: called CC=1 SCAR=0.0
664 no_names => 1,
665 depends => {
666 progs => [ 'hostname', 'date' ],
667 19 };
668  
669 7 ▶sub collect {
Subroutine collect: called CC=1 SCAR=0.0
670 7 my $self = shift;
671 7 my $infos = {};
672 7 my $dh;
673  
674 7 $dh=$self->open_cmd_pipe(qw(hostname));
675 7 my $hostname = <$dh>;
676 7 close $dh;
677 7 chomp($hostname);
678 7 $dh=$self->open_cmd_pipe(qw(hostname --fqdn));
679 7 my $fqdn_hostname = <$dh>;
680 7 close $dh;
681 7 chomp($fqdn_hostname);
682 7 $dh=$self->open_cmd_pipe(qw(date --rfc-3339=s));
683 7 my $date = <$dh>;
684 7 close $dh;
685 7 chomp($date);
686 7 $dh=$self->open_cmd_pipe(qw(uname -a));
687 7 my $uname = <$dh>;
688 7 close $dh;
689 7 chomp($uname);
690  
691 return {
692 7 hostname => $hostname,
693 fqdn_hostname => $fqdn_hostname,
694 date => $date,
695 uname => $uname,
696 };
697 }
698  
699 19 1;
700  
701 ###########################################################################
702 package StorageDisplay::Collect::SystemBlocks;
703  
704 use is_collector
705 19 ▶ provides => [ qw(lsblk lsblk-hierarchy udev) ],
Subroutine BEGIN: called CC=1 SCAR=0.0
706 no_names => 1,
707 depends => {
708 progs => [ 'lsblk', 'udevadm' ],
709 19 };
710  
711 19 ▶use StorageDisplay::Collect::JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
712  
713 14 ▶sub lsblkjson2perl {
Subroutine lsblkjson2perl: called CC=2 SCAR=7.6
714 14 my $self = shift;
715 14 my $json = shift;
716 14 my $res;
717 14 eval {
718 14 $res = StorageDisplay::Collect::JSON::jsonarray2perlhash($json, 'blockdevices', 'kname');
719 };
720 14 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 14 14
721 # workaround a 2.37.2 util-linux bug
722 0 print STDERR "Oops, trying to workaround a 2.37.2 linux-util bug in lsblk\n";
723 0 $json =~ s/":, /":null, /g;
724 0 $res = StorageDisplay::Collect::JSON::jsonarray2perlhash($json, 'blockdevices', 'kname');
725 }
726 14 return $res;
727 }
728  
729 7 ▶sub collect {
Subroutine collect: called CC=13 SCAR=25.8
730 7 my $self = shift;
731 7 my $infos = {};
732 7 my $dh;
733 my $json;
734  
735 # Get all infos on system blocks
736 # 'lsblk-json-hierarchy' -> Str(json)
737 #my $dh=open_cmd_pipe(qw(lsblk --json --bytes --output-all));
738 7 $dh=$self->open_cmd_pipe(qw(lsblk --all --json --output), 'name,kname');
739 7 $json=join("\n", <$dh>);
740 7 close $dh;
741 7 $infos->{'lsblk-hierarchy'}=$self->lsblkjson2perl($json);
742  
743 # And keep json infos
744 # 'lsblk-json' -> kn -> Str(json)
745 7 $dh=$self->open_cmd_pipe(qw(lsblk --all --json --bytes --output-all --list));
746 7 $infos->{'lsblk'}=$self->lsblkjson2perl(join("\n", <$dh>));
747 7 close $dh;
748  
749 # Get all infos with udev
750 # 'udev' -> kn ->
751 # - 'path' -> Str(P:)
752 # - 'name' -> Str(N:)
753 # - 'names' -> [ N:, S:... ]
754 # - '_udev_infos' -> id -> Str(val)
755 7 $dh=$self->open_cmd_pipe(qw(udevadm info --query all --export-db));
756 7 my $data={'_udev_infos' => {}};
757 7 my $dname;
758 my $lastline;
759 7 ▶ while (defined(my $line=<$dh>)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $dh)) 98248 7 98255
760 98248 chomp($line);
761 98248 $lastline=$line;
762 98248 ▶ if ($line eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($line eq '') { } 11020 87228 98248
763 11020 ▶ if (defined($dname)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dname) { } 1535 9485 11020
764 1535 ▶ if (exists($data->{'names'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $data->{"names"}) 1535 0 1535
765 1535 my @sorted_names=sort @{$data->{'names'}};
766 1535 $data->{'names'}=\@sorted_names;
767 }
768 1535 $infos->{'udev'}->{$dname}=$data;
769 } else {
770 #print STDERR "No 'N:' tag in udev entry ".($data->[0]//"")."\n";
771 }
772 11020 $data={'_udev_infos' => {}};
773 11020 $dname=undef;
774 } else {
775 87228 ▶ if ($line =~ /^P: (.*)$/) {
Branch: 6 branches
BranchTrueFalseTotal
if ($line =~ /^P: (.*)$/) { } 11020 76208 87228
elsif ($line =~ /^N: (.*)$/) { } 1535 74673 76208
elsif ($line =~ /^S: (.*)$/) { } 1101 73572 74673
elsif ($line =~ /^E: (DEVLINKS)=(.*)$/) { } 284 73288 73572
elsif ($line =~ /^E: ([^=]*)=(.*)$/) { } 59305 13983 73288
elsif ($line =~ /^[MRUTDILQV]: .*$/) { } 13983 0 13983
776 11020 $data->{'path'}=$1;
777 } elsif ($line =~ /^N: (.*)$/) {
778 1535 $dname=$1;
779 1535 $data->{'name'}=$1;
780 1535 push @{$data->{'names'}}, $1;
781 } elsif ($line =~ /^S: (.*)$/) {
782 1101 push @{$data->{'names'}}, $1;
783 } elsif ($line =~ /^E: (DEVLINKS)=(.*)$/) {
784 284 $data->{'_udev_infos'}->{$1}=join(' ', sort(split(' ',$2)));
785 } elsif ($line =~ /^E: ([^=]*)=(.*)$/) {
786 59305 $data->{'_udev_infos'}->{$1}=$2;
787 } elsif ($line =~ /^[MRUTDILQV]: .*$/) {
788 # Unused info. See udevadm(8) / Table 1 for more info
789 } else {
790 0 ▶ print STDERR "Ignoring '$line'".(defined($dname)?(' for '.$dname):'')."\n";
Branch: 1 branch
BranchTrueFalseTotal
defined $dname ? : 0 0 0
791 }
792 }
793 }
794 7 close $dh;
795 7 ▶ if(defined($dname)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dname) 0 7 7
796 0 die "E: pb avec $dname ($lastline)", "\n";
797 }
798 7 return $infos;
799 }
800  
801 19 1;
802  
803 ###########################################################################
804 package StorageDisplay::Collect::DeviceMapper;
805  
806 use is_collector
807 19 ▶ provides => qw(dm),
Subroutine BEGIN: called CC=1 SCAR=0.0
808 depends => {
809 progs => [ 'dmsetup' ],
810 root => 1,
811 19 };
812  
813 7 ▶sub collect {
Subroutine collect: called CC=10 SCAR=23.1
814 7 my $self = shift;
815 7 my $dm={};
816 7 my $dh;
817  
818 # Get all infos with dmsetup
819 # 'dm' -> kn ->
820 # DM_NAME
821 # DM_BLKDEVNAME
822 # DM_BLKDEVS_USED
823 # DM_SUBSYSTEM
824 # DM_DEVS_USED
825 7 $dh=$self->open_cmd_pipe_root(qw(dmsetup info -c --nameprefix --noheadings -o),
826 'name,blkdevname,blkdevs_used,subsystem,devs_used',
827 '--separator', "\n ");
828 7 my $data={};
829 7 my $dname;
830 7 ▶ while (defined(my $line=<$dh>)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $dh)) 404 7 411
831 404 chomp($line);
832 404 ▶ next if $line eq 'No devices found';
Branch: 1 branch
BranchTrueFalseTotal
if $line eq "No devices found" 4 400 404
833 400 ▶ if ($line =~ /^DM_/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^DM_/) 80 320 400
834 80 ▶ if (defined($dname)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dname) { } 75 5 80
835 75 $dm->{$dname}=$data;
836 } else {
837 #print STDERR "No 'N:' tag in udev entry ".($data->[0]//"")."\n";
838 }
839 80 $data={};
840 80 $dname=undef;
841 }
842 400 ▶ if ($line =~ /^ ?(DM_[^=]*)='(.*)'$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^ ?(DM_[^=]*)='(.*)'$/) { } 400 0 400
843 400 ▶ if ($2 ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($2 ne "") 337 63 400
844 337 $data->{$1} = $2;
845 }
846 400 ▶ if ($1 eq 'DM_BLKDEVNAME') {
Branch: 1 branch
BranchTrueFalseTotal
if ($1 eq "DM_BLKDEVNAME") 80 320 400
847 80 $dname = $2;
848 }
849 } else {
850 0 ▶ print STDERR "Ignoring '$line'".(defined($dname)?(' for '.$dname):'')."\n";
Branch: 1 branch
BranchTrueFalseTotal
defined $dname ? : 0 0 0
851 }
852 }
853 7 ▶ if (defined($dname)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dname) 5 2 7
854 5 $dm->{$dname}=$data;
855 }
856 7 close $dh;
857 7 return { 'dm' => $dm };
858 }
859  
860 19 1;
861  
862 ###########################################################################
863 package StorageDisplay::Collect::Partitions;
864  
865 use is_collector
866 19 ▶ provides => [ qw(partitions disks-no-part)],
Subroutine BEGIN: called CC=1 SCAR=0.0
867 requires => [ qw(lsblk udev) ],
868 depends => {
869 progs => [ 'parted' ],
870 root => 1,
871 19 };
872  
873 7 ▶sub select {
Subroutine select: called CC=22 SCAR=34.3
874 7 my $self = shift;
875 7 my $infos = shift;
876 7 ▶ my $request = shift // {};
Condition50%1/2
shift() // {}
l!l
07
MC/DC0%0/1
shift() // {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
877 7 my @devs=();
878  
879 7 foreach my $kn (sort keys %{$infos->{'lsblk'}}) {
880 233 my $udev_info = $infos->{'udev'}->{$kn};
881 233 my $lsblk_info = $infos->{'lsblk'}->{$kn};
882 233 ▶ next if not defined($udev_info);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $udev_info 0 233 233
883 233 ▶ if (($udev_info->{'_udev_infos'}->{DEVTYPE} // '') ne 'disk') {
Branch: 1 branch
BranchTrueFalseTotal
if (($udev_info->{"_udev_infos"}{"DEVTYPE"} // "") ne "disk") 71 162 233
Condition50%1/2
$udev_info->{"_udev_infos"}{"DEVTYPE"} // ""
l!l
2330
MC/DC0%0/1
$udev_info->{"_udev_infos"}{"DEVTYPE"} // ""
$udev_info->{"_udev_infos"}{"DEVTYPE"}
Truth table50%1/2
A
A= $udev_info->{"_udev_infos"}{"DEVTYPE"}
Aresult
11
00
884 71 next;
885 }
886 162 ▶ if (($udev_info->{'_udev_infos'}->{ID_PART_TABLE_TYPE} // '') eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if (($udev_info->{"_udev_infos"}{"ID_PART_TABLE_TYPE"} // "") eq "") 112 50 162
Condition100%2/2
$udev_info->{"_udev_infos"}{"ID_PART_TABLE_TYPE"} // ""
l!l
50112
MC/DC100%1/1
$udev_info->{"_udev_infos"}{"ID_PART_TABLE_TYPE"} // ""
$udev_info->{"_udev_infos"}{"ID_PART_TABLE_TYPE"}
Truth table100%2/2
A
A= $udev_info->{"_udev_infos"}{"ID_PART_TABLE_TYPE"}
Aresult
11
00
887 112 ▶ if (($lsblk_info->{'rm'} // 0) == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (($lsblk_info->{"rm"} // 0) == 1) 4 108 112
Condition50%1/2
$lsblk_info->{"rm"} // 0
l!l
1120
MC/DC0%0/1
$lsblk_info->{"rm"} // 0
$lsblk_info->{"rm"}
Truth table50%1/2
A
A= $lsblk_info->{"rm"}
Aresult
11
00
888 # removed disk (cd, ...), skipping
889 4 next;
890 }
891 108 ▶ if (($lsblk_info->{'type'} // '') eq 'loop'
Branch: 1 branch
BranchTrueFalseTotal
if (($lsblk_info->{"type"} // "") eq "loop" and ($lsblk_info->{"size"} // 0) == 0) 47 61 108
Condition57%4/7
($lsblk_info->{"type"} // "") eq "loop" and ($lsblk_info->{"size"} // 0) == 0
!ll&&!rl&&r
61047
$lsblk_info->{"type"} // ""
l!l
1080
$lsblk_info->{"size"} // 0
l!l
470
MC/DC0%0/2
($lsblk_info->{"type"} // "") eq "loop" and ($lsblk_info->{"size"} // 0) == 0
$lsblk_info->{"type"} $lsblk_info->{"size"}
Truth table33%1/3
A and B
A= $lsblk_info->{"type"}B= $lsblk_info->{"size"}
ABresult
0X0
100
111
892 && ($lsblk_info->{'size'} // 0) == 0) {
893 # loop device not attached
894 47 next;
895 }
896 61 ▶ if (($lsblk_info->{'type'} // '') eq 'lvm') {
Branch: 1 branch
BranchTrueFalseTotal
if (($lsblk_info->{"type"} // "") eq "lvm") 45 16 61
Condition50%1/2
$lsblk_info->{"type"} // ""
l!l
610
MC/DC0%0/1
$lsblk_info->{"type"} // ""
$lsblk_info->{"type"}
Truth table50%1/2
A
A= $lsblk_info->{"type"}
Aresult
11
00
897 # handled by lvm subsystem
898 45 next;
899 }
900 # disk with no partition, just get it
901 16 push @devs, $kn;
902 16 next;
903 }
904 50 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (($udev_info->{"_udev_infos"}{"ID_PART_TABLE_TYPE"} // "") eq "dos" and ($udev_info->{"_udev_infos"}{"ID_PART_ENTRY_NUMBER"} // "") ne "" and ($udev_info->{"_udev_infos"}{"DM_TYPE"} // "") eq "raid") 0 50 50
Condition41%5/12
($udev_info->{"_udev_infos"}{"ID_PART_TABLE_TYPE"} // "") eq "dos" and ($udev_info->{"_udev_infos"}{"ID_PART_ENTRY_NUMBER"} // "") ne "" and ($udev_info->{"_udev_infos"}{"DM_TYPE"} // "") eq "raid"
!ll&&!rl&&r
5000
($udev_info->{"_udev_infos"}{"ID_PART_TABLE_TYPE"} // "") eq "dos" and ($udev_info->{"_udev_infos"}{"ID_PART_ENTRY_NUMBER"} // "") ne ""
!ll&&!rl&&r
4370
$udev_info->{"_udev_infos"}{"ID_PART_TABLE_TYPE"} // ""
l!l
500
$udev_info->{"_udev_infos"}{"ID_PART_ENTRY_NUMBER"} // ""
l!l
07
$udev_info->{"_udev_infos"}{"DM_TYPE"} // ""
l!l
00
MC/DC0%0/3
($udev_info->{"_udev_infos"}{"ID_PART_TABLE_TYPE"} // "") eq "dos" and ($udev_info->{"_udev_infos"}{"ID_PART_ENTRY_NUMBER"} // "") ne "" and ($udev_info->{"_udev_infos"}{"DM_TYPE"} // "") eq "raid"
$udev_info->{"_udev_infos"}{"ID_PART_TABLE_TYPE"} $udev_info->{"_udev_infos"}{"ID_PART_ENTRY_NUMBER"} $udev_info->{"_udev_infos"}{"DM_TYPE"}
Truth table25%1/4
A and B and C
A= $udev_info->{"_udev_infos"}{"ID_PART_TABLE_TYPE"}B= $udev_info->{"_udev_infos"}{"ID_PART_ENTRY_NUMBER"}C= $udev_info->{"_udev_infos"}{"DM_TYPE"}
ABCresult
0XX0
10X0
1100
1111
905 ($udev_info->{'_udev_infos'}->{ID_PART_TABLE_TYPE} // '') eq 'dos'
906 && ($udev_info->{'_udev_infos'}->{ID_PART_ENTRY_NUMBER} // '') ne ''
907 && ($udev_info->{'_udev_infos'}->{DM_TYPE} // '') eq 'raid'
908 ) {
909 0 print STDERR "I: $kn seems to be a dm-mapped extended dos partition. Skipping it as disk\n";
910 #$partitions->{$kn}->{"dos-extended"}=1;
911 0 next;
912 }
913 50 push @devs, $kn;
914 }
915 7 return @devs;
916 }
917  
918 7 ▶sub collect {
Subroutine collect: called CC=20 SCAR=31.6
919 7 my $self = shift;
920 7 my $infos = shift;
921 7 my $partitions;
922 my $noparts;
923 7 my $dh;
924  
925 7 my @devs=$self->select($infos);
926  
927 7 foreach my $kn (@devs) {
928 66 my $udev_info = $infos->{'udev'}->{$kn};
929 66 ▶ if (($udev_info->{'_udev_infos'}->{ID_PART_TABLE_TYPE} // '') eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if (($udev_info->{"_udev_infos"}{"ID_PART_TABLE_TYPE"} // "") eq "") 16 50 66
Condition100%2/2
$udev_info->{"_udev_infos"}{"ID_PART_TABLE_TYPE"} // ""
l!l
5016
MC/DC100%1/1
$udev_info->{"_udev_infos"}{"ID_PART_TABLE_TYPE"} // ""
$udev_info->{"_udev_infos"}{"ID_PART_TABLE_TYPE"}
Truth table100%2/2
A
A= $udev_info->{"_udev_infos"}{"ID_PART_TABLE_TYPE"}
Aresult
11
00
930 16 $noparts->{$kn}={'no partitions' => 1};
931 16 next;
932 }
933 50 $dh=$self->open_cmd_pipe_root(qw(parted -m -s), "/dev/".$kn, qw(unit B print free));
934 50 my $state=0;
935 50 my $parted={ 'parts' => [] };
936 50 my $startline = '';
937 50 ▶ while(defined(my $line=<$dh>)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $dh)) 357 50 407
938 357 chomp($line);
939 357 my $multiline = 0;
940 357 ▶ if ($startline ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($startline ne "") 0 357 357
941 0 $line = $startline . $line;
942 0 $multiline = 1;
943 }
944 357 ▶ if ($line !~ /;$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($line =~ /;$/) 0 357 357
945 0 $startline = $line;
946 0 next;
947 }
948 357 $startline = '';
949 357 ▶ if ($state == 0) {
Branch: 3 branches
BranchTrueFalseTotal
if ($state == 0) { } 50 307 357
elsif ($state == 1) { } 50 257 307
elsif ($state == 2) { } 257 0 257
950 50 ▶ if ($line eq "BYT;") {
Branch: 1 branch
BranchTrueFalseTotal
if ($line eq "BYT;") 50 0 50
951 50 $state = 1;
952 50 next;
953 }
954 } elsif ($state == 1) {
955 50 ▶ if ($line =~ /.*:([0-9]+)B:[^:]*:[0-9]+:[0-9]+:([^:]*):(.*):;/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /.*:([0-9]+)B:[^:]*:[0-9]+:[0-9]+:([^:]*):(.*):;/) 50 0 50
956 50 $parted->{size} = $1;
957 50 $parted->{type} = $2;
958 50 $parted->{label} = $3;
959 50 $state = 2;
960 50 next;
961 }
962 } elsif ($state == 2) {
963 257 ▶ if ($line =~ m/^1:([0-9]+)B:[0-9]+B:([0-9]+)B:free;$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($line =~ /^1:([0-9]+)B:[0-9]+B:([0-9]+)B:free;$/) { } 109 148 257
elsif ($line =~ /^([0-9]+):([0-9]+)B:[0-9]+B:([0-9]+)B:[^:]*:(.*):([^:]*);$/) { } 148 0 148
964 109 push @{$parted->{parts}}, {
965 'kind' => 'free',
966 'start' => $1,
967 'size' => $2,
968 };
969 109 next;
970 } elsif ($line =~ m/^([0-9]+):([0-9]+)B:[0-9]+B:([0-9]+)B:[^:]*:(.*):([^:]*);$/) {
971 148 push @{$parted->{parts}}, {
972 'kind' => 'part',
973 'id' => $1,
974 'start' => $2,
975 'size' => $3,
976 'label' => $4,
977 'flags' => $5,
978 };
979 148 ▶ if ($multiline) {
Branch: 1 branch
BranchTrueFalseTotal
if ($multiline) 0 148 148
980 0 my $label = $4;
981 0 ▶ if ($label =~ /^Project-Id.*Content-Transfer-Encoding: 8bit$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($label =~ /^Project-Id.*Content-Transfer-Encoding: 8bit$/) 0 0 0
982 # workaround a parted bug with xfs partitions (at least)
983 0 $parted->{parts}->[-1]->{'label'}='';
984 }
985 }
986 148 next;
987 }
988 }
989 0 print STDERR "W: parted on $kn: Unknown line '$line'\n";
990 }
991 50 close($dh);
992 50 ▶ if ($state != 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($state != 2) 0 50 50
993 0 print STDERR "W: parted on $kn: invalid data (skipping device)\n";
994 0 next;
995 }
996 50 ▶ if ($udev_info->{'_udev_infos'}->{ID_PART_TABLE_TYPE} eq 'dos') {
Branch: 1 branch
BranchTrueFalseTotal
if ($udev_info->{"_udev_infos"}{"ID_PART_TABLE_TYPE"} eq "dos") 7 43 50
997 7 $dh=$self->open_cmd_pipe_root(qw(parted -s), "/dev/".$kn, qw(print));
998 7 $state=0;
999 7 ▶ while(defined(my $line=<$dh>)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $dh)) 68 5 73
1000 68 chomp($line);
1001 68 ▶ if ($line =~ /^\s([1234]) .* extended( .*)?$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s([1234]) .* extended( .*)?$/) 2 66 68
1002 2 $parted->{extended} = $1;
1003 2 last;
1004 }
1005 }
1006 }
1007 50 $partitions->{$kn}=$parted;
1008 }
1009 return {
1010 7 'partitions' => $partitions,
1011 'disks-no-part' => $noparts,
1012 };
1013 }
1014  
1015 19 1;
1016  
1017 ###########################################################################
1018 package StorageDisplay::Collect::LVM;
1019  
1020 use is_collector
1021 19 ▶ provides => 'lvm',
Subroutine BEGIN: called CC=1 SCAR=0.0
1022 depends => {
1023 progs => [ 'lvm' ],
1024 root => 1,
1025 19 };
1026  
1027 19 ▶use StorageDisplay::Collect::JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
1028  
1029 35 ▶sub lvmjson2perl {
Subroutine lvmjson2perl: called CC=9 SCAR=22.5
1030 35 my $self = shift;
1031 35 my $kind = shift;
1032 35 my $kstore = shift;
1033 35 my $uniq = shift;
1034 35 my $keys = shift;
1035 35 ▶ my $info = shift // {};
Condition50%1/2
shift() // {}
l!l
350
MC/DC0%0/1
shift() // {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
1036 35 my $json = shift;
1037 my $alldata = StorageDisplay::Collect::JSON::decode_json($json)
1038 35 ->{'report'}->[0]->{$kind};
1039 35 foreach my $data (@$alldata) {
1040 296 ▶ my $vg=$data->{vg_name} // die "no vg_name in data!";
Condition50%1/2
$data->{"vg_name"} // die("no vg_name in data!")
l!l
2960
MC/DC0%0/1
$data->{"vg_name"} // die("no vg_name in data!")
$data->{"vg_name"}
Truth table50%1/2
A
A= $data->{"vg_name"}
Aresult
11
00
1041 296 my $base = $info->{$vg}->{$kstore};
1042 296 my $hashs = [ [$info->{$vg}, $kstore] ];
1043 296 ▶ if (scalar(@$keys) == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @$keys == 1) { } 96 200 296
elsif (scalar @$keys > 1) { } 0 200 200
1044 # force creation of $info->{$vg}->{$kstore} hash if needed
1045 96 my $dummy=$info->{$vg}->{$kstore}->{$data->{$keys->[0]}};
1046 $hashs = [ [ $info->{$vg}->{$kstore},
1047 96 $data->{$keys->[0]} ] ];
1048 } elsif (scalar(@$keys) > 1) {
1049 $hashs = [
1050 map {
1051 # force creation of $info->{$vg}->{$kstore}->{$_} hash if needed
1052 0 my $dummy=$info->{$vg}->{$kstore}->{$_}->{$data->{$_}};
1053 [ $info->{$vg}->{$kstore}->{$_},
1054 0 $data->{$_} ]
1055 } @$keys
1056 ];
1057 }
1058 296 foreach my $i (@$hashs) {
1059 296 my ($h, $k) = @$i;
1060 296 ▶ if ($uniq) {
Branch: 1 branch
BranchTrueFalseTotal
if ($uniq) { } 105 191 296
1061 105 ▶ die "duplicate info" if defined($h->{$k});
Branch: 1 branch
BranchTrueFalseTotal
if defined $h->{$k} 0 105 105
1062 105 $h->{$k} = $data;
1063 } else {
1064 191 push @{$h->{$k}}, $data;
1065 }
1066 }
1067 }
1068 35 return $info;
1069 }
1070  
1071 7 ▶sub collect {
Subroutine collect: called CC=1 SCAR=0.0
1072 7 my $self = shift;
1073 7 my $dh;
1074 7 my $lvm = {};
1075  
1076 # Get all infos on LVM
1077 # 'lvm' -> 'pv'| -> Str(json)
1078 7 $dh=$self->open_cmd_pipe_root(
1079 qw(lvm pvs --units B --reportformat json --all -o),
1080 'pv_name,pv_size,pv_free,pv_used,seg_size,seg_start,segtype,pvseg_start,pvseg_size,lv_name,lv_role,vg_name',
1081 '--select', 'pv_size > 0 || vg_name != ""');
1082 7 $self->lvmjson2perl('pv', 'pvs', 0, [], $lvm, join("\n", <$dh>));
1083 7 close $dh;
1084  
1085 7 $dh=$self->open_cmd_pipe_root(
1086 qw(lvm lvs --units B --reportformat json --all -o),
1087 'lv_name,seg_size,segtype,seg_start,seg_pe_ranges,seg_le_ranges,vgname,devices,pool_lv,lv_parent');
1088 7 $self->lvmjson2perl('lv', 'lvs', 0, [], $lvm, join("\n", <$dh>));
1089 7 close $dh;
1090  
1091 7 $dh=$self->open_cmd_pipe_root(
1092 qw(lvm vgs --units B --reportformat json --all -o),
1093 'vg_name,vg_size,vg_free');
1094 7 $self->lvmjson2perl('vg', 'vgs-vg', 1, [], $lvm, join("\n", <$dh>));
1095 7 close $dh;
1096  
1097 7 $dh=$self->open_cmd_pipe_root(
1098 qw(lvm vgs --units B --reportformat json --all -o),
1099 'vg_name,pv_name,pv_size,pv_free,pv_used');
1100 7 $self->lvmjson2perl('vg', 'vgs-pv', 1, ['pv_name'], $lvm, join("\n", <$dh>));
1101 7 close $dh;
1102  
1103 7 $dh=$self->open_cmd_pipe_root(
1104 qw(lvm vgs --units B --reportformat json --all -o),
1105 'vg_name,lv_name,lv_size,data_percent,origin,pool_lv,lv_role');
1106 7 $self->lvmjson2perl('vg', 'vgs-lv', 1, ['lv_name'], $lvm, join("\n", <$dh>));
1107 7 close $dh;
1108  
1109 7 return {'lvm' => $lvm };
1110 }
1111  
1112 19 1;
1113  
1114 ###########################################################################
1115 package StorageDisplay::Collect::FS;
1116  
1117 use is_collector
1118 19 ▶ provides => 'fs',
Subroutine BEGIN: called CC=1 SCAR=0.0
1119 no_names => 1,
1120 depends => {
1121 progs => [ '/sbin/swapon', 'findmnt', 'stat' ],
1122 root => 1,
1123 19 };
1124  
1125 19 ▶use StorageDisplay::Collect::JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
1126  
1127 7 ▶sub collect {
Subroutine collect: called CC=7 SCAR=21.5
1128 7 my $self = shift;
1129 7 my $dh;
1130  
1131 # Swap and mounted FS
1132 7 $dh=$self->open_cmd_pipe(qw(/sbin/swapon --noheadings --raw --bytes),
1133 '--show=NAME,TYPE,SIZE,USED');
1134 7 my $fs={};
1135 7 ▶ while(defined(my $line=<$dh>)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $dh)) 5 7 12
1136 5 chomp($line);
1137 5 ▶ if ($line =~ m,([^ ]+) (partition|file) ([0-9]+) ([0-9]+)$,) {
Branch: 2 branches
BranchTrueFalseTotal
if ($line =~ /([^ ]+) (partition|file) ([0-9]+) ([0-9]+)$/) { } 5 0 5
elsif ($line =~ /([^ ]+) ([^ ]+) ([0-9]+) ([0-9]+)$/) { } 0 0 0
1138 5 my $info={
1139 filesystem => $1,
1140 size => $3,
1141 used => $4,
1142 free => ''.($3-$4),
1143 fstype => $2,
1144 mountpoint => 'SWAP',
1145 };
1146 5 my $dev = $1;
1147 5 ▶ if ($2 eq 'file') {
Branch: 1 branch
BranchTrueFalseTotal
if ($2 eq "file") 0 5 5
1148 0 my $dh2=$self->open_cmd_pipe_root(qw(findmnt -n -o TARGET --target), $1);
1149 0 my $mountpoint = <$dh2>;
1150 0 ▶ chomp($mountpoint) if defined($mountpoint);
Branch: 1 branch
BranchTrueFalseTotal
if defined $mountpoint 0 0 0
1151 0 close $dh2;
1152 0 $info->{'file-mountpoint'}=$mountpoint;
1153 0 $dh2=$self->open_cmd_pipe_root(qw(stat -c %s), $1);
1154 0 my $size = <$dh2>;
1155 0 chomp($size);
1156 0 close $dh2;
1157 0 $info->{'file-size'}=$size;
1158 }
1159 5 $fs->{swap}->{$dev} = $info;
1160 } elsif ($line =~ m,([^ ]+) ([^ ]+) ([0-9]+) ([0-9]+)$,) {
1161 # skipping other kind of swap
1162 } else {
1163 0 print STDERR "W: swapon: Unknown line '$line'\n";
1164 }
1165 }
1166 7 close $dh;
1167  
1168 #$dh=$self->open_cmd_pipe_root(qw(findmnt --all --output-all --json --bytes --list));
1169 #my @json=<$dh>;
1170 #close $dh;
1171 #$fs->{flatfull} = StorageDisplay::Collect::JSON::jsonarray2perlhash(join("",@json), 'filesystems', 'id');
1172  
1173 7 my $data;
1174 7 eval {
1175 7 $dh=$self->open_cmd_pipe_root(qw(findmnt --all --output-all --json --bytes));
1176 7 my @json=<$dh>;
1177 7 close $dh;
1178 7 $data = StorageDisplay::Collect::JSON::decode_json(join("",@json))->{"filesystems"}->[0];
1179 };
1180 7 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 7 7
1181 # workaround a 2.37.2 linux-util bug
1182 0 print STDERR "Oops, trying to workaround a 2.37.2 linux-util bug in findmnt\n";
1183 0 $dh=$self->open_cmd_pipe_root(qw(findmnt --all --json --bytes --output),
1184 "AVAIL,FREQ,FSROOT,FSTYPE,FS-OPTIONS,ID,LABEL,MAJ:MIN,OPTIONS,"
1185 ."OPT-FIELDS,PARENT,PARTLABEL,PARTUUID,PASSNO,PROPAGATION,SIZE,SOURCE,TARGET,"
1186 ."TID,USED,USE%,UUID,VFS-OPTIONS");
1187 0 my @json=<$dh>;
1188 0 close $dh;
1189 0 $data = StorageDisplay::Collect::JSON::decode_json(join("",@json))->{"filesystems"}->[0];
1190 }
1191  
1192 7 my $rec;
1193 272 ▶ $rec = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
1194 272 my $node = shift;
1195 my $res = {
1196 id => $node->{id},
1197 target => $node->{target},
1198 272 };
1199 272 ▶ if (exists($node->{children})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $node->{"children"}) 62 210 272
1200 62 $res->{children} = [ map { $rec->($_) } @{$node->{children}} ];
1201 }
1202 272 return $res;
1203 7 };
1204 7 $fs->{hierarchy} = $rec->($data);
1205  
1206 272 ▶ $rec = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
1207 272 my $node = shift;
1208 272 my $id = $node->{id};
1209 272 $fs->{flatfull}->{$id} = $node;
1210 272 ▶ if (exists($node->{children})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $node->{"children"}) 62 210 272
1211 62 for my $child (@{$node->{children}}) {
1212 265 $rec->($child);
1213 }
1214 62 delete $node->{children};
1215 }
1216 7 };
1217 7 $rec->($data);
1218  
1219 7 return { 'fs' => $fs };
1220 }
1221  
1222 19 1;
1223  
1224 ###########################################################################
1225 package StorageDisplay::Collect::LUKS;
1226  
1227 use is_collector
1228 19 ▶ provides => 'luks',
Subroutine BEGIN: called CC=1 SCAR=0.0
1229 requires => [ qw(dm lsblk udev) ],
1230 depends => {
1231 progs => [ 'cryptsetup' ],
1232 root => 1,
1233 19 };
1234  
1235 5 ▶sub select {
Subroutine select: called CC=6 SCAR=18.0
1236 5 my $self = shift;
1237 5 my $infos = shift;
1238 5 ▶ my $request = shift // {};
Condition50%1/2
shift() // {}
l!l
05
MC/DC0%0/1
shift() // {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
1239 5 my @devs=();
1240  
1241 5 my $dh;
1242 5 foreach my $kn (sort keys %{$infos->{'lsblk'}}) {
1243 202 my $udev_info = $infos->{'udev'}->{$kn};
1244 202 ▶ next if not defined($udev_info);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $udev_info 0 202 202
1245 202 ▶ if (($udev_info->{'_udev_infos'}->{ID_FS_TYPE} // '') ne 'crypto_LUKS') {
Branch: 1 branch
BranchTrueFalseTotal
if (($udev_info->{"_udev_infos"}{"ID_FS_TYPE"} // "") ne "crypto_LUKS") 197 5 202
Condition100%2/2
$udev_info->{"_udev_infos"}{"ID_FS_TYPE"} // ""
l!l
89113
MC/DC100%1/1
$udev_info->{"_udev_infos"}{"ID_FS_TYPE"} // ""
$udev_info->{"_udev_infos"}{"ID_FS_TYPE"}
Truth table100%2/2
A
A= $udev_info->{"_udev_infos"}{"ID_FS_TYPE"}
Aresult
11
00
1246 197 next;
1247 }
1248 5 push @devs, $kn;
1249 }
1250 5 return @devs;
1251 }
1252  
1253 5 ▶sub collect {
Subroutine collect: called CC=7 SCAR=19.5
1254 5 my $self = shift;
1255 5 my $infos = shift;
1256 5 my $dh;
1257 5 my $luks={};
1258  
1259 5 my @devs=$self->select($infos);
1260  
1261 my $decrypted={
1262 map {
1263 $_->{DM_BLKDEVS_USED} => $_->{DM_BLKDEVNAME}
1264 5 } grep {
1265 67 ▶ ($_->{DM_SUBSYSTEM} // '') eq 'CRYPT'
Condition50%1/2
$_->{"DM_SUBSYSTEM"} // ""
l!l
670
MC/DC0%0/1
$_->{"DM_SUBSYSTEM"} // ""
$_->{"DM_SUBSYSTEM"}
Truth table50%1/2
A
A= $_->{"DM_SUBSYSTEM"}
Aresult
11
00
1266 5 } values(%{$infos->{dm}})
1267 };
1268  
1269 5 foreach my $dev (@devs) {
1270 5 $dh=$self->open_cmd_pipe_root(
1271 qw(cryptsetup luksDump), '/dev/'.$dev);
1272 5 my $l={};
1273 5 my $luks_header=0;
1274 5 ▶ while(defined(my $line=<$dh>)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $dh)) 215 5 220
1275 215 chomp($line);
1276 215 ▶ if ($line =~ /^LUKS header information/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($line =~ /^LUKS header information/) { } 5 210 215
elsif ($line =~ /^Version:\s*([^\s]*)$/) { } 5 205 210
1277 5 $luks_header=1;
1278 } elsif ($line =~ /^Version:\s*([^\s]*)$/) {
1279 5 $l->{VERSION} = $1;
1280 }
1281 }
1282 5 close $dh;
1283 5 ▶ if ($luks_header) {
Branch: 1 branch
BranchTrueFalseTotal
if ($luks_header) 5 0 5
1284 5 $l->{decrypted} = $decrypted->{$dev};
1285 5 $luks->{$dev} = $l;
1286 }
1287 }
1288  
1289 5 return { 'luks' => $luks };
1290 }
1291  
1292 19 1;
1293  
1294 ###########################################################################
1295 package StorageDisplay::Collect::MD;
1296  
1297 use is_collector
1298 19 ▶ provides => 'md',
Subroutine BEGIN: called CC=1 SCAR=0.0
1299 requires => [ qw(dm lsblk udev) ],
1300 depends => {
1301 files => [ '/proc/mdstat' ],
1302 progs => [ 'mdadm' ],
1303 root => 1,
1304 19 };
1305  
1306 5 ▶sub names_avail {
Subroutine names_avail: called CC=5 SCAR=16.1
1307 5 my $self = shift;
1308 5 my $infos = shift;
1309 5 my @devs=();
1310  
1311 5 my $dh=$self->open_file('/proc/mdstat');
1312 5 ▶ while (defined(my $line=<$dh>)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $dh)) 41 5 46
1313 41 chomp($line);
1314 41 ▶ next if ($line =~ /^Personalities/);
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^Personalities/ 5 36 41
1315 36 ▶ next if ($line =~ /^unused devices/);
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^unused devices/ 5 31 36
1316 31 ▶ next if ($line =~ /^\s/);
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s/ 16 15 31
1317 15 push @devs, ((split(/\s/, $line))[0]);
1318 }
1319 5 close $dh;
1320 5 return @devs;
1321 }
1322  
1323 5 ▶sub collect {
Subroutine collect: called CC=20 SCAR=34.2
1324 5 my $self = shift;
1325 5 my $infos = shift;
1326 5 ▶ my @devs = @{ shift // [ $self->select($infos) ] };
Condition50%1/2
shift() // [$self->select($infos)]
l!l
05
MC/DC0%0/1
shift() // [$self->select($infos)]
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
1327 5 my $dh;
1328 5 my $md={};
1329  
1330 5 foreach my $dev (@devs) {
1331 8 $dh=$self->open_cmd_pipe_root(
1332 qw(mdadm --misc --detail), '/dev/'.$dev);
1333 8 my $l={};
1334 8 my $container=0;
1335 8 ▶ while(defined(my $line=<$dh>)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $dh)) 217 0 217
1336 217 chomp($line);
1337 217 ▶ if ($line =~ /^\s*Array Size :\s*([0-9]+)\s*\(/) {
Branch: 9 branches
BranchTrueFalseTotal
if ($line =~ /^\s*Array Size :\s*([0-9]+)\s*\(/) { } 8 209 217
elsif ($line =~ /^\s*Used Dev Size :\s*([0-9]+)\s*\(/) { } 7 202 209
elsif ($line =~ /^\s*Raid Level :\s*([^\s].*)/) { } 8 194 202
elsif ($line =~ /^\s*State : \s*([^\s].*)/) { } 8 186 194
elsif ($line =~ /^\s*Version : \s*([^\s].*)/) { } 8 178 186
elsif ($line =~ /^\s*Name : \s*([^\s]+)\s*/) { } 8 170 178
elsif ($line =~ /^\s*Member Arrays : \s*([^\s]+.*[^\s])\s*/) { } 0 170 170
elsif ($line =~ /^\s*Container : \s*([^\s]+), member ([0-9]+)\s*/) { } 0 170 170
elsif ($line =~ /^\s*Number\s*Major\s*Minor\s*RaidDevice(\s*State)?/) { } 8 162 170
1338 8 $l->{'array-size'} = $1*1024;
1339 } elsif ($line =~ /^\s*Used Dev Size :\s*([0-9]+)\s*\(/) {
1340 7 $l->{'used-dev-size'} = $1*1024;
1341 } elsif ($line =~ /^\s*Raid Level :\s*([^\s].*)/) {
1342 8 $l->{'raid-level'} = $1;
1343 8 ▶ if ($1 eq 'container') {
Branch: 1 branch
BranchTrueFalseTotal
if ($1 eq "container") 0 8 8
1344 0 $l->{'raid-container'} = 1;
1345 0 $container = 1;
1346 }
1347 } elsif ($line =~ /^\s*State : \s*([^\s].*)/) {
1348 8 $l->{'raid-state'} = $1;
1349 } elsif ($line =~ /^\s*Version : \s*([^\s].*)/) {
1350 8 $l->{'raid-version'} = $1;
1351 } elsif ($line =~ /^\s*Name : \s*([^\s]+)\s*/) {
1352 8 $l->{'raid-name'} = $1;
1353 } elsif ($line =~ /^\s*Member Arrays : \s*([^\s]+.*[^\s])\s*/) {
1354 0 $l->{'raid-member-arrays'} = [ split(/ +/, $1) ];
1355 } elsif ($line =~ /^\s*Container : \s*([^\s]+), member ([0-9]+)\s*/) {
1356 0 $l->{'raid-container-device'} = $1;
1357 0 $l->{'raid-container-member'} = $2;
1358 } elsif ($line =~ /^\s*Number\s*Major\s*Minor\s*RaidDevice(\s*State)?/) {
1359 8 last;
1360 }
1361 }
1362  
1363 8 my $raid_id = 0;
1364 8 ▶ while(defined(my $line=<$dh>)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $dh)) 23 8 31
1365 23 chomp($line);
1366 23 ▶ if ((! $container)
Branch: 3 branches
BranchTrueFalseTotal
if (not $container and $line =~ /^\s*([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+([0-9-]+)\s+([^\s].*[^\s])\s+([^\s]+)$/) { } 23 0 23
elsif ($container and $line =~ /^\s*(-)\s+([0-9]+)\s+([0-9]+)\s+(-)\s+([^\s]+)$/) { } 0 0 0
elsif ($line =~ /^\s*$/) { } 0 0 0
Condition33%1/3
not $container and $line =~ /^\s*([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+([0-9-]+)\s+([^\s].*[^\s])\s+([^\s]+)$/
!ll&&!rl&&r
0023
MC/DC0%0/2
not $container and $line =~ /^\s*([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+([0-9-]+)\s+([^\s].*[^\s])\s+([^\s]+)$/
not $container $line =~ /^\s*([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+([0-9-]+)\s+([^\s].*[^\s])\s+([^\s]+)$/
Truth table33%1/3
not(A) and B
A= not $containerB= $line =~ /^\s*([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+([0-9-]+)\s+([^\s].*[^\s])\s+([^\s]+)$/
ABresult
0X0
100
111
1367 && $line =~ /^\s*([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+([0-9-]+)\s+([^\s].*[^\s])\s+([^\s]+)$/) {
1368 23 $l->{'devices'}->{$6} = {
1369 state => $5,
1370 raiddevice => $4,
1371 };
1372 ▶ } elsif ($container
Condition0%0/3
$container and $line =~ /^\s*(-)\s+([0-9]+)\s+([0-9]+)\s+(-)\s+([^\s]+)$/
!ll&&!rl&&r
000
MC/DC0%0/2
$container and $line =~ /^\s*(-)\s+([0-9]+)\s+([0-9]+)\s+(-)\s+([^\s]+)$/
$container $line =~ /^\s*(-)\s+([0-9]+)\s+([0-9]+)\s+(-)\s+([^\s]+)$/
Truth table0%0/3
A and B
A= $containerB= $line =~ /^\s*(-)\s+([0-9]+)\s+([0-9]+)\s+(-)\s+([^\s]+)$/
ABresult
0X0
100
111
1373 && $line =~ /^\s*(-)\s+([0-9]+)\s+([0-9]+)\s+(-)\s+([^\s]+)$/) {
1374 0 $l->{'devices'}->{$5} = {
1375 raiddevice => $raid_id++,
1376 };
1377 } elsif ($line =~ /^\s*$/) {
1378 } else {
1379 0 print STDERR "W: mdadm on $dev: Unknown line '$line'\n";
1380 }
1381 }
1382 8 close $dh;
1383 8 $md->{$dev} = $l;
1384 }
1385  
1386 5 return { 'md' => $md };
1387 }
1388  
1389 19 1;
1390  
1391 ###########################################################################
1392 package StorageDisplay::Collect::LSI::Sas2ircu;
1393  
1394 use is_collector
1395 19 ▶ provides => 'lsi-sas-ircu',
Subroutine BEGIN: called CC=1 SCAR=0.0
1396 depends => {
1397 progs => [ 'sas2ircu' ],
1398 root => 1,
1399 19 };
1400  
1401 1 ▶sub select {
Subroutine select: called CC=14 SCAR=30.8
1402 1 my $self = shift;
1403 1 my $infos = shift;
1404 1 ▶ my $request = shift // {};
Condition50%1/2
shift() // {}
l!l
01
MC/DC0%0/1
shift() // {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
1405 1 my @devs=();
1406  
1407 1 my $dh;
1408 1 $dh=$self->open_cmd_pipe_root(qw(sas2ircu LIST));
1409 1 my $state=0;
1410 1 my $nodata=0;
1411 1 ▶ while (defined(my $line=<$dh>)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $dh)) 10 1 11
1412 10 chomp($line);
1413 10 ▶ if ($state == 0) {
Branch: 3 branches
BranchTrueFalseTotal
if ($state == 0) { } 8 2 10
elsif ($state == 1) { } 2 0 2
elsif ($state == 2) { } 0 0 0
1414 8 ▶ $nodata=1 if $line eq 'SAS2IRCU: MPTLib2 Error 1';
Branch: 1 branch
BranchTrueFalseTotal
if $line eq "SAS2IRCU: MPTLib2 Error 1" 0 8 8
1415 8 ▶ next if $line !~ /^[\s-]*-[\s-]*$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ /^[\s-]*-[\s-]*$/ 7 1 8
1416 1 $state = 1;
1417 } elsif ($state == 1) {
1418 2 ▶ if ($line =~ /^SAS2IRCU:/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($line =~ /^SAS2IRCU:/) { } 1 1 2
elsif ($line =~ /^\s*([0-9]+)\s+/) { } 1 0 1
1419 1 ▶ if ($line ne 'SAS2IRCU: Utility Completed Successfully.') {
Branch: 1 branch
BranchTrueFalseTotal
if ($line ne "SAS2IRCU: Utility Completed Successfully.") 0 1 1
1420 0 print STDERR "W: sas2ircu: $line\n";
1421 }
1422 1 $state = 2;
1423 } elsif ($line =~ /^\s*([0-9]+)\s+/) {
1424 1 push @devs, $1;
1425 } else {
1426 0 print STDERR "E: sas2ircu: unknown line: $line\n";
1427 }
1428 } elsif ($state == 2) {
1429 0 print STDERR "W: sas2ircu: $line\n";
1430 }
1431 }
1432 1 ▶ if ($state != 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($state != 2) 0 1 1
1433 0 ▶ if ($state != 0 || $nodata != 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($state != 0 or $nodata != 1) 0 0 0
Condition0%0/3
$state != 0 or $nodata != 1
l!l&&r!l&&!r
000
MC/DC0%0/2
$state != 0 or $nodata != 1
$state != 0 $nodata != 1
Truth table0%0/3
A or B
A= $state != 0B= $nodata != 1
ABresult
1X1
011
000
1434 0 print STDERR "E: sas2ircu: Cannot parse data\n";
1435 }
1436 }
1437 1 close $dh;
1438 1 return @devs;
1439 }
1440  
1441 0 ▶sub parse {
Subroutine parse: not called CC=2 SCAR=17.9
1442 0 my $parser = shift;
1443 0 my $closure = shift;
1444 0 ▶ my $res = shift // {};
Condition0%0/2
shift() // {}
l!l
00
MC/DC0%0/1
shift() // {}
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
1445  
1446 }
1447  
1448 19 my %name = (
1449 'Size (in MB)' => 'size-mb',
1450 'Volume ID' => 'id',
1451 'Volume wwid' => 'wwid',
1452 'Status of volume' => 'status',
1453 );
1454  
1455 1 ▶sub collect {
Subroutine collect: called CC=24 SCAR=33.2
1456 1 my $self = shift;
1457 1 my $infos = shift;
1458 1 my $dh;
1459 1 my $lsi={};
1460  
1461 1 my @devs=$self->select($infos);
1462  
1463  
1464 0 ▶ my $parse_section = sub {
Subroutine __ANON__: not called CC=8 SCAR=42.8
1465 0 my $self = shift;
1466 0 my $line = shift;
1467 0 ▶ if ($line eq 'Controller information') {
Branch: 5 branches
BranchTrueFalseTotal
if ($line eq 'Controller information') { } 0 0 0
elsif ($line eq 'IR Volume information') { } 0 0 0
elsif ($line eq 'Physical device information') { } 0 0 0
elsif ($line eq 'Enclosure information') { } 0 0 0
elsif ($line =~ /SAS2IRCU:/) { } 0 0 0
1468 #$self->push_new_section->($parse_controller, $closure_controller);
1469 } elsif ($line eq 'IR Volume information') {
1470 #return (1, $parse_volumes);
1471 } elsif ($line eq 'Physical device information') {
1472 #return (1, $parse_phydev);
1473 } elsif ($line eq 'Enclosure information') {
1474 #return (1, $parse_phydev);
1475 } elsif ($line =~ /SAS2IRCU:/) {
1476 0 ▶ if ($line eq 'SAS2IRCU: Command DISPLAY Completed Successfully.'
Branch: 1 branch
BranchTrueFalseTotal
if ($line eq 'SAS2IRCU: Command DISPLAY Completed Successfully.' or $line eq 'SAS2IRCU: Utility Completed Successfully.') { } 0 0 0
Condition0%0/3
$line eq "SAS2IRCU: Command DISPLAY Completed Successfully." or $line eq "SAS2IRCU: Utility Completed Successfully."
l!l&&r!l&&!r
000
MC/DC0%0/2
$line eq "SAS2IRCU: Command DISPLAY Completed Successfully." or $line eq "SAS2IRCU: Utility Completed Successfully."
$line eq "SAS2IRCU: Command DISPLAY Completed Successfully." $line eq "SAS2IRCU: Utility Completed Successfully."
Truth table0%0/3
A or B
A= $line eq "SAS2IRCU: Command DISPLAY Completed Successfully."B= $line eq "SAS2IRCU: Utility Completed Successfully."
ABresult
1X1
011
000
1477 or $line eq 'SAS2IRCU: Utility Completed Successfully.') {
1478 } else {
1479 0 print STDERR "W: sas2ircu: $line\n";
1480 }
1481 } else {
1482 #if (scalar(keys %$l) != 0) {
1483 # print STDERR "W: sas2ircu: unknown line: $line\n";
1484 #}
1485 }
1486 0 return 1;
1487 1 };
1488  
1489  
1490 1 foreach my $dev (@devs) {
1491 1 $dh=$self->open_cmd_pipe_root('sas2ircu', $dev, 'DISPLAY');
1492 1 my $l={};
1493 1 my $state = 0;
1494 1 my $wwid = {};
1495 1 my $guid = {};
1496  
1497 1 my $data = undef;
1498 1 my $secdata = undef;
1499  
1500 1 ▶ my $closure=sub {} ;
Subroutine __ANON__: called CC=1 SCAR=0.0
1501 1 ▶ my $subclosure=sub {} ;
Subroutine __ANON__: called CC=1 SCAR=0.0
1502 1 ▶ while(defined(my $line=<$dh>)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $dh)) 103 1 104
1503 103 chomp($line);
1504 103 ▶ next if $line =~ /^[\s-]*$/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^[\s-]*$/ 14 89 103
1505 89 ▶ if ($line =~ /^(Controller) information$/
Branch: 8 branches
BranchTrueFalseTotal
if ($line =~ /^(Controller) information$/ or $line =~ /^(Enclosure) information$/) { } 2 87 89
elsif ($line =~ /^IR (Volume) information$/ or $line =~ /^Physical (device) information$/) { } 2 85 87
elsif ($line =~ /^IR volume ([^\s])+$/) { } 1 84 85
elsif ($line =~ /^Device is a Hard disk$/) { } 4 80 84
elsif ($line =~ /^Initiator at ID .*$/) { } 1 79 80
elsif ($line =~ /^SAS2IRCU: .* Completed Successfully.$/) { } 2 77 79
elsif ($line =~ /^[^\s]/) { } 4 73 77
elsif ($line =~ /^\s+([^\s][^:]*[^\s])\s*:\s+([^\s].*)$/) { } 72 1 73
Condition100%3/3
$line =~ /^(Controller) information$/ or $line =~ /^(Enclosure) information$/
l!l&&r!l&&!r
1187
MC/DC100%2/2
$line =~ /^(Controller) information$/ or $line =~ /^(Enclosure) information$/
$line =~ /^(Controller) information$/ $line =~ /^(Enclosure) information$/
Truth table100%3/3
A or B
A= $line =~ /^(Controller) information$/B= $line =~ /^(Enclosure) information$/
ABresult
1X1
011
000
1506 || $line =~ /^(Enclosure) information$/) {
1507 2 my $section = lc($1);
1508 2 $subclosure->($data);
1509 2 $closure->($data);
1510 2 $data = {};
1511 2 ▶ $subclosure = sub {};
Subroutine __ANON__: called CC=1 SCAR=0.0
1512 2 ▶ $closure = sub {
Subroutine __ANON__: called CC=2 SCAR=7.4
1513 2 my $curdata = shift;
1514 2 ▶ if (exists($l->{$section})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $l->{$section}) 0 2 2
1515 0 print STDERR "E: sas2ircu: duplicate section: $line\n";
1516 }
1517 2 $l->{$section}=$curdata;
1518 2 return {};
1519 2 };
1520 2 $state=10;
1521 ▶ } elsif ($line =~ /^IR (Volume) information$/
Condition100%3/3
$line =~ /^IR (Volume) information$/ or $line =~ /^Physical (device) information$/
l!l&&r!l&&!r
1185
MC/DC100%2/2
$line =~ /^IR (Volume) information$/ or $line =~ /^Physical (device) information$/
$line =~ /^IR (Volume) information$/ $line =~ /^Physical (device) information$/
Truth table100%3/3
A or B
A= $line =~ /^IR (Volume) information$/B= $line =~ /^Physical (device) information$/
ABresult
1X1
011
000
1522 || $line =~ /^Physical (device) information$/) {
1523 2 my $section = lc($1).'s';
1524 2 $subclosure->($data);
1525 2 $closure->($data);
1526 2 $secdata=[];
1527 2 ▶ $subclosure = sub { };
Subroutine __ANON__: called CC=1 SCAR=0.0
1528 2 ▶ $closure=sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
1529 2 my $data = shift;
1530 2 ▶ if (exists($l->{$section})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $l->{$section}) 0 2 2
1531 0 print STDERR "E: sas2ircu: duplicate section: $line\n";
1532 }
1533 2 $l->{$section}=$secdata;
1534 return
1535 2 };
1536 } elsif ($line =~ /^IR volume ([^\s])+$/) {
1537 1 my $name = $1;
1538 1 $subclosure->($data);
1539 1 $data = {
1540 name => $name,
1541 };
1542 1 ▶ $subclosure = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
1543 1 my $data = shift;
1544 1 push @$secdata, $data;
1545 1 };
1546 } elsif ($line =~ /^Device is a Hard disk$/) {
1547 4 $subclosure->($data);
1548 4 $data = {};
1549 4 ▶ $subclosure = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
1550 4 my $data = shift;
1551 4 push @$secdata, $data;
1552 4 };
1553 } elsif ($line =~ /^Initiator at ID .*$/) {
1554 } elsif ($line =~ /^SAS2IRCU: .* Completed Successfully.$/) {
1555 } elsif ($line =~ /^[^\s]/) {
1556 4 ▶ if ($state != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($state != 0) 0 4 4
1557 0 print STDERR "W: sas2ircu: unknown line: $line\n";
1558 }
1559 } elsif ($line =~ /^\s+([^\s][^:]*[^\s])\s*:\s+([^\s].*)$/) {
1560 72 my $k = $1;
1561 72 my $v = $2;
1562 72 ▶ if ($k =~ m,^PHY\[([^\]]+)\] Enclosure#/Slot#,) {
Branch: 2 branches
BranchTrueFalseTotal
if ($k =~ m(^PHY\[([^\]]+)\] Enclosure#/Slot#)) { } 2 70 72
elsif ($k eq 'Size (in MB)/(in sectors)') { } 4 66 70
1563 2 my $phy=$1;
1564 2 my ($e, $s) = split(':', $v);
1565 2 $data->{PHY}->{$phy} = { enclosure => $e, slot => $s };
1566 2 next;
1567 } elsif ($k eq 'Size (in MB)/(in sectors)') {
1568 4 my ($s1, $s2) = split('/', $v);
1569 4 $data->{'size-mb'}=$s1;
1570 4 $data->{'size-s'}=$s2;
1571 4 $data->{'size'}=$s2 * 512;
1572 4 next;
1573 }
1574 66 ▶ $k = $name{$k} // $k;
Condition66%2/3
$name{$k} // $k
l!l&&r!l&&!r
4620
MC/DC0%0/2
$name{$k} // $k
$name{$k} $k
Truth table66%2/3
A // B
A= $name{$k}B= $k
ABresult
1X1
011
000
1575 66 $k =~ s/\s*[#]//;
1576 66 $k = lc($k);
1577 66 $k =~ s/\s+/-/g;
1578 66 ▶ if ($k eq 'guid') {
Branch: 2 branches
BranchTrueFalseTotal
if ($k eq 'guid') { } 4 62 66
elsif ($k eq 'wwid') { } 1 61 62
1579 4 $guid->{$v}=1;
1580 } elsif ($k eq 'wwid') {
1581 1 $wwid->{$v}=1;
1582 }
1583 66 $data->{$k}=$v;
1584 }
1585 }
1586 1 $subclosure->($data);
1587 1 $closure->($data);
1588 1 close $dh;
1589 1 $dh=$self->open_cmd_pipe(qw(find /sys/devices -name sas_address));
1590 1 my @lines=<$dh>;
1591 1 for my $line (sort @lines) {
1592 21 chomp($line);
1593 21 ▶ my $dh2 = $self->open_file($line)
Branch: 1 branch
BranchTrueFalseTotal
my $dh2 = $self->open_file($line) or die "Cannot open ${line}: $!\n" 21 0 21
1594 or die "Cannot open $line: $!\n";
1595 21 my $addr=<$dh2>;
1596 21 close $dh2;
1597 21 chomp($addr);
1598 21 $addr =~ s/^0x//;
1599 21 ▶ if (defined($wwid->{$addr})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $wwid->{$addr}) 1 20 21
1600 1 my $dir = $line;
1601 1 $dir =~ s/sas_address/block/;
1602 1 my $dh3 = $self->open_cmd_pipe('ls', '-1', $dir);
1603 1 my @dirs=<$dh3>;
1604 1 close($dh3);
1605 1 ▶ if (scalar(@dirs) != 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @dirs != 1) { } 0 1 1
1606 0 print STDERR "E: sas2ircu: bad number of block devices for $addr\n";
1607 } else {
1608 1 chomp($l->{wwid}->{$addr} = $dirs[0]);
1609 }
1610 }
1611 }
1612 1 $lsi->{$dev} = $l;
1613 }
1614  
1615 1 return { 'lsi-sas-ircu' => $lsi };
1616 }
1617  
1618 19 1;
1619  
1620 ###########################################################################
1621 package StorageDisplay::Collect::LSI::Megacli;
1622  
1623 use is_collector
1624 19 ▶ provides => 'lsi-megacli',
Subroutine BEGIN: called CC=1 SCAR=0.0
1625 depends => {
1626 progs => [ 'megaclisas-status', 'megacli' ],
1627 root => 1,
1628 19 };
1629  
1630 1 ▶sub select {
Subroutine select: called CC=5 SCAR=16.5
1631 1 my $self = shift;
1632 1 my $infos = shift;
1633 1 ▶ my $request = shift // {};
Condition50%1/2
shift() // {}
l!l
01
MC/DC0%0/1
shift() // {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
1634 1 my @devs=();
1635  
1636 1 my $dh;
1637 1 $dh=$self->open_cmd_pipe_root(qw(megacli -adpCount -NoLog));
1638 1 ▶ while (defined(my $line=<$dh>)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $dh)) 3 0 3
1639 3 chomp($line);
1640 3 ▶ next if $line !~ /^Controller Count:\s*([0-9]+)\.?\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ /^Controller Count:\s*([0-9]+)\.?\s*$/ 2 1 3
1641 1 my $nb_controllers = $1;
1642 1 ▶ for (my $i=0; $i<$nb_controllers; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $nb_controllers) 1 1 2
1643 1 push @devs, $i;
1644 }
1645 1 close $dh;
1646 1 return @devs;
1647 }
1648 0 print STDERR "E: megacli: cannot find the number of controllers, assuming 0\n";
1649 0 close $dh;
1650 0 return @devs;
1651 }
1652  
1653 0 ▶sub parse {
Subroutine parse: not called CC=2 SCAR=17.9
1654 0 my $parser = shift;
1655 0 my $closure = shift;
1656 0 ▶ my $res = shift // {};
Condition0%0/2
shift() // {}
l!l
00
MC/DC0%0/1
shift() // {}
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
1657  
1658 }
1659  
1660 14 ▶sub interleave {
Subroutine interleave: called CC=4 SCAR=13.9
1661 14 my @lists = map [@$_], @_;
1662 14 my @res;
1663 14 ▶ while (my $list = shift @lists) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $list = shift @lists) 284 14 298
1664 284 ▶ if (@$list) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$list) 256 28 284
1665 256 push @res, shift @$list;
1666 256 push @lists, $list;
1667 }
1668 }
1669 14 ▶ wantarray ? @res : \@res;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 14 0 14
1670 }
1671  
1672 1 ▶sub collect {
Subroutine collect: called CC=33 SCAR=39.1
1673 1 my $self = shift;
1674 1 my $infos = shift;
1675 1 my $dh;
1676  
1677 1 my @devs=$self->select($infos);
1678  
1679 1 my $megacli={ map { $_ => {} } @devs };
1680  
1681 1 $dh=$self->open_cmd_pipe_root('megaclisas-status');
1682  
1683 1 my $section_name;
1684 my @headers;
1685 1 ▶ while(defined(my $line=<$dh>)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $dh)) 26 1 27
1686 26 chomp($line);
1687 26 ▶ next if $line =~ /^\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*$/ 4 22 26
1688 22 ▶ if ($line =~ /^-- (.*) [Ii]nformation(s)?(\s*--)?\s*$/) {
Branch: 6 branches
BranchTrueFalseTotal
if ($line =~ /^-- (.*) [Ii]nformation(s)?(\s*--)?\s*$/) { } 4 18 22
elsif ($line =~ /^--\s*(ID\s*|.*[^\s])\s*$/) { } 4 14 18
elsif ($line =~ /^(c([0-9]+)(\s|u).*[^\s])\s*$/) { } 14 0 14
elsif ($line =~ m[^There is at least one disk/array in a NOT OPTIMAL state.$]) { } 0 0 0
elsif ($line =~ /^RAID ERROR - Arrays: OK:[0-9]+ Bad:[0-9]+ - Disks: OK:[0-9]+ Bad:[0-9]+$/) { } 0 0 0
elsif ($line =~ /^No MegaRAID or PERC adapter detected on your system!$/) { } 0 0 0
1689 4 $section_name=$1;
1690 4 ▶ if ($section_name =~ /Disk/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($section_name =~ /Disk/) 2 2 4
1691 2 $section_name = 'Disk';
1692 }
1693 } elsif ($line =~ /^--\s*(ID\s*|.*[^\s])\s*$/) {
1694 4 @headers = split(/\s*[|]\s*/, $1);
1695 } elsif ($line =~ /^(c([0-9]+)(\s|u).*[^\s])\s*$/) {
1696 14 my $idc = $2;
1697 14 ▶ next if not exists($megacli->{$idc});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $megacli->{$idc} 0 14 14
1698 14 my @infos = split(/\s*[|]\s*/, $1);
1699 14 ▶ if (scalar(@infos) != scalar(@headers)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @infos != scalar @headers) 0 14 14
1700 0 print STDERR "E: megaclisas-status: invalid number of information: $line\n";
1701 0 next;
1702 }
1703 14 my $infos = { interleave(\@headers, \@infos) };
1704 14 my $id = $infos->{ID};
1705 14 ▶ if ($section_name eq 'Disk') {
Branch: 1 branch
BranchTrueFalseTotal
if ($section_name eq "Disk") 10 4 14
1706 10 $id = $infos->{'Slot ID'};
1707 }
1708 14 ▶ if (exists($megacli->{$idc}->{$section_name}->{$id})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $megacli->{$idc}{$section_name}{$id}) 0 14 14
1709 0 print STDERR "E: megaclisas-status: duplicate info for $id: $line\n";
1710 }
1711 14 $megacli->{$idc}->{$section_name}->{$id}=$infos;
1712 } elsif ($line =~ /^There is at least one disk\/array in a NOT OPTIMAL state.$/) {
1713 # skip
1714 } elsif ($line =~ /^RAID ERROR - Arrays: OK:[0-9]+ Bad:[0-9]+ - Disks: OK:[0-9]+ Bad:[0-9]+$/) {
1715 # skip
1716 } elsif ($line =~ /^No MegaRAID or PERC adapter detected on your system!$/) {
1717 # skip
1718 } else {
1719 0 print STDERR "E: megaclisas-status: invalid line: $line\n";
1720 }
1721 }
1722 1 close($dh);
1723  
1724 1 for my $dev (@devs) {
1725 1 $dh=$self->open_cmd_pipe_root(qw(megacli -PDList), "-a$dev");
1726 1 my $cur_enc;
1727 my $cur_slot;
1728 1 my $cur_size;
1729 21 ▶ my $get_cur_disk=sub {
Subroutine __ANON__: called CC=2 SCAR=8.4
1730 21 my $slot_id = "[$cur_enc:$cur_slot]";
1731 21 ▶ if (not exists($megacli->{$dev}->{'Disk'}->{$slot_id})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $megacli->{$dev}{"Disk"}{$slot_id}) 0 21 21
1732 0 print STDERR "E: missing disk with slot $slot_id\n";
1733 0 return;
1734 }
1735 21 return $megacli->{$dev}->{'Disk'}->{$slot_id};
1736 1 };
1737 1 ▶ while(defined(my $line=<$dh>)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $dh)) 487 1 488
1738 487 chomp($line);
1739 487 ▶ next if $line =~ /^\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*$/ 42 445 487
1740 445 ▶ next if $line eq "Adapter #$dev";
Branch: 1 branch
BranchTrueFalseTotal
if $line eq "Adapter #$dev" 1 444 445
1741 444 ▶ if ($line eq "^Adapter") {
Branch: 1 branch
BranchTrueFalseTotal
if ($line eq "^Adapter") 0 444 444
1742 0 print STDERR "W: megacli: strange adapter for #$dev: $line\n";
1743 0 next;
1744 }
1745 444 ▶ if ($line =~ /^Enclosure Device ID: *([0-9]+|N\/A) *$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ m[^Enclosure Device ID: *([0-9]+|N/A) *$]) 10 434 444
1746 10 $cur_enc=$1;
1747 10 ▶ $cur_enc='' if $cur_enc eq 'N/A';
Branch: 1 branch
BranchTrueFalseTotal
if $cur_enc eq "N/A" 0 10 10
1748 10 $cur_slot=undef;
1749 10 next;
1750 }
1751 434 ▶ if ($line =~ /^Enclosure Device ID: *(.*) *$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^Enclosure Device ID: *(.*) *$/) 0 434 434
1752 0 print STDERR "W: megacli: strange enclosure device ID '$1'\n";
1753 }
1754 434 ▶ if ($line =~ /^Slot Number: *([0-9]+) *$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^Slot Number: *([0-9]+) *$/) 10 424 434
1755 10 ▶ if (defined($cur_slot) || not defined($cur_enc)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cur_slot or not defined $cur_enc) 0 10 10
Condition33%1/3
defined $cur_slot or not defined $cur_enc
l!l&&r!l&&!r
0010
MC/DC0%0/2
defined $cur_slot or not defined $cur_enc
defined $cur_slot not defined $cur_enc
Truth table33%1/3
A or not(B)
A= defined $cur_slotB= not defined $cur_enc
ABresult
1X1
011
000
1756 0 print STDERR "W: megacli: strange state when finding slot number $1\n";
1757 }
1758 10 $cur_slot=$1;
1759 10 next;
1760 }
1761 424 ▶ if ($line =~ /^Array *#: *([0-9]+) *$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^Array *#: *([0-9]+) *$/) 1 423 424
1762 1 ▶ my $d=$get_cur_disk->() // next;
Condition50%1/2
&$get_cur_disk() // (next)
l!l
10
MC/DC0%0/1
&$get_cur_disk() // (next)
&$get_cur_disk()
Truth table50%1/2
A
A= &$get_cur_disk()
Aresult
11
00
1763 1 ▶ if ($d->{'ID'} !~ /^c[0-9]+uXpY$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($d->{"ID"} =~ /^c[0-9]+uXpY$/) 0 1 1
1764 0 my $slot_id = $d->{'Slot ID'};
1765 0 print STDERR "E: slot $slot_id has a strange ID\n";
1766 0 next;
1767 }
1768 1 $d->{'ID'} =~ s/X/$dev/;
1769 }
1770 424 ▶ if ($line =~ /^Coerced Size:.*\[(0x[0-9a-f]+) *Sectors\]/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^Coerced Size:.*\[(0x[0-9a-f]+) *Sectors\]/i) 10 414 424
1771 10 ▶ my $d=$get_cur_disk->() // next;
Condition50%1/2
&$get_cur_disk() // (next)
l!l
100
MC/DC0%0/1
&$get_cur_disk() // (next)
&$get_cur_disk()
Truth table50%1/2
A
A= &$get_cur_disk()
Aresult
11
00
1772 10 $d->{'# sectors'} = $1;
1773 }
1774 424 ▶ if ($line =~ /^Sector Size: *([0-9]+)$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^Sector Size: *([0-9]+)$/i) 10 414 424
1775 10 ▶ my $d=$get_cur_disk->() // next;
Condition50%1/2
&$get_cur_disk() // (next)
l!l
100
MC/DC0%0/1
&$get_cur_disk() // (next)
&$get_cur_disk()
Truth table50%1/2
A
A= &$get_cur_disk()
Aresult
11
00
1776 10 ▶ $d->{'sector size'} = ($1==0)?512:$1;
Branch: 1 branch
BranchTrueFalseTotal
$1 == 0 ? : 10 0 10
1777 }
1778 }
1779 1 close($dh);
1780 }
1781  
1782 1 return { 'lsi-megacli' => $megacli };
1783 }
1784  
1785 19 1;
1786  
1787 ###########################################################################
1788 package StorageDisplay::Collect::Libvirt;
1789  
1790 use is_collector
1791 19 ▶ provides => 'libvirt',
Subroutine BEGIN: called CC=1 SCAR=0.0
1792 depends => {
1793 progs => [ 'virsh' ],
1794 root => 1,
1795 19 };
1796  
1797 6 ▶sub select {
Subroutine select: called CC=4 SCAR=13.9
1798 6 my $self = shift;
1799 6 my $infos = shift;
1800 6 ▶ my $request = shift // {};
Condition50%1/2
shift() // {}
l!l
06
MC/DC0%0/1
shift() // {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
1801 6 my @vms=();
1802  
1803 6 my $dh=$self->open_cmd_pipe_root(qw(virsh list --all --name));
1804 6 ▶ while(defined(my $line=<$dh>)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $dh)) 41 6 47
1805 41 chomp($line);
1806 41 ▶ next if $line =~ /^\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*$/ 6 35 41
1807 35 push @vms, $line;
1808 }
1809 6 close $dh;
1810 6 @vms = sort @vms;
1811 6 return @vms;
1812 }
1813  
1814 6 ▶sub collect {
Subroutine collect: called CC=25 SCAR=40.9
1815 6 my $self = shift;
1816 6 my $infos = shift;
1817 6 my $dh;
1818 6 my $libvirt={};
1819  
1820 6 my @vms=$self->select($infos);
1821  
1822 6 foreach my $vm (@vms) {
1823 35 $dh=$self->open_cmd_pipe_root(qw(virsh domstate), $vm);
1824 35 my $v={ name => $vm };
1825 35 ▶ while(defined(my $line=<$dh>)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $dh)) 56 21 77
1826 56 chomp($line);
1827 56 ▶ if ($line =~ /running/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /running/) 14 42 56
1828 14 $v->{state} = 'running';
1829 14 last;
1830 }
1831 }
1832 35 close $dh;
1833 35 $dh=$self->open_cmd_pipe_root(qw(virsh domblklist --details), $vm);
1834 35 ▶ while(defined(my $line=<$dh>)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $dh)) 176 35 211
1835 176 chomp($line);
1836 176 ▶ next if $line =~ /^[\s-]*$/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^[\s-]*$/ 70 106 176
1837 106 my @info=split(' ', $line);
1838 106 ▶ next if ($info[0]//'') eq 'Type';
Branch: 1 branch
BranchTrueFalseTotal
if ($info[0] // "") eq "Type" 35 71 106
Condition50%1/2
$info[0] // ""
l!l
1060
MC/DC0%0/1
$info[0] // ""
$info[0]
Truth table50%1/2
A
A= $info[0]
Aresult
11
00
1839 #next if ($info[0]//'') ne 'block';
1840 71 ▶ next if $info[3] eq '-';
Branch: 1 branch
BranchTrueFalseTotal
if $info[3] eq "-" 13 58 71
1841 58 ▶ if (scalar(@info) != 4) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @info != 4) 0 58 58
1842 0 print STDERR "W: libvirt on $vm: Unknown line '$line'\n";
1843 0 next;
1844 }
1845 58 $v->{'blocks'}->{$info[3]} = {
1846 type => $info[0],
1847 device => $info[1],
1848 target => $info[2],
1849 source => $info[3],
1850 };
1851 58 ▶ if ($info[0] eq 'file') {
Branch: 2 branches
BranchTrueFalseTotal
if ($info[0] eq 'file') { } 19 39 58
elsif ($info[0] eq 'block') { } 39 0 39
1852 19 StorageDisplay::Collect::File::select_file($info[3]);
1853 } elsif ($info[0] eq 'block') {
1854 } else {
1855 0 print STDERR "W: unknown VM device type: $info[0]\n";
1856 }
1857 }
1858 35 close $dh;
1859 35 ▶ if ($v->{state}//'' eq 'running') {
Branch: 1 branch
BranchTrueFalseTotal
if () 14 21 35
Condition100%2/2
$v->{"state"} //
l!l
1421
MC/DC100%1/1
$v->{"state"} //
$v->{"state"}
Truth table100%2/2
A
A= $v->{"state"}
Aresult
11
00
1860 # trying to get infos from QEMU guest agent
1861 14 $dh=$self->open_cmd_pipe_root(qw(virsh guestinfo --hostname --disk), $vm);
1862 14 my $curdisk='';
1863 14 my $curdiskinfo={};
1864 14 ▶ while(defined(my $line=<$dh>)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $dh)) 14 14 28
1865 14 chomp($line);
1866 14 ▶ if ($curdisk ne '' && $line !~ /^disk\.$curdisk\./) {
Branch: 1 branch
BranchTrueFalseTotal
if ($curdisk ne "" and not $line =~ /^disk\.$curdisk\./) 0 14 14
Condition33%1/3
$curdisk ne "" and not $line =~ /^disk\.$curdisk\./
!ll&&!rl&&r
1400
MC/DC0%0/2
$curdisk ne "" and not $line =~ /^disk\.$curdisk\./
$curdisk ne "" not $line =~ /^disk\.$curdisk\./
Truth table33%1/3
A and not(B)
A= $curdisk ne ""B= not $line =~ /^disk\.$curdisk\./
ABresult
0X0
100
111
1867 0 ▶ if (exists($curdiskinfo->{name}) && exists($curdiskinfo->{alias})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $curdiskinfo->{"name"} and exists $curdiskinfo->{"alias"}) 0 0 0
Condition0%0/3
exists $curdiskinfo->{"name"} and exists $curdiskinfo->{"alias"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $curdiskinfo->{"name"} and exists $curdiskinfo->{"alias"}
exists $curdiskinfo->{"name"} exists $curdiskinfo->{"alias"}
Truth table0%0/3
A and B
A= exists $curdiskinfo->{"name"}B= exists $curdiskinfo->{"alias"}
ABresult
0X0
100
111
1868 #print STDERR "W: libvirt guestagent on $vm: adding ".$curdiskinfo->{alias}."\n";
1869 0 $v->{ga}->{disks}->{$curdiskinfo->{alias}}=$curdiskinfo;
1870 }
1871 0 $curdiskinfo={};
1872 0 $curdisk = '';
1873 }
1874 14 ▶ next if $line =~ /^[\s-]*$/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^[\s-]*$/ 14 0 14
1875 0 ▶ if ($line !~ m/^([^:\s]+)\s*: (.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($line =~ /^([^:\s]+)\s*: (.*)$/) 0 0 0
1876 0 print STDERR "W: libvirt guestagent on $vm: Unknown line '$line'\n";
1877 }
1878 0 my $key=$1;
1879 0 my $value=$2;
1880 0 ▶ if ($key eq 'hostname') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "hostname") 0 0 0
1881 0 $v->{ga}->{hostname} = $value;
1882 0 next;
1883 }
1884 0 ▶ if ($key =~ /^disk\.([0-9]+)\./) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /^disk\.([0-9]+)\./) 0 0 0
1885 0 $curdisk = $1;
1886 0 ▶ if ($key =~ /\.(name|alias)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /\.(name|alias)$/) 0 0 0
1887 0 $curdiskinfo->{$1} = $value;
1888 }
1889 }
1890 }
1891 14 close $dh;
1892 14 ▶ if ($curdisk ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($curdisk ne "") 0 14 14
1893 # the last empty line should have set $curdisk to ''
1894 0 print STDERR "W: libvirt guestagent on $vm: end-before-end '$curdisk'\n";
1895 }
1896 }
1897 35 $libvirt->{$vm} = $v;
1898 }
1899  
1900 6 return { 'libvirt' => $libvirt };
1901 }
1902  
1903 19 1;
1904  
1905 ###########################################################################
1906 package StorageDisplay::Collect::Loops;
1907  
1908 use is_collector
1909 19 ▶ provides => 'loops',
Subroutine BEGIN: called CC=1 SCAR=0.0
1910 depends => {
1911 progs => [ 'losetup' ],
1912 root => 1,
1913 19 };
1914  
1915 19 ▶use StorageDisplay::Collect::JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
1916 7 ▶sub losetupjson2perl {
Subroutine losetupjson2perl: called CC=1 SCAR=0.0
1917 7 my $self = shift;
1918 7 my $json = shift;
1919 7 return StorageDisplay::Collect::JSON::jsonarray2perlhash($json, 'loopdevices', 'name');
1920 }
1921  
1922 7 ▶sub select {
Subroutine select: called CC=4 SCAR=16.0
1923 7 my $self = shift;
1924 7 my $infos = shift;
1925 7 ▶ my $request = shift // {};
Condition50%1/2
shift() // {}
l!l
07
MC/DC0%0/1
shift() // {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
1926 7 my @loops;
1927  
1928 7 my $dh=$self->open_cmd_pipe_root(qw(losetup --output NAME));
1929 7 ▶ while(defined(my $line=<$dh>)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $dh)) 0 7 7
1930 0 chomp($line);
1931 0 ▶ next if $line =~ /^NAME$/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^NAME$/ 0 0 0
1932 0 push @loops, $line;
1933 }
1934 7 close $dh;
1935 7 @loops = sort @loops;
1936 7 return @loops;
1937 }
1938  
1939 7 ▶sub collect {
Subroutine collect: called CC=3 SCAR=12.9
1940 7 my $self = shift;
1941 7 my $infos = shift;
1942 7 my $files={};
1943  
1944 7 my @loops=$self->select($infos);
1945  
1946 7 my $dh=$self->open_cmd_pipe_root(qw(losetup --output-all --list --json));
1947 7 my $all_loops = $self->losetupjson2perl(join(' ', <$dh>));
1948 7 close $dh;
1949  
1950 7 my $loops={};
1951 7 foreach my $loop (@loops) {
1952 0 $loops->{$loop} = $all_loops->{$loop};
1953 0 my $filename = $loops->{$loop}->{'back-file'};
1954 0 StorageDisplay::Collect::File::select_file($filename);
1955 0 ▶ if ($filename =~ /(.*) \(deleted\)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filename =~ /(.*) \(deleted\)/) 0 0 0
1956 0 StorageDisplay::Collect::File::select_file($1);
1957 }
1958 }
1959 7 return { 'loops' => $loops };
1960 }
1961  
1962 19 1;
1963  
1964 ###########################################################################
1965 package StorageDisplay::Collect::File;
1966  
1967 # This collector must be the last one as it collects info on requested
1968 # files by other collectors.
1969  
1970 use is_collector
1971 19 ▶ provides => 'files',
Subroutine BEGIN: called CC=1 SCAR=0.0
1972 depends => {
1973 progs => [ 'findmnt' ],
1974 root => 1,
1975 19 };
1976  
1977 19 ▶use StorageDisplay::Collect::JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
1978 19 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
1979 4 ▶sub statjson2perl {
Subroutine statjson2perl: called CC=1 SCAR=0.0
1980 4 my $self = shift;
1981 4 my $json = shift;
1982 4 return StorageDisplay::Collect::JSON::jsonarray2perlhash($json, 'stats', 'name');
1983 }
1984  
1985 19 my $files = {};
1986  
1987 19 ▶sub select_file {
Subroutine select_file: called CC=1 SCAR=0.0
1988 19 my $filename = shift;
1989 19 $files->{$filename} = 1;
1990 }
1991  
1992 7 ▶sub select {
Subroutine select: called CC=2 SCAR=7.0
1993 7 my $self = shift;
1994 7 my $infos = shift;
1995 7 ▶ my $request = shift // {};
Condition50%1/2
shift() // {}
l!l
07
MC/DC0%0/1
shift() // {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
1996 7 my @files = sort keys %{$files};
1997 7 return @files;
1998 }
1999  
2000 7 ▶sub collect {
Subroutine collect: called CC=6 SCAR=18.0
2001 7 my $self = shift;
2002 7 my $infos = shift;
2003 7 my $files={};
2004  
2005 7 my @files=$self->select($infos);
2006 7 my @json;
2007 my @present;
2008  
2009 7 ▶ if (scalar(@files) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @files == 0) 3 4 7
2010 3 return { 'files' => [] };
2011 }
2012 4 my $dh0=$self->open_cmd_pipe_root(
2013 qw(perl -e),
2014 'my '.Dumper(\@files).
2015 'grep { if (-e $_) { print "OK\n" } else { print "NACK\n" }; 1 } @{$VAR1};');
2016 4 my @res = <$dh0>;
2017 4 close $dh0;
2018 4 ▶ if (scalar(@files) != scalar(@res)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @files != scalar @res) { } 0 4 4
2019 0 print STDERR "WARNING: Something goes wrong with stat files\n";
2020 } else {
2021 4 ▶ for(my $i=0; $i<scalar(@res); $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @res) 19 4 23
2022 19 ▶ if ($res[$i] =~ /^OK/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res[$i] =~ /^OK/) { } 9 10 19
2023 9 push @present, $files[$i];
2024 } else {
2025 10 push @json, '{ "name":"'.$files[$i].'", "deleted":true },'."\n";
2026 }
2027 }
2028 }
2029 4 ▶ if (scalar(@present) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @present > 0) 4 0 4
2030 4 my $dh=$self->open_cmd_pipe_root(
2031 # '%[LH][rd]' do not exist on old stat tool
2032 qw(stat -c),
2033 '{ "name":"%n", "deleted":false, "size":%s, "inode":%i,'.
2034 ' "permission":"0%a", "mode":"0x%f", "blocks":%b,'.
2035 ' "blocksize":%B, "st_dev":%d, "hardlinks":%h,'.
2036 ' "mountpoint":"%m", "st_rdev":"%r", "st_special":"%t:%T" },',
2037 @present);
2038 4 push @json, <$dh>;
2039 }
2040 4 my $json=join("", @json);
2041 4 chomp($json);
2042 4 $json =~ s/,$//;
2043 #print STDERR "json=$json\n";
2044 4 return { 'files' => $self->statjson2perl('{ "stats": [ '.$json."\n] }") };
2045 }
2046  
2047 # This collector must be the last one as it collects info on requested
2048 # files by other collectors.
2049  
2050 19 1;
2051  
2052 ###########################################################################
2053 ###########################################################################
2054 ###########################################################################
2055 ###########################################################################
2056 package StorageDisplay::Collect;
2057  
2058 0 ▶sub dump_collect {
Subroutine dump_collect: not called CC=2 SCAR=12.6
Pod undocumented
2059 0 ▶ my $reader = shift // 'Local';
Condition0%0/2
shift() // "Local"
l!l
00
MC/DC0%0/1
shift() // "Local"
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
2060 0 my $collector = __PACKAGE__->new($reader, @_);
2061  
2062 0 my $info = $collector->collect();
2063  
2064 19 ▶ use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
2065 # sort keys
2066 0 $Data::Dumper::Sortkeys = 1;
2067 0 $Data::Dumper::Purity = 1;
2068  
2069 0 print Dumper($info);
2070 #print Dumper(\%INC);
2071 }
2072  
2073 19 1;
2074  
2075 __END__
« blib/lib/StorageDisplay/Data/Loop.pm ↑ Summary blib/lib/StorageDisplay/Data/FS.pm »