| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# |
|
2
|
|
|
|
|
|
|
# PurePerl implementation glue to '/usr/sbin/lfs' |
|
3
|
|
|
|
|
|
|
# |
|
4
|
|
|
|
|
|
|
# (C) 2010 Adrian Ulrich - |
|
5
|
|
|
|
|
|
|
# |
|
6
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or |
|
7
|
|
|
|
|
|
|
# modify it under the same terms as Perl itself. |
|
8
|
|
|
|
|
|
|
# |
|
9
|
|
|
|
|
|
|
# |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
package Lustre::LFS; |
|
12
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
45
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
require Exporter; |
|
15
|
1
|
|
|
1
|
|
10
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
156
|
|
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
|
18
|
|
|
|
|
|
|
@EXPORT = qw(); |
|
19
|
|
|
|
|
|
|
@EXPORT_OK = qw(); |
|
20
|
|
|
|
|
|
|
$VERSION = '0.01'; |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
|
23
|
1
|
|
|
1
|
|
6
|
use constant LFS_BINARY => '/usr/bin/lfs'; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
931
|
|
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
######################################################################## |
|
27
|
|
|
|
|
|
|
# Parse output of getstripe (file information) |
|
28
|
|
|
|
|
|
|
sub _parse_get_stripe_file { |
|
29
|
0
|
|
|
0
|
|
|
my($ioh) = @_; |
|
30
|
|
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
my $path = _lfs_get_path($ioh); |
|
32
|
0
|
|
|
|
|
|
my $obds = []; |
|
33
|
0
|
|
|
|
|
|
my $lmm = { stripe_count=>undef, stripe_size=>undef, stripe_offset=>undef, pool_name=>undef }; |
|
34
|
0
|
0
|
|
|
|
|
return $path unless defined $path; |
|
35
|
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
foreach my $line (@{_lfs_exec("getstripe", "--verbose", "--", $path)}) { |
|
|
0
|
|
|
|
|
|
|
|
37
|
0
|
0
|
|
|
|
|
if($line =~ /^(\d+): (\S+) (.+)$/) { # OBD information |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
$obds->[$1] = { name=>$2, status=>$3 }; |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
elsif($line =~ /^\s+(\d+)\s+(\d+)\s+(0x[0-9a-f]+)\s+(\d+)/) { # Information about OST |
|
41
|
0
|
0
|
|
|
|
|
if(exists($obds->[$1])) { |
|
42
|
0
|
|
|
|
|
|
$obds->[$1]->{objid} = $2; |
|
43
|
0
|
|
|
|
|
|
$obds->[$1]->{group} = $4; |
|
44
|
0
|
0
|
|
|
|
|
$lmm->{stripe_offset} = $1 unless defined($lmm->{stripe_offset}); |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
elsif($line =~ /lmm_(\S+):\s+(.+)$/) { # --verbose information >> add to $lmm if key exists |
|
48
|
0
|
0
|
|
|
|
|
$lmm->{$1} = $2 if exists($lmm->{$1}); |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
# else: don't care |
|
51
|
|
|
|
|
|
|
} |
|
52
|
0
|
|
|
|
|
|
return { info=>$lmm, obds=>$obds }; |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
######################################################################## |
|
56
|
|
|
|
|
|
|
# Parse directory stripe info |
|
57
|
|
|
|
|
|
|
sub _parse_get_stripe_dir { |
|
58
|
0
|
|
|
0
|
|
|
my($ioh) = @_; |
|
59
|
0
|
|
|
|
|
|
my $path = _lfs_get_path($ioh); |
|
60
|
0
|
0
|
|
|
|
|
return $path unless defined $path; |
|
61
|
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
my $lmm = { stripe_count=>undef, stripe_size=>undef, stripe_offset=>undef, pool_name=>undef, pool_name=>undef, inherit_default=>undef }; |
|
63
|
0
|
|
|
|
|
|
foreach my $line (@{_lfs_exec("getstripe", "--", $path)}) { |
|
|
0
|
|
|
|
|
|
|
|
64
|
0
|
0
|
|
|
|
|
if($line =~ /^(\(Default\) )?stripe_count: ([0-9-]+) stripe_size: ([0-9-]+) stripe_offset: ([0-9-]+)/) { |
|
65
|
0
|
0
|
|
|
|
|
$lmm->{inherit_default} = ( $1 ? 1 : 0 ); |
|
66
|
0
|
|
|
|
|
|
$lmm->{stripe_count} = $2; |
|
67
|
0
|
|
|
|
|
|
$lmm->{stripe_size} = $3; |
|
68
|
0
|
|
|
|
|
|
$lmm->{stripe_offset} = $4; |
|
69
|
0
|
0
|
|
|
|
|
if($line =~ / pool: (.+)$/) { |
|
70
|
0
|
|
|
|
|
|
$lmm->{pool_name} = $1; |
|
71
|
|
|
|
|
|
|
} |
|
72
|
0
|
|
|
|
|
|
last; # no need to parse more |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
} |
|
75
|
0
|
|
|
|
|
|
return $lmm; |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
######################################################################## |
|
80
|
|
|
|
|
|
|
# Execute the lfs binary with perls open()||exec hack |
|
81
|
|
|
|
|
|
|
sub _lfs_exec { |
|
82
|
0
|
|
|
0
|
|
|
my(@args) = @_; |
|
83
|
|
|
|
|
|
|
|
|
84
|
0
|
0
|
|
|
|
|
open(LFS, "-|") || exec(LFS_BINARY,@args); |
|
85
|
0
|
|
|
|
|
|
my @buff = ; |
|
86
|
0
|
|
|
|
|
|
close(LFS); |
|
87
|
0
|
|
|
|
|
|
return \@buff; |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
######################################################################## |
|
91
|
|
|
|
|
|
|
# Silent system() call |
|
92
|
|
|
|
|
|
|
# FIXME: THIS SHOULD SET $! |
|
93
|
|
|
|
|
|
|
sub _lfs_system { |
|
94
|
0
|
|
|
0
|
|
|
my(@args) = @_; |
|
95
|
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
open(OLD_E, ">&STDERR"); # Create a copy of STDERR and STDOUT |
|
97
|
0
|
|
|
|
|
|
open(OLD_S ,">&STDOUT"); |
|
98
|
0
|
|
|
|
|
|
open(STDOUT, ">/dev/null"); # ..and redirect the default ones to /dev/null |
|
99
|
0
|
|
|
|
|
|
open(STDERR, ">/dev/null"); |
|
100
|
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
my $rv = system(LFS_BINARY, @args); |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# .. and restore everything back. |
|
104
|
0
|
|
|
|
|
|
close(STDOUT); |
|
105
|
0
|
|
|
|
|
|
close(STDERR); |
|
106
|
0
|
|
|
|
|
|
open(STDOUT, ">&OLD_S"); |
|
107
|
0
|
|
|
|
|
|
open(STDERR, ">&OLD_E"); |
|
108
|
0
|
|
|
|
|
|
close(OLD_E); |
|
109
|
0
|
|
|
|
|
|
close(OLD_S); |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
return $rv; |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
######################################################################## |
|
116
|
|
|
|
|
|
|
# Evil hack to get the filename of an open file-descriptor. |
|
117
|
|
|
|
|
|
|
# This might crash and burn but the 'lfs' binary needs a path to work |
|
118
|
|
|
|
|
|
|
sub _lfs_get_path { |
|
119
|
0
|
|
|
0
|
|
|
my($ioh) = @_; |
|
120
|
0
|
|
|
|
|
|
my $fno = $ioh->fileno; |
|
121
|
0
|
|
|
|
|
|
my $path = undef; |
|
122
|
|
|
|
|
|
|
|
|
123
|
0
|
0
|
0
|
|
|
|
if(defined($fno) && defined($path = readlink("/proc/self/fd/$fno"))) { |
|
124
|
0
|
0
|
|
|
|
|
if($path =~ /(.+) \(deleted\)$/) { |
|
125
|
0
|
|
|
|
|
|
$path = $1; |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
} |
|
128
|
0
|
|
|
|
|
|
return $path; |
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
1; |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
__END__ |