LVM2.pm

filter: Statementstmt 27.6% 57 / 206 Branchbran 0.0% 0 / 74 Conditioncond 0.0% 0 / 48 MC/DCmcdc 0.0% 0 / 26 Subroutinesub 58.6% 17 / 29 Podpod 100% 5 / 5 totaltotal 20.3% 79 / 388 CC 66 SCAR 72.5
CC
66
Cov
17%
_find_vgs
2524.4
lv_from_dev
56.0
is_lv
30.0
CRAP 1403.2
↑ Summary LVM2/Utils.pm »
1 package Linux::LVM2;
2 {
3 3 $Linux::LVM2::VERSION = '0.14';
4 }
5 3 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 $Linux::LVM2::AUTHORITY = 'cpan:TEX';
7 }
8 # ABSTRACT: a Linux LVM2 wrapper.
9  
10 3 ▶use 5.010_000;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use mro 'c3';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use feature ':5.10';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 3 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 3 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 # use IO::Handle;
18 # use autodie;
19 # use MooseX::Params::Validate;
20  
21 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 3 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 3 ▶use Linux::LVM2::VG;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 3 ▶use Linux::LVM2::PV;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 3 ▶use Linux::LVM2::LV;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 3 ▶use Linux::LVM2::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 3 ▶use Sys::FS;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 3 ▶use Sys::Run;
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 3 has 'vgs' => (
32 'is' => 'ro',
33 'isa' => 'HashRef[Linux::LVM2::VG]',
34 'lazy' => 1,
35 'builder' => '_find_vgs',
36 );
37  
38 3 has 'verbose' => (
39 'is' => 'rw',
40 'isa' => 'Bool',
41 'default' => 0,
42 );
43  
44 3 has 'logger' => (
45 'is' => 'ro',
46 'isa' => 'Log::Tree',
47 'required' => 1,
48 );
49  
50 3 has 'sys' => (
51 'is' => 'rw',
52 'isa' => 'Sys::Run',
53 'lazy' => 1,
54 'builder' => '_init_sys',
55 );
56  
57 3 has 'fs' => (
58 'is' => 'rw',
59 'isa' => 'Sys::FS',
60 'lazy' => 1,
61 'builder' => '_init_fs',
62 );
63  
64 0 ▶sub _init_sys {
Subroutine _init_sys: not called CC=1 SCAR=6.9
65 0 my $self = shift;
66  
67 0 my $Sys = Sys::Run::->new( { 'logger' => $self->logger(), } );
68  
69 0 return $Sys;
70 }
71  
72 0 ▶sub _init_fs {
Subroutine _init_fs: not called CC=1 SCAR=6.9
73 0 my $self = shift;
74  
75 0 my $FS = Sys::FS::->new(
76 {
77 'logger' => $self->logger(),
78 'sys' => $self->sys(),
79 }
80 );
81  
82 0 return $FS;
83 }
84  
85 0 ▶sub _find_vgs {
Subroutine _find_vgs: not called CC=52 SCAR=78.3
86 0 my $self = shift;
87 0 ▶ my $vg_ref = shift || {};
Condition0%0/2
shift() || {}
l!l
00
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
88  
89 0 my %sbin = ();
90 0 $sbin{'vgdisplay'} = '/sbin/vgdisplay';
91 0 $sbin{'lvdisplay'} = '/sbin/lvdisplay';
92 0 $sbin{'lvs'} = '/sbin/lvs';
93 0 $sbin{'pvdisplay'} = '/sbin/pvdisplay';
94  
95 0 foreach my $key ( keys %sbin ) {
96 0 ▶ if ( !-x $sbin{$key} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-x $sbin{$key}) 0 0 0
97 0 croak( 'Binary not executeable: ' . $sbin{$key} );
98 }
99 }
100  
101 # read in the command output in a batch,
102 # keep the disabled warnings and output redirect as contained
103 # and brief as possible.
104 0 my ( @vgdisplay, @lvdisplay, @lvs, @pvdisplay );
105 {
106  
107 # redirect stderr, to get rid of those useless lvm warnings
108 ## no critic (ProhibitTwoArgOpen ProhibitBarewordFileHandles ProhibitNoWarnings RequireCheckedOpen RequireBriefOpen)
109 0 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.2
110 0 ▶ open( OLDSTDERR, '>&STDERR' ) unless $self->verbose();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->verbose 0 0 0
111 3 ▶ use warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
112 0 ▶ open( STDERR, '/dev/null' ) unless $self->verbose();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->verbose 0 0 0
113 ## use critic
114  
115 ## no critic (RequireCheckedClose ProhibitPunctuationVars)
116 0 local $ENV{LANG} = q{C};
117 open( my $VGS, '-|', $sbin{'vgdisplay'} . ' -c' )
118 0 ▶ or confess('Could not execute '.$sbin{'vgdisplay'}.'! Is LVM2 installed?: '.$!."\n");
Branch: 1 branch
BranchTrueFalseTotal
open my $VGS, "-|", $sbin{"vgdisplay"} . ' -c' or confess('Could not execute ' . $sbin{"vgdisplay"} . '! Is LVM2 installed?: ' . $! . "\n") 0 0 0
119 0 @vgdisplay = <$VGS>;
120 0 close($VGS);
121 open( my $PVS, '-|', $sbin{'pvdisplay'} . ' -c' )
122 0 ▶ or confess('Could not execute '.$sbin{'pvdisplay'}.'! Is LVM2 installed?: '.$!."\n");
Branch: 1 branch
BranchTrueFalseTotal
open my $PVS, "-|", $sbin{"pvdisplay"} . ' -c' or confess('Could not execute ' . $sbin{"pvdisplay"} . '! Is LVM2 installed?: ' . $! . "\n") 0 0 0
123 0 @pvdisplay = <$PVS>;
124 0 close($PVS);
125 open( my $LVD, '-|', $sbin{'lvdisplay'} . ' -c' )
126 0 ▶ or confess('Could not execute '.$sbin{'lvdisplay'}.'! Is LVM2 installed?: '.$!."\n");
Branch: 1 branch
BranchTrueFalseTotal
open my $LVD, "-|", $sbin{"lvdisplay"} . ' -c' or confess('Could not execute ' . $sbin{"lvdisplay"} . '! Is LVM2 installed?: ' . $! . "\n") 0 0 0
127 0 @lvdisplay = <$LVD>;
128 0 close($LVD);
129 open( my $LVS, '-|', $sbin{'lvs'} . ' --separator=: --units=b' )
130 0 ▶ or confess('Could not execute '.$sbin{'lvs'}.'! Is LVM2 installed?: '.$!."\n");
Branch: 1 branch
BranchTrueFalseTotal
open my $LVS, "-|", $sbin{"lvs"} . ' --separator=: --units=b' or confess('Could not execute ' . $sbin{"lvs"} . '! Is LVM2 installed?: ' . $! . "\n") 0 0 0
131 0 @lvs = <$LVS>;
132 0 close($LVS);
133 ## use critic
134  
135 ## no critic (ProhibitTwoArgOpen)
136 0 ▶ open( STDERR, '>&OLDSTDERR' ) unless $self->verbose();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->verbose 0 0 0
137 ## use critic
138 }
139  
140 # Process all VGs
141 0 foreach my $line (@vgdisplay) {
142 0 ▶ next unless $line;
Branch: 1 branch
BranchTrueFalseTotal
unless $line 0 0 0
143 0 chomp($line);
144 0 $line =~ s/^\s+//;
145 0 $line =~ s/\s+$//;
146 0 ▶ next unless $line;
Branch: 1 branch
BranchTrueFalseTotal
unless $line 0 0 0
147 0 my %h;
148 0 @h{qw(name access status vgid maxlvs curlvs openlvs maxlvsize maxpvs curpvs numpvs vgsize pesize totalpe allocpe freepe uuid)} = split( /:/, $line );
149 0 $h{'parent'} = $self;
150  
151 # if the object exists, just update it
152 0 ▶ if ( $vg_ref->{ $h{'name'} } && $vg_ref->{ $h{'name'} }->isa('Linux::LVM2::VG') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$vg_ref{$h{'name'}} and $$vg_ref{$h{'name'}}->isa('Linux::LVM2::VG')) { } 0 0 0
Condition0%0/3
$$vg_ref{$h{"name"}} and $$vg_ref{$h{"name"}}->isa("Linux::LVM2::VG")
!ll&&!rl&&r
000
MC/DC0%0/2
$$vg_ref{$h{"name"}} and $$vg_ref{$h{"name"}}->isa("Linux::LVM2::VG")
$$vg_ref{$h{"name"}} $$vg_ref{$h{"name"}}->isa("Linux::LVM2::VG")
Truth table0%0/3
A and B
A= $$vg_ref{$h{"name"}}B= $$vg_ref{$h{"name"}}->isa("Linux::LVM2::VG")
ABresult
0X0
100
111
153  
154 # some attrs are read-only, just update those which are rw
155 0 foreach my $attr ( keys %h ) {
156 0 ▶ try {
Subroutine __ANON__: not called CC=1 SCAR=6.9
157 0 $vg_ref->{ $h{'name'} }->$attr( $h{$attr} );
158 0 };
159 }
160 }
161 else {
162 0 $vg_ref->{ $h{'name'} } = Linux::LVM2::VG::->new( \%h );
163 }
164 }
165  
166 # Process all PVs
167 0 foreach my $line (@pvdisplay) {
168 0 ▶ next unless $line;
Branch: 1 branch
BranchTrueFalseTotal
unless $line 0 0 0
169 0 chomp($line);
170 0 $line =~ s/^\s+//;
171 0 $line =~ s/\s+$//;
172 0 ▶ next unless $line;
Branch: 1 branch
BranchTrueFalseTotal
unless $line 0 0 0
173 0 my %h;
174 0 @h{qw(name vg size pesize totalpe freepe allocpe uuid)} = split( /:/, $line );
175 0 ▶ if ( $h{'vg'} && $vg_ref->{ $h{'vg'} } && $vg_ref->{ $h{'vg'} }->isa('Linux::LVM2::VG') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($h{'vg'} and $$vg_ref{$h{'vg'}} and $$vg_ref{$h{'vg'}}->isa('Linux::LVM2::VG')) { } 0 0 0
Condition0%0/6
$h{"vg"} and $$vg_ref{$h{"vg"}} and $$vg_ref{$h{"vg"}}->isa("Linux::LVM2::VG")
!ll&&!rl&&r
000
$h{"vg"} and $$vg_ref{$h{"vg"}}
!ll&&!rl&&r
000
MC/DC0%0/3
$h{"vg"} and $$vg_ref{$h{"vg"}} and $$vg_ref{$h{"vg"}}->isa("Linux::LVM2::VG")
$h{"vg"} $$vg_ref{$h{"vg"}} $$vg_ref{$h{"vg"}}->isa("Linux::LVM2::VG")
Truth table0%0/4
A and B and C
A= $h{"vg"}B= $$vg_ref{$h{"vg"}}C= $$vg_ref{$h{"vg"}}->isa("Linux::LVM2::VG")
ABCresult
0XX0
10X0
1100
1111
176  
177 0 ▶ if ( $vg_ref->{ $h{'vg'} }->pvs()->{ $h{'name'} } && $vg_ref->{ $h{'vg'} }->pvs()->{ $h{'name'} }->isa('Linux::LVM2::PV') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$vg_ref{$h{'vg'}}->pvs->{$h{'name'}} and $$vg_ref{$h{'vg'}}->pvs->{$h{'name'}}->isa('Linux::LVM2::PV')) { } 0 0 0
Condition0%0/3
$$vg_ref{$h{"vg"}}->pvs->{$h{"name"}} and $$vg_ref{$h{"vg"}}->pvs->{$h{"name"}}->isa("Linux::LVM2::PV")
!ll&&!rl&&r
000
MC/DC0%0/2
$$vg_ref{$h{"vg"}}->pvs->{$h{"name"}} and $$vg_ref{$h{"vg"}}->pvs->{$h{"name"}}->isa("Linux::LVM2::PV")
$$vg_ref{$h{"vg"}}->pvs->{$h{"name"}} $$vg_ref{$h{"vg"}}->pvs->{$h{"name"}}->isa("Linux::LVM2::PV")
Truth table0%0/3
A and B
A= $$vg_ref{$h{"vg"}}->pvs->{$h{"name"}}B= $$vg_ref{$h{"vg"}}->pvs->{$h{"name"}}->isa("Linux::LVM2::PV")
ABresult
0X0
100
111
178 0 foreach my $attr ( keys %h ) {
179 0 ▶ try {
Subroutine __ANON__: not called CC=1 SCAR=6.9
180 0 $vg_ref->{ $h{'vg'} }->pvs()->{ $h{'name'} }->$attr( $h{$attr} );
181 0 };
182 }
183 }
184 else {
185 0 $h{'vg'} = $vg_ref->{ $h{'vg'} };
186 0 my $PV = Linux::LVM2::PV::->new( \%h );
187  
188 # no need to do anything with $PV, its constructor will attach itself
189 # to the vg passed it will be reachable via the associated VG
190 }
191 }
192 else {
193 0 next;
194 }
195  
196 }
197  
198 # Process each LV (from lvdisplay)
199 0 foreach my $line (@lvdisplay) {
200 0 ▶ next unless $line;
Branch: 1 branch
BranchTrueFalseTotal
unless $line 0 0 0
201 0 chomp($line);
202 0 $line =~ s/^\s+//;
203 0 $line =~ s/\s+$//;
204 0 ▶ next unless $line;
Branch: 1 branch
BranchTrueFalseTotal
unless $line 0 0 0
205 0 my %h;
206 0 @h{qw(name vg access status intlvnum opencount lvsize leassoc lealloc allocpol rasect majornum minornum)} = split( /:/, $line );
207 0 $h{'name'} =~ s#^/dev/##;
208 0 $h{'name'} =~ s#^$h{'vg'}/##;
209  
210 0 ▶ if ( $h{'vg'} && $vg_ref->{ $h{'vg'} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($h{'vg'} and $$vg_ref{$h{'vg'}}) { } 0 0 0
Condition0%0/3
$h{"vg"} and $$vg_ref{$h{"vg"}}
!ll&&!rl&&r
000
MC/DC0%0/2
$h{"vg"} and $$vg_ref{$h{"vg"}}
$h{"vg"} $$vg_ref{$h{"vg"}}
Truth table0%0/3
A and B
A= $h{"vg"}B= $$vg_ref{$h{"vg"}}
ABresult
0X0
100
111
211 0 ▶ if ( $vg_ref->{ $h{'vg'} }->lvs()->{ $h{'name'} } && $vg_ref->{ $h{'vg'} }->lvs()->{ $h{'name'} }->isa('Linux::LVM2::LV') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$vg_ref{$h{'vg'}}->lvs->{$h{'name'}} and $$vg_ref{$h{'vg'}}->lvs->{$h{'name'}}->isa('Linux::LVM2::LV')) { } 0 0 0
Condition0%0/3
$$vg_ref{$h{"vg"}}->lvs->{$h{"name"}} and $$vg_ref{$h{"vg"}}->lvs->{$h{"name"}}->isa("Linux::LVM2::LV")
!ll&&!rl&&r
000
MC/DC0%0/2
$$vg_ref{$h{"vg"}}->lvs->{$h{"name"}} and $$vg_ref{$h{"vg"}}->lvs->{$h{"name"}}->isa("Linux::LVM2::LV")
$$vg_ref{$h{"vg"}}->lvs->{$h{"name"}} $$vg_ref{$h{"vg"}}->lvs->{$h{"name"}}->isa("Linux::LVM2::LV")
Truth table0%0/3
A and B
A= $$vg_ref{$h{"vg"}}->lvs->{$h{"name"}}B= $$vg_ref{$h{"vg"}}->lvs->{$h{"name"}}->isa("Linux::LVM2::LV")
ABresult
0X0
100
111
212 0 foreach my $attr ( keys %h ) {
213  
214 # some attrs are read-only, just update those which are rw
215 0 ▶ try {
Subroutine __ANON__: not called CC=1 SCAR=6.9
216 0 $vg_ref->{ $h{'vg'} }->lvs()->{ $h{'name'} }->$attr( $h{$attr} );
217 0 };
218 }
219 }
220 else {
221 0 $h{'vg'} = $vg_ref->{ $h{'vg'} };
222 0 my $VG = Linux::LVM2::LV::->new( \%h );
223  
224 # no need to do anything with $VG, its constructor will attach itself
225 # to the vg passed it will be reachable via the associated VG
226 }
227 }
228 else {
229 0 next;
230 }
231 }
232  
233 # Try to get mount points for mounted devices
234 0 my $mounts = $self->fs()->mounts( { 'DevAsKey' => 1, } );
235  
236 # Process each LV (from LVs, provides additional information about Snapshot and Copy Progress)
237 0 foreach my $line (@lvs) {
238 0 ▶ next unless $line;
Branch: 1 branch
BranchTrueFalseTotal
unless $line 0 0 0
239 0 ▶ next if $line =~ m/\s*LV:VG:Attr/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /\s*LV:VG:Attr/ 0 0 0
240 0 chomp($line);
241 0 $line =~ s/^\s+//;
242 0 $line =~ s/\s+$//;
243 0 ▶ next unless $line;
Branch: 1 branch
BranchTrueFalseTotal
unless $line 0 0 0
244 0 my %h;
245 0 @h{qw(name vg attr lsize origin snap_pc move log copy_pc convert)} = split( /:/, $line );
246  
247 0 ▶ if ( $h{'vg'} && $h{'name'} && $vg_ref->{ $h{'vg'} } && $vg_ref->{ $h{'vg'} }->lvs()->{ $h{'name'} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($h{"vg"} and $h{"name"} and $$vg_ref{$h{"vg"}} and $$vg_ref{$h{"vg"}}->lvs->{$h{"name"}}) 0 0 0
Condition0%0/9
$h{"vg"} and $h{"name"} and $$vg_ref{$h{"vg"}} and $$vg_ref{$h{"vg"}}->lvs->{$h{"name"}}
!ll&&!rl&&r
000
$h{"vg"} and $h{"name"} and $$vg_ref{$h{"vg"}}
!ll&&!rl&&r
000
$h{"vg"} and $h{"name"}
!ll&&!rl&&r
000
MC/DC0%0/4
$h{"vg"} and $h{"name"} and $$vg_ref{$h{"vg"}} and $$vg_ref{$h{"vg"}}->lvs->{$h{"name"}}
$h{"vg"} $h{"name"} $$vg_ref{$h{"vg"}} $$vg_ref{$h{"vg"}}->lvs->{$h{"name"}}
Truth table0%0/5
A and B and C and D
A= $h{"vg"}B= $h{"name"}C= $$vg_ref{$h{"vg"}}D= $$vg_ref{$h{"vg"}}->lvs->{$h{"name"}}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
248 0 my $lv = $vg_ref->{ $h{'vg'} }->lvs()->{ $h{'name'} };
249  
250 # convert percent
251 0 foreach my $key (qw(snap_pc copy_pc)) {
252 0 ▶ $h{$key} ||= 0;
Condition0%0/2
$h{$key} ||= 0
l!l
00
MC/DC0%0/1
$h{$key} ||= 0
$h{$key}
Truth table0%0/2
A
A= $h{$key}
Aresult
11
00
253 0 $h{$key} = int( $h{$key} * 100 );
254 }
255  
256 # set parameters
257 0 foreach my $attr (qw(snap_pc move log copy_pc convert)) {
258 0 ▶ try {
Subroutine __ANON__: not called CC=2 SCAR=17.9
259 0 ▶ $h{$attr} ||= q{};
Condition0%0/2
$h{$attr} ||= ""
l!l
00
MC/DC0%0/1
$h{$attr} ||= ""
$h{$attr}
Truth table0%0/2
A
A= $h{$attr}
Aresult
11
00
260 0 $lv->$attr( $h{$attr} );
261 0 };
262 }
263  
264 # set origin of the new LV
265 0 ▶ if ( $h{'origin'} && $vg_ref->{ $h{'vg'} }->lvs()->{ $h{'origin'} } && $vg_ref->{ $h{'vg'} }->lvs()->{ $h{'origin'} }->isa('Linux::LVM2::LV') ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($h{'origin'} and $$vg_ref{$h{'vg'}}->lvs->{$h{'origin'}} and $$vg_ref{$h{'vg'}}->lvs->{$h{'origin'}}->isa('Linux::LVM2::LV')) { } 0 0 0
elsif ($h{'origin'}) { } 0 0 0
Condition0%0/6
$h{"origin"} and $$vg_ref{$h{"vg"}}->lvs->{$h{"origin"}} and $$vg_ref{$h{"vg"}}->lvs->{$h{"origin"}}->isa("Linux::LVM2::LV")
!ll&&!rl&&r
000
$h{"origin"} and $$vg_ref{$h{"vg"}}->lvs->{$h{"origin"}}
!ll&&!rl&&r
000
MC/DC0%0/3
$h{"origin"} and $$vg_ref{$h{"vg"}}->lvs->{$h{"origin"}} and $$vg_ref{$h{"vg"}}->lvs->{$h{"origin"}}->isa("Linux::LVM2::LV")
$h{"origin"} $$vg_ref{$h{"vg"}}->lvs->{$h{"origin"}} $$vg_ref{$h{"vg"}}->lvs->{$h{"origin"}}->isa("Linux::LVM2::LV")
Truth table0%0/4
A and B and C
A= $h{"origin"}B= $$vg_ref{$h{"vg"}}->lvs->{$h{"origin"}}C= $$vg_ref{$h{"vg"}}->lvs->{$h{"origin"}}->isa("Linux::LVM2::LV")
ABCresult
0XX0
10X0
1100
1111
266 0 $lv->origin( $vg_ref->{ $h{'vg'} }->lvs()->{ $h{'origin'} } );
267 }
268 elsif ( $h{'origin'} ) {
269 0 confess("Did not find origin ($h{'origin'}) of LV $h{'name'}. This is impossible!");
270 }
271  
272 # set mount point
273 0 ▶ if ( $mounts->{ $lv->mapper_path() } ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($$mounts{$lv->mapper_path}) { } 0 0 0
elsif ($$mounts{$lv->full_path}) { } 0 0 0
274 0 $lv->mount_point( $mounts->{ $lv->mapper_path() }{'mount_point'} );
275 }
276 elsif ( $mounts->{ $lv->full_path() } ) {
277 0 $lv->mount_point( $mounts->{ $lv->full_path() }{'mount_point'} );
278 }
279 else {
280 0 ▶ warn 'No mount point found for LV ' . $lv->full_path() . "\n" if $self->verbose();
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 0 0 0
281 }
282 }
283 }
284  
285 0 return $vg_ref;
286 }
287  
288 0 ▶sub is_lv {
Subroutine is_lv: not called CC=5 SCAR=34.0
Pod documented
289 0 my $self = shift;
290 0 my $vg_name = shift;
291 0 my $lv_name = shift;
292  
293 0 foreach my $vg ( keys %{ $self->vgs() } ) {
294 0 ▶ next if $vg_name && $vg ne $vg_name;
Branch: 1 branch
BranchTrueFalseTotal
if $vg_name and $vg ne $vg_name 0 0 0
Condition0%0/3
$vg_name and $vg ne $vg_name
!ll&&!rl&&r
000
MC/DC0%0/2
$vg_name and $vg ne $vg_name
$vg_name $vg ne $vg_name
Truth table0%0/3
A and B
A= $vg_nameB= $vg ne $vg_name
ABresult
0X0
100
111
295 0 ▶ if ( $self->vgs()->{$vg}->lvs()->{$lv_name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->vgs->{$vg}->lvs->{$lv_name}) 0 0 0
296 0 return 1;
297 }
298 }
299 0 return;
300 }
301  
302 0 ▶sub is_vg {
Subroutine is_vg: not called CC=2 SCAR=17.9
Pod documented
303 0 my $self = shift;
304 0 my $vg_name = shift;
305  
306 0 ▶ if ( $self->vgs()->{$vg_name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->vgs->{$vg_name}) { } 0 0 0
307 0 return 1;
308 }
309 else {
310 0 return;
311 }
312 }
313  
314 0 ▶sub lv_from_path {
Subroutine lv_from_path: not called CC=3 SCAR=24.8
Pod documented
315 0 my $self = shift;
316 0 my $path = shift;
317  
318 # find out which device $path is located
319 0 my ( $device, $fs_type, $fs_options, $mount_point ) = $self->fs()->get_mounted_device($path);
320  
321 0 my $LV = $self->lv_from_dev($device);
322 0 ▶ if ($LV) {
Branch: 1 branch
BranchTrueFalseTotal
if ($LV) { } 0 0 0
323 0 $LV->fs_type($fs_type);
324 0 $LV->fs_options($fs_options);
325 0 $LV->mount_point($mount_point);
326 0 return $LV;
327 }
328 else {
329 0 ▶ carp "Did not find lv from given path $path\n" if $self->verbose();
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 0 0 0
330 }
331 0 return;
332 }
333  
334 0 ▶sub lv_from_dev {
Subroutine lv_from_dev: not called CC=7 SCAR=40.3
Pod documented
335 0 my $self = shift;
336 0 my $dev = shift;
337  
338 0 ▶ if ( $dev =~ m#/mapper/# ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dev =~ m[/mapper/]) 0 0 0
339 0 ▶ warn "Trying to translate dev-mapper name to lvm name $dev\n" if $self->verbose();
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 0 0 0
340 0 $dev = Linux::LVM2::Utils::translate_lvm_name($dev);
341 0 ▶ warn "Translated to $dev\n" if $self->verbose();
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 0 0 0
342 }
343 0 $dev =~ s#^/dev/##;
344 0 $dev =~ s#/$##;
345  
346 0 my ( $vg, $lv ) = split /\//, $dev;
347  
348 0 ▶ if ( $vg && $lv && $self->is_lv( $vg, $lv ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($vg and $lv and $self->is_lv($vg, $lv)) 0 0 0
Condition0%0/6
$vg and $lv and $self->is_lv($vg, $lv)
!ll&&!rl&&r
000
$vg and $lv
!ll&&!rl&&r
000
MC/DC0%0/3
$vg and $lv and $self->is_lv($vg, $lv)
$vg $lv $self->is_lv($vg, $lv)
Truth table0%0/4
A and B and C
A= $vgB= $lvC= $self->is_lv($vg, $lv)
ABCresult
0XX0
10X0
1100
1111
349 0 return $self->vgs()->{$vg}->lvs()->{$lv};
350 }
351  
352 # no lv found
353 0 return;
354 }
355  
356 0 ▶sub update {
Subroutine update: not called CC=1 SCAR=6.9
Pod documented
357 0 my $self = shift;
358 0 $self->_find_vgs( $self->vgs() );
359 0 return 1;
360 }
361  
362 3 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
363 3 __PACKAGE__->meta->make_immutable;
364  
365 3 1;
366  
367 __END__
↑ Summary LVM2/Utils.pm »