| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
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
|
9
|
|
|
9
|
|
58
|
use strict; |
|
|
9
|
|
|
|
|
23
|
|
|
|
9
|
|
|
|
|
391
|
|
|
10
|
9
|
|
|
9
|
|
45
|
use warnings; |
|
|
9
|
|
|
|
|
18
|
|
|
|
9
|
|
|
|
|
867
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
package StorageDisplay::Block; |
|
13
|
|
|
|
|
|
|
# ABSTRACT: Base package for block devices DAG |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = '2.06'; # VERSION |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
1; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
package StorageDisplay::BlockTreeElement; |
|
20
|
|
|
|
|
|
|
|
|
21
|
9
|
|
|
9
|
|
64
|
use Moose; |
|
|
9
|
|
|
|
|
37
|
|
|
|
9
|
|
|
|
|
84
|
|
|
22
|
9
|
|
|
9
|
|
72331
|
use namespace::sweep; |
|
|
9
|
|
|
|
|
19
|
|
|
|
9
|
|
|
|
|
79
|
|
|
23
|
|
|
|
|
|
|
|
|
24
|
9
|
|
|
9
|
|
617
|
use Carp; |
|
|
9
|
|
|
|
|
19
|
|
|
|
9
|
|
|
|
|
679
|
|
|
25
|
9
|
|
|
9
|
|
5826
|
use StorageDisplay::Role; |
|
|
9
|
|
|
|
|
42
|
|
|
|
9
|
|
|
|
|
1300
|
|
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
with "StorageDisplay::Role::Iterable" |
|
28
|
|
|
|
|
|
|
=> { |
|
29
|
|
|
|
|
|
|
iterable => "StorageDisplay::BlockTreeElement", |
|
30
|
|
|
|
|
|
|
name => "Plain", |
|
31
|
|
|
|
|
|
|
}; |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub dname { |
|
34
|
0
|
|
|
0
|
0
|
0
|
my $self; |
|
35
|
0
|
|
|
|
|
0
|
return $self->name; |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
1; |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
################################################################## |
|
41
|
|
|
|
|
|
|
package StorageDisplay::Block; |
|
42
|
9
|
|
|
9
|
|
114
|
use Moose; |
|
|
9
|
|
|
|
|
17
|
|
|
|
9
|
|
|
|
|
84
|
|
|
43
|
9
|
|
|
9
|
|
65181
|
use namespace::sweep; |
|
|
9
|
|
|
|
|
19
|
|
|
|
9
|
|
|
|
|
124
|
|
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
extends 'StorageDisplay::BlockTreeElement'; |
|
46
|
|
|
|
|
|
|
|
|
47
|
9
|
|
|
9
|
|
7035
|
use Path::Class::Dir; |
|
|
9
|
|
|
|
|
365685
|
|
|
|
9
|
|
|
|
|
366
|
|
|
48
|
|
|
|
|
|
|
|
|
49
|
9
|
|
|
9
|
|
85
|
use Carp; |
|
|
9
|
|
|
|
|
23
|
|
|
|
9
|
|
|
|
|
6858
|
|
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
has 'names' => ( |
|
52
|
|
|
|
|
|
|
traits => [ 'Hash' ], |
|
53
|
|
|
|
|
|
|
is => 'ro', |
|
54
|
|
|
|
|
|
|
isa => 'HashRef[Path::Class::Dir]', |
|
55
|
|
|
|
|
|
|
required => 1, |
|
56
|
|
|
|
|
|
|
handles => { |
|
57
|
|
|
|
|
|
|
'addname' => 'set', |
|
58
|
|
|
|
|
|
|
'names_str' => 'keys', |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
); |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
has 'path' => ( |
|
63
|
|
|
|
|
|
|
is => 'rw', |
|
64
|
|
|
|
|
|
|
isa => 'Path::Class::Dir', |
|
65
|
|
|
|
|
|
|
required => 1, |
|
66
|
|
|
|
|
|
|
); |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
has 'state' => ( |
|
69
|
|
|
|
|
|
|
is => 'rw', |
|
70
|
|
|
|
|
|
|
isa => 'Str', |
|
71
|
|
|
|
|
|
|
default => 'unknown', |
|
72
|
|
|
|
|
|
|
lazy => 1, |
|
73
|
|
|
|
|
|
|
); |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
has 'elem' => ( |
|
76
|
|
|
|
|
|
|
is => 'ro', |
|
77
|
|
|
|
|
|
|
isa => 'StorageDisplay::Data::Elem', |
|
78
|
|
|
|
|
|
|
writer => '_elem', |
|
79
|
|
|
|
|
|
|
required => 0, |
|
80
|
|
|
|
|
|
|
); |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub provided { |
|
83
|
986
|
|
|
986
|
0
|
1939
|
my $self = shift; |
|
84
|
|
|
|
|
|
|
|
|
85
|
986
|
|
|
|
|
41959
|
return defined($self->elem); |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub providedBy { |
|
89
|
442
|
|
|
442
|
0
|
1106
|
my $self = shift; |
|
90
|
442
|
|
|
|
|
936
|
my $elem = shift; |
|
91
|
442
|
|
|
|
|
849
|
my $name = shift; |
|
92
|
|
|
|
|
|
|
|
|
93
|
442
|
50
|
|
|
|
1791
|
if ($self->provided) { |
|
94
|
0
|
|
|
|
|
0
|
croak "Duplicate provider for ".$self->name.": ".$self->elem." and ".$elem; |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
#print STDERR "Provider for ".$self->name.": ".$elem."\n"; |
|
97
|
442
|
|
|
|
|
18168
|
$self->_elem($elem); |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub dname { |
|
101
|
524
|
|
|
524
|
0
|
1334
|
my $self = shift; |
|
102
|
524
|
|
|
|
|
19925
|
my $best_name=$self->name; |
|
103
|
524
|
|
|
|
|
1373
|
my $score = 0; |
|
104
|
|
|
|
|
|
|
#print STDERR "name for ", $self->name, "\n"; |
|
105
|
|
|
|
|
|
|
#use Data::Dumper; |
|
106
|
|
|
|
|
|
|
#print STDERR Dumper($self->names), "\n"; |
|
107
|
524
|
|
|
|
|
24053
|
foreach my $n ($self->names_str) { |
|
108
|
3207
|
|
|
|
|
4539
|
my $s=0; |
|
109
|
3207
|
100
|
|
|
|
9627
|
if ($n =~ m,^disk/,) { |
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
110
|
2270
|
|
|
|
|
3458
|
$s = 20; |
|
111
|
|
|
|
|
|
|
} elsif ($n =~ m,^dm-,) { |
|
112
|
168
|
|
|
|
|
302
|
$s = 30; |
|
113
|
|
|
|
|
|
|
} elsif ($n =~ m,^mapper/,) { |
|
114
|
168
|
|
|
|
|
307
|
$s = 40; |
|
115
|
|
|
|
|
|
|
} elsif ($n =~ m,/,) { |
|
116
|
197
|
|
|
|
|
334
|
$s = 60; |
|
117
|
|
|
|
|
|
|
} else { |
|
118
|
404
|
|
|
|
|
798
|
$s = 50; |
|
119
|
|
|
|
|
|
|
} |
|
120
|
3207
|
100
|
100
|
|
|
9777
|
if ($s > $score) { |
|
|
|
100
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
#print STDERR " prefer($s) ", $n, "\n"; |
|
122
|
1064
|
|
|
|
|
1644
|
$score = $s; |
|
123
|
1064
|
|
|
|
|
1991
|
$best_name = $n; |
|
124
|
|
|
|
|
|
|
} elsif ($s == $score && $n gt $best_name) { |
|
125
|
|
|
|
|
|
|
#print STDERR " prefer($s/alpha) ", $n, "\n"; |
|
126
|
231
|
|
|
|
|
503
|
$best_name = $n; |
|
127
|
|
|
|
|
|
|
#} else { |
|
128
|
|
|
|
|
|
|
# print STDERR " reject($s) ", $n, "\n"; |
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
|
|
132
|
524
|
|
|
|
|
5300
|
return '/dev/'. |
|
133
|
|
|
|
|
|
|
$best_name; |
|
134
|
|
|
|
|
|
|
} |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
has 'size' => ( |
|
137
|
|
|
|
|
|
|
is => 'rw', |
|
138
|
|
|
|
|
|
|
isa => 'Int', |
|
139
|
|
|
|
|
|
|
lazy => 1, |
|
140
|
|
|
|
|
|
|
default => sub { |
|
141
|
|
|
|
|
|
|
my $self = shift; |
|
142
|
|
|
|
|
|
|
confess "Method 'size' not implemented or set in ".ref($self)."@".$self->name; |
|
143
|
|
|
|
|
|
|
#return -1; |
|
144
|
|
|
|
|
|
|
}, |
|
145
|
|
|
|
|
|
|
); |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub blk_info { |
|
148
|
10
|
|
|
10
|
0
|
14
|
my $self=shift; |
|
149
|
10
|
|
|
|
|
23
|
my $key=shift; |
|
150
|
10
|
|
|
|
|
36
|
return; |
|
151
|
|
|
|
|
|
|
} |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub udev_info { |
|
154
|
10
|
|
|
10
|
0
|
15
|
my $self=shift; |
|
155
|
10
|
|
|
|
|
15
|
my $key=shift; |
|
156
|
10
|
|
|
|
|
32
|
return; |
|
157
|
|
|
|
|
|
|
} |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
## function, not method |
|
160
|
|
|
|
|
|
|
sub asname { |
|
161
|
6
|
|
|
6
|
0
|
12
|
my $block = shift; |
|
162
|
6
|
|
|
|
|
8
|
my $blockname; |
|
163
|
|
|
|
|
|
|
|
|
164
|
6
|
100
|
66
|
|
|
60
|
if (blessed($block) && $block->isa("StorageDisplay::BlockTreeElement")) { |
|
165
|
3
|
|
|
|
|
118
|
$blockname = $block->name; |
|
166
|
|
|
|
|
|
|
} else { |
|
167
|
3
|
|
|
|
|
6
|
$blockname = $block; |
|
168
|
|
|
|
|
|
|
} |
|
169
|
6
|
|
|
|
|
39
|
return $blockname; |
|
170
|
|
|
|
|
|
|
} |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
1; |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
################################################################## |
|
175
|
|
|
|
|
|
|
package StorageDisplay::Block::NoSystem; |
|
176
|
9
|
|
|
9
|
|
100
|
use Moose; |
|
|
9
|
|
|
|
|
19
|
|
|
|
9
|
|
|
|
|
130
|
|
|
177
|
9
|
|
|
9
|
|
72138
|
use namespace::sweep; |
|
|
9
|
|
|
|
|
21
|
|
|
|
9
|
|
|
|
|
110
|
|
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
extends 'StorageDisplay::Block'; |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
has 'id' => ( |
|
182
|
|
|
|
|
|
|
is => 'ro', |
|
183
|
|
|
|
|
|
|
isa => 'Str', |
|
184
|
|
|
|
|
|
|
required => 0, |
|
185
|
|
|
|
|
|
|
); |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
has 'dname' => ( |
|
188
|
|
|
|
|
|
|
is => 'ro', |
|
189
|
|
|
|
|
|
|
isa => 'Str', |
|
190
|
|
|
|
|
|
|
required => 1, |
|
191
|
|
|
|
|
|
|
); |
|
192
|
|
|
|
|
|
|
|
|
193
|
9
|
|
|
9
|
|
1182
|
use Carp; |
|
|
9
|
|
|
|
|
23
|
|
|
|
9
|
|
|
|
|
2497
|
|
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
around BUILDARGS => sub { |
|
196
|
|
|
|
|
|
|
my $orig = shift; |
|
197
|
|
|
|
|
|
|
my $class = shift; |
|
198
|
|
|
|
|
|
|
my %args = (@_); |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
my $name = $args{'name'} // $args{'id'}; |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
my $dname = $args{'name'} // $args{'id'}; |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
return $class->$orig( |
|
205
|
|
|
|
|
|
|
'name' => $name, |
|
206
|
|
|
|
|
|
|
'dname' => $dname, |
|
207
|
|
|
|
|
|
|
'names' => { $name => Path::Class::Dir->new() }, |
|
208
|
|
|
|
|
|
|
'path' => Path::Class::Dir->new(), |
|
209
|
|
|
|
|
|
|
@_ |
|
210
|
|
|
|
|
|
|
); |
|
211
|
|
|
|
|
|
|
}; |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
################################################################## |
|
214
|
|
|
|
|
|
|
package StorageDisplay::Block::System; |
|
215
|
9
|
|
|
9
|
|
82
|
use Moose; |
|
|
9
|
|
|
|
|
20
|
|
|
|
9
|
|
|
|
|
73
|
|
|
216
|
9
|
|
|
9
|
|
73268
|
use namespace::sweep; |
|
|
9
|
|
|
|
|
21
|
|
|
|
9
|
|
|
|
|
64
|
|
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
extends 'StorageDisplay::Block'; |
|
219
|
|
|
|
|
|
|
|
|
220
|
9
|
|
|
9
|
|
1111
|
use Carp; |
|
|
9
|
|
|
|
|
22
|
|
|
|
9
|
|
|
|
|
5264
|
|
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
has '_blk_infos' => ( |
|
223
|
|
|
|
|
|
|
is => 'ro', |
|
224
|
|
|
|
|
|
|
isa => 'HashRef', |
|
225
|
|
|
|
|
|
|
traits => [ 'Hash' ], |
|
226
|
|
|
|
|
|
|
required => 1, |
|
227
|
|
|
|
|
|
|
handles => { |
|
228
|
|
|
|
|
|
|
'blk_info' => 'get', |
|
229
|
|
|
|
|
|
|
} |
|
230
|
|
|
|
|
|
|
); |
|
231
|
|
|
|
|
|
|
has '_udev_infos' => ( |
|
232
|
|
|
|
|
|
|
is => 'ro', |
|
233
|
|
|
|
|
|
|
isa => 'HashRef[Str]', |
|
234
|
|
|
|
|
|
|
traits => [ 'Hash' ], |
|
235
|
|
|
|
|
|
|
required => 1, |
|
236
|
|
|
|
|
|
|
handles => { |
|
237
|
|
|
|
|
|
|
'udev_info' => 'get', |
|
238
|
|
|
|
|
|
|
} |
|
239
|
|
|
|
|
|
|
); |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
sub size { |
|
242
|
131
|
|
|
131
|
0
|
375
|
my $self = shift; |
|
243
|
131
|
|
|
|
|
6507
|
return $self->blk_info('SIZE'); |
|
244
|
|
|
|
|
|
|
} |
|
245
|
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
sub kname { |
|
247
|
17
|
|
|
17
|
0
|
34
|
my $self = shift; |
|
248
|
17
|
|
|
|
|
719
|
return $self->blk_info('KNAME'); |
|
249
|
|
|
|
|
|
|
} |
|
250
|
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
around BUILDARGS => sub { |
|
252
|
|
|
|
|
|
|
my $orig = shift; |
|
253
|
|
|
|
|
|
|
my $class = shift; |
|
254
|
|
|
|
|
|
|
my $name = shift; |
|
255
|
|
|
|
|
|
|
my $st = shift; |
|
256
|
|
|
|
|
|
|
my $blk_info = $st->get_info('lsblk', $name); |
|
257
|
|
|
|
|
|
|
my %args; |
|
258
|
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
if ( @_ != 0 || ref $name ) { |
|
260
|
|
|
|
|
|
|
croak "Invalid call to new"; |
|
261
|
|
|
|
|
|
|
} |
|
262
|
|
|
|
|
|
|
my $f; |
|
263
|
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
my $udev_info = $st->get_info('udev', $name); |
|
265
|
|
|
|
|
|
|
foreach my $k (keys %{$udev_info}) { |
|
266
|
|
|
|
|
|
|
if ($k eq 'path') { |
|
267
|
|
|
|
|
|
|
$args{$k}=Path::Class::Dir->new($udev_info->{$k}); |
|
268
|
|
|
|
|
|
|
} elsif ($k eq 'names') { |
|
269
|
|
|
|
|
|
|
$args{$k} = { map { $_ => Path::Class::Dir->new($_) } @{$udev_info->{$k}} }; |
|
270
|
|
|
|
|
|
|
} else { |
|
271
|
|
|
|
|
|
|
$args{$k}=$udev_info->{$k}; |
|
272
|
|
|
|
|
|
|
} |
|
273
|
|
|
|
|
|
|
} |
|
274
|
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
if (defined($blk_info)) { |
|
276
|
|
|
|
|
|
|
my %hash; |
|
277
|
|
|
|
|
|
|
%hash = map { |
|
278
|
|
|
|
|
|
|
if (defined($blk_info->{$_})) { |
|
279
|
|
|
|
|
|
|
uc $_ => $blk_info->{$_} |
|
280
|
|
|
|
|
|
|
} else { |
|
281
|
|
|
|
|
|
|
() |
|
282
|
|
|
|
|
|
|
} |
|
283
|
|
|
|
|
|
|
} keys %$blk_info; |
|
284
|
|
|
|
|
|
|
$args{'_blk_infos'}=\%hash; |
|
285
|
|
|
|
|
|
|
} else { |
|
286
|
|
|
|
|
|
|
croak "coucou"; |
|
287
|
|
|
|
|
|
|
} |
|
288
|
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
return $class->$orig( |
|
290
|
|
|
|
|
|
|
%args, @_ |
|
291
|
|
|
|
|
|
|
); |
|
292
|
|
|
|
|
|
|
}; |
|
293
|
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
1; |
|
295
|
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
__END__ |
|
297
|
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
=pod |
|
299
|
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
=encoding UTF-8 |
|
301
|
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
=head1 NAME |
|
303
|
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
StorageDisplay::Block - Base package for block devices DAG |
|
305
|
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
=head1 VERSION |
|
307
|
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
version 2.06 |
|
309
|
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
=head1 AUTHOR |
|
311
|
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
Vincent Danjean <Vincent.Danjean@ens-lyon.org> |
|
313
|
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
315
|
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
This software is copyright (c) 2014-2023 by Vincent Danjean. |
|
317
|
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
319
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
320
|
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
=cut |