-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdump.php
116 lines (101 loc) · 3.03 KB
/
dump.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
require_once 'read_vsn1.php';
$data = parse_vsn1(file_get_contents('data.txt'));
#print_r($data);
$vg = Array();
$pv = Array();
foreach($data as $vgname => $value)
if(is_array($value) && isset($value['seqno']))
{
$vgtmp = Array('pv' => Array(), 'lv' => Array());
$vg[$vgname] = &$vgtmp;
foreach($value['physical_volumes'] as $pvname => $pvdata)
{
$pvtmp = Array('device' => $pvdata['device'],
'npe' => $pvdata['pe_count'],
'uses' => Array());
$vgtmp['pv'][$pvname] = &$pvtmp;
$pv[$pvdata['device']] = &$pvtmp;
unset($pvtmp);
}
foreach($value['logical_volumes'] as $lvname => $lvdata)
{
#$lvtmp = Array('name' => $lvname, 'parts' => Array());
#$vgtmp['lv'][$lvname] = &$lvtmp;
foreach($lvdata as $datakey => $datavalues)
{
if(preg_match('/^segment[0-9]/', $datakey))
{
$seg = (int)substr($datakey, 7);
$nparts = 1; $partkey = 'parts';
if($datavalues['type'] == 'mirror')
{
$nparts = $datavalues['mirror_count'];
$partkey = 'mirrors';
}
if($datavalues['type'] == 'striped')
{
$nparts = $datavalues['stripe_count'];
$partkey = 'stripes';
}
$fpe = $datavalues['start_extent'];
$npe = $datavalues['extent_count'] / $nparts;
if($datavalues['type'] == 'thin-pool')
{
$nparts = 0;
}
if($datavalues['type'] == 'thin')
{
$nparts = 0;
}
for($n=0; $n < $nparts; ++$n)
{
$partcode = strtoupper(base_convert(10+$n,10,36));
$lvnamepart = "{$lvname}$partcode-$seg";
$lvpart = &$vgtmp['lv'][$lvnamepart];
$pvname = $datavalues[$partkey][$n*2+0];
$pvoffs = $datavalues[$partkey][$n*2+1];
$lvpart =
Array(//'start' => $fpe,
'count' => $npe,
'pv' => $pvname,
'pvoffs' => $pvoffs);
if($partkey != 'mirrors')
{
$vgtmp['pv'][$pvname]['uses'][$pvoffs] =
Array('count' => $npe,
'lv' => $lvnamepart,
// 'lvoffs' => $fpe
);
}
unset($lvpart);
}
}
}
#unset($lvtmp);
}
unset($vgtmp);
}
foreach($pv as &$pvdata)
ksort($pvdata['uses']);
unset($pvdata);
foreach($vg as $vgname => $vgdata)
{
print "!! $vgname\n\n";
foreach($vgdata['pv'] as $pvname => $pvdata)
{
print "! {$pvdata['device']}\n";
$begin = 0;
$end = $pvdata['npe'];
foreach($pvdata['uses'] as $offset => $data)
{
if($offset > $begin)
printf("(%d)\t%s\n", $offset-$begin, '-');
printf("%d\t%s\n", $data['count'], $data['lv']);
$begin = $offset + $data['count'];
}
if($end > $begin)
printf("(%d)\t%s\n", $end-$begin, '-');
print "\n";
}
}