blib/lib/Linux/LVM.pm

filter: Statementstmt 7.3% 20 / 274 Branchbran 0.0% 0 / 162 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 33.3% 4 / 12 Podpod 0.0% 0 / 8 totaltotal 5.2% 24 / 456 CC 90 SCAR 69.4
CC
90
Cov
5%
get_vg_information
1980.0
get_lv_info
506.0
get_pv_info
342.0
CRAP 1035.4
↑ Summary
1 package Linux::LVM;
2  
3 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 require Exporter;
8 1 ▶use AutoLoader qw(AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 our @ISA = qw(Exporter);
11  
12 # Items to export into callers namespace by default. Note: do not export
13 # names by default without a very good reason. Use EXPORT_OK instead.
14 # Do not simply export all your public functions/methods/constants.
15  
16 # This allows declaration use Linux::LVM ':all';
17 # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
18 # will save memory.
19 1 our %EXPORT_TAGS = ( 'all' => [ qw( get_volume_group_list
20 get_volume_group_information
21 get_logical_volume_information
22 get_physical_volume_information
23 get_vg_information
24 get_pv_info
25 get_lv_info
26 ) ] );
27  
28 1 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
29  
30 1 our @EXPORT = qw( get_volume_group_list
31 get_volume_group_information
32 get_logical_volume_information
33 get_physical_volume_information
34 get_vg_information
35 get_pv_info
36 get_lv_info
37 );
38  
39 1 our $VERSION = '0.17';
40 1 our $units;
41  
42 # Preloaded methods go here.
43  
44 # Autoload methods go after =cut, and are processed by the autosplit program.
45  
46 #-----------------------------------------------------------------------#
47 # Subroutine: units #
48 #-----------------------------------------------------------------------#
49 # Description: Set units to be used for pe_size, lv_size, etc. #
50 # legal values are same as lvm --units: #
51 # hbskmgtpeHBSKMGTPE #
52 # (h)uman-readable, (b)ytes, (s)ectors, (k)ilobytes, #
53 # (m)egabytes, (g)igabytes, (t)erabytes, (p)etabytes, #
54 # (e)xabytes. Capitalise to use multiples of 1000 (S.I.) #
55 # instead of 1024. #
56 # Can also specify custom units e.g. --units 3M #
57 #-----------------------------------------------------------------------#
58 # Parameters: None #
59 #-----------------------------------------------------------------------#
60 # Return Values: On success, a array with the volume group names. #
61 #-----------------------------------------------------------------------#
62 0 ▶sub units {
Subroutine units: not called CC=2 SCAR=17.9
Pod undocumented
63 0 shift;
64 0 ▶ $units = shift() if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
65 0 return $units;
66 }
67  
68 #-----------------------------------------------------------------------#
69 # Subroutine: get_volume_group_list #
70 #-----------------------------------------------------------------------#
71 # Description: This function will return a sorted list of all of the #
72 # active volume groups on the system. #
73 #-----------------------------------------------------------------------#
74 # Parameters: None #
75 #-----------------------------------------------------------------------#
76 # Return Values: On success, a array with the volume group names. #
77 #-----------------------------------------------------------------------#
78 0 ▶sub get_volume_group_list() {
Subroutine get_volume_group_list: not called CC=1 SCAR=6.9
Pod undocumented
79 0 my %vg = get_vg_information();
80 0 return (sort keys(%vg));
81 } # End of the get_volume_group_list routine.
82  
83  
84 #-----------------------------------------------------------------------#
85 # Subroutine: get_volume_group_information #
86 #-----------------------------------------------------------------------#
87 # Description: This function will return a hash containing all of the #
88 # data about the specified volume group. #
89 #-----------------------------------------------------------------------#
90 # Parameters: A string containing a volume group name. #
91 #-----------------------------------------------------------------------#
92 # Return Values: On success, a hash with the volume group data. #
93 #-----------------------------------------------------------------------#
94 0 ▶sub get_volume_group_information($) {
Subroutine get_volume_group_information: not called CC=4 SCAR=30.0
Pod undocumented
95 0 my $volume_group = $_[0];
96 0 my %vg_info;
97 0 my %vg = get_vg_information();
98  
99 0 foreach(sort keys %{$vg{$volume_group}}) {
100 0 ▶ if ( $_ eq "pvols" ) { next; }
Branch: 2 branches
BranchTrueFalseTotal
if ($_ eq 'pvols') { } 0 0 0
elsif ($_ eq 'lvols') { } 0 0 0
101 0 elsif( $_ eq "lvols" ) { next; }
102 else {
103 0 $vg_info{$_} = $vg{$volume_group}->{$_};
104 }
105 }
106 0 return %vg_info;
107 } # End of the get_volume_group_information routine.
108  
109  
110 #-----------------------------------------------------------------------#
111 # Subroutine: get_volume_group_information #
112 #-----------------------------------------------------------------------#
113 # Description: This function will return a hash containing all of the #
114 # data about the specified volume group. #
115 #-----------------------------------------------------------------------#
116 # Parameters: A string containing a volume group name. #
117 #-----------------------------------------------------------------------#
118 # Return Values: On success, a hash with the volume group data. #
119 #-----------------------------------------------------------------------#
120 0 ▶sub get_logical_volume_information($) {
Subroutine get_logical_volume_information: not called CC=3 SCAR=24.8
Pod undocumented
121 0 my $volume_group = $_[0];
122 0 my %lv_info;
123 my $lvname;
124 0 my %vg = get_vg_information();
125  
126 0 foreach $lvname (sort keys %{$vg{$volume_group}->{lvols}}) {
127 0 foreach(sort keys %{$vg{$volume_group}->{lvols}->{$lvname}}) {
128 0 $lv_info{$lvname}->{$_} = $vg{$volume_group}->{lvols}->{$lvname}->{$_};
129 }
130 }
131 0 return %lv_info;
132 } # End of the get_logical_volume_information routine.
133  
134  
135 #-----------------------------------------------------------------------#
136 # Subroutine: get_volume_group_information #
137 #-----------------------------------------------------------------------#
138 # Description: This function will return a hash containing all of the #
139 # data about the specified volume group. #
140 #-----------------------------------------------------------------------#
141 # Parameters: A string containing a volume group name. #
142 #-----------------------------------------------------------------------#
143 # Return Values: On success, a hash with the volume group data. #
144 #-----------------------------------------------------------------------#
145 0 ▶sub get_physical_volume_information($) {
Subroutine get_physical_volume_information: not called CC=3 SCAR=24.8
Pod undocumented
146 0 my $volume_group = $_[0];
147 0 my %pv_info;
148 my $pvname;
149 0 my %vg = get_vg_information();
150  
151 0 foreach $pvname (sort keys %{$vg{$volume_group}->{pvols}}) {
152 0 foreach(sort keys %{$vg{$volume_group}->{pvols}->{$pvname}}) {
153 0 $pv_info{$pvname}->{$_} = $vg{$volume_group}->{pvols}->{$pvname}->{$_};
154 }
155 }
156 0 return %pv_info;
157 } # End of the get_physical_volume_information routine.
158  
159  
160 #-----------------------------------------------------------------------#
161 # Subroutine: get_vg_information #
162 #-----------------------------------------------------------------------#
163 # Description: This function will return a hash containing all of the #
164 # volume group information for the system. #
165 #-----------------------------------------------------------------------#
166 # Parameters: None #
167 #-----------------------------------------------------------------------#
168 # Return Values: On success, a hash with all of the vg information. #
169 #-----------------------------------------------------------------------#
170 0 ▶sub get_vg_information() {
Subroutine get_vg_information: not called CC=44 SCAR=75.9
Pod undocumented
171 0 my %vghash;
172 my $vgn;
173 0 my $lvn;
174 0 my $pvn;
175  
176 0 my @vginfo;
177
178 0 my $units_arg = '';
179 0 ▶ $units_arg = " --units $units " if ($units);
Branch: 1 branch
BranchTrueFalseTotal
if $Linux::LVM::units 0 0 0
180 0 ▶ if ( -e "/usr/sbin/vgdisplay" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e '/usr/sbin/vgdisplay') { } 0 0 0
181 0 @vginfo = `/usr/sbin/vgdisplay -v $units_arg`;
182 } else {
183 0 ▶ if( ! -e "/sbin/vgdisplay" ) { die("LVM utilities not installed in /sbin or /usr/sbin"); }
Branch: 1 branch
BranchTrueFalseTotal
unless (-e "/sbin/vgdisplay") 0 0 0
184 0 @vginfo = `/sbin/vgdisplay -v $units_arg`;
185 }
186  
187 0 VGINF: foreach(@vginfo) {
188 0 chomp;
189 0 s/^\s+//g;
190 0 s/\s+$//g;
191 0 ▶ next VGINF if m/^$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^$/ 0 0 0
192  
193 # Parse the volume group name.
194 0 ▶ if( m/VG Name\s+(\S+)/ ) {
Branch: 19 branches
BranchTrueFalseTotal
if (/VG Name\s+(\S+)/) { } 0 0 0
elsif (/VG Access\s+(\S+)/) { } 0 0 0
elsif (/VG Status\s+(.+)/) { } 0 0 0
elsif (/VG #\s+(\S+)/) { } 0 0 0
elsif (/MAX LV Size\s+(\S+) (\S+)/) { } 0 0 0
elsif (/MAX LV\s+(\S+)/) { } 0 0 0
elsif (/Cur LV\s+(\S+)/) { } 0 0 0
elsif (/Open LV\s+(\S+)/) { } 0 0 0
elsif (/Max PV\s+(\S+)/) { } 0 0 0
elsif (/Cur PV\s+(\S+)/) { } 0 0 0
elsif (/Act PV\s+(\S+)/) { } 0 0 0
elsif (/VG Size\s+(\S+) (\S+)/) { } 0 0 0
elsif (/PE Size\s+(\S+) (\S+)/) { } 0 0 0
elsif (m[Total PE / Free PE\s+(\S+) / (\S+)]m) { } 0 0 0
elsif (/Total PE\s+(\S+)/) { } 0 0 0
elsif (m[Alloc PE / Size\s+(\S+) / (\S+) (\S+)]) { } 0 0 0
elsif (m[Free PE / Size\s+(\S+) / (\S+) (\S+)]) { } 0 0 0
elsif (/VG UUID\s+(\S+)/) { } 0 0 0
elsif (/LV Name\s+(\S+)/) { } 0 0 0
195 0 $vgn = $1; $vghash{$vgn}->{vgname} = $1;
196 0 next VGINF; }
197  
198 # Parse the volume group access.
199 elsif( m/VG Access\s+(\S+)/ ) {
200 0 $vghash{$vgn}->{access} = $1;
201 0 next VGINF; }
202  
203 # Parse the volume group status.
204 elsif( m/VG Status\s+(.+)/ ) {
205 0 $vghash{$vgn}->{status} = $1;
206 0 next VGINF; }
207  
208 # Parse the volume group number.
209 elsif( m/VG #\s+(\S+)/ ) {
210 0 $vghash{$vgn}->{vg_number} = $1;
211 0 next VGINF; }
212  
213 # Parse the maximum logical volume size and size unit for the volume group.
214 elsif( m/MAX LV Size\s+(\S+) (\S+)/ ) {
215 0 $vghash{$vgn}->{max_lv_size} = $1;
216 0 $vghash{$vgn}->{max_lv_size_unit} = $2;
217 0 next VGINF; }
218  
219 # Parse the maximum number of logical volumes for the volume group.
220 elsif( m/MAX LV\s+(\S+)/ ) {
221 0 $vghash{$vgn}->{max_lv} = $1;
222 0 next VGINF; }
223  
224 # Parse the current number of logical volumes for the volume group.
225 elsif( m/Cur LV\s+(\S+)/ ) {
226 0 $vghash{$vgn}->{cur_lv} = $1;
227 0 next VGINF; }
228  
229 # Parse the number of open logical volumes for the volume group.
230 elsif( m/Open LV\s+(\S+)/ ) {
231 0 $vghash{$vgn}->{open_lv} = $1;
232 0 next VGINF; }
233  
234 # Parse the number of physical volumes accessible to the volume group.
235 elsif( m/Max PV\s+(\S+)/ ) {
236 0 $vghash{$vgn}->{max_pv} = $1;
237 0 next VGINF; }
238  
239 # Parse the current number of physical volumes in the volume group.
240 elsif( m/Cur PV\s+(\S+)/ ) {
241 0 $vghash{$vgn}->{cur_pv} = $1;
242 0 next VGINF; }
243  
244 # Parse the number of active physical volumes in the volume group.
245 elsif( m/Act PV\s+(\S+)/ ) {
246 0 $vghash{$vgn}->{act_pv} = $1;
247 0 next VGINF; }
248  
249 # Parse the size of the volume group.
250 elsif( m/VG Size\s+(\S+) (\S+)/ ) {
251 0 $vghash{$vgn}->{vg_size} = $1;
252 0 $vghash{$vgn}->{vg_size_unit} = $2;
253 0 next VGINF; }
254  
255 # Parse the physical extent size and unit for one extent of volume group.
256 elsif( m/PE Size\s+(\S+) (\S+)/ ) {
257 0 $vghash{$vgn}->{pe_size} = $1;
258 0 $vghash{$vgn}->{pe_size_unit} = $2;
259 0 next VGINF; }
260  
261 # Parse the total number and number of free physical extents from the physical disk.
262 elsif( m/Total PE \/ Free PE\s+(\S+) \/ (\S+)/m ) {
263 0 $vghash{$vgn}->{pvols}->{$pvn}->{total_pe} = $1;
264 0 $vghash{$vgn}->{pvols}->{$pvn}->{free_pe} = $2;
265 0 next VGINF; }
266  
267 # Parse the total number of physical extents from the volume group.
268 elsif( m/Total PE\s+(\S+)/ ) {
269 0 $vghash{$vgn}->{total_pe} = $1;
270 0 next VGINF; }
271  
272 # Parse the number of allocated physical extents from the volume group.
273 elsif( m/Alloc PE \/ Size\s+(\S+) \/ (\S+) (\S+)/ ) {
274 0 $vghash{$vgn}->{alloc_pe} = $1;
275 0 $vghash{$vgn}->{alloc_pe_size} = $2;
276 0 $vghash{$vgn}->{alloc_pe_size_unit} = $3;
277 0 next VGINF; }
278  
279 # Parse the volume group name.
280 elsif( m/Free PE \/ Size\s+(\S+) \/ (\S+) (\S+)/ ) {
281 0 $vghash{$vgn}->{free_pe} = $1;
282 0 $vghash{$vgn}->{free_pe_size} = $2;
283 0 $vghash{$vgn}->{free_pe_size_unit} = $3;
284 0 next VGINF; }
285  
286 # Parse the volume group uuid.
287 elsif( m/VG UUID\s+(\S+)/ ) {
288 0 $vghash{$vgn}->{uuid} = $1;
289 0 next VGINF; }
290  
291 # Parse the logical volume name.
292 elsif( m/LV Name\s+(\S+)/ ) {
293 0 $lvn = $1;
294 0 $vghash{$vgn}->{lvols}->{$lvn}->{name} = $1;
295 0 next VGINF; }
296  
297 # since version 2.02.89 'LV Name' is no longer the full path, 'LV Path' is.
298 # LV Path may be bogus or missing in some cases, such as thin pools.
299 0 ▶ if( m/LV Path\s+(\S+)/ ) {
Branch: 19 branches
BranchTrueFalseTotal
if (/LV Path\s+(\S+)/) { } 0 0 0
elsif (/LV UUID\s+(\S+)/) { } 0 0 0
elsif (/Segments\s+(\S+)/) { } 0 0 0
elsif (/LV Size\s+(\S+) (\S+)/) { } 0 0 0
elsif (/LV Write Access\s+(\S+)/) { } 0 0 0
elsif (/LV Status\s+(.+)/) { } 0 0 0
elsif (/Current LE\s+(\S+)/) { } 0 0 0
elsif (/Allocated LE\s+(\S+)/) { } 0 0 0
elsif (/Allocation\s+(.+)/) { } 0 0 0
elsif (/LV #\s+(\S+)/) { } 0 0 0
elsif (/# open\s+(\S+)/) { } 0 0 0
elsif (/Block device\s+(\S+)/) { } 0 0 0
elsif (/Read ahead sectors\s+(\S+)/) { } 0 0 0
elsif (/Allocated to snapshot\s+(\S+)%/) { } 0 0 0
elsif (/COW-table size\s+([0-9\.]+)\s+(\S+)/) { } 0 0 0
elsif (/Mirrored volumes\s+(.+)/) { } 0 0 0
elsif (/PV Name\s+(\S+)/) { } 0 0 0
elsif (/PV Status\s+(.+)/) { } 0 0 0
elsif (/PV UUID\s+(.+)/) { } 0 0 0
300 0 $vghash{$vgn}->{lvols}->{$lvn}->{name} = $1;
301 0 next LVINF; }
302  
303 # Parse the logical volume UUID.
304 elsif( m/LV UUID\s+(\S+)/ ) {
305 0 $vghash{$vgn}->{lvols}->{$lvn}->{uuid} = $1;
306 0 next VGINF; }
307  
308 # Parse the logical volume UUID.
309 elsif( m/Segments\s+(\S+)/ ) {
310 0 $vghash{$vgn}->{lvols}->{$lvn}->{segments} = $1;
311 0 next VGINF; }
312  
313 # Parse the logical volume size and unit.
314 elsif( m/LV Size\s+(\S+) (\S+)/ ) {
315 0 $vghash{$vgn}->{lvols}->{$lvn}->{lv_size} = $1;
316 0 $vghash{$vgn}->{lvols}->{$lvn}->{lv_size_unit} = $2;
317 0 next VGINF; }
318  
319 # Parse the logical volume write access.
320 elsif( m/LV Write Access\s+(\S+)/ ) {
321 0 $vghash{$vgn}->{lvols}->{$lvn}->{write_access} = $1;
322 0 next VGINF; }
323  
324 # Parse the logical volume status.
325 elsif( m/LV Status\s+(.+)/ ) {
326 0 $vghash{$vgn}->{lvols}->{$lvn}->{status} = $1;
327 0 next VGINF; }
328  
329 # Parse the number of logical extents in the logical volume.
330 elsif( m/Current LE\s+(\S+)/ ) {
331 0 $vghash{$vgn}->{lvols}->{$lvn}->{cur_le} = $1;
332 0 next VGINF; }
333  
334 # Parse the number of allocated logical extents in the logical volume.
335 elsif( m/Allocated LE\s+(\S+)/ ) {
336 0 $vghash{$vgn}->{lvols}->{$lvn}->{alloc_le} = $1;
337 0 next VGINF; }
338  
339 # Parse the allocation type for the logical volume.
340 elsif( m/Allocation\s+(.+)/ ) {
341 0 $vghash{$vgn}->{lvols}->{$lvn}->{allocation} = $1;
342 0 next VGINF; }
343  
344 # Parse the volume number.
345 elsif( m/LV #\s+(\S+)/ ) {
346 0 $vghash{$vgn}->{lvols}->{$lvn}->{lv_number} = $1;
347 0 next VGINF; }
348  
349 # Parse the number of times the logical volume is open.
350 elsif( m/# open\s+(\S+)/ ) {
351 0 $vghash{$vgn}->{lvols}->{$lvn}->{open_lv} = $1;
352 0 next VGINF; }
353  
354 # Parse the block device of the logical volume.
355 elsif( m/Block device\s+(\S+)/ ) {
356 0 $vghash{$vgn}->{lvols}->{$lvn}->{device} = $1;
357 0 next VGINF; }
358  
359 # Parse the value for the read ahead sectors of the logical volume.
360 elsif( m/Read ahead sectors\s+(\S+)/ ) {
361 0 $vghash{$vgn}->{lvols}->{$lvn}->{read_ahead} = $1;
362 0 next VGINF; }
363  
364  
365 elsif( m/Allocated to snapshot\s+(\S+)%/ ) {
366 0 $vghash{$vgn}->{lvols}->{$lvn}->{'allocated_to_snapshot'} = $1;
367 0 next VGINF; }
368  
369 elsif( m/COW-table size\s+([0-9\.]+)\s+(\S+)/ ) {
370 0 $vghash{$vgn}->{lvols}->{$lvn}->{'cow_table_size'} = $1;
371 0 $vghash{$vgn}->{lvols}->{$lvn}->{'cow_table_unit'} = $2;
372 0 next VGINF; }
373  
374 elsif( m/Mirrored volumes\s+(.+)/ ) {
375 0 $vghash{$vgn}->{lvols}->{$lvn}->{'mirrored_volumes'} = $1;
376 0 next VGINF; }
377  
378 # Parse the physical disk name.
379 elsif( m/PV Name\s+(\S+)/ ) {
380 0 $pvn = $1;
381 0 $vghash{$vgn}->{pvols}->{$pvn}->{device} = $1;
382 0 next VGINF; }
383  
384 # Parse the status of the physical disk.
385 elsif( m/PV Status\s+(.+)/ ) {
386 0 $vghash{$vgn}->{pvols}->{$pvn}->{status} = $1;
387 0 next VGINF; }
388  
389 # Parse the status of the physical disk.
390 elsif( m/PV UUID\s+(.+)/ ) {
391 0 $vghash{$vgn}->{pvols}->{$pvn}->{uuid} = $1;
392 0 next VGINF; }
393  
394 }
395 0 return %vghash;
396 } # End of the get_vg_information routine.
397  
398  
399 #-----------------------------------------------------------------------#
400 # Subroutine: get_pv_info #
401 #-----------------------------------------------------------------------#
402 # Description: This function will return a hash containing all of the #
403 # information about the specified physical volume. #
404 #-----------------------------------------------------------------------#
405 # Parameters: None #
406 #-----------------------------------------------------------------------#
407 # Return Values: On success, a hash with all of the pv information. #
408 #-----------------------------------------------------------------------#
409 0 ▶sub get_pv_info($) {
Subroutine get_pv_info: not called CC=18 SCAR=58.3
Pod undocumented
410 0 my $pvname = $_[0];
411 0 my %pvhash;
412 my @pvinfo;
413  
414 0 ▶ if( ! -e "$pvname" ) { die("Physical Disk: $pvname does not exist."); }
Branch: 1 branch
BranchTrueFalseTotal
unless (-e "$pvname") 0 0 0
415  
416 0 my $units_arg = '';
417 0 ▶ $units_arg = " --units $units " if ($units);
Branch: 1 branch
BranchTrueFalseTotal
if $Linux::LVM::units 0 0 0
418  
419 0 ▶ if ( -e "/usr/sbin/pvdisplay" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e '/usr/sbin/pvdisplay') { } 0 0 0
420 0 @pvinfo = `/usr/sbin/pvdisplay $units_arg $pvname`;
421 } else {
422 0 ▶ if( ! -e "/sbin/pvdisplay" ) { die("LVM utilities not installed in /sbin or /usr/sbin"); }
Branch: 1 branch
BranchTrueFalseTotal
unless (-e "/sbin/pvdisplay") 0 0 0
423 0 @pvinfo = `/sbin/pvdisplay $units_arg $pvname`;
424 }
425  
426  
427 0 PVINF: foreach(@pvinfo) {
428 # Get the name of the physical volume.
429 0 ▶ if( m/PV Name\s+(\S+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/PV Name\s+(\S+)/) 0 0 0
430 0 $pvhash{pv_name} = $1;
431 0 next PVINF; }
432  
433 # Get the name of the volume group the physical volume belongs to.
434 0 ▶ if( m/VG Name\s+(\S+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/VG Name\s+(\S+)/) 0 0 0
435 0 $pvhash{vg_name} = $1;
436 0 next PVINF; }
437  
438 # Get the size information of the physical volume.
439 0 ▶ if( m/PV Size\s+(\S+) (\S+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/PV Size\s+(\S+) (\S+)/) 0 0 0
440 0 $pvhash{size} = $1;
441 0 $pvhash{size_unit} = $2;
442 0 next PVINF; }
443  
444 # Get the physical volume number.
445 0 ▶ if( m/PV\#\s+(\S+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/PV\#\s+(\S+)/) 0 0 0
446 0 $pvhash{pv_number} = $1;
447 0 next PVINF; }
448  
449 # Get the status of the physical volume.
450 0 ▶ if( m/PV Status\s+(.+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/PV Status\s+(.+)/) 0 0 0
451 0 $pvhash{status} = $1;
452 0 next PVINF; }
453  
454 # Get the allocation status of the physical volume.
455 0 ▶ if( m/Allocatable\s+(.+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/Allocatable\s+(.+)/) 0 0 0
456 0 $pvhash{allocatable} = $1;
457 0 next PVINF; }
458  
459 # Get the number of logical volumes on the physical volume.
460 0 ▶ if( m/Cur LV\s+(\S+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/Cur LV\s+(\S+)/) 0 0 0
461 0 $pvhash{num_lvols} = $1;
462 0 next PVINF; }
463  
464 # Get the physical extent size and unit of the physical volume.
465 0 ▶ if( m/PE Size \((\S+)\)\s+(\S+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/PE Size \((\S+)\)\s+(\S+)/) 0 0 0
466 0 $pvhash{pe_size} = $2;
467 0 $pvhash{pe_size_unit} = $1;
468 0 next PVINF; }
469  
470 # Get the total numver of physical extents on the physical volume.
471 0 ▶ if( m/Total PE\s+(\S+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/Total PE\s+(\S+)/) 0 0 0
472 0 $pvhash{total_pe} = $1;
473 0 next PVINF; }
474  
475 # Get the number of free extents on the physical volume.
476 0 ▶ if( m/Free PE\s+(\S+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/Free PE\s+(\S+)/) 0 0 0
477 0 $pvhash{free_pe} = $1;
478 0 next PVINF; }
479  
480 # Get the number of allocated physical extents on the physical volume.
481 0 ▶ if( m/Allocated PE\s+(\S+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/Allocated PE\s+(\S+)/) 0 0 0
482 0 $pvhash{alloc_pe} = $1;
483 0 next PVINF; }
484  
485 # Get the UUID of the physical volume.
486 0 ▶ if( m/PV UUID\s+(\S+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/PV UUID\s+(\S+)/) 0 0 0
487 0 $pvhash{uuid} = $1;
488 0 next PVINF; }
489 }
490 0 return %pvhash;
491 } # End of the get_pv_info routine.
492  
493  
494 #-----------------------------------------------------------------------#
495 # Subroutine: get_lv_info #
496 #-----------------------------------------------------------------------#
497 # Description: This function will return a hash containing all of the #
498 # information about the specified logical volume. #
499 #-----------------------------------------------------------------------#
500 # Parameters: None #
501 #-----------------------------------------------------------------------#
502 # Return Values: On success, a hash with all of the lv information. #
503 #-----------------------------------------------------------------------#
504 0 ▶sub get_lv_info($) {
Subroutine get_lv_info: not called CC=22 SCAR=62.3
Pod undocumented
505 0 my $lvname = $_[0];
506 0 my %lvhash;
507 my @lvinfo;
508  
509 0 ▶ if( ! -e "$lvname" ) { die("Logical Disk: $lvname does not exist."); }
Branch: 1 branch
BranchTrueFalseTotal
unless (-e "$lvname") 0 0 0
510  
511 0 my $units_arg = '';
512 0 ▶ $units_arg = " --units $units " if ($units);
Branch: 1 branch
BranchTrueFalseTotal
if $Linux::LVM::units 0 0 0
513 0 ▶ if ( -e "/usr/sbin/vgdisplay" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e '/usr/sbin/vgdisplay') { } 0 0 0
514 0 @lvinfo = `/usr/sbin/lvdisplay $units_arg $lvname`;
515 } else {
516 0 ▶ if( ! -e "/sbin/vgdisplay" ) { die("LVM utilities not installed in /sbin or /usr/sbin"); }
Branch: 1 branch
BranchTrueFalseTotal
unless (-e "/sbin/vgdisplay") 0 0 0
517 0 @lvinfo = `/sbin/lvdisplay $units_arg $lvname`;
518 }
519  
520 0 LVINF: foreach(@lvinfo) {
521  
522 # Get the logical volume name.
523 0 ▶ if( m/LV Name\s+(\S+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/LV Name\s+(\S+)/) 0 0 0
524 0 $lvhash{lv_name} = $1;
525 0 next LVINF; }
526  
527  
528 # since version 2.02.89 'LV Name' is no longer the full path, 'LV Path' is.
529 # LV Path may be bogus or missing in some cases, such as thin pools.
530 0 ▶ if( m/LV Path\s+(\S+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/LV Path\s+(\S+)/) 0 0 0
531 0 $lvhash{lv_name} = $1;
532 0 next LVINF; }
533  
534 # Get the volume group name.
535 0 ▶ if( m/VG Name\s+(\S+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/VG Name\s+(\S+)/) 0 0 0
536 0 $lvhash{vg_name} = $1;
537 0 next LVINF; }
538  
539 # Get the volume group name.
540 0 ▶ if( m/LV UUID\s+(\S+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/LV UUID\s+(\S+)/) 0 0 0
541 0 $lvhash{uuid} = $1;
542 0 next LVINF; }
543  
544 # Get the logical volume write status.
545 0 ▶ if( m/LV Write Access\s+(.+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/LV Write Access\s+(.+)/) 0 0 0
546 0 $lvhash{access} = $1;
547 0 next LVINF; }
548  
549 # Get the logical volume status.
550 0 ▶ if( m/LV Status\s+(.+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/LV Status\s+(.+)/) 0 0 0
551 0 $lvhash{status} = $1;
552 0 next LVINF; }
553  
554 # Get the logical volume number.
555 0 ▶ if( m/LV \#\s+(\S+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/LV \#\s+(\S+)/) 0 0 0
556 0 $lvhash{lv_number} = $1;
557 0 next LVINF; }
558  
559 # Get the number of opens for the logical volume.
560 0 ▶ if( m/\# open\s+(\S+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/\# open\s+(\S+)/) 0 0 0
561 0 $lvhash{lv_open} = $1;
562 0 next LVINF; }
563  
564 # Get the logical volume size and size unit.
565 0 ▶ if( m/LV Size\s+(\S+) (\S+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/LV Size\s+(\S+) (\S+)/) 0 0 0
566 0 $lvhash{size} = $1;
567 0 $lvhash{size_unit} = $2;
568 0 next LVINF; }
569  
570 # Get the number of extents assigned to the logical volume.
571 0 ▶ if( m/Current LE\s+(\S+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/Current LE\s+(\S+)/) 0 0 0
572 0 $lvhash{current_le} = $1;
573 0 next LVINF; }
574  
575 # Get the number of extents allocated to the logical volume.
576 0 ▶ if( m/Allocated LE\s+(\S+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/Allocated LE\s+(\S+)/) 0 0 0
577 0 $lvhash{alloc_le} = $1;
578 0 next LVINF; }
579  
580 # Get the extent allocation type of the logical volume.
581 0 ▶ if( m/Allocation\s+(.+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/Allocation\s+(.+)/) 0 0 0
582 0 $lvhash{allocation} = $1;
583 0 next LVINF; }
584  
585 # Get the number of read ahead sectors for the logical volume.
586 0 ▶ if( m/Read ahead sectors\s+(\S+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/Read ahead sectors\s+(\S+)/) 0 0 0
587 0 $lvhash{read_ahead} = $1;
588 0 next LVINF; }
589  
590 # Get the block device of the logical volume.
591 0 ▶ if( m/Block device\s+(\S+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/Block device\s+(\S+)/) 0 0 0
592 0 $lvhash{block_device} = $1;
593 0 next LVINF; }
594  
595 0 ▶ if( m/Allocated to snapshot\s+(\S+)%/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if (/Allocated to snapshot\s+(\S+)%/) { } 0 0 0
elsif (/COW-table size\s+([0-9\.]+)\s+(\S+)/) { } 0 0 0
596 0 $lvhash{allocated_to_snapshot} = $1;
597 0 next LVINF; }
598  
599 elsif( m/COW-table size\s+([0-9\.]+)\s+(\S+)/ ) {
600 0 $lvhash{'cow_table_size'} = $1;
601 0 $lvhash{'cow_table_unit'} = $2;
602 0 next LVINF; }
603 }
604 0 return %lvhash;
605 } # End of the get_lv_info routine.
606  
607  
608 1 1;
609 __END__
↑ Summary