mirror of
git://sourceware.org/git/lvm2.git
synced 2026-01-02 20:32:47 +03:00
Compare commits
391 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b6556dce8b | ||
|
|
aa8d8bc8b5 | ||
|
|
0800dcfdc4 | ||
|
|
12b0101e94 | ||
|
|
021b391a02 | ||
|
|
d11e2b6057 | ||
|
|
264d90e7e5 | ||
|
|
f9f3da9e78 | ||
|
|
6435b49153 | ||
|
|
f9aa2941cf | ||
|
|
5a933d4bee | ||
|
|
5536aea0df | ||
|
|
976666d216 | ||
|
|
9a5bcd4392 | ||
|
|
812060a118 | ||
|
|
089b5052e6 | ||
|
|
874e5d72f4 | ||
|
|
6b11de1329 | ||
|
|
2245a7ad8d | ||
|
|
ee5ec1b870 | ||
|
|
74ccfe851b | ||
|
|
e1c24bd5a2 | ||
|
|
1349b79728 | ||
|
|
d294d7604c | ||
|
|
01df2cf464 | ||
|
|
45b7322488 | ||
|
|
b3055e992f | ||
|
|
3da548565c | ||
|
|
a975e85548 | ||
|
|
c4b5ade752 | ||
|
|
a4b61b0794 | ||
|
|
f6011184b8 | ||
|
|
74de118c6e | ||
|
|
9c25e77c17 | ||
|
|
440113e67e | ||
|
|
a11b60c445 | ||
|
|
a6052681ad | ||
|
|
482d50536a | ||
|
|
25c79a4fcd | ||
|
|
02946144ac | ||
|
|
71a360e9a3 | ||
|
|
f7912d88b1 | ||
|
|
975101d7d2 | ||
|
|
ef58c5ff55 | ||
|
|
e10221804a | ||
|
|
284ed9ee0e | ||
|
|
5d7b961997 | ||
|
|
c699a5c4b4 | ||
|
|
1f4ceb89cf | ||
|
|
0934ca0040 | ||
|
|
4738f892c2 | ||
|
|
33004fcf33 | ||
|
|
34d214c166 | ||
|
|
a56cd92a1e | ||
|
|
7251348507 | ||
|
|
01cd5c84d6 | ||
|
|
e210599fa6 | ||
|
|
dbe7cee7e9 | ||
|
|
7370d88ceb | ||
|
|
34458e0c57 | ||
|
|
05c8c3abf2 | ||
|
|
e9d464b4d3 | ||
|
|
6968c3ab9b | ||
|
|
131a8a9650 | ||
|
|
379ecbf9a9 | ||
|
|
7b9dfa9a28 | ||
|
|
fbd0f5eed2 | ||
|
|
5970f904ae | ||
|
|
8cbcb2868d | ||
|
|
8ff2a4b026 | ||
|
|
ae14d205a5 | ||
|
|
ec5d560ec5 | ||
|
|
fb543b53c0 | ||
|
|
39c16422e2 | ||
|
|
4d5b273ebe | ||
|
|
ed6a860fad | ||
|
|
423e579292 | ||
|
|
ee11aa9e75 | ||
|
|
c46d20fa92 | ||
|
|
dc8d17574c | ||
|
|
5c17cd04c8 | ||
|
|
67ada02076 | ||
|
|
32d94c2eaf | ||
|
|
687b39a12a | ||
|
|
705af407bf | ||
|
|
080052da2e | ||
|
|
ef735fd92a | ||
|
|
17c16dcafc | ||
|
|
a89b3018fb | ||
|
|
851e2ebd32 | ||
|
|
1225ce7fe8 | ||
|
|
7e77a31b96 | ||
|
|
d146b9002f | ||
|
|
1f9d567b23 | ||
|
|
ed1b3a023c | ||
|
|
1ca18f501a | ||
|
|
49588ccd98 | ||
|
|
098dedc092 | ||
|
|
b06f6b9545 | ||
|
|
ba3cb94999 | ||
|
|
74c67fbf4b | ||
|
|
32b46e4910 | ||
|
|
ecf5539ed2 | ||
|
|
ac9db4e4d5 | ||
|
|
0eb96094b0 | ||
|
|
30b3ac7dc5 | ||
|
|
0092790c7d | ||
|
|
28909d8a51 | ||
|
|
b20cfbb7b6 | ||
|
|
97639bd0a8 | ||
|
|
161ec73c96 | ||
|
|
957d6bea15 | ||
|
|
f8b6e5b414 | ||
|
|
1ab450870e | ||
|
|
de45f4884c | ||
|
|
5da1f3e7c8 | ||
|
|
983014952b | ||
|
|
55298019a3 | ||
|
|
a1ffc3f271 | ||
|
|
2fb60aa997 | ||
|
|
f5ec76537a | ||
|
|
728491fd2b | ||
|
|
d9d3f2b9e4 | ||
|
|
3fe4864f65 | ||
|
|
0b156f22a4 | ||
|
|
35b1d93813 | ||
|
|
d770851ac0 | ||
|
|
989e7b1033 | ||
|
|
c4e0eb7b49 | ||
|
|
71f5d0dac7 | ||
|
|
561b0c4381 | ||
|
|
995fbc7330 | ||
|
|
10ab8949c4 | ||
|
|
c441202fea | ||
|
|
ca261b0bee | ||
|
|
52f3709f67 | ||
|
|
c2ca6187fe | ||
|
|
671a13d295 | ||
|
|
14c3e2eccf | ||
|
|
08e5b852c2 | ||
|
|
1c9606c824 | ||
|
|
3cd47b5c9b | ||
|
|
aedc729087 | ||
|
|
5f7cfa3fa9 | ||
|
|
0083f30af5 | ||
|
|
4a06f05ef5 | ||
|
|
8f37cadce8 | ||
|
|
a11603ca6c | ||
|
|
86274842e9 | ||
|
|
cf9c955a44 | ||
|
|
55d828c35f | ||
|
|
cdff28aca6 | ||
|
|
b9da39274f | ||
|
|
c379aa5782 | ||
|
|
9dcabac9dd | ||
|
|
794f3a2b9f | ||
|
|
2066121b7c | ||
|
|
0c4067f143 | ||
|
|
8aa69243b7 | ||
|
|
8697263bde | ||
|
|
ea25c4f65c | ||
|
|
82ac3ebd7e | ||
|
|
13cb94909c | ||
|
|
b57ca2a763 | ||
|
|
83c49e9745 | ||
|
|
e15771d78d | ||
|
|
6edc4920ba | ||
|
|
302bb1bd93 | ||
|
|
529b1bceee | ||
|
|
42cd47d32e | ||
|
|
711d884c2e | ||
|
|
183d1c4674 | ||
|
|
faed63a0bb | ||
|
|
53bff262f8 | ||
|
|
3251a708e4 | ||
|
|
b5dbdbf7b2 | ||
|
|
a9649e92c9 | ||
|
|
b561f1fa8b | ||
|
|
cecd7491b5 | ||
|
|
55a66322b5 | ||
|
|
155c31a2d7 | ||
|
|
a89ce91089 | ||
|
|
b897fe6700 | ||
|
|
548a351b06 | ||
|
|
4b1da57ca1 | ||
|
|
529aec7f25 | ||
|
|
1661e545cb | ||
|
|
ec71d08878 | ||
|
|
ac258b7dd7 | ||
|
|
0f57876233 | ||
|
|
1d25a3693d | ||
|
|
45fa428bf1 | ||
|
|
177fa80f1a | ||
|
|
3261261bfe | ||
|
|
d4de7934f8 | ||
|
|
c3475af809 | ||
|
|
b12f707812 | ||
|
|
22c0c34d60 | ||
|
|
a60b66f230 | ||
|
|
83f6e93628 | ||
|
|
222b5f0229 | ||
|
|
30aa383e26 | ||
|
|
676b401294 | ||
|
|
ebf57159de | ||
|
|
199d2aafec | ||
|
|
81952f56fd | ||
|
|
c5bac82b43 | ||
|
|
081b86109c | ||
|
|
8ac2028a75 | ||
|
|
264fed1c9f | ||
|
|
dd59f7b2c7 | ||
|
|
9245a760db | ||
|
|
b61b32bbc3 | ||
|
|
09b3914f5d | ||
|
|
fe644e4c9e | ||
|
|
7b09bf2156 | ||
|
|
987d0aae66 | ||
|
|
9cbcbc1c22 | ||
|
|
cfc4e2bc60 | ||
|
|
a03405fa81 | ||
|
|
d5c9ccbe6e | ||
|
|
e52772d65f | ||
|
|
1e3259e728 | ||
|
|
e905a20a60 | ||
|
|
88e2be7a33 | ||
|
|
8939131600 | ||
|
|
ba37ebff8b | ||
|
|
28f4cb7e07 | ||
|
|
db1e7102cd | ||
|
|
07eb7a5830 | ||
|
|
b7c6c685fa | ||
|
|
212134df70 | ||
|
|
6eeb5528f5 | ||
|
|
54fad845c9 | ||
|
|
d6c0de6fc7 | ||
|
|
649c8649f7 | ||
|
|
da2f53d1b1 | ||
|
|
405139e3b8 | ||
|
|
4f8d347171 | ||
|
|
bf0db4876c | ||
|
|
47a14884d6 | ||
|
|
3a7bbc8b08 | ||
|
|
1b1d65372c | ||
|
|
fd2faaa16e | ||
|
|
0609cdb9ea | ||
|
|
d3bb140f89 | ||
|
|
b31dc66628 | ||
|
|
09476171a6 | ||
|
|
33dee813b5 | ||
|
|
bb4e73c40b | ||
|
|
b1f23ffa94 | ||
|
|
b0e8cec1e7 | ||
|
|
5077ae19bc | ||
|
|
0d8447bf59 | ||
|
|
c6cf08a274 | ||
|
|
dc49ae519e | ||
|
|
904539476a | ||
|
|
3fbf02dc82 | ||
|
|
c9392a840d | ||
|
|
d164e8ab72 | ||
|
|
6dc62c9fb6 | ||
|
|
87a9684d66 | ||
|
|
94525e2f44 | ||
|
|
b408b1b3b9 | ||
|
|
27c2f09e32 | ||
|
|
19bc4d3349 | ||
|
|
f2b6c424d6 | ||
|
|
a49d4453e9 | ||
|
|
65e50087b9 | ||
|
|
2d90f759d9 | ||
|
|
4230ac7674 | ||
|
|
d96e9182e9 | ||
|
|
68c87b9616 | ||
|
|
7f8e9a0b6d | ||
|
|
81a229f2a5 | ||
|
|
8be7ae2733 | ||
|
|
846bca4cb1 | ||
|
|
f36f353789 | ||
|
|
939a2731ed | ||
|
|
835dab97ff | ||
|
|
fa904b53be | ||
|
|
0ec52dddce | ||
|
|
c289355a3a | ||
|
|
02a13a5a18 | ||
|
|
6cf2a0281b | ||
|
|
120d35f9af | ||
|
|
2b15d5e7b3 | ||
|
|
fc167bd3f0 | ||
|
|
91b04abf05 | ||
|
|
77faac8740 | ||
|
|
43b3d54855 | ||
|
|
69e9b85700 | ||
|
|
0b6d132759 | ||
|
|
7c233c6c0c | ||
|
|
c35b290fa4 | ||
|
|
3d95cfb367 | ||
|
|
b90fc3a56e | ||
|
|
1ef3fdccf5 | ||
|
|
02b7f77bd8 | ||
|
|
0ac7ead922 | ||
|
|
da9d0e03ce | ||
|
|
120f65f672 | ||
|
|
200a14caa4 | ||
|
|
35bf6da8e2 | ||
|
|
f08f70276c | ||
|
|
1ae50fd95b | ||
|
|
40512beb47 | ||
|
|
0d7f9b2c94 | ||
|
|
52f42140a7 | ||
|
|
3f6c50297f | ||
|
|
f72d80afc5 | ||
|
|
7c5cb13b22 | ||
|
|
d728750eb2 | ||
|
|
02a70e5667 | ||
|
|
44e51ea5fa | ||
|
|
87e201460a | ||
|
|
039bd945e2 | ||
|
|
e9e52d2b4b | ||
|
|
2bf92e7399 | ||
|
|
5b0df241f0 | ||
|
|
76f5b05eff | ||
|
|
40fb6c998f | ||
|
|
33f50a342d | ||
|
|
81523ab68a | ||
|
|
2bf8cc62cf | ||
|
|
1ae8247af3 | ||
|
|
5ef32227ec | ||
|
|
6456e773bd | ||
|
|
234fe53ca3 | ||
|
|
7c93e7a7b3 | ||
|
|
8afc6c7f4b | ||
|
|
4609d0fa3a | ||
|
|
d452c035c6 | ||
|
|
45113c8f5a | ||
|
|
0acdd3c62b | ||
|
|
96d7d0a33e | ||
|
|
b6b280267b | ||
|
|
6e6d253b1a | ||
|
|
d92c105db2 | ||
|
|
906db728d6 | ||
|
|
c4b7411565 | ||
|
|
de06396046 | ||
|
|
ee6bfeb8e3 | ||
|
|
058347321f | ||
|
|
feefe49324 | ||
|
|
187381a9a2 | ||
|
|
993dfa4368 | ||
|
|
7e35a16440 | ||
|
|
e4eeb15926 | ||
|
|
634e0db26d | ||
|
|
56855c23e1 | ||
|
|
0b00f742e3 | ||
|
|
b7ab3f673c | ||
|
|
be04ea1e35 | ||
|
|
1f8e695802 | ||
|
|
2d82b2c64f | ||
|
|
d076caf473 | ||
|
|
c7abdefa31 | ||
|
|
ba772c0bca | ||
|
|
5bad234119 | ||
|
|
c7e7baaf23 | ||
|
|
36658a671b | ||
|
|
045f2e10ba | ||
|
|
fb5a7db66d | ||
|
|
ba7d33982e | ||
|
|
c62279a755 | ||
|
|
17fa1a7ffb | ||
|
|
e89ceac351 | ||
|
|
0b8c30c109 | ||
|
|
9ab0f463cc | ||
|
|
6433dda7b8 | ||
|
|
fa7a2f4be4 | ||
|
|
ba90e16505 | ||
|
|
008f710203 | ||
|
|
df2740f126 | ||
|
|
2db89d143e | ||
|
|
0525d49da3 | ||
|
|
e2b0745882 | ||
|
|
92e804fc50 | ||
|
|
67abf45576 | ||
|
|
d2c9c814e7 | ||
|
|
22f8881a64 | ||
|
|
4ab20322fe | ||
|
|
5370eeecea | ||
|
|
ba71cb5dd7 | ||
|
|
9aad6c2c52 | ||
|
|
4d9627f20c | ||
|
|
c142492e91 | ||
|
|
6bf8d9e207 | ||
|
|
4f9a6168c1 | ||
|
|
38397f99aa |
1
BUGS
Normal file
1
BUGS
Normal file
@@ -0,0 +1 @@
|
||||
LVM2's device-mapper driver and ext3 are incompatible at the moment.
|
||||
340
COPYING
Normal file
340
COPYING
Normal file
@@ -0,0 +1,340 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Library General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Library General
|
||||
Public License instead of this License.
|
||||
483
COPYING.LIB
Normal file
483
COPYING.LIB
Normal file
@@ -0,0 +1,483 @@
|
||||
|
||||
GNU LIBRARY GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1991 Free Software Foundation, Inc.
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
[This is the first released version of the library GPL. It is
|
||||
numbered 2 because it goes with version 2 of the ordinary GPL.]
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
Licenses are intended to guarantee your freedom to share and change
|
||||
free software--to make sure the software is free for all its users.
|
||||
|
||||
This license, the Library General Public License, applies to some
|
||||
specially designated Free Software Foundation software, and to any
|
||||
other libraries whose authors decide to use it. You can use it for
|
||||
your libraries, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if
|
||||
you distribute copies of the library, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of the library, whether gratis
|
||||
or for a fee, you must give the recipients all the rights that we gave
|
||||
you. You must make sure that they, too, receive or can get the source
|
||||
code. If you link a program with the library, you must provide
|
||||
complete object files to the recipients so that they can relink them
|
||||
with the library, after making changes to the library and recompiling
|
||||
it. And you must show them these terms so they know their rights.
|
||||
|
||||
Our method of protecting your rights has two steps: (1) copyright
|
||||
the library, and (2) offer you this license which gives you legal
|
||||
permission to copy, distribute and/or modify the library.
|
||||
|
||||
Also, for each distributor's protection, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
library. If the library is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original
|
||||
version, so that any problems introduced by others will not reflect on
|
||||
the original authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that companies distributing free
|
||||
software will individually obtain patent licenses, thus in effect
|
||||
transforming the program into proprietary software. To prevent this,
|
||||
we have made it clear that any patent must be licensed for everyone's
|
||||
free use or not licensed at all.
|
||||
|
||||
Most GNU software, including some libraries, is covered by the ordinary
|
||||
GNU General Public License, which was designed for utility programs. This
|
||||
license, the GNU Library General Public License, applies to certain
|
||||
designated libraries. This license is quite different from the ordinary
|
||||
one; be sure to read it in full, and don't assume that anything in it is
|
||||
the same as in the ordinary license.
|
||||
|
||||
The reason we have a separate public license for some libraries is that
|
||||
they blur the distinction we usually make between modifying or adding to a
|
||||
program and simply using it. Linking a program with a library, without
|
||||
changing the library, is in some sense simply using the library, and is
|
||||
analogous to running a utility program or application program. However, in
|
||||
a textual and legal sense, the linked executable is a combined work, a
|
||||
derivative of the original library, and the ordinary General Public License
|
||||
treats it as such.
|
||||
|
||||
Because of this blurred distinction, using the ordinary General
|
||||
Public License for libraries did not effectively promote software
|
||||
sharing, because most developers did not use the libraries. We
|
||||
concluded that weaker conditions might promote sharing better.
|
||||
|
||||
However, unrestricted linking of non-free programs would deprive the
|
||||
users of those programs of all benefit from the free status of the
|
||||
libraries themselves. This Library General Public License is intended to
|
||||
permit developers of non-free programs to use free libraries, while
|
||||
preserving your freedom as a user of such programs to change the free
|
||||
libraries that are incorporated in them. (We have not seen how to achieve
|
||||
this as regards changes in header files, but we have achieved it as regards
|
||||
changes in the actual functions of the Library.) The hope is that this
|
||||
will lead to faster development of free libraries.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow. Pay close attention to the difference between a
|
||||
"work based on the library" and a "work that uses the library". The
|
||||
former contains code derived from the library, while the latter only
|
||||
works together with the library.
|
||||
|
||||
Note that it is possible for a library to be covered by the ordinary
|
||||
General Public License rather than by this special one.
|
||||
|
||||
GNU LIBRARY GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License Agreement applies to any software library which
|
||||
contains a notice placed by the copyright holder or other authorized
|
||||
party saying it may be distributed under the terms of this Library
|
||||
General Public License (also called "this License"). Each licensee is
|
||||
addressed as "you".
|
||||
|
||||
A "library" means a collection of software functions and/or data
|
||||
prepared so as to be conveniently linked with application programs
|
||||
(which use some of those functions and data) to form executables.
|
||||
|
||||
The "Library", below, refers to any such software library or work
|
||||
which has been distributed under these terms. A "work based on the
|
||||
Library" means either the Library or any derivative work under
|
||||
copyright law: that is to say, a work containing the Library or a
|
||||
portion of it, either verbatim or with modifications and/or translated
|
||||
straightforwardly into another language. (Hereinafter, translation is
|
||||
included without limitation in the term "modification".)
|
||||
|
||||
"Source code" for a work means the preferred form of the work for
|
||||
making modifications to it. For a library, complete source code means
|
||||
all the source code for all modules it contains, plus any associated
|
||||
interface definition files, plus the scripts used to control compilation
|
||||
and installation of the library.
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running a program using the Library is not restricted, and output from
|
||||
such a program is covered only if its contents constitute a work based
|
||||
on the Library (independent of the use of the Library in a tool for
|
||||
writing it). Whether that is true depends on what the Library does
|
||||
and what the program that uses the Library does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Library's
|
||||
complete source code as you receive it, in any medium, provided that
|
||||
you conspicuously and appropriately publish on each copy an
|
||||
appropriate copyright notice and disclaimer of warranty; keep intact
|
||||
all the notices that refer to this License and to the absence of any
|
||||
warranty; and distribute a copy of this License along with the
|
||||
Library.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy,
|
||||
and you may at your option offer warranty protection in exchange for a
|
||||
fee.
|
||||
|
||||
2. You may modify your copy or copies of the Library or any portion
|
||||
of it, thus forming a work based on the Library, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) The modified work must itself be a software library.
|
||||
|
||||
b) You must cause the files modified to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
c) You must cause the whole of the work to be licensed at no
|
||||
charge to all third parties under the terms of this License.
|
||||
|
||||
d) If a facility in the modified Library refers to a function or a
|
||||
table of data to be supplied by an application program that uses
|
||||
the facility, other than as an argument passed when the facility
|
||||
is invoked, then you must make a good faith effort to ensure that,
|
||||
in the event an application does not supply such function or
|
||||
table, the facility still operates, and performs whatever part of
|
||||
its purpose remains meaningful.
|
||||
|
||||
(For example, a function in a library to compute square roots has
|
||||
a purpose that is entirely well-defined independent of the
|
||||
application. Therefore, Subsection 2d requires that any
|
||||
application-supplied function or table used by this function must
|
||||
be optional: if the application does not supply it, the square
|
||||
root function must still compute square roots.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Library,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Library, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote
|
||||
it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Library.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Library
|
||||
with the Library (or with a work based on the Library) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may opt to apply the terms of the ordinary GNU General Public
|
||||
License instead of this License to a given copy of the Library. To do
|
||||
this, you must alter all the notices that refer to this License, so
|
||||
that they refer to the ordinary GNU General Public License, version 2,
|
||||
instead of to this License. (If a newer version than version 2 of the
|
||||
ordinary GNU General Public License has appeared, then you can specify
|
||||
that version instead if you wish.) Do not make any other change in
|
||||
these notices.
|
||||
|
||||
Once this change is made in a given copy, it is irreversible for
|
||||
that copy, so the ordinary GNU General Public License applies to all
|
||||
subsequent copies and derivative works made from that copy.
|
||||
|
||||
This option is useful when you wish to copy part of the code of
|
||||
the Library into a program that is not a library.
|
||||
|
||||
4. You may copy and distribute the Library (or a portion or
|
||||
derivative of it, under Section 2) in object code or executable form
|
||||
under the terms of Sections 1 and 2 above provided that you accompany
|
||||
it with the complete corresponding machine-readable source code, which
|
||||
must be distributed under the terms of Sections 1 and 2 above on a
|
||||
medium customarily used for software interchange.
|
||||
|
||||
If distribution of object code is made by offering access to copy
|
||||
from a designated place, then offering equivalent access to copy the
|
||||
source code from the same place satisfies the requirement to
|
||||
distribute the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
5. A program that contains no derivative of any portion of the
|
||||
Library, but is designed to work with the Library by being compiled or
|
||||
linked with it, is called a "work that uses the Library". Such a
|
||||
work, in isolation, is not a derivative work of the Library, and
|
||||
therefore falls outside the scope of this License.
|
||||
|
||||
However, linking a "work that uses the Library" with the Library
|
||||
creates an executable that is a derivative of the Library (because it
|
||||
contains portions of the Library), rather than a "work that uses the
|
||||
library". The executable is therefore covered by this License.
|
||||
Section 6 states terms for distribution of such executables.
|
||||
|
||||
When a "work that uses the Library" uses material from a header file
|
||||
that is part of the Library, the object code for the work may be a
|
||||
derivative work of the Library even though the source code is not.
|
||||
Whether this is true is especially significant if the work can be
|
||||
linked without the Library, or if the work is itself a library. The
|
||||
threshold for this to be true is not precisely defined by law.
|
||||
|
||||
If such an object file uses only numerical parameters, data
|
||||
structure layouts and accessors, and small macros and small inline
|
||||
functions (ten lines or less in length), then the use of the object
|
||||
file is unrestricted, regardless of whether it is legally a derivative
|
||||
work. (Executables containing this object code plus portions of the
|
||||
Library will still fall under Section 6.)
|
||||
|
||||
Otherwise, if the work is a derivative of the Library, you may
|
||||
distribute the object code for the work under the terms of Section 6.
|
||||
Any executables containing that work also fall under Section 6,
|
||||
whether or not they are linked directly with the Library itself.
|
||||
|
||||
6. As an exception to the Sections above, you may also compile or
|
||||
link a "work that uses the Library" with the Library to produce a
|
||||
work containing portions of the Library, and distribute that work
|
||||
under terms of your choice, provided that the terms permit
|
||||
modification of the work for the customer's own use and reverse
|
||||
engineering for debugging such modifications.
|
||||
|
||||
You must give prominent notice with each copy of the work that the
|
||||
Library is used in it and that the Library and its use are covered by
|
||||
this License. You must supply a copy of this License. If the work
|
||||
during execution displays copyright notices, you must include the
|
||||
copyright notice for the Library among them, as well as a reference
|
||||
directing the user to the copy of this License. Also, you must do one
|
||||
of these things:
|
||||
|
||||
a) Accompany the work with the complete corresponding
|
||||
machine-readable source code for the Library including whatever
|
||||
changes were used in the work (which must be distributed under
|
||||
Sections 1 and 2 above); and, if the work is an executable linked
|
||||
with the Library, with the complete machine-readable "work that
|
||||
uses the Library", as object code and/or source code, so that the
|
||||
user can modify the Library and then relink to produce a modified
|
||||
executable containing the modified Library. (It is understood
|
||||
that the user who changes the contents of definitions files in the
|
||||
Library will not necessarily be able to recompile the application
|
||||
to use the modified definitions.)
|
||||
|
||||
b) Accompany the work with a written offer, valid for at
|
||||
least three years, to give the same user the materials
|
||||
specified in Subsection 6a, above, for a charge no more
|
||||
than the cost of performing this distribution.
|
||||
|
||||
c) If distribution of the work is made by offering access to copy
|
||||
from a designated place, offer equivalent access to copy the above
|
||||
specified materials from the same place.
|
||||
|
||||
d) Verify that the user has already received a copy of these
|
||||
materials or that you have already sent this user a copy.
|
||||
|
||||
For an executable, the required form of the "work that uses the
|
||||
Library" must include any data and utility programs needed for
|
||||
reproducing the executable from it. However, as a special exception,
|
||||
the source code distributed need not include anything that is normally
|
||||
distributed (in either source or binary form) with the major
|
||||
components (compiler, kernel, and so on) of the operating system on
|
||||
which the executable runs, unless that component itself accompanies
|
||||
the executable.
|
||||
|
||||
It may happen that this requirement contradicts the license
|
||||
restrictions of other proprietary libraries that do not normally
|
||||
accompany the operating system. Such a contradiction means you cannot
|
||||
use both them and the Library together in an executable that you
|
||||
distribute.
|
||||
|
||||
7. You may place library facilities that are a work based on the
|
||||
Library side-by-side in a single library together with other library
|
||||
facilities not covered by this License, and distribute such a combined
|
||||
library, provided that the separate distribution of the work based on
|
||||
the Library and of the other library facilities is otherwise
|
||||
permitted, and provided that you do these two things:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work
|
||||
based on the Library, uncombined with any other library
|
||||
facilities. This must be distributed under the terms of the
|
||||
Sections above.
|
||||
|
||||
b) Give prominent notice with the combined library of the fact
|
||||
that part of it is a work based on the Library, and explaining
|
||||
where to find the accompanying uncombined form of the same work.
|
||||
|
||||
8. You may not copy, modify, sublicense, link with, or distribute
|
||||
the Library except as expressly provided under this License. Any
|
||||
attempt otherwise to copy, modify, sublicense, link with, or
|
||||
distribute the Library is void, and will automatically terminate your
|
||||
rights under this License. However, parties who have received copies,
|
||||
or rights, from you under this License will not have their licenses
|
||||
terminated so long as such parties remain in full compliance.
|
||||
|
||||
9. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Library or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Library (or any work based on the
|
||||
Library), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Library or works based on it.
|
||||
|
||||
10. Each time you redistribute the Library (or any work based on the
|
||||
Library), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute, link with or modify the Library
|
||||
subject to these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
11. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Library at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Library by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Library.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under any
|
||||
particular circumstance, the balance of the section is intended to apply,
|
||||
and the section as a whole is intended to apply in other circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
12. If the distribution and/or use of the Library is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Library under this License may add
|
||||
an explicit geographical distribution limitation excluding those countries,
|
||||
so that distribution is permitted only in or among countries not thus
|
||||
excluded. In such case, this License incorporates the limitation as if
|
||||
written in the body of this License.
|
||||
|
||||
13. The Free Software Foundation may publish revised and/or new
|
||||
versions of the Library General Public License from time to time.
|
||||
Such new versions will be similar in spirit to the present version,
|
||||
but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Library
|
||||
specifies a version number of this License which applies to it and
|
||||
"any later version", you have the option of following the terms and
|
||||
conditions either of that version or of any later version published by
|
||||
the Free Software Foundation. If the Library does not specify a
|
||||
license version number, you may choose any version ever published by
|
||||
the Free Software Foundation.
|
||||
|
||||
14. If you wish to incorporate parts of the Library into other free
|
||||
programs whose distribution conditions are incompatible with these,
|
||||
write to the author to ask for permission. For software which is
|
||||
copyrighted by the Free Software Foundation, write to the Free
|
||||
Software Foundation; we sometimes make exceptions for this. Our
|
||||
decision will be guided by the two goals of preserving the free status
|
||||
of all derivatives of our free software and of promoting the sharing
|
||||
and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
||||
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
|
||||
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
|
||||
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
||||
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
||||
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
||||
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
|
||||
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
|
||||
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
|
||||
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
|
||||
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
||||
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
Appendix: How to Apply These Terms to Your New Libraries
|
||||
|
||||
If you develop a new library, and you want it to be of the greatest
|
||||
possible use to the public, we recommend making it free software that
|
||||
everyone can redistribute and change. You can do so by permitting
|
||||
redistribution under these terms (or, alternatively, under the terms of the
|
||||
ordinary General Public License).
|
||||
|
||||
To apply these terms, attach the following notices to the library. It is
|
||||
safest to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least the
|
||||
"copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the library's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
MA 02111-1307, USA
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the library, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the
|
||||
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1990
|
||||
Ty Coon, President of Vice
|
||||
|
||||
That's all there is to it!
|
||||
36
INSTALL
Normal file
36
INSTALL
Normal file
@@ -0,0 +1,36 @@
|
||||
LVM2 installation
|
||||
=================
|
||||
|
||||
1) Install device-mapper
|
||||
|
||||
Ensure the device-mapper has been installed on the machine.
|
||||
|
||||
The device-mapper should be in the kernel (look for 'device-mapper'
|
||||
messages in the kernel logs) and /usr/include/libdevmapper.h should
|
||||
be present.
|
||||
|
||||
The device-mapper is available from:
|
||||
ftp://ftp.sistina.com/pub/LVM2/device-mapper/
|
||||
|
||||
|
||||
2) Generate custom makefiles.
|
||||
|
||||
Run the 'configure' script from the top directory.
|
||||
|
||||
If you do not have GNU readline (http://www.gnu.org/directory/readline.html)
|
||||
installed use
|
||||
./configure --disable-readline
|
||||
|
||||
|
||||
3) Build and install LVM2.
|
||||
|
||||
Run 'make install' from the top directory.
|
||||
|
||||
|
||||
4) Create a configuration file
|
||||
|
||||
The tools will work fine without a configuration file being
|
||||
present, but you ought to review the example file in doc/example.conf.
|
||||
For example, specifying the devices that LVM2 is to use should
|
||||
make the tools run more efficiently - and avoid scanning /dev/cdrom!
|
||||
|
||||
18
INTRO
Normal file
18
INTRO
Normal file
@@ -0,0 +1,18 @@
|
||||
An introduction to LVM2
|
||||
=======================
|
||||
|
||||
Background
|
||||
|
||||
|
||||
Compatibility with LVM1
|
||||
|
||||
|
||||
New features
|
||||
|
||||
|
||||
Missing features
|
||||
|
||||
|
||||
Future enhancements
|
||||
|
||||
|
||||
@@ -22,5 +22,13 @@ VPATH = @srcdir@
|
||||
|
||||
SUBDIRS = include man lib tools
|
||||
|
||||
ifeq ($(MAKECMDGOALS),distclean)
|
||||
SUBDIRS += test/mm test/device test/format1 test/regex test/filters
|
||||
endif
|
||||
|
||||
include make.tmpl
|
||||
|
||||
lib: include
|
||||
tools: include lib
|
||||
|
||||
|
||||
|
||||
27
README
27
README
@@ -1,2 +1,25 @@
|
||||
This is pretty much empty so far...if you can't see subdirectories,
|
||||
try 'cvs -f update'
|
||||
This directory contains a beta release of LMV2, the new version of
|
||||
the userland LVM tools designed for the new device-mapper for
|
||||
the Linux kernel.
|
||||
|
||||
The device-mapper needs to be installed before compiling these LVM2 tools.
|
||||
|
||||
For more information about LVM2 read the INTRO file.
|
||||
Installation instructions are in INSTALL.
|
||||
|
||||
This is beta-quality software, released for testing purposes only.
|
||||
There is no warranty - see COPYING and COPYING.LIB.
|
||||
|
||||
Tarballs are available from:
|
||||
ftp://ftp.sistina.com/pub/LVM2/tools/
|
||||
ftp://ftp.sistina.com/pub/LVM2/device-mapper/
|
||||
|
||||
To access the CVS tree use:
|
||||
cvs -d :pserver:cvs@tech.sistina.com:/data/cvs login
|
||||
CVS password: cvs1
|
||||
cvs -d :pserver:cvs@tech.sistina.com:/data/cvs checkout LVM2
|
||||
|
||||
Mailing list for discussion/bug reports etc.
|
||||
lvm-devel@sistina.com
|
||||
Subscribe from http://lists.sistina.com/mailman/listinfo/lvm-devel
|
||||
|
||||
|
||||
29
TODO
Normal file
29
TODO
Normal file
@@ -0,0 +1,29 @@
|
||||
before 2.0
|
||||
-----------
|
||||
|
||||
vgexport
|
||||
vgimport
|
||||
snapshots
|
||||
device-mapper support for 2.5 kernel series
|
||||
review FIXMEs
|
||||
extra validation & full consistency checks in format1 with LVM1
|
||||
partial activation
|
||||
error message review
|
||||
locking during metadata changes
|
||||
format2 with atomic transactions
|
||||
bidirectional format1/format2 migration tool
|
||||
persistent minors
|
||||
stats
|
||||
pvmove
|
||||
review tool exit codes for LVM1 compatibility
|
||||
|
||||
before 2.1
|
||||
----------
|
||||
|
||||
e2fsadm
|
||||
lvmdiskscan
|
||||
lvmsadc
|
||||
lvmsar
|
||||
pvdata
|
||||
vgsplit
|
||||
vgmknodes
|
||||
245
configure
vendored
245
configure
vendored
@@ -16,8 +16,6 @@ ac_help="$ac_help
|
||||
--with-user=USER Set the owner of installed files "
|
||||
ac_help="$ac_help
|
||||
--with-group=GROUP Set the group owner of installed files "
|
||||
ac_help="$ac_help
|
||||
--with-kernel_dir=DIR linux kernel source in DIR [/usr/src/linux]"
|
||||
ac_help="$ac_help
|
||||
--enable-jobs=NUM Number of jobs to run simultaneously"
|
||||
ac_help="$ac_help
|
||||
@@ -561,7 +559,7 @@ do
|
||||
# Extract the first word of "$ac_prog", so it can be a program name with args.
|
||||
set dummy $ac_prog; ac_word=$2
|
||||
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
|
||||
echo "configure:565: checking for $ac_word" >&5
|
||||
echo "configure:563: checking for $ac_word" >&5
|
||||
if eval "test \"`echo '$''{'ac_cv_prog_AWK'+set}'`\" = set"; then
|
||||
echo $ac_n "(cached) $ac_c" 1>&6
|
||||
else
|
||||
@@ -593,7 +591,7 @@ done
|
||||
# Extract the first word of "gcc", so it can be a program name with args.
|
||||
set dummy gcc; ac_word=$2
|
||||
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
|
||||
echo "configure:597: checking for $ac_word" >&5
|
||||
echo "configure:595: checking for $ac_word" >&5
|
||||
if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
|
||||
echo $ac_n "(cached) $ac_c" 1>&6
|
||||
else
|
||||
@@ -623,7 +621,7 @@ if test -z "$CC"; then
|
||||
# Extract the first word of "cc", so it can be a program name with args.
|
||||
set dummy cc; ac_word=$2
|
||||
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
|
||||
echo "configure:627: checking for $ac_word" >&5
|
||||
echo "configure:625: checking for $ac_word" >&5
|
||||
if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
|
||||
echo $ac_n "(cached) $ac_c" 1>&6
|
||||
else
|
||||
@@ -674,7 +672,7 @@ fi
|
||||
# Extract the first word of "cl", so it can be a program name with args.
|
||||
set dummy cl; ac_word=$2
|
||||
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
|
||||
echo "configure:678: checking for $ac_word" >&5
|
||||
echo "configure:676: checking for $ac_word" >&5
|
||||
if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
|
||||
echo $ac_n "(cached) $ac_c" 1>&6
|
||||
else
|
||||
@@ -706,7 +704,7 @@ fi
|
||||
fi
|
||||
|
||||
echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works""... $ac_c" 1>&6
|
||||
echo "configure:710: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5
|
||||
echo "configure:708: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5
|
||||
|
||||
ac_ext=c
|
||||
# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
|
||||
@@ -717,12 +715,12 @@ cross_compiling=$ac_cv_prog_cc_cross
|
||||
|
||||
cat > conftest.$ac_ext << EOF
|
||||
|
||||
#line 721 "configure"
|
||||
#line 719 "configure"
|
||||
#include "confdefs.h"
|
||||
|
||||
main(){return(0);}
|
||||
EOF
|
||||
if { (eval echo configure:726: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
|
||||
if { (eval echo configure:724: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
|
||||
ac_cv_prog_cc_works=yes
|
||||
# If we can't run a trivial program, we are probably using a cross compiler.
|
||||
if (./conftest; exit) 2>/dev/null; then
|
||||
@@ -748,12 +746,12 @@ if test $ac_cv_prog_cc_works = no; then
|
||||
{ echo "configure: error: installation or configuration problem: C compiler cannot create executables." 1>&2; exit 1; }
|
||||
fi
|
||||
echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler""... $ac_c" 1>&6
|
||||
echo "configure:752: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5
|
||||
echo "configure:750: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5
|
||||
echo "$ac_t""$ac_cv_prog_cc_cross" 1>&6
|
||||
cross_compiling=$ac_cv_prog_cc_cross
|
||||
|
||||
echo $ac_n "checking whether we are using GNU C""... $ac_c" 1>&6
|
||||
echo "configure:757: checking whether we are using GNU C" >&5
|
||||
echo "configure:755: checking whether we are using GNU C" >&5
|
||||
if eval "test \"`echo '$''{'ac_cv_prog_gcc'+set}'`\" = set"; then
|
||||
echo $ac_n "(cached) $ac_c" 1>&6
|
||||
else
|
||||
@@ -762,7 +760,7 @@ else
|
||||
yes;
|
||||
#endif
|
||||
EOF
|
||||
if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:766: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then
|
||||
if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:764: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then
|
||||
ac_cv_prog_gcc=yes
|
||||
else
|
||||
ac_cv_prog_gcc=no
|
||||
@@ -781,7 +779,7 @@ ac_test_CFLAGS="${CFLAGS+set}"
|
||||
ac_save_CFLAGS="$CFLAGS"
|
||||
CFLAGS=
|
||||
echo $ac_n "checking whether ${CC-cc} accepts -g""... $ac_c" 1>&6
|
||||
echo "configure:785: checking whether ${CC-cc} accepts -g" >&5
|
||||
echo "configure:783: checking whether ${CC-cc} accepts -g" >&5
|
||||
if eval "test \"`echo '$''{'ac_cv_prog_cc_g'+set}'`\" = set"; then
|
||||
echo $ac_n "(cached) $ac_c" 1>&6
|
||||
else
|
||||
@@ -824,7 +822,7 @@ fi
|
||||
# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff"
|
||||
# ./install, which can be erroneously created by make from ./install.sh.
|
||||
echo $ac_n "checking for a BSD compatible install""... $ac_c" 1>&6
|
||||
echo "configure:828: checking for a BSD compatible install" >&5
|
||||
echo "configure:826: checking for a BSD compatible install" >&5
|
||||
if test -z "$INSTALL"; then
|
||||
if eval "test \"`echo '$''{'ac_cv_path_install'+set}'`\" = set"; then
|
||||
echo $ac_n "(cached) $ac_c" 1>&6
|
||||
@@ -877,7 +875,7 @@ test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL_PROGRAM}'
|
||||
test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644'
|
||||
|
||||
echo $ac_n "checking whether ln -s works""... $ac_c" 1>&6
|
||||
echo "configure:881: checking whether ln -s works" >&5
|
||||
echo "configure:879: checking whether ln -s works" >&5
|
||||
if eval "test \"`echo '$''{'ac_cv_prog_LN_S'+set}'`\" = set"; then
|
||||
echo $ac_n "(cached) $ac_c" 1>&6
|
||||
else
|
||||
@@ -898,7 +896,7 @@ else
|
||||
fi
|
||||
|
||||
echo $ac_n "checking whether ${MAKE-make} sets \${MAKE}""... $ac_c" 1>&6
|
||||
echo "configure:902: checking whether ${MAKE-make} sets \${MAKE}" >&5
|
||||
echo "configure:900: checking whether ${MAKE-make} sets \${MAKE}" >&5
|
||||
set dummy ${MAKE-make}; ac_make=`echo "$2" | sed 'y%./+-%__p_%'`
|
||||
if eval "test \"`echo '$''{'ac_cv_prog_make_${ac_make}_set'+set}'`\" = set"; then
|
||||
echo $ac_n "(cached) $ac_c" 1>&6
|
||||
@@ -927,7 +925,7 @@ fi
|
||||
# Extract the first word of "ranlib", so it can be a program name with args.
|
||||
set dummy ranlib; ac_word=$2
|
||||
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
|
||||
echo "configure:931: checking for $ac_word" >&5
|
||||
echo "configure:929: checking for $ac_word" >&5
|
||||
if eval "test \"`echo '$''{'ac_cv_prog_RANLIB'+set}'`\" = set"; then
|
||||
echo $ac_n "(cached) $ac_c" 1>&6
|
||||
else
|
||||
@@ -960,12 +958,12 @@ for ac_hdr in dirent.h sys/ndir.h sys/dir.h ndir.h
|
||||
do
|
||||
ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
|
||||
echo $ac_n "checking for $ac_hdr that defines DIR""... $ac_c" 1>&6
|
||||
echo "configure:964: checking for $ac_hdr that defines DIR" >&5
|
||||
echo "configure:962: checking for $ac_hdr that defines DIR" >&5
|
||||
if eval "test \"`echo '$''{'ac_cv_header_dirent_$ac_safe'+set}'`\" = set"; then
|
||||
echo $ac_n "(cached) $ac_c" 1>&6
|
||||
else
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 969 "configure"
|
||||
#line 967 "configure"
|
||||
#include "confdefs.h"
|
||||
#include <sys/types.h>
|
||||
#include <$ac_hdr>
|
||||
@@ -973,7 +971,7 @@ int main() {
|
||||
DIR *dirp = 0;
|
||||
; return 0; }
|
||||
EOF
|
||||
if { (eval echo configure:977: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
|
||||
if { (eval echo configure:975: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
|
||||
rm -rf conftest*
|
||||
eval "ac_cv_header_dirent_$ac_safe=yes"
|
||||
else
|
||||
@@ -998,7 +996,7 @@ done
|
||||
# Two versions of opendir et al. are in -ldir and -lx on SCO Xenix.
|
||||
if test $ac_header_dirent = dirent.h; then
|
||||
echo $ac_n "checking for opendir in -ldir""... $ac_c" 1>&6
|
||||
echo "configure:1002: checking for opendir in -ldir" >&5
|
||||
echo "configure:1000: checking for opendir in -ldir" >&5
|
||||
ac_lib_var=`echo dir'_'opendir | sed 'y%./+-%__p_%'`
|
||||
if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
|
||||
echo $ac_n "(cached) $ac_c" 1>&6
|
||||
@@ -1006,7 +1004,7 @@ else
|
||||
ac_save_LIBS="$LIBS"
|
||||
LIBS="-ldir $LIBS"
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 1010 "configure"
|
||||
#line 1008 "configure"
|
||||
#include "confdefs.h"
|
||||
/* Override any gcc2 internal prototype to avoid an error. */
|
||||
/* We use char because int might match the return type of a gcc2
|
||||
@@ -1017,7 +1015,7 @@ int main() {
|
||||
opendir()
|
||||
; return 0; }
|
||||
EOF
|
||||
if { (eval echo configure:1021: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
|
||||
if { (eval echo configure:1019: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
|
||||
rm -rf conftest*
|
||||
eval "ac_cv_lib_$ac_lib_var=yes"
|
||||
else
|
||||
@@ -1039,7 +1037,7 @@ fi
|
||||
|
||||
else
|
||||
echo $ac_n "checking for opendir in -lx""... $ac_c" 1>&6
|
||||
echo "configure:1043: checking for opendir in -lx" >&5
|
||||
echo "configure:1041: checking for opendir in -lx" >&5
|
||||
ac_lib_var=`echo x'_'opendir | sed 'y%./+-%__p_%'`
|
||||
if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
|
||||
echo $ac_n "(cached) $ac_c" 1>&6
|
||||
@@ -1047,7 +1045,7 @@ else
|
||||
ac_save_LIBS="$LIBS"
|
||||
LIBS="-lx $LIBS"
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 1051 "configure"
|
||||
#line 1049 "configure"
|
||||
#include "confdefs.h"
|
||||
/* Override any gcc2 internal prototype to avoid an error. */
|
||||
/* We use char because int might match the return type of a gcc2
|
||||
@@ -1058,7 +1056,7 @@ int main() {
|
||||
opendir()
|
||||
; return 0; }
|
||||
EOF
|
||||
if { (eval echo configure:1062: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
|
||||
if { (eval echo configure:1060: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
|
||||
rm -rf conftest*
|
||||
eval "ac_cv_lib_$ac_lib_var=yes"
|
||||
else
|
||||
@@ -1081,7 +1079,7 @@ fi
|
||||
fi
|
||||
|
||||
echo $ac_n "checking how to run the C preprocessor""... $ac_c" 1>&6
|
||||
echo "configure:1085: checking how to run the C preprocessor" >&5
|
||||
echo "configure:1083: checking how to run the C preprocessor" >&5
|
||||
# On Suns, sometimes $CPP names a directory.
|
||||
if test -n "$CPP" && test -d "$CPP"; then
|
||||
CPP=
|
||||
@@ -1096,13 +1094,13 @@ else
|
||||
# On the NeXT, cc -E runs the code through the compiler's parser,
|
||||
# not just through cpp.
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 1100 "configure"
|
||||
#line 1098 "configure"
|
||||
#include "confdefs.h"
|
||||
#include <assert.h>
|
||||
Syntax Error
|
||||
EOF
|
||||
ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
|
||||
{ (eval echo configure:1106: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
|
||||
{ (eval echo configure:1104: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
|
||||
ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
|
||||
if test -z "$ac_err"; then
|
||||
:
|
||||
@@ -1113,13 +1111,13 @@ else
|
||||
rm -rf conftest*
|
||||
CPP="${CC-cc} -E -traditional-cpp"
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 1117 "configure"
|
||||
#line 1115 "configure"
|
||||
#include "confdefs.h"
|
||||
#include <assert.h>
|
||||
Syntax Error
|
||||
EOF
|
||||
ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
|
||||
{ (eval echo configure:1123: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
|
||||
{ (eval echo configure:1121: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
|
||||
ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
|
||||
if test -z "$ac_err"; then
|
||||
:
|
||||
@@ -1130,13 +1128,13 @@ else
|
||||
rm -rf conftest*
|
||||
CPP="${CC-cc} -nologo -E"
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 1134 "configure"
|
||||
#line 1132 "configure"
|
||||
#include "confdefs.h"
|
||||
#include <assert.h>
|
||||
Syntax Error
|
||||
EOF
|
||||
ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
|
||||
{ (eval echo configure:1140: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
|
||||
{ (eval echo configure:1138: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
|
||||
ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
|
||||
if test -z "$ac_err"; then
|
||||
:
|
||||
@@ -1161,12 +1159,12 @@ fi
|
||||
echo "$ac_t""$CPP" 1>&6
|
||||
|
||||
echo $ac_n "checking for ANSI C header files""... $ac_c" 1>&6
|
||||
echo "configure:1165: checking for ANSI C header files" >&5
|
||||
echo "configure:1163: checking for ANSI C header files" >&5
|
||||
if eval "test \"`echo '$''{'ac_cv_header_stdc'+set}'`\" = set"; then
|
||||
echo $ac_n "(cached) $ac_c" 1>&6
|
||||
else
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 1170 "configure"
|
||||
#line 1168 "configure"
|
||||
#include "confdefs.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
@@ -1174,7 +1172,7 @@ else
|
||||
#include <float.h>
|
||||
EOF
|
||||
ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
|
||||
{ (eval echo configure:1178: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
|
||||
{ (eval echo configure:1176: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
|
||||
ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
|
||||
if test -z "$ac_err"; then
|
||||
rm -rf conftest*
|
||||
@@ -1191,7 +1189,7 @@ rm -f conftest*
|
||||
if test $ac_cv_header_stdc = yes; then
|
||||
# SunOS 4.x string.h does not declare mem*, contrary to ANSI.
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 1195 "configure"
|
||||
#line 1193 "configure"
|
||||
#include "confdefs.h"
|
||||
#include <string.h>
|
||||
EOF
|
||||
@@ -1209,7 +1207,7 @@ fi
|
||||
if test $ac_cv_header_stdc = yes; then
|
||||
# ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 1213 "configure"
|
||||
#line 1211 "configure"
|
||||
#include "confdefs.h"
|
||||
#include <stdlib.h>
|
||||
EOF
|
||||
@@ -1230,7 +1228,7 @@ if test "$cross_compiling" = yes; then
|
||||
:
|
||||
else
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 1234 "configure"
|
||||
#line 1232 "configure"
|
||||
#include "confdefs.h"
|
||||
#include <ctype.h>
|
||||
#define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
|
||||
@@ -1241,7 +1239,7 @@ if (XOR (islower (i), ISLOWER (i)) || toupper (i) != TOUPPER (i)) exit(2);
|
||||
exit (0); }
|
||||
|
||||
EOF
|
||||
if { (eval echo configure:1245: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
|
||||
if { (eval echo configure:1243: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
|
||||
then
|
||||
:
|
||||
else
|
||||
@@ -1268,17 +1266,17 @@ for ac_hdr in fcntl.h malloc.h sys/ioctl.h unistd.h
|
||||
do
|
||||
ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
|
||||
echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
|
||||
echo "configure:1272: checking for $ac_hdr" >&5
|
||||
echo "configure:1270: checking for $ac_hdr" >&5
|
||||
if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
|
||||
echo $ac_n "(cached) $ac_c" 1>&6
|
||||
else
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 1277 "configure"
|
||||
#line 1275 "configure"
|
||||
#include "confdefs.h"
|
||||
#include <$ac_hdr>
|
||||
EOF
|
||||
ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
|
||||
{ (eval echo configure:1282: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
|
||||
{ (eval echo configure:1280: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
|
||||
ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
|
||||
if test -z "$ac_err"; then
|
||||
rm -rf conftest*
|
||||
@@ -1306,18 +1304,18 @@ done
|
||||
|
||||
|
||||
echo $ac_n "checking for working const""... $ac_c" 1>&6
|
||||
echo "configure:1310: checking for working const" >&5
|
||||
echo "configure:1308: checking for working const" >&5
|
||||
if eval "test \"`echo '$''{'ac_cv_c_const'+set}'`\" = set"; then
|
||||
echo $ac_n "(cached) $ac_c" 1>&6
|
||||
else
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 1315 "configure"
|
||||
#line 1313 "configure"
|
||||
#include "confdefs.h"
|
||||
|
||||
int main() {
|
||||
|
||||
/* Ultrix mips cc rejects this. */
|
||||
typedef int charset[2]; const charset x;
|
||||
typedef int charset[2]; const charset x = {0,0};
|
||||
/* SunOS 4.1.1 cc rejects this. */
|
||||
char const *const *ccp;
|
||||
char **p;
|
||||
@@ -1360,7 +1358,7 @@ ccp = (char const *const *) p;
|
||||
|
||||
; return 0; }
|
||||
EOF
|
||||
if { (eval echo configure:1364: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
|
||||
if { (eval echo configure:1362: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
|
||||
rm -rf conftest*
|
||||
ac_cv_c_const=yes
|
||||
else
|
||||
@@ -1381,21 +1379,21 @@ EOF
|
||||
fi
|
||||
|
||||
echo $ac_n "checking for inline""... $ac_c" 1>&6
|
||||
echo "configure:1385: checking for inline" >&5
|
||||
echo "configure:1383: checking for inline" >&5
|
||||
if eval "test \"`echo '$''{'ac_cv_c_inline'+set}'`\" = set"; then
|
||||
echo $ac_n "(cached) $ac_c" 1>&6
|
||||
else
|
||||
ac_cv_c_inline=no
|
||||
for ac_kw in inline __inline__ __inline; do
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 1392 "configure"
|
||||
#line 1390 "configure"
|
||||
#include "confdefs.h"
|
||||
|
||||
int main() {
|
||||
} $ac_kw foo() {
|
||||
} int $ac_kw foo() {
|
||||
; return 0; }
|
||||
EOF
|
||||
if { (eval echo configure:1399: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
|
||||
if { (eval echo configure:1397: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
|
||||
rm -rf conftest*
|
||||
ac_cv_c_inline=$ac_kw; break
|
||||
else
|
||||
@@ -1421,12 +1419,12 @@ EOF
|
||||
esac
|
||||
|
||||
echo $ac_n "checking for off_t""... $ac_c" 1>&6
|
||||
echo "configure:1425: checking for off_t" >&5
|
||||
echo "configure:1423: checking for off_t" >&5
|
||||
if eval "test \"`echo '$''{'ac_cv_type_off_t'+set}'`\" = set"; then
|
||||
echo $ac_n "(cached) $ac_c" 1>&6
|
||||
else
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 1430 "configure"
|
||||
#line 1428 "configure"
|
||||
#include "confdefs.h"
|
||||
#include <sys/types.h>
|
||||
#if STDC_HEADERS
|
||||
@@ -1454,12 +1452,12 @@ EOF
|
||||
fi
|
||||
|
||||
echo $ac_n "checking for pid_t""... $ac_c" 1>&6
|
||||
echo "configure:1458: checking for pid_t" >&5
|
||||
echo "configure:1456: checking for pid_t" >&5
|
||||
if eval "test \"`echo '$''{'ac_cv_type_pid_t'+set}'`\" = set"; then
|
||||
echo $ac_n "(cached) $ac_c" 1>&6
|
||||
else
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 1463 "configure"
|
||||
#line 1461 "configure"
|
||||
#include "confdefs.h"
|
||||
#include <sys/types.h>
|
||||
#if STDC_HEADERS
|
||||
@@ -1487,12 +1485,12 @@ EOF
|
||||
fi
|
||||
|
||||
echo $ac_n "checking for size_t""... $ac_c" 1>&6
|
||||
echo "configure:1491: checking for size_t" >&5
|
||||
echo "configure:1489: checking for size_t" >&5
|
||||
if eval "test \"`echo '$''{'ac_cv_type_size_t'+set}'`\" = set"; then
|
||||
echo $ac_n "(cached) $ac_c" 1>&6
|
||||
else
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 1496 "configure"
|
||||
#line 1494 "configure"
|
||||
#include "confdefs.h"
|
||||
#include <sys/types.h>
|
||||
#if STDC_HEADERS
|
||||
@@ -1520,12 +1518,12 @@ EOF
|
||||
fi
|
||||
|
||||
echo $ac_n "checking for st_rdev in struct stat""... $ac_c" 1>&6
|
||||
echo "configure:1524: checking for st_rdev in struct stat" >&5
|
||||
echo "configure:1522: checking for st_rdev in struct stat" >&5
|
||||
if eval "test \"`echo '$''{'ac_cv_struct_st_rdev'+set}'`\" = set"; then
|
||||
echo $ac_n "(cached) $ac_c" 1>&6
|
||||
else
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 1529 "configure"
|
||||
#line 1527 "configure"
|
||||
#include "confdefs.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
@@ -1533,7 +1531,7 @@ int main() {
|
||||
struct stat s; s.st_rdev;
|
||||
; return 0; }
|
||||
EOF
|
||||
if { (eval echo configure:1537: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
|
||||
if { (eval echo configure:1535: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
|
||||
rm -rf conftest*
|
||||
ac_cv_struct_st_rdev=yes
|
||||
else
|
||||
@@ -1554,12 +1552,12 @@ EOF
|
||||
fi
|
||||
|
||||
echo $ac_n "checking whether time.h and sys/time.h may both be included""... $ac_c" 1>&6
|
||||
echo "configure:1558: checking whether time.h and sys/time.h may both be included" >&5
|
||||
echo "configure:1556: checking whether time.h and sys/time.h may both be included" >&5
|
||||
if eval "test \"`echo '$''{'ac_cv_header_time'+set}'`\" = set"; then
|
||||
echo $ac_n "(cached) $ac_c" 1>&6
|
||||
else
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 1563 "configure"
|
||||
#line 1561 "configure"
|
||||
#include "confdefs.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
@@ -1568,7 +1566,7 @@ int main() {
|
||||
struct tm *tp;
|
||||
; return 0; }
|
||||
EOF
|
||||
if { (eval echo configure:1572: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
|
||||
if { (eval echo configure:1570: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
|
||||
rm -rf conftest*
|
||||
ac_cv_header_time=yes
|
||||
else
|
||||
@@ -1609,15 +1607,6 @@ else
|
||||
fi
|
||||
|
||||
|
||||
# Check whether --with-kernel_dir or --without-kernel_dir was given.
|
||||
if test "${with_kernel_dir+set}" = set; then
|
||||
withval="$with_kernel_dir"
|
||||
kernel_dir="$withval"
|
||||
else
|
||||
kernel_dir=/usr/src/linux
|
||||
fi
|
||||
|
||||
|
||||
# Check whether --enable-jobs or --disable-jobs was given.
|
||||
if test "${enable_jobs+set}" = set; then
|
||||
enableval="$enable_jobs"
|
||||
@@ -1652,13 +1641,13 @@ fi;
|
||||
|
||||
if test $ac_cv_prog_gcc = yes; then
|
||||
echo $ac_n "checking whether ${CC-cc} needs -traditional""... $ac_c" 1>&6
|
||||
echo "configure:1656: checking whether ${CC-cc} needs -traditional" >&5
|
||||
echo "configure:1645: checking whether ${CC-cc} needs -traditional" >&5
|
||||
if eval "test \"`echo '$''{'ac_cv_prog_gcc_traditional'+set}'`\" = set"; then
|
||||
echo $ac_n "(cached) $ac_c" 1>&6
|
||||
else
|
||||
ac_pattern="Autoconf.*'x'"
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 1662 "configure"
|
||||
#line 1651 "configure"
|
||||
#include "confdefs.h"
|
||||
#include <sgtty.h>
|
||||
Autoconf TIOCGETP
|
||||
@@ -1676,7 +1665,7 @@ rm -f conftest*
|
||||
|
||||
if test $ac_cv_prog_gcc_traditional = no; then
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 1680 "configure"
|
||||
#line 1669 "configure"
|
||||
#include "confdefs.h"
|
||||
#include <termio.h>
|
||||
Autoconf TCGETA
|
||||
@@ -1698,12 +1687,12 @@ echo "$ac_t""$ac_cv_prog_gcc_traditional" 1>&6
|
||||
fi
|
||||
|
||||
echo $ac_n "checking return type of signal handlers""... $ac_c" 1>&6
|
||||
echo "configure:1702: checking return type of signal handlers" >&5
|
||||
echo "configure:1691: checking return type of signal handlers" >&5
|
||||
if eval "test \"`echo '$''{'ac_cv_type_signal'+set}'`\" = set"; then
|
||||
echo $ac_n "(cached) $ac_c" 1>&6
|
||||
else
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 1707 "configure"
|
||||
#line 1696 "configure"
|
||||
#include "confdefs.h"
|
||||
#include <sys/types.h>
|
||||
#include <signal.h>
|
||||
@@ -1720,7 +1709,7 @@ int main() {
|
||||
int i;
|
||||
; return 0; }
|
||||
EOF
|
||||
if { (eval echo configure:1724: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
|
||||
if { (eval echo configure:1713: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
|
||||
rm -rf conftest*
|
||||
ac_cv_type_signal=void
|
||||
else
|
||||
@@ -1739,12 +1728,12 @@ EOF
|
||||
|
||||
|
||||
echo $ac_n "checking for vprintf""... $ac_c" 1>&6
|
||||
echo "configure:1743: checking for vprintf" >&5
|
||||
echo "configure:1732: checking for vprintf" >&5
|
||||
if eval "test \"`echo '$''{'ac_cv_func_vprintf'+set}'`\" = set"; then
|
||||
echo $ac_n "(cached) $ac_c" 1>&6
|
||||
else
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 1748 "configure"
|
||||
#line 1737 "configure"
|
||||
#include "confdefs.h"
|
||||
/* System header to define __stub macros and hopefully few prototypes,
|
||||
which can conflict with char vprintf(); below. */
|
||||
@@ -1767,7 +1756,7 @@ vprintf();
|
||||
|
||||
; return 0; }
|
||||
EOF
|
||||
if { (eval echo configure:1771: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
|
||||
if { (eval echo configure:1760: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
|
||||
rm -rf conftest*
|
||||
eval "ac_cv_func_vprintf=yes"
|
||||
else
|
||||
@@ -1791,12 +1780,12 @@ fi
|
||||
|
||||
if test "$ac_cv_func_vprintf" != yes; then
|
||||
echo $ac_n "checking for _doprnt""... $ac_c" 1>&6
|
||||
echo "configure:1795: checking for _doprnt" >&5
|
||||
echo "configure:1784: checking for _doprnt" >&5
|
||||
if eval "test \"`echo '$''{'ac_cv_func__doprnt'+set}'`\" = set"; then
|
||||
echo $ac_n "(cached) $ac_c" 1>&6
|
||||
else
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 1800 "configure"
|
||||
#line 1789 "configure"
|
||||
#include "confdefs.h"
|
||||
/* System header to define __stub macros and hopefully few prototypes,
|
||||
which can conflict with char _doprnt(); below. */
|
||||
@@ -1819,7 +1808,7 @@ _doprnt();
|
||||
|
||||
; return 0; }
|
||||
EOF
|
||||
if { (eval echo configure:1823: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
|
||||
if { (eval echo configure:1812: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
|
||||
rm -rf conftest*
|
||||
eval "ac_cv_func__doprnt=yes"
|
||||
else
|
||||
@@ -1846,12 +1835,12 @@ fi
|
||||
for ac_func in mkdir rmdir uname
|
||||
do
|
||||
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
|
||||
echo "configure:1850: checking for $ac_func" >&5
|
||||
echo "configure:1839: checking for $ac_func" >&5
|
||||
if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
|
||||
echo $ac_n "(cached) $ac_c" 1>&6
|
||||
else
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 1855 "configure"
|
||||
#line 1844 "configure"
|
||||
#include "confdefs.h"
|
||||
/* System header to define __stub macros and hopefully few prototypes,
|
||||
which can conflict with char $ac_func(); below. */
|
||||
@@ -1874,7 +1863,7 @@ $ac_func();
|
||||
|
||||
; return 0; }
|
||||
EOF
|
||||
if { (eval echo configure:1878: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
|
||||
if { (eval echo configure:1867: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
|
||||
rm -rf conftest*
|
||||
eval "ac_cv_func_$ac_func=yes"
|
||||
else
|
||||
@@ -1902,14 +1891,14 @@ done
|
||||
if test x$READLINE = xyes; then
|
||||
|
||||
echo $ac_n "checking for library containing tgetent""... $ac_c" 1>&6
|
||||
echo "configure:1906: checking for library containing tgetent" >&5
|
||||
echo "configure:1895: checking for library containing tgetent" >&5
|
||||
if eval "test \"`echo '$''{'ac_cv_search_tgetent'+set}'`\" = set"; then
|
||||
echo $ac_n "(cached) $ac_c" 1>&6
|
||||
else
|
||||
ac_func_search_save_LIBS="$LIBS"
|
||||
ac_cv_search_tgetent="no"
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 1913 "configure"
|
||||
#line 1902 "configure"
|
||||
#include "confdefs.h"
|
||||
/* Override any gcc2 internal prototype to avoid an error. */
|
||||
/* We use char because int might match the return type of a gcc2
|
||||
@@ -1920,7 +1909,7 @@ int main() {
|
||||
tgetent()
|
||||
; return 0; }
|
||||
EOF
|
||||
if { (eval echo configure:1924: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
|
||||
if { (eval echo configure:1913: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
|
||||
rm -rf conftest*
|
||||
ac_cv_search_tgetent="none required"
|
||||
else
|
||||
@@ -1931,7 +1920,7 @@ rm -f conftest*
|
||||
test "$ac_cv_search_tgetent" = "no" && for i in ncurses curses termcap termlib; do
|
||||
LIBS="-l$i $ac_func_search_save_LIBS"
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 1935 "configure"
|
||||
#line 1924 "configure"
|
||||
#include "confdefs.h"
|
||||
/* Override any gcc2 internal prototype to avoid an error. */
|
||||
/* We use char because int might match the return type of a gcc2
|
||||
@@ -1942,7 +1931,7 @@ int main() {
|
||||
tgetent()
|
||||
; return 0; }
|
||||
EOF
|
||||
if { (eval echo configure:1946: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
|
||||
if { (eval echo configure:1935: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
|
||||
rm -rf conftest*
|
||||
ac_cv_search_tgetent="-l$i"
|
||||
break
|
||||
@@ -1976,7 +1965,7 @@ fi
|
||||
|
||||
if test x$READLINE = xyes; then
|
||||
echo $ac_n "checking for readline in -lreadline""... $ac_c" 1>&6
|
||||
echo "configure:1980: checking for readline in -lreadline" >&5
|
||||
echo "configure:1969: checking for readline in -lreadline" >&5
|
||||
ac_lib_var=`echo readline'_'readline | sed 'y%./+-%__p_%'`
|
||||
if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
|
||||
echo $ac_n "(cached) $ac_c" 1>&6
|
||||
@@ -1984,7 +1973,7 @@ else
|
||||
ac_save_LIBS="$LIBS"
|
||||
LIBS="-lreadline $LIBS"
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 1988 "configure"
|
||||
#line 1977 "configure"
|
||||
#include "confdefs.h"
|
||||
/* Override any gcc2 internal prototype to avoid an error. */
|
||||
/* We use char because int might match the return type of a gcc2
|
||||
@@ -1995,7 +1984,7 @@ int main() {
|
||||
readline()
|
||||
; return 0; }
|
||||
EOF
|
||||
if { (eval echo configure:1999: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
|
||||
if { (eval echo configure:1988: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
|
||||
rm -rf conftest*
|
||||
eval "ac_cv_lib_$ac_lib_var=yes"
|
||||
else
|
||||
@@ -2031,7 +2020,64 @@ package as well (which may be called readline-devel or something similar).
|
||||
|
||||
fi
|
||||
|
||||
echo $ac_n "checking for rl_completion_matches""... $ac_c" 1>&6
|
||||
echo "configure:2025: checking for rl_completion_matches" >&5
|
||||
if eval "test \"`echo '$''{'ac_cv_func_rl_completion_matches'+set}'`\" = set"; then
|
||||
echo $ac_n "(cached) $ac_c" 1>&6
|
||||
else
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
#line 2030 "configure"
|
||||
#include "confdefs.h"
|
||||
/* System header to define __stub macros and hopefully few prototypes,
|
||||
which can conflict with char rl_completion_matches(); below. */
|
||||
#include <assert.h>
|
||||
/* Override any gcc2 internal prototype to avoid an error. */
|
||||
/* We use char because int might match the return type of a gcc2
|
||||
builtin and then its argument prototype would still apply. */
|
||||
char rl_completion_matches();
|
||||
|
||||
int main() {
|
||||
|
||||
/* The GNU C library defines this for functions which it implements
|
||||
to always fail with ENOSYS. Some functions are actually named
|
||||
something starting with __ and the normal name is an alias. */
|
||||
#if defined (__stub_rl_completion_matches) || defined (__stub___rl_completion_matches)
|
||||
choke me
|
||||
#else
|
||||
rl_completion_matches();
|
||||
#endif
|
||||
|
||||
; return 0; }
|
||||
EOF
|
||||
if { (eval echo configure:2053: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
|
||||
rm -rf conftest*
|
||||
eval "ac_cv_func_rl_completion_matches=yes"
|
||||
else
|
||||
echo "configure: failed program was:" >&5
|
||||
cat conftest.$ac_ext >&5
|
||||
rm -rf conftest*
|
||||
eval "ac_cv_func_rl_completion_matches=no"
|
||||
fi
|
||||
rm -f conftest*
|
||||
fi
|
||||
|
||||
if eval "test \"`echo '$ac_cv_func_'rl_completion_matches`\" = yes"; then
|
||||
echo "$ac_t""yes" 1>&6
|
||||
HAVE_RL_COMPLETION_MATCHES=yes
|
||||
else
|
||||
echo "$ac_t""no" 1>&6
|
||||
HAVE_RL_COMPLETION_MATCHES=no
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
if test "-f VERSION"; then
|
||||
LVM_VERSION="\"`cat VERSION`\""
|
||||
else
|
||||
LVM_VERSION="Unknown"
|
||||
fi
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -2159,9 +2205,12 @@ include/Makefile \
|
||||
lib/Makefile \
|
||||
man/Makefile \
|
||||
tools/Makefile \
|
||||
tools/version.h \
|
||||
test/mm/Makefile \
|
||||
test/device/Makefile \
|
||||
test/format1/Makefile \
|
||||
test/regex/Makefile \
|
||||
test/filters/Makefile \
|
||||
" | sed "s/:[^ ]*//g"` conftest*; exit 1' 1 2 15
|
||||
EOF
|
||||
cat >> $CONFIG_STATUS <<EOF
|
||||
@@ -2206,9 +2255,10 @@ s%@CPP@%$CPP%g
|
||||
s%@JOBS@%$JOBS%g
|
||||
s%@STATIC_LINK@%$STATIC_LINK%g
|
||||
s%@READLINE@%$READLINE%g
|
||||
s%@kernel_dir@%$kernel_dir%g
|
||||
s%@HAVE_RL_COMPLETION_MATCHES@%$HAVE_RL_COMPLETION_MATCHES%g
|
||||
s%@OWNER@%$OWNER%g
|
||||
s%@GROUP@%$GROUP%g
|
||||
s%@LVM_VERSION@%$LVM_VERSION%g
|
||||
|
||||
CEOF
|
||||
EOF
|
||||
@@ -2257,9 +2307,12 @@ include/Makefile \
|
||||
lib/Makefile \
|
||||
man/Makefile \
|
||||
tools/Makefile \
|
||||
tools/version.h \
|
||||
test/mm/Makefile \
|
||||
test/device/Makefile \
|
||||
test/format1/Makefile \
|
||||
test/regex/Makefile \
|
||||
test/filters/Makefile \
|
||||
"}
|
||||
EOF
|
||||
cat >> $CONFIG_STATUS <<\EOF
|
||||
|
||||
21
configure.in
21
configure.in
@@ -61,12 +61,6 @@ AC_ARG_WITH(group,
|
||||
[ GROUP="$withval" ],
|
||||
[ GROUP="root" ])
|
||||
|
||||
dnl -- Where the linux src tree is
|
||||
AC_ARG_WITH(kernel_dir,
|
||||
[ --with-kernel_dir=DIR linux kernel source in DIR [/usr/src/linux]],
|
||||
[ kernel_dir="$withval" ],
|
||||
[ kernel_dir=/usr/src/linux ])
|
||||
|
||||
AC_ARG_ENABLE(jobs, [ --enable-jobs=NUM Number of jobs to run simultaneously], JOBS=-j$enableval, JOBS=)
|
||||
|
||||
dnl Enables staticly linked tools
|
||||
@@ -118,14 +112,24 @@ package as well (which may be called readline-devel or something similar).
|
||||
)
|
||||
exit
|
||||
)
|
||||
AC_CHECK_FUNC(rl_completion_matches, HAVE_RL_COMPLETION_MATCHES=yes,
|
||||
HAVE_RL_COMPLETION_MATCHES=no)
|
||||
fi
|
||||
|
||||
if test "-f VERSION"; then
|
||||
LVM_VERSION="\"`cat VERSION`\""
|
||||
else
|
||||
LVM_VERSION="Unknown"
|
||||
fi
|
||||
|
||||
AC_SUBST(JOBS)
|
||||
AC_SUBST(STATIC_LINK)
|
||||
AC_SUBST(READLINE)
|
||||
AC_SUBST(kernel_dir)
|
||||
AC_SUBST(HAVE_RL_COMPLETION_MATCHES)
|
||||
AC_SUBST(OWNER)
|
||||
AC_SUBST(GROUP)
|
||||
AC_SUBST(LIBS)
|
||||
AC_SUBST(LVM_VERSION)
|
||||
dnl First and last lines should not contain files to generate in order to
|
||||
dnl keep utility scripts running properly
|
||||
AC_OUTPUT( \
|
||||
@@ -135,7 +139,10 @@ include/Makefile \
|
||||
lib/Makefile \
|
||||
man/Makefile \
|
||||
tools/Makefile \
|
||||
tools/version.h \
|
||||
test/mm/Makefile \
|
||||
test/device/Makefile \
|
||||
test/format1/Makefile \
|
||||
test/regex/Makefile \
|
||||
test/filters/Makefile \
|
||||
)
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
Wow! This is really incredible documentation!
|
||||
137
doc/example.conf
Normal file
137
doc/example.conf
Normal file
@@ -0,0 +1,137 @@
|
||||
# This is an example configuration file for the LVM2 system. It
|
||||
# contains the default settings that would be used if there was no
|
||||
# /etc/lvm/lvm.conf file.
|
||||
# Refer to 'man lvm.conf' for further information.
|
||||
|
||||
|
||||
# This section allows the user to configure which block devices should
|
||||
# be used by the LVM system.
|
||||
devices {
|
||||
|
||||
# where do you want your volume groups to appear ?
|
||||
dir = "/dev"
|
||||
|
||||
# An array of directories that contain the device nodes you wish
|
||||
# to use with LVM2.
|
||||
scan = "/dev"
|
||||
|
||||
# A very important option, that allows you to tune the LVM2 system
|
||||
# to just look at a restricted set of devices that you're
|
||||
# interested in.
|
||||
|
||||
# The filter consists of an array of regular expressions. These
|
||||
# expressions can be delimited by a character of your choice, and
|
||||
# prefixed with either an 'a' (for accept) or 'r' (for reject).
|
||||
# ATM you cannot use anchors (^ or $) in your regular expression.
|
||||
|
||||
# By default we accept every block device:
|
||||
filter = "a/.*/"
|
||||
|
||||
# When testing I like to work with just loopback devices:
|
||||
# filter = ["a/loop/", "r/.*/"]
|
||||
|
||||
# Or maybe all loops and ide drives except hdc:
|
||||
# filter =["a|loop|", "r|/dev/hdc|", "a|/dev/ide|", "r|.*|"]
|
||||
|
||||
# The results of all the filtering are cached on disk to avoid
|
||||
# rescanning dud devices (which can take a very long time). By
|
||||
# default this cache file is hidden in the /etc/lvm directory, it
|
||||
# is human readable to aid filter debugging.
|
||||
cache = "/etc/lvm/.cache"
|
||||
|
||||
# You can turn off writing this cache file by setting this to 0.
|
||||
write_cache_state = 1
|
||||
}
|
||||
|
||||
# A section that allows the user to configure the nature of the
|
||||
# information that LVM2 reports.
|
||||
log {
|
||||
|
||||
# Where should the log of error and debug messages go ? By
|
||||
# default there is no log.
|
||||
#file = "/var/log/lvm2.log"
|
||||
|
||||
# Should we overwrite the last log. By default we append.
|
||||
overwrite = 0
|
||||
|
||||
# There are 9 log levels, with 9 being the most verbose.
|
||||
level = 3
|
||||
|
||||
# Controls the messages sent to stdout or stderr while running
|
||||
# LVM2. There are three levels of verbosity, 3 being the most
|
||||
# verbose.
|
||||
verbose = 0
|
||||
|
||||
# Should we send log messages through syslog?
|
||||
# 1 is yes; 0 is no.
|
||||
syslog = 1
|
||||
|
||||
# Choose format of output messages
|
||||
# Whether or not (1 or 0) to indent messages according to their severity
|
||||
indent = 1
|
||||
|
||||
# Whether or not (1 or 0) to display the command name on each line output
|
||||
command_names = 0
|
||||
|
||||
# A prefix to use before the message text (but after the command name,
|
||||
# if selected)
|
||||
prefix = " "
|
||||
|
||||
# To make the messages look similar to the original LVM use:
|
||||
# indent = 0
|
||||
# command_names = 1
|
||||
# prefix = " -- "
|
||||
}
|
||||
|
||||
# Configuration of metadata backups and archiving. In LVM2 when we
|
||||
# talk about a 'backup' we mean making a copy of the metadata for the
|
||||
# *current* system. The 'archive' contains old metadata configurations.
|
||||
# Backups are stored in a human readeable text format.
|
||||
backup {
|
||||
|
||||
# Should we maintain a backup of the current metadata configuration ?
|
||||
# Use 1 for Yes; 0 for No.
|
||||
# Think very hard before turning this off.
|
||||
backup = 1
|
||||
|
||||
# Where shall we keep it ?
|
||||
backup_dir = "/etc/lvm/backup"
|
||||
|
||||
|
||||
# Should we maintain an archive of old metadata configurations.
|
||||
# Use 1 for Yes; 0 for No.
|
||||
# On by default. Think very hard before turning this off.
|
||||
archive = 1
|
||||
|
||||
# Where should archived files go ?
|
||||
archive_dir = "/etc/lvm/archive"
|
||||
|
||||
# What is the minimum number of archive files you wish to keep ?
|
||||
retain_min = 10
|
||||
|
||||
# What is the minimum time you wish to keep an archive file for ?
|
||||
retain_days = 30
|
||||
}
|
||||
|
||||
# Settings for the running LVM2 in shell mode.
|
||||
shell {
|
||||
|
||||
# Number of lines of history to store in ~/.lvm_history
|
||||
history_size = 100
|
||||
}
|
||||
|
||||
# Miscellaneous global settings
|
||||
global {
|
||||
|
||||
# The file creation mask for any files and directories created.
|
||||
# Interpreted as octal if the first digit is zero.
|
||||
umask = 077
|
||||
|
||||
# Allow other users to read the files
|
||||
#umask = 022
|
||||
|
||||
# Enabling test mode means that no changes to the on disk metadata
|
||||
# will be made. Equivalent to having the -t option on every
|
||||
# command. Defaults to off.
|
||||
test = 0
|
||||
}
|
||||
52
doc/pvmove_outline.txt
Normal file
52
doc/pvmove_outline.txt
Normal file
@@ -0,0 +1,52 @@
|
||||
Let's say we have an LV, made up of three segments of different PV's,
|
||||
I've also added in the device major:minor as this will be useful
|
||||
later:
|
||||
|
||||
+-----------------------------+
|
||||
| PV1 | PV2 | PV3 | 254:3
|
||||
+----------+---------+--------+
|
||||
|
||||
|
||||
Now our hero decides to PV move PV2 to PV4:
|
||||
|
||||
1. Suspend our LV (254:3), this starts queueing all io, and flushes
|
||||
all pending io. Once the suspend has completed we are free to change
|
||||
the mapping table.
|
||||
|
||||
2. Set up *another* (254:4) device with the mapping table of our LV.
|
||||
|
||||
3. Load a new mapping table into (254:3) that has identity targets for
|
||||
parts that aren't moving, and a mirror target for parts that are.
|
||||
|
||||
4. Unsuspend (254:3)
|
||||
|
||||
So now we have:
|
||||
destination of copy
|
||||
+--------------------->--------------+
|
||||
| |
|
||||
+-----------------------------+ + -----------+
|
||||
| Identity | mirror | Ident. | 254:3 | PV4 |
|
||||
+----------+---------+--------+ +------------+
|
||||
| | |
|
||||
\/ \/ \/
|
||||
+-----------------------------+
|
||||
| PV1 | PV2 | PV3 | 254:4
|
||||
+----------+---------+--------+
|
||||
|
||||
Any writes to segment2 of the LV get intercepted by the mirror target
|
||||
who checks that that chunk has been copied to the new destination, if
|
||||
it hasn't it queues the initial copy and defers the current io until
|
||||
it has finished. Then the current io is written to *both* PV2 and the
|
||||
PV4.
|
||||
|
||||
5. When the copying has completed 254:3 is suspended/pending flushed.
|
||||
|
||||
6. 254:4 is taken down
|
||||
|
||||
7. metadata is updated on disk
|
||||
|
||||
8. 254:3 has new mapping table loaded:
|
||||
|
||||
+-----------------------------+
|
||||
| PV1 | PV4 | PV3 | 254:3
|
||||
+----------+---------+--------+
|
||||
@@ -1 +0,0 @@
|
||||
The driver directory
|
||||
@@ -1,104 +0,0 @@
|
||||
The main goal of this driver is to support volume management in
|
||||
general, not just for LVM. The kernel should provide general
|
||||
services, not support specific applications. eg, The driver has no
|
||||
concept of volume groups.
|
||||
|
||||
The driver does this by mapping sector ranges for the logical device
|
||||
onto 'targets'.
|
||||
|
||||
When the logical device is accessed, the make_request function looks
|
||||
up the correct target for the given sector, and then asks this target
|
||||
to do the remapping.
|
||||
|
||||
A btree structure is used to hold the sector range -> target mapping.
|
||||
Since we know all the entries in the btree in advance we can make a
|
||||
very compact tree, omitting pointers to child nodes, (child nodes
|
||||
locations can be calculated). Typical users would find they only have
|
||||
a handful of targets for each logical volume LV.
|
||||
|
||||
Benchmarking with bonnie++ suggests that this is certainly no slower
|
||||
than current LVM.
|
||||
|
||||
|
||||
Target types are not hard coded, instead the register_mapping_type
|
||||
function should be called. A target type is specified using three
|
||||
functions (see the header):
|
||||
|
||||
dm_ctr_fn - takes a string and contructs a target specific piece of
|
||||
context data.
|
||||
dm_dtr_fn - destroy contexts.
|
||||
dm_map_fn - function that takes a buffer_head and some previously
|
||||
constructed context and performs the remapping.
|
||||
|
||||
Currently there are two two trivial mappers, which are automatically
|
||||
registered: 'linear', and 'io_error'. Linear alone is enough to
|
||||
implement most of LVM.
|
||||
|
||||
|
||||
I do not like ioctl interfaces so this driver is currently controlled
|
||||
through a /proc interface. /proc/device-mapper/control allows you to
|
||||
create and remove devices by 'cat'ing a line of the following format:
|
||||
|
||||
create <device name> [minor no]
|
||||
remove <device name>
|
||||
|
||||
If you're not using devfs you'll have to do the mknod'ing yourself,
|
||||
otherwise the device will appear in /dev/device-mapper automatically.
|
||||
|
||||
/proc/device-mapper/<device name> accepts the mapping table:
|
||||
|
||||
begin
|
||||
<sector start> <length> <target name> <target args>...
|
||||
...
|
||||
end
|
||||
|
||||
where <target args> are specific to the target type, eg. for a linear
|
||||
mapping:
|
||||
|
||||
<sector start> <length> linear <major> <minor> <start>
|
||||
|
||||
and the io-err mapping:
|
||||
|
||||
<sector start> <length> io-err
|
||||
|
||||
The begin/end lines around the table are nasty, they should be handled
|
||||
by open/close of the file.
|
||||
|
||||
The interface is far from complete, currently loading a table either
|
||||
succeeds or fails, you have no way of knowing which line of the
|
||||
mapping table was erroneous. Also there is no way to get status
|
||||
information out, though this should be easy to add, either as another
|
||||
/proc file, or just by reading the same /proc/device-mapper/<device>
|
||||
file. I will be seperating the loading and validation of a table from
|
||||
the binding of a valid table to a device.
|
||||
|
||||
It has been suggested that I should implement a little custom
|
||||
filesystem rather than labouring with /proc. For example doing a
|
||||
mkdir foo in /wherever/device-mapper would create a new device. People
|
||||
waiting for a status change (eg, a mirror operation to complete) could
|
||||
poll a file. Does the community find this an acceptable way to go ?
|
||||
|
||||
|
||||
At the moment the table assumes 32 bit keys (sectors), the move to 64
|
||||
bits will involve no interface changes, since the tables will be read
|
||||
in as ascii data. A different table implementation can therefor be
|
||||
provided at another time. Either just by changing offset_t to 64
|
||||
bits, or maybe implementing a structure which looks up the keys in
|
||||
stages (ie, 32 bits at a time).
|
||||
|
||||
|
||||
More interesting targets:
|
||||
|
||||
striped mapping; given a stripe size and a number of device regions
|
||||
this would stripe data across the regions. Especially useful, since
|
||||
we could limit each striped region to a 32 bit area and then avoid
|
||||
nasty 64 bit %'s.
|
||||
|
||||
mirror mapping; would set off a kernel thread slowly copying data from
|
||||
one region to another, ensuring that any new writes got copied to both
|
||||
destinations correctly. Enabling us to implement a live pvmove
|
||||
correctly.
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,88 +0,0 @@
|
||||
/*
|
||||
* device-mapper.h
|
||||
*
|
||||
* Copyright (C) 2001 Sistina Software (UK) Limited.
|
||||
*
|
||||
* This file is released under the GPL.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Changelog
|
||||
*
|
||||
* 14/08/2001 - First version [Joe Thornber]
|
||||
*/
|
||||
|
||||
#ifndef DEVICE_MAPPER_H
|
||||
#define DEVICE_MAPPER_H
|
||||
|
||||
#include <linux/major.h>
|
||||
|
||||
/* FIXME: Use value from local range for now, for co-existence with LVM 1 */
|
||||
#define DM_BLK_MAJOR 124
|
||||
|
||||
struct dm_table;
|
||||
struct dm_dev;
|
||||
struct text_region;
|
||||
typedef unsigned int offset_t;
|
||||
|
||||
typedef void (*dm_error_fn)(const char *message, void *private);
|
||||
|
||||
/*
|
||||
* constructor, destructor and map fn types
|
||||
*/
|
||||
typedef int (*dm_ctr_fn)(struct dm_table *t, offset_t b, offset_t l,
|
||||
struct text_region *args, void **context,
|
||||
dm_error_fn err, void *e_private);
|
||||
|
||||
typedef void (*dm_dtr_fn)(struct dm_table *t, void *c);
|
||||
typedef int (*dm_map_fn)(struct buffer_head *bh, int rw, void *context);
|
||||
typedef int (*dm_err_fn)(struct buffer_head *bh, int rw, void *context);
|
||||
|
||||
|
||||
/*
|
||||
* Contructors should call this to make sure any
|
||||
* destination devices are handled correctly
|
||||
* (ie. opened/closed).
|
||||
*/
|
||||
int dm_table_get_device(struct dm_table *t, const char *path,
|
||||
struct dm_dev **result);
|
||||
void dm_table_put_device(struct dm_table *table, struct dm_dev *d);
|
||||
|
||||
/*
|
||||
* information about a target type
|
||||
*/
|
||||
struct target_type {
|
||||
const char *name;
|
||||
struct module *module;
|
||||
dm_ctr_fn ctr;
|
||||
dm_dtr_fn dtr;
|
||||
dm_map_fn map;
|
||||
dm_err_fn err;
|
||||
};
|
||||
|
||||
int dm_register_target(struct target_type *t);
|
||||
int dm_unregister_target(struct target_type *t);
|
||||
|
||||
/*
|
||||
* These may be useful for people writing target
|
||||
* types.
|
||||
*/
|
||||
struct text_region {
|
||||
const char *b;
|
||||
const char *e;
|
||||
};
|
||||
|
||||
int dm_get_number(struct text_region *txt, unsigned int *n);
|
||||
int dm_get_line(struct text_region *txt, struct text_region *line);
|
||||
int dm_get_word(struct text_region *txt, struct text_region *word);
|
||||
void dm_txt_copy(char *dest, size_t max, struct text_region *txt);
|
||||
void dm_eat_space(struct text_region *txt);
|
||||
|
||||
|
||||
#endif /* DEVICE_MAPPER_H */
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* c-file-style: "linux"
|
||||
* End:
|
||||
*/
|
||||
@@ -1,553 +0,0 @@
|
||||
/*
|
||||
* *very* heavily based on ramfs
|
||||
*
|
||||
* Copyright (C) 2001 Sistina Software
|
||||
*
|
||||
* This file is released under the GPL.
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/pagemap.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/string.h>
|
||||
#include <linux/locks.h>
|
||||
#include <linux/file.h>
|
||||
|
||||
#include <asm/uaccess.h>
|
||||
|
||||
#include "dm.h"
|
||||
|
||||
/* some magic number */
|
||||
#define DM_MAGIC 0x444D4653
|
||||
|
||||
static struct super_operations dm_ops;
|
||||
static struct address_space_operations dm_aops;
|
||||
static struct file_operations dm_dir_operations;
|
||||
static struct file_operations dm_file_operations;
|
||||
static struct inode_operations dm_dir_inode_operations;
|
||||
|
||||
struct vfsmount *_mnt;
|
||||
|
||||
static int _unlink(struct inode *dir, struct dentry *dentry);
|
||||
|
||||
#define NOT_A_TABLE ((struct dm_table *) 1)
|
||||
|
||||
/*
|
||||
* context for the line splitter and error function.
|
||||
*/
|
||||
struct line_c {
|
||||
unsigned int line_num;
|
||||
loff_t next_read;
|
||||
char data[MAX_TARGET_LINE];
|
||||
|
||||
struct file *in;
|
||||
struct file *out;
|
||||
};
|
||||
|
||||
static int is_identifier(const char *str, int len)
|
||||
{
|
||||
if (len > DM_NAME_LEN - 1)
|
||||
return 0;
|
||||
|
||||
while(len--) {
|
||||
if (!isalnum(*str) && *str != '_')
|
||||
return 0;
|
||||
str++;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Grabs lines one at a time from the table file.
|
||||
*/
|
||||
int extract_line(struct text_region *line, void *private)
|
||||
{
|
||||
struct line_c *lc = (struct line_c *) private;
|
||||
struct text_region text;
|
||||
ssize_t n;
|
||||
loff_t off = lc->next_read;
|
||||
const char *read_begin;
|
||||
mm_segment_t fs;
|
||||
|
||||
fs = get_fs();
|
||||
set_fs(get_ds());
|
||||
|
||||
n = lc->in->f_op->read(lc->in, lc->data, sizeof (lc->data), &off);
|
||||
|
||||
set_fs(fs);
|
||||
|
||||
if (n <= 0)
|
||||
return 0;
|
||||
|
||||
read_begin = text.b = lc->data;
|
||||
text.e = lc->data + n;
|
||||
|
||||
if (!dm_get_line(&text, line))
|
||||
return 0;
|
||||
|
||||
lc->line_num++;
|
||||
lc->next_read += line->e - read_begin;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static struct file *open_error_file(struct file *table)
|
||||
{
|
||||
struct file *f;
|
||||
char *name, *buffer;
|
||||
int bufsize = PATH_MAX + 1;
|
||||
|
||||
if (bufsize < PAGE_SIZE)
|
||||
bufsize = PAGE_SIZE;
|
||||
|
||||
/* Get space to append ".err" */
|
||||
buffer = (char *) kmalloc(bufsize + 4, GFP_KERNEL);
|
||||
|
||||
if (!buffer)
|
||||
return 0;
|
||||
|
||||
/* Get path name */
|
||||
name = d_path(table->f_dentry, table->f_vfsmnt, buffer, bufsize);
|
||||
|
||||
if (!name) {
|
||||
kfree(buffer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Create error file */
|
||||
strcat(name, ".err");
|
||||
f = filp_open(name, O_WRONLY | O_TRUNC | O_CREAT, S_IRUGO);
|
||||
|
||||
kfree(buffer);
|
||||
|
||||
if (f)
|
||||
f->f_dentry->d_inode->u.generic_ip = NOT_A_TABLE;
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
static void close_error_file(struct file *out)
|
||||
{
|
||||
fput(out);
|
||||
}
|
||||
|
||||
static void parse_error(const char *message, void *private)
|
||||
{
|
||||
struct line_c *lc = (struct line_c *) private;
|
||||
char buffer[32];
|
||||
|
||||
#define emit(b, l) lc->out->f_op->write(lc->out, (b), (l), &lc->out->f_pos)
|
||||
|
||||
emit(lc->in->f_dentry->d_name.name, lc->in->f_dentry->d_name.len);
|
||||
sprintf(buffer, "(%d): ", lc->line_num);
|
||||
emit(buffer, strlen(buffer));
|
||||
emit(message, strlen(message));
|
||||
emit("\n", 1);
|
||||
|
||||
#undef emit
|
||||
}
|
||||
|
||||
static int _release(struct inode *inode, struct file *f)
|
||||
{
|
||||
/* FIXME: we should lock the inode to
|
||||
prevent someone else opening it while
|
||||
we are parsing */
|
||||
struct line_c *lc;
|
||||
struct dm_table *table = (struct dm_table *) inode->u.generic_ip;
|
||||
|
||||
/* noop for files without tables (.err files) */
|
||||
if (table == NOT_A_TABLE)
|
||||
return 0;
|
||||
|
||||
/* only bother parsing if it was open for a write */
|
||||
if (!(f->f_mode & S_IWUGO))
|
||||
return 0;
|
||||
|
||||
/* free off the old table */
|
||||
if (table) {
|
||||
dm_table_destroy(table);
|
||||
inode->u.generic_ip = 0;
|
||||
}
|
||||
|
||||
if (!(lc = kmalloc(sizeof (*lc), GFP_KERNEL)))
|
||||
return -ENOMEM;
|
||||
|
||||
memset(lc, 0, sizeof (*lc));
|
||||
lc->in = f;
|
||||
|
||||
if (!(lc->out = open_error_file(lc->in)))
|
||||
return -ENOMEM;
|
||||
|
||||
table = dm_parse(extract_line, lc, parse_error, lc);
|
||||
close_error_file(lc->out);
|
||||
|
||||
kfree(lc);
|
||||
inode->u.generic_ip = table;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void _put_inode(struct inode *inode)
|
||||
{
|
||||
struct mapped_device *md =
|
||||
(struct mapped_device *) inode->u.generic_ip;
|
||||
struct dm_table *table = (struct dm_table *) inode->u.generic_ip;
|
||||
|
||||
if (inode->i_mode & S_IFDIR) {
|
||||
if (md)
|
||||
dm_remove(md);
|
||||
|
||||
} else {
|
||||
if (table)
|
||||
dm_table_destroy(table);
|
||||
|
||||
}
|
||||
|
||||
inode->u.generic_ip = 0;
|
||||
force_delete(inode);
|
||||
}
|
||||
|
||||
static int _statfs(struct super_block *sb, struct statfs *buf)
|
||||
{
|
||||
buf->f_type = DM_MAGIC;
|
||||
buf->f_bsize = PAGE_CACHE_SIZE;
|
||||
buf->f_namelen = 255;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Lookup the data. This is trivial - if the dentry didn't already
|
||||
* exist, we know it is negative.
|
||||
*/
|
||||
static struct dentry *_lookup(struct inode *dir, struct dentry *dentry)
|
||||
{
|
||||
d_add(dentry, NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Read a page. Again trivial. If it didn't already exist
|
||||
* in the page cache, it is zero-filled.
|
||||
*/
|
||||
static int _readpage(struct file *file, struct page *page)
|
||||
{
|
||||
if (!Page_Uptodate(page)) {
|
||||
memset(kmap(page), 0, PAGE_CACHE_SIZE);
|
||||
kunmap(page);
|
||||
flush_dcache_page(page);
|
||||
SetPageUptodate(page);
|
||||
}
|
||||
UnlockPage(page);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Writing: just make sure the page gets marked dirty, so that
|
||||
* the page stealer won't grab it.
|
||||
*/
|
||||
static int _writepage(struct page *page)
|
||||
{
|
||||
SetPageDirty(page);
|
||||
UnlockPage(page);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _prepare_write(struct file *file, struct page *page,
|
||||
unsigned offset, unsigned to)
|
||||
{
|
||||
void *addr = kmap(page);
|
||||
if (!Page_Uptodate(page)) {
|
||||
memset(addr, 0, PAGE_CACHE_SIZE);
|
||||
flush_dcache_page(page);
|
||||
SetPageUptodate(page);
|
||||
}
|
||||
SetPageDirty(page);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _commit_write(struct file *file, struct page *page,
|
||||
unsigned offset, unsigned to)
|
||||
{
|
||||
struct inode *inode = page->mapping->host;
|
||||
loff_t pos = ((loff_t) page->index << PAGE_CACHE_SHIFT) + to;
|
||||
|
||||
kunmap(page);
|
||||
if (pos > inode->i_size)
|
||||
inode->i_size = pos;
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct inode *_get_inode(struct super_block *sb, int mode, int dev)
|
||||
{
|
||||
struct inode *inode = new_inode(sb);
|
||||
|
||||
if (inode) {
|
||||
inode->i_mode = mode;
|
||||
inode->i_uid = current->fsuid;
|
||||
inode->i_gid = current->fsgid;
|
||||
inode->i_blksize = PAGE_CACHE_SIZE;
|
||||
inode->i_blocks = 0;
|
||||
inode->i_rdev = NODEV;
|
||||
inode->i_mapping->a_ops = &dm_aops;
|
||||
inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
|
||||
switch (mode & S_IFMT) {
|
||||
case S_IFBLK:
|
||||
case S_IFCHR:
|
||||
init_special_inode(inode, mode, dev);
|
||||
break;
|
||||
case S_IFREG:
|
||||
inode->i_fop = &dm_file_operations;
|
||||
break;
|
||||
case S_IFDIR:
|
||||
inode->i_op = &dm_dir_inode_operations;
|
||||
inode->i_fop = &dm_dir_operations;
|
||||
break;
|
||||
case S_IFLNK:
|
||||
inode->i_op = &page_symlink_inode_operations;
|
||||
break;
|
||||
default:
|
||||
make_bad_inode(inode);
|
||||
}
|
||||
}
|
||||
return inode;
|
||||
}
|
||||
|
||||
/*
|
||||
* File creation. Allocate an inode, and we're done..
|
||||
*/
|
||||
static int _mknod(struct inode *dir, struct dentry *dentry, int mode)
|
||||
{
|
||||
int error = -ENOSPC;
|
||||
struct inode *inode = _get_inode(dir->i_sb, mode, 0);
|
||||
|
||||
if (inode) {
|
||||
d_instantiate(dentry, inode);
|
||||
dget(dentry); /* Extra count - pin the dentry in core */
|
||||
error = 0;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
static int _mkdir(struct inode *dir, struct dentry *dentry, int mode)
|
||||
{
|
||||
int r;
|
||||
const char *name = (const char *) dentry->d_name.name;
|
||||
struct mapped_device *md;
|
||||
|
||||
if (!is_identifier(name, dentry->d_name.len))
|
||||
return -EPERM; /* or EINVAL ? */
|
||||
|
||||
md = dm_create(name, -1);
|
||||
if (IS_ERR(md))
|
||||
return PTR_ERR(md);
|
||||
|
||||
r = _mknod(dir, dentry, mode | S_IFDIR);
|
||||
if (r) {
|
||||
dm_remove(md);
|
||||
return r;
|
||||
}
|
||||
|
||||
dentry->d_inode->u.generic_ip = md;
|
||||
md->inode = dentry->d_inode;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _rmdir(struct inode *dir, struct dentry *dentry)
|
||||
{
|
||||
int r = _unlink(dir, dentry);
|
||||
return r;
|
||||
}
|
||||
|
||||
static int _create(struct inode *dir, struct dentry *dentry, int mode)
|
||||
{
|
||||
int r;
|
||||
|
||||
if ((r = _mknod(dir, dentry, mode | S_IFREG)))
|
||||
return r;
|
||||
|
||||
dentry->d_inode->u.generic_ip = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int positive(struct dentry *dentry)
|
||||
{
|
||||
return dentry->d_inode && !d_unhashed(dentry);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check that a directory is empty (this works
|
||||
* for regular files too, they'll just always be
|
||||
* considered empty..).
|
||||
*
|
||||
* Note that an empty directory can still have
|
||||
* children, they just all have to be negative..
|
||||
*/
|
||||
static int _empty(struct dentry *dentry)
|
||||
{
|
||||
struct list_head *list;
|
||||
|
||||
spin_lock(&dcache_lock);
|
||||
list = dentry->d_subdirs.next;
|
||||
|
||||
while (list != &dentry->d_subdirs) {
|
||||
struct dentry *de = list_entry(list, struct dentry, d_child);
|
||||
|
||||
if (positive(de)) {
|
||||
spin_unlock(&dcache_lock);
|
||||
return 0;
|
||||
}
|
||||
list = list->next;
|
||||
}
|
||||
spin_unlock(&dcache_lock);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* This works for both directories and regular files.
|
||||
* (non-directories will always have empty subdirs)
|
||||
*/
|
||||
static int _unlink(struct inode *dir, struct dentry *dentry)
|
||||
{
|
||||
int retval = -ENOTEMPTY;
|
||||
|
||||
if (_empty(dentry)) {
|
||||
struct inode *inode = dentry->d_inode;
|
||||
|
||||
inode->i_nlink--;
|
||||
dput(dentry); /* Undo the count from "create" - this does all the work */
|
||||
retval = 0;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*
|
||||
* The VFS layer already does all the dentry stuff for rename,
|
||||
* we just have to decrement the usage count for the target if
|
||||
* it exists so that the VFS layer correctly free's it when it
|
||||
* gets overwritten.
|
||||
*/
|
||||
static int _rename(struct inode *old_dir, struct dentry *old_dentry,
|
||||
struct inode *new_dir, struct dentry *new_dentry)
|
||||
{
|
||||
struct inode *inode = new_dentry->d_inode;
|
||||
struct mapped_device *md = old_dir->u.generic_ip;
|
||||
struct dm_table *table = old_dentry->d_inode->u.generic_ip;
|
||||
|
||||
if (!md || !table)
|
||||
return -EINVAL;
|
||||
|
||||
if (!_empty(new_dentry))
|
||||
return -ENOTEMPTY;
|
||||
|
||||
if (!strcmp(new_dentry->d_name.name, "ACTIVE")) {
|
||||
/* activate the table */
|
||||
dm_activate(md, table);
|
||||
|
||||
} else if (!strcmp(old_dentry->d_name.name, "ACTIVE")) {
|
||||
dm_suspend(md);
|
||||
|
||||
}
|
||||
|
||||
if (inode) {
|
||||
inode->i_nlink--;
|
||||
dput(new_dentry);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _sync_file(struct file *file, struct dentry *dentry,
|
||||
int datasync)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct address_space_operations dm_aops = {
|
||||
readpage: _readpage,
|
||||
writepage: _writepage,
|
||||
prepare_write: _prepare_write,
|
||||
commit_write: _commit_write
|
||||
};
|
||||
|
||||
static struct file_operations dm_file_operations = {
|
||||
read: generic_file_read,
|
||||
write: generic_file_write,
|
||||
fsync: _sync_file,
|
||||
release: _release,
|
||||
};
|
||||
|
||||
static struct file_operations dm_dir_operations = {
|
||||
read: generic_read_dir,
|
||||
readdir: dcache_readdir,
|
||||
fsync: _sync_file,
|
||||
};
|
||||
|
||||
static struct inode_operations root_dir_inode_operations = {
|
||||
lookup: _lookup,
|
||||
mkdir: _mkdir,
|
||||
rmdir: _rmdir,
|
||||
rename: _rename,
|
||||
};
|
||||
|
||||
static struct inode_operations dm_dir_inode_operations = {
|
||||
create: _create,
|
||||
lookup: _lookup,
|
||||
unlink: _unlink,
|
||||
rename: _rename,
|
||||
};
|
||||
|
||||
static struct super_operations dm_ops = {
|
||||
statfs: _statfs,
|
||||
put_inode: _put_inode,
|
||||
};
|
||||
|
||||
static struct super_block *_read_super(struct super_block *sb, void *data,
|
||||
int silent)
|
||||
{
|
||||
struct inode *inode;
|
||||
struct dentry *root;
|
||||
|
||||
sb->s_blocksize = PAGE_CACHE_SIZE;
|
||||
sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
|
||||
sb->s_magic = DM_MAGIC;
|
||||
sb->s_op = &dm_ops;
|
||||
inode = _get_inode(sb, S_IFDIR | 0755, 0);
|
||||
inode->i_op = &root_dir_inode_operations;
|
||||
if (!inode)
|
||||
return NULL;
|
||||
|
||||
root = d_alloc_root(inode);
|
||||
if (!root) {
|
||||
iput(inode);
|
||||
return NULL;
|
||||
}
|
||||
sb->s_root = root;
|
||||
return sb;
|
||||
}
|
||||
|
||||
static DECLARE_FSTYPE(_fs_type, "dmfs", _read_super, FS_SINGLE);
|
||||
|
||||
int __init dm_fs_init(void)
|
||||
{
|
||||
int r;
|
||||
if ((r = register_filesystem(&_fs_type)))
|
||||
return r;
|
||||
|
||||
_mnt = kern_mount(&_fs_type);
|
||||
|
||||
if (IS_ERR(_mnt)) {
|
||||
unregister_filesystem(&_fs_type);
|
||||
return PTR_ERR(_mnt);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void __exit dm_fs_exit(void)
|
||||
{
|
||||
unregister_filesystem(&_fs_type);
|
||||
}
|
||||
@@ -1,125 +0,0 @@
|
||||
/*
|
||||
* dm-linear.c
|
||||
*
|
||||
* Copyright (C) 2001 Sistina Software (UK) Limited.
|
||||
*
|
||||
* This file is released under the GPL.
|
||||
*/
|
||||
|
||||
#include <linux/config.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/blkdev.h>
|
||||
#include <linux/device-mapper.h>
|
||||
|
||||
#include "dm.h"
|
||||
|
||||
/*
|
||||
* linear: maps a linear range of a device.
|
||||
*/
|
||||
struct linear_c {
|
||||
long delta; /* FIXME: we need a signed offset type */
|
||||
struct dm_dev *dev;
|
||||
};
|
||||
|
||||
/*
|
||||
* construct a linear mapping.
|
||||
* <dev_path> <offset>
|
||||
*/
|
||||
static int linear_ctr(struct dm_table *t, offset_t b, offset_t l,
|
||||
struct text_region *args, void **context,
|
||||
dm_error_fn err, void *e_private)
|
||||
{
|
||||
struct linear_c *lc;
|
||||
unsigned int start;
|
||||
struct text_region word;
|
||||
char path[256]; /* FIXME: magic */
|
||||
int r = -EINVAL;
|
||||
|
||||
if (!(lc = kmalloc(sizeof(lc), GFP_KERNEL))) {
|
||||
err("couldn't allocate memory for linear context", e_private);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
if (!dm_get_word(args, &word)) {
|
||||
err("couldn't get device path", e_private);
|
||||
goto bad;
|
||||
}
|
||||
|
||||
dm_txt_copy(path, sizeof(path) - 1, &word);
|
||||
|
||||
if (!dm_get_number(args, &start)) {
|
||||
err("destination start not given", e_private);
|
||||
goto bad;
|
||||
}
|
||||
|
||||
if ((r = dm_table_get_device(t, path, &lc->dev))) {
|
||||
err("couldn't lookup device", e_private);
|
||||
r = -ENXIO;
|
||||
goto bad;
|
||||
}
|
||||
|
||||
lc->delta = (int) start - (int) b;
|
||||
*context = lc;
|
||||
return 0;
|
||||
|
||||
bad:
|
||||
kfree(lc);
|
||||
return r;
|
||||
}
|
||||
|
||||
static void linear_dtr(struct dm_table *t, void *c)
|
||||
{
|
||||
struct linear_c *lc = (struct linear_c *) c;
|
||||
dm_table_put_device(t, lc->dev);
|
||||
kfree(c);
|
||||
}
|
||||
|
||||
static int linear_map(struct buffer_head *bh, int rw, void *context)
|
||||
{
|
||||
struct linear_c *lc = (struct linear_c *) context;
|
||||
|
||||
bh->b_rdev = lc->dev->dev;
|
||||
bh->b_rsector = bh->b_rsector + lc->delta;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static struct target_type linear_target = {
|
||||
name: "linear",
|
||||
module: THIS_MODULE,
|
||||
ctr: linear_ctr,
|
||||
dtr: linear_dtr,
|
||||
map: linear_map,
|
||||
};
|
||||
|
||||
static int __init linear_init(void)
|
||||
{
|
||||
int r = dm_register_target(&linear_target);
|
||||
|
||||
if (r < 0)
|
||||
printk(KERN_ERR
|
||||
"Device mapper: Linear: register failed %d\n", r);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static void __exit linear_exit(void)
|
||||
{
|
||||
int r = dm_unregister_target(&linear_target);
|
||||
|
||||
if (r < 0)
|
||||
printk(KERN_ERR
|
||||
"Device mapper: Linear: unregister failed %d\n", r);
|
||||
}
|
||||
|
||||
module_init(linear_init);
|
||||
module_exit(linear_exit);
|
||||
|
||||
MODULE_AUTHOR("Joe Thornber <thornber@uk.sistina.com>");
|
||||
MODULE_DESCRIPTION("Device Mapper: Linear mapping");
|
||||
#ifdef MODULE_LICENSE
|
||||
MODULE_LICENSE("GPL");
|
||||
#endif
|
||||
|
||||
@@ -1,201 +0,0 @@
|
||||
/*
|
||||
* dm-parse.c
|
||||
*
|
||||
* Copyright (C) 2001 Sistina Software
|
||||
*
|
||||
* This software is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GNU CC; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* 4/09/2001 - First version [Joe Thornber]
|
||||
*/
|
||||
|
||||
#include "dm.h"
|
||||
|
||||
struct dm_table *dm_parse(extract_line_fn line_fn, void *l_private,
|
||||
dm_error_fn err_fn, void *e_private)
|
||||
{
|
||||
struct text_region line, word;
|
||||
struct dm_table *table = dm_table_create();
|
||||
struct target_type *ttype;
|
||||
offset_t start, size, high;
|
||||
char target_name[64];
|
||||
void *context;
|
||||
int last_line_good = 1, was_error = 0;
|
||||
|
||||
if (!table)
|
||||
return 0;
|
||||
|
||||
#define PARSE_ERROR(msg) {\
|
||||
last_line_good = 0;\
|
||||
was_error = 1;\
|
||||
err_fn(msg, e_private);\
|
||||
continue;}
|
||||
|
||||
while (line_fn(&line, l_private)) {
|
||||
|
||||
/*
|
||||
* each line is of the format:
|
||||
* <sector start> <length (sectors)> <target type> <args...>
|
||||
*/
|
||||
|
||||
/* the line may be blank ... */
|
||||
dm_eat_space(&line);
|
||||
if (dm_empty_tok(&line) || (*line.b == '#'))
|
||||
continue;
|
||||
|
||||
/* sector start */
|
||||
if (!dm_get_number(&line, &start))
|
||||
PARSE_ERROR("expecting a number for sector start");
|
||||
|
||||
/* length */
|
||||
if (!dm_get_number(&line, &size))
|
||||
PARSE_ERROR("expecting a number for region length");
|
||||
|
||||
/* target type */
|
||||
if (!dm_get_word(&line, &word))
|
||||
PARSE_ERROR("target type missing");
|
||||
|
||||
/* we have to copy the target type to a C str */
|
||||
dm_txt_copy(target_name, sizeof(target_name), &word);
|
||||
|
||||
/* lookup the target type */
|
||||
if (!(ttype = dm_get_target_type(target_name)))
|
||||
PARSE_ERROR("unable to find target type");
|
||||
|
||||
/* check there isn't a gap, but only if the last target
|
||||
parsed ok. */
|
||||
if (last_line_good &&
|
||||
|
||||
((table->num_targets &&
|
||||
start != table->highs[table->num_targets - 1] + 1) ||
|
||||
(!table->num_targets && start)))
|
||||
PARSE_ERROR("gap in target ranges");
|
||||
|
||||
/* build the target */
|
||||
if (ttype->ctr(table, start, size, &line, &context,
|
||||
err_fn, e_private))
|
||||
PARSE_ERROR("target constructor failed");
|
||||
|
||||
/* no point registering the target
|
||||
if there was an error. */
|
||||
if (was_error) {
|
||||
ttype->dtr(table, context);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* add the target to the table */
|
||||
high = start + (size - 1);
|
||||
if (dm_table_add_target(table, high, ttype, context))
|
||||
PARSE_ERROR("internal error adding target to table");
|
||||
}
|
||||
|
||||
#undef PARSE_ERROR
|
||||
|
||||
if (was_error || dm_table_complete(table)) {
|
||||
dm_table_destroy(table);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return table;
|
||||
}
|
||||
|
||||
/*
|
||||
* convert the text in txt to an unsigned int,
|
||||
* returns 0 on failure.
|
||||
*/
|
||||
int dm_get_number(struct text_region *txt, unsigned int *n)
|
||||
{
|
||||
char *ptr;
|
||||
|
||||
dm_eat_space(txt);
|
||||
if (dm_empty_tok(txt))
|
||||
return 0;
|
||||
|
||||
*n = simple_strtoul(txt->b, &ptr, 10);
|
||||
if (ptr == txt->b)
|
||||
return 0;
|
||||
|
||||
txt->b = ptr;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* extracts text up to the next '\n'.
|
||||
*/
|
||||
int dm_get_line(struct text_region *txt, struct text_region *line)
|
||||
{
|
||||
const char *ptr;
|
||||
|
||||
dm_eat_space(txt);
|
||||
if (dm_empty_tok(txt))
|
||||
return 0;
|
||||
|
||||
ptr = line->b = txt->b;
|
||||
while((ptr != txt->e) && (*ptr != '\n'))
|
||||
ptr++;
|
||||
|
||||
txt->b = line->e = ptr;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* extracts the next non-whitespace token from the file.
|
||||
*/
|
||||
int dm_get_word(struct text_region *txt, struct text_region *word)
|
||||
{
|
||||
const char *ptr;
|
||||
|
||||
dm_eat_space(txt);
|
||||
|
||||
if (dm_empty_tok(txt))
|
||||
return 0;
|
||||
|
||||
word->b = txt->b;
|
||||
for (ptr = word->b = txt->b;
|
||||
ptr != txt->e && !isspace((int) *ptr); ptr++)
|
||||
;
|
||||
|
||||
word->e = txt->b = ptr;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* copy a text region into a traditional C str.
|
||||
*/
|
||||
void dm_txt_copy(char *dest, size_t max, struct text_region *txt)
|
||||
{
|
||||
size_t len = txt->e - txt->b;
|
||||
if (len > --max)
|
||||
len = max;
|
||||
strncpy(dest, txt->b, len);
|
||||
dest[len] = '\0';
|
||||
}
|
||||
|
||||
/*
|
||||
* skip leading whitespace
|
||||
*/
|
||||
void dm_eat_space(struct text_region *txt)
|
||||
{
|
||||
while(txt->b != txt->e && isspace((int) *txt->b))
|
||||
(txt->b)++;
|
||||
}
|
||||
|
||||
|
||||
EXPORT_SYMBOL(dm_get_number);
|
||||
EXPORT_SYMBOL(dm_get_word);
|
||||
EXPORT_SYMBOL(dm_txt_copy);
|
||||
EXPORT_SYMBOL(dm_eat_space);
|
||||
@@ -1,338 +0,0 @@
|
||||
/*
|
||||
* dm-table.c
|
||||
*
|
||||
* Copyright (C) 2001 Sistina Software (UK) Limited.
|
||||
*
|
||||
* This file is released under the GPL.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Changelog
|
||||
*
|
||||
* 16/08/2001 - First version [Joe Thornber]
|
||||
*/
|
||||
|
||||
#include "dm.h"
|
||||
|
||||
/* ceiling(n / size) * size */
|
||||
static inline ulong round_up(ulong n, ulong size)
|
||||
{
|
||||
ulong r = n % size;
|
||||
return n + (r ? (size - r) : 0);
|
||||
}
|
||||
|
||||
/* ceiling(n / size) */
|
||||
static inline ulong div_up(ulong n, ulong size)
|
||||
{
|
||||
return round_up(n, size) / size;
|
||||
}
|
||||
|
||||
/* similar to ceiling(log_size(n)) */
|
||||
static uint int_log(ulong n, ulong base)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
while (n > 1) {
|
||||
n = div_up(n, base);
|
||||
result++;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* return the highest key that you could lookup
|
||||
* from the n'th node on level l of the btree.
|
||||
*/
|
||||
static offset_t high(struct dm_table *t, int l, int n)
|
||||
{
|
||||
for (; l < t->depth - 1; l++)
|
||||
n = get_child(n, CHILDREN_PER_NODE - 1);
|
||||
|
||||
if (n >= t->counts[l])
|
||||
return (offset_t) -1;
|
||||
|
||||
return get_node(t, l, n)[KEYS_PER_NODE - 1];
|
||||
}
|
||||
|
||||
/*
|
||||
* fills in a level of the btree based on the
|
||||
* highs of the level below it.
|
||||
*/
|
||||
static int setup_btree_index(int l, struct dm_table *t)
|
||||
{
|
||||
int n, k;
|
||||
offset_t *node;
|
||||
|
||||
for (n = 0; n < t->counts[l]; n++) {
|
||||
node = get_node(t, l, n);
|
||||
|
||||
for (k = 0; k < KEYS_PER_NODE; k++)
|
||||
node[k] = high(t, l + 1, get_child(n, k));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* highs, and targets are managed as dynamic
|
||||
* arrays during a table load.
|
||||
*/
|
||||
static int alloc_targets(struct dm_table *t, int num)
|
||||
{
|
||||
offset_t *n_highs;
|
||||
struct target *n_targets;
|
||||
int n = t->num_targets;
|
||||
int size = (sizeof(struct target) + sizeof(offset_t)) * num;
|
||||
|
||||
n_highs = vmalloc(size);
|
||||
if (!n_highs)
|
||||
return -ENOMEM;
|
||||
|
||||
n_targets = (struct target *) (n_highs + num);
|
||||
|
||||
if (n) {
|
||||
memcpy(n_highs, t->highs, sizeof(*n_highs) * n);
|
||||
memcpy(n_targets, t->targets, sizeof(*n_targets) * n);
|
||||
}
|
||||
|
||||
vfree(t->highs);
|
||||
|
||||
t->num_allocated = num;
|
||||
t->highs = n_highs;
|
||||
t->targets = n_targets;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct dm_table *dm_table_create(void)
|
||||
{
|
||||
struct dm_table *t = kmalloc(sizeof(struct dm_table), GFP_NOIO);
|
||||
|
||||
if (!t)
|
||||
return 0;
|
||||
|
||||
memset(t, 0, sizeof(*t));
|
||||
INIT_LIST_HEAD(&t->devices);
|
||||
|
||||
/* allocate a single nodes worth of targets to
|
||||
begin with */
|
||||
if (alloc_targets(t, KEYS_PER_NODE)) {
|
||||
kfree(t);
|
||||
t = 0;
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
static void free_devices(struct list_head *devices)
|
||||
{
|
||||
struct list_head *tmp, *next;
|
||||
|
||||
for (tmp = devices->next; tmp != devices; tmp = next) {
|
||||
struct dm_dev *dd = list_entry(tmp, struct dm_dev, list);
|
||||
next = tmp->next;
|
||||
kfree(dd);
|
||||
}
|
||||
}
|
||||
|
||||
void dm_table_destroy(struct dm_table *t)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* free the indexes (see dm_table_complete) */
|
||||
if (t->depth >= 2)
|
||||
vfree(t->index[t->depth - 2]);
|
||||
vfree(t->highs);
|
||||
|
||||
/* free the targets */
|
||||
for (i = 0; i < t->num_targets; i++) {
|
||||
struct target *tgt = &t->targets[i];
|
||||
if (tgt->private)
|
||||
tgt->type->dtr(t, tgt->private);
|
||||
}
|
||||
|
||||
/* free the device list */
|
||||
if (t->devices.next != &t->devices) {
|
||||
WARN("there are still devices present, someone isn't "
|
||||
"calling dm_table_remove_device");
|
||||
|
||||
free_devices(&t->devices);
|
||||
}
|
||||
|
||||
kfree(t);
|
||||
}
|
||||
|
||||
/*
|
||||
* Checks to see if we need to extend
|
||||
* highs or targets.
|
||||
*/
|
||||
static inline int check_space(struct dm_table *t)
|
||||
{
|
||||
if (t->num_targets >= t->num_allocated)
|
||||
return alloc_targets(t, t->num_allocated * 2);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* convert a device path to a kdev_t.
|
||||
*/
|
||||
int lookup_device(const char *path, kdev_t *dev)
|
||||
{
|
||||
int r;
|
||||
struct nameidata nd;
|
||||
struct inode *inode;
|
||||
|
||||
if (!path_init(path, LOOKUP_FOLLOW, &nd))
|
||||
return 0;
|
||||
|
||||
if ((r = path_walk(path, &nd)))
|
||||
goto bad;
|
||||
|
||||
inode = nd.dentry->d_inode;
|
||||
if (!inode) {
|
||||
r = -ENOENT;
|
||||
goto bad;
|
||||
}
|
||||
|
||||
if (!S_ISBLK(inode->i_mode)) {
|
||||
r = -EINVAL;
|
||||
goto bad;
|
||||
}
|
||||
|
||||
*dev = inode->i_bdev->bd_dev;
|
||||
|
||||
bad:
|
||||
path_release(&nd);
|
||||
return r;
|
||||
}
|
||||
|
||||
/*
|
||||
* see if we've already got a device in the list.
|
||||
*/
|
||||
static struct dm_dev *find_device(struct list_head *l, kdev_t dev)
|
||||
{
|
||||
struct list_head *tmp;
|
||||
|
||||
for (tmp = l->next; tmp != l; tmp = tmp->next) {
|
||||
|
||||
struct dm_dev *dd = list_entry(tmp, struct dm_dev, list);
|
||||
if (dd->dev == dev)
|
||||
return dd;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* add a device to the list, or just increment the
|
||||
* usage count if it's already present.
|
||||
*/
|
||||
int dm_table_get_device(struct dm_table *t, const char *path,
|
||||
struct dm_dev **result)
|
||||
{
|
||||
int r;
|
||||
kdev_t dev;
|
||||
struct dm_dev *dd;
|
||||
|
||||
/* convert the path to a device */
|
||||
if ((r = lookup_device(path, &dev)))
|
||||
return r;
|
||||
|
||||
dd = find_device(&t->devices, dev);
|
||||
if (!dd) {
|
||||
dd = kmalloc(sizeof(*dd), GFP_KERNEL);
|
||||
if (!dd)
|
||||
return -ENOMEM;
|
||||
|
||||
dd->dev = dev;
|
||||
dd->bd = 0;
|
||||
atomic_set(&dd->count, 0);
|
||||
list_add(&dd->list, &t->devices);
|
||||
}
|
||||
atomic_inc(&dd->count);
|
||||
*result = dd;
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*
|
||||
* decrement a devices use count and remove it if
|
||||
* neccessary.
|
||||
*/
|
||||
void dm_table_put_device(struct dm_table *t, struct dm_dev *dd)
|
||||
{
|
||||
if (atomic_dec_and_test(&dd->count)) {
|
||||
list_del(&dd->list);
|
||||
kfree(dd);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* adds a target to the map
|
||||
*/
|
||||
int dm_table_add_target(struct dm_table *t, offset_t high,
|
||||
struct target_type *type, void *private)
|
||||
{
|
||||
int r, n;
|
||||
|
||||
if ((r = check_space(t)))
|
||||
return r;
|
||||
|
||||
n = t->num_targets++;
|
||||
t->highs[n] = high;
|
||||
t->targets[n].type = type;
|
||||
t->targets[n].private = private;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int setup_indexes(struct dm_table *t)
|
||||
{
|
||||
int i, total = 0;
|
||||
offset_t *indexes;
|
||||
|
||||
/* allocate the space for *all* the indexes */
|
||||
for (i = t->depth - 2; i >= 0; i--) {
|
||||
t->counts[i] = div_up(t->counts[i + 1], CHILDREN_PER_NODE);
|
||||
total += t->counts[i];
|
||||
}
|
||||
|
||||
if (!(indexes = vmalloc(NODE_SIZE * total)))
|
||||
return -ENOMEM;
|
||||
|
||||
/* set up internal nodes, bottom-up */
|
||||
for (i = t->depth - 2, total = 0; i >= 0; i--) {
|
||||
t->index[i] = indexes + (KEYS_PER_NODE * t->counts[i]);
|
||||
setup_btree_index(i, t);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* builds the btree to index the map
|
||||
*/
|
||||
int dm_table_complete(struct dm_table *t)
|
||||
{
|
||||
int leaf_nodes, r = 0;
|
||||
|
||||
/* how many indexes will the btree have ? */
|
||||
leaf_nodes = div_up(t->num_targets, KEYS_PER_NODE);
|
||||
t->depth = 1 + int_log(leaf_nodes, CHILDREN_PER_NODE);
|
||||
|
||||
/* leaf layer has already been set up */
|
||||
t->counts[t->depth - 1] = leaf_nodes;
|
||||
t->index[t->depth - 1] = t->highs;
|
||||
|
||||
if (t->depth >= 2)
|
||||
r = setup_indexes(t);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
EXPORT_SYMBOL(dm_table_get_device);
|
||||
EXPORT_SYMBOL(dm_table_put_device);
|
||||
@@ -1,181 +0,0 @@
|
||||
/*
|
||||
* dm-target.c
|
||||
*
|
||||
* Copyright (C) 2001 Sistina Software (UK) Limited
|
||||
*
|
||||
* This file is released under the GPL.
|
||||
*/
|
||||
|
||||
/*
|
||||
* 16/08/2001 - First Version [Joe Thornber]
|
||||
*/
|
||||
|
||||
#include "dm.h"
|
||||
#include <linux/kmod.h>
|
||||
|
||||
struct tt_internal {
|
||||
struct target_type tt;
|
||||
|
||||
struct list_head list;
|
||||
long use;
|
||||
};
|
||||
|
||||
static LIST_HEAD(_targets);
|
||||
static rwlock_t _lock = RW_LOCK_UNLOCKED;
|
||||
|
||||
#define DM_MOD_NAME_SIZE 32
|
||||
|
||||
static inline struct tt_internal *__find_target_type(const char *name)
|
||||
{
|
||||
struct list_head *tmp;
|
||||
struct tt_internal *ti;
|
||||
|
||||
for(tmp = _targets.next; tmp != &_targets; tmp = tmp->next) {
|
||||
|
||||
ti = list_entry(tmp, struct tt_internal, list);
|
||||
if (!strcmp(name, ti->tt.name))
|
||||
return ti;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct tt_internal *get_target_type(const char *name)
|
||||
{
|
||||
struct tt_internal *ti;
|
||||
|
||||
read_lock(&_lock);
|
||||
ti = __find_target_type(name);
|
||||
|
||||
if (ti) {
|
||||
if (ti->use == 0 && ti->tt.module)
|
||||
__MOD_INC_USE_COUNT(ti->tt.module);
|
||||
ti->use++;
|
||||
}
|
||||
read_unlock(&_lock);
|
||||
|
||||
return ti;
|
||||
}
|
||||
|
||||
static void load_module(const char *name)
|
||||
{
|
||||
char module_name[DM_MOD_NAME_SIZE] = "dm-";
|
||||
|
||||
/* Length check for strcat() below */
|
||||
if (strlen(name) > (DM_MOD_NAME_SIZE - 4))
|
||||
return;
|
||||
|
||||
strcat(module_name, name);
|
||||
request_module(module_name);
|
||||
}
|
||||
|
||||
struct target_type *dm_get_target_type(const char *name)
|
||||
{
|
||||
struct tt_internal *ti = get_target_type(name);
|
||||
|
||||
if (!ti) {
|
||||
load_module(name);
|
||||
ti = get_target_type(name);
|
||||
}
|
||||
|
||||
return ti ? &ti->tt : 0;
|
||||
}
|
||||
|
||||
void dm_put_target_type(struct target_type *t)
|
||||
{
|
||||
struct tt_internal *ti = (struct tt_internal *) t;
|
||||
|
||||
read_lock(&_lock);
|
||||
if (--ti->use == 0 && ti->tt.module)
|
||||
__MOD_DEC_USE_COUNT(ti->tt.module);
|
||||
|
||||
if (ti->use < 0)
|
||||
BUG();
|
||||
read_unlock(&_lock);
|
||||
}
|
||||
|
||||
static struct tt_internal *alloc_target(struct target_type *t)
|
||||
{
|
||||
struct tt_internal *ti = kmalloc(sizeof(*ti), GFP_KERNEL);
|
||||
|
||||
if (ti) {
|
||||
memset(ti, 0, sizeof(*ti));
|
||||
ti->tt = *t;
|
||||
}
|
||||
|
||||
return ti;
|
||||
}
|
||||
|
||||
int dm_register_target(struct target_type *t)
|
||||
{
|
||||
int rv = 0;
|
||||
struct tt_internal *ti = alloc_target(t);
|
||||
|
||||
if (!ti)
|
||||
return -ENOMEM;
|
||||
|
||||
write_lock(&_lock);
|
||||
if (__find_target_type(t->name))
|
||||
rv = -EEXIST;
|
||||
else
|
||||
list_add(&ti->list, &_targets);
|
||||
|
||||
write_unlock(&_lock);
|
||||
return rv;
|
||||
}
|
||||
|
||||
int dm_unregister_target(struct target_type *t)
|
||||
{
|
||||
struct tt_internal *ti = (struct tt_internal *) t;
|
||||
int rv = -ETXTBSY;
|
||||
|
||||
write_lock(&_lock);
|
||||
if (ti->use == 0) {
|
||||
list_del(&ti->list);
|
||||
kfree(ti);
|
||||
rv = 0;
|
||||
}
|
||||
write_unlock(&_lock);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
/*
|
||||
* io-err: always fails an io, useful for bringing
|
||||
* up LV's that have holes in them.
|
||||
*/
|
||||
static int io_err_ctr(struct dm_table *t, offset_t b, offset_t l,
|
||||
struct text_region *args, void **context,
|
||||
dm_error_fn err, void *e_private)
|
||||
{
|
||||
*context = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void io_err_dtr(struct dm_table *t, void *c)
|
||||
{
|
||||
/* empty */
|
||||
}
|
||||
|
||||
static int io_err_map(struct buffer_head *bh, int rw, void *context)
|
||||
{
|
||||
buffer_IO_error(bh);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct target_type error_target = {
|
||||
name: "error",
|
||||
ctr: io_err_ctr,
|
||||
dtr: io_err_dtr,
|
||||
map: io_err_map
|
||||
};
|
||||
|
||||
|
||||
int dm_target_init(void)
|
||||
{
|
||||
return dm_register_target(&error_target);
|
||||
}
|
||||
|
||||
EXPORT_SYMBOL(dm_register_target);
|
||||
EXPORT_SYMBOL(dm_unregister_target);
|
||||
|
||||
@@ -1,920 +0,0 @@
|
||||
/*
|
||||
* device-mapper.c
|
||||
*
|
||||
* Copyright (C) 2001 Sistina Software
|
||||
*
|
||||
* This software is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GNU CC; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Changelog
|
||||
*
|
||||
* 14/08/2001 - First Version [Joe Thornber]
|
||||
*/
|
||||
|
||||
#include "dm.h"
|
||||
|
||||
/* defines for blk.h */
|
||||
#define MAJOR_NR DM_BLK_MAJOR
|
||||
#define DEVICE_NR(device) MINOR(device) /* has no partition bits */
|
||||
#define DEVICE_NAME "device-mapper" /* name for messaging */
|
||||
#define DEVICE_NO_RANDOM /* no entropy to contribute */
|
||||
#define DEVICE_OFF(d) /* do-nothing */
|
||||
|
||||
#include <linux/blk.h>
|
||||
#include <linux/blkpg.h>
|
||||
|
||||
/* we only need this for the lv_bmap struct definition, not happy */
|
||||
#include <linux/lvm.h>
|
||||
|
||||
#define MAX_DEVICES 64
|
||||
#define DEFAULT_READ_AHEAD 64
|
||||
|
||||
const char *_name = "device-mapper";
|
||||
int _version[3] = {0, 1, 0};
|
||||
|
||||
struct io_hook {
|
||||
struct mapped_device *md;
|
||||
struct target *target;
|
||||
int rw;
|
||||
|
||||
void (*end_io)(struct buffer_head * bh, int uptodate);
|
||||
void *context;
|
||||
};
|
||||
|
||||
kmem_cache_t *_io_hook_cache;
|
||||
|
||||
#define rl down_read(&_dev_lock)
|
||||
#define ru up_read(&_dev_lock)
|
||||
#define wl down_write(&_dev_lock)
|
||||
#define wu up_write(&_dev_lock)
|
||||
|
||||
struct rw_semaphore _dev_lock;
|
||||
static struct mapped_device *_devs[MAX_DEVICES];
|
||||
|
||||
/* block device arrays */
|
||||
static int _block_size[MAX_DEVICES];
|
||||
static int _blksize_size[MAX_DEVICES];
|
||||
static int _hardsect_size[MAX_DEVICES];
|
||||
|
||||
const char *_fs_dir = "device-mapper";
|
||||
static devfs_handle_t _dev_dir;
|
||||
|
||||
static int request(request_queue_t *q, int rw, struct buffer_head *bh);
|
||||
static int dm_user_bmap(struct inode *inode, struct lv_bmap *lvb);
|
||||
|
||||
/*
|
||||
* setup and teardown the driver
|
||||
*/
|
||||
static int dm_init(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
init_rwsem(&_dev_lock);
|
||||
|
||||
if (!_io_hook_cache)
|
||||
_io_hook_cache = kmem_cache_create("dm io hooks",
|
||||
sizeof(struct io_hook),
|
||||
0, 0, NULL, NULL);
|
||||
|
||||
if (!_io_hook_cache)
|
||||
return -ENOMEM;
|
||||
|
||||
if ((ret = dm_fs_init()) || (ret = dm_target_init()))
|
||||
return ret;
|
||||
|
||||
/* set up the arrays */
|
||||
read_ahead[MAJOR_NR] = DEFAULT_READ_AHEAD;
|
||||
blk_size[MAJOR_NR] = _block_size;
|
||||
blksize_size[MAJOR_NR] = _blksize_size;
|
||||
hardsect_size[MAJOR_NR] = _hardsect_size;
|
||||
|
||||
if (devfs_register_blkdev(MAJOR_NR, _name, &dm_blk_dops) < 0) {
|
||||
printk(KERN_ERR "%s -- register_blkdev failed\n", _name);
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
blk_queue_make_request(BLK_DEFAULT_QUEUE(MAJOR_NR), request);
|
||||
|
||||
_dev_dir = devfs_mk_dir(0, _fs_dir, NULL);
|
||||
|
||||
printk(KERN_INFO "%s %d.%d.%d initialised\n", _name,
|
||||
_version[0], _version[1], _version[2]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dm_exit(void)
|
||||
{
|
||||
if (kmem_cache_destroy(_io_hook_cache))
|
||||
WARN("it looks like there are still some io_hooks allocated");
|
||||
_io_hook_cache = 0;
|
||||
|
||||
dm_fs_exit();
|
||||
|
||||
if (devfs_unregister_blkdev(MAJOR_NR, _name) < 0)
|
||||
printk(KERN_ERR "%s -- unregister_blkdev failed\n", _name);
|
||||
|
||||
read_ahead[MAJOR_NR] = 0;
|
||||
blk_size[MAJOR_NR] = 0;
|
||||
blksize_size[MAJOR_NR] = 0;
|
||||
hardsect_size[MAJOR_NR] = 0;
|
||||
|
||||
printk(KERN_INFO "%s %d.%d.%d cleaned up\n", _name,
|
||||
_version[0], _version[1], _version[2]);
|
||||
}
|
||||
|
||||
/*
|
||||
* block device functions
|
||||
*/
|
||||
static int dm_blk_open(struct inode *inode, struct file *file)
|
||||
{
|
||||
int minor = MINOR(inode->i_rdev);
|
||||
struct mapped_device *md;
|
||||
|
||||
if (minor >= MAX_DEVICES)
|
||||
return -ENXIO;
|
||||
|
||||
wl;
|
||||
md = _devs[minor];
|
||||
|
||||
if (!md || !is_active(md)) {
|
||||
wu;
|
||||
return -ENXIO;
|
||||
}
|
||||
|
||||
md->use_count++;
|
||||
wu;
|
||||
|
||||
MOD_INC_USE_COUNT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int dm_blk_close(struct inode *inode, struct file *file)
|
||||
{
|
||||
int minor = MINOR(inode->i_rdev);
|
||||
struct mapped_device *md;
|
||||
|
||||
if (minor >= MAX_DEVICES)
|
||||
return -ENXIO;
|
||||
|
||||
wl;
|
||||
md = _devs[minor];
|
||||
if (!md || md->use_count < 1) {
|
||||
WARN("reference count in mapped_device incorrect");
|
||||
wu;
|
||||
return -ENXIO;
|
||||
}
|
||||
|
||||
md->use_count--;
|
||||
wu;
|
||||
|
||||
MOD_DEC_USE_COUNT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* In 512-byte units */
|
||||
#define VOLUME_SIZE(minor) (_block_size[(minor)] >> 1)
|
||||
|
||||
static int dm_blk_ioctl(struct inode *inode, struct file *file,
|
||||
uint command, ulong a)
|
||||
{
|
||||
int minor = MINOR(inode->i_rdev);
|
||||
long size;
|
||||
|
||||
if (minor >= MAX_DEVICES)
|
||||
return -ENXIO;
|
||||
|
||||
switch (command) {
|
||||
case BLKSSZGET:
|
||||
case BLKROGET:
|
||||
case BLKROSET:
|
||||
#if 0
|
||||
case BLKELVSET:
|
||||
case BLKELVGET:
|
||||
#endif
|
||||
return blk_ioctl(inode->i_dev, command, a);
|
||||
break;
|
||||
|
||||
case BLKGETSIZE:
|
||||
size = VOLUME_SIZE(minor);
|
||||
if (copy_to_user((void *) a, &size, sizeof (long)))
|
||||
return -EFAULT;
|
||||
break;
|
||||
|
||||
case BLKFLSBUF:
|
||||
if (!capable(CAP_SYS_ADMIN))
|
||||
return -EACCES;
|
||||
fsync_dev(inode->i_rdev);
|
||||
invalidate_buffers(inode->i_rdev);
|
||||
return 0;
|
||||
|
||||
case BLKRAGET:
|
||||
if (copy_to_user
|
||||
((void *) a, &read_ahead[MAJOR(inode->i_rdev)],
|
||||
sizeof (long)))
|
||||
return -EFAULT;
|
||||
return 0;
|
||||
|
||||
case BLKRASET:
|
||||
if (!capable(CAP_SYS_ADMIN))
|
||||
return -EACCES;
|
||||
read_ahead[MAJOR(inode->i_rdev)] = a;
|
||||
return 0;
|
||||
|
||||
case BLKRRPART:
|
||||
return -EINVAL;
|
||||
|
||||
case LV_BMAP:
|
||||
return dm_user_bmap(inode, (struct lv_bmap *) a);
|
||||
|
||||
default:
|
||||
WARN("unknown block ioctl %d", command);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline struct io_hook *alloc_io_hook(void)
|
||||
{
|
||||
return kmem_cache_alloc(_io_hook_cache, GFP_NOIO);
|
||||
}
|
||||
|
||||
static inline void free_io_hook(struct io_hook *ih)
|
||||
{
|
||||
kmem_cache_free(_io_hook_cache, ih);
|
||||
}
|
||||
|
||||
/*
|
||||
* FIXME: need to decide if deferred_io's need
|
||||
* their own slab, I say no for now since they are
|
||||
* only used when the device is suspended.
|
||||
*/
|
||||
static inline struct deferred_io *alloc_deferred(void)
|
||||
{
|
||||
return kmalloc(sizeof(struct deferred_io), GFP_NOIO);
|
||||
}
|
||||
|
||||
static inline void free_deferred(struct deferred_io *di)
|
||||
{
|
||||
kfree(di);
|
||||
}
|
||||
|
||||
/*
|
||||
* call a targets optional error function if
|
||||
* an io failed.
|
||||
*/
|
||||
static inline int call_err_fn(struct io_hook *ih, struct buffer_head *bh)
|
||||
{
|
||||
dm_err_fn err = ih->target->type->err;
|
||||
if (err)
|
||||
return err(bh, ih->rw, ih->target->private);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* bh->b_end_io routine that decrements the
|
||||
* pending count and then calls the original
|
||||
* bh->b_end_io fn.
|
||||
*/
|
||||
static void dec_pending(struct buffer_head *bh, int uptodate)
|
||||
{
|
||||
struct io_hook *ih = bh->b_private;
|
||||
|
||||
if (!uptodate && call_err_fn(ih, bh))
|
||||
return;
|
||||
|
||||
if (atomic_dec_and_test(&ih->md->pending))
|
||||
/* nudge anyone waiting on suspend queue */
|
||||
wake_up(&ih->md->wait);
|
||||
|
||||
bh->b_end_io = ih->end_io;
|
||||
bh->b_private = ih->context;
|
||||
free_io_hook(ih);
|
||||
|
||||
bh->b_end_io(bh, uptodate);
|
||||
}
|
||||
|
||||
/*
|
||||
* add the bh to the list of deferred io.
|
||||
*/
|
||||
static int queue_io(struct mapped_device *md, struct buffer_head *bh, int rw)
|
||||
{
|
||||
struct deferred_io *di = alloc_deferred();
|
||||
|
||||
if (!di)
|
||||
return -ENOMEM;
|
||||
|
||||
wl;
|
||||
if (test_bit(DM_ACTIVE, &md->state)) {
|
||||
wu;
|
||||
return 0;
|
||||
}
|
||||
|
||||
di->bh = bh;
|
||||
di->rw = rw;
|
||||
di->next = md->deferred;
|
||||
md->deferred = di;
|
||||
wu;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* do the bh mapping for a given leaf
|
||||
*/
|
||||
static inline int __map_buffer(struct mapped_device *md,
|
||||
struct buffer_head *bh, int rw, int leaf)
|
||||
{
|
||||
int r;
|
||||
dm_map_fn fn;
|
||||
void *context;
|
||||
struct io_hook *ih = NULL;
|
||||
struct target *ti = md->map->targets + leaf;
|
||||
|
||||
fn = ti->type->map;
|
||||
context = ti->private;
|
||||
|
||||
ih = alloc_io_hook();
|
||||
|
||||
if (!ih)
|
||||
return 0;
|
||||
|
||||
ih->md = md;
|
||||
ih->rw = rw;
|
||||
ih->target = ti;
|
||||
ih->end_io = bh->b_end_io;
|
||||
ih->context = bh->b_private;
|
||||
|
||||
r = fn(bh, rw, context);
|
||||
|
||||
if (r > 0) {
|
||||
/* hook the end io request fn */
|
||||
atomic_inc(&md->pending);
|
||||
bh->b_end_io = dec_pending;
|
||||
bh->b_private = ih;
|
||||
|
||||
} else if (r == 0)
|
||||
/* we don't need to hook */
|
||||
free_io_hook(ih);
|
||||
|
||||
else if (r < 0) {
|
||||
free_io_hook(ih);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* search the btree for the correct target.
|
||||
*/
|
||||
static inline int __find_node(struct dm_table *t, struct buffer_head *bh)
|
||||
{
|
||||
int l, n = 0, k = 0;
|
||||
offset_t *node;
|
||||
|
||||
for (l = 0; l < t->depth; l++) {
|
||||
n = get_child(n, k);
|
||||
node = get_node(t, l, n);
|
||||
|
||||
for (k = 0; k < KEYS_PER_NODE; k++)
|
||||
if (node[k] >= bh->b_rsector)
|
||||
break;
|
||||
}
|
||||
|
||||
return (KEYS_PER_NODE * n) + k;
|
||||
}
|
||||
|
||||
static int request(request_queue_t *q, int rw, struct buffer_head *bh)
|
||||
{
|
||||
struct mapped_device *md;
|
||||
int r, minor = MINOR(bh->b_rdev);
|
||||
|
||||
if (minor >= MAX_DEVICES)
|
||||
goto bad_no_lock;
|
||||
|
||||
rl;
|
||||
md = _devs[minor];
|
||||
|
||||
if (!md || !md->map)
|
||||
goto bad;
|
||||
|
||||
/* if we're suspended we have to queue this io for later */
|
||||
if (!test_bit(DM_ACTIVE, &md->state)) {
|
||||
ru;
|
||||
r = queue_io(md, bh, rw);
|
||||
|
||||
if (r < 0)
|
||||
goto bad_no_lock;
|
||||
|
||||
else if (r > 0)
|
||||
return 0; /* deferred successfully */
|
||||
|
||||
rl; /* FIXME: there's still a race here */
|
||||
}
|
||||
|
||||
if (!__map_buffer(md, bh, rw, __find_node(md->map, bh)))
|
||||
goto bad;
|
||||
|
||||
ru;
|
||||
return 1;
|
||||
|
||||
bad:
|
||||
ru;
|
||||
|
||||
bad_no_lock:
|
||||
buffer_IO_error(bh);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int check_dev_size(int minor, unsigned long block)
|
||||
{
|
||||
/* FIXME: check this */
|
||||
unsigned long max_sector = (_block_size[minor] << 1) + 1;
|
||||
unsigned long sector = (block + 1) * (_blksize_size[minor] >> 9);
|
||||
|
||||
return (sector > max_sector) ? 0 : 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* creates a dummy buffer head and maps it (for lilo).
|
||||
*/
|
||||
static int do_bmap(kdev_t dev, unsigned long block,
|
||||
kdev_t *r_dev, unsigned long *r_block)
|
||||
{
|
||||
struct mapped_device *md;
|
||||
struct buffer_head bh;
|
||||
int minor = MINOR(dev), r;
|
||||
struct target *t;
|
||||
|
||||
rl;
|
||||
if ((minor >= MAX_DEVICES) || !(md = _devs[minor]) ||
|
||||
!test_bit(DM_ACTIVE, &md->state)) {
|
||||
r = -ENXIO;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!check_dev_size(minor, block)) {
|
||||
r = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* setup dummy bh */
|
||||
memset(&bh, 0, sizeof(bh));
|
||||
bh.b_blocknr = block;
|
||||
bh.b_dev = bh.b_rdev = dev;
|
||||
bh.b_size = _blksize_size[minor];
|
||||
bh.b_rsector = block * (bh.b_size >> 9);
|
||||
|
||||
/* find target */
|
||||
t = md->map->targets + __find_node(md->map, &bh);
|
||||
|
||||
/* do the mapping */
|
||||
r = t->type->map(&bh, READ, t->private);
|
||||
|
||||
*r_dev = bh.b_rdev;
|
||||
*r_block = bh.b_rsector / (bh.b_size >> 9);
|
||||
|
||||
out:
|
||||
ru;
|
||||
return r;
|
||||
}
|
||||
|
||||
/*
|
||||
* marshals arguments and results between user and
|
||||
* kernel space.
|
||||
*/
|
||||
static int dm_user_bmap(struct inode *inode, struct lv_bmap *lvb)
|
||||
{
|
||||
unsigned long block, r_block;
|
||||
kdev_t r_dev;
|
||||
int r;
|
||||
|
||||
if (get_user(block, &lvb->lv_block))
|
||||
return -EFAULT;
|
||||
|
||||
if ((r = do_bmap(inode->i_rdev, block, &r_dev, &r_block)))
|
||||
return r;
|
||||
|
||||
if (put_user(kdev_t_to_nr(r_dev), &lvb->lv_dev) ||
|
||||
put_user(r_block, &lvb->lv_block))
|
||||
return -EFAULT;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* see if the device with a specific minor # is
|
||||
* free.
|
||||
*/
|
||||
static inline int __specific_dev(int minor)
|
||||
{
|
||||
if (minor > MAX_DEVICES) {
|
||||
WARN("request for a mapped_device > than MAX_DEVICES");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!_devs[minor])
|
||||
return minor;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* find the first free device.
|
||||
*/
|
||||
static inline int __any_old_dev(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < MAX_DEVICES; i++)
|
||||
if (!_devs[i])
|
||||
return i;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* allocate and initialise a blank device.
|
||||
*/
|
||||
static struct mapped_device *alloc_dev(int minor)
|
||||
{
|
||||
struct mapped_device *md = kmalloc(sizeof(*md), GFP_KERNEL);
|
||||
|
||||
if (!md)
|
||||
return 0;
|
||||
|
||||
memset(md, 0, sizeof (*md));
|
||||
|
||||
wl;
|
||||
minor = (minor < 0) ? __any_old_dev() : __specific_dev(minor);
|
||||
|
||||
if (minor < 0) {
|
||||
WARN("no free devices available");
|
||||
wu;
|
||||
kfree(md);
|
||||
return 0;
|
||||
}
|
||||
|
||||
md->dev = MKDEV(DM_BLK_MAJOR, minor);
|
||||
md->name[0] = '\0';
|
||||
md->state = 0;
|
||||
|
||||
init_waitqueue_head(&md->wait);
|
||||
|
||||
_devs[minor] = md;
|
||||
wu;
|
||||
|
||||
return md;
|
||||
}
|
||||
|
||||
/*
|
||||
* open a device so we can use it as a map
|
||||
* destination.
|
||||
*/
|
||||
static int open_dev(struct dm_dev *d)
|
||||
{
|
||||
int err;
|
||||
|
||||
if (d->bd)
|
||||
BUG();
|
||||
|
||||
if (!(d->bd = bdget(kdev_t_to_nr(d->dev))))
|
||||
return -ENOMEM;
|
||||
|
||||
if ((err = blkdev_get(d->bd, FMODE_READ|FMODE_WRITE, 0, BDEV_FILE))) {
|
||||
bdput(d->bd);
|
||||
return err;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* close a device that we've been using.
|
||||
*/
|
||||
static void close_dev(struct dm_dev *d)
|
||||
{
|
||||
if (!d->bd)
|
||||
return;
|
||||
|
||||
blkdev_put(d->bd, BDEV_FILE);
|
||||
bdput(d->bd);
|
||||
d->bd = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Close a list of devices.
|
||||
*/
|
||||
static void close_devices(struct list_head *devices)
|
||||
{
|
||||
struct list_head *tmp;
|
||||
|
||||
for (tmp = devices->next; tmp != devices; tmp = tmp->next) {
|
||||
struct dm_dev *dd = list_entry(tmp, struct dm_dev, list);
|
||||
close_dev(dd);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Open a list of devices.
|
||||
*/
|
||||
static int open_devices(struct list_head *devices)
|
||||
{
|
||||
int r = 0;
|
||||
struct list_head *tmp;
|
||||
|
||||
for (tmp = devices->next; tmp != devices; tmp = tmp->next) {
|
||||
struct dm_dev *dd = list_entry(tmp, struct dm_dev, list);
|
||||
if ((r = open_dev(dd)))
|
||||
goto bad;
|
||||
}
|
||||
return 0;
|
||||
|
||||
bad:
|
||||
close_devices(devices);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
struct mapped_device *dm_find_by_minor(int minor)
|
||||
{
|
||||
struct mapped_device *md;
|
||||
|
||||
rl;
|
||||
md = _devs[minor];
|
||||
ru;
|
||||
|
||||
return md;
|
||||
}
|
||||
|
||||
static int register_device(struct mapped_device *md)
|
||||
{
|
||||
md->devfs_entry =
|
||||
devfs_register(_dev_dir, md->name, DEVFS_FL_CURRENT_OWNER,
|
||||
MAJOR(md->dev), MINOR(md->dev),
|
||||
S_IFBLK | S_IRUSR | S_IWUSR | S_IRGRP,
|
||||
&dm_blk_dops, NULL);
|
||||
|
||||
if (!md->devfs_entry)
|
||||
return -ENOMEM;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int unregister_device(struct mapped_device *md)
|
||||
{
|
||||
devfs_unregister(md->devfs_entry);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* constructor for a new device
|
||||
*/
|
||||
struct mapped_device *dm_create(const char *name, int minor)
|
||||
{
|
||||
int r;
|
||||
struct mapped_device *md;
|
||||
|
||||
if (minor >= MAX_DEVICES)
|
||||
return ERR_PTR(-ENXIO);
|
||||
|
||||
if (!(md = alloc_dev(minor)))
|
||||
return ERR_PTR(-ENXIO);
|
||||
|
||||
wl;
|
||||
strcpy(md->name, name);
|
||||
_devs[minor] = md;
|
||||
if ((r = register_device(md))) {
|
||||
wu;
|
||||
return ERR_PTR(r);
|
||||
}
|
||||
wu;
|
||||
|
||||
return md;
|
||||
}
|
||||
|
||||
/*
|
||||
* destructor for the device. md->map is
|
||||
* deliberately not destroyed, dm-fs should manage
|
||||
* table objects.
|
||||
*/
|
||||
int dm_remove(struct mapped_device *md)
|
||||
{
|
||||
int minor, r;
|
||||
|
||||
wl;
|
||||
if (md->use_count) {
|
||||
wu;
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
if ((r = unregister_device(md))) {
|
||||
wu;
|
||||
return r;
|
||||
}
|
||||
|
||||
minor = MINOR(md->dev);
|
||||
_devs[minor] = 0;
|
||||
wu;
|
||||
|
||||
kfree(md);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* the hardsect size for a mapped device is the
|
||||
* smallest hard sect size from the devices it
|
||||
* maps onto.
|
||||
*/
|
||||
static int __find_hardsect_size(struct list_head *devices)
|
||||
{
|
||||
int result = INT_MAX, size;
|
||||
struct list_head *tmp;
|
||||
|
||||
for (tmp = devices->next; tmp != devices; tmp = tmp->next) {
|
||||
struct dm_dev *dd = list_entry(tmp, struct dm_dev, list);
|
||||
size = get_hardsect_size(dd->dev);
|
||||
if (size < result)
|
||||
result = size;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Bind a table to the device.
|
||||
*/
|
||||
void __bind(struct mapped_device *md, struct dm_table *t)
|
||||
{
|
||||
int minor = MINOR(md->dev);
|
||||
|
||||
md->map = t;
|
||||
|
||||
/* in k */
|
||||
_block_size[minor] = (t->highs[t->num_targets - 1] + 1) >> 1;
|
||||
|
||||
_blksize_size[minor] = BLOCK_SIZE;
|
||||
_hardsect_size[minor] = __find_hardsect_size(&t->devices);
|
||||
register_disk(NULL, md->dev, 1, &dm_blk_dops, _block_size[minor]);
|
||||
}
|
||||
|
||||
/*
|
||||
* requeue the deferred buffer_heads by calling
|
||||
* generic_make_request.
|
||||
*/
|
||||
static void __flush_deferred_io(struct mapped_device *md)
|
||||
{
|
||||
struct deferred_io *c, *n;
|
||||
|
||||
for (c = md->deferred, md->deferred = 0; c; c = n) {
|
||||
n = c->next;
|
||||
generic_make_request(c->rw, c->bh);
|
||||
free_deferred(c);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* make the device available for use, if was
|
||||
* previously suspended rather than newly created
|
||||
* then all queued io is flushed
|
||||
*/
|
||||
int dm_activate(struct mapped_device *md, struct dm_table *table)
|
||||
{
|
||||
int r;
|
||||
|
||||
/* check that the mapping has at least been loaded. */
|
||||
if (!table->num_targets)
|
||||
return -EINVAL;
|
||||
|
||||
wl;
|
||||
|
||||
/* you must be deactivated first */
|
||||
if (is_active(md)) {
|
||||
wu;
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
__bind(md, table);
|
||||
|
||||
if ((r = open_devices(&md->map->devices))) {
|
||||
wu;
|
||||
return r;
|
||||
}
|
||||
|
||||
set_bit(DM_ACTIVE, &md->state);
|
||||
__flush_deferred_io(md);
|
||||
wu;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Deactivate the device, the device must not be
|
||||
* opened by anyone.
|
||||
*/
|
||||
int dm_deactivate(struct mapped_device *md)
|
||||
{
|
||||
rl;
|
||||
if (md->use_count) {
|
||||
ru;
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
fsync_dev(md->dev);
|
||||
|
||||
ru;
|
||||
|
||||
wl;
|
||||
if (md->use_count) {
|
||||
/* drat, somebody got in quick ... */
|
||||
wu;
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
close_devices(&md->map->devices);
|
||||
md->map = 0;
|
||||
clear_bit(DM_ACTIVE, &md->state);
|
||||
wu;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* We need to be able to change a mapping table
|
||||
* under a mounted filesystem. for example we
|
||||
* might want to move some data in the background.
|
||||
* Before the table can be swapped with
|
||||
* dm_bind_table, dm_suspend must be called to
|
||||
* flush any in flight buffer_heads and ensure
|
||||
* that any further io gets deferred.
|
||||
*/
|
||||
void dm_suspend(struct mapped_device *md)
|
||||
{
|
||||
DECLARE_WAITQUEUE(wait, current);
|
||||
|
||||
wl;
|
||||
if (!is_active(md)) {
|
||||
wu;
|
||||
return;
|
||||
}
|
||||
|
||||
clear_bit(DM_ACTIVE, &md->state);
|
||||
wu;
|
||||
|
||||
/* wait for all the pending io to flush */
|
||||
add_wait_queue(&md->wait, &wait);
|
||||
current->state = TASK_UNINTERRUPTIBLE;
|
||||
do {
|
||||
wl;
|
||||
if (!atomic_read(&md->pending))
|
||||
break;
|
||||
|
||||
wu;
|
||||
schedule();
|
||||
|
||||
} while (1);
|
||||
|
||||
current->state = TASK_RUNNING;
|
||||
remove_wait_queue(&md->wait, &wait);
|
||||
close_devices(&md->map->devices);
|
||||
|
||||
md->map = 0;
|
||||
wu;
|
||||
}
|
||||
|
||||
struct block_device_operations dm_blk_dops = {
|
||||
open: dm_blk_open,
|
||||
release: dm_blk_close,
|
||||
ioctl: dm_blk_ioctl
|
||||
};
|
||||
|
||||
/*
|
||||
* module hooks
|
||||
*/
|
||||
module_init(dm_init);
|
||||
module_exit(dm_exit);
|
||||
|
||||
MODULE_DESCRIPTION("device-mapper driver");
|
||||
MODULE_AUTHOR("Joe Thornber <thornber@btconnect.com>");
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* c-file-style: "linux"
|
||||
* End:
|
||||
*/
|
||||
@@ -1,276 +0,0 @@
|
||||
/*
|
||||
* dm.h
|
||||
*
|
||||
* Copyright (C) 2001 Sistina Software
|
||||
*
|
||||
* This file is released under the GPL.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Internal header file for device mapper
|
||||
*
|
||||
* Changelog
|
||||
*
|
||||
* 16/08/2001 - First version [Joe Thornber]
|
||||
*/
|
||||
|
||||
/*
|
||||
* This driver attempts to provide a generic way of specifying logical
|
||||
* devices which are mapped onto other devices.
|
||||
*
|
||||
* It does this by mapping sections of the logical device onto 'targets'.
|
||||
*
|
||||
* When the logical device is accessed the make_request function looks up
|
||||
* the correct target for the given sector, and then asks this target
|
||||
* to do the remapping.
|
||||
*
|
||||
* (dm-table.c) A btree like structure is used to hold the sector
|
||||
* range -> target mapping. Because we know all the entries in the
|
||||
* btree in advance we can make a very compact tree, omitting pointers
|
||||
* to child nodes, (child nodes locations can be calculated). Each
|
||||
* node of the btree is 1 level cache line in size, this gives a small
|
||||
* performance boost.
|
||||
*
|
||||
* A userland test program for the btree gave the following results on a
|
||||
* 1 Gigahertz Athlon machine:
|
||||
*
|
||||
* entries in btree lookups per second
|
||||
* ---------------- ------------------
|
||||
* 5 25,000,000
|
||||
* 1000 7,700,000
|
||||
* 10,000,000 3,800,000
|
||||
*
|
||||
* Of course these results should be taken with a pinch of salt; the
|
||||
* lookups were sequential and there were no other applications (other
|
||||
* than X + emacs) running to give any pressure on the level 1 cache.
|
||||
*
|
||||
* Typical LVM users would find they have very few targets for each
|
||||
* LV (probably less than 10).
|
||||
*
|
||||
* (dm-target.c) Target types are not hard coded, instead the
|
||||
* register_mapping_type function should be called. A target type is
|
||||
* specified using three functions (see the header):
|
||||
*
|
||||
* dm_ctr_fn - takes a string and contructs a target specific piece of
|
||||
* context data.
|
||||
* dm_dtr_fn - destroy contexts.
|
||||
* dm_map_fn - function that takes a buffer_head and some previously
|
||||
* constructed context and performs the remapping.
|
||||
*
|
||||
* Currently there are two two trivial mappers, which are
|
||||
* automatically registered: 'linear', and 'io_error'. Linear alone
|
||||
* is enough to implement most LVM features (omitting striped volumes
|
||||
* and snapshots).
|
||||
*
|
||||
* (dm-fs.c) The driver is controlled through a /proc interface:
|
||||
* /proc/device-mapper/control allows you to create and remove devices
|
||||
* by 'cat'ing a line of the following format:
|
||||
*
|
||||
* create <device name> [minor no]
|
||||
* remove <device name>
|
||||
*
|
||||
* /proc/device-mapper/<device name> accepts the mapping table:
|
||||
*
|
||||
* begin
|
||||
* <sector start> <length> <target name> <target args>...
|
||||
* ...
|
||||
* end
|
||||
*
|
||||
* The begin/end lines are nasty, they should be handled by open/close
|
||||
* for the file.
|
||||
*
|
||||
* At the moment the table assumes 32 bit keys (sectors), the move to
|
||||
* 64 bits will involve no interface changes, since the tables will be
|
||||
* read in as ascii data. A different table implementation can
|
||||
* therefor be provided at another time. Either just by changing offset_t
|
||||
* to 64 bits, or maybe implementing a structure which looks up the keys in
|
||||
* stages (ie, 32 bits at a time).
|
||||
*
|
||||
* More interesting targets:
|
||||
*
|
||||
* striped mapping; given a stripe size and a number of device regions
|
||||
* this would stripe data across the regions. Especially useful, since
|
||||
* we could limit each striped region to a 32 bit area and then avoid
|
||||
* nasty 64 bit %'s.
|
||||
*
|
||||
* mirror mapping (reflector ?); would set off a kernel thread slowly
|
||||
* copying data from one region to another, ensuring that any new
|
||||
* writes got copied to both destinations correctly. Great for
|
||||
* implementing pvmove. Not sure how userland would be notified that
|
||||
* the copying process had completed. Possibly by reading a /proc entry
|
||||
* for the LV. Could also use poll() for this kind of thing.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef DM_INTERNAL_H
|
||||
#define DM_INTERNAL_H
|
||||
|
||||
#include <linux/version.h>
|
||||
#include <linux/major.h>
|
||||
#include <linux/iobuf.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/vmalloc.h>
|
||||
#include <linux/compatmac.h>
|
||||
#include <linux/cache.h>
|
||||
#include <linux/devfs_fs_kernel.h>
|
||||
#include <linux/ctype.h>
|
||||
#include <linux/device-mapper.h>
|
||||
#include <linux/list.h>
|
||||
|
||||
#define MAX_DEPTH 16
|
||||
#define NODE_SIZE L1_CACHE_BYTES
|
||||
#define KEYS_PER_NODE (NODE_SIZE / sizeof(offset_t))
|
||||
#define CHILDREN_PER_NODE (KEYS_PER_NODE + 1)
|
||||
#define DM_NAME_LEN 128
|
||||
#define MAX_TARGET_LINE 256
|
||||
|
||||
enum {
|
||||
DM_BOUND = 0, /* device has been bound to a table */
|
||||
DM_ACTIVE, /* device is running */
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* list of devices that a metadevice uses
|
||||
* and hence should open/close.
|
||||
*/
|
||||
struct dm_dev {
|
||||
atomic_t count;
|
||||
struct list_head list;
|
||||
|
||||
kdev_t dev;
|
||||
struct block_device *bd;
|
||||
};
|
||||
|
||||
/*
|
||||
* io that had to be deferred while we were
|
||||
* suspended
|
||||
*/
|
||||
struct deferred_io {
|
||||
int rw;
|
||||
struct buffer_head *bh;
|
||||
struct deferred_io *next;
|
||||
};
|
||||
|
||||
/*
|
||||
* btree leaf, these do the actual mapping
|
||||
*/
|
||||
struct target {
|
||||
struct target_type *type;
|
||||
void *private;
|
||||
};
|
||||
|
||||
/*
|
||||
* the btree
|
||||
*/
|
||||
struct dm_table {
|
||||
/* btree table */
|
||||
int depth;
|
||||
int counts[MAX_DEPTH]; /* in nodes */
|
||||
offset_t *index[MAX_DEPTH];
|
||||
|
||||
int num_targets;
|
||||
int num_allocated;
|
||||
offset_t *highs;
|
||||
struct target *targets;
|
||||
|
||||
/* a list of devices used by this table */
|
||||
struct list_head devices;
|
||||
};
|
||||
|
||||
/*
|
||||
* the actual device struct
|
||||
*/
|
||||
struct mapped_device {
|
||||
kdev_t dev;
|
||||
char name[DM_NAME_LEN];
|
||||
struct inode *inode;
|
||||
|
||||
int use_count;
|
||||
int state;
|
||||
|
||||
/* a list of io's that arrived while we were suspended */
|
||||
atomic_t pending;
|
||||
wait_queue_head_t wait;
|
||||
struct deferred_io *deferred;
|
||||
|
||||
struct dm_table *map;
|
||||
|
||||
/* used by dm-fs.c */
|
||||
devfs_handle_t devfs_entry;
|
||||
};
|
||||
|
||||
extern struct block_device_operations dm_blk_dops;
|
||||
|
||||
|
||||
/* dm-target.c */
|
||||
int dm_target_init(void);
|
||||
struct target_type *dm_get_target_type(const char *name);
|
||||
void dm_put_target_type(struct target_type *t);
|
||||
|
||||
/* dm.c */
|
||||
struct mapped_device *dm_find_by_minor(int minor);
|
||||
|
||||
struct mapped_device *dm_create(const char *name, int minor);
|
||||
int dm_remove(struct mapped_device *md);
|
||||
|
||||
int dm_activate(struct mapped_device *md, struct dm_table *t);
|
||||
int dm_deactivate(struct mapped_device *md);
|
||||
|
||||
void dm_suspend(struct mapped_device *md);
|
||||
|
||||
|
||||
/* dm-table.c */
|
||||
struct dm_table *dm_table_create(void);
|
||||
void dm_table_destroy(struct dm_table *t);
|
||||
|
||||
int dm_table_add_target(struct dm_table *t, offset_t high,
|
||||
struct target_type *type, void *private);
|
||||
int dm_table_complete(struct dm_table *t);
|
||||
|
||||
/* dm-parse.c */
|
||||
typedef int (*extract_line_fn)(struct text_region *line,
|
||||
void *private);
|
||||
|
||||
struct dm_table *dm_parse(extract_line_fn line_fn, void *line_private,
|
||||
dm_error_fn err_fn, void *err_private);
|
||||
|
||||
|
||||
static inline int dm_empty_tok(struct text_region *txt)
|
||||
{
|
||||
return txt->b >= txt->e;
|
||||
}
|
||||
|
||||
/* dm-fs.c */
|
||||
int dm_fs_init(void);
|
||||
void dm_fs_exit(void);
|
||||
|
||||
|
||||
|
||||
#define WARN(f, x...) printk(KERN_WARNING "device-mapper: " f "\n" , ## x)
|
||||
|
||||
/*
|
||||
* calculate the index of the child node of the
|
||||
* n'th node k'th key.
|
||||
*/
|
||||
static inline int get_child(int n, int k)
|
||||
{
|
||||
return (n * CHILDREN_PER_NODE) + k;
|
||||
}
|
||||
|
||||
/*
|
||||
* returns the n'th node of level l from table t.
|
||||
*/
|
||||
static inline offset_t *get_node(struct dm_table *t, int l, int n)
|
||||
{
|
||||
return t->index[l] + (n * KEYS_PER_NODE);
|
||||
}
|
||||
|
||||
static inline int is_active(struct mapped_device *md)
|
||||
{
|
||||
return test_bit(DM_ACTIVE, &md->state);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,156 +0,0 @@
|
||||
/*
|
||||
* dmfs-error.c
|
||||
*
|
||||
* Copyright (C) 2001 Sistina Software
|
||||
*
|
||||
* This software is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GNU CC; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <linux/config.h>
|
||||
#include <linux/list.h>
|
||||
#include <linux/fs.h>
|
||||
|
||||
#include "dm.h"
|
||||
|
||||
struct dmfs_error {
|
||||
struct list_head list;
|
||||
unsigned len;
|
||||
char *msg;
|
||||
};
|
||||
|
||||
void dmfs_add_error(struct dm_table *t, unsigned num, char *str)
|
||||
{
|
||||
int len = strlen(str) + sizeof(struct dmfs_error) + 12;
|
||||
struct dmfs_error *e = kmalloc(len, GFP_KERNEL);
|
||||
if (e) {
|
||||
e->msg = (char *)(e + 1);
|
||||
e->len = sprintf(e->msg, "%8u: %s\n", num, str);
|
||||
list_add(&e->list, &t->errors);
|
||||
}
|
||||
}
|
||||
|
||||
void dmfs_zap_errors(struct dm_table *t)
|
||||
{
|
||||
struct dmfs_error *e;
|
||||
|
||||
while(!list_empty(&t->errors)) {
|
||||
e = list_entry(t->errors.next, struct dmfs_error, list);
|
||||
list_del(&e->list);
|
||||
kfree(e);
|
||||
}
|
||||
}
|
||||
|
||||
static struct dmfs_error *find_initial_message(struct dm_table *t, loff_t *pos)
|
||||
{
|
||||
struct dmfs_error *e;
|
||||
struct list_head *tmp, *head;
|
||||
|
||||
tmp = head = &t->errors;
|
||||
for(;;) {
|
||||
tmp = tmp->next;
|
||||
if (tmp == head)
|
||||
break;
|
||||
e = list_entry(tmp, struct dmfs_error, list);
|
||||
if (*pos < e->len)
|
||||
return e;
|
||||
(*pos) -= e->len;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int copy_sequence(struct dm_table *t, struct dmfs_error *e, char *buf,
|
||||
size_t size, loff_t offset)
|
||||
{
|
||||
char *from;
|
||||
int amount;
|
||||
int copied = 0;
|
||||
|
||||
do {
|
||||
from = e->msg + offset;
|
||||
amount = e->len - offset;
|
||||
|
||||
if (copy_to_user(buf, from, amount))
|
||||
return -EFAULT;
|
||||
|
||||
buf += amount;
|
||||
copied += amount;
|
||||
size -= amount;
|
||||
offset = 0;
|
||||
|
||||
if (e->list.next == &t->errors)
|
||||
break;
|
||||
e = list_entry(e->list.next, struct dmfs_error, list);
|
||||
} while(size > 0);
|
||||
|
||||
return amount;
|
||||
}
|
||||
|
||||
static ssize_t dmfs_error_read(struct file *file, char *buf, size_t size, loff_t *pos)
|
||||
{
|
||||
struct dmfs_i *dmi = DMFS_I(file->f_dentry->d_parent->d_inode);
|
||||
struct dm_table *t = dmi->table;
|
||||
int copied = 0;
|
||||
loff_t offset = *pos;
|
||||
|
||||
if (!access_ok(VERIFY_WRITE, buf, size))
|
||||
return -EFAULT;
|
||||
|
||||
down(&dmi->sem);
|
||||
if (dmi->table) {
|
||||
struct dmfs_error *e = find_initial_message(t, &offset);
|
||||
if (e) {
|
||||
copied = copy_sequence(t, e, buf, size, offset);
|
||||
if (copied > 0)
|
||||
(*pos) += copied;
|
||||
}
|
||||
}
|
||||
up(&dmi->sem);
|
||||
return copied;
|
||||
}
|
||||
|
||||
static int dmfs_error_sync(struct file *file, struct dentry *dentry, int datasync)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct file_operations dmfs_error_file_operations = {
|
||||
read: dmfs_error_read,
|
||||
fsync: dmfs_error_sync,
|
||||
};
|
||||
|
||||
static struct inode_operations dmfs_error_inode_operations = {
|
||||
};
|
||||
|
||||
struct inode *dmfs_create_error(struct inode *dir, int mode)
|
||||
{
|
||||
struct inode *inode = new_inode(dir->i_sb);
|
||||
|
||||
if (inode) {
|
||||
inode->i_mode = mode | S_IFREG;
|
||||
inode->i_uid = current->fsuid;
|
||||
inode->i_gid = current->fsgid;
|
||||
inode->i_blksize = PAGE_CACHE_SIZE;
|
||||
inode->i_blocks = 0;
|
||||
inode->i_rdev = NODEV;
|
||||
inode->i_atime = inode->i_ctime = inode->i_mtime = CURRENT_TIME;
|
||||
inode->i_fop = &dmfs_error_file_operations;
|
||||
inode->i_op = &dmfs_error_inode_operations;
|
||||
}
|
||||
|
||||
return inode;
|
||||
}
|
||||
|
||||
@@ -1,282 +0,0 @@
|
||||
/*
|
||||
* dmfs-lv.c
|
||||
*
|
||||
* Copyright (C) 2001 Sistina Software
|
||||
*
|
||||
* This software is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GNU CC; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/* Heavily based upon ramfs */
|
||||
|
||||
#include <linux/config.h>
|
||||
#include <linux/ctype.h>
|
||||
#include <linux/fs.h>
|
||||
|
||||
#include "dm.h"
|
||||
|
||||
extern struct address_space_operations dmfs_address_space_operations;
|
||||
extern struct inode *dmfs_create_tdir(struct super_block *sb, int mode);
|
||||
|
||||
struct dentry *dmfs_verify_name(struct inode *dir, const char *name)
|
||||
{
|
||||
struct nameidata nd;
|
||||
int err = -ENOENT;
|
||||
struct file file;
|
||||
struct dentry *dentry;
|
||||
|
||||
memset(&file, 0, sizeof(struct file));
|
||||
|
||||
if (!path_init(name, LOOKUP_FOLLOW, &nd))
|
||||
return ERR_PTR(-EINVAL);
|
||||
|
||||
err = path_walk(name, &nd);
|
||||
if (err)
|
||||
goto err_out;
|
||||
|
||||
err = -EINVAL;
|
||||
if (nd.mnt->mnt_sb != dir->i_sb)
|
||||
goto err_out;
|
||||
|
||||
if (nd.dentry->d_parent->d_inode != dir)
|
||||
goto err_out;
|
||||
|
||||
err = -ENODATA;
|
||||
if (DMFS_I(nd.dentry->d_inode) == NULL ||
|
||||
DMFS_I(nd.dentry->d_inode)->table == NULL)
|
||||
goto err_out;
|
||||
|
||||
if (!list_empty(&(DMFS_I(nd.dentry->d_inode)->table->errors)))
|
||||
goto err_out;
|
||||
|
||||
dentry = nd.dentry;
|
||||
file.f_dentry = nd.dentry->d_parent;
|
||||
err = deny_write_access(&file);
|
||||
if (err)
|
||||
goto err_out;
|
||||
|
||||
dget(dentry);
|
||||
path_release(&nd);
|
||||
return dentry;
|
||||
err_out:
|
||||
path_release(&nd);
|
||||
return ERR_PTR(err);
|
||||
}
|
||||
|
||||
struct inode *dmfs_create_symlink(struct inode *dir, int mode)
|
||||
{
|
||||
struct inode *inode = dmfs_new_inode(dir->i_sb, mode | S_IFLNK);
|
||||
|
||||
if (inode) {
|
||||
inode->i_mapping->a_ops = &dmfs_address_space_operations;
|
||||
inode->i_op = &page_symlink_inode_operations;
|
||||
}
|
||||
|
||||
return inode;
|
||||
}
|
||||
|
||||
static int dmfs_lv_unlink(struct inode *dir, struct dentry *dentry)
|
||||
{
|
||||
struct inode *inode = dentry->d_inode;
|
||||
struct file file = { f_dentry: dentry->d_parent };
|
||||
|
||||
if (!(inode->i_mode & S_IFLNK))
|
||||
return -EINVAL;
|
||||
|
||||
dm_suspend(DMFS_I(dir)->md);
|
||||
allow_write_access(&file);
|
||||
inode->i_nlink--;
|
||||
dput(dentry);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int dmfs_lv_symlink(struct inode *dir, struct dentry *dentry,
|
||||
const char *symname)
|
||||
{
|
||||
struct inode *inode;
|
||||
struct dentry *de;
|
||||
int rv;
|
||||
int l;
|
||||
|
||||
if (dentry->d_name.len != 6 ||
|
||||
memcmp(dentry->d_name.name, "ACTIVE", 6) != 0)
|
||||
return -EINVAL;
|
||||
|
||||
de = dmfs_verify_name(dir, symname);
|
||||
if (IS_ERR(de))
|
||||
return PTR_ERR(de);
|
||||
|
||||
inode = dmfs_create_symlink(dir, S_IRWXUGO);
|
||||
if (inode == NULL) {
|
||||
rv = -ENOSPC;
|
||||
goto out_allow_write;
|
||||
}
|
||||
|
||||
DMFS_I(inode)->dentry = de;
|
||||
d_instantiate(dentry, inode);
|
||||
dget(dentry);
|
||||
|
||||
l = strlen(symname) + 1;
|
||||
rv = block_symlink(inode, symname, l);
|
||||
if (rv)
|
||||
goto out_dput;
|
||||
|
||||
rv = dm_activate(DMFS_I(dir)->md, DMFS_I(de->d_inode)->table);
|
||||
if (rv)
|
||||
goto out_dput;
|
||||
|
||||
return rv;
|
||||
|
||||
out_dput:
|
||||
DMFS_I(inode)->dentry = NULL;
|
||||
out_allow_write:
|
||||
{
|
||||
struct file file = { f_dentry: de->d_parent };
|
||||
allow_write_access(&file);
|
||||
dput(de);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
static int is_identifier(const char *str, int len)
|
||||
{
|
||||
while(len--) {
|
||||
if (!isalnum(*str) && *str != '_')
|
||||
return 0;
|
||||
str++;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int dmfs_lv_mkdir(struct inode *dir, struct dentry *dentry, int mode)
|
||||
{
|
||||
struct inode *inode;
|
||||
int rv = -ENOSPC;
|
||||
|
||||
if (dentry->d_name.len >= DM_NAME_LEN)
|
||||
return -EINVAL;
|
||||
|
||||
if (!is_identifier(dentry->d_name.name, dentry->d_name.len))
|
||||
return -EPERM;
|
||||
|
||||
if (dentry->d_name.len == 6 &&
|
||||
memcmp(dentry->d_name.name, "ACTIVE", 6) == 0)
|
||||
return -EINVAL;
|
||||
|
||||
if (dentry->d_name.name[0] == '.')
|
||||
return -EINVAL;
|
||||
|
||||
inode = dmfs_create_tdir(dir->i_sb, mode);
|
||||
if (inode) {
|
||||
d_instantiate(dentry, inode);
|
||||
dget(dentry);
|
||||
rv = 0;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
/*
|
||||
* if u.generic_ip is not NULL, then it indicates an inode which
|
||||
* represents a table. If it is NULL then the inode is a virtual
|
||||
* file and should be deleted along with the directory.
|
||||
*/
|
||||
static inline int positive(struct dentry *dentry)
|
||||
{
|
||||
return dentry->d_inode && !d_unhashed(dentry);
|
||||
}
|
||||
|
||||
static int empty(struct dentry *dentry)
|
||||
{
|
||||
struct list_head *list;
|
||||
|
||||
spin_lock(&dcache_lock);
|
||||
list = dentry->d_subdirs.next;
|
||||
|
||||
while(list != &dentry->d_subdirs) {
|
||||
struct dentry *de = list_entry(list, struct dentry, d_child);
|
||||
|
||||
if (positive(de)) {
|
||||
spin_unlock(&dcache_lock);
|
||||
return 0;
|
||||
}
|
||||
list = list->next;
|
||||
}
|
||||
spin_unlock(&dcache_lock);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int dmfs_lv_rmdir(struct inode *dir, struct dentry *dentry)
|
||||
{
|
||||
int ret = -ENOTEMPTY;
|
||||
|
||||
if (empty(dentry)) {
|
||||
struct inode *inode = dentry->d_inode;
|
||||
inode->i_nlink--;
|
||||
dput(dentry);
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static struct dentry *dmfs_lv_lookup(struct inode *dir, struct dentry *dentry)
|
||||
{
|
||||
d_add(dentry, NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int dmfs_lv_sync(struct file *file, struct dentry *dentry, int datasync)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct file_operations dmfs_lv_file_operations = {
|
||||
read: generic_read_dir,
|
||||
readdir: dcache_readdir,
|
||||
fsync: dmfs_lv_sync,
|
||||
};
|
||||
|
||||
static struct inode_operations dmfs_lv_inode_operations = {
|
||||
lookup: dmfs_lv_lookup,
|
||||
unlink: dmfs_lv_unlink,
|
||||
symlink: dmfs_lv_symlink,
|
||||
mkdir: dmfs_lv_mkdir,
|
||||
rmdir: dmfs_lv_rmdir,
|
||||
};
|
||||
|
||||
struct inode *dmfs_create_lv(struct super_block *sb, int mode, struct dentry *dentry)
|
||||
{
|
||||
struct inode *inode = dmfs_new_inode(sb, mode | S_IFDIR);
|
||||
struct mapped_device *md;
|
||||
const char *name = dentry->d_name.name;
|
||||
char tmp_name[DM_NAME_LEN + 1];
|
||||
|
||||
if (inode) {
|
||||
inode->i_fop = &dmfs_lv_file_operations;
|
||||
inode->i_op = &dmfs_lv_inode_operations;
|
||||
memcpy(tmp_name, name, dentry->d_name.len);
|
||||
tmp_name[dentry->d_name.len] = 0;
|
||||
md = dm_create(tmp_name, -1);
|
||||
if (IS_ERR(md)) {
|
||||
iput(inode);
|
||||
return ERR_PTR(PTR_ERR(md));
|
||||
}
|
||||
DMFS_I(inode)->md = md;
|
||||
}
|
||||
|
||||
return inode;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,164 +0,0 @@
|
||||
/*
|
||||
* dmfs-root.c
|
||||
*
|
||||
* Copyright (C) 2001 Sistina Software
|
||||
*
|
||||
* This software is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GNU CC; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/* Heavily based upon ramfs */
|
||||
|
||||
#include <linux/config.h>
|
||||
#include <linux/ctype.h>
|
||||
#include <linux/fs.h>
|
||||
|
||||
#include "dm.h"
|
||||
|
||||
extern struct inode *dmfs_create_lv(struct super_block *sb, int mode, struct dentry *dentry);
|
||||
|
||||
static int is_identifier(const char *str, int len)
|
||||
{
|
||||
while(len--) {
|
||||
if (!isalnum(*str) && *str != '_')
|
||||
return 0;
|
||||
str++;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int dmfs_root_mkdir(struct inode *dir, struct dentry *dentry, int mode)
|
||||
{
|
||||
struct inode *inode;
|
||||
int rv = -ENOSPC;
|
||||
|
||||
if (dentry->d_name.len >= DM_NAME_LEN)
|
||||
return -EINVAL;
|
||||
|
||||
if (!is_identifier(dentry->d_name.name, dentry->d_name.len))
|
||||
return -EPERM;
|
||||
|
||||
if (dentry->d_name.name[0] == '.')
|
||||
return -EINVAL;
|
||||
|
||||
inode = dmfs_create_lv(dir->i_sb, mode, dentry);
|
||||
if (inode) {
|
||||
d_instantiate(dentry, inode);
|
||||
dget(dentry);
|
||||
rv = 0;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
/*
|
||||
* if u.generic_ip is not NULL, then it indicates an inode which
|
||||
* represents a table. If it is NULL then the inode is a virtual
|
||||
* file and should be deleted along with the directory.
|
||||
*/
|
||||
static inline int positive(struct dentry *dentry)
|
||||
{
|
||||
return dentry->d_inode && !d_unhashed(dentry);
|
||||
}
|
||||
|
||||
static int empty(struct dentry *dentry)
|
||||
{
|
||||
struct list_head *list;
|
||||
|
||||
spin_lock(&dcache_lock);
|
||||
list = dentry->d_subdirs.next;
|
||||
|
||||
while(list != &dentry->d_subdirs) {
|
||||
struct dentry *de = list_entry(list, struct dentry, d_child);
|
||||
|
||||
if (positive(de)) {
|
||||
spin_unlock(&dcache_lock);
|
||||
return 0;
|
||||
}
|
||||
list = list->next;
|
||||
}
|
||||
spin_unlock(&dcache_lock);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int dmfs_root_rmdir(struct inode *dir, struct dentry *dentry)
|
||||
{
|
||||
int ret = -ENOTEMPTY;
|
||||
|
||||
if (empty(dentry)) {
|
||||
struct inode *inode = dentry->d_inode;
|
||||
ret = dm_deactivate(DMFS_I(inode)->md);
|
||||
if (ret == 0) {
|
||||
inode->i_nlink--;
|
||||
dput(dentry);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static struct dentry *dmfs_root_lookup(struct inode *dir, struct dentry *dentry)
|
||||
{
|
||||
d_add(dentry, NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int dmfs_root_rename(struct inode *old_dir, struct dentry *old_dentry,
|
||||
struct inode *new_dir, struct dentry *new_dentry)
|
||||
{
|
||||
/* Can only rename - not move between directories! */
|
||||
if (old_dir != new_dir)
|
||||
return -EPERM;
|
||||
|
||||
return -EINVAL; /* FIXME: a change of LV name here */
|
||||
}
|
||||
|
||||
static int dmfs_root_sync(struct file *file, struct dentry *dentry, int datasync)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct file_operations dmfs_root_file_operations = {
|
||||
read: generic_read_dir,
|
||||
readdir: dcache_readdir,
|
||||
fsync: dmfs_root_sync,
|
||||
};
|
||||
|
||||
static struct inode_operations dmfs_root_inode_operations = {
|
||||
lookup: dmfs_root_lookup,
|
||||
mkdir: dmfs_root_mkdir,
|
||||
rmdir: dmfs_root_rmdir,
|
||||
rename: dmfs_root_rename,
|
||||
};
|
||||
|
||||
struct inode *dmfs_create_root(struct super_block *sb, int mode)
|
||||
{
|
||||
struct inode *inode = new_inode(sb);
|
||||
|
||||
if (inode) {
|
||||
inode->i_mode = mode | S_IFDIR;
|
||||
inode->i_uid = current->fsuid;
|
||||
inode->i_gid = current->fsgid;
|
||||
inode->i_blksize = PAGE_CACHE_SIZE;
|
||||
inode->i_blocks = 0;
|
||||
inode->i_rdev = NODEV;
|
||||
inode->i_atime = inode->i_ctime = inode->i_mtime = CURRENT_TIME;
|
||||
inode->i_fop = &dmfs_root_file_operations;
|
||||
inode->i_op = &dmfs_root_inode_operations;
|
||||
}
|
||||
|
||||
return inode;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* dmfs-status.c
|
||||
*
|
||||
* Copyright (C) 2001 Sistina Software
|
||||
*
|
||||
* This software is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GNU CC; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <linux/config.h>
|
||||
#include <linux/fs.h>
|
||||
|
||||
#include "dm.h"
|
||||
|
||||
static ssize_t dmfs_status_read(struct file *file, char *buf, size_t size, loff_t *pos)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int dmfs_status_sync(struct file *file, struct dentry *dentry, int datasync)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct file_operations dmfs_status_file_operations = {
|
||||
read: dmfs_status_read,
|
||||
fsync: dmfs_status_sync,
|
||||
};
|
||||
|
||||
static struct inode_operations dmfs_status_inode_operations = {
|
||||
};
|
||||
|
||||
struct inode *dmfs_create_status(struct inode *dir, int mode)
|
||||
{
|
||||
struct inode *inode = new_inode(dir->i_sb);
|
||||
|
||||
if (inode) {
|
||||
inode->i_mode = mode | S_IFREG;
|
||||
inode->i_uid = current->fsuid;
|
||||
inode->i_gid = current->fsgid;
|
||||
inode->i_blksize = PAGE_CACHE_SIZE;
|
||||
inode->i_blocks = 0;
|
||||
inode->i_rdev = NODEV;
|
||||
inode->i_atime = inode->i_ctime = inode->i_mtime = CURRENT_TIME;
|
||||
inode->i_fop = &dmfs_status_file_operations;
|
||||
inode->i_op = &dmfs_status_inode_operations;
|
||||
}
|
||||
|
||||
return inode;
|
||||
}
|
||||
|
||||
@@ -1,112 +0,0 @@
|
||||
/*
|
||||
* dmfs-super.c
|
||||
*
|
||||
* Copyright (C) 2001 Sistina Software
|
||||
*
|
||||
* This software is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GNU CC; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <linux/config.h>
|
||||
#include <linux/fs.h>
|
||||
|
||||
#include "dm.h"
|
||||
|
||||
#define DMFS_MAGIC 0x444D4653
|
||||
|
||||
extern struct inode *dmfs_create_root(struct super_block *sb, int);
|
||||
|
||||
static int dmfs_statfs(struct super_block *sb, struct statfs *buf)
|
||||
{
|
||||
buf->f_type = sb->s_magic;
|
||||
buf->f_bsize = sb->s_blocksize;
|
||||
buf->f_namelen = DM_NAME_LEN - 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dmfs_delete_inode(struct inode *inode)
|
||||
{
|
||||
struct dmfs_i *dmi = DMFS_I(inode);
|
||||
|
||||
if (dmi) {
|
||||
if (dmi->md)
|
||||
dm_remove(dmi->md);
|
||||
if (dmi->table)
|
||||
dm_table_destroy(dmi->table);
|
||||
if (dmi->dentry)
|
||||
dput(dmi->dentry);
|
||||
kfree(dmi);
|
||||
}
|
||||
|
||||
inode->u.generic_ip = NULL;
|
||||
clear_inode(inode);
|
||||
}
|
||||
|
||||
static struct super_operations dmfs_super_operations = {
|
||||
statfs: dmfs_statfs,
|
||||
put_inode: force_delete,
|
||||
delete_inode: dmfs_delete_inode,
|
||||
};
|
||||
|
||||
struct super_block *dmfs_read_super(struct super_block *sb, void *data, int silent)
|
||||
{
|
||||
struct inode *inode;
|
||||
struct dentry *root;
|
||||
|
||||
sb->s_blocksize = PAGE_CACHE_SIZE;
|
||||
sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
|
||||
sb->s_magic = DMFS_MAGIC;
|
||||
sb->s_op = &dmfs_super_operations;
|
||||
sb->s_maxbytes = MAX_NON_LFS;
|
||||
|
||||
inode = dmfs_create_root(sb, 0755);
|
||||
if (IS_ERR(inode))
|
||||
return NULL;
|
||||
root = d_alloc_root(inode);
|
||||
if (!root) {
|
||||
iput(inode);
|
||||
return NULL;
|
||||
}
|
||||
sb->s_root = root;
|
||||
|
||||
return sb;
|
||||
}
|
||||
|
||||
struct inode *dmfs_new_inode(struct super_block *sb, int mode)
|
||||
{
|
||||
struct inode *inode = new_inode(sb);
|
||||
struct dmfs_i *dmi;
|
||||
|
||||
if (inode) {
|
||||
inode->i_mode = mode;
|
||||
inode->i_uid = current->fsuid;
|
||||
inode->i_gid = current->fsgid;
|
||||
inode->i_blksize = PAGE_CACHE_SIZE;
|
||||
inode->i_blocks = 0;
|
||||
inode->i_rdev = NODEV;
|
||||
inode->i_atime = inode->i_ctime = inode->i_mtime = CURRENT_TIME;
|
||||
|
||||
dmi = kmalloc(sizeof(struct dmfs_i), GFP_KERNEL);
|
||||
if (dmi == NULL) {
|
||||
iput(inode);
|
||||
return NULL;
|
||||
}
|
||||
memset(dmi, 0, sizeof(struct dmfs_i));
|
||||
init_MUTEX(&dmi->sem);
|
||||
inode->u.generic_ip = dmi;
|
||||
}
|
||||
return inode;
|
||||
}
|
||||
@@ -1,379 +0,0 @@
|
||||
/*
|
||||
* dmfs-table.c
|
||||
*
|
||||
* Copyright (C) 2001 Sistina Software
|
||||
*
|
||||
* This software is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GNU CC; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <linux/config.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/mm.h>
|
||||
|
||||
#include "dm.h"
|
||||
|
||||
static offset_t start_of_next_range(struct dm_table *t)
|
||||
{
|
||||
offset_t n = 0;
|
||||
if (t->num_targets) {
|
||||
n = t->highs[t->num_targets - 1] + 1;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
static void dmfs_parse_line(struct dm_table *t, unsigned num, char *str)
|
||||
{
|
||||
char *p = str;
|
||||
const char *tok;
|
||||
offset_t start, size, high;
|
||||
void *context;
|
||||
struct target_type *ttype;
|
||||
int rv = 0;
|
||||
char *msg;
|
||||
|
||||
printk("dmfs_parse_line: (%s)\n", str);
|
||||
|
||||
msg = "No start argument";
|
||||
tok = next_token(&p);
|
||||
if (!tok)
|
||||
goto out;
|
||||
start = simple_strtoul(tok, NULL, 10);
|
||||
|
||||
msg = "No size argument";
|
||||
tok = next_token(&p);
|
||||
if (!tok)
|
||||
goto out;
|
||||
size = simple_strtoul(tok, NULL, 10);
|
||||
|
||||
msg = "Gap in table";
|
||||
if (start != start_of_next_range(t))
|
||||
goto out;
|
||||
|
||||
msg = "No target type";
|
||||
tok = next_token(&p);
|
||||
if (!tok)
|
||||
goto out;
|
||||
|
||||
msg = "Target type unknown";
|
||||
ttype = dm_get_target_type(tok);
|
||||
if (ttype) {
|
||||
msg = "This message should never appear (constructor error)";
|
||||
rv = ttype->ctr(t, start, size, p, &context);
|
||||
msg = context;
|
||||
if (rv == 0) {
|
||||
printk("dmfs_parse: %ul %ul %s %s\n", start, size,
|
||||
ttype->name,
|
||||
ttype->print ? ttype->print(context) : "-");
|
||||
msg = "Error adding target to table";
|
||||
high = start + (size - 1);
|
||||
if (dm_table_add_target(t, high, ttype, context) == 0)
|
||||
return;
|
||||
ttype->dtr(t, context);
|
||||
}
|
||||
dm_put_target_type(ttype);
|
||||
}
|
||||
out:
|
||||
dmfs_add_error(t, num, msg);
|
||||
}
|
||||
|
||||
|
||||
static int dmfs_copy(char *dst, int dstlen, char *src, int srclen, int *flag)
|
||||
{
|
||||
int len = min(dstlen, srclen);
|
||||
char *start = dst;
|
||||
|
||||
while(len) {
|
||||
*dst = *src++;
|
||||
if (*dst == '\n')
|
||||
goto end_of_line;
|
||||
dst++;
|
||||
len--;
|
||||
}
|
||||
out:
|
||||
return (dst - start);
|
||||
end_of_line:
|
||||
dst++;
|
||||
*flag = 1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
static int dmfs_line_is_not_comment(char *str)
|
||||
{
|
||||
while(*str) {
|
||||
if (*str == '#')
|
||||
break;
|
||||
if (!isspace(*str))
|
||||
return 1;
|
||||
str++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int dmfs_parse_page(struct dm_table *t, char *buf, int end, unsigned long end_index, char *tmp, unsigned long *tmpl, int *num)
|
||||
{
|
||||
int copied;
|
||||
unsigned long len = end ? end_index : PAGE_CACHE_SIZE - 1;
|
||||
|
||||
do {
|
||||
int flag = 0;
|
||||
copied = dmfs_copy(tmp + *tmpl, PAGE_SIZE - *tmpl - 1, buf, len, &flag);
|
||||
buf += copied;
|
||||
len -= copied;
|
||||
if (*tmpl + copied == PAGE_SIZE - 1)
|
||||
goto line_too_long;
|
||||
(*tmpl) += copied;
|
||||
if (flag || (len == 0 && end)) {
|
||||
*(tmp + *tmpl) = 0;
|
||||
if (dmfs_line_is_not_comment(tmp))
|
||||
dmfs_parse_line(t, *num, tmp);
|
||||
(*num)++;
|
||||
*tmpl = 0;
|
||||
}
|
||||
} while(len > 0);
|
||||
return 0;
|
||||
|
||||
line_too_long:
|
||||
dmfs_add_error(t, *num, "Line too long");
|
||||
/* FIXME: Add code to recover from this */
|
||||
return -1;
|
||||
}
|
||||
|
||||
static struct dm_table *dmfs_parse(struct inode *inode)
|
||||
{
|
||||
struct address_space *mapping = inode->i_mapping;
|
||||
unsigned long index = 0;
|
||||
unsigned long end_index, end_offset;
|
||||
unsigned long page;
|
||||
unsigned long rem = 0;
|
||||
struct dm_table *t;
|
||||
struct page *pg;
|
||||
int num = 0;
|
||||
|
||||
if (inode->i_size == 0)
|
||||
return NULL;
|
||||
|
||||
page = __get_free_page(GFP_KERNEL);
|
||||
|
||||
if (!page)
|
||||
return NULL;
|
||||
|
||||
t = dm_table_create();
|
||||
if (!t) {
|
||||
free_page(page);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
end_index = inode->i_size >> PAGE_CACHE_SHIFT;
|
||||
end_offset = inode->i_size & (PAGE_CACHE_SIZE - 1);
|
||||
|
||||
do {
|
||||
pg = find_get_page(mapping, index);
|
||||
|
||||
if (pg) {
|
||||
char *kaddr;
|
||||
int rv;
|
||||
|
||||
if (!Page_Uptodate(pg))
|
||||
goto broken;
|
||||
|
||||
kaddr = kmap(pg);
|
||||
rv = dmfs_parse_page(t, kaddr, (index == end_index), end_offset, (char *)page, &rem, &num);
|
||||
kunmap(pg);
|
||||
page_cache_release(pg);
|
||||
|
||||
if (rv)
|
||||
goto parse_error;
|
||||
}
|
||||
|
||||
index++;
|
||||
} while(index <= end_index);
|
||||
|
||||
free_page(page);
|
||||
if (list_empty(&t->errors)) {
|
||||
dm_table_complete(t);
|
||||
}
|
||||
|
||||
return t;
|
||||
|
||||
broken:
|
||||
printk(KERN_ERR "dmfs_parse: Page not uptodate\n");
|
||||
page_cache_release(pg);
|
||||
free_page(page);
|
||||
dm_table_destroy(t);
|
||||
return NULL;
|
||||
|
||||
parse_error:
|
||||
printk(KERN_ERR "dmfs_parse: Parse error\n");
|
||||
free_page(page);
|
||||
dm_table_destroy(t);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int dmfs_table_release(struct inode *inode, struct file *f)
|
||||
{
|
||||
struct dentry *dentry = f->f_dentry;
|
||||
struct inode *parent = dentry->d_parent->d_inode;
|
||||
struct dmfs_i *dmi = DMFS_I(parent);
|
||||
struct dm_table *table;
|
||||
|
||||
if (f->f_mode & FMODE_WRITE) {
|
||||
|
||||
down(&dmi->sem);
|
||||
table = dmfs_parse(dentry->d_parent->d_inode);
|
||||
|
||||
if (table) {
|
||||
if (dmi->table)
|
||||
dm_table_destroy(dmi->table);
|
||||
dmi->table = table;
|
||||
}
|
||||
up(&dmi->sem);
|
||||
|
||||
put_write_access(parent);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int dmfs_readpage(struct file *file, struct page *page)
|
||||
{
|
||||
if (!Page_Uptodate(page)) {
|
||||
memset(kmap(page), 0, PAGE_CACHE_SIZE);
|
||||
kunmap(page);
|
||||
flush_dcache_page(page);
|
||||
SetPageUptodate(page);
|
||||
}
|
||||
UnlockPage(page);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int dmfs_writepage(struct page *page)
|
||||
{
|
||||
SetPageDirty(page);
|
||||
UnlockPage(page);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int dmfs_prepare_write(struct file *file, struct page *page,
|
||||
unsigned offset, unsigned to)
|
||||
{
|
||||
void *addr = kmap(page);
|
||||
if (!Page_Uptodate(page)) {
|
||||
memset(addr, 0, PAGE_CACHE_SIZE);
|
||||
flush_dcache_page(page);
|
||||
SetPageUptodate(page);
|
||||
}
|
||||
SetPageDirty(page);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int dmfs_commit_write(struct file *file, struct page *page,
|
||||
unsigned offset, unsigned to)
|
||||
{
|
||||
struct inode *inode = page->mapping->host;
|
||||
loff_t pos = ((loff_t) page->index << PAGE_CACHE_SHIFT) + to;
|
||||
|
||||
kunmap(page);
|
||||
if (pos > inode->i_size)
|
||||
inode->i_size = pos;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* There is a small race here in that two processes might call this at
|
||||
* the same time and both fail. So its a fail safe race :-) This should
|
||||
* move into namei.c (and thus use the spinlock and do this properly)
|
||||
* at some stage if we continue to use this set of functions for ensuring
|
||||
* exclusive write access to the file
|
||||
*/
|
||||
static int get_exclusive_write_access(struct inode *inode)
|
||||
{
|
||||
if (get_write_access(inode))
|
||||
return -1;
|
||||
if (atomic_read(&inode->i_writecount) != 1) {
|
||||
put_write_access(inode);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int dmfs_table_open(struct inode *inode, struct file *file)
|
||||
{
|
||||
struct dentry *dentry = file->f_dentry;
|
||||
struct inode *parent = dentry->d_parent->d_inode;
|
||||
|
||||
if (file->f_mode & FMODE_WRITE) {
|
||||
if (get_exclusive_write_access(parent))
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int dmfs_table_sync(struct file *file, struct dentry *dentry, int datasync)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int dmfs_table_revalidate(struct dentry *dentry)
|
||||
{
|
||||
struct inode *inode = dentry->d_inode;
|
||||
struct inode *parent = dentry->d_parent->d_inode;
|
||||
|
||||
inode->i_size = parent->i_size;
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct address_space_operations dmfs_address_space_operations = {
|
||||
readpage: dmfs_readpage,
|
||||
writepage: dmfs_writepage,
|
||||
prepare_write: dmfs_prepare_write,
|
||||
commit_write: dmfs_commit_write,
|
||||
};
|
||||
|
||||
static struct file_operations dmfs_table_file_operations = {
|
||||
llseek: generic_file_llseek,
|
||||
read: generic_file_read,
|
||||
write: generic_file_write,
|
||||
open: dmfs_table_open,
|
||||
release: dmfs_table_release,
|
||||
fsync: dmfs_table_sync,
|
||||
};
|
||||
|
||||
static struct inode_operations dmfs_table_inode_operations = {
|
||||
revalidate: dmfs_table_revalidate,
|
||||
};
|
||||
|
||||
struct inode *dmfs_create_table(struct inode *dir, int mode)
|
||||
{
|
||||
struct inode *inode = new_inode(dir->i_sb);
|
||||
|
||||
if (inode) {
|
||||
inode->i_mode = mode | S_IFREG;
|
||||
inode->i_uid = current->fsuid;
|
||||
inode->i_gid = current->fsgid;
|
||||
inode->i_blksize = PAGE_CACHE_SIZE;
|
||||
inode->i_blocks = 0;
|
||||
inode->i_rdev = NODEV;
|
||||
inode->i_atime = inode->i_ctime = inode->i_mtime = CURRENT_TIME;
|
||||
inode->i_mapping = dir->i_mapping;
|
||||
inode->i_mapping->a_ops = &dmfs_address_space_operations;
|
||||
inode->i_fop = &dmfs_table_file_operations;
|
||||
inode->i_op = &dmfs_table_inode_operations;
|
||||
}
|
||||
|
||||
return inode;
|
||||
}
|
||||
|
||||
@@ -1,137 +0,0 @@
|
||||
/*
|
||||
* dmfs-tdir.c
|
||||
*
|
||||
* Copyright (C) 2001 Sistina Software
|
||||
*
|
||||
* This software is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GNU CC; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/* Heavily based upon ramfs */
|
||||
|
||||
#include <linux/config.h>
|
||||
#include <linux/fs.h>
|
||||
|
||||
#include "dm.h"
|
||||
|
||||
extern struct inode *dmfs_create_error(struct inode *, int);
|
||||
extern struct inode *dmfs_create_table(struct inode *, int);
|
||||
extern struct inode *dmfs_create_status(struct inode *, int);
|
||||
|
||||
|
||||
static int dmfs_tdir_unlink(struct inode *dir, struct dentry *dentry)
|
||||
{
|
||||
struct inode *inode = dentry->d_inode;
|
||||
|
||||
inode->i_mapping = &inode->i_data;
|
||||
inode->i_nlink--;
|
||||
dput(dentry);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct dentry *dmfs_tdir_lookup(struct inode *dir, struct dentry *dentry)
|
||||
{
|
||||
struct inode *inode = NULL;
|
||||
const char *name = dentry->d_name.name;
|
||||
|
||||
switch(dentry->d_name.len) {
|
||||
case 5:
|
||||
if (memcmp("table", name, 5) == 0) {
|
||||
inode = dmfs_create_table(dir, 0600);
|
||||
break;
|
||||
}
|
||||
if (memcmp("error", name, 5) == 0)
|
||||
inode = dmfs_create_error(dir, 0600);
|
||||
break;
|
||||
case 6:
|
||||
if (memcmp("status", name, 6) == 0)
|
||||
inode = dmfs_create_status(dir, 0600);
|
||||
break;
|
||||
}
|
||||
|
||||
d_add(dentry, inode);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int dmfs_tdir_readdir(struct file *filp, void *dirent, filldir_t filldir)
|
||||
{
|
||||
int i;
|
||||
struct dentry *dentry = filp->f_dentry;
|
||||
|
||||
i = filp->f_pos;
|
||||
switch(i) {
|
||||
case 0:
|
||||
if (filldir(dirent, ".", 1, i, dentry->d_inode->i_ino, DT_DIR) < 0)
|
||||
break;
|
||||
i++;
|
||||
filp->f_pos++;
|
||||
/* fallthrough */
|
||||
case 1:
|
||||
if (filldir(dirent, "..", 2, i, dentry->d_parent->d_inode->i_ino, DT_DIR) < 0)
|
||||
break;
|
||||
i++;
|
||||
filp->f_pos++;
|
||||
/* fallthrough */
|
||||
case 2:
|
||||
if (filldir(dirent, "table", 5, i, 2, DT_REG) < 0)
|
||||
break;
|
||||
i++;
|
||||
filp->f_pos++;
|
||||
/* fallthrough */
|
||||
case 3:
|
||||
if (filldir(dirent, "error", 5, i, 3, DT_REG) < 0)
|
||||
break;
|
||||
i++;
|
||||
filp->f_pos++;
|
||||
/* fallthrough */
|
||||
case 4:
|
||||
if (filldir(dirent, "status", 6, i, 4, DT_REG) < 0)
|
||||
break;
|
||||
i++;
|
||||
filp->f_pos++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int dmfs_tdir_sync(struct file *file, struct dentry *dentry, int datasync)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct file_operations dmfs_tdir_file_operations = {
|
||||
read: generic_read_dir,
|
||||
readdir: dmfs_tdir_readdir,
|
||||
fsync: dmfs_tdir_sync,
|
||||
};
|
||||
|
||||
static struct inode_operations dmfs_tdir_inode_operations = {
|
||||
lookup: dmfs_tdir_lookup,
|
||||
unlink: dmfs_tdir_unlink,
|
||||
};
|
||||
|
||||
struct inode *dmfs_create_tdir(struct super_block *sb, int mode)
|
||||
{
|
||||
struct inode *inode = dmfs_new_inode(sb, mode | S_IFDIR);
|
||||
|
||||
if (inode) {
|
||||
inode->i_fop = &dmfs_tdir_file_operations;
|
||||
inode->i_op = &dmfs_tdir_inode_operations;
|
||||
}
|
||||
|
||||
return inode;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,88 +0,0 @@
|
||||
diff -urN 2.4.7pre6/fs/buffer.c bh_async/fs/buffer.c
|
||||
--- 2.4.7pre6/fs/buffer.c Wed Jul 11 06:03:18 2001
|
||||
+++ bh_async/fs/buffer.c Thu Jul 12 07:55:08 2001
|
||||
@@ -827,10 +827,11 @@
|
||||
* that unlock the page..
|
||||
*/
|
||||
spin_lock_irqsave(&page_uptodate_lock, flags);
|
||||
+ mark_buffer_async(bh, 0);
|
||||
unlock_buffer(bh);
|
||||
tmp = bh->b_this_page;
|
||||
while (tmp != bh) {
|
||||
- if (tmp->b_end_io == end_buffer_io_async && buffer_locked(tmp))
|
||||
+ if (buffer_async(tmp) && buffer_locked(tmp))
|
||||
goto still_busy;
|
||||
tmp = tmp->b_this_page;
|
||||
}
|
||||
@@ -862,8 +863,9 @@
|
||||
return;
|
||||
}
|
||||
|
||||
-void set_buffer_async_io(struct buffer_head *bh) {
|
||||
+inline void set_buffer_async_io(struct buffer_head *bh) {
|
||||
bh->b_end_io = end_buffer_io_async ;
|
||||
+ mark_buffer_async(bh, 1);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1553,7 +1555,7 @@
|
||||
/* Stage 2: lock the buffers, mark them clean */
|
||||
do {
|
||||
lock_buffer(bh);
|
||||
- bh->b_end_io = end_buffer_io_async;
|
||||
+ set_buffer_async_io(bh);
|
||||
get_bh(bh);
|
||||
set_bit(BH_Uptodate, &bh->b_state);
|
||||
clear_bit(BH_Dirty, &bh->b_state);
|
||||
@@ -1755,7 +1757,7 @@
|
||||
for (i = 0; i < nr; i++) {
|
||||
struct buffer_head * bh = arr[i];
|
||||
lock_buffer(bh);
|
||||
- bh->b_end_io = end_buffer_io_async;
|
||||
+ set_buffer_async_io(bh);
|
||||
get_bh(bh);
|
||||
}
|
||||
|
||||
@@ -2200,7 +2202,7 @@
|
||||
lock_buffer(bh);
|
||||
bh->b_blocknr = *(b++);
|
||||
set_bit(BH_Mapped, &bh->b_state);
|
||||
- bh->b_end_io = end_buffer_io_async;
|
||||
+ set_buffer_async_io(bh);
|
||||
get_bh(bh);
|
||||
bh = bh->b_this_page;
|
||||
} while (bh != head);
|
||||
diff -urN 2.4.7pre6/include/linux/fs.h bh_async/include/linux/fs.h
|
||||
--- 2.4.7pre6/include/linux/fs.h Wed Jul 11 06:03:19 2001
|
||||
+++ bh_async/include/linux/fs.h Thu Jul 12 07:54:26 2001
|
||||
@@ -215,6 +215,7 @@
|
||||
BH_New, /* 1 if the buffer is new and not yet written out */
|
||||
BH_Protected, /* 1 if the buffer is protected */
|
||||
BH_JBD, /* 1 if it has an attached journal_head */
|
||||
+ BH_Async, /* 1 if the buffer is under end_buffer_io_async I/O */
|
||||
|
||||
BH_PrivateStart,/* not a state bit, but the first bit available
|
||||
* for private allocation by other entities
|
||||
@@ -275,6 +276,7 @@
|
||||
#define buffer_mapped(bh) __buffer_state(bh,Mapped)
|
||||
#define buffer_new(bh) __buffer_state(bh,New)
|
||||
#define buffer_protected(bh) __buffer_state(bh,Protected)
|
||||
+#define buffer_async(bh) __buffer_state(bh,Async)
|
||||
|
||||
#define bh_offset(bh) ((unsigned long)(bh)->b_data & ~PAGE_MASK)
|
||||
|
||||
@@ -1110,6 +1112,14 @@
|
||||
extern void FASTCALL(mark_buffer_dirty(struct buffer_head *bh));
|
||||
|
||||
#define atomic_set_buffer_dirty(bh) test_and_set_bit(BH_Dirty, &(bh)->b_state)
|
||||
+
|
||||
+static inline void mark_buffer_async(struct buffer_head * bh, int on)
|
||||
+{
|
||||
+ if (on)
|
||||
+ set_bit(BH_Async, &bh->b_state);
|
||||
+ else
|
||||
+ clear_bit(BH_Async, &bh->b_state);
|
||||
+}
|
||||
|
||||
/*
|
||||
* If an error happens during the make_request, this function
|
||||
@@ -1,10 +0,0 @@
|
||||
--- linux-2.4.9-ac5/drivers/md/Config.in Sun Mar 11 13:33:24 2001
|
||||
+++ linux/drivers/md/Config.in Thu Sep 13 18:02:17 2001
|
||||
@@ -13,5 +13,7 @@
|
||||
dep_tristate ' RAID-4/RAID-5 mode' CONFIG_MD_RAID5 $CONFIG_BLK_DEV_MD
|
||||
|
||||
dep_tristate ' Logical volume manager (LVM) support' CONFIG_BLK_DEV_LVM $CONFIG_MD
|
||||
+dep_tristate ' Device mapper support' CONFIG_BLK_DEV_DM $CONFIG_MD
|
||||
+dep_tristate ' Device mapper linear target' CONFIG_BLK_DEV_DM_LINEAR $CONFIG_BLK_DEV_DM
|
||||
|
||||
endmenu
|
||||
@@ -1,13 +0,0 @@
|
||||
--- uml_build/arch/um/config.in.orig Tue Jan 2 14:33:42 2001
|
||||
+++ uml_build/arch/um/config.in Tue Jan 2 14:35:42 2001
|
||||
@@ -15,6 +15,8 @@
|
||||
bool 'Prompt for development and/or incomplete code/drivers' CONFIG_EXPERIMENTAL
|
||||
endmenu
|
||||
|
||||
+source drivers/md/Config.in
|
||||
+
|
||||
mainmenu_option next_comment
|
||||
comment 'Processor features'
|
||||
bool 'Symmetric multi-processing support' CONFIG_SMP
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,25 +0,0 @@
|
||||
--- linux-2.4.9-ac5/drivers/md/Makefile Sat Sep 1 16:24:46 2001
|
||||
+++ linux/drivers/md/Makefile Fri Sep 14 09:12:39 2001
|
||||
@@ -7,6 +7,7 @@
|
||||
export-objs := md.o xor.o
|
||||
list-multi := lvm-mod.o
|
||||
lvm-mod-objs := lvm.o lvm-snap.o lvm-fs.o
|
||||
+dm-mod-objs := dm.o dm-table.o dm-target.o dm-fs.o dm-parse.o dm-blkdev.o
|
||||
|
||||
# Note: link order is important. All raid personalities
|
||||
# and xor.o must come before md.o, as they each initialise
|
||||
@@ -19,8 +20,14 @@
|
||||
obj-$(CONFIG_MD_RAID5) += raid5.o xor.o
|
||||
obj-$(CONFIG_BLK_DEV_MD) += md.o
|
||||
obj-$(CONFIG_BLK_DEV_LVM) += lvm-mod.o
|
||||
+obj-$(CONFIG_BLK_DEV_DM) += dm-mod.o
|
||||
+obj-$(CONFIG_BLK_DEV_DM_LINEAR) += dm-linear.o
|
||||
|
||||
include $(TOPDIR)/Rules.make
|
||||
|
||||
lvm-mod.o: $(lvm-mod-objs)
|
||||
$(LD) -r -o $@ $(lvm-mod-objs)
|
||||
+
|
||||
+dm-mod.o: $(dm-mod-objs)
|
||||
+ $(LD) -r -o $@ $(dm-mod-objs)
|
||||
+
|
||||
@@ -1,13 +0,0 @@
|
||||
00_latest Latest source - I only tend to update this before
|
||||
making a release. So if you got this from CVS copy
|
||||
or link the source files in by hand.
|
||||
|
||||
00_config Add device-mapper to the MD section
|
||||
|
||||
00_config_uml only apply for uml, turns on the md section
|
||||
|
||||
00_makefile Add device-mapper to the MD Makefile.
|
||||
|
||||
00_bh-async-3 AA's async bh patch so we can hook b_end_io
|
||||
to keep track of pending io.
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
FILES
|
||||
-----
|
||||
|
||||
setup-uml - script to build a user mode linux system, with the lvm driver
|
||||
symbolically linked back to the LVM dir so I can work from CVS.
|
||||
|
||||
uml-lvm.patch - patch to enable lvm in the uml configuration
|
||||
|
||||
uml.patch.bz2 - uml patch from
|
||||
http://sourceforge.net/project/showfiles.php?group_id=429
|
||||
|
||||
config-uml - .config which turns on LVM
|
||||
|
||||
|
||||
RUNNING
|
||||
-------
|
||||
|
||||
o checkout an LVM dir for use with uml
|
||||
make sure you've got a copy of a root filesystem kicking about
|
||||
|
||||
o edit the variables at the top of 'setup'
|
||||
|
||||
o run setup-uml
|
||||
|
||||
o move to your uml dir and run lvm-install as root
|
||||
|
||||
o then run the 'up' script to run uml
|
||||
|
||||
o if you want to rebuild uml after changing the LVM driver just change into
|
||||
the linux directory and do a 'make linux ARCH=um'. Don't forget the ARCH=um.
|
||||
@@ -1,299 +0,0 @@
|
||||
#
|
||||
# Automatically generated by make menuconfig: don't edit
|
||||
#
|
||||
CONFIG_USERMODE=y
|
||||
# CONFIG_ISA is not set
|
||||
# CONFIG_SBUS is not set
|
||||
# CONFIG_PCI is not set
|
||||
CONFIG_UID16=y
|
||||
CONFIG_RWSEM_XCHGADD_ALGORITHM=y
|
||||
|
||||
#
|
||||
# Code maturity level options
|
||||
#
|
||||
CONFIG_EXPERIMENTAL=y
|
||||
|
||||
#
|
||||
# Multi-device support (RAID and LVM)
|
||||
#
|
||||
CONFIG_MD=y
|
||||
# CONFIG_BLK_DEV_MD is not set
|
||||
# CONFIG_MD_LINEAR is not set
|
||||
# CONFIG_MD_RAID0 is not set
|
||||
# CONFIG_MD_RAID1 is not set
|
||||
# CONFIG_MD_RAID5 is not set
|
||||
# CONFIG_BLK_DEV_LVM is not set
|
||||
CONFIG_BLK_DEV_DM=y
|
||||
|
||||
#
|
||||
# General Setup
|
||||
#
|
||||
CONFIG_STDIO_CONSOLE=y
|
||||
CONFIG_NET=y
|
||||
CONFIG_SYSVIPC=y
|
||||
CONFIG_BSD_PROCESS_ACCT=y
|
||||
CONFIG_SYSCTL=y
|
||||
CONFIG_BINFMT_AOUT=y
|
||||
CONFIG_BINFMT_ELF=y
|
||||
CONFIG_BINFMT_MISC=y
|
||||
CONFIG_UNIX98_PTYS=y
|
||||
CONFIG_UNIX98_PTY_COUNT=256
|
||||
CONFIG_SSL=y
|
||||
CONFIG_HOSTFS=m
|
||||
CONFIG_MCONSOLE=y
|
||||
CONFIG_MAGIC_SYSRQ=y
|
||||
|
||||
#
|
||||
# Loadable module support
|
||||
#
|
||||
CONFIG_MODULES=y
|
||||
# CONFIG_KMOD is not set
|
||||
|
||||
#
|
||||
# Devices
|
||||
#
|
||||
CONFIG_BLK_DEV_UBD=y
|
||||
# CONFIG_BLK_DEV_UBD_SYNC is not set
|
||||
CONFIG_BLK_DEV_LOOP=y
|
||||
CONFIG_BLK_DEV_NBD=y
|
||||
CONFIG_BLK_DEV_RAM=y
|
||||
CONFIG_BLK_DEV_RAM_SIZE=4096
|
||||
CONFIG_BLK_DEV_INITRD=y
|
||||
# CONFIG_MMAPPER is not set
|
||||
|
||||
#
|
||||
# Networking options
|
||||
#
|
||||
# CONFIG_PACKET is not set
|
||||
CONFIG_NETLINK=y
|
||||
# CONFIG_RTNETLINK is not set
|
||||
# CONFIG_NETLINK_DEV is not set
|
||||
# CONFIG_NETFILTER is not set
|
||||
# CONFIG_FILTER is not set
|
||||
CONFIG_UNIX=y
|
||||
CONFIG_INET=y
|
||||
# CONFIG_IP_MULTICAST is not set
|
||||
# CONFIG_IP_ADVANCED_ROUTER is not set
|
||||
# CONFIG_IP_PNP is not set
|
||||
# CONFIG_NET_IPIP is not set
|
||||
# CONFIG_NET_IPGRE is not set
|
||||
# CONFIG_INET_ECN is not set
|
||||
# CONFIG_SYN_COOKIES is not set
|
||||
# CONFIG_IPV6 is not set
|
||||
# CONFIG_KHTTPD is not set
|
||||
# CONFIG_ATM is not set
|
||||
# CONFIG_IPX is not set
|
||||
# CONFIG_ATALK is not set
|
||||
# CONFIG_DECNET is not set
|
||||
# CONFIG_BRIDGE is not set
|
||||
# CONFIG_X25 is not set
|
||||
# CONFIG_LAPB is not set
|
||||
# CONFIG_LLC is not set
|
||||
# CONFIG_NET_DIVERT is not set
|
||||
# CONFIG_ECONET is not set
|
||||
# CONFIG_WAN_ROUTER is not set
|
||||
# CONFIG_NET_FASTROUTE is not set
|
||||
# CONFIG_NET_HW_FLOWCONTROL is not set
|
||||
|
||||
#
|
||||
# QoS and/or fair queueing
|
||||
#
|
||||
# CONFIG_NET_SCHED is not set
|
||||
|
||||
#
|
||||
# Network drivers
|
||||
#
|
||||
|
||||
#
|
||||
# ARCnet devices
|
||||
#
|
||||
# CONFIG_ARCNET is not set
|
||||
CONFIG_DUMMY=y
|
||||
# CONFIG_BONDING is not set
|
||||
# CONFIG_EQUALIZER is not set
|
||||
CONFIG_TUN=y
|
||||
CONFIG_ETHERTAP=y
|
||||
|
||||
#
|
||||
# Ethernet (10 or 100Mbit)
|
||||
#
|
||||
# CONFIG_NET_ETHERNET is not set
|
||||
|
||||
#
|
||||
# Ethernet (1000 Mbit)
|
||||
#
|
||||
# CONFIG_ACENIC is not set
|
||||
# CONFIG_ACENIC_OMIT_TIGON_I is not set
|
||||
# CONFIG_DL2K is not set
|
||||
# CONFIG_MYRI_SBUS is not set
|
||||
# CONFIG_HAMACHI is not set
|
||||
# CONFIG_YELLOWFIN is not set
|
||||
# CONFIG_SK98LIN is not set
|
||||
# CONFIG_FDDI is not set
|
||||
# CONFIG_HIPPI is not set
|
||||
# CONFIG_PLIP is not set
|
||||
CONFIG_PPP=y
|
||||
# CONFIG_PPP_MULTILINK is not set
|
||||
# CONFIG_PPP_FILTER is not set
|
||||
# CONFIG_PPP_ASYNC is not set
|
||||
# CONFIG_PPP_SYNC_TTY is not set
|
||||
# CONFIG_PPP_DEFLATE is not set
|
||||
# CONFIG_PPP_BSDCOMP is not set
|
||||
# CONFIG_PPPOE is not set
|
||||
CONFIG_SLIP=y
|
||||
# CONFIG_SLIP_COMPRESSED is not set
|
||||
# CONFIG_SLIP_SMART is not set
|
||||
# CONFIG_SLIP_MODE_SLIP6 is not set
|
||||
|
||||
#
|
||||
# Wireless LAN (non-hamradio)
|
||||
#
|
||||
# CONFIG_NET_RADIO is not set
|
||||
|
||||
#
|
||||
# Token Ring devices
|
||||
#
|
||||
# CONFIG_TR is not set
|
||||
# CONFIG_NET_FC is not set
|
||||
# CONFIG_RCPCI is not set
|
||||
# CONFIG_SHAPER is not set
|
||||
|
||||
#
|
||||
# Wan interfaces
|
||||
#
|
||||
# CONFIG_WAN is not set
|
||||
|
||||
#
|
||||
# Network device support
|
||||
#
|
||||
CONFIG_NETDEVICES=y
|
||||
CONFIG_UML_NET=y
|
||||
CONFIG_UML_NET_ETHERTAP=y
|
||||
CONFIG_UML_NET_SLIP=y
|
||||
CONFIG_UML_NET_DAEMON=y
|
||||
CONFIG_UML_NET_MCAST=y
|
||||
CONFIG_ETHERTAP=y
|
||||
CONFIG_TUN=y
|
||||
|
||||
#
|
||||
# File systems
|
||||
#
|
||||
CONFIG_QUOTA=y
|
||||
CONFIG_AUTOFS_FS=m
|
||||
CONFIG_AUTOFS4_FS=m
|
||||
CONFIG_REISERFS_FS=m
|
||||
# CONFIG_REISERFS_CHECK is not set
|
||||
# CONFIG_ADFS_FS is not set
|
||||
# CONFIG_ADFS_FS_RW is not set
|
||||
# CONFIG_AFFS_FS is not set
|
||||
# CONFIG_HFS_FS is not set
|
||||
# CONFIG_BFS_FS is not set
|
||||
CONFIG_FAT_FS=m
|
||||
CONFIG_MSDOS_FS=m
|
||||
CONFIG_UMSDOS_FS=m
|
||||
CONFIG_VFAT_FS=m
|
||||
# CONFIG_EFS_FS is not set
|
||||
# CONFIG_JFFS_FS is not set
|
||||
# CONFIG_CRAMFS is not set
|
||||
# CONFIG_TMPFS is not set
|
||||
# CONFIG_RAMFS is not set
|
||||
CONFIG_ISO9660_FS=m
|
||||
# CONFIG_JOLIET is not set
|
||||
CONFIG_MINIX_FS=m
|
||||
# CONFIG_VXFS_FS is not set
|
||||
# CONFIG_NTFS_FS is not set
|
||||
# CONFIG_NTFS_RW is not set
|
||||
# CONFIG_HPFS_FS is not set
|
||||
CONFIG_PROC_FS=y
|
||||
CONFIG_DEVFS_FS=y
|
||||
CONFIG_DEVFS_MOUNT=y
|
||||
# CONFIG_DEVFS_DEBUG is not set
|
||||
CONFIG_DEVPTS_FS=y
|
||||
# CONFIG_QNX4FS_FS is not set
|
||||
# CONFIG_QNX4FS_RW is not set
|
||||
# CONFIG_ROMFS_FS is not set
|
||||
CONFIG_EXT2_FS=y
|
||||
# CONFIG_SYSV_FS is not set
|
||||
# CONFIG_UDF_FS is not set
|
||||
# CONFIG_UDF_RW is not set
|
||||
# CONFIG_UFS_FS is not set
|
||||
# CONFIG_UFS_FS_WRITE is not set
|
||||
|
||||
#
|
||||
# Network File Systems
|
||||
#
|
||||
# CONFIG_CODA_FS is not set
|
||||
# CONFIG_NFS_FS is not set
|
||||
# CONFIG_NFS_V3 is not set
|
||||
# CONFIG_ROOT_NFS is not set
|
||||
# CONFIG_NFSD is not set
|
||||
# CONFIG_NFSD_V3 is not set
|
||||
# CONFIG_SUNRPC is not set
|
||||
# CONFIG_LOCKD is not set
|
||||
# CONFIG_SMB_FS is not set
|
||||
# CONFIG_NCP_FS is not set
|
||||
# CONFIG_NCPFS_PACKET_SIGNING is not set
|
||||
# CONFIG_NCPFS_IOCTL_LOCKING is not set
|
||||
# CONFIG_NCPFS_STRONG is not set
|
||||
# CONFIG_NCPFS_NFS_NS is not set
|
||||
# CONFIG_NCPFS_OS2_NS is not set
|
||||
# CONFIG_NCPFS_SMALLDOS is not set
|
||||
# CONFIG_NCPFS_NLS is not set
|
||||
# CONFIG_NCPFS_EXTRAS is not set
|
||||
|
||||
#
|
||||
# Partition Types
|
||||
#
|
||||
# CONFIG_PARTITION_ADVANCED is not set
|
||||
CONFIG_MSDOS_PARTITION=y
|
||||
# CONFIG_SMB_NLS is not set
|
||||
CONFIG_NLS=y
|
||||
|
||||
#
|
||||
# Native Language Support
|
||||
#
|
||||
CONFIG_NLS_DEFAULT="iso8859-1"
|
||||
# CONFIG_NLS_CODEPAGE_437 is not set
|
||||
# CONFIG_NLS_CODEPAGE_737 is not set
|
||||
# CONFIG_NLS_CODEPAGE_775 is not set
|
||||
# CONFIG_NLS_CODEPAGE_850 is not set
|
||||
# CONFIG_NLS_CODEPAGE_852 is not set
|
||||
# CONFIG_NLS_CODEPAGE_855 is not set
|
||||
# CONFIG_NLS_CODEPAGE_857 is not set
|
||||
# CONFIG_NLS_CODEPAGE_860 is not set
|
||||
# CONFIG_NLS_CODEPAGE_861 is not set
|
||||
# CONFIG_NLS_CODEPAGE_862 is not set
|
||||
# CONFIG_NLS_CODEPAGE_863 is not set
|
||||
# CONFIG_NLS_CODEPAGE_864 is not set
|
||||
# CONFIG_NLS_CODEPAGE_865 is not set
|
||||
# CONFIG_NLS_CODEPAGE_866 is not set
|
||||
# CONFIG_NLS_CODEPAGE_869 is not set
|
||||
# CONFIG_NLS_CODEPAGE_936 is not set
|
||||
# CONFIG_NLS_CODEPAGE_950 is not set
|
||||
# CONFIG_NLS_CODEPAGE_932 is not set
|
||||
# CONFIG_NLS_CODEPAGE_949 is not set
|
||||
# CONFIG_NLS_CODEPAGE_874 is not set
|
||||
# CONFIG_NLS_ISO8859_8 is not set
|
||||
# CONFIG_NLS_CODEPAGE_1251 is not set
|
||||
# CONFIG_NLS_ISO8859_1 is not set
|
||||
# CONFIG_NLS_ISO8859_2 is not set
|
||||
# CONFIG_NLS_ISO8859_3 is not set
|
||||
# CONFIG_NLS_ISO8859_4 is not set
|
||||
# CONFIG_NLS_ISO8859_5 is not set
|
||||
# CONFIG_NLS_ISO8859_6 is not set
|
||||
# CONFIG_NLS_ISO8859_7 is not set
|
||||
# CONFIG_NLS_ISO8859_9 is not set
|
||||
# CONFIG_NLS_ISO8859_13 is not set
|
||||
# CONFIG_NLS_ISO8859_14 is not set
|
||||
# CONFIG_NLS_ISO8859_15 is not set
|
||||
# CONFIG_NLS_KOI8_R is not set
|
||||
# CONFIG_NLS_KOI8_U is not set
|
||||
# CONFIG_NLS_UTF8 is not set
|
||||
|
||||
#
|
||||
# Kernel hacking
|
||||
#
|
||||
CONFIG_DEBUGSYM=y
|
||||
CONFIG_PT_PROXY=y
|
||||
# CONFIG_GPROF is not set
|
||||
# CONFIG_GCOV is not set
|
||||
@@ -1,179 +0,0 @@
|
||||
#! /usr/bin/perl -w
|
||||
|
||||
use Cwd;
|
||||
|
||||
##############################
|
||||
# Start user configurable bit
|
||||
##############################
|
||||
|
||||
# Please use absolute paths too.
|
||||
# you can't use ~'s in your paths here.
|
||||
|
||||
# the directory where you've checked out lvm, keep a seperate copy for uml,
|
||||
# the uml kernel will have links to these files
|
||||
$lvm_src="/home/thornber/sistina/LVM2";
|
||||
|
||||
|
||||
# the debian root image, get it from here:
|
||||
# http://prdownloads.sourceforge.net/user-mode-linux/root_fs_debian2.2_small.bz2
|
||||
# unzip it once you've downloaded it
|
||||
$root_fs="/home/thornber/uml/root_fs_debian2.2_small";
|
||||
|
||||
# these are 100 Meg files created with dd
|
||||
# these become our PV's /dev/ubd/[1-4]
|
||||
# I sometimes use ubd/1 as swap though.
|
||||
@block_devices = ("/home/thornber/uml/scratch1",
|
||||
"/home/thornber/uml/scratch2",
|
||||
"/home/thornber/uml/scratch3",
|
||||
"/home/thornber/uml/scratch4");
|
||||
|
||||
# directory where uml will be built, and the up, lvm-install scripts will
|
||||
# be placed
|
||||
$dest_dir="/home/thornber/builds/uml-lvm2";
|
||||
|
||||
# It must be 2.4.8, can be .gz or .bz2
|
||||
$kernel_tarball="/home/thornber/packages/2.4/linux-2.4.9.tar";
|
||||
|
||||
###############################
|
||||
# end of user configurable bit
|
||||
###############################
|
||||
|
||||
|
||||
$wd = cwd;
|
||||
$uml_patch = $wd . "/uml.patch.bz2";
|
||||
$lvm_uml_patch = $wd . "/uml-lvm.patch";
|
||||
$driver = $lvm_src . "/driver/device-mapper";
|
||||
|
||||
|
||||
# check we've got everything we need
|
||||
&check_file($root_fs);
|
||||
&check_dir($lvm_src);
|
||||
&check_file($kernel_tarball);
|
||||
&check_dir($dest_dir);
|
||||
&check_file($uml_patch);
|
||||
&check_file($lvm_uml_patch);
|
||||
|
||||
|
||||
chdir($dest_dir);
|
||||
&extract_kernel($dest_dir, $kernel_tarball);
|
||||
chdir("linux");
|
||||
&run_command("bzip2 -dc $uml_patch | patch -p1", "patching kernel with uml");
|
||||
&run_command("patch -p1 < $lvm_uml_patch", "enabling LVM driver");
|
||||
|
||||
chdir("$dest_dir/linux");
|
||||
|
||||
&run_command("cd include/linux; ln -s $driver/device-mapper.h",
|
||||
"linking device-mapper.h");
|
||||
|
||||
&run_command("cd drivers/md; ln -s $driver/dm.h", "linking dm.h");
|
||||
&run_command("cd drivers/md; ln -s $driver/dm-fs.c", "linking dm-fs.c");
|
||||
&run_command("cd drivers/md; ln -s $driver/dm-table.c", "linking dm-table.c");
|
||||
&run_command("cd drivers/md; ln -s $driver/dm-target.c",
|
||||
"linking dm-target.c");
|
||||
&run_command("cd drivers/md; ln -s $driver/dm.c", "linking dm.c");
|
||||
|
||||
chdir("$dest_dir/linux");
|
||||
&run_command("make oldconfig ARCH=um", "making oldconfig ARCH=um");
|
||||
&run_command("make dep ARCH=um", "making dependencies");
|
||||
&run_command("make linux ARCH=um", "building linux uml");
|
||||
|
||||
chdir($dest_dir);
|
||||
&run_command("ln -s $dest_dir/linux/linux uml", "creating link for linux");
|
||||
|
||||
chdir($dest_dir);
|
||||
&run_command("ln -s $root_fs ./root_fs", "linking root filesystem");
|
||||
|
||||
chdir($dest_dir);
|
||||
&link_devices();
|
||||
&write_up();
|
||||
&run_command("mkdir root_fs_mnt");
|
||||
&write_lvm_install();
|
||||
|
||||
print "Dont forget to run $dest_dir/lvm-install as root\n";
|
||||
|
||||
|
||||
sub write_lvm_install {
|
||||
open(OUT, "> lvm-install");
|
||||
print OUT "#! /bin/sh\n\n";
|
||||
print OUT <<"end";
|
||||
mount root_fs root_fs_mnt -o loop
|
||||
cd $lvm_src; make install; cd $dest_dir
|
||||
umount root_fs_mnt
|
||||
end
|
||||
|
||||
close OUT;
|
||||
system "chmod +x lvm-install";
|
||||
}
|
||||
|
||||
|
||||
sub write_up {
|
||||
open(UP, "> up");
|
||||
print UP "#! /bin/sh\n\n./uml ";
|
||||
$count = 1;
|
||||
for $d (@block_devices) {
|
||||
print UP "ubd$count=ubd$count ";
|
||||
$count++;
|
||||
}
|
||||
print UP "\n";
|
||||
close UP;
|
||||
system("chmod +x up");
|
||||
}
|
||||
|
||||
sub link_devices {
|
||||
$count = 1;
|
||||
foreach $d (@block_devices) {
|
||||
&run_command("ln -s $d ubd$count",
|
||||
"linking block device ubd$count");
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
|
||||
sub extract_kernel {
|
||||
my($dest, $tb) = @_;
|
||||
my($cmd);
|
||||
if($tb =~ m/\.bz2/) {
|
||||
$cmd = "tar Ixf $tb";
|
||||
|
||||
} elsif($tb =~ m/\.gz/) {
|
||||
$cmd = "tar zxf $tb";
|
||||
|
||||
} else {
|
||||
$cmd = "tar xf $tb";
|
||||
}
|
||||
|
||||
&run_command($cmd, "extracting kernel");
|
||||
}
|
||||
|
||||
sub run_command {
|
||||
my($cmd) = shift;
|
||||
my($desc) = shift;
|
||||
my($r);
|
||||
print STDERR $desc, " ... ";
|
||||
$r = system("$cmd > /dev/null");
|
||||
if(!$r) {
|
||||
print STDERR "done.\n";
|
||||
return;
|
||||
} else {
|
||||
print STDERR "failed.\n";
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
sub check_file {
|
||||
$f = shift;
|
||||
if(! -e $f) {
|
||||
print STDERR "couldn't find $f\n";
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
sub check_dir {
|
||||
$f = shift;
|
||||
if(! -e $f || ! -d $f) {
|
||||
print STDERR "couldn't find a directory called $f\n";
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
--- uml_build/arch/um/config.in.orig Tue Jan 2 14:33:42 2001
|
||||
+++ uml_build/arch/um/config.in Tue Jan 2 14:35:42 2001
|
||||
@@ -15,6 +15,8 @@
|
||||
bool 'Prompt for development and/or incomplete code/drivers' CONFIG_EXPERIMENTAL
|
||||
endmenu
|
||||
|
||||
+source drivers/md/Config.in
|
||||
+
|
||||
mainmenu_option next_comment
|
||||
comment 'Processor features'
|
||||
bool 'Symmetric multi-processing support' CONFIG_SMP
|
||||
--- linux/drivers/md/Config.in.orig Tue Aug 21 14:18:30 2001
|
||||
+++ linux/drivers/md/Config.in Tue Aug 21 14:19:08 2001
|
||||
@@ -14,4 +14,6 @@
|
||||
|
||||
dep_tristate ' Logical volume manager (LVM) support' CONFIG_BLK_DEV_LVM $CONFIG_MD
|
||||
|
||||
+dep_tristate ' Device mapper support' CONFIG_BLK_DEV_DM $CONFIG_MD
|
||||
+
|
||||
endmenu
|
||||
--- linux/drivers/md/Makefile.orig Tue Aug 21 14:19:14 2001
|
||||
+++ linux/drivers/md/Makefile Tue Aug 21 14:20:06 2001
|
||||
@@ -19,6 +19,7 @@
|
||||
obj-$(CONFIG_MD_RAID5) += raid5.o xor.o
|
||||
obj-$(CONFIG_BLK_DEV_MD) += md.o
|
||||
obj-$(CONFIG_BLK_DEV_LVM) += lvm-mod.o
|
||||
+obj-$(CONFIG_BLK_DEV_DM) += dm.o dm-table.o dm-target.o dm-fs.o dm-parse.o
|
||||
|
||||
include $(TOPDIR)/Rules.make
|
||||
|
||||
Binary file not shown.
@@ -1,16 +1,29 @@
|
||||
../lib/activate/activate.h
|
||||
../lib/config/config.h
|
||||
../lib/datastruct/bitset.h
|
||||
../lib/datastruct/btree.h
|
||||
../lib/datastruct/hash.h
|
||||
../lib/datastruct/list.h
|
||||
../lib/datastruct/lvm-types.h
|
||||
../lib/device/dev-cache.h
|
||||
../lib/device/device.h
|
||||
../lib/display/display.h
|
||||
../lib/filters/filter-composite.h
|
||||
../lib/filters/filter-persistent.h
|
||||
../lib/filters/filter-regex.h
|
||||
../lib/filters/filter.h
|
||||
../lib/format1/format1.h
|
||||
../lib/format1/lvm1_label.h
|
||||
../lib/format_text/format-text.h
|
||||
../lib/label/label.h
|
||||
../lib/label/uuid-map.h
|
||||
../lib/log/log.h
|
||||
../lib/metadata/metadata.h
|
||||
../lib/mm/dbg_malloc.h
|
||||
../lib/mm/pool.h
|
||||
../lib/mm/xlate.h
|
||||
../lib/misc/lvm-file.h
|
||||
../lib/misc/lvm-string.h
|
||||
../lib/regex/matcher.h
|
||||
../lib/uuid/uuid.h
|
||||
../lib/vgcache/vgcache.h
|
||||
|
||||
@@ -31,11 +31,13 @@ all: .symlinks_created
|
||||
for i in `cat .symlinks`; do $(LN_S) $$i ; done
|
||||
touch $@
|
||||
|
||||
clean:
|
||||
|
||||
distclean:
|
||||
find . -maxdepth 1 -type l -exec $(RM) \{\} \;
|
||||
$(RM) Makefile .include_symlinks .symlinks_created
|
||||
|
||||
.PHONY: clean distclean all
|
||||
clean:
|
||||
|
||||
install:
|
||||
|
||||
.PHONY: clean distclean all install
|
||||
|
||||
|
||||
@@ -10,23 +10,47 @@ VPATH = @srcdir@
|
||||
|
||||
SOURCES=\
|
||||
activate/activate.c \
|
||||
activate/fs.c \
|
||||
activate/names.c \
|
||||
config/config.c \
|
||||
datastruct/bitset.c \
|
||||
datastruct/btree.c \
|
||||
datastruct/hash.c \
|
||||
device/dev-cache.c \
|
||||
device/dev-io.c \
|
||||
device/device.c \
|
||||
display/display.c \
|
||||
filters/filter-composite.c \
|
||||
filters/filter-persistent.c \
|
||||
filters/filter-regex.c \
|
||||
filters/filter.c \
|
||||
format1/disk-rep.c \
|
||||
format1/format1.c \
|
||||
format1/import-export.c \
|
||||
format1/import-extents.c \
|
||||
format1/layout.c \
|
||||
format1/lvm1_label.c \
|
||||
format1/vg_number.c \
|
||||
format_text/archive.c \
|
||||
format_text/export.c \
|
||||
format_text/flags.c \
|
||||
format_text/format-text.c \
|
||||
format_text/import.c \
|
||||
label/label.c \
|
||||
label/uuid-map.c \
|
||||
log/log.c \
|
||||
metadata/lv_manip.c \
|
||||
metadata/merge.c \
|
||||
metadata/metadata.c \
|
||||
metadata/pv_map.c \
|
||||
misc/lvm-file.c \
|
||||
mm/dbg_malloc.c \
|
||||
mm/pool.c \
|
||||
uuid/uuid.c
|
||||
regex/matcher.c \
|
||||
regex/parse_rx.c \
|
||||
regex/ttree.c \
|
||||
uuid/uuid.c \
|
||||
vgcache/vgcache.c
|
||||
|
||||
TARGETS=liblvm.a
|
||||
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
Base library directory
|
||||
@@ -1,35 +1,452 @@
|
||||
/*
|
||||
* Copyright (C) 2001 Sistina Software (UK) Limited.
|
||||
*
|
||||
* This file is released under the GPL.
|
||||
* This file is released under the LGPL.
|
||||
*/
|
||||
|
||||
#include "metadata.h"
|
||||
#include "activate.h"
|
||||
#include "display.h"
|
||||
#include "log.h"
|
||||
#include "fs.h"
|
||||
#include "lvm-string.h"
|
||||
#include "names.h"
|
||||
|
||||
int lv_activate(struct volume_group *vg, struct logical_volume *lv)
|
||||
#include <limits.h>
|
||||
|
||||
|
||||
int library_version(char *version, size_t size)
|
||||
{
|
||||
return 0;
|
||||
if (!dm_get_library_version(version, size))
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int lv_deactivate(struct volume_group *vg, struct logical_volume *lv)
|
||||
static struct dm_task *_setup_task_with_name(struct logical_volume *lv,
|
||||
const char *lv_name,
|
||||
int task)
|
||||
{
|
||||
return 0;
|
||||
char name[128];
|
||||
struct dm_task *dmt;
|
||||
|
||||
if (!(dmt = dm_task_create(task))) {
|
||||
stack;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!build_dm_name(name, sizeof(name), lv->vg->name, lv_name)) {
|
||||
stack;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dm_task_set_name(dmt, name);
|
||||
|
||||
return dmt;
|
||||
}
|
||||
|
||||
int lvs_in_vg_activated(struct volume_group *vg)
|
||||
static struct dm_task *_setup_task(struct logical_volume *lv, int task)
|
||||
{
|
||||
return 0;
|
||||
return _setup_task_with_name(lv, lv->name, task);
|
||||
}
|
||||
|
||||
int driver_version(char *version, size_t size)
|
||||
{
|
||||
int r = 0;
|
||||
struct dm_task *dmt;
|
||||
|
||||
log_very_verbose("Getting driver version");
|
||||
if (!(dmt = dm_task_create(DM_DEVICE_VERSION))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!dm_task_run(dmt))
|
||||
log_error("Failed to get driver version");
|
||||
|
||||
if (!dm_task_get_driver_version(dmt, version, size))
|
||||
goto out;
|
||||
|
||||
r = 1;
|
||||
|
||||
out:
|
||||
dm_task_destroy(dmt);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
int lv_info(struct logical_volume *lv, struct dm_info *info)
|
||||
{
|
||||
int r = 0;
|
||||
struct dm_task *dmt;
|
||||
|
||||
log_very_verbose("Getting device info for %s", lv->name);
|
||||
if (!(dmt = _setup_task(lv, DM_DEVICE_INFO))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!dm_task_run(dmt)) {
|
||||
stack;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!dm_task_get_info(dmt, info)) {
|
||||
stack;
|
||||
goto out;
|
||||
}
|
||||
r = 1;
|
||||
|
||||
out:
|
||||
dm_task_destroy(dmt);
|
||||
return r;
|
||||
}
|
||||
|
||||
int lv_rename(const char *old_name, struct logical_volume *lv)
|
||||
{
|
||||
int r = 0;
|
||||
char new_name[PATH_MAX];
|
||||
struct dm_task *dmt;
|
||||
|
||||
if (test_mode())
|
||||
return 0;
|
||||
|
||||
if (!(dmt = _setup_task_with_name(lv, old_name, DM_DEVICE_RENAME))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!build_dm_name(new_name, sizeof(new_name),
|
||||
lv->vg->name, lv->name)) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!dm_task_set_newname(dmt, new_name)) {
|
||||
stack;
|
||||
r = 0;
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!dm_task_run(dmt)) {
|
||||
stack;
|
||||
r = 0;
|
||||
goto end;
|
||||
}
|
||||
|
||||
fs_rename_lv(old_name, lv);
|
||||
|
||||
end:
|
||||
dm_task_destroy(dmt);
|
||||
return r;
|
||||
}
|
||||
|
||||
int lv_active(struct logical_volume *lv)
|
||||
{
|
||||
int r = -1;
|
||||
struct dm_info info;
|
||||
|
||||
if (!lv_info(lv, &info)) {
|
||||
stack;
|
||||
return r;
|
||||
}
|
||||
|
||||
log_very_verbose("%s is%s active", lv->name, info.exists ? "":" not");
|
||||
return info.exists;
|
||||
}
|
||||
|
||||
int lv_suspended(struct logical_volume *lv)
|
||||
{
|
||||
int r = -1;
|
||||
struct dm_info info;
|
||||
|
||||
if (!lv_info(lv, &info)) {
|
||||
stack;
|
||||
return r;
|
||||
}
|
||||
|
||||
log_very_verbose("%s is%s suspended", lv->name,
|
||||
info.suspended ? "":" not");
|
||||
return info.suspended;
|
||||
}
|
||||
|
||||
int lv_open_count(struct logical_volume *lv)
|
||||
{
|
||||
int r = -1;
|
||||
struct dm_info info;
|
||||
|
||||
if (!lv_info(lv, &info)) {
|
||||
stack;
|
||||
return r;
|
||||
}
|
||||
|
||||
log_very_verbose("%s is open %d time(s)", lv->name, info.open_count);
|
||||
return info.open_count;
|
||||
}
|
||||
|
||||
/*
|
||||
* Emit a target for a given segment.
|
||||
*/
|
||||
static int _emit_target(struct dm_task *dmt, struct stripe_segment *seg)
|
||||
{
|
||||
char params[1024];
|
||||
uint64_t esize = seg->lv->vg->extent_size;
|
||||
uint32_t s, stripes = seg->stripes;
|
||||
int w = 0, tw = 0, error = 0;
|
||||
const char *no_space =
|
||||
"Insufficient space to write target parameters.";
|
||||
char *filler = "/dev/ioerror";
|
||||
char *target;
|
||||
|
||||
if (stripes == 1) {
|
||||
if (!seg->area[0].pv) {
|
||||
target = "error";
|
||||
error = 1;
|
||||
}
|
||||
else
|
||||
target = "linear";
|
||||
}
|
||||
|
||||
if (stripes > 1) {
|
||||
target = "striped";
|
||||
tw = lvm_snprintf(params, sizeof(params), "%u %u ",
|
||||
stripes, seg->stripe_size);
|
||||
|
||||
if (tw < 0) {
|
||||
log_err(no_space);
|
||||
return 0;
|
||||
}
|
||||
|
||||
w = tw;
|
||||
}
|
||||
|
||||
if (!error) {
|
||||
for (s = 0; s < stripes; s++, w += tw) {
|
||||
if (!seg->area[s].pv)
|
||||
tw = lvm_snprintf(
|
||||
params + w, sizeof(params) - w,
|
||||
"%s 0%s", filler,
|
||||
s == (stripes - 1) ? "" : " ");
|
||||
else
|
||||
tw = lvm_snprintf(
|
||||
params + w, sizeof(params) - w,
|
||||
"%s %" PRIu64 "%s",
|
||||
dev_name(seg->area[s].pv->dev),
|
||||
(seg->area[s].pv->pe_start +
|
||||
(esize * seg->area[s].pe)),
|
||||
s == (stripes - 1) ? "" : " ");
|
||||
|
||||
if (tw < 0) {
|
||||
log_err(no_space);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log_very_verbose("Adding target: %" PRIu64 " %" PRIu64 " %s %s",
|
||||
esize * seg->le, esize * seg->len,
|
||||
target, params);
|
||||
|
||||
if (!dm_task_add_target(dmt, esize * seg->le, esize * seg->len,
|
||||
target, params)) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _load(struct logical_volume *lv, int task)
|
||||
{
|
||||
int r = 0;
|
||||
struct dm_task *dmt;
|
||||
struct list *segh;
|
||||
struct stripe_segment *seg;
|
||||
|
||||
log_very_verbose("Generating devmapper parameters for %s", lv->name);
|
||||
if (!(dmt = _setup_task(lv, task))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
list_iterate(segh, &lv->segments) {
|
||||
seg = list_item(segh, struct stripe_segment);
|
||||
if (!_emit_target(dmt, seg)) {
|
||||
log_error("Unable to activate logical volume '%s'",
|
||||
lv->name);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
if (!((lv->status & LVM_WRITE) && (lv->vg->status & LVM_WRITE))) {
|
||||
if (!dm_task_set_ro(dmt))
|
||||
log_error("Failed to set %s read-only during "
|
||||
"activation.", lv->name);
|
||||
else
|
||||
log_very_verbose("Activating %s read-only", lv->name);
|
||||
}
|
||||
|
||||
|
||||
if (!(r = dm_task_run(dmt)))
|
||||
stack;
|
||||
|
||||
log_verbose("Logical volume %s%s activated", lv->name,
|
||||
r == 1 ? "" : " not");
|
||||
|
||||
out:
|
||||
dm_task_destroy(dmt);
|
||||
return r;
|
||||
}
|
||||
|
||||
/* FIXME: Always display error msg */
|
||||
int lv_activate(struct logical_volume *lv)
|
||||
{
|
||||
if (test_mode())
|
||||
return 0;
|
||||
|
||||
log_very_verbose("Activating %s", lv->name);
|
||||
return _load(lv, DM_DEVICE_CREATE) && fs_add_lv(lv);
|
||||
}
|
||||
|
||||
int _suspend(struct logical_volume *lv, int sus)
|
||||
{
|
||||
int r;
|
||||
struct dm_task *dmt;
|
||||
int task = sus ? DM_DEVICE_SUSPEND : DM_DEVICE_RESUME;
|
||||
|
||||
log_very_verbose("%s %s", sus ? "Suspending" : "Resuming", lv->name);
|
||||
if (!(dmt = _setup_task(lv, task))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(r = dm_task_run(dmt)))
|
||||
log_err("Couldn't %s device '%s'", sus ? "suspend" : "resume",
|
||||
lv->name);
|
||||
|
||||
dm_task_destroy(dmt);
|
||||
return r;
|
||||
}
|
||||
|
||||
int lv_suspend(struct logical_volume *lv)
|
||||
{
|
||||
return _suspend(lv, 1);
|
||||
}
|
||||
|
||||
int lv_reactivate(struct logical_volume *lv)
|
||||
{
|
||||
int r;
|
||||
|
||||
if (test_mode())
|
||||
return 0;
|
||||
|
||||
if (!lv_suspended(lv) && !_suspend(lv, 1)) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
r = _load(lv, DM_DEVICE_RELOAD);
|
||||
|
||||
if (!_suspend(lv, 0)) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
int lv_deactivate(struct logical_volume *lv)
|
||||
{
|
||||
int r;
|
||||
struct dm_task *dmt;
|
||||
|
||||
log_very_verbose("Deactivating %s", lv->name);
|
||||
if (test_mode())
|
||||
return 0;
|
||||
|
||||
if (!(dmt = _setup_task(lv, DM_DEVICE_REMOVE))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(r = dm_task_run(dmt)))
|
||||
stack;
|
||||
|
||||
dm_task_destroy(dmt);
|
||||
|
||||
fs_del_lv(lv);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
int activate_lvs_in_vg(struct volume_group *vg)
|
||||
{
|
||||
return 0;
|
||||
struct list *lvh;
|
||||
struct logical_volume *lv;
|
||||
int count = 0;
|
||||
|
||||
list_iterate(lvh, &vg->lvs) {
|
||||
lv = list_item(lvh, struct lv_list)->lv;
|
||||
count += (!lv_active(lv) && lv_activate(lv));
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
int lv_update_write_access(struct logical_volume *lv)
|
||||
{
|
||||
struct dm_info info;
|
||||
|
||||
if (!lv_info(lv, &info)) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!info.exists || info.suspended)
|
||||
/* Noop */
|
||||
return 1;
|
||||
|
||||
return lv_reactivate(lv);
|
||||
}
|
||||
|
||||
int deactivate_lvs_in_vg(struct volume_group *vg)
|
||||
{
|
||||
return 0;
|
||||
struct list *lvh;
|
||||
struct logical_volume *lv;
|
||||
int count = 0;
|
||||
|
||||
list_iterate(lvh, &vg->lvs) {
|
||||
lv = list_item(lvh, struct lv_list)->lv;
|
||||
count += ((lv_active(lv) == 1) && lv_deactivate(lv));
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
int lvs_in_vg_activated(struct volume_group *vg)
|
||||
{
|
||||
struct list *lvh;
|
||||
struct logical_volume *lv;
|
||||
int count = 0;
|
||||
|
||||
list_iterate(lvh, &vg->lvs) {
|
||||
lv = list_item(lvh, struct lv_list)->lv;
|
||||
count += (lv_active(lv) == 1);
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
int lvs_in_vg_opened(struct volume_group *vg)
|
||||
{
|
||||
struct list *lvh;
|
||||
struct logical_volume *lv;
|
||||
int count = 0;
|
||||
|
||||
list_iterate(lvh, &vg->lvs) {
|
||||
lv = list_item(lvh, struct lv_list)->lv;
|
||||
count += (lv_open_count(lv) == 1);
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
@@ -7,22 +7,46 @@
|
||||
#ifndef LVM_ACTIVATE_H
|
||||
#define LVM_ACTIVATE_H
|
||||
|
||||
#include <libdevmapper.h>
|
||||
|
||||
/* FIXME Snapshot handling? */
|
||||
|
||||
int lv_activate(struct volume_group *vg,
|
||||
struct logical_volume *lv);
|
||||
int driver_version(char *version, size_t size);
|
||||
int library_version(char *version, size_t size);
|
||||
|
||||
int lv_deactivate(struct volume_group *vg,
|
||||
struct logical_volume *lv);
|
||||
int lv_active(struct logical_volume *lv);
|
||||
int lv_suspended(struct logical_volume *lv);
|
||||
int lv_open_count(struct logical_volume *lv);
|
||||
int lv_info(struct logical_volume *lv, struct dm_info *info);
|
||||
int lv_rename(const char *old_name, struct logical_volume *lv);
|
||||
|
||||
/* Return number of LVs in the VG that are active */
|
||||
int lv_activate(struct logical_volume *lv);
|
||||
int lv_reactivate(struct logical_volume *lv);
|
||||
int lv_deactivate(struct logical_volume *lv);
|
||||
int lv_suspend(struct logical_volume *lv);
|
||||
|
||||
/*
|
||||
* Return number of LVs in the VG that are
|
||||
* active.
|
||||
*/
|
||||
int lvs_in_vg_activated(struct volume_group *vg);
|
||||
int lvs_in_vg_opened(struct volume_group *vg);
|
||||
|
||||
/* Activate all LVs in the VG. Ignore any that are already active. */
|
||||
/* Return number activated */
|
||||
/*
|
||||
* Test for (lv->status & LVM_WRITE)
|
||||
*/
|
||||
int lv_update_write_access(struct logical_volume *lv);
|
||||
|
||||
/*
|
||||
* Activate all LVs in the VG. Ignore any that
|
||||
* are already active. Return number
|
||||
* activated.
|
||||
*/
|
||||
int activate_lvs_in_vg(struct volume_group *vg);
|
||||
|
||||
/* Deactivate all LVs in the VG */
|
||||
/*
|
||||
* Deactivate all LVs in the VG
|
||||
*/
|
||||
int deactivate_lvs_in_vg(struct volume_group *vg);
|
||||
|
||||
#endif
|
||||
|
||||
160
lib/activate/fs.c
Normal file
160
lib/activate/fs.c
Normal file
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
* Copyright (C) 2001 Sistina Software (UK) Limited.
|
||||
*
|
||||
* This file is released under the LGPL.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "fs.h"
|
||||
#include "log.h"
|
||||
#include "names.h"
|
||||
|
||||
#include <libdevmapper.h>
|
||||
|
||||
|
||||
/*
|
||||
* Lazy programmer: I'm just going to always try
|
||||
* and create/remove the vg directory, and not say
|
||||
* anything if it fails.
|
||||
*/
|
||||
static int _mk_dir(struct volume_group *vg)
|
||||
{
|
||||
char vg_path[PATH_MAX];
|
||||
|
||||
if (!build_vg_path(vg_path, sizeof(vg_path),
|
||||
vg->cmd->dev_dir, vg->name)) {
|
||||
log_error("Couldn't construct name of volume group directory.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
log_very_verbose("Creating directory %s", vg_path);
|
||||
mkdir(vg_path, 0555);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _rm_dir(struct volume_group *vg)
|
||||
{
|
||||
char vg_path[PATH_MAX];
|
||||
|
||||
if (!build_vg_path(vg_path, sizeof(vg_path),
|
||||
vg->cmd->dev_dir, vg->name)) {
|
||||
log_error("Couldn't construct name of volume group dir for %s",
|
||||
vg->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
log_very_verbose("Removing directory %s", vg_path);
|
||||
rmdir(vg_path);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _mk_link(struct logical_volume *lv)
|
||||
{
|
||||
char lv_path[PATH_MAX], link_path[PATH_MAX];
|
||||
struct stat buf;
|
||||
|
||||
if (!build_dm_path(lv_path, sizeof(lv_path), lv->vg->name, lv->name)) {
|
||||
log_error("Couldn't create destination pathname for "
|
||||
"logical volume link for %s", lv->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!build_lv_link_path(link_path, sizeof(link_path),
|
||||
lv->vg->cmd->dev_dir,
|
||||
lv->vg->name, lv->name)) {
|
||||
log_error("Couldn't create source pathname for "
|
||||
"logical volume link %s", lv->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!lstat(link_path, &buf)) {
|
||||
if (!S_ISLNK(buf.st_mode)) {
|
||||
log_error("Symbolic link %s not created: file exists",
|
||||
link_path);
|
||||
return 0;
|
||||
}
|
||||
if (unlink(link_path) < 0) {
|
||||
log_sys_error("unlink", link_path);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
log_very_verbose("Linking %s to %s", link_path, lv_path);
|
||||
if (symlink(lv_path, link_path) < 0) {
|
||||
log_sys_error("symlink", link_path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _rm_link(struct logical_volume *lv, const char *lv_name)
|
||||
{
|
||||
struct stat buf;
|
||||
char link_path[PATH_MAX];
|
||||
|
||||
if (!lv_name)
|
||||
lv_name = lv->name;
|
||||
|
||||
if (!build_lv_link_path(link_path, sizeof(link_path),
|
||||
lv->vg->cmd->dev_dir,
|
||||
lv->vg->name, lv->name)) {
|
||||
log_error("Couldn't determine link pathname.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
log_very_verbose("Removing link %s", link_path);
|
||||
if (lstat(link_path, &buf) || !S_ISLNK(buf.st_mode)) {
|
||||
log_error("%s not symbolic link - not removing",
|
||||
link_path);
|
||||
return 0;
|
||||
}
|
||||
if (unlink(link_path) < 0) {
|
||||
log_sys_error("unlink", link_path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int fs_add_lv(struct logical_volume *lv)
|
||||
{
|
||||
if (!_mk_dir(lv->vg) ||
|
||||
!_mk_link(lv)) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int fs_del_lv(struct logical_volume *lv)
|
||||
{
|
||||
if (!_rm_link(lv, NULL) ||
|
||||
!_rm_dir(lv->vg)) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int fs_rename_lv(const char *old_name, struct logical_volume *lv)
|
||||
{
|
||||
if (!_rm_link(lv, old_name))
|
||||
stack;
|
||||
|
||||
if (!_mk_link(lv))
|
||||
stack;
|
||||
|
||||
return 1;
|
||||
}
|
||||
23
lib/activate/fs.h
Normal file
23
lib/activate/fs.h
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (C) 2001 Sistina Software (UK) Limited.
|
||||
*
|
||||
* This file is released under the LGPL.
|
||||
*/
|
||||
|
||||
#ifndef _LVM_FS_H
|
||||
#define _LVM_FS_H
|
||||
|
||||
#include "metadata.h"
|
||||
|
||||
/*
|
||||
* These calls, private to the activate unit, set
|
||||
* up the volume group directory in /dev and the
|
||||
* symbolic links to the dm device.
|
||||
*/
|
||||
|
||||
int fs_add_lv(struct logical_volume *lv);
|
||||
int fs_del_lv(struct logical_volume *lv);
|
||||
int fs_rename_lv(const char *old_name, struct logical_volume *lv);
|
||||
|
||||
|
||||
#endif
|
||||
88
lib/activate/names.c
Normal file
88
lib/activate/names.c
Normal file
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright (C) 2002 Sistina Software (UK) Limited.
|
||||
*
|
||||
* This file is released under the LGPL.
|
||||
*/
|
||||
|
||||
#include "names.h"
|
||||
#include "lvm-string.h"
|
||||
#include "log.h"
|
||||
#include "limits.h"
|
||||
|
||||
#include <libdevmapper.h>
|
||||
|
||||
/*
|
||||
* The volume group name and the logical volume name are
|
||||
* seperated by a single ':', any colons in the vg name are
|
||||
* doubled up to form a pair.
|
||||
*/
|
||||
int build_dm_name(char *buffer, size_t len,
|
||||
const char *vg_name, const char *lv_name)
|
||||
{
|
||||
char *out;
|
||||
const char *in;
|
||||
|
||||
for (out = buffer, in = vg_name; len && *in; len--) {
|
||||
if (*in == ':') {
|
||||
*out++ = ':';
|
||||
if (!--len)
|
||||
break;
|
||||
}
|
||||
|
||||
*out++ = *in++;
|
||||
len--;
|
||||
}
|
||||
|
||||
if (!len)
|
||||
return 0;
|
||||
|
||||
if (lvm_snprintf(out, len, ":%s", lv_name) == -1) {
|
||||
log_err("Couldn't build logical volume name.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int build_dm_path(char *buffer, size_t len,
|
||||
const char *vg_name, const char *lv_name)
|
||||
{
|
||||
char dev_name[PATH_MAX];
|
||||
|
||||
if (!build_dm_name(dev_name, sizeof(dev_name), vg_name, lv_name)) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (lvm_snprintf(buffer, len, "%s/%s", dm_dir(), dev_name) == -1) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int build_vg_path(char *buffer, size_t len,
|
||||
const char *dev_dir, const char *vg_name)
|
||||
{
|
||||
if (lvm_snprintf(buffer, len, "%s%s", dev_dir, vg_name) == -1) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int build_lv_link_path(char *buffer, size_t len, const char *dev_dir,
|
||||
const char *vg_name, const char *lv_name)
|
||||
{
|
||||
if (lvm_snprintf(buffer, len, "%s%s/%s",
|
||||
dev_dir, vg_name, lv_name) == -1) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
50
lib/activate/names.h
Normal file
50
lib/activate/names.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (C) 2002 Sistina Software (UK) Limited.
|
||||
*
|
||||
* This file is released under the LGPL.
|
||||
*/
|
||||
|
||||
#ifndef _LVM_NAMES_H
|
||||
#define _LVM_NAMES_H
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
/*
|
||||
* Functions that build up useful paths to devices, sym-links
|
||||
* etc. Names are passed in as strings, rather than via the
|
||||
* appropriate metadata structures, so we can use it for renaming
|
||||
* devices.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* The name of the device-mapper device for a particular LV.
|
||||
* eg, vg0:music
|
||||
*/
|
||||
int build_dm_name(char *buffer, size_t len,
|
||||
const char *vg_name, const char *lv_name);
|
||||
|
||||
/*
|
||||
* The path of the device-mapper device for a particular LV.
|
||||
* eg, /dev/device-mapper/vg0:music
|
||||
*/
|
||||
int build_dm_path(char *buffer, size_t len,
|
||||
const char *vg_name, const char *lv_name);
|
||||
|
||||
/*
|
||||
* Path to the volume group directory.
|
||||
* eg, /dev/vg0
|
||||
*/
|
||||
int build_vg_path(char *buffer, size_t len,
|
||||
const char *dev_dir, const char *vg_name);
|
||||
|
||||
/*
|
||||
* Path to the symbolic link that lives in the volume group
|
||||
* directory.
|
||||
* eg, /dev/vg0/music
|
||||
*/
|
||||
int build_lv_link_path(char *buffer, size_t len,
|
||||
const char *dev_dir,
|
||||
const char *vg_name, const char *lv_name);
|
||||
|
||||
#endif
|
||||
@@ -1,12 +1,17 @@
|
||||
/*
|
||||
* Copyright (C) 2001 Sistina Software (UK) Limited.
|
||||
*
|
||||
* This file is released under the GPL.
|
||||
* This file is released under the LGPL.
|
||||
*/
|
||||
|
||||
#include "table-build.c"
|
||||
|
||||
/* FIXME: optimise linear runs */
|
||||
static void _print_run(FILE *fp, struct logical_volume *lv)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
int build_table(struct volume_group *vg, struct logical_volume *lv,
|
||||
const char *file)
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright (C) 2001 Sistina Software (UK) Limited.
|
||||
*
|
||||
* This file is released under the GPL.
|
||||
* This file is released under the LGPL.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
@@ -54,27 +54,36 @@ static struct config_node *_file(struct parser *p);
|
||||
static struct config_node *_section(struct parser *p);
|
||||
static struct config_value *_value(struct parser *p);
|
||||
static struct config_value *_type(struct parser *p);
|
||||
static void _parse_error(struct parser *p, const char *file, int line,
|
||||
const char *mess);
|
||||
static int _match_aux(struct parser *p, int t);
|
||||
static struct config_value *_create_value(struct parser *p);
|
||||
static struct config_node *_create_node(struct parser *p);
|
||||
static char *_dup_tok(struct parser *p);
|
||||
static int _tok_match(const char *str, const char *b, const char *e);
|
||||
|
||||
#define MAX_INDENT 32
|
||||
|
||||
#define match(t) do {\
|
||||
if (!_match_aux(p, (t))) {\
|
||||
_parse_error(p, __FILE__, __LINE__, "unexpected token"); \
|
||||
log_error("Parse error at line %d: unexpected token", p->line); \
|
||||
return 0;\
|
||||
} \
|
||||
} while(0);
|
||||
|
||||
|
||||
static int _tok_match(const char *str, const char *b, const char *e)
|
||||
{
|
||||
while (*str && (b != e)) {
|
||||
if (*str++ != *b++)
|
||||
return 0;
|
||||
}
|
||||
|
||||
return !(*str || (b != e));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* public interface
|
||||
*/
|
||||
struct config_file *create_config_file()
|
||||
struct config_file *create_config_file(void)
|
||||
{
|
||||
struct cs *c;
|
||||
struct pool *mem = pool_create(10 * 1024);
|
||||
@@ -233,7 +242,7 @@ int write_config(struct config_file *cf, const char *file)
|
||||
*/
|
||||
static struct config_node *_file(struct parser *p)
|
||||
{
|
||||
struct config_node *root = 0, *n, *l;
|
||||
struct config_node *root = NULL, *n, *l = NULL;
|
||||
while (p->t != TOK_EOF) {
|
||||
if (!(n = _section(p))) {
|
||||
stack;
|
||||
@@ -252,7 +261,7 @@ static struct config_node *_file(struct parser *p)
|
||||
static struct config_node *_section(struct parser *p)
|
||||
{
|
||||
/* IDENTIFIER '{' VALUE* '}' */
|
||||
struct config_node *root, *n, *l;
|
||||
struct config_node *root, *n, *l = NULL;
|
||||
if (!(root = _create_node(p))) {
|
||||
stack;
|
||||
return 0;
|
||||
@@ -319,14 +328,15 @@ static struct config_value *_value(struct parser *p)
|
||||
return h;
|
||||
}
|
||||
|
||||
static struct config_value *_type(struct parser *p) {
|
||||
static struct config_value *_type(struct parser *p)
|
||||
{
|
||||
/* [0-9]+ | [0-9]*\.[0-9]* | ".*" */
|
||||
struct config_value *v = _create_value(p);
|
||||
|
||||
switch (p->t) {
|
||||
case TOK_INT:
|
||||
v->type = CFG_INT;
|
||||
v->v.i = strtol(p->tb, 0, 10); /* FIXME: check error */
|
||||
v->v.i = strtol(p->tb, 0, 0); /* FIXME: check error */
|
||||
match(TOK_INT);
|
||||
break;
|
||||
|
||||
@@ -349,18 +359,12 @@ static struct config_value *_type(struct parser *p) {
|
||||
break;
|
||||
|
||||
default:
|
||||
_parse_error(p, __FILE__, __LINE__, "expected a value");
|
||||
log_error("Parse error at line %d: expected a value", p->line);
|
||||
return 0;
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
static void _parse_error(struct parser *p, const char *file, int line,
|
||||
const char *mess)
|
||||
{
|
||||
plog(_LOG_ERR, file, line, "parse error at %d: %s", p->line, mess);
|
||||
}
|
||||
|
||||
static int _match_aux(struct parser *p, int t)
|
||||
{
|
||||
if (p->t != t)
|
||||
@@ -544,25 +548,34 @@ struct config_node *find_config_node(struct config_node *cn,
|
||||
}
|
||||
|
||||
const char *
|
||||
find_config_str(struct config_node *cn,
|
||||
find_config_str(struct config_node *cn,
|
||||
const char *path, char sep, const char *fail)
|
||||
{
|
||||
struct config_node *n = find_config_node(cn, path, sep);
|
||||
|
||||
if (n && n->v->type == CFG_STRING)
|
||||
if (n && n->v->type == CFG_STRING) {
|
||||
log_very_verbose("Setting %s to %s", path, n->v->v.str);
|
||||
return n->v->v.str;
|
||||
}
|
||||
|
||||
if (fail)
|
||||
log_very_verbose("%s not found in config: defaulting to %s",
|
||||
path, fail);
|
||||
return fail;
|
||||
}
|
||||
|
||||
int find_config_int(struct config_node *cn, const char *path,
|
||||
int find_config_int(struct config_node *cn, const char *path,
|
||||
char sep, int fail)
|
||||
{
|
||||
struct config_node *n = find_config_node(cn, path, sep);
|
||||
|
||||
if (n && n->v->type == CFG_INT)
|
||||
if (n && n->v->type == CFG_INT) {
|
||||
log_very_verbose("Setting %s to %d", path, n->v->v.i);
|
||||
return n->v->v.i;
|
||||
}
|
||||
|
||||
log_very_verbose("%s not found in config: defaulting to %d",
|
||||
path, fail);
|
||||
return fail;
|
||||
}
|
||||
|
||||
@@ -571,25 +584,91 @@ float find_config_float(struct config_node *cn, const char *path,
|
||||
{
|
||||
struct config_node *n = find_config_node(cn, path, sep);
|
||||
|
||||
if (n && n->v->type == CFG_FLOAT)
|
||||
if (n && n->v->type == CFG_FLOAT) {
|
||||
log_very_verbose("Setting %s to %f", path, n->v->v.r);
|
||||
return n->v->v.r;
|
||||
}
|
||||
|
||||
log_very_verbose("%s not found in config: defaulting to %f",
|
||||
path, fail);
|
||||
|
||||
return fail;
|
||||
|
||||
}
|
||||
|
||||
static int _tok_match(const char *str, const char *b, const char *e)
|
||||
static int _str_in_array(const char *str, const char *values[])
|
||||
{
|
||||
while (*str && (b != e)) {
|
||||
if (*str++ != *b++)
|
||||
return 0;
|
||||
}
|
||||
int i;
|
||||
|
||||
return !(*str || (b != e));
|
||||
for (i = 0; values[i]; i++)
|
||||
if (!strcasecmp(str, values[i]))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _str_to_bool(const char *str, int fail)
|
||||
{
|
||||
static const char *_true_values[] = {"y", "yes", "on", "true", NULL};
|
||||
static const char *_false_values[] = {"n", "no", "off", "false", NULL};
|
||||
|
||||
if (_str_in_array(str, _true_values))
|
||||
return 1;
|
||||
|
||||
if (_str_in_array(str, _false_values))
|
||||
return 0;
|
||||
|
||||
return fail;
|
||||
}
|
||||
|
||||
int find_config_bool(struct config_node *cn, const char *path,
|
||||
char sep, int fail)
|
||||
{
|
||||
struct config_node *n = find_config_node(cn, path, sep);
|
||||
struct config_value *v;
|
||||
|
||||
if (!n)
|
||||
return fail;
|
||||
|
||||
v = n->v;
|
||||
|
||||
switch (v->type) {
|
||||
case CFG_INT:
|
||||
return v->v.i ? 1 : 0;
|
||||
|
||||
case CFG_STRING:
|
||||
return _str_to_bool(v->v.str, fail);
|
||||
}
|
||||
|
||||
return fail;
|
||||
}
|
||||
|
||||
int get_config_uint32(struct config_node *cn, const char *path,
|
||||
char sep, uint32_t *result)
|
||||
{
|
||||
struct config_node *n;
|
||||
|
||||
n = find_config_node(cn, path, sep);
|
||||
|
||||
if (!n || !n->v || n->v->type != CFG_INT)
|
||||
return 0;
|
||||
|
||||
*result = n->v->v.i;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int get_config_uint64(struct config_node *cn, const char *path,
|
||||
char sep, uint64_t *result)
|
||||
{
|
||||
struct config_node *n;
|
||||
|
||||
n = find_config_node(cn, path, sep);
|
||||
|
||||
if (!n || !n->v || n->v->type != CFG_INT)
|
||||
return 0;
|
||||
|
||||
/* FIXME Support 64-bit value! */
|
||||
*result = (uint64_t) n->v->v.i;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* c-file-style: "linux"
|
||||
* End:
|
||||
*/
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
/*
|
||||
* Copyright (C) 2001 Sistina Software (UK) Limited.
|
||||
*
|
||||
* This file is released under the GPL.
|
||||
* This file is released under the LGPL.
|
||||
*/
|
||||
|
||||
#ifndef _LVM_CONFIG_H
|
||||
#define _LVM_CONFIG_H
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
enum {
|
||||
CFG_STRING,
|
||||
@@ -34,7 +35,7 @@ struct config_file {
|
||||
struct config_node *root;
|
||||
};
|
||||
|
||||
struct config_file *create_config_file();
|
||||
struct config_file *create_config_file(void);
|
||||
void destroy_config_file(struct config_file *cf);
|
||||
|
||||
int read_config(struct config_file *cf, const char *file);
|
||||
@@ -52,10 +53,20 @@ int find_config_int(struct config_node *cn, const char *path,
|
||||
float find_config_float(struct config_node *cn, const char *path,
|
||||
char sep, float fail);
|
||||
|
||||
/*
|
||||
* Understands (0, ~0), (y, n), (yes, no), (on,
|
||||
* off), (true, false).
|
||||
*/
|
||||
int find_config_bool(struct config_node *cn, const char *path,
|
||||
char sep, int fail);
|
||||
|
||||
|
||||
|
||||
int get_config_uint32(struct config_node *cn, const char *path,
|
||||
char sep, uint32_t *result);
|
||||
|
||||
int get_config_uint64(struct config_node *cn, const char *path,
|
||||
char sep, uint64_t *result);
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* c-file-style: "linux"
|
||||
* End:
|
||||
*/
|
||||
|
||||
79
lib/datastruct/bitset.c
Normal file
79
lib/datastruct/bitset.c
Normal file
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (C) 2001 Sistina Software (UK) Limited.
|
||||
*
|
||||
* This file is released under the LGPL.
|
||||
*/
|
||||
|
||||
#include "bitset.h"
|
||||
#include "dbg_malloc.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
/* FIXME: calculate this. */
|
||||
#define INT_SHIFT 5
|
||||
|
||||
bitset_t bitset_create(struct pool *mem, unsigned num_bits)
|
||||
{
|
||||
int n = (num_bits / BITS_PER_INT) + 2;
|
||||
int size = sizeof(int) * n;
|
||||
unsigned *bs = pool_zalloc(mem, size);
|
||||
|
||||
if (!bs)
|
||||
return NULL;
|
||||
|
||||
*bs = num_bits;
|
||||
return bs;
|
||||
}
|
||||
|
||||
void bitset_destroy(bitset_t bs)
|
||||
{
|
||||
dbg_free(bs);
|
||||
}
|
||||
|
||||
void bit_union(bitset_t out, bitset_t in1, bitset_t in2)
|
||||
{
|
||||
int i;
|
||||
for(i = (in1[0] / BITS_PER_INT) + 1; i; i--)
|
||||
out[i] = in1[i] | in2[i];
|
||||
}
|
||||
|
||||
/*
|
||||
* FIXME: slow
|
||||
*/
|
||||
static inline int _test_word(uint32_t test, int bit)
|
||||
{
|
||||
while (bit < BITS_PER_INT) {
|
||||
if (test & (0x1 << bit))
|
||||
return bit;
|
||||
bit++;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int bit_get_next(bitset_t bs, int last_bit)
|
||||
{
|
||||
int bit, word;
|
||||
uint32_t test;
|
||||
|
||||
last_bit++; /* otherwise we'll return the same bit again */
|
||||
|
||||
while(last_bit < bs[0]) {
|
||||
word = last_bit >> INT_SHIFT;
|
||||
test = bs[word + 1];
|
||||
bit = last_bit & (BITS_PER_INT - 1);
|
||||
|
||||
if ((bit = _test_word(test, bit)) >= 0)
|
||||
return (word * BITS_PER_INT) + bit;
|
||||
|
||||
last_bit = last_bit - (last_bit & (BITS_PER_INT - 1)) +
|
||||
BITS_PER_INT;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int bit_get_first(bitset_t bs)
|
||||
{
|
||||
return bit_get_next(bs, -1);
|
||||
}
|
||||
46
lib/datastruct/bitset.h
Normal file
46
lib/datastruct/bitset.h
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (C) 2001 Sistina Software (UK) Limited.
|
||||
*
|
||||
* This file is released under the GPL.
|
||||
*/
|
||||
|
||||
#ifndef _LVM_BITSET_H
|
||||
#define _LVM_BITSET_H
|
||||
|
||||
#include "lvm-types.h"
|
||||
#include "pool.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
typedef uint32_t *bitset_t;
|
||||
|
||||
bitset_t bitset_create(struct pool *mem, unsigned num_bits);
|
||||
|
||||
void bit_union(bitset_t out, bitset_t in1, bitset_t in2);
|
||||
int bit_get_first(bitset_t bs);
|
||||
int bit_get_next(bitset_t bs, int last_bit);
|
||||
|
||||
|
||||
#define BITS_PER_INT (sizeof(int) * CHAR_BIT)
|
||||
|
||||
#define bit(bs, i) \
|
||||
(bs[(i / BITS_PER_INT) + 1] & (0x1 << (i & (BITS_PER_INT - 1))))
|
||||
|
||||
#define bit_set(bs, i) \
|
||||
(bs[(i / BITS_PER_INT) + 1] |= (0x1 << (i & (BITS_PER_INT - 1))))
|
||||
|
||||
#define bit_clear(bs, i) \
|
||||
(bs[(i / BITS_PER_INT) + 1] &= ~(0x1 << (i & (BITS_PER_INT - 1))))
|
||||
|
||||
#define bit_set_all(bs) \
|
||||
memset(bs + 1, -1, ((*bs / BITS_PER_INT) + 1) * sizeof(int))
|
||||
|
||||
#define bit_clear_all(bs) \
|
||||
memset(bs + 1, 0, ((*bs / BITS_PER_INT) + 1) * sizeof(int))
|
||||
|
||||
#define bit_copy(bs1, bs2) \
|
||||
memcpy(bs1 + 1, bs2 + 1, ((*bs1 / BITS_PER_INT) + 1) * sizeof(int))
|
||||
|
||||
#endif
|
||||
130
lib/datastruct/btree.c
Normal file
130
lib/datastruct/btree.c
Normal file
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* Copyright (C) 2001 Sistina Software (UK) Limited.
|
||||
*
|
||||
* This file is released under the LGPL.
|
||||
*/
|
||||
|
||||
#include "btree.h"
|
||||
#include "log.h"
|
||||
|
||||
struct node {
|
||||
uint32_t key;
|
||||
struct node *l, *r, *p;
|
||||
|
||||
void *data;
|
||||
};
|
||||
|
||||
struct btree {
|
||||
struct pool *mem;
|
||||
struct node *root;
|
||||
};
|
||||
|
||||
struct btree *btree_create(struct pool *mem)
|
||||
{
|
||||
struct btree *t = pool_alloc(mem, sizeof(*t));
|
||||
|
||||
if (t) {
|
||||
t->mem = mem;
|
||||
t->root = NULL;
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
/*
|
||||
* Shuffle the bits in a key, to try and remove
|
||||
* any ordering.
|
||||
*/
|
||||
static uint32_t _shuffle(uint32_t k)
|
||||
{
|
||||
#if 1
|
||||
return ((k & 0xff) << 24 |
|
||||
(k & 0xff00) << 8 |
|
||||
(k & 0xff0000) >> 8 |
|
||||
(k & 0xff000000) >> 24);
|
||||
#else
|
||||
return k;
|
||||
#endif
|
||||
}
|
||||
|
||||
struct node **_lookup(struct node **c, uint32_t key, struct node **p)
|
||||
{
|
||||
*p = NULL;
|
||||
while (*c) {
|
||||
*p = *c;
|
||||
if ((*c)->key == key)
|
||||
break;
|
||||
|
||||
if (key < (*c)->key)
|
||||
c = &(*c)->l;
|
||||
|
||||
else
|
||||
c = &(*c)->r;
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
void *btree_lookup(struct btree *t, uint32_t k)
|
||||
{
|
||||
uint32_t key = _shuffle(k);
|
||||
struct node *p, **c = _lookup(&t->root, key, &p);
|
||||
return (*c) ? (*c)->data : NULL;
|
||||
}
|
||||
|
||||
int btree_insert(struct btree *t, uint32_t k, void *data)
|
||||
{
|
||||
uint32_t key = _shuffle(k);
|
||||
struct node *p, **c = _lookup(&t->root, key, &p), *n;
|
||||
|
||||
if (!*c) {
|
||||
if (!(n = pool_alloc(t->mem, sizeof(*n)))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
n->key = key;
|
||||
n->data = data;
|
||||
n->l = n->r = NULL;
|
||||
n->p = p;
|
||||
|
||||
*c = n;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void *btree_get_data(struct btree_iter *it)
|
||||
{
|
||||
return ((struct node *) it)->data;
|
||||
}
|
||||
|
||||
static inline struct node *_left(struct node *n)
|
||||
{
|
||||
while (n->l)
|
||||
n = n->l;
|
||||
return n;
|
||||
}
|
||||
|
||||
struct btree_iter *btree_first(struct btree *t)
|
||||
{
|
||||
if (!t->root)
|
||||
return NULL;
|
||||
|
||||
return (struct btree_iter *) _left(t->root);
|
||||
}
|
||||
|
||||
struct btree_iter *btree_next(struct btree_iter *it)
|
||||
{
|
||||
struct node *n = (struct node *) it;
|
||||
uint32_t k = n->key;
|
||||
|
||||
if (n->r)
|
||||
return (struct btree_iter *) _left(n->r);
|
||||
|
||||
do
|
||||
n = n->p;
|
||||
while (n && k > n->key);
|
||||
|
||||
return (struct btree_iter *) n;
|
||||
}
|
||||
26
lib/datastruct/btree.h
Normal file
26
lib/datastruct/btree.h
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (C) 2001 Sistina Software (UK) Limited.
|
||||
*
|
||||
* This file is released under the GPL.
|
||||
*/
|
||||
|
||||
#ifndef _LVM_BTREE_H
|
||||
#define _LVM_BTREE_H
|
||||
|
||||
#include "lvm-types.h"
|
||||
#include "pool.h"
|
||||
|
||||
struct btree;
|
||||
|
||||
struct btree *btree_create(struct pool *mem);
|
||||
|
||||
void *btree_lookup(struct btree *t, uint32_t k);
|
||||
int btree_insert(struct btree *t, uint32_t k, void *data);
|
||||
|
||||
struct btree_iter;
|
||||
void *btree_get_data(struct btree_iter *it);
|
||||
|
||||
struct btree_iter *btree_first(struct btree *t);
|
||||
struct btree_iter *btree_next(struct btree_iter *it);
|
||||
|
||||
#endif
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright (C) 2001 Sistina Software
|
||||
*
|
||||
* This file is released under the GPL.
|
||||
* This file is released under the LGPL.
|
||||
*/
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ struct hash_table *hash_create(unsigned size_hint)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void hash_destroy(struct hash_table *t)
|
||||
static void _free_nodes(struct hash_table *t)
|
||||
{
|
||||
struct hash_node *c, *n;
|
||||
int i;
|
||||
@@ -110,7 +110,11 @@ void hash_destroy(struct hash_table *t)
|
||||
n = c->next;
|
||||
dbg_free(c);
|
||||
}
|
||||
}
|
||||
|
||||
void hash_destroy(struct hash_table *t)
|
||||
{
|
||||
_free_nodes(t);
|
||||
dbg_free(t->slots);
|
||||
dbg_free(t);
|
||||
}
|
||||
@@ -127,7 +131,7 @@ static inline struct hash_node **_find(struct hash_table *t, const char *key)
|
||||
return c;
|
||||
}
|
||||
|
||||
char *hash_lookup(struct hash_table *t, const char *key)
|
||||
void *hash_lookup(struct hash_table *t, const char *key)
|
||||
{
|
||||
struct hash_node **c = _find(t, key);
|
||||
return *c ? (*c)->data : 0;
|
||||
@@ -181,6 +185,18 @@ void hash_iterate(struct hash_table *t, iterate_fn f)
|
||||
f(c->data);
|
||||
}
|
||||
|
||||
void hash_wipe(struct hash_table *t)
|
||||
{
|
||||
_free_nodes(t);
|
||||
memset(t->slots, 0, sizeof(struct hash_node *) * t->num_slots);
|
||||
t->num_nodes = 0;
|
||||
}
|
||||
|
||||
char *hash_get_key(struct hash_table *t, struct hash_node *n)
|
||||
{
|
||||
return n->key;
|
||||
}
|
||||
|
||||
void *hash_get_data(struct hash_table *t, struct hash_node *n)
|
||||
{
|
||||
return n->data;
|
||||
|
||||
@@ -14,14 +14,16 @@ typedef void (*iterate_fn)(void *data);
|
||||
|
||||
struct hash_table *hash_create(unsigned size_hint);
|
||||
void hash_destroy(struct hash_table *t);
|
||||
void hash_wipe(struct hash_table *t);
|
||||
|
||||
char *hash_lookup(struct hash_table *t, const char *key);
|
||||
void *hash_lookup(struct hash_table *t, const char *key);
|
||||
int hash_insert(struct hash_table *t, const char *key, void *data);
|
||||
void hash_remove(struct hash_table *t, const char *key);
|
||||
|
||||
unsigned hash_get_num_entries(struct hash_table *t);
|
||||
void hash_iterate(struct hash_table *t, iterate_fn f);
|
||||
|
||||
char *hash_get_key(struct hash_table *t, struct hash_node *n);
|
||||
void *hash_get_data(struct hash_table *t, struct hash_node *n);
|
||||
struct hash_node *hash_get_first(struct hash_table *t);
|
||||
struct hash_node *hash_get_next(struct hash_table *t, struct hash_node *n);
|
||||
|
||||
@@ -1,110 +1,72 @@
|
||||
/* stolen from the Linux kernel. */
|
||||
/*
|
||||
* Copyright (C) 2001 Sistina Software
|
||||
*
|
||||
* This file is released under the LGPL.
|
||||
*/
|
||||
|
||||
#ifndef _LVM_LIST_H
|
||||
#define _LVM_LIST_H
|
||||
|
||||
/*
|
||||
* Simple doubly linked list implementation.
|
||||
*
|
||||
* Some of the internal functions ("__xxx") are useful when
|
||||
* manipulating whole lists rather than single entries, as
|
||||
* sometimes we already know the next/prev entries and we can
|
||||
* generate better code by using them directly rather than
|
||||
* using the generic single-entry routines.
|
||||
*/
|
||||
#include <assert.h>
|
||||
|
||||
struct list_head {
|
||||
struct list_head *next, *prev;
|
||||
struct list {
|
||||
struct list *n, *p;
|
||||
};
|
||||
|
||||
#define LIST_HEAD_INIT(name) { &(name), &(name) }
|
||||
|
||||
#define LIST_HEAD(name) \
|
||||
struct list_head name = { &name, &name }
|
||||
|
||||
#define INIT_LIST_HEAD(ptr) do { \
|
||||
(ptr)->next = (ptr); (ptr)->prev = (ptr); \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* Insert a new entry between two known consecutive entries.
|
||||
*
|
||||
* This is only for internal list manipulation where we know
|
||||
* the prev/next entries already!
|
||||
*/
|
||||
static __inline__ void __list_add(struct list_head *new,
|
||||
struct list_head *prev,
|
||||
struct list_head *next)
|
||||
{
|
||||
next->prev = new;
|
||||
new->next = next;
|
||||
new->prev = prev;
|
||||
prev->next = new;
|
||||
static inline void list_init(struct list *head) {
|
||||
head->n = head->p = head;
|
||||
}
|
||||
|
||||
/*
|
||||
* Insert a new entry after the specified head..
|
||||
*/
|
||||
static __inline__ void list_add(struct list_head *new, struct list_head *head)
|
||||
{
|
||||
__list_add(new, head, head->next);
|
||||
static inline void list_add(struct list *head, struct list *elem) {
|
||||
assert(head->n);
|
||||
|
||||
elem->n = head;
|
||||
elem->p = head->p;
|
||||
|
||||
head->p->n = elem;
|
||||
head->p = elem;
|
||||
}
|
||||
|
||||
/*
|
||||
* Insert a new entry at the tail
|
||||
*/
|
||||
static __inline__ void list_add_tail(struct list_head *new, struct list_head *head)
|
||||
{
|
||||
__list_add(new, head->prev, head);
|
||||
static inline void list_add_h(struct list *head, struct list *elem) {
|
||||
assert(head->n);
|
||||
|
||||
elem->n = head->n;
|
||||
elem->p = head;
|
||||
|
||||
head->n->p = elem;
|
||||
head->n = elem;
|
||||
}
|
||||
|
||||
/*
|
||||
* Delete a list entry by making the prev/next entries
|
||||
* point to each other.
|
||||
*
|
||||
* This is only for internal list manipulation where we know
|
||||
* the prev/next entries already!
|
||||
*/
|
||||
static __inline__ void __list_del(struct list_head * prev,
|
||||
struct list_head * next)
|
||||
{
|
||||
next->prev = prev;
|
||||
prev->next = next;
|
||||
static inline void list_del(struct list *elem) {
|
||||
elem->n->p = elem->p;
|
||||
elem->p->n = elem->n;
|
||||
}
|
||||
|
||||
static __inline__ void list_del(struct list_head *entry)
|
||||
{
|
||||
__list_del(entry->prev, entry->next);
|
||||
static inline int list_empty(struct list *head) {
|
||||
return head->n == head;
|
||||
}
|
||||
|
||||
static __inline__ int list_empty(struct list_head *head)
|
||||
{
|
||||
return head->next == head;
|
||||
#define list_iterate(v, head) \
|
||||
for (v = (head)->n; v != head; v = v->n)
|
||||
|
||||
#define list_iterate_safe(v, t, head) \
|
||||
for (v = (head)->n, t = v->n; v != head; v = t, t = v->n)
|
||||
|
||||
static inline int list_size(struct list *head) {
|
||||
int s = 0;
|
||||
struct list *v;
|
||||
|
||||
list_iterate(v, head)
|
||||
s++;
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/*
|
||||
* Splice in "list" into "head"
|
||||
*/
|
||||
static __inline__ void list_splice(struct list_head *list, struct list_head *head)
|
||||
{
|
||||
struct list_head *first = list->next;
|
||||
#define list_item(v, t) \
|
||||
((t *)((uintptr_t)(v) - (uintptr_t)&((t *) 0)->list))
|
||||
|
||||
if (first != list) {
|
||||
struct list_head *last = list->prev;
|
||||
struct list_head *at = head->next;
|
||||
|
||||
first->prev = head;
|
||||
head->next = first;
|
||||
|
||||
last->next = at;
|
||||
at->prev = last;
|
||||
}
|
||||
}
|
||||
|
||||
#define list_entry(ptr, type, member) \
|
||||
((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
|
||||
|
||||
#define list_for_each(pos, head) \
|
||||
for (pos = (head)->next; pos != (head); pos = pos->next)
|
||||
/* Given a known element in a known structure, locate the struct list */
|
||||
#define list_head(v, t, e) \
|
||||
(((t *)((uintptr_t)(v) - (uintptr_t)&((t *) 0)->e))->list)
|
||||
|
||||
#endif
|
||||
|
||||
@@ -7,18 +7,14 @@
|
||||
#ifndef _LVM_TYPES_H
|
||||
#define _LVM_TYPES_H
|
||||
|
||||
#include "list.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
typedef __uint8_t uint8_t;
|
||||
typedef __uint16_t uint16_t;
|
||||
typedef __uint32_t uint32_t;
|
||||
typedef __uint64_t uint64_t;
|
||||
|
||||
#if 0
|
||||
typedef __int8_t int8_t;
|
||||
typedef __int16_t int16_t;
|
||||
typedef __int32_t int32_t;
|
||||
typedef __int64_t int64_t;
|
||||
#endif
|
||||
struct str_list {
|
||||
struct list list;
|
||||
char *str;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright (C) 2001 Sistina Software (UK) Limited.
|
||||
*
|
||||
* This file is released under the GPL.
|
||||
* This file is released under the LGPL.
|
||||
*/
|
||||
|
||||
#include "dev-cache.h"
|
||||
@@ -9,6 +9,8 @@
|
||||
#include "pool.h"
|
||||
#include "hash.h"
|
||||
#include "list.h"
|
||||
#include "lvm-types.h"
|
||||
#include "btree.h"
|
||||
#include "dbg_malloc.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
@@ -17,6 +19,7 @@
|
||||
#include <unistd.h>
|
||||
#include <sys/param.h>
|
||||
#include <dirent.h>
|
||||
#include <linux/kdev_t.h>
|
||||
|
||||
/*
|
||||
* FIXME: really need to seperate names from the devices since
|
||||
@@ -24,21 +27,22 @@
|
||||
*/
|
||||
|
||||
struct dev_iter {
|
||||
struct hash_node *current;
|
||||
struct btree_iter *current;
|
||||
struct dev_filter *filter;
|
||||
};
|
||||
|
||||
struct dir_list {
|
||||
struct list_head list;
|
||||
struct list list;
|
||||
char dir[0];
|
||||
};
|
||||
|
||||
static struct {
|
||||
struct pool *mem;
|
||||
struct hash_table *devices;
|
||||
struct hash_table *names;
|
||||
struct btree *devices;
|
||||
|
||||
int has_scanned;
|
||||
struct list_head dirs;
|
||||
struct list dirs;
|
||||
|
||||
} _cache;
|
||||
|
||||
@@ -46,28 +50,85 @@ static struct {
|
||||
#define _alloc(x) pool_alloc(_cache.mem, (x))
|
||||
#define _free(x) pool_free(_cache.mem, (x))
|
||||
|
||||
static int _dir_scan(const char *dir);
|
||||
static int _insert(const char *path, int rec);
|
||||
|
||||
/*
|
||||
* return a new path for the destination of the path.
|
||||
*/
|
||||
static char *_follow_link(const char *path, struct stat *info)
|
||||
static struct device *_create_dev(dev_t d)
|
||||
{
|
||||
char buffer[PATH_MAX + 1];
|
||||
int n;
|
||||
n = readlink(path, buffer, sizeof(buffer) - 1);
|
||||
struct device *dev;
|
||||
|
||||
if (n <= 0)
|
||||
return NULL;
|
||||
|
||||
buffer[n] = '\0';
|
||||
|
||||
if (stat(buffer, info) < 0) {
|
||||
log_sys_very_verbose("stat", buffer);
|
||||
if (!(dev = _alloc(sizeof(*dev)))) {
|
||||
stack;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pool_strdup(_cache.mem, buffer);
|
||||
list_init(&dev->aliases);
|
||||
dev->dev = d;
|
||||
dev->fd = -1;
|
||||
return dev;
|
||||
}
|
||||
|
||||
static int _add_alias(struct device *dev, const char *path)
|
||||
{
|
||||
struct str_list *sl = _alloc(sizeof(*sl));
|
||||
|
||||
if (!sl) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(sl->str = pool_strdup(_cache.mem, path))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
list_add(&dev->aliases, &sl->list);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Either creates a new dev, or adds an alias to
|
||||
* an existing dev.
|
||||
*/
|
||||
static int _insert_dev(const char *path, dev_t d)
|
||||
{
|
||||
struct device *dev;
|
||||
|
||||
/* is this device already registered ? */
|
||||
if (!(dev = (struct device *) btree_lookup(_cache.devices, d))) {
|
||||
/* create new device */
|
||||
if (!(dev = _create_dev(d))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(btree_insert(_cache.devices, d, dev))) {
|
||||
log_err("Couldn't insert device into binary tree.");
|
||||
_free(dev);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!_add_alias(dev, path)) {
|
||||
log_err("Couldn't add alias to dev cache.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!hash_insert(_cache.names, path, dev)) {
|
||||
log_err("Couldn't add name to hash in dev cache.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static char *_join(const char *dir, const char *name)
|
||||
{
|
||||
int len = strlen(dir) + strlen(name) + 2;
|
||||
char *r = dbg_malloc(len);
|
||||
if (r)
|
||||
snprintf(r, len, "%s/%s", dir, name);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -92,86 +153,9 @@ static void _collapse_slashes(char *str)
|
||||
*str = *ptr;
|
||||
}
|
||||
|
||||
static struct device *_create_dev(const char *path, struct stat *info)
|
||||
static int _insert_dir(const char *dir)
|
||||
{
|
||||
struct device *dev;
|
||||
char *name = pool_strdup(_cache.mem, path);
|
||||
|
||||
if (!name) {
|
||||
stack;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
_collapse_slashes(name);
|
||||
|
||||
if (!(dev = _alloc(sizeof(*dev)))) {
|
||||
stack;
|
||||
goto bad;
|
||||
}
|
||||
|
||||
dev->name = name;
|
||||
dev->dev = info->st_rdev;
|
||||
return dev;
|
||||
|
||||
bad:
|
||||
_free(name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int _insert(const char *path, int recurse)
|
||||
{
|
||||
struct stat info;
|
||||
struct device *dev;
|
||||
|
||||
log_very_verbose("dev-cache adding %s", path);
|
||||
|
||||
if (stat(path, &info) < 0) {
|
||||
log_sys_very_verbose("stat", path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (S_ISDIR(info.st_mode)) {
|
||||
if (recurse)
|
||||
return _dir_scan(path);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (S_ISLNK(info.st_mode)) {
|
||||
log_debug("%s is a symbolic link, following", path);
|
||||
if (!(path = _follow_link(path, &info))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!S_ISBLK(info.st_mode)) {
|
||||
log_debug("%s is not a block device", path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(dev = _create_dev(path, &info))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
hash_insert(_cache.devices, path, dev);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static char *_join(const char *dir, const char *name)
|
||||
{
|
||||
int len = strlen(dir) + strlen(name) + 2;
|
||||
char *r = dbg_malloc(len);
|
||||
if (r)
|
||||
snprintf(r, len, "%s/%s", dir, name);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static int _dir_scan(const char *dir)
|
||||
{
|
||||
int n, dirent_count;
|
||||
int n, dirent_count, r = 1;
|
||||
struct dirent **dirent;
|
||||
char *path;
|
||||
|
||||
@@ -183,77 +167,196 @@ static int _dir_scan(const char *dir)
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((path = _join(dir, dirent[n]->d_name)))
|
||||
_insert(path, 1);
|
||||
if (!(path = _join(dir, dirent[n]->d_name))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
_collapse_slashes(path);
|
||||
r &= _insert(path, 1);
|
||||
dbg_free(path);
|
||||
|
||||
free(dirent[n]);
|
||||
}
|
||||
free(dirent);
|
||||
}
|
||||
|
||||
return 1;
|
||||
return r;
|
||||
}
|
||||
|
||||
static int _insert(const char *path, int rec)
|
||||
{
|
||||
struct stat info;
|
||||
int r = 0;
|
||||
|
||||
if (stat(path, &info) < 0) {
|
||||
log_sys_very_verbose("stat", path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (S_ISDIR(info.st_mode)) { /* add a directory */
|
||||
if (rec)
|
||||
r = _insert_dir(path);
|
||||
|
||||
} else { /* add a device */
|
||||
if (!S_ISBLK(info.st_mode)) {
|
||||
log_debug("%s: Not a block device", path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!_insert_dev(path, info.st_rdev)) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
r = 1;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static void _full_scan(void)
|
||||
{
|
||||
struct list_head *tmp;
|
||||
struct list *dh;
|
||||
|
||||
if (_cache.has_scanned)
|
||||
return;
|
||||
|
||||
list_for_each(tmp, &_cache.dirs) {
|
||||
struct dir_list *dl = list_entry(tmp, struct dir_list, list);
|
||||
_dir_scan(dl->dir);
|
||||
}
|
||||
list_iterate(dh, &_cache.dirs) {
|
||||
struct dir_list *dl = list_item(dh, struct dir_list);
|
||||
_insert_dir(dl->dir);
|
||||
};
|
||||
|
||||
_cache.has_scanned = 1;
|
||||
}
|
||||
|
||||
int dev_cache_init(void)
|
||||
{
|
||||
_cache.names = NULL;
|
||||
|
||||
if (!(_cache.mem = pool_create(10 * 1024))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(_cache.devices = hash_create(128))) {
|
||||
if (!(_cache.names = hash_create(128))) {
|
||||
stack;
|
||||
pool_destroy(_cache.mem);
|
||||
_cache.mem = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
INIT_LIST_HEAD(&_cache.dirs);
|
||||
if (!(_cache.devices = btree_create(_cache.mem))) {
|
||||
log_err("Couldn't create binary tree for dev-cache.");
|
||||
goto bad;
|
||||
}
|
||||
|
||||
list_init(&_cache.dirs);
|
||||
|
||||
return 1;
|
||||
|
||||
bad:
|
||||
dev_cache_exit();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void _check_closed(struct device *dev)
|
||||
{
|
||||
if (dev->fd >= 0)
|
||||
log_err("Device '%s' has been left open.", dev_name(dev));
|
||||
}
|
||||
|
||||
static inline void _check_for_open_devices(void)
|
||||
{
|
||||
hash_iterate(_cache.names, (iterate_fn)_check_closed);
|
||||
}
|
||||
|
||||
void dev_cache_exit(void)
|
||||
{
|
||||
_check_for_open_devices();
|
||||
|
||||
pool_destroy(_cache.mem);
|
||||
hash_destroy(_cache.devices);
|
||||
if (_cache.names)
|
||||
hash_destroy(_cache.names);
|
||||
}
|
||||
|
||||
int dev_cache_add_dir(const char *path)
|
||||
{
|
||||
struct dir_list *dl;
|
||||
struct stat st;
|
||||
|
||||
if (stat(path, &st)) {
|
||||
log_error("Ignoring %s: %s", path, strerror(errno));
|
||||
/* But don't fail */
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!S_ISDIR(st.st_mode)) {
|
||||
log_error("Ignoring %s: Not a directory", path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!(dl = _alloc(sizeof(*dl) + strlen(path) + 1)))
|
||||
return 0;
|
||||
|
||||
strcpy(dl->dir, path);
|
||||
list_add(&dl->list, &_cache.dirs);
|
||||
list_add(&_cache.dirs, &dl->list);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Check cached device name is still valid before returning it */
|
||||
/* This should be a rare occurrence */
|
||||
/* FIXME Make rest of code pass/cache struct device instead of dev_name */
|
||||
const char *dev_name_confirmed(struct device *dev)
|
||||
{
|
||||
struct stat buf;
|
||||
char *name;
|
||||
int r;
|
||||
|
||||
while ((r = stat(name = list_item(dev->aliases.n,
|
||||
struct str_list)->str, &buf)) ||
|
||||
(buf.st_rdev != dev->dev)) {
|
||||
if (r < 0)
|
||||
log_sys_error("stat", name);
|
||||
log_error("Path %s no longer valid for device(%d,%d)",
|
||||
name, (int) MAJOR(dev->dev), (int) MINOR(dev->dev));
|
||||
|
||||
/* Remove the incorrect hash entry */
|
||||
hash_remove(_cache.names, name);
|
||||
|
||||
/* Leave list alone if there isn't an alternative name */
|
||||
/* so dev_name will always find something to return. */
|
||||
/* Otherwise add the name to the correct device. */
|
||||
if (list_size(&dev->aliases) > 1) {
|
||||
list_del(dev->aliases.n);
|
||||
if (!r)
|
||||
_insert(name, 0);
|
||||
continue;
|
||||
}
|
||||
|
||||
log_error("Aborting - please provide new pathname for what "
|
||||
"used to be %s", name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return dev_name(dev);
|
||||
}
|
||||
|
||||
|
||||
struct device *dev_cache_get(const char *name, struct dev_filter *f)
|
||||
{
|
||||
struct device *d = (struct device *) hash_lookup(_cache.devices, name);
|
||||
struct stat buf;
|
||||
struct device *d = (struct device *) hash_lookup(_cache.names, name);
|
||||
|
||||
/* If the entry's wrong, remove it */
|
||||
if (d && (stat(name, &buf) || (buf.st_rdev != d->dev))) {
|
||||
hash_remove(_cache.names, name);
|
||||
d = NULL;
|
||||
}
|
||||
|
||||
if (!d) {
|
||||
_insert(name, 0);
|
||||
d = (struct device *) hash_lookup(_cache.devices, name);
|
||||
d = (struct device *) hash_lookup(_cache.names, name);
|
||||
}
|
||||
|
||||
return (d && (!f || f->passes_filter(f, d))) ? d : NULL;
|
||||
@@ -267,7 +370,7 @@ struct dev_iter *dev_iter_create(struct dev_filter *f)
|
||||
return NULL;
|
||||
|
||||
_full_scan();
|
||||
di->current = hash_get_first(_cache.devices);
|
||||
di->current = btree_first(_cache.devices);
|
||||
di->filter = f;
|
||||
|
||||
return di;
|
||||
@@ -280,8 +383,8 @@ void dev_iter_destroy(struct dev_iter *iter)
|
||||
|
||||
static inline struct device *_iter_next(struct dev_iter *iter)
|
||||
{
|
||||
struct device *d = hash_get_data(_cache.devices, iter->current);
|
||||
iter->current = hash_get_next(_cache.devices, iter->current);
|
||||
struct device *d = btree_get_data(iter->current);
|
||||
iter->current = btree_next(iter->current);
|
||||
return d;
|
||||
}
|
||||
|
||||
@@ -297,5 +400,3 @@ struct device *dev_iter_get(struct dev_iter *iter)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
struct dev_filter {
|
||||
int (*passes_filter)(struct dev_filter *f, struct device *dev);
|
||||
void (*destroy)(struct dev_filter *f);
|
||||
void *private;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright (C) 2001 Sistina Software
|
||||
*
|
||||
* This file is released under the GPL.
|
||||
* This file is released under the LGPL.
|
||||
*/
|
||||
|
||||
#include "device.h"
|
||||
@@ -13,22 +13,23 @@
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mount.h>
|
||||
#include <linux/fs.h> // UGH!!! for BLKSSZGET
|
||||
|
||||
int dev_get_size(struct device *dev, uint64_t *size)
|
||||
{
|
||||
int fd;
|
||||
long s;
|
||||
const char *name = dev_name(dev);
|
||||
|
||||
log_very_verbose("Getting size of %s", dev->name);
|
||||
if ((fd = open(dev->name, O_RDONLY)) < 0) {
|
||||
log_sys_error("open", dev->name);
|
||||
log_very_verbose("Getting size of %s", name);
|
||||
if ((fd = open(name, O_RDONLY)) < 0) {
|
||||
log_sys_error("open", name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* FIXME: add 64 bit ioctl */
|
||||
if (ioctl(fd, BLKGETSIZE, &s) < 0) {
|
||||
log_sys_error("ioctl BLKGETSIZE", dev->name);
|
||||
log_sys_error("ioctl BLKGETSIZE", name);
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
@@ -38,17 +39,91 @@ int dev_get_size(struct device *dev, uint64_t *size)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int dev_get_sectsize(struct device *dev, uint32_t *size)
|
||||
{
|
||||
int fd;
|
||||
int s;
|
||||
const char *name = dev_name(dev);
|
||||
|
||||
log_very_verbose("Getting size of %s", name);
|
||||
if ((fd = open(name, O_RDONLY)) < 0) {
|
||||
log_sys_error("open", name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ioctl(fd, BLKSSZGET, &s) < 0) {
|
||||
log_sys_error("ioctl BLKSSZGET", name);
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
close(fd);
|
||||
*size = (uint32_t) s;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int dev_open(struct device *dev, int flags)
|
||||
{
|
||||
struct stat buf;
|
||||
const char *name = dev_name_confirmed(dev);
|
||||
|
||||
if (!name) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (dev->fd >= 0) {
|
||||
log_error("Device '%s' has already been opened", name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((stat(name, &buf) < 0) || (buf.st_rdev != dev->dev)) {
|
||||
log_error("%s: stat failed: Has device name changed?", name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((dev->fd = open(name, flags)) < 0) {
|
||||
log_sys_error("open", name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((fstat(dev->fd, &buf) < 0) || (buf.st_rdev != dev->dev)) {
|
||||
log_error("%s: fstat failed: Has device name changed?", name);
|
||||
dev_close(dev);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int dev_close(struct device *dev)
|
||||
{
|
||||
if (dev->fd < 0) {
|
||||
log_error("Attempt to close device '%s' "
|
||||
"which is not open.", dev_name(dev));
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (close(dev->fd))
|
||||
log_sys_error("close", dev_name(dev));
|
||||
|
||||
dev->fd = -1;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* FIXME: factor common code out.
|
||||
*/
|
||||
|
||||
int _read(int fd, void *buf, size_t count)
|
||||
{
|
||||
size_t n = 0;
|
||||
int tot = 0;
|
||||
|
||||
while (tot < count) {
|
||||
n = read(fd, buf, count - tot);
|
||||
do
|
||||
n = read(fd, buf, count - tot);
|
||||
while ((n < 0) && ((errno == EINTR) || (errno == EAGAIN)));
|
||||
|
||||
if (n <= 0)
|
||||
return tot ? tot : n;
|
||||
@@ -63,22 +138,20 @@ int _read(int fd, void *buf, size_t count)
|
||||
int64_t dev_read(struct device *dev, uint64_t offset,
|
||||
int64_t len, void *buffer)
|
||||
{
|
||||
int64_t r;
|
||||
int fd = open(dev->name, O_RDONLY);
|
||||
const char *name = dev_name(dev);
|
||||
int fd = dev->fd;
|
||||
|
||||
if (fd < 0) {
|
||||
log_sys_very_verbose("open", dev->name);
|
||||
log_err("Attempt to read an unopened device (%s).", name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (lseek(fd, offset, SEEK_SET) < 0) {
|
||||
log_sys_error("lseek", dev->name);
|
||||
log_sys_error("lseek", name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
r = _read(fd, buffer, len);
|
||||
close(fd);
|
||||
return r;
|
||||
return _read(fd, buffer, len);
|
||||
}
|
||||
|
||||
int _write(int fd, const void *buf, size_t count)
|
||||
@@ -86,8 +159,14 @@ int _write(int fd, const void *buf, size_t count)
|
||||
size_t n = 0;
|
||||
int tot = 0;
|
||||
|
||||
/* Skip all writes */
|
||||
if (test_mode())
|
||||
return count;
|
||||
|
||||
while (tot < count) {
|
||||
n = write(fd, buf, count - tot);
|
||||
do
|
||||
n = write(fd, buf, count - tot);
|
||||
while ((n < 0) && ((errno == EINTR) || (errno == EAGAIN)));
|
||||
|
||||
if (n <= 0)
|
||||
return tot ? tot : n;
|
||||
@@ -102,20 +181,55 @@ int _write(int fd, const void *buf, size_t count)
|
||||
int64_t dev_write(struct device *dev, uint64_t offset,
|
||||
int64_t len, void *buffer)
|
||||
{
|
||||
int64_t r;
|
||||
int fd = open(dev->name, O_WRONLY);
|
||||
const char *name = dev_name(dev);
|
||||
int fd = dev->fd;
|
||||
|
||||
if (fd < 0) {
|
||||
log_sys_error("open", dev->name);
|
||||
log_error("Attempt to write to unopened device %s", name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (lseek(fd, offset, SEEK_SET) < 0) {
|
||||
log_sys_error("lseek", dev->name);
|
||||
log_sys_error("lseek", name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
r = _write(fd, buffer, len);
|
||||
close(fd);
|
||||
return r;
|
||||
return _write(fd, buffer, len);
|
||||
}
|
||||
|
||||
int dev_zero(struct device *dev, uint64_t offset, int64_t len)
|
||||
{
|
||||
int64_t r, s;
|
||||
char buffer[4096];
|
||||
const char *name = dev_name(dev);
|
||||
int fd = dev->fd;
|
||||
|
||||
if (fd < 0) {
|
||||
log_error("Attempt to zero part of an unopened device %s",
|
||||
name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (lseek(fd, offset, SEEK_SET) < 0) {
|
||||
log_sys_error("lseek", name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
while (1) {
|
||||
s = len > sizeof(buffer) ? sizeof(buffer) : len;
|
||||
r = _write(fd, buffer, s);
|
||||
|
||||
if (r <= 0)
|
||||
break;
|
||||
|
||||
len -= r;
|
||||
if (!len) {
|
||||
r = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* FIXME: Always display error */
|
||||
return (len == 0);
|
||||
}
|
||||
|
||||
@@ -8,35 +8,51 @@
|
||||
#define _LVM_DEVICE_H
|
||||
|
||||
#include "lvm-types.h"
|
||||
#include "list.h"
|
||||
|
||||
/*
|
||||
* All devices in LVM will be represented by one of these.
|
||||
* pointer comparisons are valid.
|
||||
*/
|
||||
struct device {
|
||||
char *name;
|
||||
struct list aliases; /* struct str_list from lvm-types.h */
|
||||
dev_t dev;
|
||||
|
||||
/* private */
|
||||
int fd;
|
||||
};
|
||||
|
||||
struct device_list {
|
||||
struct list list;
|
||||
struct device *dev;
|
||||
};
|
||||
|
||||
/*
|
||||
* All io should use these routines, rather than opening the devices
|
||||
* by hand. You do not have to call an open routine. ATM all io is
|
||||
* immediately flushed.
|
||||
* All io should use these routines.
|
||||
*/
|
||||
int dev_get_size(struct device *dev, uint64_t *size);
|
||||
int dev_get_sectsize(struct device *dev, uint32_t *size);
|
||||
|
||||
int dev_open(struct device *dev, int flags);
|
||||
int dev_close(struct device *dev);
|
||||
|
||||
int64_t dev_read(struct device *dev,
|
||||
uint64_t offset, int64_t len, void *buffer);
|
||||
int64_t dev_write(struct device *dev,
|
||||
uint64_t offset, int64_t len, void *buffer);
|
||||
int dev_zero(struct device *dev, uint64_t offset, int64_t len);
|
||||
|
||||
|
||||
static inline const char *dev_name(struct device *dev) {
|
||||
return list_item(dev->aliases.n, struct str_list)->str;
|
||||
}
|
||||
|
||||
/* Return a valid device name from the alias list; NULL otherwise */
|
||||
const char *dev_name_confirmed(struct device *dev);
|
||||
|
||||
static inline int is_lvm_partition(const char *name) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
#define LVM_DEFAULT_DIR_PREFIX "/dev/"
|
||||
/* FIXME Allow config file override */
|
||||
static inline char *lvm_dir_prefix(void) { return LVM_DEFAULT_DIR_PREFIX; }
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -18,12 +18,15 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
#include "display.h"
|
||||
#include "metadata.h"
|
||||
#include "dbg_malloc.h"
|
||||
#include "log.h"
|
||||
#include "display.h"
|
||||
#include "activate.h"
|
||||
#include "uuid.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
|
||||
#define SIZE_BUF 128
|
||||
|
||||
@@ -59,36 +62,460 @@ char *display_size(unsigned long long size, size_len_t sl)
|
||||
return size_buf;
|
||||
}
|
||||
|
||||
/*
|
||||
* FIXME: this function is badly named, it doesn't display the data it
|
||||
* creates a new uuid string with -'s in it. It would be better if
|
||||
* the destination was passed in as well. EJT
|
||||
*/
|
||||
char *display_uuid(char *uuidstr) {
|
||||
int i, j;
|
||||
char *uuid;
|
||||
void pvdisplay_colons(struct physical_volume *pv)
|
||||
{
|
||||
char uuid[64];
|
||||
|
||||
if ((!uuidstr) || !(uuid = dbg_malloc(NAME_LEN))) {
|
||||
log_error("no memory for uuid display buffer");
|
||||
return NULL;
|
||||
if (!pv)
|
||||
return;
|
||||
|
||||
if (!id_write_format(&pv->id, uuid, sizeof(uuid))) {
|
||||
stack;
|
||||
return;
|
||||
}
|
||||
|
||||
memset(uuid, 0, NAME_LEN);
|
||||
log_print("%s:%s:%" PRIu64 ":-1:%u:%u:-1:%" PRIu64 ":%u:%u:%u:%s",
|
||||
dev_name(pv->dev), pv->vg_name, pv->size,
|
||||
/* FIXME pv->pv_number, Derive or remove? */
|
||||
pv->status, /* FIXME Support old or new format here? */
|
||||
pv->status & ALLOCATABLE_PV, /* FIXME remove? */
|
||||
/* FIXME pv->lv_cur, Remove? */
|
||||
pv->pe_size / 2,
|
||||
pv->pe_count,
|
||||
pv->pe_count - pv->pe_allocated,
|
||||
pv->pe_allocated, *uuid ? uuid : "none");
|
||||
|
||||
i = 6;
|
||||
memcpy(uuid, uuidstr, i);
|
||||
uuidstr += i;
|
||||
|
||||
for (j = 0; j < 6; j++) {
|
||||
uuid[i++] = '-';
|
||||
memcpy(&uuid[i], uuidstr, 4);
|
||||
uuidstr += 4;
|
||||
i += 4;
|
||||
}
|
||||
|
||||
memcpy(&uuid[i], uuidstr, 2);
|
||||
|
||||
/* Caller must free */
|
||||
return uuid;
|
||||
return;
|
||||
}
|
||||
|
||||
void pvdisplay_full(struct physical_volume *pv)
|
||||
{
|
||||
char uuid[64];
|
||||
char *size, *size1; /*, *size2; */
|
||||
|
||||
uint64_t pe_free;
|
||||
|
||||
if (!pv)
|
||||
return;
|
||||
|
||||
if (!id_write_format(&pv->id, uuid, sizeof(uuid))) {
|
||||
stack;
|
||||
return;
|
||||
}
|
||||
|
||||
log_print("--- %sPhysical volume ---", pv->pe_size ? "" : "NEW ");
|
||||
log_print("PV Name %s", dev_name(pv->dev));
|
||||
log_print("VG Name %s%s", pv->vg_name,
|
||||
pv->status & EXPORTED_VG ? " (exported)" : "");
|
||||
|
||||
size = display_size(pv->size / 2, SIZE_SHORT);
|
||||
if (pv->pe_size && pv->pe_count) {
|
||||
size1 = display_size((pv->size - pv->pe_count * pv->pe_size)
|
||||
/ 2, SIZE_SHORT);
|
||||
|
||||
/******** FIXME display LVM on-disk data size
|
||||
size2 = display_size(pv->size / 2, SIZE_SHORT);
|
||||
********/
|
||||
|
||||
log_print("PV Size %s" " / not usable %s", /* [LVM: %s]", */
|
||||
size, size1); /* , size2); */
|
||||
|
||||
dbg_free(size1);
|
||||
/* dbg_free(size2); */
|
||||
} else
|
||||
log_print("PV Size %s", size);
|
||||
dbg_free(size);
|
||||
|
||||
/*********FIXME Anything use this?
|
||||
log_print("PV# %u", pv->pv_number);
|
||||
**********/
|
||||
|
||||
pe_free = pv->pe_count - pv->pe_allocated;
|
||||
if (pv->pe_count && (pv->status & ALLOCATABLE_PV))
|
||||
log_print("Allocatable yes %s",
|
||||
(!pe_free && pv->pe_count) ? "(but full)" : "");
|
||||
else
|
||||
log_print("Allocatable NO");
|
||||
|
||||
/*********FIXME
|
||||
log_print("Cur LV %u", pv->lv_cur);
|
||||
*********/
|
||||
log_print("PE Size (KByte) %" PRIu64, pv->pe_size / 2);
|
||||
log_print("Total PE %u", pv->pe_count);
|
||||
log_print("Free PE %" PRIu64, pe_free);
|
||||
log_print("Allocated PE %u", pv->pe_allocated);
|
||||
|
||||
#ifdef LVM_FUTURE
|
||||
printf("Stale PE %u", pv->pe_stale);
|
||||
#endif
|
||||
|
||||
log_print("PV UUID %s", *uuid ? uuid : "none");
|
||||
log_print(" ");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int pvdisplay_short(struct volume_group *vg, struct physical_volume *pv)
|
||||
{
|
||||
if (!pv)
|
||||
return 0;
|
||||
|
||||
log_print("PV Name %s ", dev_name(pv->dev));
|
||||
/* FIXME pv->pv_number); */
|
||||
log_print("PV Status %sallocatable",
|
||||
(pv->status & ALLOCATABLE_PV) ? "" : "NOT ");
|
||||
log_print("Total PE / Free PE %u / %u",
|
||||
pv->pe_count, pv->pe_count - pv->pe_allocated);
|
||||
|
||||
log_print(" ");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void lvdisplay_colons(struct logical_volume *lv)
|
||||
{
|
||||
int inkernel;
|
||||
struct dm_info info;
|
||||
inkernel = lv_info(lv, &info) && info.exists;
|
||||
|
||||
log_print("%s%s/%s:%s:%d:%d:-1:%d:%" PRIu64 ":%d:-1:%d:%d:%d:%d",
|
||||
lv->vg->cmd->dev_dir,
|
||||
lv->vg->name,
|
||||
lv->name,
|
||||
lv->vg->name,
|
||||
(lv->status & (LVM_READ | LVM_WRITE)) >> 8,
|
||||
inkernel ? 1 : 0,
|
||||
/* FIXME lv->lv_number, */
|
||||
inkernel ? info.open_count : 0, lv->size, lv->le_count,
|
||||
/* FIXME Add num allocated to struct! lv->lv_allocated_le, */
|
||||
((lv->status & ALLOC_STRICT) +
|
||||
(lv->status & ALLOC_CONTIGUOUS) * 2), lv->read_ahead,
|
||||
inkernel ? info.major : -1,
|
||||
inkernel ? info.minor : -1
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
int lvdisplay_full(struct logical_volume *lv)
|
||||
{
|
||||
char *size;
|
||||
uint32_t alloc;
|
||||
struct dm_info info;
|
||||
int inkernel;
|
||||
|
||||
inkernel = lv_info(lv, &info) && info.exists;
|
||||
|
||||
log_print("--- Logical volume ---");
|
||||
|
||||
log_print("LV Name %s%s/%s", lv->vg->cmd->dev_dir,
|
||||
lv->vg->name, lv->name);
|
||||
log_print("VG Name %s", lv->vg->name);
|
||||
|
||||
log_print("LV Write Access %s",
|
||||
(lv->status & LVM_WRITE) ? "read/write" : "read only");
|
||||
|
||||
/******* FIXME Snapshot
|
||||
if (lv->status & (LVM_SNAPSHOT_ORG | LVM_SNAPSHOT)) {
|
||||
if (lvm_tab_vg_read_with_pv_and_lv(vg_name, &vg) < 0) {
|
||||
ret = -LVM_ELV_SHOW_VG_READ_WITH_PV_AND_LV;
|
||||
goto lv_show_end;
|
||||
}
|
||||
printf("LV snapshot status ");
|
||||
if (vg_check_active(vg_name) == TRUE) {
|
||||
vg_t *vg_core;
|
||||
if ((ret = vg_status_with_pv_and_lv(vg_name, &vg_core)) == 0) {
|
||||
lv_t *lv_ptr =
|
||||
vg_core->
|
||||
lv[lv_get_index_by_name(vg_core, lv->lv_name)];
|
||||
if (lv_ptr->lv_access & LV_SNAPSHOT) {
|
||||
if (lv_ptr->lv_status & LV_ACTIVE)
|
||||
printf("active ");
|
||||
else
|
||||
printf("INACTIVE ");
|
||||
}
|
||||
if (lv_ptr->lv_access & LV_SNAPSHOT_ORG) {
|
||||
printf("source of\n");
|
||||
while (lv_ptr->lv_snapshot_next != NULL) {
|
||||
lv_ptr = lv_ptr->lv_snapshot_next;
|
||||
printf(" %s [%s]\n",
|
||||
lv_ptr->lv_name,
|
||||
(lv_ptr->
|
||||
lv_status & LV_ACTIVE) ? "active" :
|
||||
"INACTIVE");
|
||||
}
|
||||
vg_free(vg_core, TRUE);
|
||||
} else {
|
||||
printf("destination for %s\n",
|
||||
lv_ptr->lv_snapshot_org->lv_name);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
printf("INACTIVE ");
|
||||
if (lv->lv_access & LV_SNAPSHOT_ORG)
|
||||
printf("original\n");
|
||||
else
|
||||
printf("snapshot\n");
|
||||
}
|
||||
}
|
||||
***********/
|
||||
|
||||
if (inkernel && info.suspended)
|
||||
log_print("LV Status suspended");
|
||||
else
|
||||
log_print("LV Status %savailable",
|
||||
inkernel ? "" : "NOT ");
|
||||
|
||||
/********* FIXME lv_number
|
||||
log_print("LV # %u", lv->lv_number + 1);
|
||||
************/
|
||||
|
||||
if (inkernel)
|
||||
log_print("# open %u", info.open_count);
|
||||
|
||||
/********
|
||||
#ifdef LVM_FUTURE
|
||||
printf("Mirror copies %u\n", lv->lv_mirror_copies);
|
||||
printf("Consistency recovery ");
|
||||
if (lv->lv_recovery | LV_BADBLOCK_ON)
|
||||
printf("bad blocks\n");
|
||||
else
|
||||
printf("none\n");
|
||||
printf("Schedule %u\n", lv->lv_schedule);
|
||||
#endif
|
||||
********/
|
||||
|
||||
size = display_size(lv->size / 2, SIZE_SHORT);
|
||||
log_print("LV Size %s", size);
|
||||
dbg_free(size);
|
||||
|
||||
log_print("Current LE %u", lv->le_count);
|
||||
|
||||
/********** FIXME allocation
|
||||
log_print("Allocated LE %u", lv->allocated_le);
|
||||
**********/
|
||||
|
||||
/********** FIXME Snapshot
|
||||
if (lv->lv_access & LV_SNAPSHOT) {
|
||||
printf("snapshot chunk size %s\n",
|
||||
(dummy = lvm_show_size(lv->lv_chunk_size / 2, SHORT)));
|
||||
dbg_free(dummy);
|
||||
dummy = NULL;
|
||||
if (lv->lv_remap_end > 0) {
|
||||
lv_remap_ptr = lv->lv_remap_ptr;
|
||||
if (lv_remap_ptr > lv->lv_remap_end)
|
||||
lv_remap_ptr = lv->lv_remap_end;
|
||||
dummy = lvm_show_size(lv_remap_ptr *
|
||||
lv->lv_chunk_size / 2, SHORT);
|
||||
dummy1 = lvm_show_size(lv->lv_remap_end *
|
||||
lv->lv_chunk_size / 2, SHORT);
|
||||
printf("Allocated to snapshot %.2f%% [%s/%s]\n",
|
||||
(float) lv_remap_ptr * 100 / lv->lv_remap_end,
|
||||
dummy, dummy1);
|
||||
dbg_free(dummy);
|
||||
dbg_free(dummy1);
|
||||
dummy =
|
||||
lvm_show_size((vg->
|
||||
lv[lv_get_index_by_number
|
||||
(vg,
|
||||
lv->lv_number)]->lv_size -
|
||||
lv->lv_remap_end * lv->lv_chunk_size) / 2,
|
||||
SHORT);
|
||||
printf("Allocated to COW-table %s\n", dummy);
|
||||
dbg_free(dummy);
|
||||
}
|
||||
}
|
||||
******************/
|
||||
|
||||
log_print("Segments %u", list_size(&lv->segments));
|
||||
|
||||
/********* FIXME Stripes & stripesize for each segment
|
||||
log_print("Stripe size (KByte) %u", lv->stripesize / 2);
|
||||
***********/
|
||||
|
||||
/**************
|
||||
#ifdef LVM_FUTURE
|
||||
printf("Bad block ");
|
||||
if (lv->lv_badblock == LV_BADBLOCK_ON)
|
||||
printf("on\n");
|
||||
else
|
||||
printf("off\n");
|
||||
#endif
|
||||
***************/
|
||||
|
||||
/* FIXME next free == ALLOC_SIMPLE */
|
||||
alloc = lv->status & (ALLOC_STRICT | ALLOC_CONTIGUOUS);
|
||||
log_print("Allocation %s%s%s%s",
|
||||
!(alloc & (ALLOC_STRICT | ALLOC_CONTIGUOUS)) ? "next free" :
|
||||
"", (alloc == ALLOC_STRICT) ? "strict" : "",
|
||||
(alloc == ALLOC_CONTIGUOUS) ? "contiguous" : "",
|
||||
(alloc ==
|
||||
(ALLOC_STRICT | ALLOC_CONTIGUOUS)) ? "strict/contiguous" :
|
||||
"");
|
||||
|
||||
log_print("Read ahead sectors %u", lv->read_ahead);
|
||||
|
||||
/****************
|
||||
#ifdef LVM_FUTURE
|
||||
printf("IO Timeout (seconds) ");
|
||||
if (lv->lv_io_timeout == 0)
|
||||
printf("default\n\n");
|
||||
else
|
||||
printf("%lu\n\n", lv->lv_io_timeout);
|
||||
#endif
|
||||
*************/
|
||||
|
||||
if (inkernel)
|
||||
log_print("Block device %d:%d", info.major,
|
||||
info.minor);
|
||||
|
||||
log_print(" ");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void _display_stripe(struct stripe_segment *seg, int s, const char *pre)
|
||||
{
|
||||
uint32_t len = seg->len / seg->stripes;
|
||||
|
||||
log_print("%sphysical volume\t%s", pre,
|
||||
seg->area[s].pv ? dev_name(seg->area[s].pv->dev) : "Missing");
|
||||
|
||||
if (seg->area[s].pv)
|
||||
log_print("%sphysical extents\t%d to %d", pre,
|
||||
seg->area[s].pe, seg->area[s].pe + len - 1);
|
||||
}
|
||||
|
||||
int lvdisplay_segments(struct logical_volume *lv)
|
||||
{
|
||||
int s;
|
||||
struct list *segh;
|
||||
struct stripe_segment *seg;
|
||||
|
||||
log_print("--- Segments ---");
|
||||
|
||||
list_iterate (segh, &lv->segments) {
|
||||
seg = list_item(segh, struct stripe_segment);
|
||||
|
||||
log_print("logical extent %d to %d:",
|
||||
seg->le, seg->le + seg->len - 1);
|
||||
|
||||
if (seg->stripes == 1)
|
||||
_display_stripe(seg, 0, " ");
|
||||
|
||||
else {
|
||||
log_print(" stripes\t\t%d", seg->stripes);
|
||||
log_print(" stripe size\t\t%d", seg->stripe_size);
|
||||
|
||||
for (s = 0; s < seg->stripes; s++) {
|
||||
log_print(" stripe %d:", s);
|
||||
_display_stripe(seg, s, " ");
|
||||
}
|
||||
}
|
||||
log_print(" ");
|
||||
}
|
||||
|
||||
log_print(" ");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void vgdisplay_extents(struct volume_group *vg)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void vgdisplay_full(struct volume_group *vg)
|
||||
{
|
||||
uint32_t access;
|
||||
char *s1;
|
||||
char uuid[64];
|
||||
|
||||
log_print("--- Volume group ---");
|
||||
log_print("VG Name %s", vg->name);
|
||||
log_print("System ID %s", vg->system_id);
|
||||
access = vg->status & (LVM_READ | LVM_WRITE);
|
||||
log_print("VG Access %s%s%s%s",
|
||||
access == (LVM_READ | LVM_WRITE) ? "read/write" : "",
|
||||
access == LVM_READ ? "read" : "",
|
||||
access == LVM_WRITE ? "write" : "",
|
||||
access == 0 ? "error" : "");
|
||||
log_print("VG Status %s%sresizable",
|
||||
vg->status & EXPORTED_VG ? "exported/" : "",
|
||||
vg->status & RESIZEABLE_VG ? "" : "NOT ");
|
||||
/******* FIXME vg number
|
||||
log_print ("VG # %u\n", vg->vg_number);
|
||||
********/
|
||||
if (vg->status & CLUSTERED) {
|
||||
log_print("Clustered yes");
|
||||
log_print("Shared %s",
|
||||
vg->status & SHARED ? "yes" : "no");
|
||||
}
|
||||
log_print("MAX LV %u", vg->max_lv);
|
||||
log_print("Cur LV %u", vg->lv_count);
|
||||
/****** FIXME Open LVs
|
||||
log_print ( "Open LV %u", vg->lv_open);
|
||||
*******/
|
||||
/****** FIXME Max LV Size
|
||||
log_print ( "MAX LV Size %s",
|
||||
( s1 = display_size ( LVM_LV_SIZE_MAX(vg) / 2, SIZE_SHORT)));
|
||||
free ( s1);
|
||||
*********/
|
||||
log_print("Max PV %u", vg->max_pv);
|
||||
log_print("Cur PV %u", vg->pv_count);
|
||||
/******* FIXME act PVs
|
||||
log_print ( "Act PV %u", vg->pv_act);
|
||||
*********/
|
||||
|
||||
s1 = display_size(vg->extent_count * vg->extent_size / 2, SIZE_SHORT);
|
||||
log_print("VG Size %s", s1);
|
||||
dbg_free(s1);
|
||||
|
||||
s1 = display_size(vg->extent_size / 2, SIZE_SHORT);
|
||||
log_print("PE Size %s", s1);
|
||||
dbg_free(s1);
|
||||
|
||||
log_print("Total PE %u", vg->extent_count);
|
||||
|
||||
s1 =
|
||||
display_size((vg->extent_count - vg->free_count) *
|
||||
vg->extent_size / 2, SIZE_SHORT);
|
||||
log_print("Alloc PE / Size %u / %s",
|
||||
vg->extent_count - vg->free_count, s1);
|
||||
dbg_free(s1);
|
||||
|
||||
s1 = display_size(vg->free_count * vg->extent_size / 2, SIZE_SHORT);
|
||||
log_print("Free PE / Size %u / %s", vg->free_count, s1);
|
||||
dbg_free(s1);
|
||||
|
||||
if (!id_write_format(&vg->id, uuid, sizeof(uuid))) {
|
||||
stack;
|
||||
return;
|
||||
}
|
||||
|
||||
log_print("VG UUID %s", uuid);
|
||||
log_print(" ");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void vgdisplay_colons(struct volume_group *vg)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void vgdisplay_short(struct volume_group *vg)
|
||||
{
|
||||
char *s1, *s2, *s3;
|
||||
s1 = display_size(vg->extent_count * vg->extent_size / 2, SIZE_SHORT);
|
||||
s2 =
|
||||
display_size((vg->extent_count - vg->free_count) * vg->extent_size /
|
||||
2, SIZE_SHORT);
|
||||
s3 = display_size(vg->free_count * vg->extent_size / 2, SIZE_SHORT);
|
||||
log_print("\"%s\" %-9s [%-9s used / %s free]", vg->name,
|
||||
/********* FIXME if "open" print "/used" else print "/idle"??? ******/
|
||||
s1, s2, s3);
|
||||
dbg_free(s1);
|
||||
dbg_free(s2);
|
||||
dbg_free(s3);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -21,11 +21,27 @@
|
||||
#ifndef _LVM_DISPLAY_H
|
||||
#define _LVM_DISPLAY_H
|
||||
|
||||
#include "metadata.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef enum {SIZE_LONG=0, SIZE_SHORT=1} size_len_t;
|
||||
|
||||
/* Specify size in KB */
|
||||
char *display_size(unsigned long long size, size_len_t sl);
|
||||
|
||||
char *display_uuid(char *uuidstr);
|
||||
|
||||
void pvdisplay_colons(struct physical_volume *pv);
|
||||
void pvdisplay_full(struct physical_volume *pv);
|
||||
int pvdisplay_short(struct volume_group *vg, struct physical_volume *pv);
|
||||
|
||||
void lvdisplay_colons(struct logical_volume *lv);
|
||||
int lvdisplay_segments(struct logical_volume *lv);
|
||||
int lvdisplay_full(struct logical_volume *lv);
|
||||
|
||||
void vgdisplay_extents(struct volume_group *vg);
|
||||
void vgdisplay_full(struct volume_group *vg);
|
||||
void vgdisplay_colons(struct volume_group *vg);
|
||||
void vgdisplay_short(struct volume_group *vg);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,278 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2001 Sistina Software
|
||||
*
|
||||
* This LVM library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This LVM library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this LVM library; if not, write to the Free
|
||||
* Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
* MA 02111-1307, USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
#include "display.h"
|
||||
#include "metadata.h"
|
||||
#include "dbg_malloc.h"
|
||||
#include "log.h"
|
||||
|
||||
void pv_display_colons(pv_t * pv)
|
||||
{
|
||||
char *uuid;
|
||||
|
||||
if (!pv)
|
||||
return;
|
||||
|
||||
uuid = display_uuid(pv->pv_uuid);
|
||||
|
||||
printf("%s:%s:%d:%d:%d:%d:%d:%d:%d:%d:%d:%s\n",
|
||||
pv->pv_name,
|
||||
pv->vg_name,
|
||||
pv->pv_size,
|
||||
pv->pv_number,
|
||||
pv->pv_status,
|
||||
pv->pv_allocatable,
|
||||
pv->lv_cur,
|
||||
pv->pe_size / 2,
|
||||
pv->pe_total,
|
||||
pv->pe_total - pv->pe_allocated,
|
||||
pv->pe_allocated, uuid ? uuid : "none");
|
||||
|
||||
dbg_free(uuid);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void pv_display_full(pv_t * pv)
|
||||
{
|
||||
ulong pe_free;
|
||||
char *size = NULL;
|
||||
char *uuid;
|
||||
|
||||
if (!pv)
|
||||
return;
|
||||
|
||||
uuid = display_uuid(pv->pv_uuid);
|
||||
|
||||
printf("--- %sPhysical volume ---\n", pv->pe_size ? "" : "NEW ");
|
||||
printf("PV Name %s\n", pv->pv_name);
|
||||
printf("VG Name %s\n", pv->vg_name);
|
||||
|
||||
size = display_size(pv->pv_size / 2, SIZE_SHORT);
|
||||
printf("PV Size %s", size);
|
||||
dbg_free(size);
|
||||
|
||||
if (pv->pe_size && pv->pe_total) {
|
||||
size =
|
||||
display_size((pv->pv_size - pv->pe_size * pv->pe_total) / 2,
|
||||
SIZE_SHORT);
|
||||
printf(" / NOT usable %s ", size);
|
||||
dbg_free(size);
|
||||
|
||||
size =
|
||||
display_size(
|
||||
(pv->pe_on_disk.base +
|
||||
pv->pe_total * sizeof (pe_disk_t)) / 1024,
|
||||
SIZE_SHORT);
|
||||
printf("[LVM: %s]", size);
|
||||
dbg_free(size);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
printf("PV# %u\n", pv->pv_number);
|
||||
printf("PV Status %savailable\n",
|
||||
(pv->pv_status & PV_ACTIVE) ? "" : "NOT ");
|
||||
|
||||
printf("Allocatable ");
|
||||
pe_free = pv->pe_total - pv->pe_allocated;
|
||||
if (pv->pe_total > 0 && (pv->pv_allocatable & PV_ALLOCATABLE)) {
|
||||
printf("yes");
|
||||
if (pe_free == 0 && pv->pe_total > 0)
|
||||
printf(" (but full)");
|
||||
printf("\n");
|
||||
} else
|
||||
printf("NO\n");
|
||||
|
||||
printf("Cur LV %u\n", pv->lv_cur);
|
||||
printf("PE Size (KByte) %u\n", pv->pe_size / 2);
|
||||
printf("Total PE %u\n", pv->pe_total);
|
||||
printf("Free PE %lu\n", pe_free);
|
||||
printf("Allocated PE %u\n", pv->pe_allocated);
|
||||
|
||||
#ifdef LVM_FUTURE
|
||||
printf("Stale PE %u\n", pv->pe_stale);
|
||||
#endif
|
||||
|
||||
printf("PV UUID %s\n", uuid ? uuid : "none");
|
||||
printf("\n");
|
||||
|
||||
dbg_free(uuid);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*******
|
||||
void pv_display_short(pv_t * pv)
|
||||
{
|
||||
|
||||
if (pv != NULL) {
|
||||
printf("PV Name (#) %s (%u)\n", pv->pv_name,
|
||||
pv->pv_number);
|
||||
printf("PV Status ");
|
||||
if (!(pv->pv_status & PV_ACTIVE))
|
||||
printf("NOT ");
|
||||
printf("available / ");
|
||||
if (!(pv->pv_allocatable & PV_ALLOCATABLE))
|
||||
printf("NOT ");
|
||||
printf("allocatable\n");
|
||||
printf("Total PE / Free PE %u / %u\n",
|
||||
pv->pe_total, pv->pe_total - pv->pe_allocated);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void pv_display_pe(pv_t * pv, pe_disk_t * pe)
|
||||
{
|
||||
int p;
|
||||
|
||||
for (p = 0; p < pv->pe_total; p++)
|
||||
printf("pe#: %4d vg: %s lv: %d le: %d\n",
|
||||
p, pv->vg_name, pe[p].lv_num, pe[p].le_num);
|
||||
|
||||
return;
|
||||
}
|
||||
*******/
|
||||
|
||||
void pv_display_pe_text(pv_t * pv, pe_disk_t * pe, lv_disk_t * lvs)
|
||||
{
|
||||
int flag = 0;
|
||||
int lv_num_last = 0;
|
||||
int p = 0;
|
||||
int pe_free = 0;
|
||||
int *pe_this_count = NULL;
|
||||
int pt = 0;
|
||||
int pt_count = 0;
|
||||
lv_disk_t *lv;
|
||||
char *lv_name_this = NULL;
|
||||
char *lv_names = NULL;
|
||||
char *lv_names_sav = NULL;
|
||||
pe_disk_t *pe_this = NULL;
|
||||
|
||||
if ((pe_this = dbg_malloc(pv->pe_total * sizeof (pe_disk_t))) == NULL) {
|
||||
log_error("pe_this allocation failed");
|
||||
goto pv_display_pe_text_out;
|
||||
}
|
||||
|
||||
if ((pe_this_count = dbg_malloc(pv->pe_total * sizeof (int))) == NULL) {
|
||||
log_error("pe_this_count allocation failed");
|
||||
goto pv_display_pe_text_out;
|
||||
}
|
||||
|
||||
memset(pe_this, 0, pv->pe_total * sizeof (pe_disk_t));
|
||||
memset(pe_this_count, 0, pv->pe_total * sizeof (int));
|
||||
|
||||
/* get PE and LE summaries */
|
||||
pt_count = 0;
|
||||
for (p = pt_count; p < pv->pe_total; p++) {
|
||||
if (pe[p].lv_num != 0) {
|
||||
flag = 0;
|
||||
for (pt = 0; pt < pt_count; pt++) {
|
||||
if (pe_this[pt].lv_num == pe[p].lv_num) {
|
||||
flag = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (flag == 0) {
|
||||
pe_this[pt_count].lv_num = pe[p].lv_num;
|
||||
for (pt = 0; pt < pv->pe_total; pt++)
|
||||
if (pe_this[pt_count].lv_num ==
|
||||
pe[pt].lv_num)
|
||||
pe_this_count[pt_count]++;
|
||||
pt_count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lv = lvs;
|
||||
printf(" --- Distribution of physical volume ---\n"
|
||||
" LV Name LE of LV PE for LV\n");
|
||||
for (pt = 0; pt < pt_count; pt++) {
|
||||
printf(" %-25s ", lv->lv_name);
|
||||
if (strlen(lv->lv_name) > 25)
|
||||
printf("\n ");
|
||||
printf("%-8u %-8d\n",
|
||||
lv->lv_allocated_le,
|
||||
pe_this_count[pt]);
|
||||
if (pe_this[pt].lv_num > lv_num_last) {
|
||||
lv_num_last = pe_this[pt].lv_num;
|
||||
lv_names_sav = lv_names;
|
||||
if ((lv_names = dbg_realloc(lv_names,
|
||||
lv_num_last * NAME_LEN)) ==
|
||||
NULL) {
|
||||
log_error("realloc error in %s [line %d]",
|
||||
__FILE__, __LINE__);
|
||||
goto pv_display_pe_text_out;
|
||||
} else
|
||||
lv_names_sav = NULL;
|
||||
}
|
||||
strcpy(&lv_names[(pe_this[pt].lv_num - 1) * NAME_LEN],
|
||||
lv->lv_name);
|
||||
lv++;
|
||||
}
|
||||
|
||||
printf("\n --- Physical extents ---\n"
|
||||
" PE LV LE Disk sector\n");
|
||||
pe_free = -1;
|
||||
for (p = 0; p < pv->pe_total; p++) {
|
||||
if (pe[p].lv_num != 0) {
|
||||
if (pe_free > -1) {
|
||||
pv_display_pe_free(pe_free, p);
|
||||
pe_free = -1;
|
||||
}
|
||||
lv_name_this = &lv_names[(pe[p].lv_num - 1) * NAME_LEN];
|
||||
printf(" %05d %-25s ", p, lv_name_this);
|
||||
if (strlen(lv_name_this) > 25)
|
||||
printf("\n ");
|
||||
printf("%05d %ld\n", pe[p].le_num,
|
||||
get_pe_offset(p, pv));
|
||||
|
||||
} else if (pe_free == -1)
|
||||
pe_free = p;
|
||||
}
|
||||
|
||||
if (pe_free > 0)
|
||||
pv_display_pe_free(pe_free, p);
|
||||
|
||||
pv_display_pe_text_out:
|
||||
if (lv_names != NULL)
|
||||
dbg_free(lv_names);
|
||||
else if (lv_names_sav != NULL)
|
||||
dbg_free(lv_names_sav);
|
||||
if (pe_this != NULL)
|
||||
dbg_free(pe_this);
|
||||
if (pe_this_count != NULL)
|
||||
dbg_free(pe_this_count);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void pv_display_pe_free(int pe_free, int p)
|
||||
{
|
||||
printf(" %05d free\n", pe_free);
|
||||
|
||||
if (p - pe_free > 1)
|
||||
printf(" .....\n %05d free\n", p - 1);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2001 Sistina Software
|
||||
*
|
||||
* This LVM library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This LVM library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this LVM library; if not, write to the Free
|
||||
* Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
* MA 02111-1307, USA
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _LVM_DISPLAY_METADATA_H
|
||||
#define _LVM_DISPLAY_METADATA_H
|
||||
|
||||
#if 0
|
||||
#include "metadata/metadata.h"
|
||||
|
||||
void pv_display_colons(pv_t * pv);
|
||||
void pv_display_full(pv_t * pv);
|
||||
void pv_show_short(pv_t * pv);
|
||||
void pv_display_pe(pv_t * pv, pe_disk_t * pe);
|
||||
void pv_display_pe_free(int pe_free, int p);
|
||||
void pv_display_pe_text(pv_t * pv, pe_disk_t * pe, lv_disk_t * lvs);
|
||||
|
||||
static inline unsigned long get_pe_offset(ulong p, pv_t *pv)
|
||||
{
|
||||
return pv->pe_start + (p * pv->pe_size);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
71
lib/filters/filter-composite.c
Normal file
71
lib/filters/filter-composite.c
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (C) 2001 Sistina Software (UK) Limited.
|
||||
*
|
||||
* This file is released under the LGPL.
|
||||
*/
|
||||
|
||||
#include "filter-composite.h"
|
||||
#include "dbg_malloc.h"
|
||||
#include "log.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
static int _and_p(struct dev_filter *f, struct device *dev)
|
||||
{
|
||||
struct dev_filter **filters = (struct dev_filter **) f->private;
|
||||
|
||||
while (*filters) {
|
||||
if (!(*filters)->passes_filter(*filters, dev))
|
||||
return 0;
|
||||
filters++;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void _destroy(struct dev_filter *f)
|
||||
{
|
||||
struct dev_filter **filters = (struct dev_filter **) f->private;
|
||||
|
||||
while (*filters) {
|
||||
(*filters)->destroy(*filters);
|
||||
filters++;
|
||||
}
|
||||
|
||||
dbg_free(f->private);
|
||||
dbg_free(f);
|
||||
}
|
||||
|
||||
|
||||
struct dev_filter *composite_filter_create(int n, ...)
|
||||
{
|
||||
struct dev_filter **filters = dbg_malloc(sizeof(*filters) * (n + 1));
|
||||
struct dev_filter *cf;
|
||||
va_list ap;
|
||||
int i;
|
||||
|
||||
if (!filters) {
|
||||
stack;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(cf = dbg_malloc(sizeof(*cf)))) {
|
||||
stack;
|
||||
dbg_free(filters);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
va_start(ap, n);
|
||||
for (i = 0; i < n; i++) {
|
||||
struct dev_filter *f = va_arg(ap, struct dev_filter *);
|
||||
filters[i] = f;
|
||||
}
|
||||
filters[i] = NULL;
|
||||
va_end(ap);
|
||||
|
||||
cf->passes_filter = _and_p;
|
||||
cf->destroy = _destroy;
|
||||
cf->private = filters;
|
||||
|
||||
return cf;
|
||||
}
|
||||
14
lib/filters/filter-composite.h
Normal file
14
lib/filters/filter-composite.h
Normal file
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright (C) 2001 Sistina Software (UK) Limited.
|
||||
*
|
||||
* This file is released under the GPL.
|
||||
*/
|
||||
|
||||
#ifndef _LVM_FILTER_COMPOSITE_H
|
||||
#define _LVM_FILTER_COMPOSITE_H
|
||||
|
||||
#include "dev-cache.h"
|
||||
|
||||
struct dev_filter *composite_filter_create(int n, ...);
|
||||
|
||||
#endif
|
||||
242
lib/filters/filter-persistent.c
Normal file
242
lib/filters/filter-persistent.c
Normal file
@@ -0,0 +1,242 @@
|
||||
/*
|
||||
* Copyright (C) 2001 Sistina Software (UK) Limited.
|
||||
*
|
||||
* This file is released under the LGPL.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "dev-cache.h"
|
||||
#include "hash.h"
|
||||
#include "dbg_malloc.h"
|
||||
#include "log.h"
|
||||
#include "filter-persistent.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
struct pfilter {
|
||||
char *file;
|
||||
struct hash_table *devices;
|
||||
struct dev_filter *real;
|
||||
};
|
||||
|
||||
/*
|
||||
* entries in the table can be in one of these
|
||||
* states.
|
||||
*/
|
||||
#define PF_BAD_DEVICE ((void *) 1)
|
||||
#define PF_GOOD_DEVICE ((void *) 2)
|
||||
|
||||
static int _init_hash(struct pfilter *pf)
|
||||
{
|
||||
if (pf->devices)
|
||||
hash_destroy(pf->devices);
|
||||
|
||||
pf->devices = hash_create(128);
|
||||
return pf->devices ? 1 : 0;
|
||||
}
|
||||
|
||||
int persistent_filter_wipe(struct dev_filter *f)
|
||||
{
|
||||
struct pfilter *pf = (struct pfilter *) f->private;
|
||||
|
||||
hash_wipe(pf->devices);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _read_array(struct pfilter *pf, struct config_file *cf,
|
||||
const char *path, void *data)
|
||||
{
|
||||
struct config_node *cn;
|
||||
struct config_value *cv;
|
||||
|
||||
if (!(cn = find_config_node(cf->root, path, '/'))) {
|
||||
log_very_verbose("Couldn't find %s array in '%s'",
|
||||
path, pf->file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* iterate through the array, adding
|
||||
* devices as we go.
|
||||
*/
|
||||
for (cv = cn->v; cv; cv = cv->next) {
|
||||
if (cv->type != CFG_STRING) {
|
||||
log_verbose("Devices array contains a value "
|
||||
"which is not a string ... ignoring");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!hash_insert(pf->devices, cv->v.str, data))
|
||||
log_verbose("Couldn't add '%s' to filter ... ignoring",
|
||||
cv->v.str);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int persistent_filter_load(struct dev_filter *f)
|
||||
{
|
||||
struct pfilter *pf = (struct pfilter *) f->private;
|
||||
|
||||
int r = 0;
|
||||
struct config_file *cf;
|
||||
|
||||
if (!(cf = create_config_file())) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!read_config(cf, pf->file)) {
|
||||
stack;
|
||||
goto out;
|
||||
}
|
||||
|
||||
_read_array(pf, cf, "persistent_filter_cache/valid_devices",
|
||||
PF_GOOD_DEVICE);
|
||||
_read_array(pf, cf, "persistent_filter_cache/invalid_devices",
|
||||
PF_BAD_DEVICE);
|
||||
|
||||
if (hash_get_num_entries(pf->devices))
|
||||
r = 1;
|
||||
|
||||
out:
|
||||
destroy_config_file(cf);
|
||||
return r;
|
||||
}
|
||||
|
||||
static void _write_array(struct pfilter *pf, FILE *fp, const char *path,
|
||||
void *data)
|
||||
{
|
||||
void *d;
|
||||
int first = 1;
|
||||
struct hash_node *n;
|
||||
|
||||
for (n = hash_get_first(pf->devices); n;
|
||||
n = hash_get_next(pf->devices, n)) {
|
||||
d = hash_get_data(pf->devices, n);
|
||||
|
||||
if (d != data)
|
||||
continue;
|
||||
|
||||
if (!first)
|
||||
fprintf(fp, ",\n");
|
||||
else {
|
||||
fprintf(fp, "\t%s=[\n", path);
|
||||
first = 0;
|
||||
}
|
||||
|
||||
fprintf(fp, "\t\t\"%s\"", hash_get_key(pf->devices, n));
|
||||
}
|
||||
|
||||
if (!first)
|
||||
fprintf(fp, "\n\t]\n");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int persistent_filter_dump(struct dev_filter *f)
|
||||
{
|
||||
struct pfilter *pf = (struct pfilter *) f->private;
|
||||
|
||||
FILE *fp;
|
||||
|
||||
if (!hash_get_num_entries(pf->devices)) {
|
||||
log_very_verbose("Internal persistent device cache empty "
|
||||
"- not writing to %s", pf->file);
|
||||
return 0;
|
||||
}
|
||||
log_very_verbose("Dumping persistent device cache to %s", pf->file);
|
||||
|
||||
fp = fopen(pf->file, "w");
|
||||
if (!fp) {
|
||||
log_sys_error("fopen", pf->file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
fprintf(fp, "# This file is automatically maintained by lvm.\n\n");
|
||||
fprintf(fp, "persistent_filter_cache {\n");
|
||||
|
||||
_write_array(pf, fp, "valid_devices", PF_GOOD_DEVICE);
|
||||
_write_array(pf, fp, "invalid_devices", PF_BAD_DEVICE);
|
||||
|
||||
fprintf(fp, "}\n");
|
||||
fclose(fp);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _lookup_p(struct dev_filter *f, struct device *dev)
|
||||
{
|
||||
struct pfilter *pf = (struct pfilter *) f->private;
|
||||
void *l = hash_lookup(pf->devices, dev_name(dev));
|
||||
struct str_list *sl;
|
||||
struct list *ah;
|
||||
|
||||
if (!l) {
|
||||
l = pf->real->passes_filter(pf->real, dev) ?
|
||||
PF_GOOD_DEVICE : PF_BAD_DEVICE;
|
||||
|
||||
list_iterate(ah, &dev->aliases) {
|
||||
sl = list_item(ah, struct str_list);
|
||||
hash_insert(pf->devices, sl->str, l);
|
||||
}
|
||||
}
|
||||
|
||||
return l == PF_GOOD_DEVICE;
|
||||
}
|
||||
|
||||
static void _destroy(struct dev_filter *f)
|
||||
{
|
||||
struct pfilter *pf = (struct pfilter *) f->private;
|
||||
|
||||
hash_destroy(pf->devices);
|
||||
dbg_free(pf->file);
|
||||
pf->real->destroy(pf->real);
|
||||
dbg_free(pf);
|
||||
dbg_free(f);
|
||||
}
|
||||
|
||||
struct dev_filter *persistent_filter_create(struct dev_filter *real,
|
||||
const char *file)
|
||||
{
|
||||
struct pfilter *pf;
|
||||
struct dev_filter *f = NULL;
|
||||
|
||||
if (!(pf = dbg_malloc(sizeof(*pf)))) {
|
||||
stack;
|
||||
return NULL;
|
||||
}
|
||||
memset(pf, 0, sizeof(*pf));
|
||||
|
||||
if (!(pf->file = dbg_malloc(strlen(file) + 1))) {
|
||||
stack;
|
||||
goto bad;
|
||||
}
|
||||
strcpy(pf->file, file);
|
||||
pf->real = real;
|
||||
|
||||
if (!(_init_hash(pf))) {
|
||||
log_error("Couldn't create hash table for persistent filter.");
|
||||
goto bad;
|
||||
}
|
||||
|
||||
if (!(f = dbg_malloc(sizeof(*f)))) {
|
||||
stack;
|
||||
goto bad;
|
||||
}
|
||||
|
||||
f->passes_filter = _lookup_p;
|
||||
f->destroy = _destroy;
|
||||
f->private = pf;
|
||||
|
||||
return f;
|
||||
|
||||
bad:
|
||||
dbg_free(pf->file);
|
||||
if (pf->devices)
|
||||
hash_destroy(pf->devices);
|
||||
dbg_free(pf);
|
||||
dbg_free(f);
|
||||
return NULL;
|
||||
}
|
||||
19
lib/filters/filter-persistent.h
Normal file
19
lib/filters/filter-persistent.h
Normal file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright (C) 2001 Sistina Software (UK) Limited.
|
||||
*
|
||||
* This file is released under the GPL.
|
||||
*/
|
||||
|
||||
#ifndef _LVM_FILTER_PERSISTENT_H
|
||||
#define _LVM_FILTER_PERSISTENT_H
|
||||
|
||||
#include "dev-cache.h"
|
||||
|
||||
struct dev_filter *persistent_filter_create(struct dev_filter *f,
|
||||
const char *file);
|
||||
|
||||
int persistent_filter_wipe(struct dev_filter *f);
|
||||
int persistent_filter_load(struct dev_filter *f);
|
||||
int persistent_filter_dump(struct dev_filter *f);
|
||||
|
||||
#endif
|
||||
228
lib/filters/filter-regex.c
Normal file
228
lib/filters/filter-regex.c
Normal file
@@ -0,0 +1,228 @@
|
||||
/*
|
||||
* Copyright (C) 2001 Sistina Software (UK) Limited.
|
||||
*
|
||||
* This file is released under the LGPL.
|
||||
*/
|
||||
|
||||
#include "pool.h"
|
||||
#include "filter-regex.h"
|
||||
#include "matcher.h"
|
||||
#include "device.h"
|
||||
#include "bitset.h"
|
||||
#include "log.h"
|
||||
#include "list.h"
|
||||
|
||||
struct rfilter {
|
||||
struct pool *mem;
|
||||
bitset_t accept;
|
||||
struct matcher *engine;
|
||||
};
|
||||
|
||||
static int _extract_pattern(struct pool *mem, const char *pat,
|
||||
char **regex, bitset_t accept, int index)
|
||||
{
|
||||
char sep, *r, *ptr;
|
||||
|
||||
/*
|
||||
* is this an accept or reject pattern
|
||||
*/
|
||||
switch (*pat) {
|
||||
case 'a':
|
||||
bit_set(accept, index);
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
bit_clear(accept, index);
|
||||
break;
|
||||
|
||||
default:
|
||||
log_info("pattern must begin with 'a' or 'r'");
|
||||
return 0;
|
||||
}
|
||||
pat++;
|
||||
|
||||
/*
|
||||
* get the seperator
|
||||
*/
|
||||
switch (*pat) {
|
||||
case '(':
|
||||
sep = ')';
|
||||
break;
|
||||
|
||||
case '[':
|
||||
sep = ']';
|
||||
break;
|
||||
|
||||
case '{':
|
||||
sep = '}';
|
||||
break;
|
||||
|
||||
default:
|
||||
sep = *pat;
|
||||
}
|
||||
pat++;
|
||||
|
||||
/*
|
||||
* copy the regex
|
||||
*/
|
||||
if (!(r = pool_strdup(mem, pat))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* trim the trailing character, having checked it's sep.
|
||||
*/
|
||||
ptr = r + strlen(r) - 1;
|
||||
if (*ptr != sep) {
|
||||
log_info("invalid seperator at end of regex");
|
||||
return 0;
|
||||
}
|
||||
*ptr = '\0';
|
||||
|
||||
regex[index] = r;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _build_matcher(struct rfilter *rf, struct config_value *val)
|
||||
{
|
||||
struct pool *scratch;
|
||||
struct config_value *v;
|
||||
char **regex;
|
||||
int count = 0, i, r = 0;
|
||||
|
||||
if (!(scratch = pool_create(1024))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* count how many patterns we have.
|
||||
*/
|
||||
for (v = val; v; v = v->next) {
|
||||
|
||||
if (v->type != CFG_STRING) {
|
||||
log_info("filter patterns must be enclosed in quotes");
|
||||
goto out;
|
||||
}
|
||||
|
||||
count++;
|
||||
}
|
||||
|
||||
/*
|
||||
* allocate space for them
|
||||
*/
|
||||
if (!(regex = pool_alloc(scratch, sizeof(*regex) * count))) {
|
||||
stack;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/*
|
||||
* create the accept/reject bitset
|
||||
*/
|
||||
rf->accept = bitset_create(rf->mem, count);
|
||||
|
||||
/*
|
||||
* fill the array back to front because we
|
||||
* want the opposite precedence to what
|
||||
* the matcher gives.
|
||||
*/
|
||||
for (v = val, i = count - 1; v; v = v->next, i--)
|
||||
if (!_extract_pattern(scratch, v->v.str,
|
||||
regex, rf->accept, i)) {
|
||||
log_info("invalid filter pattern");
|
||||
goto out;
|
||||
}
|
||||
|
||||
/*
|
||||
* build the matcher.
|
||||
*/
|
||||
if (!(rf->engine = matcher_create(rf->mem,
|
||||
(const char **) regex, count)))
|
||||
stack;
|
||||
r = 1;
|
||||
|
||||
out:
|
||||
pool_destroy(scratch);
|
||||
return r;
|
||||
}
|
||||
|
||||
static int _accept_p(struct dev_filter *f, struct device *dev)
|
||||
{
|
||||
struct list *ah;
|
||||
int m, first = 1, rejected = 0;
|
||||
struct rfilter *rf = (struct rfilter *) f->private;
|
||||
struct str_list *sl;
|
||||
|
||||
list_iterate(ah, &dev->aliases) {
|
||||
sl = list_item(ah, struct str_list);
|
||||
m = matcher_run(rf->engine, sl->str);
|
||||
|
||||
if (m >= 0) {
|
||||
if (bit(rf->accept, m)) {
|
||||
|
||||
if (!first) {
|
||||
list_del(&sl->list);
|
||||
list_add_h(&dev->aliases, &sl->list);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
rejected = 1;
|
||||
}
|
||||
|
||||
first = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* pass everything that doesn't match
|
||||
* anything.
|
||||
*/
|
||||
return !rejected;
|
||||
}
|
||||
|
||||
static void _destroy(struct dev_filter *f)
|
||||
{
|
||||
struct rfilter *rf = (struct rfilter *) f->private;
|
||||
pool_destroy(rf->mem);
|
||||
}
|
||||
|
||||
struct dev_filter *regex_filter_create(struct config_value *patterns)
|
||||
{
|
||||
struct pool *mem = pool_create(10 * 1024);
|
||||
struct rfilter *rf;
|
||||
struct dev_filter *f;
|
||||
|
||||
if (!mem) {
|
||||
stack;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(rf = pool_alloc(mem, sizeof(*rf)))) {
|
||||
stack;
|
||||
goto bad;
|
||||
}
|
||||
|
||||
rf->mem = mem;
|
||||
|
||||
if (!_build_matcher(rf, patterns)) {
|
||||
stack;
|
||||
goto bad;
|
||||
}
|
||||
|
||||
if (!(f = pool_zalloc(mem, sizeof(*f)))) {
|
||||
stack;
|
||||
goto bad;
|
||||
}
|
||||
|
||||
f->passes_filter = _accept_p;
|
||||
f->destroy = _destroy;
|
||||
f->private = rf;
|
||||
return f;
|
||||
|
||||
bad:
|
||||
pool_destroy(mem);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
23
lib/filters/filter-regex.h
Normal file
23
lib/filters/filter-regex.h
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (C) 2001 Sistina Software (UK) Limited.
|
||||
*
|
||||
* This file is released under the GPL.
|
||||
*/
|
||||
|
||||
#ifndef _LVM_FILTER_REGEX_H
|
||||
#define _LVM_FILTER_REGEX_H
|
||||
|
||||
#include "config.h"
|
||||
#include "dev-cache.h"
|
||||
|
||||
/*
|
||||
* patterns must be an array of strings of the form:
|
||||
* [ra]<sep><regex><sep>, eg,
|
||||
* r/cdrom/ - reject cdroms
|
||||
* a|loop/[0-4]| - accept loops 0 to 4
|
||||
* r|.*| - reject everything else
|
||||
*/
|
||||
|
||||
struct dev_filter *regex_filter_create(struct config_value *patterns);
|
||||
|
||||
#endif
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "log.h"
|
||||
#include "dev-cache.h"
|
||||
#include "filter.h"
|
||||
#include "lvm-string.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <dirent.h>
|
||||
@@ -29,6 +30,8 @@
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <fcntl.h>
|
||||
#include <linux/kdev_t.h>
|
||||
|
||||
#define NUMBER_OF_MAJORS 256
|
||||
@@ -38,6 +41,8 @@ typedef struct {
|
||||
int max_partitions;
|
||||
} device_info_t;
|
||||
|
||||
static int _md_major = -1;
|
||||
|
||||
static device_info_t device_info[] = {
|
||||
{"ide", 16}, /* IDE disk */
|
||||
{"sd", 16}, /* SCSI disk */
|
||||
@@ -49,50 +54,68 @@ static device_info_t device_info[] = {
|
||||
{"ida", 16}, /* Compaq SMART2 */
|
||||
{"cciss", 16}, /* Compaq CCISS array */
|
||||
{"ubd", 16}, /* User-mode virtual block device */
|
||||
{"ataraid", 16}, /* ATA Raid */
|
||||
{NULL, 0}
|
||||
};
|
||||
|
||||
static int *scan_proc_dev(void);
|
||||
static int *scan_proc_dev(const char *proc);
|
||||
|
||||
static int passes_config_device_filter(struct dev_filter *f, struct device *dev)
|
||||
static int passes_lvm_type_device_filter(struct dev_filter *f,
|
||||
struct device *dev)
|
||||
{
|
||||
/* FIXME Check against config file scan/reject entries */
|
||||
int fd;
|
||||
const char *name = dev_name(dev);
|
||||
|
||||
/* Is this a recognised device type? */
|
||||
if (!(((int *) f->private)[MAJOR(dev->dev)]))
|
||||
return 0;
|
||||
else
|
||||
return 1;
|
||||
|
||||
/* Check it's accessible */
|
||||
if ((fd = open(name, O_RDONLY)) < 0) {
|
||||
log_debug("Unable to open %s: %s", name, strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
|
||||
close(fd);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct dev_filter *config_filter_create()
|
||||
struct dev_filter *lvm_type_filter_create(const char *proc)
|
||||
{
|
||||
struct dev_filter *f;
|
||||
|
||||
if (!(f = dbg_malloc(sizeof (struct dev_filter)))) {
|
||||
log_error("lvm_v1_filter allocation failed");
|
||||
log_error("LVM type filter allocation failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
f->passes_filter = passes_config_device_filter;
|
||||
f->passes_filter = passes_lvm_type_device_filter;
|
||||
f->destroy = lvm_type_filter_destroy;
|
||||
|
||||
if (!(f->private = scan_proc_dev()))
|
||||
if (!(f->private = scan_proc_dev(proc)))
|
||||
return NULL;
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
void config_filter_destroy(struct dev_filter *f)
|
||||
int md_major(void)
|
||||
{
|
||||
return _md_major;
|
||||
}
|
||||
|
||||
void lvm_type_filter_destroy(struct dev_filter *f)
|
||||
{
|
||||
dbg_free(f->private);
|
||||
dbg_free(f);
|
||||
return;
|
||||
}
|
||||
|
||||
static int *scan_proc_dev(void)
|
||||
static int *scan_proc_dev(const char *proc)
|
||||
{
|
||||
char line[80];
|
||||
FILE *procdevices = NULL;
|
||||
char proc_devices[PATH_MAX];
|
||||
FILE *pd = NULL;
|
||||
int ret = 0;
|
||||
int i, j = 0;
|
||||
int line_maj = 0;
|
||||
@@ -106,13 +129,19 @@ static int *scan_proc_dev(void)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(procdevices = fopen("/proc/devices", "r"))) {
|
||||
log_error("Failed to open /proc/devices: %s", strerror(errno));
|
||||
if (lvm_snprintf(proc_devices, sizeof(proc_devices),
|
||||
"%s/devices", proc) < 0) {
|
||||
log_error("Failed to create /proc/devices string");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(pd = fopen(proc_devices, "r"))) {
|
||||
log_sys_error("fopen", proc_devices);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(max_partitions_by_major, 0, sizeof (int) * NUMBER_OF_MAJORS);
|
||||
while (fgets(line, 80, procdevices) != NULL) {
|
||||
while (fgets(line, 80, pd) != NULL) {
|
||||
i = 0;
|
||||
while (line[i] == ' ' && line[i] != '\0')
|
||||
i++;
|
||||
@@ -134,6 +163,10 @@ static int *scan_proc_dev(void)
|
||||
while (line[i] == ' ' && line[i] != '\0')
|
||||
i++;
|
||||
|
||||
/* Look for md device */
|
||||
if (!strncmp("md", line + i, 2) && isspace(*(line + i + 2)))
|
||||
_md_major = line_maj;
|
||||
|
||||
/* Go through the valid device names and if there is a
|
||||
match store max number of partitions */
|
||||
for (j = 0; device_info[j].name != NULL; j++) {
|
||||
@@ -149,6 +182,6 @@ static int *scan_proc_dev(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose(procdevices);
|
||||
fclose(pd);
|
||||
return max_partitions_by_major;
|
||||
}
|
||||
|
||||
@@ -21,9 +21,11 @@
|
||||
#ifndef _LVM_FILTER_H
|
||||
#define _LVM_FILTER_H
|
||||
|
||||
struct dev_filter *config_filter_create();
|
||||
struct dev_filter *lvm_type_filter_create();
|
||||
|
||||
void config_filter_destroy(struct dev_filter *f);
|
||||
void lvm_type_filter_destroy(struct dev_filter *f);
|
||||
|
||||
int md_major(void);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,13 +1,21 @@
|
||||
/*
|
||||
* Copyright (C) 2001 Sistina Software (UK) Limited.
|
||||
*
|
||||
* This file is released under the GPL.
|
||||
* This file is released under the LGPL.
|
||||
*/
|
||||
|
||||
#include "disk-rep.h"
|
||||
#include "dbg_malloc.h"
|
||||
#include "pool.h"
|
||||
#include "xlate.h"
|
||||
#include "log.h"
|
||||
#include "vgcache.h"
|
||||
#include "filter.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <linux/kdev_t.h>
|
||||
|
||||
#define fail do {stack; return 0;} while(0)
|
||||
#define xx16(v) disk->v = xlate16(disk->v)
|
||||
@@ -19,68 +27,73 @@
|
||||
* between disk and core. The same code works
|
||||
* both ways of course.
|
||||
*/
|
||||
static void _xlate_pv(struct pv_disk *disk)
|
||||
static void _xlate_pvd(struct pv_disk *disk)
|
||||
{
|
||||
xx16(version);
|
||||
xx16(version);
|
||||
|
||||
xx32(pv_on_disk.base); xx32(pv_on_disk.size);
|
||||
xx32(vg_on_disk.base); xx32(vg_on_disk.size);
|
||||
xx32(pv_uuidlist_on_disk.base); xx32(pv_uuidlist_on_disk.size);
|
||||
xx32(lv_on_disk.base); xx32(lv_on_disk.size);
|
||||
xx32(pe_on_disk.base); xx32(pe_on_disk.size);
|
||||
xx32(pv_on_disk.base);
|
||||
xx32(pv_on_disk.size);
|
||||
xx32(vg_on_disk.base);
|
||||
xx32(vg_on_disk.size);
|
||||
xx32(pv_uuidlist_on_disk.base);
|
||||
xx32(pv_uuidlist_on_disk.size);
|
||||
xx32(lv_on_disk.base);
|
||||
xx32(lv_on_disk.size);
|
||||
xx32(pe_on_disk.base);
|
||||
xx32(pe_on_disk.size);
|
||||
|
||||
xx32(pv_major);
|
||||
xx32(pv_number);
|
||||
xx32(pv_status);
|
||||
xx32(pv_allocatable);
|
||||
xx32(pv_size);
|
||||
xx32(lv_cur);
|
||||
xx32(pe_size);
|
||||
xx32(pe_total);
|
||||
xx32(pe_allocated);
|
||||
xx32(pv_major);
|
||||
xx32(pv_number);
|
||||
xx32(pv_status);
|
||||
xx32(pv_allocatable);
|
||||
xx32(pv_size);
|
||||
xx32(lv_cur);
|
||||
xx32(pe_size);
|
||||
xx32(pe_total);
|
||||
xx32(pe_allocated);
|
||||
xx32(pe_start);
|
||||
}
|
||||
|
||||
static void _xlate_lv(struct lv_disk *disk)
|
||||
static void _xlate_lvd(struct lv_disk *disk)
|
||||
{
|
||||
xx32(lv_access);
|
||||
xx32(lv_status);
|
||||
xx32(lv_open);
|
||||
xx32(lv_dev);
|
||||
xx32(lv_number);
|
||||
xx32(lv_mirror_copies);
|
||||
xx32(lv_recovery);
|
||||
xx32(lv_schedule);
|
||||
xx32(lv_size);
|
||||
xx32(lv_snapshot_minor);
|
||||
xx16(lv_chunk_size);
|
||||
xx16(dummy);
|
||||
xx32(lv_allocated_le);
|
||||
xx32(lv_stripes);
|
||||
xx32(lv_stripesize);
|
||||
xx32(lv_badblock);
|
||||
xx32(lv_allocation);
|
||||
xx32(lv_io_timeout);
|
||||
xx32(lv_read_ahead);
|
||||
xx32(lv_access);
|
||||
xx32(lv_status);
|
||||
xx32(lv_open);
|
||||
xx32(lv_dev);
|
||||
xx32(lv_number);
|
||||
xx32(lv_mirror_copies);
|
||||
xx32(lv_recovery);
|
||||
xx32(lv_schedule);
|
||||
xx32(lv_size);
|
||||
xx32(lv_snapshot_minor);
|
||||
xx16(lv_chunk_size);
|
||||
xx16(dummy);
|
||||
xx32(lv_allocated_le);
|
||||
xx32(lv_stripes);
|
||||
xx32(lv_stripesize);
|
||||
xx32(lv_badblock);
|
||||
xx32(lv_allocation);
|
||||
xx32(lv_io_timeout);
|
||||
xx32(lv_read_ahead);
|
||||
}
|
||||
|
||||
static void _xlate_vg(struct vg_disk *disk)
|
||||
static void _xlate_vgd(struct vg_disk *disk)
|
||||
{
|
||||
xx32(vg_number);
|
||||
xx32(vg_access);
|
||||
xx32(vg_status);
|
||||
xx32(lv_max);
|
||||
xx32(lv_cur);
|
||||
xx32(lv_open);
|
||||
xx32(pv_max);
|
||||
xx32(pv_cur);
|
||||
xx32(pv_act);
|
||||
xx32(dummy);
|
||||
xx32(vgda);
|
||||
xx32(pe_size);
|
||||
xx32(pe_total);
|
||||
xx32(pe_allocated);
|
||||
xx32(pvg_total);
|
||||
xx32(vg_number);
|
||||
xx32(vg_access);
|
||||
xx32(vg_status);
|
||||
xx32(lv_max);
|
||||
xx32(lv_cur);
|
||||
xx32(lv_open);
|
||||
xx32(pv_max);
|
||||
xx32(pv_cur);
|
||||
xx32(pv_act);
|
||||
xx32(dummy);
|
||||
xx32(vgda);
|
||||
xx32(pe_size);
|
||||
xx32(pe_total);
|
||||
xx32(pe_allocated);
|
||||
xx32(pvg_total);
|
||||
}
|
||||
|
||||
static void _xlate_extents(struct pe_disk *extents, int count)
|
||||
@@ -119,34 +132,49 @@ static int _munge_formats(struct pv_disk *pvd)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _read_pv(struct disk_list *data)
|
||||
int read_pvd(struct device *dev, struct pv_disk *pvd)
|
||||
{
|
||||
struct pv_disk *pvd = &data->pv;
|
||||
if (dev_read(data->dev, 0, sizeof(*pvd), pvd) != sizeof(*pvd))
|
||||
fail;
|
||||
_xlate_pv(pvd);
|
||||
if (dev_read(dev, 0, sizeof(*pvd), pvd) != sizeof(*pvd)) {
|
||||
log_very_verbose("Failed to read PV data from %s",
|
||||
dev_name(dev));
|
||||
return 0;
|
||||
}
|
||||
|
||||
_xlate_pvd(pvd);
|
||||
|
||||
if (pvd->id[0] != 'H' || pvd->id[1] != 'M') {
|
||||
log_very_verbose("%s does not have a valid PV identifier",
|
||||
dev_name(dev));
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!_munge_formats(pvd)) {
|
||||
log_very_verbose("Unknown metadata version %d found on %s",
|
||||
pvd->version, dev_name(dev));
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _read_lv(struct device *dev, ulong pos, struct lv_disk *disk)
|
||||
static int _read_lvd(struct device *dev, ulong pos, struct lv_disk *disk)
|
||||
{
|
||||
if (dev_read(dev, pos, sizeof(*disk), disk) != sizeof(*disk))
|
||||
fail;
|
||||
|
||||
_xlate_lv(disk);
|
||||
_xlate_lvd(disk);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _read_vg(struct disk_list *data)
|
||||
static int _read_vgd(struct disk_list *data)
|
||||
{
|
||||
struct vg_disk *vgd = &data->vg;
|
||||
unsigned long pos = data->pv.vg_on_disk.base;
|
||||
struct vg_disk *vgd = &data->vgd;
|
||||
ulong pos = data->pvd.vg_on_disk.base;
|
||||
if (dev_read(data->dev, pos, sizeof(*vgd), vgd) != sizeof(*vgd))
|
||||
fail;
|
||||
|
||||
_xlate_vg(vgd);
|
||||
_xlate_vgd(vgd);
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -156,10 +184,10 @@ static int _read_uuids(struct disk_list *data)
|
||||
int num_read = 0;
|
||||
struct uuid_list *ul;
|
||||
char buffer[NAME_LEN];
|
||||
ulong pos = data->pv.pv_uuidlist_on_disk.base;
|
||||
ulong end = pos + data->pv.pv_uuidlist_on_disk.size;
|
||||
ulong pos = data->pvd.pv_uuidlist_on_disk.base;
|
||||
ulong end = pos + data->pvd.pv_uuidlist_on_disk.size;
|
||||
|
||||
while(pos < end && num_read < data->vg.pv_cur) {
|
||||
while (pos < end && num_read < data->vgd.pv_cur) {
|
||||
if (dev_read(data->dev, pos, sizeof(buffer), buffer) !=
|
||||
sizeof(buffer))
|
||||
fail;
|
||||
@@ -168,9 +196,9 @@ static int _read_uuids(struct disk_list *data)
|
||||
fail;
|
||||
|
||||
memcpy(ul->uuid, buffer, NAME_LEN);
|
||||
ul->uuid[NAME_LEN] = '\0';
|
||||
ul->uuid[NAME_LEN - 1] = '\0';
|
||||
|
||||
list_add(&ul->list, &data->uuids);
|
||||
list_add(&data->uuids, &ul->list);
|
||||
|
||||
pos += NAME_LEN;
|
||||
num_read++;
|
||||
@@ -179,37 +207,33 @@ static int _read_uuids(struct disk_list *data)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _check_lv(struct lv_disk *lvd)
|
||||
static inline int _check_lvd(struct lv_disk *lvd)
|
||||
{
|
||||
/* FIXME: add more checks */
|
||||
if (lvd->lv_name[0] == '\0') {
|
||||
log_debug("lv has no name");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
return !(lvd->lv_name[0] == '\0');
|
||||
}
|
||||
|
||||
static int _read_lvs(struct disk_list *data)
|
||||
{
|
||||
int i;
|
||||
unsigned long pos;
|
||||
int i, read = 0;
|
||||
ulong pos;
|
||||
struct lvd_list *ll;
|
||||
struct vg_disk *vgd = &data->vgd;
|
||||
|
||||
for(i = 0; i < data->vg.lv_cur; i++) {
|
||||
pos = data->pv.lv_on_disk.base + (i * sizeof(struct lv_disk));
|
||||
for (i = 0; (i < vgd->lv_max) && (read < vgd->lv_cur); i++) {
|
||||
pos = data->pvd.lv_on_disk.base + (i * sizeof(struct lv_disk));
|
||||
ll = pool_alloc(data->mem, sizeof(*ll));
|
||||
|
||||
if (!ll)
|
||||
fail;
|
||||
|
||||
if (!_read_lv(data->dev, pos, &ll->lv))
|
||||
if (!_read_lvd(data->dev, pos, &ll->lvd))
|
||||
fail;
|
||||
|
||||
if (!_check_lv(&ll->lv))
|
||||
fail;
|
||||
if (!_check_lvd(&ll->lvd))
|
||||
continue;
|
||||
|
||||
list_add(&ll->list, &data->lvs);
|
||||
read++;
|
||||
list_add(&data->lvds, &ll->list);
|
||||
}
|
||||
|
||||
return 1;
|
||||
@@ -217,9 +241,9 @@ static int _read_lvs(struct disk_list *data)
|
||||
|
||||
static int _read_extents(struct disk_list *data)
|
||||
{
|
||||
size_t len = sizeof(struct pe_disk) * data->pv.pe_total;
|
||||
size_t len = sizeof(struct pe_disk) * data->pvd.pe_total;
|
||||
struct pe_disk *extents = pool_alloc(data->mem, len);
|
||||
unsigned long pos = data->pv.pe_on_disk.base;
|
||||
ulong pos = data->pvd.pe_on_disk.base;
|
||||
|
||||
if (!extents)
|
||||
fail;
|
||||
@@ -227,95 +251,194 @@ static int _read_extents(struct disk_list *data)
|
||||
if (dev_read(data->dev, pos, len, extents) != len)
|
||||
fail;
|
||||
|
||||
_xlate_extents(extents, data->pv.pe_total);
|
||||
_xlate_extents(extents, data->pvd.pe_total);
|
||||
data->extents = extents;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct disk_list *read_pv(struct device *dev, struct pool *mem,
|
||||
const char *vg_name)
|
||||
/*
|
||||
* If exported, remove "PV_EXP" from end of VG name
|
||||
*/
|
||||
static void _munge_exported_vg(struct disk_list *data)
|
||||
{
|
||||
int l, s;
|
||||
|
||||
/* Return if PV not in a VG or VG not exported */
|
||||
if ((!*data->pvd.vg_name) ||
|
||||
!(data->vgd.vg_status & VG_EXPORTED))
|
||||
return;
|
||||
|
||||
l = strlen(data->pvd.vg_name);
|
||||
s = sizeof(EXPORTED_TAG);
|
||||
if (!strncmp(data->pvd.vg_name + l - s + 1, EXPORTED_TAG, s))
|
||||
data->pvd.vg_name[l - s + 1] = '\0';
|
||||
|
||||
data->pvd.pv_status |= VG_EXPORTED;
|
||||
}
|
||||
|
||||
static struct disk_list *__read_disk(struct device *dev, struct pool *mem,
|
||||
const char *vg_name)
|
||||
{
|
||||
struct disk_list *data = pool_alloc(mem, sizeof(*data));
|
||||
const char *name = dev_name(dev);
|
||||
|
||||
if (!data) {
|
||||
stack;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
data->dev = dev;
|
||||
data->mem = mem;
|
||||
INIT_LIST_HEAD(&data->uuids);
|
||||
INIT_LIST_HEAD(&data->lvs);
|
||||
list_init(&data->uuids);
|
||||
list_init(&data->lvds);
|
||||
|
||||
if (!_read_pv(data)) {
|
||||
log_debug("Failed to read PV data from %s", dev->name);
|
||||
goto bad;
|
||||
}
|
||||
|
||||
if (data->pv.id[0] != 'H' || data->pv.id[1] != 'M') {
|
||||
log_very_verbose("%s does not have a valid PV identifier",
|
||||
dev->name);
|
||||
goto bad;
|
||||
}
|
||||
|
||||
if (!_munge_formats(&data->pv)) {
|
||||
log_very_verbose("Unknown metadata version %d found on %s",
|
||||
data->pv.version, dev->name);
|
||||
if (!read_pvd(dev, &data->pvd)) {
|
||||
stack;
|
||||
goto bad;
|
||||
}
|
||||
|
||||
/*
|
||||
* is it an orphan ?
|
||||
*/
|
||||
if (data->pv.vg_name == '\0') {
|
||||
log_very_verbose("%s is not a member of any VG", dev->name);
|
||||
return data;
|
||||
if (!*data->pvd.vg_name) {
|
||||
log_very_verbose("%s is not a member of any VG", name);
|
||||
|
||||
/* Update VG cache */
|
||||
vgcache_add(data->pvd.vg_name, dev);
|
||||
|
||||
return (vg_name) ? NULL : data;
|
||||
}
|
||||
|
||||
if (vg_name && strcmp(vg_name, data->pv.vg_name)) {
|
||||
log_very_verbose("%s is not a member of the VG %s",
|
||||
dev->name, vg_name);
|
||||
if (!_read_vgd(data)) {
|
||||
log_error("Failed to read VG data from PV (%s)", name);
|
||||
goto bad;
|
||||
}
|
||||
|
||||
if (!_read_vg(data)) {
|
||||
log_error("Failed to read VG data from PV (%s)", dev->name);
|
||||
/* If VG is exported, set VG name back to the real name */
|
||||
_munge_exported_vg(data);
|
||||
|
||||
/* Update VG cache with what we found */
|
||||
vgcache_add(data->pvd.vg_name, dev);
|
||||
|
||||
if (vg_name && strcmp(vg_name, data->pvd.vg_name)) {
|
||||
log_very_verbose("%s is not a member of the VG %s",
|
||||
name, vg_name);
|
||||
goto bad;
|
||||
}
|
||||
|
||||
if (!_read_uuids(data)) {
|
||||
log_error("Failed to read PV uuid list from %s", dev->name);
|
||||
log_error("Failed to read PV uuid list from %s", name);
|
||||
goto bad;
|
||||
}
|
||||
|
||||
if (!_read_lvs(data)) {
|
||||
log_error("Failed to read LV's from %s", dev->name);
|
||||
log_error("Failed to read LV's from %s", name);
|
||||
goto bad;
|
||||
}
|
||||
|
||||
if (!_read_extents(data)) {
|
||||
log_error("Failed to read extents from %s", dev->name);
|
||||
log_error("Failed to read extents from %s", name);
|
||||
goto bad;
|
||||
}
|
||||
|
||||
log_very_verbose("Found %s in %sVG %s", name,
|
||||
(data->vgd.vg_status & VG_EXPORTED) ? "exported " : "",
|
||||
data->pvd.vg_name);
|
||||
|
||||
return data;
|
||||
|
||||
bad:
|
||||
bad:
|
||||
pool_free(data->mem, data);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct disk_list *read_disk(struct device *dev, struct pool *mem,
|
||||
const char *vg_name)
|
||||
{
|
||||
struct disk_list *r;
|
||||
|
||||
if (!dev_open(dev, O_RDONLY)) {
|
||||
stack;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
r = __read_disk(dev, mem, vg_name);
|
||||
|
||||
if (!dev_close(dev))
|
||||
stack;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static void _add_pv_to_list(struct list *head, struct disk_list *data)
|
||||
{
|
||||
struct list *pvdh;
|
||||
struct pv_disk *pvd;
|
||||
|
||||
list_iterate(pvdh, head) {
|
||||
pvd = &list_item(pvdh, struct disk_list)->pvd;
|
||||
if (!strncmp(data->pvd.pv_uuid, pvd->pv_uuid,
|
||||
sizeof(pvd->pv_uuid))) {
|
||||
if (MAJOR(data->dev->dev) != md_major()) {
|
||||
log_very_verbose("Ignoring duplicate PV %s on "
|
||||
"%s", pvd->pv_uuid,
|
||||
dev_name(data->dev));
|
||||
return;
|
||||
}
|
||||
log_very_verbose("Duplicate PV %s - using md %s",
|
||||
pvd->pv_uuid, dev_name(data->dev));
|
||||
list_del(pvdh);
|
||||
break;
|
||||
}
|
||||
}
|
||||
list_add(head, &data->list);
|
||||
}
|
||||
|
||||
/*
|
||||
* Build a list of pv_d's structures, allocated
|
||||
* from mem. We keep track of the first object
|
||||
* allocated form the pool so we can free off all
|
||||
* the memory if something goes wrong.
|
||||
* Build a list of pv_d's structures, allocated from mem.
|
||||
* We keep track of the first object allocated form the pool
|
||||
* so we can free off all the memory if something goes wrong.
|
||||
*/
|
||||
int read_pvs_in_vg(const char *vg_name, struct dev_filter *filter,
|
||||
struct pool *mem, struct list_head *head)
|
||||
struct pool *mem, struct list *head)
|
||||
{
|
||||
struct dev_iter *iter = dev_iter_create(filter);
|
||||
struct dev_iter *iter;
|
||||
struct device *dev;
|
||||
struct disk_list *data = NULL;
|
||||
|
||||
struct list *pvdh, *pvdh2;
|
||||
|
||||
/* Fast path if we already saw this VG and cached the list of PVs */
|
||||
if ((pvdh = vgcache_find(vg_name))) {
|
||||
list_iterate(pvdh2, pvdh) {
|
||||
dev = list_item(pvdh2, struct pvdev_list)->dev;
|
||||
if (!(data = read_disk(dev, mem, vg_name)))
|
||||
break;
|
||||
_add_pv_to_list(head, data);
|
||||
}
|
||||
|
||||
/* Did we find the whole VG? */
|
||||
if (!vg_name || !*vg_name ||
|
||||
(data && *data->pvd.vg_name &&
|
||||
list_size(head) == data->vgd.pv_cur))
|
||||
return 1;
|
||||
|
||||
/* Something changed. Remove the hints. */
|
||||
list_init(head);
|
||||
vgcache_del(vg_name);
|
||||
}
|
||||
|
||||
if (!(iter = dev_iter_create(filter))) {
|
||||
log_error("read_pvs_in_vg: dev_iter_create failed");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Otherwise do a complete scan */
|
||||
for (dev = dev_iter_get(iter); dev; dev = dev_iter_get(iter)) {
|
||||
if ((data = read_pv(dev, mem, vg_name)))
|
||||
list_add(&data->list, head);
|
||||
if ((data = read_disk(dev, mem, vg_name))) {
|
||||
_add_pv_to_list(head, data);
|
||||
}
|
||||
}
|
||||
dev_iter_destroy(iter);
|
||||
|
||||
@@ -325,17 +448,16 @@ int read_pvs_in_vg(const char *vg_name, struct dev_filter *filter,
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static int _write_vg(struct disk_list *data)
|
||||
static int _write_vgd(struct disk_list *data)
|
||||
{
|
||||
struct vg_disk *vgd = &data->vg;
|
||||
unsigned long pos = data->pv.vg_on_disk.base;
|
||||
struct vg_disk *vgd = &data->vgd;
|
||||
ulong pos = data->pvd.vg_on_disk.base;
|
||||
|
||||
_xlate_vg(vgd);
|
||||
_xlate_vgd(vgd);
|
||||
if (dev_write(data->dev, pos, sizeof(*vgd), vgd) != sizeof(*vgd))
|
||||
fail;
|
||||
|
||||
_xlate_vg(vgd);
|
||||
_xlate_vgd(vgd);
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -343,18 +465,18 @@ static int _write_vg(struct disk_list *data)
|
||||
static int _write_uuids(struct disk_list *data)
|
||||
{
|
||||
struct uuid_list *ul;
|
||||
struct list_head *tmp;
|
||||
ulong pos = data->pv.pv_uuidlist_on_disk.base;
|
||||
ulong end = pos + data->pv.pv_uuidlist_on_disk.size;
|
||||
struct list *uh;
|
||||
ulong pos = data->pvd.pv_uuidlist_on_disk.base;
|
||||
ulong end = pos + data->pvd.pv_uuidlist_on_disk.size;
|
||||
|
||||
list_for_each(tmp, &data->uuids) {
|
||||
list_iterate(uh, &data->uuids) {
|
||||
if (pos >= end) {
|
||||
log_error("Too many uuids to fit on %s",
|
||||
data->dev->name);
|
||||
dev_name(data->dev));
|
||||
return 0;
|
||||
}
|
||||
|
||||
ul = list_entry(tmp, struct uuid_list, list);
|
||||
ul = list_item(uh, struct uuid_list);
|
||||
if (dev_write(data->dev, pos, NAME_LEN, ul->uuid) != NAME_LEN)
|
||||
fail;
|
||||
|
||||
@@ -364,27 +486,34 @@ static int _write_uuids(struct disk_list *data)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _write_lv(struct device *dev, ulong pos, struct lv_disk *disk)
|
||||
static int _write_lvd(struct device *dev, ulong pos, struct lv_disk *disk)
|
||||
{
|
||||
_xlate_lv(disk);
|
||||
_xlate_lvd(disk);
|
||||
if (dev_write(dev, pos, sizeof(*disk), disk) != sizeof(*disk))
|
||||
fail;
|
||||
|
||||
_xlate_lv(disk);
|
||||
_xlate_lvd(disk);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _write_lvs(struct disk_list *data)
|
||||
{
|
||||
struct list_head *tmp;
|
||||
unsigned long pos;
|
||||
struct list *lvh;
|
||||
ulong pos;
|
||||
|
||||
list_for_each(tmp, &data->lvs) {
|
||||
struct lvd_list *ll = list_entry(tmp, struct lvd_list, list);
|
||||
pos = data->pv.lv_on_disk.base;
|
||||
pos = data->pvd.lv_on_disk.base;
|
||||
|
||||
if (!_write_lv(data->dev, pos, &ll->lv))
|
||||
if (!dev_zero(data->dev, pos, data->pvd.lv_on_disk.size)) {
|
||||
log_error("Couldn't zero lv area on device '%s'",
|
||||
dev_name(data->dev));
|
||||
return 0;
|
||||
}
|
||||
|
||||
list_iterate(lvh, &data->lvds) {
|
||||
struct lvd_list *ll = list_item(lvh, struct lvd_list);
|
||||
|
||||
if (!_write_lvd(data->dev, pos, &ll->lvd))
|
||||
fail;
|
||||
|
||||
pos += sizeof(struct lv_disk);
|
||||
@@ -395,48 +524,73 @@ static int _write_lvs(struct disk_list *data)
|
||||
|
||||
static int _write_extents(struct disk_list *data)
|
||||
{
|
||||
size_t len = sizeof(struct pe_disk) * data->pv.pe_total;
|
||||
size_t len = sizeof(struct pe_disk) * data->pvd.pe_total;
|
||||
struct pe_disk *extents = data->extents;
|
||||
unsigned long pos = data->pv.pe_on_disk.base;
|
||||
ulong pos = data->pvd.pe_on_disk.base;
|
||||
|
||||
_xlate_extents(extents, data->pv.pe_total);
|
||||
_xlate_extents(extents, data->pvd.pe_total);
|
||||
if (dev_write(data->dev, pos, len, extents) != len)
|
||||
fail;
|
||||
|
||||
_xlate_extents(extents, data->pv.pe_total);
|
||||
_xlate_extents(extents, data->pvd.pe_total);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _write_pv(struct disk_list *data)
|
||||
static int _write_pvd(struct disk_list *data)
|
||||
{
|
||||
struct pv_disk *disk = &data->pv;
|
||||
char *buf;
|
||||
ulong pos = data->pvd.pv_on_disk.base;
|
||||
ulong size = data->pvd.pv_on_disk.size;
|
||||
|
||||
_xlate_pv(disk);
|
||||
if (dev_write(data->dev, 0, sizeof(*disk), disk) != sizeof(*disk))
|
||||
if(size < sizeof(struct pv_disk)) {
|
||||
log_error("Invalid PV structure size.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Make sure that the gap between the PV structure and
|
||||
the next one is zeroed in order to make non LVM tools
|
||||
happy (idea from AED) */
|
||||
buf = dbg_malloc(size);
|
||||
if(!buf) {
|
||||
log_err("Couldn't allocate temporary PV buffer.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
memset(buf, 0, size);
|
||||
memcpy(buf, &data->pvd, sizeof(struct pv_disk));
|
||||
|
||||
_xlate_pvd((struct pv_disk *)buf);
|
||||
if (dev_write(data->dev, pos, size, buf) != size) {
|
||||
dbg_free(buf);
|
||||
fail;
|
||||
}
|
||||
|
||||
_xlate_pv(disk);
|
||||
|
||||
dbg_free(buf);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _write_all_pv(struct disk_list *data)
|
||||
/*
|
||||
* assumes the device has been opened.
|
||||
*/
|
||||
static int __write_all_pvd(struct disk_list *data)
|
||||
{
|
||||
const char *pv_name = data->dev->name;
|
||||
const char *pv_name = dev_name(data->dev);
|
||||
|
||||
if (!_write_pv(data)) {
|
||||
if (!_write_pvd(data)) {
|
||||
log_error("Failed to write PV structure onto %s", pv_name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!test_mode())
|
||||
vgcache_add(data->pvd.vg_name, data->dev);
|
||||
/*
|
||||
* Stop here for orphan pv's.
|
||||
*/
|
||||
if (data->pv.vg_name[0] == '\0')
|
||||
if (data->pvd.vg_name[0] == '\0')
|
||||
return 1;
|
||||
|
||||
if (!_write_vg(data)) {
|
||||
if (!_write_vgd(data)) {
|
||||
log_error("Failed to write VG data to %s", pv_name);
|
||||
return 0;
|
||||
}
|
||||
@@ -459,22 +613,43 @@ static int _write_all_pv(struct disk_list *data)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* opens the device and hands to the above fn.
|
||||
*/
|
||||
static int _write_all_pvd(struct disk_list *data)
|
||||
{
|
||||
int r;
|
||||
|
||||
if (!dev_open(data->dev, O_WRONLY)) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
r = __write_all_pvd(data);
|
||||
|
||||
if (!dev_close(data->dev))
|
||||
stack;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/*
|
||||
* Writes all the given pv's to disk. Does very
|
||||
* little sanity checking, so make sure correct
|
||||
* data is passed to here.
|
||||
*/
|
||||
int write_pvs(struct list_head *pvs)
|
||||
int write_disks(struct list *pvs)
|
||||
{
|
||||
struct list_head *tmp;
|
||||
struct list *pvh;
|
||||
struct disk_list *dl;
|
||||
|
||||
list_for_each(tmp, pvs) {
|
||||
dl = list_entry(tmp, struct disk_list, list);
|
||||
if (!(_write_all_pv(dl)))
|
||||
list_iterate(pvh, pvs) {
|
||||
dl = list_item(pvh, struct disk_list);
|
||||
if (!(_write_all_pvd(dl)))
|
||||
fail;
|
||||
|
||||
log_debug("Successfully wrote data to %s", dl->dev->name);
|
||||
log_very_verbose("Successfully wrote data to %s",
|
||||
dev_name(dl->dev));
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
@@ -18,9 +18,12 @@
|
||||
#define MAX_LV 256
|
||||
#define MAX_VG 99
|
||||
|
||||
#define MIN_PE_SIZE ( 8192L / SECTOR_SIZE) /* 8 KB in sectors */
|
||||
#define MAX_PE_SIZE ( 16L * 1024L * 1024L / SECTOR_SIZE * 1024)
|
||||
#define MIN_PE_SIZE (8192L / SECTOR_SIZE) /* 8 KB in sectors */
|
||||
#define MAX_PE_SIZE (16L * 1024L * 1024L / SECTOR_SIZE * 1024)
|
||||
#define PE_SIZE_PV_SIZE_REL 5 /* PV size must be at least 5 times PE size */
|
||||
#define MAX_LE_TOTAL 65534 /* 2^16 - 2 */
|
||||
#define MAX_PE_TOTAL ((uint32_t) -2)
|
||||
|
||||
|
||||
#define UNMAPPED_EXTENT 0
|
||||
|
||||
@@ -52,6 +55,9 @@
|
||||
#define PV_ACTIVE 0x01 /* pv_status */
|
||||
#define PV_ALLOCATABLE 0x02 /* pv_allocatable */
|
||||
|
||||
#define EXPORTED_TAG "PV_EXP" /* Identifier for exported PV */
|
||||
#define IMPORTED_TAG "PV_IMP" /* Identifier for imported PV */
|
||||
|
||||
|
||||
struct data_area {
|
||||
uint32_t base;
|
||||
@@ -134,24 +140,24 @@ struct pe_disk {
|
||||
|
||||
|
||||
struct uuid_list {
|
||||
struct list_head list;
|
||||
struct list list;
|
||||
char uuid[NAME_LEN];
|
||||
};
|
||||
|
||||
struct lvd_list {
|
||||
struct list_head list;
|
||||
struct lv_disk lv;
|
||||
struct list list;
|
||||
struct lv_disk lvd;
|
||||
};
|
||||
|
||||
struct disk_list {
|
||||
struct list list;
|
||||
struct pool *mem;
|
||||
struct device *dev;
|
||||
struct list_head list;
|
||||
|
||||
struct pv_disk pv;
|
||||
struct vg_disk vg;
|
||||
struct list_head uuids;
|
||||
struct list_head lvs;
|
||||
struct pv_disk pvd;
|
||||
struct vg_disk vgd;
|
||||
struct list uuids;
|
||||
struct list lvds;
|
||||
struct pe_disk *extents;
|
||||
};
|
||||
|
||||
@@ -178,13 +184,15 @@ int calculate_extent_count(struct physical_volume *pv);
|
||||
* Low level io routines which read/write
|
||||
* disk_lists.
|
||||
*/
|
||||
struct disk_list *read_pv(struct device *dev, struct pool *mem,
|
||||
const char *vg_name);
|
||||
int read_pvd(struct device *dev, struct pv_disk *pvd);
|
||||
|
||||
struct disk_list *read_disk(struct device *dev, struct pool *mem,
|
||||
const char *vg_name);
|
||||
|
||||
int read_pvs_in_vg(const char *vg_name, struct dev_filter *filter,
|
||||
struct pool *mem, struct list_head *results);
|
||||
struct pool *mem, struct list *results);
|
||||
|
||||
int write_pvs(struct list_head *pvs);
|
||||
int write_disks(struct list *pvds);
|
||||
|
||||
|
||||
/*
|
||||
@@ -192,42 +200,45 @@ int write_pvs(struct list_head *pvs);
|
||||
* core structures.
|
||||
*/
|
||||
int import_pv(struct pool *mem, struct device *dev,
|
||||
struct volume_group *vg,
|
||||
struct physical_volume *pv, struct pv_disk *pvd);
|
||||
int export_pv(struct pv_disk *pvd, struct physical_volume *pv);
|
||||
int export_pv(struct pool *mem, struct volume_group *vg,
|
||||
struct pv_disk *pvd, struct physical_volume *pv);
|
||||
|
||||
int import_vg(struct pool *mem,
|
||||
struct volume_group *vg, struct disk_list *dl);
|
||||
struct volume_group *vg, struct disk_list *dl,
|
||||
int partial);
|
||||
int export_vg(struct vg_disk *vgd, struct volume_group *vg);
|
||||
|
||||
int import_lv(struct pool *mem, struct logical_volume *lv,
|
||||
struct lv_disk *lvd);
|
||||
void export_lv(struct lv_disk *lvd, struct volume_group *vg,
|
||||
struct logical_volume *lv, const char *prefix);
|
||||
struct logical_volume *lv, const char *dev_dir);
|
||||
|
||||
int import_extents(struct pool *mem, struct volume_group *vg,
|
||||
struct list_head *pvs);
|
||||
int import_extents(struct pool *mem, struct volume_group *vg,
|
||||
struct list *pvds);
|
||||
int export_extents(struct disk_list *dl, int lv_num,
|
||||
struct logical_volume *lv,
|
||||
struct physical_volume *pv);
|
||||
|
||||
int import_pvs(struct pool *mem, struct list_head *pvs,
|
||||
struct list_head *results, int *count);
|
||||
int import_pvs(struct pool *mem, struct volume_group *vg,
|
||||
struct list *pvds, struct list *results, int *count);
|
||||
|
||||
int import_lvs(struct pool *mem, struct volume_group *vg,
|
||||
struct list_head *pvs);
|
||||
struct list *pvds);
|
||||
int export_lvs(struct disk_list *dl, struct volume_group *vg,
|
||||
struct physical_volume *pv, const char *prefix);
|
||||
struct physical_volume *pv, const char *dev_dir);
|
||||
|
||||
int export_uuids(struct disk_list *dl, struct volume_group *vg);
|
||||
|
||||
void export_numbers(struct list_head *pvs, struct volume_group *vg);
|
||||
void export_numbers(struct list *pvds, struct volume_group *vg);
|
||||
|
||||
void export_pv_act(struct list_head *pvs);
|
||||
void export_pv_act(struct list *pvds);
|
||||
|
||||
/* blech */
|
||||
int get_free_vg_number(struct dev_filter *filter, const char *candidate_vg,
|
||||
int *result);
|
||||
int export_vg_number(struct list_head *pvs, const char *vg_name,
|
||||
int export_vg_number(struct list *pvds, const char *vg_name,
|
||||
struct dev_filter *filter);
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright (C) 2001 Sistina Software (UK) Limited.
|
||||
*
|
||||
* This file is released under the GPL.
|
||||
* This file is released under the LGPL.
|
||||
*/
|
||||
|
||||
#include "disk-rep.h"
|
||||
@@ -13,42 +13,79 @@
|
||||
#include "display.h"
|
||||
|
||||
/* VG consistency checks */
|
||||
static int _check_vgs(struct list_head *pvs)
|
||||
static int _check_vgs(struct list *pvs, int *partial)
|
||||
{
|
||||
struct list_head *tmp;
|
||||
struct disk_list *dl;
|
||||
struct list *pvh, *t;
|
||||
struct disk_list *dl = NULL;
|
||||
struct disk_list *first = NULL;
|
||||
|
||||
int pv_count = 0;
|
||||
int exported = -1;
|
||||
|
||||
/* check all the vg's are the same */
|
||||
list_for_each(tmp, pvs) {
|
||||
dl = list_entry(tmp, struct disk_list, list);
|
||||
*partial = 0;
|
||||
|
||||
/*
|
||||
* If there are exported and unexported PVs, ignore exported ones.
|
||||
* This means an active VG won't be affected if disks are inserted
|
||||
* bearing an exported VG with the same name.
|
||||
*/
|
||||
list_iterate(pvh, pvs) {
|
||||
dl = list_item(pvh, struct disk_list);
|
||||
|
||||
if (exported < 0) {
|
||||
exported = dl->pvd.pv_status & VG_EXPORTED;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (exported != (dl->pvd.pv_status & VG_EXPORTED)) {
|
||||
/* Remove exported PVs */
|
||||
list_iterate_safe(pvh, t, pvs) {
|
||||
dl = list_item(pvh, struct disk_list);
|
||||
if (dl->pvd.pv_status & VG_EXPORTED)
|
||||
list_del(pvh);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Remove any PVs with VG structs that differ from the first */
|
||||
list_iterate_safe(pvh, t, pvs) {
|
||||
dl = list_item(pvh, struct disk_list);
|
||||
|
||||
if (!first)
|
||||
first = dl;
|
||||
else if (memcmp(&first->vg, &dl->vg, sizeof(first->vg))) {
|
||||
log_err("VG data differs between PVs %s and %s",
|
||||
first->dev->name, dl->dev->name);
|
||||
|
||||
else if (memcmp(&first->vgd, &dl->vgd, sizeof(first->vgd))) {
|
||||
log_error("VG data differs between PVs %s and %s",
|
||||
dev_name(first->dev), dev_name(dl->dev));
|
||||
list_del(pvh);
|
||||
if (partial_mode()) {
|
||||
*partial = 1;
|
||||
continue;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
pv_count++;
|
||||
}
|
||||
|
||||
/* On entry to fn, list known to be non-empty */
|
||||
if (!(pv_count == dl->vg.pv_cur)) {
|
||||
log_error("Only %d out of %d PV(s) found for VG %s",
|
||||
pv_count, dl->vg.pv_cur, dl->pv.vg_name);
|
||||
return 0;
|
||||
if (pv_count != dl->vgd.pv_cur) {
|
||||
log_error("%d PV(s) found for VG %s: expected %d",
|
||||
pv_count, dl->pvd.vg_name, dl->vgd.pv_cur);
|
||||
if (!partial_mode())
|
||||
return 0;
|
||||
*partial = 1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static struct volume_group *_build_vg(struct pool *mem, struct list_head *pvs)
|
||||
static struct volume_group *_build_vg(struct pool *mem, struct list *pvs)
|
||||
{
|
||||
struct volume_group *vg = pool_alloc(mem, sizeof(*vg));
|
||||
struct disk_list *dl;
|
||||
int partial;
|
||||
|
||||
if (!vg)
|
||||
goto bad;
|
||||
@@ -56,20 +93,20 @@ static struct volume_group *_build_vg(struct pool *mem, struct list_head *pvs)
|
||||
if (list_empty(pvs))
|
||||
goto bad;
|
||||
|
||||
dl = list_entry(pvs->next, struct disk_list, list);
|
||||
|
||||
memset(vg, 0, sizeof(*vg));
|
||||
|
||||
INIT_LIST_HEAD(&vg->pvs);
|
||||
INIT_LIST_HEAD(&vg->lvs);
|
||||
list_init(&vg->pvs);
|
||||
list_init(&vg->lvs);
|
||||
|
||||
if (!_check_vgs(pvs))
|
||||
if (!_check_vgs(pvs, &partial))
|
||||
goto bad;
|
||||
|
||||
if (!import_vg(mem, vg, dl))
|
||||
dl = list_item(pvs->n, struct disk_list);
|
||||
|
||||
if (!import_vg(mem, vg, dl, partial))
|
||||
goto bad;
|
||||
|
||||
if (!import_pvs(mem, pvs, &vg->pvs, &vg->pv_count))
|
||||
if (!import_pvs(mem, vg, pvs, &vg->pvs, &vg->pv_count))
|
||||
goto bad;
|
||||
|
||||
if (!import_lvs(mem, vg, pvs))
|
||||
@@ -86,37 +123,42 @@ static struct volume_group *_build_vg(struct pool *mem, struct list_head *pvs)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct volume_group *_vg_read(struct io_space *is, const char *vg_name)
|
||||
static struct volume_group *_vg_read(struct format_instance *fi,
|
||||
const char *vg_name)
|
||||
{
|
||||
struct pool *mem = pool_create(1024 * 10);
|
||||
struct list_head pvs;
|
||||
struct volume_group *vg;
|
||||
INIT_LIST_HEAD(&pvs);
|
||||
struct list pvs;
|
||||
struct volume_group *vg = NULL;
|
||||
list_init(&pvs);
|
||||
|
||||
if (!mem) {
|
||||
stack;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Strip prefix if present */
|
||||
if (!strncmp(vg_name, is->prefix, strlen(is->prefix)))
|
||||
vg_name += strlen(is->prefix);
|
||||
/* Strip dev_dir if present */
|
||||
vg_name = strip_dir(vg_name, fi->cmd->dev_dir);
|
||||
|
||||
if (!read_pvs_in_vg(vg_name, is->filter, mem, &pvs)) {
|
||||
if (!read_pvs_in_vg(vg_name, fi->cmd->filter, mem, &pvs)) {
|
||||
stack;
|
||||
return NULL;
|
||||
goto bad;
|
||||
}
|
||||
|
||||
if (!(vg = _build_vg(is->mem, &pvs)))
|
||||
if (!(vg = _build_vg(fi->cmd->mem, &pvs))) {
|
||||
stack;
|
||||
goto bad;
|
||||
}
|
||||
|
||||
vg->cmd = fi->cmd;
|
||||
|
||||
bad:
|
||||
pool_destroy(mem);
|
||||
return vg;
|
||||
}
|
||||
|
||||
static struct disk_list *_flatten_pv(struct pool *mem, struct volume_group *vg,
|
||||
struct physical_volume *pv,
|
||||
const char *prefix)
|
||||
const char *dev_dir)
|
||||
{
|
||||
struct disk_list *dl = pool_alloc(mem, sizeof(*dl));
|
||||
|
||||
@@ -128,13 +170,13 @@ static struct disk_list *_flatten_pv(struct pool *mem, struct volume_group *vg,
|
||||
dl->mem = mem;
|
||||
dl->dev = pv->dev;
|
||||
|
||||
INIT_LIST_HEAD(&dl->uuids);
|
||||
INIT_LIST_HEAD(&dl->lvs);
|
||||
list_init(&dl->uuids);
|
||||
list_init(&dl->lvds);
|
||||
|
||||
if (!export_pv(&dl->pv, pv) ||
|
||||
!export_vg(&dl->vg, vg) ||
|
||||
if (!export_pv(mem, vg, &dl->pvd, pv) ||
|
||||
!export_vg(&dl->vgd, vg) ||
|
||||
!export_uuids(dl, vg) ||
|
||||
!export_lvs(dl, vg, pv, prefix) ||
|
||||
!export_lvs(dl, vg, pv, dev_dir) ||
|
||||
!calculate_layout(dl)) {
|
||||
stack;
|
||||
pool_free(mem, dl);
|
||||
@@ -145,28 +187,28 @@ static struct disk_list *_flatten_pv(struct pool *mem, struct volume_group *vg,
|
||||
}
|
||||
|
||||
static int _flatten_vg(struct pool *mem, struct volume_group *vg,
|
||||
struct list_head *pvs, const char *prefix,
|
||||
struct list *pvds, const char *dev_dir,
|
||||
struct dev_filter *filter)
|
||||
{
|
||||
struct list_head *tmp;
|
||||
struct list *pvh;
|
||||
struct pv_list *pvl;
|
||||
struct disk_list *data;
|
||||
|
||||
list_for_each(tmp, &vg->pvs) {
|
||||
pvl = list_entry(tmp, struct pv_list, list);
|
||||
list_iterate(pvh, &vg->pvs) {
|
||||
pvl = list_item(pvh, struct pv_list);
|
||||
|
||||
if (!(data = _flatten_pv(mem, vg, &pvl->pv, prefix))) {
|
||||
if (!(data = _flatten_pv(mem, vg, pvl->pv, dev_dir))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
list_add(&data->list, pvs);
|
||||
list_add(pvds, &data->list);
|
||||
}
|
||||
|
||||
export_numbers(pvs, vg);
|
||||
export_pv_act(pvs);
|
||||
export_numbers(pvds, vg);
|
||||
export_pv_act(pvds);
|
||||
|
||||
if (!export_vg_number(pvs, vg->name, filter)) {
|
||||
if (!export_vg_number(pvds, vg->name, filter)) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
@@ -174,10 +216,10 @@ static int _flatten_vg(struct pool *mem, struct volume_group *vg,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _vg_write(struct io_space *is, struct volume_group *vg)
|
||||
static int _vg_write(struct format_instance *fi, struct volume_group *vg)
|
||||
{
|
||||
struct pool *mem = pool_create(1024 * 10);
|
||||
struct list_head pvs;
|
||||
struct list pvds;
|
||||
int r = 0;
|
||||
|
||||
if (!mem) {
|
||||
@@ -185,59 +227,65 @@ static int _vg_write(struct io_space *is, struct volume_group *vg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
INIT_LIST_HEAD(&pvs);
|
||||
if (vg->status & PARTIAL_VG) {
|
||||
log_error("Cannot change metadata for partial volume group %s",
|
||||
vg->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
r = (_flatten_vg(mem, vg, &pvs, is->prefix, is->filter) &&
|
||||
write_pvs(&pvs));
|
||||
list_init(&pvds);
|
||||
|
||||
r = (_flatten_vg(mem, vg, &pvds, fi->cmd->dev_dir, fi->cmd->filter) &&
|
||||
write_disks(&pvds));
|
||||
pool_destroy(mem);
|
||||
return r;
|
||||
}
|
||||
|
||||
static struct physical_volume *_pv_read(struct io_space *is,
|
||||
static struct physical_volume *_pv_read(struct format_instance *fi,
|
||||
const char *name)
|
||||
{
|
||||
struct pool *mem = pool_create(1024);
|
||||
struct physical_volume *pv;
|
||||
struct physical_volume *pv = NULL;
|
||||
struct disk_list *dl;
|
||||
struct device *dev;
|
||||
|
||||
log_very_verbose("Reading physical volume data %s from disk", name);
|
||||
|
||||
if (!mem) {
|
||||
stack;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(dev = dev_cache_get(name, is->filter))) {
|
||||
if (!(dev = dev_cache_get(name, fi->cmd->filter))) {
|
||||
stack;
|
||||
goto bad;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!(dl = read_pv(dev, mem, NULL))) {
|
||||
if (!(dl = read_disk(dev, mem, NULL))) {
|
||||
stack;
|
||||
goto bad;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!(pv = pool_alloc(is->mem, sizeof(*pv)))) {
|
||||
if (!(pv = pool_alloc(fi->cmd->mem, sizeof(*pv)))) {
|
||||
stack;
|
||||
goto bad;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!import_pv(is->mem, dl->dev, pv, &dl->pv)) {
|
||||
if (!import_pv(fi->cmd->mem, dl->dev, NULL, pv, &dl->pvd)) {
|
||||
stack;
|
||||
goto bad;
|
||||
pool_free(fi->cmd->mem, pv);
|
||||
pv = NULL;
|
||||
}
|
||||
|
||||
out:
|
||||
pool_destroy(mem);
|
||||
return pv;
|
||||
|
||||
bad:
|
||||
pool_destroy(mem);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct list_head *_get_pvs(struct io_space *is)
|
||||
static struct list *_get_pvs(struct format_instance *fi)
|
||||
{
|
||||
struct pool *mem = pool_create(1024 * 10);
|
||||
struct list_head pvs, *results;
|
||||
struct list pvs, *results;
|
||||
uint32_t count;
|
||||
|
||||
if (!mem) {
|
||||
@@ -245,21 +293,21 @@ static struct list_head *_get_pvs(struct io_space *is)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(results = pool_alloc(is->mem, sizeof(*results)))) {
|
||||
if (!(results = pool_alloc(fi->cmd->mem, sizeof(*results)))) {
|
||||
stack;
|
||||
pool_destroy(mem);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
INIT_LIST_HEAD(&pvs);
|
||||
INIT_LIST_HEAD(results);
|
||||
list_init(&pvs);
|
||||
list_init(results);
|
||||
|
||||
if (!read_pvs_in_vg(NULL, is->filter, mem, &pvs)) {
|
||||
if (!read_pvs_in_vg(NULL, fi->cmd->filter, mem, &pvs)) {
|
||||
stack;
|
||||
goto bad;
|
||||
}
|
||||
|
||||
if (!import_pvs(is->mem, &pvs, results, &count)) {
|
||||
if (!import_pvs(fi->cmd->mem, NULL, &pvs, results, &count)) {
|
||||
stack;
|
||||
goto bad;
|
||||
}
|
||||
@@ -268,18 +316,18 @@ static struct list_head *_get_pvs(struct io_space *is)
|
||||
return results;
|
||||
|
||||
bad:
|
||||
pool_free(mem, results);
|
||||
pool_free(fi->cmd->mem, results);
|
||||
pool_destroy(mem);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int _find_vg_name(struct list_head *names, const char *vg)
|
||||
static int _find_vg_name(struct list *names, const char *vg)
|
||||
{
|
||||
struct list_head *tmp;
|
||||
struct list *nh;
|
||||
struct name_list *nl;
|
||||
|
||||
list_for_each(tmp, names) {
|
||||
nl = list_entry(tmp, struct name_list, list);
|
||||
list_iterate(nh, names) {
|
||||
nl = list_item(nh, struct name_list);
|
||||
if (!strcmp(nl->name, vg))
|
||||
return 1;
|
||||
}
|
||||
@@ -287,10 +335,10 @@ static int _find_vg_name(struct list_head *names, const char *vg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct list_head *_get_vgs(struct io_space *is)
|
||||
static struct list *_get_vgs(struct format_instance *fi)
|
||||
{
|
||||
struct list_head *tmp, *pvs;
|
||||
struct list_head *names = pool_alloc(is->mem, sizeof(*names));
|
||||
struct list *pvh;
|
||||
struct list *pvs, *names = pool_alloc(fi->cmd->mem, sizeof(*names));
|
||||
struct name_list *nl;
|
||||
|
||||
if (!names) {
|
||||
@@ -298,31 +346,32 @@ static struct list_head *_get_vgs(struct io_space *is)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
INIT_LIST_HEAD(names);
|
||||
list_init(names);
|
||||
|
||||
if (!(pvs = _get_pvs(is))) {
|
||||
if (!(pvs = _get_pvs(fi))) {
|
||||
stack;
|
||||
goto bad;
|
||||
}
|
||||
|
||||
list_for_each(tmp, pvs) {
|
||||
struct pv_list *pvl = list_entry(tmp, struct pv_list, list);
|
||||
list_iterate(pvh, pvs) {
|
||||
struct pv_list *pvl = list_item(pvh, struct pv_list);
|
||||
|
||||
if (!(*pvl->pv.vg_name) ||
|
||||
_find_vg_name(names, pvl->pv.vg_name))
|
||||
if (!(*pvl->pv->vg_name) ||
|
||||
_find_vg_name(names, pvl->pv->vg_name))
|
||||
continue;
|
||||
|
||||
if (!(nl = pool_alloc(is->mem, sizeof(*nl)))) {
|
||||
if (!(nl = pool_alloc(fi->cmd->mem, sizeof(*nl)))) {
|
||||
stack;
|
||||
goto bad;
|
||||
}
|
||||
|
||||
if (!(nl->name = pool_strdup(is->mem, pvl->pv.vg_name))) {
|
||||
if (!(nl->name = pool_strdup(fi->cmd->mem,
|
||||
pvl->pv->vg_name))) {
|
||||
stack;
|
||||
goto bad;
|
||||
}
|
||||
|
||||
list_add(&nl->list, names);
|
||||
list_add(names, &nl->list);
|
||||
}
|
||||
|
||||
if (list_empty(names))
|
||||
@@ -331,11 +380,11 @@ static struct list_head *_get_vgs(struct io_space *is)
|
||||
return names;
|
||||
|
||||
bad:
|
||||
pool_free(is->mem, names);
|
||||
pool_free(fi->cmd->mem, names);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int _pv_setup(struct io_space *is, struct physical_volume *pv,
|
||||
static int _pv_setup(struct format_instance *fi, struct physical_volume *pv,
|
||||
struct volume_group *vg)
|
||||
{
|
||||
/*
|
||||
@@ -349,26 +398,39 @@ static int _pv_setup(struct io_space *is, struct physical_volume *pv,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _pv_write(struct io_space *is, struct physical_volume *pv)
|
||||
static int _lv_setup(struct format_instance *fi, struct logical_volume *lv)
|
||||
{
|
||||
if (lv->le_count > MAX_LE_TOTAL) {
|
||||
log_error("logical volumes cannot contain more than "
|
||||
"%d extents.", MAX_LE_TOTAL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _pv_write(struct format_instance *fi, struct physical_volume *pv)
|
||||
{
|
||||
struct pool *mem;
|
||||
struct disk_list *dl;
|
||||
struct list_head pvs;
|
||||
struct list pvs;
|
||||
|
||||
INIT_LIST_HEAD(&pvs);
|
||||
list_init(&pvs);
|
||||
|
||||
if (*pv->vg_name) {
|
||||
log_error("Assertion failed: can't _pv_write non-orphan PV "
|
||||
if (*pv->vg_name || pv->pe_allocated ) {
|
||||
log_error("Assertion failed: can't _pv_write non-orphan PV "
|
||||
"(in VG %s)", pv->vg_name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Ensure any residual PE structure is gone */
|
||||
pv->pe_size = pv->pe_count = pv->pe_start = 0;
|
||||
|
||||
if (!(mem = pool_create(1024))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
if (!(dl = pool_alloc(mem, sizeof(*dl)))) {
|
||||
stack;
|
||||
goto bad;
|
||||
@@ -376,13 +438,18 @@ static int _pv_write(struct io_space *is, struct physical_volume *pv)
|
||||
dl->mem = mem;
|
||||
dl->dev = pv->dev;
|
||||
|
||||
if (!export_pv(&dl->pv, pv)) {
|
||||
if (!export_pv(mem, NULL, &dl->pvd, pv)) {
|
||||
stack;
|
||||
goto bad;
|
||||
}
|
||||
|
||||
list_add(&dl->list, &pvs);
|
||||
if (!write_pvs(&pvs)) {
|
||||
/* must be set to be able to zero gap after PV structure in
|
||||
dev_write in order to make other disk tools happy */
|
||||
dl->pvd.pv_on_disk.base = METADATA_BASE;
|
||||
dl->pvd.pv_on_disk.size = PV_SIZE;
|
||||
|
||||
list_add(&pvs, &dl->list);
|
||||
if (!write_disks(&pvs)) {
|
||||
stack;
|
||||
goto bad;
|
||||
}
|
||||
@@ -395,7 +462,7 @@ static int _pv_write(struct io_space *is, struct physical_volume *pv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _vg_setup(struct io_space *is, struct volume_group *vg)
|
||||
int _vg_setup(struct format_instance *fi, struct volume_group *vg)
|
||||
{
|
||||
/* just check max_pv and max_lv */
|
||||
if (vg->max_lv >= MAX_LV)
|
||||
@@ -408,7 +475,7 @@ int _vg_setup(struct io_space *is, struct volume_group *vg)
|
||||
char *dummy, *dummy2;
|
||||
|
||||
log_error("Extent size must be between %s and %s",
|
||||
(dummy = display_size(MIN_PE_SIZE / 2, SIZE_SHORT)),
|
||||
(dummy = display_size(MIN_PE_SIZE / 2, SIZE_SHORT)),
|
||||
(dummy2 = display_size(MAX_PE_SIZE / 2, SIZE_SHORT)));
|
||||
|
||||
dbg_free(dummy);
|
||||
@@ -433,39 +500,37 @@ int _vg_setup(struct io_space *is, struct volume_group *vg)
|
||||
return 1;
|
||||
}
|
||||
|
||||
void _destroy(struct io_space *ios)
|
||||
void _destroy(struct format_instance *fi)
|
||||
{
|
||||
dbg_free(ios->prefix);
|
||||
pool_destroy(ios->mem);
|
||||
dbg_free(ios);
|
||||
dbg_free(fi);
|
||||
}
|
||||
|
||||
struct io_space *create_lvm1_format(const char *prefix, struct pool *mem,
|
||||
struct dev_filter *filter)
|
||||
|
||||
static struct format_handler _format1_ops = {
|
||||
get_vgs: _get_vgs,
|
||||
get_pvs: _get_pvs,
|
||||
pv_read: _pv_read,
|
||||
pv_setup: _pv_setup,
|
||||
pv_write: _pv_write,
|
||||
lv_setup: _lv_setup,
|
||||
vg_read: _vg_read,
|
||||
vg_setup: _vg_setup,
|
||||
vg_write: _vg_write,
|
||||
destroy: _destroy,
|
||||
};
|
||||
|
||||
struct format_instance *create_lvm1_format(struct cmd_context *cmd)
|
||||
{
|
||||
struct io_space *ios = dbg_malloc(sizeof(*ios));
|
||||
struct format_instance *fi = dbg_malloc(sizeof(*fi));
|
||||
|
||||
ios->get_vgs = _get_vgs;
|
||||
ios->get_pvs = _get_pvs;
|
||||
ios->pv_read = _pv_read;
|
||||
ios->pv_setup = _pv_setup;
|
||||
ios->pv_write = _pv_write;
|
||||
ios->vg_read = _vg_read;
|
||||
ios->vg_setup = _vg_setup;
|
||||
ios->vg_write = _vg_write;
|
||||
ios->destroy = _destroy;
|
||||
|
||||
ios->prefix = dbg_malloc(strlen(prefix) + 1);
|
||||
if (!ios->prefix) {
|
||||
if (!fi) {
|
||||
stack;
|
||||
dbg_free(ios);
|
||||
return 0;
|
||||
return NULL;
|
||||
}
|
||||
strcpy(ios->prefix, prefix);
|
||||
|
||||
ios->mem = mem;
|
||||
ios->filter = filter;
|
||||
ios->private = NULL;
|
||||
fi->cmd = cmd;
|
||||
fi->ops = &_format1_ops;
|
||||
fi->private = NULL;
|
||||
|
||||
return ios;
|
||||
return fi;
|
||||
}
|
||||
|
||||
@@ -4,12 +4,11 @@
|
||||
* This file is released under the GPL.
|
||||
*/
|
||||
|
||||
#ifndef LVM_FORMAT1_H
|
||||
#define LVM_FORMAT1_H
|
||||
#ifndef _LVM_FORMAT1_H
|
||||
#define _LVM_FORMAT1_H
|
||||
|
||||
#include "metadata.h"
|
||||
|
||||
struct io_space *create_lvm1_format(const char *prefix, struct pool *mem,
|
||||
struct dev_filter *filter);
|
||||
struct format_instance *create_lvm1_format(struct cmd_context *cmd);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
/*
|
||||
* Copyright (C) 2001 Sistina Software (UK) Limited.
|
||||
*
|
||||
* This file is released under the GPL.
|
||||
* Translates between disk and in-core formats.
|
||||
*
|
||||
* This file is released under the LGPL.
|
||||
*/
|
||||
|
||||
#include "disk-rep.h"
|
||||
@@ -10,6 +12,7 @@
|
||||
#include "hash.h"
|
||||
#include "list.h"
|
||||
#include "log.h"
|
||||
#include "lvm-string.h"
|
||||
|
||||
#include <time.h>
|
||||
#include <sys/utsname.h>
|
||||
@@ -34,64 +37,8 @@ static char *_create_lv_name(struct pool *mem, const char *full_name)
|
||||
return pool_strdup(mem, ptr);
|
||||
}
|
||||
|
||||
static struct logical_volume *_find_lv(struct volume_group *vg,
|
||||
const char *name)
|
||||
{
|
||||
struct list_head *tmp;
|
||||
struct logical_volume *lv;
|
||||
struct lv_list *ll;
|
||||
const char *ptr = strrchr(name, '/') + 1;
|
||||
|
||||
list_for_each(tmp, &vg->lvs) {
|
||||
ll = list_entry(tmp, struct lv_list, list);
|
||||
lv = &ll->lv;
|
||||
|
||||
if (!strcmp(ptr, lv->name))
|
||||
return lv;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct physical_volume *_find_pv(struct volume_group *vg,
|
||||
struct device *dev)
|
||||
{
|
||||
struct list_head *tmp;
|
||||
struct physical_volume *pv;
|
||||
struct pv_list *pl;
|
||||
|
||||
list_for_each(tmp, &vg->pvs) {
|
||||
pl = list_entry(tmp, struct pv_list, list);
|
||||
pv = &pl->pv;
|
||||
if (dev == pv->dev)
|
||||
return pv;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int _fill_lv_array(struct logical_volume **lvs,
|
||||
struct volume_group *vg, struct disk_list *dl)
|
||||
{
|
||||
struct list_head *tmp;
|
||||
struct logical_volume *lv;
|
||||
int i = 0;
|
||||
|
||||
list_for_each(tmp, &dl->lvs) {
|
||||
struct lvd_list *ll = list_entry(tmp, struct lvd_list, list);
|
||||
|
||||
if (!(lv = _find_lv(vg, ll->lv.lv_name))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
lvs[i] = lv;
|
||||
i++;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int import_pv(struct pool *mem, struct device *dev,
|
||||
struct volume_group *vg,
|
||||
struct physical_volume *pv, struct pv_disk *pvd)
|
||||
{
|
||||
memset(pv, 0, sizeof(*pv));
|
||||
@@ -103,21 +50,36 @@ int import_pv(struct pool *mem, struct device *dev,
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (pvd->pv_status & PV_ACTIVE)
|
||||
pv->status |= ACTIVE;
|
||||
/* Store system_id from first PV if PV belongs to a VG */
|
||||
if (vg && !*vg->system_id)
|
||||
strncpy(vg->system_id, pvd->system_id, NAME_LEN);
|
||||
|
||||
if (vg &&
|
||||
strncmp(vg->system_id, pvd->system_id, sizeof(pvd->system_id)))
|
||||
log_very_verbose("System ID %s on %s differs from %s for "
|
||||
"volume group", pvd->system_id,
|
||||
dev_name(pv->dev), vg->system_id);
|
||||
|
||||
/*
|
||||
* If exported, we still need to flag in pv->status too because
|
||||
* we don't always have a struct volume_group when we need this.
|
||||
*/
|
||||
if (pvd->pv_status & VG_EXPORTED)
|
||||
pv->status |= EXPORTED_VG;
|
||||
|
||||
if (pvd->pv_allocatable)
|
||||
pv->status |= ALLOCATED_PV;
|
||||
pv->status |= ALLOCATABLE_PV;
|
||||
|
||||
pv->size = pvd->pv_size;
|
||||
pv->pe_size = pvd->pe_size;
|
||||
pv->pe_start = pvd->pe_start;
|
||||
pv->pe_count = pvd->pe_total;
|
||||
pv->pe_allocated = pvd->pe_allocated;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _system_id(char *system_id)
|
||||
int _system_id(char *s, const char *prefix)
|
||||
{
|
||||
struct utsname uts;
|
||||
|
||||
@@ -126,11 +88,17 @@ static int _system_id(char *system_id)
|
||||
return 0;
|
||||
}
|
||||
|
||||
sprintf(system_id, "%s%lu", uts.nodename, time(NULL));
|
||||
if (lvm_snprintf(s, NAME_LEN, "%s%s%lu",
|
||||
prefix, uts.nodename, time(NULL)) < 0) {
|
||||
log_error("Generated system_id too long");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int export_pv(struct pv_disk *pvd, struct physical_volume *pv)
|
||||
int export_pv(struct pool *mem, struct volume_group *vg,
|
||||
struct pv_disk *pvd, struct physical_volume *pv)
|
||||
{
|
||||
memset(pvd, 0, sizeof(*pvd));
|
||||
|
||||
@@ -150,12 +118,55 @@ int export_pv(struct pv_disk *pvd, struct physical_volume *pv)
|
||||
if (pv->vg_name)
|
||||
strncpy(pvd->vg_name, pv->vg_name, sizeof(pvd->vg_name));
|
||||
|
||||
/* Preserve existing system_id if it exists */
|
||||
if (vg && *vg->system_id)
|
||||
strncpy(pvd->system_id, vg->system_id, sizeof(pvd->system_id));
|
||||
|
||||
/* Is VG already exported or being exported? */
|
||||
if (vg && (vg->status & EXPORTED_VG)) {
|
||||
/* Does system_id need setting? */
|
||||
if (!*vg->system_id ||
|
||||
strncmp(vg->system_id, EXPORTED_TAG,
|
||||
sizeof(EXPORTED_TAG) - 1)) {
|
||||
if (!_system_id(pvd->system_id, EXPORTED_TAG)) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (strlen(pvd->vg_name) + sizeof(EXPORTED_TAG) >
|
||||
sizeof(pvd->vg_name)) {
|
||||
log_error("Volume group name %s too long to export",
|
||||
pvd->vg_name);
|
||||
return 0;
|
||||
}
|
||||
strcat(pvd->vg_name, EXPORTED_TAG);
|
||||
}
|
||||
|
||||
/* Is VG being imported? */
|
||||
if (vg && !(vg->status & EXPORTED_VG) && *vg->system_id &&
|
||||
!strncmp(vg->system_id, EXPORTED_TAG, sizeof(EXPORTED_TAG) - 1)) {
|
||||
if (!_system_id(pvd->system_id, IMPORTED_TAG)) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Generate system_id if PV is in VG */
|
||||
if (!pvd->system_id || !*pvd->system_id)
|
||||
if (!_system_id(pvd->system_id, "")) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Update internal system_id if we changed it */
|
||||
if (vg &&
|
||||
(!*vg->system_id ||
|
||||
strncmp(vg->system_id, pvd->system_id, sizeof(pvd->system_id))))
|
||||
strncpy(vg->system_id, pvd->system_id, NAME_LEN);
|
||||
|
||||
//pvd->pv_major = MAJOR(pv->dev);
|
||||
|
||||
if (pv->status & ACTIVE)
|
||||
pvd->pv_status |= PV_ACTIVE;
|
||||
|
||||
if (pv->status & ALLOCATED_PV)
|
||||
if (pv->status & ALLOCATABLE_PV)
|
||||
pvd->pv_allocatable = PV_ALLOCATABLE;
|
||||
|
||||
pvd->pv_size = pv->size;
|
||||
@@ -165,43 +176,43 @@ int export_pv(struct pv_disk *pvd, struct physical_volume *pv)
|
||||
pvd->pe_allocated = pv->pe_allocated;
|
||||
pvd->pe_start = pv->pe_start;
|
||||
|
||||
if (!_system_id(pvd->system_id)) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int import_vg(struct pool *mem,
|
||||
struct volume_group *vg, struct disk_list *dl)
|
||||
struct volume_group *vg, struct disk_list *dl,
|
||||
int partial)
|
||||
{
|
||||
struct vg_disk *vgd = &dl->vg;
|
||||
struct vg_disk *vgd = &dl->vgd;
|
||||
memcpy(vg->id.uuid, vgd->vg_uuid, ID_LEN);
|
||||
|
||||
if (!_check_vg_name(dl->pv.vg_name)) {
|
||||
if (!_check_vg_name(dl->pvd.vg_name)) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(vg->name = pool_strdup(mem, dl->pv.vg_name))) {
|
||||
if (!(vg->name = pool_strdup(mem, dl->pvd.vg_name))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (vgd->vg_status & VG_ACTIVE)
|
||||
vg->status |= ACTIVE;
|
||||
if (!(vg->system_id = pool_alloc(mem, NAME_LEN))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
*vg->system_id = '\0';
|
||||
|
||||
if (vgd->vg_status & VG_EXPORTED)
|
||||
vg->status |= EXPORTED_VG;
|
||||
|
||||
if (vgd->vg_status & VG_EXTENDABLE)
|
||||
vg->status |= EXTENDABLE_VG;
|
||||
vg->status |= RESIZEABLE_VG;
|
||||
|
||||
if (vgd->vg_access & VG_READ)
|
||||
if (partial || (vgd->vg_access & VG_READ))
|
||||
vg->status |= LVM_READ;
|
||||
|
||||
if (vgd->vg_access & VG_WRITE)
|
||||
if (!partial && (vgd->vg_access & VG_WRITE))
|
||||
vg->status |= LVM_WRITE;
|
||||
|
||||
if (vgd->vg_access & VG_CLUSTERED)
|
||||
@@ -215,6 +226,10 @@ int import_vg(struct pool *mem,
|
||||
vg->free_count = vgd->pe_total - vgd->pe_allocated;
|
||||
vg->max_lv = vgd->lv_max;
|
||||
vg->max_pv = vgd->pv_max;
|
||||
|
||||
if (partial)
|
||||
vg->status |= PARTIAL_VG;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -235,13 +250,10 @@ int export_vg(struct vg_disk *vgd, struct volume_group *vg)
|
||||
if (vg->status & SHARED)
|
||||
vgd->vg_access |= VG_SHARED;
|
||||
|
||||
if (vg->status & ACTIVE)
|
||||
vgd->vg_status |= VG_ACTIVE;
|
||||
|
||||
if (vg->status & EXPORTED_VG)
|
||||
vgd->vg_status |= VG_EXPORTED;
|
||||
|
||||
if (vg->status & EXTENDABLE_VG)
|
||||
if (vg->status & RESIZEABLE_VG)
|
||||
vgd->vg_status |= VG_EXTENDABLE;
|
||||
|
||||
vgd->lv_max = vg->max_lv;
|
||||
@@ -259,16 +271,12 @@ int export_vg(struct vg_disk *vgd, struct volume_group *vg)
|
||||
|
||||
int import_lv(struct pool *mem, struct logical_volume *lv, struct lv_disk *lvd)
|
||||
{
|
||||
int len;
|
||||
memset(&lv->id, 0, sizeof(lv->id));
|
||||
if (!(lv->name = _create_lv_name(mem, lvd->lv_name))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (lvd->lv_status & LV_ACTIVE)
|
||||
lv->status |= ACTIVE;
|
||||
|
||||
if (lvd->lv_status & LV_SPINDOWN)
|
||||
lv->status |= SPINDOWN_LV;
|
||||
|
||||
@@ -287,31 +295,31 @@ int import_lv(struct pool *mem, struct logical_volume *lv, struct lv_disk *lvd)
|
||||
if (lvd->lv_badblock)
|
||||
lv->status |= BADBLOCK_ON;
|
||||
|
||||
if (lvd->lv_allocation == LV_STRICT)
|
||||
if (lvd->lv_allocation & LV_STRICT)
|
||||
lv->status |= ALLOC_STRICT;
|
||||
else
|
||||
lv->status |= ALLOC_CONTIGUOUS;
|
||||
|
||||
if (lvd->lv_allocation & LV_CONTIGUOUS)
|
||||
lv->status |= ALLOC_CONTIGUOUS;
|
||||
else
|
||||
lv->status |= ALLOC_SIMPLE;
|
||||
|
||||
lv->read_ahead = lvd->lv_read_ahead;
|
||||
lv->size = lvd->lv_size;
|
||||
lv->le_count = lvd->lv_allocated_le;
|
||||
|
||||
len = sizeof(struct pe_specifier) * lv->le_count;
|
||||
if (!(lv->map = pool_alloc(mem, len))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
memset(lv->map, 0, len);
|
||||
list_init(&lv->segments);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void export_lv(struct lv_disk *lvd, struct volume_group *vg,
|
||||
struct logical_volume *lv, const char *prefix)
|
||||
struct logical_volume *lv, const char *dev_dir)
|
||||
{
|
||||
memset(lvd, 0, sizeof(*lvd));
|
||||
snprintf(lvd->lv_name, sizeof(lvd->lv_name), "%s/%s",
|
||||
prefix, lv->name);
|
||||
snprintf(lvd->lv_name, sizeof(lvd->lv_name), "%s%s/%s",
|
||||
dev_dir, vg->name, lv->name);
|
||||
|
||||
/* FIXME: Add 'if' test */
|
||||
_check_vg_name(vg->name);
|
||||
strcpy(lvd->vg_name, vg->name);
|
||||
|
||||
@@ -327,12 +335,15 @@ void export_lv(struct lv_disk *lvd, struct volume_group *vg,
|
||||
if (lv->status & SNAPSHOT_ORG)
|
||||
lvd->lv_access |= LV_SNAPSHOT_ORG;
|
||||
|
||||
if (lv->status & ACTIVE)
|
||||
lvd->lv_status |= LV_ACTIVE;
|
||||
|
||||
if (lv->status & SPINDOWN_LV)
|
||||
lvd->lv_status |= LV_SPINDOWN;
|
||||
|
||||
lvd->lv_read_ahead = lv->read_ahead;
|
||||
lvd->lv_stripes = list_item(lv->segments.n,
|
||||
struct stripe_segment)->stripes;
|
||||
lvd->lv_stripesize = list_item(lv->segments.n,
|
||||
struct stripe_segment)->stripe_size;
|
||||
|
||||
lvd->lv_size = lv->size;
|
||||
lvd->lv_allocated_le = lv->le_count;
|
||||
|
||||
@@ -340,50 +351,33 @@ void export_lv(struct lv_disk *lvd, struct volume_group *vg,
|
||||
lvd->lv_badblock = LV_BADBLOCK_ON;
|
||||
|
||||
if (lv->status & ALLOC_STRICT)
|
||||
lvd->lv_allocation = LV_STRICT;
|
||||
else
|
||||
lvd->lv_allocation = LV_CONTIGUOUS;
|
||||
lvd->lv_allocation |= LV_STRICT;
|
||||
|
||||
if (lv->status & ALLOC_CONTIGUOUS)
|
||||
lvd->lv_allocation |= LV_CONTIGUOUS;
|
||||
}
|
||||
|
||||
int import_extents(struct pool *mem, struct volume_group *vg,
|
||||
struct list_head *pvs)
|
||||
int export_extents(struct disk_list *dl, int lv_num,
|
||||
struct logical_volume *lv,
|
||||
struct physical_volume *pv)
|
||||
{
|
||||
struct list_head *tmp;
|
||||
struct disk_list *dl;
|
||||
struct logical_volume *lv, *lvs[MAX_LV];
|
||||
struct physical_volume *pv;
|
||||
struct pe_disk *e;
|
||||
int i;
|
||||
uint32_t lv_num, le;
|
||||
struct list *segh;
|
||||
struct pe_disk *ped;
|
||||
struct stripe_segment *seg;
|
||||
uint32_t pe, s;
|
||||
|
||||
list_for_each(tmp, pvs) {
|
||||
dl = list_entry(tmp, struct disk_list, list);
|
||||
pv = _find_pv(vg, dl->dev);
|
||||
e = dl->extents;
|
||||
list_iterate (segh, &lv->segments) {
|
||||
seg = list_item(segh, struct stripe_segment);
|
||||
|
||||
/* build an array of lv's for this pv */
|
||||
if (!_fill_lv_array(lvs, vg, dl)) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
for (s = 0; s < seg->stripes; s++) {
|
||||
if (seg->area[s].pv != pv)
|
||||
continue; /* not our pv */
|
||||
|
||||
for (i = 0; i < dl->pv.pe_total; i++) {
|
||||
lv_num = e[i].lv_num;
|
||||
|
||||
if (lv_num == UNMAPPED_EXTENT)
|
||||
continue;
|
||||
|
||||
else if(lv_num > dl->pv.lv_cur) {
|
||||
log_err("invalid lv in extent map\n");
|
||||
return 0;
|
||||
|
||||
} else {
|
||||
lv_num--;
|
||||
lv = lvs[lv_num];
|
||||
le = e[i].le_num;
|
||||
|
||||
lv->map[le].pv = pv;
|
||||
lv->map[le].pe = i;
|
||||
for (pe = 0; pe < (seg->len / seg->stripes); pe++) {
|
||||
ped = &dl->extents[pe + seg->area[s].pe];
|
||||
ped->lv_num = lv_num;
|
||||
ped->le_num = (seg->le / seg->stripes) + pe +
|
||||
s * (lv->le_count / seg->stripes);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -391,46 +385,30 @@ int import_extents(struct pool *mem, struct volume_group *vg,
|
||||
return 1;
|
||||
}
|
||||
|
||||
int export_extents(struct disk_list *dl, int lv_num,
|
||||
struct logical_volume *lv,
|
||||
struct physical_volume *pv)
|
||||
int import_pvs(struct pool *mem, struct volume_group *vg,
|
||||
struct list *pvds, struct list *results, int *count)
|
||||
{
|
||||
struct pe_disk *ped;
|
||||
int le;
|
||||
|
||||
for (le = 0; le < lv->le_count; le++) {
|
||||
if (lv->map[le].pv == pv) {
|
||||
ped = &dl->extents[lv->map[le].pe];
|
||||
ped->lv_num = lv_num;
|
||||
ped->le_num = le;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int import_pvs(struct pool *mem, struct list_head *pvs,
|
||||
struct list_head *results, int *count)
|
||||
{
|
||||
struct list_head *tmp;
|
||||
struct list *pvdh;
|
||||
struct disk_list *dl;
|
||||
struct pv_list *pvl;
|
||||
|
||||
*count = 0;
|
||||
list_for_each(tmp, pvs) {
|
||||
dl = list_entry(tmp, struct disk_list, list);
|
||||
pvl = pool_alloc(mem, sizeof(*pvl));
|
||||
list_iterate(pvdh, pvds) {
|
||||
|
||||
if (!pvl) {
|
||||
dl = list_item(pvdh, struct disk_list);
|
||||
|
||||
if (!(pvl = pool_alloc(mem, sizeof(*pvl))) ||
|
||||
!(pvl->pv = pool_alloc(mem, sizeof(*pvl->pv)))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!import_pv(mem, dl->dev, &pvl->pv, &dl->pv)) {
|
||||
if (!import_pv(mem, dl->dev, vg, pvl->pv, &dl->pvd)) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
list_add(&pvl->list, results);
|
||||
list_add(results, &pvl->list);
|
||||
(*count)++;
|
||||
}
|
||||
|
||||
@@ -441,41 +419,43 @@ static struct logical_volume *_add_lv(struct pool *mem,
|
||||
struct volume_group *vg,
|
||||
struct lv_disk *lvd)
|
||||
{
|
||||
struct lv_list *ll = pool_alloc(mem, sizeof(*ll));
|
||||
struct lv_list *ll;
|
||||
struct logical_volume *lv;
|
||||
|
||||
if (!ll) {
|
||||
if (!(ll = pool_zalloc(mem, sizeof(*ll))) ||
|
||||
!(ll->lv = pool_zalloc(mem, sizeof(*ll->lv)))) {
|
||||
stack;
|
||||
return NULL;
|
||||
}
|
||||
lv = &ll->lv;
|
||||
lv = ll->lv;
|
||||
|
||||
if (!import_lv(mem, &ll->lv, lvd)) {
|
||||
if (!import_lv(mem, lv, lvd)) {
|
||||
stack;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
list_add(&ll->list, &vg->lvs);
|
||||
list_add(&vg->lvs, &ll->list);
|
||||
lv->vg = vg;
|
||||
vg->lv_count++;
|
||||
|
||||
return lv;
|
||||
}
|
||||
|
||||
int import_lvs(struct pool *mem, struct volume_group *vg,
|
||||
struct list_head *pvs)
|
||||
struct list *pvds)
|
||||
{
|
||||
struct list_head *tmp, *tmp2;
|
||||
struct disk_list *dl;
|
||||
struct lvd_list *ll;
|
||||
struct lv_disk *lvd;
|
||||
struct list *pvdh, *lvdh;
|
||||
|
||||
list_for_each(tmp, pvs) {
|
||||
dl = list_entry(tmp, struct disk_list, list);
|
||||
list_for_each(tmp2, &dl->lvs) {
|
||||
ll = list_entry(tmp2, struct lvd_list, list);
|
||||
lvd = &ll->lv;
|
||||
list_iterate(pvdh, pvds) {
|
||||
dl = list_item(pvdh, struct disk_list);
|
||||
list_iterate(lvdh, &dl->lvds) {
|
||||
ll = list_item(lvdh, struct lvd_list);
|
||||
lvd = &ll->lvd;
|
||||
|
||||
if (!_find_lv(vg, lvd->lv_name) &&
|
||||
if (!find_lv(vg, lvd->lv_name) &&
|
||||
!_add_lv(mem, vg, lvd)) {
|
||||
stack;
|
||||
return 0;
|
||||
@@ -487,17 +467,17 @@ int import_lvs(struct pool *mem, struct volume_group *vg,
|
||||
}
|
||||
|
||||
int export_lvs(struct disk_list *dl, struct volume_group *vg,
|
||||
struct physical_volume *pv, const char *prefix)
|
||||
struct physical_volume *pv, const char *dev_dir)
|
||||
{
|
||||
struct list_head *tmp;
|
||||
struct list *lvh;
|
||||
struct lv_list *ll;
|
||||
struct lvd_list *lvdl;
|
||||
int lv_num = 1, len;
|
||||
int lv_num = 0, len;
|
||||
|
||||
/*
|
||||
* setup the pv's extents array
|
||||
*/
|
||||
len = sizeof(struct pe_disk) * dl->pv.pe_total;
|
||||
len = sizeof(struct pe_disk) * dl->pvd.pe_total;
|
||||
if (!(dl->extents = pool_alloc(dl->mem, len))) {
|
||||
stack;
|
||||
return 0;
|
||||
@@ -505,111 +485,90 @@ int export_lvs(struct disk_list *dl, struct volume_group *vg,
|
||||
memset(dl->extents, 0, len);
|
||||
|
||||
|
||||
list_for_each(tmp, &vg->lvs) {
|
||||
ll = list_entry(tmp, struct lv_list, list);
|
||||
list_iterate(lvh, &vg->lvs) {
|
||||
ll = list_item(lvh, struct lv_list);
|
||||
if (!(lvdl = pool_alloc(dl->mem, sizeof(*lvdl)))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
export_lv(&lvdl->lv, vg, &ll->lv, prefix);
|
||||
if (!export_extents(dl, lv_num++, &ll->lv, pv)) {
|
||||
export_lv(&lvdl->lvd, vg, ll->lv, dev_dir);
|
||||
lvdl->lvd.lv_number = lv_num;
|
||||
if (!export_extents(dl, lv_num + 1, ll->lv, pv)) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
list_add(&lvdl->list, &dl->lvs);
|
||||
dl->pv.lv_cur++;
|
||||
list_add(&dl->lvds, &lvdl->list);
|
||||
dl->pvd.lv_cur++;
|
||||
lv_num++;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int export_uuids(struct disk_list *dl, struct volume_group *vg)
|
||||
{
|
||||
struct list_head *tmp;
|
||||
struct uuid_list *ul;
|
||||
struct pv_list *pvl;
|
||||
struct list *pvh;
|
||||
|
||||
list_for_each(tmp, &vg->pvs) {
|
||||
pvl = list_entry(tmp, struct pv_list, list);
|
||||
list_iterate(pvh, &vg->pvs) {
|
||||
pvl = list_item(pvh, struct pv_list);
|
||||
if (!(ul = pool_alloc(dl->mem, sizeof(*ul)))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
memset(ul->uuid, 0, sizeof(ul->uuid));
|
||||
memcpy(ul->uuid, pvl->pv.id.uuid, ID_LEN);
|
||||
memcpy(ul->uuid, pvl->pv->id.uuid, ID_LEN);
|
||||
|
||||
list_add(&ul->list, &dl->uuids);
|
||||
list_add(&dl->uuids, &ul->list);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _get_lv_number(struct volume_group *vg, const char *name)
|
||||
{
|
||||
/* FIXME: inefficient */
|
||||
struct list_head *tmp;
|
||||
struct lv_list *ll;
|
||||
int r = 0;
|
||||
|
||||
list_for_each (tmp, &vg->lvs) {
|
||||
ll = list_entry(tmp, struct lv_list, list);
|
||||
if (!strcmp(ll->lv.name, name))
|
||||
break;
|
||||
r++;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/*
|
||||
* This calculates the nasty pv_number and
|
||||
* lv_number fields used by LVM1. Very
|
||||
* inefficient code.
|
||||
*/
|
||||
void export_numbers(struct list_head *pvs, struct volume_group *vg)
|
||||
void export_numbers(struct list *pvds, struct volume_group *vg)
|
||||
{
|
||||
struct list_head *tmp, *tmp2;
|
||||
struct list *pvdh;
|
||||
struct disk_list *dl;
|
||||
struct lvd_list *ll;
|
||||
int pv_num = 1;
|
||||
|
||||
list_for_each (tmp, pvs) {
|
||||
dl = list_entry(tmp, struct disk_list, list);
|
||||
dl->pv.pv_number = pv_num++;
|
||||
|
||||
list_for_each (tmp2, &dl->lvs) {
|
||||
ll = list_entry(tmp2, struct lvd_list, list);
|
||||
ll->lv.lv_number = _get_lv_number(vg, ll->lv.lv_name);
|
||||
}
|
||||
list_iterate(pvdh, pvds) {
|
||||
dl = list_item(pvdh, struct disk_list);
|
||||
dl->pvd.pv_number = pv_num++;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculate vg_disk->pv_act.
|
||||
*/
|
||||
void export_pv_act(struct list_head *pvs)
|
||||
void export_pv_act(struct list *pvds)
|
||||
{
|
||||
struct list_head *tmp;
|
||||
struct list *pvdh;
|
||||
struct disk_list *dl;
|
||||
int act = 0;
|
||||
|
||||
list_for_each (tmp, pvs) {
|
||||
dl = list_entry(tmp, struct disk_list, list);
|
||||
if (dl->pv.pv_status & PV_ACTIVE)
|
||||
list_iterate(pvdh, pvds) {
|
||||
dl = list_item(pvdh, struct disk_list);
|
||||
if (dl->pvd.pv_status & PV_ACTIVE)
|
||||
act++;
|
||||
}
|
||||
|
||||
list_for_each (tmp, pvs) {
|
||||
dl = list_entry(tmp, struct disk_list, list);
|
||||
dl->vg.pv_act = act;
|
||||
list_iterate(pvdh, pvds) {
|
||||
dl = list_item(pvdh, struct disk_list);
|
||||
dl->vgd.pv_act = act;
|
||||
}
|
||||
}
|
||||
|
||||
int export_vg_number(struct list_head *pvs, const char *vg_name,
|
||||
int export_vg_number(struct list *pvds, const char *vg_name,
|
||||
struct dev_filter *filter)
|
||||
{
|
||||
struct list_head *tmp;
|
||||
struct list *pvdh;
|
||||
struct disk_list *dl;
|
||||
int vg_num;
|
||||
|
||||
@@ -618,9 +577,9 @@ int export_vg_number(struct list_head *pvs, const char *vg_name,
|
||||
return 0;
|
||||
}
|
||||
|
||||
list_for_each (tmp, pvs) {
|
||||
dl = list_entry(tmp, struct disk_list, list);
|
||||
dl->vg.vg_number = vg_num;
|
||||
list_iterate(pvdh, pvds) {
|
||||
dl = list_item(pvdh, struct disk_list);
|
||||
dl->vgd.vg_number = vg_num;
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
369
lib/format1/import-extents.c
Normal file
369
lib/format1/import-extents.c
Normal file
@@ -0,0 +1,369 @@
|
||||
/*
|
||||
* Copyright (C) 2001 Sistina Software (UK) Limited.
|
||||
*
|
||||
* This file is released under the LGPL.
|
||||
*/
|
||||
|
||||
#include "metadata.h"
|
||||
#include "hash.h"
|
||||
#include "dbg_malloc.h"
|
||||
#include "log.h"
|
||||
#include "pool.h"
|
||||
#include "disk-rep.h"
|
||||
|
||||
/*
|
||||
* After much thought I have decided it is easier,
|
||||
* and probably no less efficient, to convert the
|
||||
* pe->le map to a full le->pe map, and then
|
||||
* process this to get the segments form that
|
||||
* we're after. Any code which goes directly from
|
||||
* the pe->le map to segments would be gladly
|
||||
* accepted, if it is less complicated than this
|
||||
* file.
|
||||
*/
|
||||
struct pe_specifier {
|
||||
struct physical_volume *pv;
|
||||
uint32_t pe;
|
||||
};
|
||||
|
||||
struct lv_map {
|
||||
struct logical_volume *lv;
|
||||
uint32_t stripes;
|
||||
uint32_t stripe_size;
|
||||
struct pe_specifier *map;
|
||||
};
|
||||
|
||||
static struct hash_table *_create_lv_maps(struct pool *mem,
|
||||
struct volume_group *vg)
|
||||
{
|
||||
struct hash_table *maps = hash_create(32);
|
||||
struct list *llh;
|
||||
struct lv_list *ll;
|
||||
struct lv_map *lvm;
|
||||
|
||||
if (!maps) {
|
||||
log_err("Unable to create hash table for holding "
|
||||
"extent maps.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
list_iterate(llh, &vg->lvs) {
|
||||
ll = list_item(llh, struct lv_list);
|
||||
|
||||
if (!(lvm = pool_alloc(mem, sizeof(*lvm)))) {
|
||||
stack;
|
||||
goto bad;
|
||||
}
|
||||
|
||||
lvm->lv = ll->lv;
|
||||
if (!(lvm->map = pool_zalloc(mem, sizeof(*lvm->map)
|
||||
* ll->lv->le_count))) {
|
||||
stack;
|
||||
goto bad;
|
||||
}
|
||||
|
||||
if (!hash_insert(maps, ll->lv->name, lvm)) {
|
||||
stack;
|
||||
goto bad;
|
||||
}
|
||||
}
|
||||
|
||||
return maps;
|
||||
|
||||
bad:
|
||||
hash_destroy(maps);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int _fill_lv_array(struct lv_map **lvs,
|
||||
struct hash_table *maps, struct disk_list *dl)
|
||||
{
|
||||
struct list *lvh;
|
||||
struct lv_map *lvm;
|
||||
|
||||
memset(lvs, 0, sizeof(*lvs) * MAX_LV);
|
||||
list_iterate(lvh, &dl->lvds) {
|
||||
struct lvd_list *ll = list_item(lvh, struct lvd_list);
|
||||
|
||||
if (!(lvm = hash_lookup(maps, strrchr(ll->lvd.lv_name, '/')
|
||||
+ 1))) {
|
||||
log_err("Physical volume (%s) contains an "
|
||||
"unknown logical volume (%s).",
|
||||
dev_name(dl->dev), ll->lvd.lv_name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
lvm->stripes = ll->lvd.lv_stripes;
|
||||
lvm->stripe_size = ll->lvd.lv_stripesize;
|
||||
|
||||
lvs[ll->lvd.lv_number] = lvm;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _fill_maps(struct hash_table *maps, struct volume_group *vg,
|
||||
struct list *pvds)
|
||||
{
|
||||
struct list *pvdh;
|
||||
struct disk_list *dl;
|
||||
struct physical_volume *pv;
|
||||
struct lv_map *lvms[MAX_LV], *lvm;
|
||||
struct pe_disk *e;
|
||||
uint32_t i, lv_num, le;
|
||||
|
||||
list_iterate(pvdh, pvds) {
|
||||
dl = list_item(pvdh, struct disk_list);
|
||||
pv = find_pv(vg, dl->dev);
|
||||
e = dl->extents;
|
||||
|
||||
/* build an array of lv's for this pv */
|
||||
if (!_fill_lv_array(lvms, maps, dl)) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < dl->pvd.pe_total; i++) {
|
||||
lv_num = e[i].lv_num;
|
||||
|
||||
if (lv_num == UNMAPPED_EXTENT)
|
||||
continue;
|
||||
|
||||
else {
|
||||
lv_num--;
|
||||
lvm = lvms[lv_num];
|
||||
|
||||
if (!lvm) {
|
||||
log_err("invalid lv in extent map");
|
||||
return 0;
|
||||
}
|
||||
|
||||
le = e[i].le_num;
|
||||
|
||||
if (le >= lvm->lv->le_count) {
|
||||
log_err("logical extent number "
|
||||
"out of bounds");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (lvm->map[le].pv) {
|
||||
log_err("logical extent (%u) "
|
||||
"already mapped.", le);
|
||||
return 0;
|
||||
}
|
||||
|
||||
lvm->map[le].pv = pv;
|
||||
lvm->map[le].pe = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _check_single_map(struct lv_map *lvm)
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
for (i = 0; i < lvm->lv->le_count; i++) {
|
||||
if (!lvm->map[i].pv) {
|
||||
log_err("Logical volume (%s) contains an incomplete "
|
||||
"mapping table.", lvm->lv->name);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _check_maps_are_complete(struct hash_table *maps)
|
||||
{
|
||||
struct hash_node *n;
|
||||
struct lv_map *lvm;
|
||||
|
||||
for (n = hash_get_first(maps); n; n = hash_get_next(maps, n)) {
|
||||
lvm = (struct lv_map *) hash_get_data(maps, n);
|
||||
|
||||
if (!_check_single_map(lvm)) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static struct stripe_segment *_alloc_seg(struct pool *mem, uint32_t stripes)
|
||||
{
|
||||
struct stripe_segment *seg;
|
||||
uint32_t len = sizeof(*seg) + (stripes * sizeof(seg->area[0]));
|
||||
|
||||
if (!(seg = pool_zalloc(mem, len))) {
|
||||
stack;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return seg;
|
||||
}
|
||||
|
||||
static int _read_linear(struct pool *mem, struct lv_map *lvm)
|
||||
{
|
||||
uint32_t le = 0;
|
||||
struct stripe_segment *seg;
|
||||
|
||||
while (le < lvm->lv->le_count) {
|
||||
seg = _alloc_seg(mem, 1);
|
||||
|
||||
seg->lv = lvm->lv;
|
||||
seg->le = le;
|
||||
seg->len = 0;
|
||||
seg->stripe_size = 0;
|
||||
seg->stripes = 1;
|
||||
|
||||
seg->area[0].pv = lvm->map[le].pv;
|
||||
seg->area[0].pe = lvm->map[le].pe;
|
||||
|
||||
do
|
||||
seg->len++;
|
||||
|
||||
while ((lvm->map[le + seg->len].pv == seg->area[0].pv) &&
|
||||
(lvm->map[le + seg->len].pe == seg->area[0].pe +
|
||||
seg->len));
|
||||
|
||||
le += seg->len;
|
||||
|
||||
list_add(&lvm->lv->segments, &seg->list);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _check_stripe(struct lv_map *lvm, struct stripe_segment *seg,
|
||||
uint32_t base_le, uint32_t len)
|
||||
{
|
||||
uint32_t le, st;
|
||||
|
||||
le = base_le + seg->len;
|
||||
|
||||
/*
|
||||
* Is the next physical extent in every stripe adjacent to the last?
|
||||
*/
|
||||
for (st = 0; st < seg->stripes; st++)
|
||||
if ((lvm->map[le + st * len].pv != seg->area[st].pv) ||
|
||||
(lvm->map[le + st * len].pe != seg->area[st].pe + seg->len))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _read_stripes(struct pool *mem, struct lv_map *lvm)
|
||||
{
|
||||
uint32_t st, le = 0, len;
|
||||
struct stripe_segment *seg;
|
||||
|
||||
/*
|
||||
* Work out overall striped length
|
||||
*/
|
||||
if (lvm->lv->le_count % lvm->stripes) {
|
||||
log_error("Number of stripes (%u) incompatible "
|
||||
"with logical extent count (%u) for %s",
|
||||
lvm->stripes, lvm->lv->le_count,
|
||||
lvm->lv->name);
|
||||
}
|
||||
len = lvm->lv->le_count / lvm->stripes;
|
||||
|
||||
while (le < len) {
|
||||
if (!(seg = _alloc_seg(mem, lvm->stripes))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
seg->lv = lvm->lv;
|
||||
seg->stripe_size = lvm->stripe_size;
|
||||
seg->stripes = lvm->stripes;
|
||||
seg->le = seg->stripes * le;
|
||||
seg->len = 1;
|
||||
|
||||
/*
|
||||
* Set up start positions of each stripe in this segment
|
||||
*/
|
||||
for (st = 0; st < seg->stripes; st++) {
|
||||
seg->area[st].pv = lvm->map[le + st * len].pv;
|
||||
seg->area[st].pe = lvm->map[le + st * len].pe;
|
||||
}
|
||||
|
||||
/*
|
||||
* Find how many blocks are contiguous in all stripes
|
||||
* and so can form part of this segment
|
||||
*/
|
||||
while (_check_stripe(lvm, seg, le, len))
|
||||
seg->len++;
|
||||
|
||||
le += seg->len;
|
||||
seg->len *= seg->stripes;
|
||||
|
||||
list_add(&lvm->lv->segments, &seg->list);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _build_segments(struct pool *mem, struct lv_map *lvm)
|
||||
{
|
||||
return (lvm->stripes > 1 ? _read_stripes(mem, lvm) :
|
||||
_read_linear(mem, lvm));
|
||||
}
|
||||
|
||||
static int _build_all_segments(struct pool *mem, struct hash_table *maps)
|
||||
{
|
||||
struct hash_node *n;
|
||||
struct lv_map *lvm;
|
||||
|
||||
for (n = hash_get_first(maps); n; n = hash_get_next(maps, n)) {
|
||||
lvm = (struct lv_map *) hash_get_data(maps, n);
|
||||
if (!_build_segments(mem, lvm)) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int import_extents(struct pool *mem, struct volume_group *vg, struct list *pvds)
|
||||
{
|
||||
int r = 0;
|
||||
struct pool *scratch = pool_create(10 * 1024);
|
||||
struct hash_table *maps;
|
||||
|
||||
if (!scratch) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(maps = _create_lv_maps(scratch, vg))) {
|
||||
log_err("Couldn't allocate logical volume maps.");
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!_fill_maps(maps, vg, pvds)) {
|
||||
log_err("Couldn't fill logical volume maps.");
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!_check_maps_are_complete(maps) && !(vg->status & PARTIAL_VG)) {
|
||||
stack;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!_build_all_segments(mem, maps)) {
|
||||
log_err("Couldn't build extent segments.");
|
||||
goto out;
|
||||
}
|
||||
r = 1;
|
||||
|
||||
out:
|
||||
if (maps)
|
||||
hash_destroy(maps);
|
||||
pool_destroy(scratch);
|
||||
return r;
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright (C) 2001 Sistina Software (UK) Limited.
|
||||
*
|
||||
* This file is released under the GPL.
|
||||
* This file is released under the LGPL.
|
||||
*/
|
||||
|
||||
#include "disk-rep.h"
|
||||
@@ -66,17 +66,17 @@ static void _calc_simple_layout(struct pv_disk *pvd)
|
||||
|
||||
int _check_vg_limits(struct disk_list *dl)
|
||||
{
|
||||
if (dl->vg.lv_max >= MAX_LV) {
|
||||
if (dl->vgd.lv_max > MAX_LV) {
|
||||
log_error("MaxLogicalVolumes of %d exceeds format limit of %d "
|
||||
"for VG '%s'", dl->vg.lv_max, MAX_LV - 1,
|
||||
dl->pv.vg_name);
|
||||
"for VG '%s'", dl->vgd.lv_max, MAX_LV - 1,
|
||||
dl->pvd.vg_name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (dl->vg.pv_max >= MAX_PV) {
|
||||
if (dl->vgd.pv_max > MAX_PV) {
|
||||
log_error("MaxPhysicalVolumes of %d exceeds format limit of %d "
|
||||
"for VG '%s'", dl->vg.pv_max, MAX_PV - 1,
|
||||
dl->pv.vg_name);
|
||||
"for VG '%s'", dl->vgd.pv_max, MAX_PV - 1,
|
||||
dl->pvd.vg_name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ int _check_vg_limits(struct disk_list *dl)
|
||||
*/
|
||||
int calculate_layout(struct disk_list *dl)
|
||||
{
|
||||
struct pv_disk *pvd = &dl->pv;
|
||||
struct pv_disk *pvd = &dl->pvd;
|
||||
|
||||
_calc_simple_layout(pvd);
|
||||
if (!_adjust_pe_on_disk(pvd)) {
|
||||
@@ -117,6 +117,7 @@ int calculate_extent_count(struct physical_volume *pv)
|
||||
|
||||
if (!pvd) {
|
||||
stack;
|
||||
dbg_free(pvd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -130,20 +131,30 @@ int calculate_extent_count(struct physical_volume *pv)
|
||||
|
||||
if (pvd->pe_total < PE_SIZE_PV_SIZE_REL) {
|
||||
log_error("Insufficient space for extents on %s",
|
||||
pv->dev->name);
|
||||
dev_name(pv->dev));
|
||||
dbg_free(pvd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
do {
|
||||
pvd->pe_total--;
|
||||
_calc_simple_layout(pvd);
|
||||
end = ((pvd->pe_on_disk.base + pvd->pe_on_disk.size) /
|
||||
SECTOR_SIZE);
|
||||
end = ((pvd->pe_on_disk.base + pvd->pe_on_disk.size + \
|
||||
SECTOR_SIZE - 1) / SECTOR_SIZE);
|
||||
|
||||
pvd->pe_start = _round_up(end, PE_ALIGN);
|
||||
|
||||
} while((pvd->pe_start + (pvd->pe_total * pv->pe_size)) > pv->size);
|
||||
|
||||
if (pvd->pe_total > MAX_PE_TOTAL) {
|
||||
log_error("Metadata extent limit (%u) exceeded for %s - "
|
||||
"%u required", MAX_PE_TOTAL, dev_name(pv->dev),
|
||||
pvd->pe_total);
|
||||
dbg_free(pvd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
pv->pe_count = pvd->pe_total;
|
||||
pv->pe_start = pvd->pe_start;
|
||||
dbg_free(pvd);
|
||||
|
||||
145
lib/format1/lvm1_label.c
Normal file
145
lib/format1/lvm1_label.c
Normal file
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
* Copyright (C) 2002 Sistina Software (UK) Limited.
|
||||
*
|
||||
* This file is released under the LGPL.
|
||||
*/
|
||||
|
||||
#include "lvm1_label.h"
|
||||
#include "dbg_malloc.h"
|
||||
#include "disk-rep.h"
|
||||
#include "log.h"
|
||||
#include "label.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
static void _not_supported(const char *op)
|
||||
{
|
||||
log_err("The '%s' operation is not supported for the lvm1 labeller.",
|
||||
op);
|
||||
}
|
||||
|
||||
static int _can_handle(struct labeller *l, struct device *dev)
|
||||
{
|
||||
struct pv_disk pvd;
|
||||
int r;
|
||||
|
||||
if (!dev_open(dev, O_RDONLY)) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
r = read_pvd(dev, &pvd);
|
||||
|
||||
if (!dev_close(dev))
|
||||
stack;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static int _write(struct labeller *l,
|
||||
struct device *dev, struct label *label)
|
||||
{
|
||||
_not_supported("write");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _remove(struct labeller *l, struct device *dev)
|
||||
{
|
||||
_not_supported("remove");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct label *_to_label(struct pv_disk *pvd)
|
||||
{
|
||||
struct label *l;
|
||||
struct lvm_label_info *info;
|
||||
|
||||
if (!(l = dbg_malloc(sizeof(*l)))) {
|
||||
log_err("Couldn't allocate label.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(info = (struct lvm_label_info *) dbg_strdup(pvd->vg_name))) {
|
||||
dbg_free(l);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memcpy(&l->id, &pvd->pv_uuid, sizeof(l->id));
|
||||
strcpy(l->volume_type, "lvm");
|
||||
l->version[0] = 1;
|
||||
l->version[0] = 0;
|
||||
l->version[0] = 0;
|
||||
l->extra_info = info;
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
static int _read(struct labeller *l, struct device *dev, struct label **label)
|
||||
{
|
||||
struct pv_disk pvd;
|
||||
int r = 0;
|
||||
|
||||
if (!dev_open(dev, O_RDONLY)) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
r = read_pvd(dev, &pvd);
|
||||
|
||||
if (!dev_close(dev))
|
||||
stack;
|
||||
|
||||
if (!r) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert the disk_list into a label structure.
|
||||
*/
|
||||
if (!(*label = _to_label(&pvd))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void _destroy_label(struct labeller *l, struct label *label)
|
||||
{
|
||||
dbg_free(label->extra_info);
|
||||
dbg_free(label);
|
||||
}
|
||||
|
||||
static void _destroy(struct labeller *l)
|
||||
{
|
||||
dbg_free(l);
|
||||
}
|
||||
|
||||
|
||||
struct label_ops _lvm1_ops = {
|
||||
can_handle: _can_handle,
|
||||
write: _write,
|
||||
remove: _remove,
|
||||
read: _read,
|
||||
verify: _can_handle,
|
||||
destroy_label: _destroy_label,
|
||||
destroy: _destroy
|
||||
};
|
||||
|
||||
struct labeller *lvm1_labeller_create(void)
|
||||
{
|
||||
struct labeller *l;
|
||||
|
||||
if (!(l = dbg_malloc(sizeof(*l)))) {
|
||||
log_err("Couldn't allocate labeller object.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
l->ops = &_lvm1_ops;
|
||||
l->private = NULL;
|
||||
|
||||
return l;
|
||||
}
|
||||
21
lib/format1/lvm1_label.h
Normal file
21
lib/format1/lvm1_label.h
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (C) 2002 Sistina Software (UK) Limited.
|
||||
*
|
||||
* This file is released under the LGPL.
|
||||
*/
|
||||
|
||||
#ifndef _LVM_LVM1_LABEL_H
|
||||
#define _LVM_LVM1_LABEL_H
|
||||
|
||||
/*
|
||||
* This is what the 'extra_info' field of the label will point to
|
||||
* if the label type is lvm1.
|
||||
*/
|
||||
struct lvm_label_info {
|
||||
char volume_group[0];
|
||||
};
|
||||
|
||||
|
||||
struct labeller *lvm1_labeller_create(void);
|
||||
|
||||
#endif
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright (C) 2001 Sistina Software (UK) Limited.
|
||||
*
|
||||
* This file is released under the GPL.
|
||||
* This file is released under the LGPL.
|
||||
*/
|
||||
|
||||
#include "log.h"
|
||||
@@ -12,18 +12,19 @@
|
||||
* FIXME: Quick hack. We can use caching to
|
||||
* prevent a total re-read, even so vg_number
|
||||
* causes the tools to check *every* pv. Yuck.
|
||||
* Put in seperate file so it wouldn't contaminate
|
||||
* Put in separate file so it wouldn't contaminate
|
||||
* other code.
|
||||
*/
|
||||
int get_free_vg_number(struct dev_filter *filter, const char *candidate_vg,
|
||||
int *result)
|
||||
{
|
||||
struct list_head all_pvs, *tmp;
|
||||
struct list *pvh;
|
||||
struct list all_pvs;
|
||||
struct disk_list *dl;
|
||||
struct pool *mem = pool_create(10 * 1024);
|
||||
int numbers[MAX_VG], i, r = 0;
|
||||
|
||||
INIT_LIST_HEAD(&all_pvs);
|
||||
list_init(&all_pvs);
|
||||
|
||||
if (!mem) {
|
||||
stack;
|
||||
@@ -37,12 +38,13 @@ int get_free_vg_number(struct dev_filter *filter, const char *candidate_vg,
|
||||
|
||||
memset(numbers, 0, sizeof(numbers));
|
||||
|
||||
list_for_each (tmp, &all_pvs) {
|
||||
dl = list_entry(tmp, struct disk_list, list);
|
||||
if (!strcmp(dl->pv.vg_name, candidate_vg))
|
||||
list_iterate(pvh, &all_pvs) {
|
||||
dl = list_item(pvh, struct disk_list);
|
||||
if (!*dl->pvd.vg_name ||
|
||||
!strcmp(dl->pvd.vg_name, candidate_vg))
|
||||
continue;
|
||||
|
||||
numbers[dl->vg.vg_number] = 1;
|
||||
numbers[dl->vgd.vg_number] = 1;
|
||||
}
|
||||
|
||||
for (i = 0; i < MAX_VG; i++) {
|
||||
|
||||
421
lib/format_text/archive.c
Normal file
421
lib/format_text/archive.c
Normal file
@@ -0,0 +1,421 @@
|
||||
/*
|
||||
* Copyright (C) 2001 Sistina Software (UK) Limited.
|
||||
*
|
||||
* This file is released under the LGPL.
|
||||
*/
|
||||
|
||||
#include "format-text.h"
|
||||
|
||||
#include "log.h"
|
||||
#include "pool.h"
|
||||
#include "config.h"
|
||||
#include "hash.h"
|
||||
#include "import-export.h"
|
||||
#include "lvm-string.h"
|
||||
#include "lvm-file.h"
|
||||
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/file.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
|
||||
/*
|
||||
* The format instance is given a directory path upon creation.
|
||||
* Each file in this directory whose name is of the form
|
||||
* '(.*)_[0-9]*.vg' is a config file (see lib/config.[hc]), which
|
||||
* contains a description of a single volume group.
|
||||
*
|
||||
* The prefix ($1 from the above regex) of the config file gives
|
||||
* the volume group name.
|
||||
*
|
||||
* Backup files that have expired will be removed.
|
||||
*/
|
||||
|
||||
struct archive_c {
|
||||
uint32_t retain_days;
|
||||
uint32_t min_retains;
|
||||
|
||||
char *dir;
|
||||
|
||||
/*
|
||||
* An ordered list of previous archives. Each list
|
||||
* entered against the vg name. Most recent first.
|
||||
*/
|
||||
struct hash_table *vg_archives;
|
||||
|
||||
/*
|
||||
* Scratch pool. Contents of vg_archives come from here.
|
||||
*/
|
||||
struct pool *mem;
|
||||
};
|
||||
|
||||
/*
|
||||
* A list of these is built up for each volume group. Ordered
|
||||
* with the least recent at the head.
|
||||
*/
|
||||
struct archive_file {
|
||||
struct list list;
|
||||
|
||||
char *path;
|
||||
char *vg;
|
||||
int index;
|
||||
};
|
||||
|
||||
/*
|
||||
* This format is write only.
|
||||
*/
|
||||
static void _unsupported(const char *cmd)
|
||||
{
|
||||
log_err("The archive format doesn't support '%s'", cmd);
|
||||
}
|
||||
|
||||
static struct list *_get_vgs(struct format_instance *fi)
|
||||
{
|
||||
_unsupported("get_vgs");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct list *_get_pvs(struct format_instance *fi)
|
||||
{
|
||||
_unsupported("get_pvs");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct physical_volume *_pv_read(struct format_instance *fi,
|
||||
const char *pv_name)
|
||||
{
|
||||
_unsupported("pv_read");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int _pv_setup(struct format_instance *fi, struct physical_volume *pv,
|
||||
struct volume_group *vg)
|
||||
{
|
||||
_unsupported("pv_setup");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _pv_write(struct format_instance *fi, struct physical_volume *pv)
|
||||
{
|
||||
_unsupported("pv_write");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _vg_setup(struct format_instance *fi, struct volume_group *vg)
|
||||
{
|
||||
_unsupported("vg_setup");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct volume_group *_vg_read(struct format_instance *fi,
|
||||
const char *vg_name)
|
||||
{
|
||||
_unsupported("vg_read");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void _destroy(struct format_instance *fi)
|
||||
{
|
||||
struct archive_c *bc = (struct archive_c *) fi->private;
|
||||
if (bc->vg_archives)
|
||||
hash_destroy(bc->vg_archives);
|
||||
pool_destroy(bc->mem);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Extract vg name and version number from a filename.
|
||||
*/
|
||||
static int _split_vg(const char *filename, char *vg, size_t vg_size,
|
||||
uint32_t *index)
|
||||
{
|
||||
int len, vg_len;
|
||||
char *dot, *underscore;
|
||||
|
||||
len = strlen(filename);
|
||||
if (len < 7)
|
||||
return 0;
|
||||
|
||||
dot = (char *) (filename + len - 3);
|
||||
if (strcmp(".vg", dot))
|
||||
return 0;
|
||||
|
||||
if (!(underscore = rindex(filename, '_')))
|
||||
return 0;
|
||||
|
||||
if (sscanf(underscore + 1, "%u", index) != 1)
|
||||
return 0;
|
||||
|
||||
vg_len = underscore - filename;
|
||||
if (vg_len + 1 > vg_size)
|
||||
return 0;
|
||||
|
||||
strncpy(vg, filename, vg_len);
|
||||
vg[vg_len] = '\0';
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void _insert_file(struct list *head, struct archive_file *b)
|
||||
{
|
||||
struct list *bh;
|
||||
struct archive_file *bf;
|
||||
|
||||
if (list_empty(head)) {
|
||||
list_add(head, &b->list);
|
||||
return;
|
||||
}
|
||||
|
||||
/* index increases through list */
|
||||
list_iterate (bh, head) {
|
||||
bf = list_item(bh, struct archive_file);
|
||||
|
||||
if (bf->index > b->index) {
|
||||
list_add(&bf->list, &b->list);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
list_add_h(&bf->list, &b->list);
|
||||
}
|
||||
|
||||
static int _scan_vg(struct archive_c *bc, const char *file,
|
||||
const char *vg_name, int index)
|
||||
{
|
||||
struct archive_file *b;
|
||||
struct list *files;
|
||||
|
||||
/*
|
||||
* Do we need to create a new list of archive files for
|
||||
* this vg ?
|
||||
*/
|
||||
if (!(files = hash_lookup(bc->vg_archives, vg_name))) {
|
||||
if (!(files = pool_alloc(bc->mem, sizeof(*files)))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
list_init(files);
|
||||
if (!hash_insert(bc->vg_archives, vg_name, files)) {
|
||||
log_err("Couldn't insert archive file "
|
||||
"into hash table.");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a new archive file.
|
||||
*/
|
||||
if (!(b = pool_alloc(bc->mem, sizeof(*b)))) {
|
||||
log_err("Couldn't create new archive file.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
b->index = index;
|
||||
b->path = (char *)file;
|
||||
b->vg = (char *)vg_name;
|
||||
|
||||
/*
|
||||
* Insert it to the correct part of the list.
|
||||
*/
|
||||
_insert_file(files, b);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static char *_join(struct pool *mem, const char *dir, const char *name)
|
||||
{
|
||||
if (!pool_begin_object(mem, 32) ||
|
||||
!pool_grow_object(mem, dir, strlen(dir)) ||
|
||||
!pool_grow_object(mem, "/", 1) ||
|
||||
!pool_grow_object(mem, name, strlen(name)) ||
|
||||
!pool_grow_object(mem, "\0", 1)) {
|
||||
stack;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pool_end_object(mem);
|
||||
}
|
||||
|
||||
static int _scan_dir(struct archive_c *bc)
|
||||
{
|
||||
int r = 0, i, count, index;
|
||||
char vg_name[64], *path;
|
||||
struct dirent **dirent;
|
||||
|
||||
if ((count = scandir(bc->dir, &dirent, NULL, alphasort)) < 0) {
|
||||
log_err("Couldn't scan archive directory.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
if ((dirent[i]->d_name[0] == '.') ||
|
||||
!_split_vg(dirent[i]->d_name, vg_name,
|
||||
sizeof(vg_name), &index))
|
||||
continue;
|
||||
|
||||
if (!(path = _join(bc->mem, bc->dir, dirent[i]->d_name))) {
|
||||
stack;
|
||||
goto out;
|
||||
}
|
||||
|
||||
_scan_vg(bc, path, vg_name, index);
|
||||
}
|
||||
r = 1;
|
||||
|
||||
out:
|
||||
for (i = 0; i < count; i++)
|
||||
free(dirent[i]);
|
||||
free(dirent);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static int _scan_archives(struct archive_c *bc)
|
||||
{
|
||||
pool_empty(bc->mem);
|
||||
|
||||
if (bc->vg_archives)
|
||||
hash_destroy(bc->vg_archives);
|
||||
|
||||
if (!(bc->vg_archives = hash_create(128))) {
|
||||
log_err("Couldn't create hash table for scanning archives.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!_scan_dir(bc)) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _vg_write(struct format_instance *fi, struct volume_group *vg)
|
||||
{
|
||||
int r = 0, i, fd;
|
||||
unsigned int index = 0;
|
||||
struct archive_c *bc = (struct archive_c *) fi->private;
|
||||
struct archive_file *last;
|
||||
FILE *fp = NULL;
|
||||
char temp_file[PATH_MAX], archive_name[PATH_MAX];
|
||||
|
||||
if (!create_temp_name(bc->dir, temp_file, sizeof(temp_file), &fd)) {
|
||||
log_err("Couldn't create temporary archive name.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(fp = fdopen(fd, "w"))) {
|
||||
log_err("Couldn't create FILE object for archive.");
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!text_vg_export(fp, vg)) {
|
||||
stack;
|
||||
fclose(fp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
|
||||
/*
|
||||
* Now we want to rename this file to <vg>_index.vg.
|
||||
*/
|
||||
if (!_scan_archives(bc)) {
|
||||
log_err("Couldn't scan the archive directory (%s).", bc->dir);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if ((last = (struct archive_file *) hash_lookup(bc->vg_archives,
|
||||
vg->name))) {
|
||||
/* move to the last in the list */
|
||||
last = list_item(last->list.p, struct archive_file);
|
||||
index = last->index + 1;
|
||||
}
|
||||
|
||||
for (i = 0; i < 10; i++) {
|
||||
if (lvm_snprintf(archive_name, sizeof(archive_name),
|
||||
"%s/%s_%05d.vg",
|
||||
bc->dir, vg->name, index) < 0) {
|
||||
log_err("archive file name too long.");
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (lvm_rename(temp_file, archive_name)) {
|
||||
r = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
out:
|
||||
return r;
|
||||
}
|
||||
|
||||
void archive_expire(struct format_instance *fi)
|
||||
{
|
||||
/* FIXME: finish */
|
||||
}
|
||||
|
||||
static struct format_handler _archive_handler = {
|
||||
get_vgs: _get_vgs,
|
||||
get_pvs: _get_pvs,
|
||||
pv_read: _pv_read,
|
||||
pv_setup: _pv_setup,
|
||||
pv_write: _pv_write,
|
||||
vg_setup: _vg_setup,
|
||||
vg_read: _vg_read,
|
||||
vg_write: _vg_write,
|
||||
destroy: _destroy
|
||||
};
|
||||
|
||||
struct format_instance *archive_format_create(struct cmd_context *cmd,
|
||||
const char *dir,
|
||||
uint32_t retain_days,
|
||||
uint32_t min_retains)
|
||||
{
|
||||
struct format_instance *fi;
|
||||
struct archive_c *bc = NULL;
|
||||
struct pool *mem = cmd->mem;
|
||||
|
||||
if (!(bc = pool_zalloc(mem, sizeof(*bc)))) {
|
||||
stack;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(bc->mem = pool_create(1024))) {
|
||||
stack;
|
||||
goto bad;
|
||||
}
|
||||
|
||||
if (!(bc->dir = pool_strdup(mem, dir))) {
|
||||
stack;
|
||||
goto bad;
|
||||
}
|
||||
|
||||
bc->retain_days = retain_days;
|
||||
bc->min_retains = min_retains;
|
||||
|
||||
if (!(fi = pool_alloc(mem, sizeof(*fi)))) {
|
||||
stack;
|
||||
goto bad;
|
||||
}
|
||||
|
||||
fi->cmd = cmd;
|
||||
fi->ops = &_archive_handler;
|
||||
fi->private = bc;
|
||||
|
||||
return fi;
|
||||
|
||||
bad:
|
||||
if (bc->mem)
|
||||
pool_destroy(bc->mem);
|
||||
|
||||
pool_free(mem, bc);
|
||||
return NULL;
|
||||
}
|
||||
487
lib/format_text/export.c
Normal file
487
lib/format_text/export.c
Normal file
@@ -0,0 +1,487 @@
|
||||
/*
|
||||
* Copyright (C) 2001 Sistina Software (UK) Limited.
|
||||
*
|
||||
* This file is released under the LGPL.
|
||||
*/
|
||||
|
||||
#include "import-export.h"
|
||||
#include "metadata.h"
|
||||
#include "log.h"
|
||||
#include "hash.h"
|
||||
#include "pool.h"
|
||||
#include "dbg_malloc.h"
|
||||
#include "lvm-string.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <time.h>
|
||||
|
||||
|
||||
/*
|
||||
* The first half of this file deals with
|
||||
* exporting the vg, ie. writing it to a file.
|
||||
*/
|
||||
struct formatter {
|
||||
struct pool *mem; /* pv names allocated from here */
|
||||
struct hash_table *pv_names; /* dev_name -> pv_name (eg, pv1) */
|
||||
|
||||
FILE *fp; /* where we're writing to */
|
||||
int indent; /* current level of indentation */
|
||||
|
||||
int error;
|
||||
};
|
||||
|
||||
/*
|
||||
* Formatting functions.
|
||||
*/
|
||||
static void _out_size(struct formatter *f, uint64_t size,
|
||||
const char *fmt, ...)
|
||||
__attribute__ (( format (printf, 3, 4) ));
|
||||
|
||||
static void _out_hint(struct formatter *f, const char *fmt, ...)
|
||||
__attribute__ (( format (printf, 2, 3) ));
|
||||
|
||||
static void _out(struct formatter *f, const char *fmt, ...)
|
||||
__attribute__ (( format (printf, 2, 3) ));
|
||||
|
||||
|
||||
#define MAX_INDENT 5
|
||||
static void _inc_indent(struct formatter *f)
|
||||
{
|
||||
if (++f->indent > MAX_INDENT)
|
||||
f->indent = MAX_INDENT;
|
||||
}
|
||||
|
||||
static void _dec_indent(struct formatter *f)
|
||||
{
|
||||
if (!f->indent--) {
|
||||
log_error("Internal error tracking indentation");
|
||||
f->indent = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Newline function for prettier layout.
|
||||
*/
|
||||
static void _nl(struct formatter *f)
|
||||
{
|
||||
fprintf(f->fp, "\n");
|
||||
}
|
||||
|
||||
#define COMMENT_TAB 6
|
||||
static void _out_with_comment(struct formatter *f, const char *comment,
|
||||
const char *fmt, va_list ap)
|
||||
{
|
||||
int i;
|
||||
char white_space[MAX_INDENT + 1];
|
||||
|
||||
if (ferror(f->fp))
|
||||
return;
|
||||
|
||||
for (i = 0; i < f->indent; i++)
|
||||
white_space[i] = '\t';
|
||||
white_space[i] = '\0';
|
||||
fprintf(f->fp, white_space);
|
||||
i = vfprintf(f->fp, fmt, ap);
|
||||
|
||||
if (comment) {
|
||||
/*
|
||||
* line comments up if possible.
|
||||
*/
|
||||
i += 8 * f->indent;
|
||||
i /= 8;
|
||||
i++;
|
||||
|
||||
do
|
||||
fputc('\t', f->fp);
|
||||
|
||||
while (++i < COMMENT_TAB);
|
||||
|
||||
fprintf(f->fp, comment);
|
||||
}
|
||||
fputc('\n', f->fp);
|
||||
}
|
||||
|
||||
/*
|
||||
* Formats a string, converting a size specified
|
||||
* in 512-byte sectors to a more human readable
|
||||
* form (eg, megabytes). We may want to lift this
|
||||
* for other code to use.
|
||||
*/
|
||||
static int _sectors_to_units(uint64_t sectors, char *buffer, size_t s)
|
||||
{
|
||||
static char *_units[] = {
|
||||
"Kilobytes",
|
||||
"Megabytes",
|
||||
"Gigabytes",
|
||||
"Terrabytes",
|
||||
NULL
|
||||
};
|
||||
|
||||
int i;
|
||||
double d = (double) sectors;
|
||||
|
||||
/* to convert to K */
|
||||
d /= 2.0;
|
||||
|
||||
for (i = 0; (d > 1024.0) && _units[i]; i++)
|
||||
d /= 1024.0;
|
||||
|
||||
return lvm_snprintf(buffer, s, "# %g %s", d, _units[i]) > 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Appends a comment giving a size in more easily
|
||||
* readable form (eg, 4M instead of 8096).
|
||||
*/
|
||||
static void _out_size(struct formatter *f, uint64_t size,
|
||||
const char *fmt, ...)
|
||||
{
|
||||
char buffer[64];
|
||||
va_list ap;
|
||||
|
||||
_sectors_to_units(size, buffer, sizeof(buffer));
|
||||
|
||||
va_start(ap, fmt);
|
||||
_out_with_comment(f, buffer, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
/*
|
||||
* Appends a comment indicating that the line is
|
||||
* only a hint.
|
||||
*/
|
||||
static void _out_hint(struct formatter *f, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
_out_with_comment(f, "# Hint only", fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
/*
|
||||
* The normal output function.
|
||||
*/
|
||||
static void _out(struct formatter *f, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
_out_with_comment(f, NULL, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
static int _print_header(struct formatter *f, struct volume_group *vg)
|
||||
{
|
||||
time_t t;
|
||||
|
||||
t = time(NULL);
|
||||
|
||||
_out(f,
|
||||
"# This file was originally generated by the LVM2 library\n"
|
||||
"# Generated: %s\n", ctime(&t));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _print_vg(struct formatter *f, struct volume_group *vg)
|
||||
{
|
||||
char buffer[256];
|
||||
|
||||
if (!id_write_format(&vg->id, buffer, sizeof(buffer))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
_out(f, "id = \"%s\"", buffer);
|
||||
|
||||
if (!print_flags(vg->status, VG_FLAGS, buffer, sizeof(buffer))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
_out(f, "status = %s", buffer);
|
||||
if (vg->system_id && *vg->system_id)
|
||||
_out(f, "system_id = \"%s\"", vg->system_id);
|
||||
_out_size(f, vg->extent_size, "extent_size = %u", vg->extent_size);
|
||||
_out(f, "max_lv = %u", vg->max_lv);
|
||||
_out(f, "max_pv = %u", vg->max_pv);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the pv%d name from the formatters hash
|
||||
* table.
|
||||
*/
|
||||
static inline const char *
|
||||
_get_pv_name(struct formatter *f, struct physical_volume *pv)
|
||||
{
|
||||
return (pv) ? (const char *)
|
||||
hash_lookup(f->pv_names, dev_name(pv->dev)) :
|
||||
"Missing";
|
||||
}
|
||||
|
||||
static int _print_pvs(struct formatter *f, struct volume_group *vg)
|
||||
{
|
||||
struct list *pvh;
|
||||
struct physical_volume *pv;
|
||||
char buffer[256];
|
||||
const char *name;
|
||||
|
||||
_out(f, "physical_volumes {");
|
||||
_inc_indent(f);
|
||||
|
||||
list_iterate (pvh, &vg->pvs) {
|
||||
|
||||
pv = list_item(pvh, struct pv_list)->pv;
|
||||
|
||||
if (!(name = _get_pv_name(f, pv))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
_nl(f);
|
||||
_out(f, "%s {", name);
|
||||
_inc_indent(f);
|
||||
|
||||
if (!id_write_format(&pv->id, buffer, sizeof(buffer))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
_out(f, "id = \"%s\"", buffer);
|
||||
_out_hint(f, "device = \"%s\"", dev_name(pv->dev));
|
||||
_nl(f);
|
||||
|
||||
if (!print_flags(pv->status, PV_FLAGS,
|
||||
buffer, sizeof(buffer))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
_out(f, "status = %s", buffer);
|
||||
_out(f, "pe_start = %llu", pv->pe_start);
|
||||
_out_size(f, vg->extent_size * (uint64_t) pv->pe_count,
|
||||
"pe_count = %u", pv->pe_count);
|
||||
|
||||
_dec_indent(f);
|
||||
_out(f, "}");
|
||||
}
|
||||
|
||||
_dec_indent(f);
|
||||
_out(f, "}");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _print_segment(struct formatter *f, struct volume_group *vg,
|
||||
int count, struct stripe_segment *seg)
|
||||
{
|
||||
int s;
|
||||
const char *name;
|
||||
|
||||
_out(f, "segment%u {", count);
|
||||
_inc_indent(f);
|
||||
|
||||
_out(f, "start_extent = %u", seg->le);
|
||||
_out_size(f, seg->len * vg->extent_size, "extent_count = %u", seg->len);
|
||||
_out(f, "stripes = %u", seg->stripes);
|
||||
|
||||
if (seg->stripes > 1)
|
||||
_out_size(f, seg->stripe_size,
|
||||
"stripe_size = %u", seg->stripe_size);
|
||||
|
||||
_nl(f);
|
||||
_out(f, "areas = [");
|
||||
_inc_indent(f);
|
||||
|
||||
for (s = 0; s < seg->stripes; s++) {
|
||||
if (!(name = _get_pv_name(f, seg->area[s].pv))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
_out(f, "\"%s\", %u%s", name, seg->area[s].pe,
|
||||
(s == seg->stripes - 1) ? "" : ",");
|
||||
}
|
||||
|
||||
_dec_indent(f);
|
||||
_out(f, "]");
|
||||
|
||||
_dec_indent(f);
|
||||
_out(f, "}");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _count_segments(struct logical_volume *lv)
|
||||
{
|
||||
int r = 0;
|
||||
struct list *segh;
|
||||
|
||||
list_iterate (segh, &lv->segments)
|
||||
r++;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static int _print_lvs(struct formatter *f, struct volume_group *vg)
|
||||
{
|
||||
struct list *lvh, *segh;
|
||||
struct logical_volume *lv;
|
||||
struct stripe_segment *seg;
|
||||
char buffer[256];
|
||||
int seg_count;
|
||||
|
||||
_out(f, "logical_volumes {");
|
||||
_nl(f);
|
||||
_inc_indent(f);
|
||||
|
||||
list_iterate (lvh, &vg->lvs) {
|
||||
lv = list_item(lvh, struct lv_list)->lv;
|
||||
|
||||
_out(f, "%s {", lv->name);
|
||||
_inc_indent(f);
|
||||
|
||||
if (!print_flags(lv->status, LV_FLAGS,
|
||||
buffer, sizeof(buffer))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
_out(f, "status = %s", buffer);
|
||||
_out(f, "read_ahead = %u", lv->read_ahead);
|
||||
_out(f, "segment_count = %u", _count_segments(lv));
|
||||
_nl(f);
|
||||
|
||||
seg_count = 1;
|
||||
list_iterate (segh, &lv->segments) {
|
||||
seg = list_item(segh, struct stripe_segment);
|
||||
|
||||
if (!_print_segment(f, vg, seg_count++, seg)) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
_dec_indent(f);
|
||||
_out(f, "}");
|
||||
}
|
||||
|
||||
_dec_indent(f);
|
||||
_out(f, "}");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* In the text format we refer to pv's as 'pv1',
|
||||
* 'pv2' etc. This function builds a hash table
|
||||
* to enable a quick lookup from device -> name.
|
||||
*/
|
||||
static int _build_pv_names(struct formatter *f,
|
||||
struct volume_group *vg)
|
||||
{
|
||||
int count = 0;
|
||||
struct list *pvh;
|
||||
struct physical_volume *pv;
|
||||
char buffer[32], *name;
|
||||
|
||||
if (!(f->mem = pool_create(512))) {
|
||||
stack;
|
||||
goto bad;
|
||||
}
|
||||
|
||||
if (!(f->pv_names = hash_create(128))) {
|
||||
stack;
|
||||
goto bad;
|
||||
}
|
||||
|
||||
list_iterate (pvh, &vg->pvs) {
|
||||
pv = list_item(pvh, struct pv_list)->pv;
|
||||
|
||||
if (lvm_snprintf(buffer, sizeof(buffer),
|
||||
"pv%d", count++) < 0) {
|
||||
stack;
|
||||
goto bad;
|
||||
}
|
||||
|
||||
if (!(name = pool_strdup(f->mem, buffer))) {
|
||||
stack;
|
||||
goto bad;
|
||||
}
|
||||
|
||||
if (!hash_insert(f->pv_names, dev_name(pv->dev), name)) {
|
||||
stack;
|
||||
goto bad;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
bad:
|
||||
if (f->mem)
|
||||
pool_destroy(f->mem);
|
||||
|
||||
if (f->pv_names)
|
||||
hash_destroy(f->pv_names);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int text_vg_export(FILE *fp, struct volume_group *vg)
|
||||
{
|
||||
int r = 0;
|
||||
struct formatter *f;
|
||||
|
||||
if (!(f = dbg_malloc(sizeof(*f)))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
memset(f, 0, sizeof(*f));
|
||||
f->fp = fp;
|
||||
f->indent = 0;
|
||||
|
||||
if (!_build_pv_names(f, vg)) {
|
||||
stack;
|
||||
goto out;
|
||||
}
|
||||
|
||||
#define fail do {stack; goto out;} while(0)
|
||||
|
||||
if (!_print_header(f, vg))
|
||||
fail;
|
||||
|
||||
_out(f, "%s {", vg->name);
|
||||
_inc_indent(f);
|
||||
|
||||
if (!_print_vg(f, vg))
|
||||
fail;
|
||||
|
||||
_nl(f);
|
||||
|
||||
if (!_print_pvs(f, vg))
|
||||
fail;
|
||||
|
||||
_nl(f);
|
||||
|
||||
if (!_print_lvs(f, vg))
|
||||
fail;
|
||||
|
||||
#undef fail
|
||||
|
||||
_dec_indent(f);
|
||||
_out(f, "}");
|
||||
r = !ferror(f->fp);
|
||||
|
||||
out:
|
||||
if (f->mem)
|
||||
pool_destroy(f->mem);
|
||||
|
||||
if (f->pv_names)
|
||||
hash_destroy(f->pv_names);
|
||||
|
||||
dbg_free(f);
|
||||
return r;
|
||||
}
|
||||
161
lib/format_text/flags.c
Normal file
161
lib/format_text/flags.c
Normal file
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
* Copyright (C) 2001 Sistina Software (UK) Limited.
|
||||
*
|
||||
* This file is released under the LGPL.
|
||||
*/
|
||||
|
||||
#include "log.h"
|
||||
#include "metadata.h"
|
||||
#include "import-export.h"
|
||||
#include "lvm-string.h"
|
||||
|
||||
/*
|
||||
* Bitsets held in the 'status' flags get
|
||||
* converted into arrays of strings.
|
||||
*/
|
||||
struct flag {
|
||||
int mask;
|
||||
char *description;
|
||||
};
|
||||
|
||||
static struct flag _vg_flags[] = {
|
||||
{EXPORTED_VG, "EXPORTED"},
|
||||
{RESIZEABLE_VG, "RESIZEABLE"},
|
||||
{PARTIAL_VG, "PARTIAL"},
|
||||
{LVM_READ, "READ"},
|
||||
{LVM_WRITE, "WRITE"},
|
||||
{CLUSTERED, "CLUSTERED"},
|
||||
{SHARED, "SHARED"},
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
static struct flag _pv_flags[] = {
|
||||
{ALLOCATABLE_PV, "ALLOCATABLE"},
|
||||
{EXPORTED_VG, "EXPORTED"},
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
static struct flag _lv_flags[] = {
|
||||
{LVM_READ, "READ"},
|
||||
{LVM_WRITE, "WRITE"},
|
||||
{ALLOC_SIMPLE, "ALLOC_SIMPLE"},
|
||||
{ALLOC_STRICT, "ALLOC_STRICT"},
|
||||
{ALLOC_CONTIGUOUS, "ALLOC_CONTIGUOUS"},
|
||||
{SNAPSHOT, "SNASHOT"},
|
||||
{SNAPSHOT_ORG, "SNAPSHOT_ORIGIN"},
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
static struct flag *_get_flags(int type)
|
||||
{
|
||||
switch (type) {
|
||||
case VG_FLAGS:
|
||||
return _vg_flags;
|
||||
|
||||
case PV_FLAGS:
|
||||
return _pv_flags;
|
||||
|
||||
case LV_FLAGS:
|
||||
return _lv_flags;
|
||||
}
|
||||
|
||||
log_err("Unknown flag set requested.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int _emit(char **buffer, size_t *size, const char *fmt, ...)
|
||||
{
|
||||
size_t n;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
n = vsnprintf(*buffer, *size, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
if (n < 0 || (n == *size))
|
||||
return 0;
|
||||
|
||||
*buffer += n;
|
||||
*size -= n;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Converts a bitset to an array of string values,
|
||||
* using one of the tables defined at the top of
|
||||
* the file.
|
||||
*/
|
||||
int print_flags(uint32_t status, int type, char *buffer, size_t size)
|
||||
{
|
||||
int f, first = 1;
|
||||
struct flag *flags;
|
||||
|
||||
if (!(flags = _get_flags(type))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!_emit(&buffer, &size, "["))
|
||||
return 0;
|
||||
|
||||
for (f = 0; flags[f].mask; f++) {
|
||||
if (status & flags[f].mask) {
|
||||
if (!first) {
|
||||
if (!_emit(&buffer, &size, ", "))
|
||||
return 0;
|
||||
|
||||
} else
|
||||
first = 0;
|
||||
|
||||
if (!_emit(&buffer, &size, "\"%s\"",
|
||||
flags[f].description))
|
||||
return 0;
|
||||
|
||||
status &= ~flags[f].mask;
|
||||
}
|
||||
}
|
||||
|
||||
if (!_emit(&buffer, &size, "]"))
|
||||
return 0;
|
||||
|
||||
if (status)
|
||||
log_error("Metadata inconsistency: Not all flags successfully "
|
||||
"exported.");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int read_flags(uint32_t *status, int type, struct config_value *cv)
|
||||
{
|
||||
int f;
|
||||
uint32_t s = 0;
|
||||
struct flag *flags;
|
||||
|
||||
if (!(flags = _get_flags(type))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (cv) {
|
||||
if (cv->type != CFG_STRING) {
|
||||
log_err("Status value is not a string.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (f = 0; flags[f].description; f++)
|
||||
if (!strcmp(flags[f].description, cv->v.str)) {
|
||||
s |= flags[f].mask;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!flags[f].description) {
|
||||
log_err("Unknown status flag '%s'.", cv->v.str);
|
||||
return 0;
|
||||
}
|
||||
|
||||
cv = cv->next;
|
||||
}
|
||||
|
||||
*status = s;
|
||||
return 1;
|
||||
}
|
||||
210
lib/format_text/format-text.c
Normal file
210
lib/format_text/format-text.c
Normal file
@@ -0,0 +1,210 @@
|
||||
/*
|
||||
* Copyright (C) 2001 Sistina Software (UK) Limited.
|
||||
*
|
||||
* This file is released under the LGPL.
|
||||
*/
|
||||
|
||||
#include "format-text.h"
|
||||
#include "import-export.h"
|
||||
|
||||
#include "lvm-file.h"
|
||||
#include "log.h"
|
||||
#include "pool.h"
|
||||
#include "config.h"
|
||||
#include "hash.h"
|
||||
#include "dbg_malloc.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/file.h>
|
||||
#include <limits.h>
|
||||
|
||||
/*
|
||||
* NOTE: Currently there can be only one vg per file.
|
||||
*/
|
||||
|
||||
struct text_c {
|
||||
char *path;
|
||||
struct uuid_map *um;
|
||||
};
|
||||
|
||||
static void _not_written(const char *cmd)
|
||||
{
|
||||
log_err("The text format is lacking an implementation for '%s'", cmd);
|
||||
}
|
||||
|
||||
static struct list *_get_vgs(struct format_instance *fi)
|
||||
{
|
||||
_not_written("_get_vgs");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct list *_get_pvs(struct format_instance *fi)
|
||||
{
|
||||
_not_written("_get_vgs");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct physical_volume *_pv_read(struct format_instance *fi,
|
||||
const char *pv_name)
|
||||
{
|
||||
_not_written("_get_vgs");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int _pv_setup(struct format_instance *fi, struct physical_volume *pv,
|
||||
struct volume_group *vg)
|
||||
{
|
||||
_not_written("_get_vgs");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _pv_write(struct format_instance *fi, struct physical_volume *pv)
|
||||
{
|
||||
_not_written("_get_vgs");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _vg_setup(struct format_instance *fi, struct volume_group *vg)
|
||||
{
|
||||
_not_written("_get_vgs");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct volume_group *_vg_read(struct format_instance *fi,
|
||||
const char *vg_name)
|
||||
{
|
||||
struct text_c *tc = (struct text_c *) fi->private;
|
||||
struct volume_group *vg;
|
||||
|
||||
if (!(vg = text_vg_import(fi->cmd, tc->path, tc->um))) {
|
||||
stack;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Currently you can only have a single volume group per
|
||||
* text file (this restriction may remain). We need to
|
||||
* check that it contains the correct volume group.
|
||||
*/
|
||||
if (strcmp(vg_name, vg->name)) {
|
||||
pool_free(fi->cmd->mem, vg);
|
||||
log_err("'%s' does not contain volume group '%s'.",
|
||||
tc->path, vg_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return vg;
|
||||
}
|
||||
|
||||
static int _vg_write(struct format_instance *fi, struct volume_group *vg)
|
||||
{
|
||||
struct text_c *tc = (struct text_c *) fi->private;
|
||||
|
||||
FILE *fp;
|
||||
int fd;
|
||||
char *slash;
|
||||
char temp_file[PATH_MAX], temp_dir[PATH_MAX];
|
||||
|
||||
slash = rindex(tc->path, '/');
|
||||
|
||||
if (slash == 0)
|
||||
strcpy(temp_dir, ".");
|
||||
else if (slash - tc->path < PATH_MAX) {
|
||||
strncpy(temp_dir, tc->path, slash - tc->path);
|
||||
temp_dir[slash - tc->path] = '\0';
|
||||
|
||||
} else {
|
||||
log_error("Text format failed to determine directory.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!create_temp_name(temp_dir, temp_file, sizeof(temp_file), &fd)) {
|
||||
log_err("Couldn't create temporary text file name.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(fp = fdopen(fd, "w"))) {
|
||||
log_sys_error("fdopen", temp_file);
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!text_vg_export(fp, vg)) {
|
||||
log_error("Failed to write metadata to %s.", temp_file);
|
||||
fclose(fp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (fclose(fp)) {
|
||||
log_sys_error("fclose", tc->path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (rename(temp_file, tc->path)) {
|
||||
log_error("%s: rename to %s failed: %s", temp_file, tc->path,
|
||||
strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void _destroy(struct format_instance *fi)
|
||||
{
|
||||
struct text_c *tc = (struct text_c *) fi->private;
|
||||
|
||||
dbg_free(tc->path);
|
||||
dbg_free(tc);
|
||||
dbg_free(fi);
|
||||
}
|
||||
|
||||
static struct format_handler _text_handler = {
|
||||
get_vgs: _get_vgs,
|
||||
get_pvs: _get_pvs,
|
||||
pv_read: _pv_read,
|
||||
pv_setup: _pv_setup,
|
||||
pv_write: _pv_write,
|
||||
vg_setup: _vg_setup,
|
||||
vg_read: _vg_read,
|
||||
vg_write: _vg_write,
|
||||
destroy: _destroy
|
||||
};
|
||||
|
||||
struct format_instance *text_format_create(struct cmd_context *cmd,
|
||||
const char *file,
|
||||
struct uuid_map *um)
|
||||
{
|
||||
const char *no_alloc = "Couldn't allocate text format object.";
|
||||
|
||||
struct format_instance *fi;
|
||||
char *path;
|
||||
struct text_c *tc;
|
||||
|
||||
if (!(fi = dbg_malloc(sizeof(*fi)))) {
|
||||
log_err(no_alloc);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(path = dbg_strdup(file))) {
|
||||
dbg_free(fi);
|
||||
log_err(no_alloc);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(tc = dbg_malloc(sizeof(*tc)))) {
|
||||
dbg_free(fi);
|
||||
dbg_free(path);
|
||||
log_err(no_alloc);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tc->path = path;
|
||||
tc->um = um;
|
||||
|
||||
fi->cmd = cmd;
|
||||
fi->ops = &_text_handler;
|
||||
fi->private = tc;
|
||||
|
||||
return fi;
|
||||
}
|
||||
37
lib/format_text/format-text.h
Normal file
37
lib/format_text/format-text.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (C) 2001 Sistina Software (UK) Limited.
|
||||
*
|
||||
* This file is released under the LGPL.
|
||||
*/
|
||||
|
||||
#ifndef _LVM_FORMAT_TEXT_H
|
||||
#define _LVM_FORMAT_TEXT_H
|
||||
|
||||
#include "lvm-types.h"
|
||||
#include "metadata.h"
|
||||
#include "uuid-map.h"
|
||||
|
||||
/*
|
||||
* The archive format is used to maintain a set of metadata backup files
|
||||
* in an archive directory.
|
||||
* 'retain_days' is the minimum number of days that an archive file must
|
||||
* be held for.
|
||||
*
|
||||
* 'min_archives' is the minimum number of archives required to be kept
|
||||
* for each volume group.
|
||||
*/
|
||||
struct format_instance *archive_format_create(struct cmd_context *cmd,
|
||||
const char *dir,
|
||||
uint32_t retain_days,
|
||||
uint32_t min_archives);
|
||||
|
||||
void backup_expire(struct format_instance *fi);
|
||||
|
||||
/*
|
||||
* The text format can read and write a volume_group to a file.
|
||||
*/
|
||||
struct format_instance *text_format_create(struct cmd_context *cmd,
|
||||
const char *file,
|
||||
struct uuid_map *um);
|
||||
|
||||
#endif
|
||||
31
lib/format_text/import-export.h
Normal file
31
lib/format_text/import-export.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (C) 2001 Sistina Software (UK) Limited.
|
||||
*
|
||||
* This file is released under the LGPL.
|
||||
*/
|
||||
|
||||
#ifndef _LVM_TEXT_IMPORT_EXPORT_H
|
||||
#define _LVM_TEXT_IMPORT_EXPORT_H
|
||||
|
||||
#include "config.h"
|
||||
#include "lvm-types.h"
|
||||
#include "metadata.h"
|
||||
#include "uuid-map.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
enum {
|
||||
VG_FLAGS,
|
||||
PV_FLAGS,
|
||||
LV_FLAGS
|
||||
};
|
||||
|
||||
int print_flags(uint32_t status, int type, char *buffer, size_t size);
|
||||
int read_flags(uint32_t *status, int type, struct config_value *cv);
|
||||
|
||||
|
||||
int text_vg_export(FILE *fp, struct volume_group *vg);
|
||||
struct volume_group *text_vg_import(struct cmd_context *cmd, const char *file,
|
||||
struct uuid_map *um);
|
||||
|
||||
#endif
|
||||
552
lib/format_text/import.c
Normal file
552
lib/format_text/import.c
Normal file
@@ -0,0 +1,552 @@
|
||||
/*
|
||||
* Copyright (C) 2001 Sistina Software (UK) Limited.
|
||||
*
|
||||
* This file is released under the LGPL.
|
||||
*/
|
||||
|
||||
#include "metadata.h"
|
||||
#include "import-export.h"
|
||||
#include "pool.h"
|
||||
#include "log.h"
|
||||
#include "uuid.h"
|
||||
#include "hash.h"
|
||||
|
||||
|
||||
typedef int (*section_fn)(struct pool *mem,
|
||||
struct volume_group *vg, struct config_node *pvn,
|
||||
struct config_node *vgn, struct hash_table *pv_hash,
|
||||
struct uuid_map *um);
|
||||
|
||||
#define _read_int32(root, path, result) \
|
||||
get_config_uint32(root, path, '/', result)
|
||||
|
||||
#define _read_int64(root, path, result) \
|
||||
get_config_uint64(root, path, '/', result)
|
||||
|
||||
static int _read_id(struct id *id, struct config_node *cn, const char *path)
|
||||
{
|
||||
struct config_value *cv;
|
||||
|
||||
if (!(cn = find_config_node(cn, path, '/'))) {
|
||||
log_err("Couldn't find uuid.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
cv = cn->v;
|
||||
if (!cv || !cv->v.str) {
|
||||
log_err("uuid must be a string.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!id_read_format(id, cv->v.str)) {
|
||||
log_err("Invalid uuid.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _read_pv(struct pool *mem,
|
||||
struct volume_group *vg, struct config_node *pvn,
|
||||
struct config_node *vgn,
|
||||
struct hash_table *pv_hash,
|
||||
struct uuid_map *um)
|
||||
{
|
||||
struct physical_volume *pv;
|
||||
struct pv_list *pvl;
|
||||
struct config_node *cn;
|
||||
|
||||
if (!(pvl = pool_zalloc(mem, sizeof(*pvl))) ||
|
||||
!(pvl->pv = pool_zalloc(mem, sizeof(*pvl->pv)))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
pv = pvl->pv;
|
||||
|
||||
/*
|
||||
* Add the pv to the pv hash for quick lookup when we read
|
||||
* the lv segments.
|
||||
*/
|
||||
if (!hash_insert(pv_hash, pvn->key, pv)) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(pvn = pvn->child)) {
|
||||
log_err("Empty pv section.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!_read_id(&pv->id, pvn, "id")) {
|
||||
log_err("Couldn't read uuid for volume group.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Use the uuid map to convert the uuid into a device.
|
||||
*/
|
||||
if (!(pv->dev = uuid_map_lookup(um, &pv->id))) {
|
||||
char buffer[64];
|
||||
|
||||
if (!id_write_format(&pv->id, buffer, sizeof(buffer))) {
|
||||
log_err("Couldn't find device.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
log_err("Couldn't find device with uuid '%s'.", buffer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(pv->vg_name = pool_strdup(mem, vg->name))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(cn = find_config_node(pvn, "status", '/'))) {
|
||||
log_err("Couldn't find status flags for physical volume.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(read_flags(&pv->status, PV_FLAGS, cn->v))) {
|
||||
log_err("Couldn't read status flags for physical volume.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!_read_int64(pvn, "pe_start", &pv->pe_start)) {
|
||||
log_err("Couldn't read extent size for volume group.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!_read_int32(pvn, "pe_count", &pv->pe_count)) {
|
||||
log_err("Couldn't find extent count (pe_count) for "
|
||||
"physical volume.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* adjust the volume group. */
|
||||
vg->extent_count += pv->pe_count;
|
||||
vg->free_count += pv->pe_count;
|
||||
|
||||
pv->pe_size = vg->extent_size;
|
||||
pv->size = pv->pe_size * (uint64_t) pv->pe_count;
|
||||
pv->pe_allocated = 0;
|
||||
|
||||
vg->pv_count++;
|
||||
list_add(&vg->pvs, &pvl->list);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void _insert_segment(struct logical_volume *lv,
|
||||
struct stripe_segment *seg)
|
||||
{
|
||||
struct list *segh;
|
||||
struct stripe_segment *comp;
|
||||
|
||||
list_iterate (segh, &lv->segments) {
|
||||
comp = list_item(segh, struct stripe_segment);
|
||||
|
||||
if (comp->le > seg->le) {
|
||||
list_add(&comp->list, &seg->list);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
lv->le_count += seg->len;
|
||||
list_add(&lv->segments, &seg->list);
|
||||
}
|
||||
|
||||
static int _read_segment(struct pool *mem, struct volume_group *vg,
|
||||
struct logical_volume *lv, struct config_node *sn,
|
||||
struct hash_table *pv_hash)
|
||||
{
|
||||
int s;
|
||||
uint32_t stripes;
|
||||
struct stripe_segment *seg;
|
||||
struct config_node *cn;
|
||||
struct config_value *cv;
|
||||
const char *seg_name = sn->key;
|
||||
|
||||
if (!(sn = sn->child)) {
|
||||
log_err("Empty segment section.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!_read_int32(sn, "stripes", &stripes)) {
|
||||
log_err("Couldn't read 'stripes' for segment '%s'.",
|
||||
sn->key);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(seg = pool_zalloc(mem, sizeof(*seg) +
|
||||
(sizeof(seg->area[0]) * stripes)))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
seg->stripes = stripes;
|
||||
|
||||
if (!_read_int32(sn, "start_extent", &seg->le)) {
|
||||
log_err("Couldn't read 'start_extent' for segment '%s'.",
|
||||
sn->key);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!_read_int32(sn, "extent_count", &seg->len)) {
|
||||
log_err("Couldn't read 'extent_count' for segment '%s'.",
|
||||
sn->key);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (seg->stripes == 0) {
|
||||
log_err("Zero stripes is *not* allowed for segment '%s'.",
|
||||
sn->key);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((seg->stripes != 1) &&
|
||||
!_read_int32(sn, "stripe_size", &seg->stripe_size)) {
|
||||
log_err("Couldn't read 'stripe_size' for segment '%s'.",
|
||||
sn->key);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(cn = find_config_node(sn, "areas", '/'))) {
|
||||
log_err("Couldn't find 'areas' array for segment '%s'.",
|
||||
sn->key);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Read the stripes from the 'areas' array.
|
||||
* FIXME: we could move this to a separate function.
|
||||
*/
|
||||
for (cv = cn->v, s = 0; cv && s < seg->stripes; s++, cv = cv->next) {
|
||||
|
||||
/* first we read the pv */
|
||||
const char *bad = "Badly formed areas array for segment '%s'.";
|
||||
struct physical_volume *pv;
|
||||
uint32_t allocated;
|
||||
|
||||
if (cv->type != CFG_STRING) {
|
||||
log_err(bad, sn->key);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(pv = hash_lookup(pv_hash, cv->v.str))) {
|
||||
log_err("Couldn't find physical volume '%s' for "
|
||||
"segment '%s'.",
|
||||
cn->v->v.str ? cn->v->v.str : "NULL",
|
||||
seg_name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
seg->area[s].pv = pv;
|
||||
|
||||
if (!(cv = cv->next)) {
|
||||
log_err(bad, sn->key);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (cv->type != CFG_INT) {
|
||||
log_err(bad, sn->key);
|
||||
return 0;
|
||||
}
|
||||
|
||||
seg->area[s].pe = cv->v.i;
|
||||
|
||||
/*
|
||||
* Adjust the extent counts in the pv and vg.
|
||||
*/
|
||||
allocated = seg->len / seg->stripes;
|
||||
pv->pe_allocated += allocated;
|
||||
vg->free_count -= allocated;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check we read the correct number of stripes.
|
||||
*/
|
||||
if (cv || (s < seg->stripes)) {
|
||||
log_err("Incorrect number of stripes in 'area' array "
|
||||
"for segment '%s'.", seg_name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Insert into correct part of segment list.
|
||||
*/
|
||||
_insert_segment(lv, seg);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _read_segments(struct pool *mem, struct volume_group *vg,
|
||||
struct logical_volume *lv, struct config_node *lvn,
|
||||
struct hash_table *pv_hash)
|
||||
{
|
||||
struct config_node *sn;
|
||||
int count = 0, seg_count;
|
||||
|
||||
for (sn = lvn; sn; sn = sn->sib) {
|
||||
|
||||
/*
|
||||
* All sub-sections are assumed to be segments.
|
||||
*/
|
||||
if (!sn->v) {
|
||||
if (!_read_segment(mem, vg, lv, sn, pv_hash)) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
if (!_read_int32(lvn, "segment_count", &seg_count)) {
|
||||
log_err("Couldn't read segment count for logical volume.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (seg_count != count) {
|
||||
log_err("segment_count and actual number of segments "
|
||||
"disagree.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check there are no gaps or overlaps in the lv.
|
||||
*/
|
||||
if (!lv_check_segments(lv)) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Merge segments in case someones been editing things by hand.
|
||||
*/
|
||||
if (!lv_merge_segments(lv)) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _read_lv(struct pool *mem,
|
||||
struct volume_group *vg, struct config_node *lvn,
|
||||
struct config_node *vgn, struct hash_table *pv_hash,
|
||||
struct uuid_map *um)
|
||||
{
|
||||
struct logical_volume *lv;
|
||||
struct lv_list *lvl;
|
||||
struct config_node *cn;
|
||||
|
||||
if (!(lvl = pool_zalloc(mem, sizeof(*lvl))) ||
|
||||
!(lvl->lv = pool_zalloc(mem, sizeof(*lvl->lv)))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
lv = lvl->lv;
|
||||
|
||||
if (!(lv->name = pool_strdup(mem, lvn->key))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(lvn = lvn->child)) {
|
||||
log_err("Empty logical volume section.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
lv->vg = vg;
|
||||
|
||||
|
||||
if (!(cn = find_config_node(lvn, "status", '/'))) {
|
||||
log_err("Couldn't find status flags for logical volume.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(read_flags(&lv->status, LV_FLAGS, cn->v))) {
|
||||
log_err("Couldn't read status flags for logical volume.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!_read_int32(lvn, "read_ahead", &lv->read_ahead)) {
|
||||
log_err("Couldn't read 'read_ahead' value for "
|
||||
"logical volume.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
list_init(&lv->segments);
|
||||
if (!_read_segments(mem, vg, lv, lvn, pv_hash)) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
lv->size = (uint64_t) lv->le_count * (uint64_t) vg->extent_size;
|
||||
|
||||
vg->lv_count++;
|
||||
list_add(&vg->lvs, &lvl->list);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _read_sections(const char *section, section_fn fn,
|
||||
struct pool *mem,
|
||||
struct volume_group *vg, struct config_node *vgn,
|
||||
struct hash_table *pv_hash,
|
||||
struct uuid_map *um)
|
||||
{
|
||||
struct config_node *n;
|
||||
|
||||
if (!(n = find_config_node(vgn, section, '/'))) {
|
||||
log_err("Couldn't find section '%s'.", section);
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (n = n->child; n; n = n->sib) {
|
||||
if (!fn(mem, vg, n, vgn, pv_hash, um)) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static struct volume_group *_read_vg(struct pool *mem, struct config_file *cf,
|
||||
struct uuid_map *um)
|
||||
{
|
||||
struct config_node *vgn = cf->root, *cn;
|
||||
struct volume_group *vg;
|
||||
struct hash_table *pv_hash = NULL;
|
||||
|
||||
if (!vgn) {
|
||||
log_err("Couldn't find volume group.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(vgn = cf->root)) {
|
||||
log_err("Couldn't find volume group in file.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(vg = pool_zalloc(mem, sizeof(*vg)))) {
|
||||
stack;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(vg->name = pool_strdup(mem, vgn->key))) {
|
||||
stack;
|
||||
goto bad;
|
||||
}
|
||||
|
||||
vgn = vgn->child;
|
||||
if (!_read_id(&vg->id, vgn, "id")) {
|
||||
log_err("Couldn't read uuid for volume group %s.",
|
||||
vg->name);
|
||||
goto bad;
|
||||
}
|
||||
|
||||
if (!(cn = find_config_node(vgn, "status", '/'))) {
|
||||
log_err("Couldn't find status flags for volume group %s.",
|
||||
vg->name);
|
||||
goto bad;
|
||||
}
|
||||
|
||||
if (!(read_flags(&vg->status, VG_FLAGS, cn->v))) {
|
||||
log_err("Couldn't read status flags for volume group %s.",
|
||||
vg->name);
|
||||
goto bad;
|
||||
}
|
||||
|
||||
if (!_read_int32(vgn, "extent_size", &vg->extent_size)) {
|
||||
log_err("Couldn't read extent size for volume group %s.",
|
||||
vg->name);
|
||||
goto bad;
|
||||
}
|
||||
|
||||
/*
|
||||
* 'extent_count' and 'free_count' get filled in
|
||||
* implicitly when reading in the pv's and lv's.
|
||||
*/
|
||||
|
||||
if (!_read_int32(vgn, "max_lv", &vg->max_lv)) {
|
||||
log_err("Couldn't read 'max_lv' for volume group %s.",
|
||||
vg->name);
|
||||
goto bad;
|
||||
}
|
||||
|
||||
if (!_read_int32(vgn, "max_pv", &vg->max_pv)) {
|
||||
log_err("Couldn't read 'max_pv' for volume group %s.",
|
||||
vg->name);
|
||||
goto bad;
|
||||
}
|
||||
|
||||
/*
|
||||
* The pv hash memoises the pv section names -> pv
|
||||
* structures.
|
||||
*/
|
||||
if (!(pv_hash = hash_create(32))) {
|
||||
log_err("Couldn't create hash table.");
|
||||
goto bad;
|
||||
}
|
||||
|
||||
list_init(&vg->pvs);
|
||||
if (!_read_sections("physical_volumes", _read_pv, mem, vg,
|
||||
vgn, pv_hash, um)) {
|
||||
log_err("Couldn't find all physical volumes for volume "
|
||||
"group %s.", vg->name);
|
||||
goto bad;
|
||||
}
|
||||
|
||||
list_init(&vg->lvs);
|
||||
if (!_read_sections("logical_volumes", _read_lv, mem, vg,
|
||||
vgn, pv_hash, um)) {
|
||||
log_err("Couldn't read all logical volumes for volume "
|
||||
"group %s.", vg->name);
|
||||
goto bad;
|
||||
}
|
||||
|
||||
hash_destroy(pv_hash);
|
||||
|
||||
/*
|
||||
* Finished.
|
||||
*/
|
||||
return vg;
|
||||
|
||||
bad:
|
||||
if (pv_hash)
|
||||
hash_destroy(pv_hash);
|
||||
|
||||
pool_free(mem, vg);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct volume_group *text_vg_import(struct cmd_context *cmd,
|
||||
const char *file,
|
||||
struct uuid_map *um)
|
||||
{
|
||||
struct volume_group *vg = NULL;
|
||||
struct config_file *cf;
|
||||
|
||||
if (!(cf = create_config_file())) {
|
||||
stack;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!read_config(cf, file)) {
|
||||
log_error("Couldn't read volume group file.");
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!(vg = _read_vg(cmd->mem, cf, um))) {
|
||||
stack;
|
||||
goto out;
|
||||
}
|
||||
|
||||
vg->cmd = cmd;
|
||||
|
||||
out:
|
||||
destroy_config_file(cf);
|
||||
return vg;
|
||||
}
|
||||
67
lib/format_text/sample.vg
Normal file
67
lib/format_text/sample.vg
Normal file
@@ -0,0 +1,67 @@
|
||||
# An example volume group
|
||||
|
||||
# YYYY-MM-DD HH:MM:SS
|
||||
output_date = "2001-12-11 11:35:12"
|
||||
|
||||
sample_volume_group {
|
||||
|
||||
id = "ksjdlfksjldskjlsk"
|
||||
status = ["ACTIVE"]
|
||||
|
||||
extent_size = 8192 # 4 Megabytes
|
||||
|
||||
max_lv = 99
|
||||
max_pv = 255
|
||||
|
||||
physical_volumes {
|
||||
|
||||
pv1 {
|
||||
id = "lksjdflksdlsk"
|
||||
device = "/dev/hda1" # Hint only
|
||||
|
||||
status = ["ALLOCATABLE"]
|
||||
pe_start = 8192
|
||||
pe_count = 2048 # 8 Gigabytes
|
||||
}
|
||||
|
||||
pv2 {
|
||||
id = "lksjdflksdlsk"
|
||||
device = "/dev/hda2" # Hint only
|
||||
|
||||
status = ["ALLOCATABLE"]
|
||||
pe_start = 8192
|
||||
pe_count = 1024 # 4 Gigabytes
|
||||
}
|
||||
}
|
||||
|
||||
logical_volumes {
|
||||
|
||||
music {
|
||||
status = ["ACTIVE"]
|
||||
read_ahead = 1024
|
||||
|
||||
segment_count = 2
|
||||
|
||||
segment1 {
|
||||
start_extent = 0
|
||||
extent_count = 1024 # 4 Gigabytes
|
||||
stripes = 1
|
||||
|
||||
areas = [
|
||||
"pv1", 0
|
||||
]
|
||||
}
|
||||
|
||||
segment2 {
|
||||
start_extent = 1024
|
||||
extent_count = 2048 # 8 Gigabytes
|
||||
stripes = 2
|
||||
stripe_size = 32 # 16 Kilobytes
|
||||
|
||||
areas = [
|
||||
"pv1", 1024,
|
||||
"pv2", 0
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
154
lib/label/label.c
Normal file
154
lib/label/label.c
Normal file
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
* Copyright (C) 2002 Sistina Software
|
||||
*
|
||||
* This file is released under the LGPL.
|
||||
*/
|
||||
|
||||
#include "label.h"
|
||||
#include "list.h"
|
||||
#include "dbg_malloc.h"
|
||||
#include "log.h"
|
||||
|
||||
/*
|
||||
* Internal labeller struct.
|
||||
*/
|
||||
struct labeller_i {
|
||||
struct list list;
|
||||
|
||||
struct labeller *l;
|
||||
char name[0];
|
||||
};
|
||||
|
||||
static struct list _labellers;
|
||||
|
||||
|
||||
static struct labeller_i *_alloc_li(const char *name, struct labeller *l)
|
||||
{
|
||||
struct labeller_i *li;
|
||||
size_t len;
|
||||
|
||||
len = sizeof(*li) + strlen(name) + 1;
|
||||
|
||||
if (!(li = dbg_malloc(len))) {
|
||||
log_error("Couldn't allocate memory for labeller list object.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
li->l = l;
|
||||
strcpy(li->name, name);
|
||||
|
||||
return li;
|
||||
}
|
||||
|
||||
static void _free_li(struct labeller_i *li)
|
||||
{
|
||||
dbg_free(li);
|
||||
}
|
||||
|
||||
|
||||
int label_init(void)
|
||||
{
|
||||
list_init(&_labellers);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void label_exit(void)
|
||||
{
|
||||
struct list *c, *n;
|
||||
struct labeller_i *li;
|
||||
|
||||
for (c = _labellers.n; c != &_labellers; c = n) {
|
||||
n = c->n;
|
||||
li = list_item(c, struct labeller_i);
|
||||
_free_li(li);
|
||||
}
|
||||
}
|
||||
|
||||
int label_register_handler(const char *name, struct labeller *handler)
|
||||
{
|
||||
struct labeller_i *li;
|
||||
|
||||
if (!(li = _alloc_li(name, handler))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
list_add(&_labellers, &li->list);
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct labeller *label_get_handler(const char *name)
|
||||
{
|
||||
struct list *lih;
|
||||
struct labeller_i *li;
|
||||
|
||||
list_iterate (lih, &_labellers) {
|
||||
li = list_item(lih, struct labeller_i);
|
||||
if (!strcmp(li->name, name))
|
||||
return li->l;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct labeller *_find_labeller(struct device *dev)
|
||||
{
|
||||
struct list *lih;
|
||||
struct labeller_i *li;
|
||||
|
||||
list_iterate (lih, &_labellers) {
|
||||
li = list_item(lih, struct labeller_i);
|
||||
if (li->l->ops->can_handle(li->l, dev))
|
||||
return li->l;
|
||||
}
|
||||
|
||||
log_debug("No label on device '%s'.", dev_name(dev));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int label_remove(struct device *dev)
|
||||
{
|
||||
struct labeller *l;
|
||||
|
||||
if (!(l = _find_labeller(dev))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return l->ops->remove(l, dev);
|
||||
}
|
||||
|
||||
int label_read(struct device *dev, struct label **result)
|
||||
{
|
||||
int r;
|
||||
struct list *lih;
|
||||
struct labeller_i *li;
|
||||
|
||||
list_iterate (lih, &_labellers) {
|
||||
li = list_item(lih, struct labeller_i);
|
||||
if ((r = li->l->ops->read(li->l, dev, result))) {
|
||||
(*result)->labeller = li->l;
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
log_debug("No label on device '%s'.", dev_name(dev));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int label_verify(struct device *dev)
|
||||
{
|
||||
struct labeller *l;
|
||||
|
||||
if (!(l = _find_labeller(dev))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return l->ops->verify(l, dev);
|
||||
}
|
||||
|
||||
void label_destroy(struct label *lab)
|
||||
{
|
||||
lab->labeller->ops->destroy_label(lab->labeller, lab);
|
||||
}
|
||||
90
lib/label/label.h
Normal file
90
lib/label/label.h
Normal file
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (C) 2002 Sistina Software (UK) Limited.
|
||||
*
|
||||
* This file is released under the LGPL.
|
||||
*/
|
||||
|
||||
#ifndef _LVM_LABEL_H
|
||||
#define _LVM_LABEL_H
|
||||
|
||||
#include "uuid.h"
|
||||
#include "device.h"
|
||||
|
||||
struct label {
|
||||
struct id id;
|
||||
|
||||
char volume_type[32];
|
||||
uint32_t version[3];
|
||||
|
||||
void *extra_info;
|
||||
|
||||
struct labeller *labeller;
|
||||
};
|
||||
|
||||
struct labeller;
|
||||
|
||||
struct label_ops {
|
||||
/*
|
||||
* Is the device labelled with this format ?
|
||||
*/
|
||||
int (*can_handle)(struct labeller *l, struct device *dev);
|
||||
|
||||
/*
|
||||
* Write a label to a volume.
|
||||
*/
|
||||
int (*write)(struct labeller *l,
|
||||
struct device *dev, struct label *label);
|
||||
|
||||
/*
|
||||
* Remove a label from a device.
|
||||
*/
|
||||
int (*remove)(struct labeller *l, struct device *dev);
|
||||
|
||||
/*
|
||||
* Read a label from a volume.
|
||||
*/
|
||||
int (*read)(struct labeller *l,
|
||||
struct device *dev, struct label **label);
|
||||
|
||||
/*
|
||||
* Additional consistency checks for the paranoid.
|
||||
*/
|
||||
int (*verify)(struct labeller *l, struct device *dev);
|
||||
|
||||
/*
|
||||
* Destroy a previously read label.
|
||||
*/
|
||||
void (*destroy_label)(struct labeller *l, struct label *label);
|
||||
|
||||
/*
|
||||
* Destructor.
|
||||
*/
|
||||
void (*destroy)(struct labeller *l);
|
||||
};
|
||||
|
||||
struct labeller {
|
||||
struct label_ops *ops;
|
||||
void *private;
|
||||
};
|
||||
|
||||
|
||||
int label_init(void);
|
||||
void label_exit(void);
|
||||
|
||||
int label_register_handler(const char *name, struct labeller *handler);
|
||||
|
||||
struct labeller *label_get_handler(const char *name);
|
||||
|
||||
int label_remove(struct device *dev);
|
||||
int label_read(struct device *dev, struct label **result);
|
||||
int label_verify(struct device *dev);
|
||||
void label_destroy(struct label *lab);
|
||||
|
||||
/*
|
||||
* We'll support two label types: the 'pretend the
|
||||
* LVM1 pv structure at the begining of the disk
|
||||
* is a label' hack, and pjc's 1 sector labels at
|
||||
* the front and back of the device.
|
||||
*/
|
||||
|
||||
#endif
|
||||
561
lib/label/lvm2_label.c
Normal file
561
lib/label/lvm2_label.c
Normal file
@@ -0,0 +1,561 @@
|
||||
/*
|
||||
* Copyright (C) 2001-2002 Sistina Software
|
||||
*
|
||||
* This file is released under the LGPL.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "device.h"
|
||||
#include "dev-cache.h"
|
||||
#include "log.h"
|
||||
#include "pool.h"
|
||||
#include "dbg_malloc.h"
|
||||
#include "filter.h"
|
||||
#include "label.h"
|
||||
#include "lvm2_label.h"
|
||||
#include "xlate.h"
|
||||
|
||||
/* Label Magic is "LnXl" - error: imagination failure */
|
||||
#define LABEL_MAGIC 0x6c586e4c
|
||||
|
||||
/* Size of blocks that dev_get_size() returns the number of */
|
||||
#define BLOCK_SIZE 512
|
||||
|
||||
/* This is just the "struct lvm2_label" with the data pointer removed */
|
||||
struct label_ondisk
|
||||
{
|
||||
uint32_t magic;
|
||||
uint32_t crc;
|
||||
uint64_t label1_loc;
|
||||
uint64_t label2_loc;
|
||||
uint16_t datalen;
|
||||
uint16_t pad;
|
||||
|
||||
uint32_t version[3];
|
||||
char disk_type[32];
|
||||
};
|
||||
|
||||
struct filter_private
|
||||
{
|
||||
void *mem;
|
||||
char disk_type[32];
|
||||
uint32_t version[3];
|
||||
int version_match;
|
||||
};
|
||||
|
||||
|
||||
/* Calculate CRC32 of a buffer */
|
||||
static uint32_t crc32(uint32_t initial, const unsigned char *databuf, size_t datalen)
|
||||
{
|
||||
static const u_int crctab[] = {
|
||||
0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac,
|
||||
0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c,
|
||||
0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c,
|
||||
0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c
|
||||
};
|
||||
uint32_t idx, crc = initial;
|
||||
|
||||
for (idx = 0; idx < datalen; idx++) {
|
||||
crc ^= *databuf++;
|
||||
crc = (crc >> 4) ^ crctab[crc & 0xf];
|
||||
crc = (crc >> 4) ^ crctab[crc & 0xf];
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
|
||||
/* Calculate crc */
|
||||
static uint32_t calc_crc(struct label_ondisk *label, char *data)
|
||||
{
|
||||
uint32_t crcval = 0xffffffff;
|
||||
|
||||
crcval = crc32(crcval, (char *)&label->magic, sizeof(label->magic));
|
||||
crcval = crc32(crcval, (char *)&label->label1_loc, sizeof(label->label1_loc));
|
||||
crcval = crc32(crcval, (char *)&label->label2_loc, sizeof(label->label2_loc));
|
||||
crcval = crc32(crcval, (char *)&label->datalen, sizeof(label->datalen));
|
||||
crcval = crc32(crcval, (char *)&label->version, sizeof(label->version));
|
||||
crcval = crc32(crcval, (char *)label->disk_type, strlen(label->disk_type));
|
||||
crcval = crc32(crcval, (char *)data, label->datalen);
|
||||
|
||||
return crcval;
|
||||
}
|
||||
|
||||
/* Calculate the locations we should find the labels in */
|
||||
static inline void get_label_locations(uint64_t size, uint32_t sectsize, long *first, long *second)
|
||||
{
|
||||
*first = sectsize;
|
||||
*second = size*BLOCK_SIZE - sectsize;
|
||||
}
|
||||
|
||||
/* Read a label off disk */
|
||||
static int lvm2_label_read(struct labeller *l, struct device *dev, struct label **label)
|
||||
{
|
||||
uint64_t size;
|
||||
uint32_t sectsize;
|
||||
char *block;
|
||||
struct label_ondisk *ondisk;
|
||||
int status;
|
||||
int iter;
|
||||
long offset[2];
|
||||
|
||||
if (!dev_get_size(dev, &size))
|
||||
return 0;
|
||||
|
||||
if (!dev_get_sectsize(dev, §size))
|
||||
return 0;
|
||||
|
||||
if (!dev_open(dev, O_RDONLY))
|
||||
return 0;
|
||||
|
||||
block = dbg_malloc(sectsize);
|
||||
if (!block)
|
||||
{
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
ondisk = (struct label_ondisk *)block;
|
||||
get_label_locations(size, sectsize, &offset[0], &offset[1]);
|
||||
|
||||
/* If the first label is bad then use the second */
|
||||
for (iter = 0; iter <= 1; iter++)
|
||||
{
|
||||
status = dev_read(dev, offset[iter], sectsize, block);
|
||||
if (status)
|
||||
{
|
||||
struct label *incore;
|
||||
int i;
|
||||
int found_nul;
|
||||
|
||||
/* If the MAGIC doesn't match there's no point in
|
||||
carrying on */
|
||||
if (xlate32(ondisk->magic) != LABEL_MAGIC)
|
||||
continue;
|
||||
|
||||
/* Look for a NUL in the disk_type string so we don't
|
||||
SEGV is something has gone horribly wrong */
|
||||
found_nul = 0;
|
||||
for (i=0; i<sizeof(ondisk->disk_type); i++)
|
||||
if (ondisk->disk_type[i] == '\0')
|
||||
found_nul = 1;
|
||||
|
||||
if (!found_nul)
|
||||
continue;
|
||||
|
||||
incore = dbg_malloc(sizeof(struct label));
|
||||
if (incore == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Copy and convert endianness */
|
||||
strncpy(incore->volume_type, ondisk->disk_type, sizeof(incore->volume_type));
|
||||
incore->version[0] = xlate32(ondisk->version[0]);
|
||||
incore->version[1] = xlate32(ondisk->version[1]);
|
||||
incore->version[2] = xlate32(ondisk->version[2]);
|
||||
incore->extra_len = xlate16(ondisk->datalen);
|
||||
incore->extra_info = block + sizeof(struct label_ondisk);
|
||||
|
||||
/* Make sure datalen is a sensible size too */
|
||||
if (incore->extra_len > sectsize)
|
||||
continue;
|
||||
|
||||
/* Check Crc */
|
||||
if (xlate32(ondisk->crc) != calc_crc(ondisk, incore->extra_info))
|
||||
{
|
||||
log_error("Crc %d on device %s does not match. got %x, expected %x",
|
||||
iter, dev_name(dev), xlate32(ondisk->crc), calc_crc(ondisk, incore->extra_info));
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Check label locations match our view of the device */
|
||||
if (xlate64(ondisk->label1_loc) != offset[0])
|
||||
log_error("Label 1 location is wrong in label %d - check block size of the device\n",
|
||||
iter);
|
||||
if (xlate64(ondisk->label2_loc) != offset[1])
|
||||
log_error("Label 2 location is wrong in label %d - the size of the device must have changed\n",
|
||||
iter);
|
||||
|
||||
/* Copy to user's data area */
|
||||
*label = incore;
|
||||
incore->extra_info = dbg_malloc(incore->extra_len);
|
||||
if (!incore->extra_info)
|
||||
{
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
memcpy(incore->extra_info, block + sizeof(struct label_ondisk), incore->extra_len);
|
||||
|
||||
dbg_free(block);
|
||||
dev_close(dev);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
dbg_free(block);
|
||||
dev_close(dev);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Write a label to a device */
|
||||
static int lvm2_label_write(struct labeller *l, struct device *dev, struct label *label)
|
||||
{
|
||||
uint64_t size;
|
||||
uint32_t sectsize;
|
||||
char *block;
|
||||
struct label_ondisk *ondisk;
|
||||
int status1, status2;
|
||||
long offset[2];
|
||||
|
||||
if (!dev_get_size(dev, &size))
|
||||
return 0;
|
||||
|
||||
if (!dev_get_sectsize(dev, §size))
|
||||
return 0;
|
||||
|
||||
/* Can the metata fit in the remaining space ? */
|
||||
if (label->extra_len > sectsize - sizeof(struct label_ondisk))
|
||||
return 0;
|
||||
|
||||
block = dbg_malloc(sizeof(struct label_ondisk) + label->extra_len);
|
||||
if (!block)
|
||||
{
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
ondisk = (struct label_ondisk *)block;
|
||||
|
||||
get_label_locations(size, sectsize, &offset[0], &offset[1]);
|
||||
|
||||
/* Make into ondisk format */
|
||||
ondisk->magic = xlate32(LABEL_MAGIC);
|
||||
ondisk->version[0] = xlate32(label->version[0]);
|
||||
ondisk->version[1] = xlate32(label->version[1]);
|
||||
ondisk->version[2] = xlate32(label->version[2]);
|
||||
ondisk->label1_loc = xlate64(offset[0]);
|
||||
ondisk->label2_loc = xlate64(offset[1]);
|
||||
ondisk->datalen = xlate16(label->extra_len);
|
||||
strncpy(ondisk->disk_type, label->volume_type, sizeof(ondisk->disk_type));
|
||||
memcpy(block+sizeof(struct label_ondisk), label->extra_info, label->extra_len);
|
||||
ondisk->crc = xlate32(calc_crc(ondisk, label->extra_info));
|
||||
|
||||
/* Write metadata to disk */
|
||||
if (!dev_open(dev, O_RDWR))
|
||||
{
|
||||
dbg_free(block);
|
||||
return 0;
|
||||
}
|
||||
|
||||
status1 = dev_write(dev, offset[0], sizeof(struct label_ondisk) + label->extra_len, block);
|
||||
if (!status1)
|
||||
log_error("Error writing label 1\n");
|
||||
|
||||
/* Write another at the end of the device */
|
||||
status2 = dev_write(dev, offset[1], sizeof(struct label_ondisk) + label->extra_len, block);
|
||||
if (!status2)
|
||||
{
|
||||
char zerobuf[sizeof(struct label_ondisk)];
|
||||
log_error("Error writing label 2\n");
|
||||
|
||||
/* Wipe the first label so it doesn't get confusing */
|
||||
memset(zerobuf, 0, sizeof(struct label_ondisk));
|
||||
if (!dev_write(dev, offset[0], sizeof(struct label_ondisk), zerobuf))
|
||||
log_error("Error erasing label 1\n");
|
||||
}
|
||||
|
||||
dbg_free(block);
|
||||
dev_close(dev);
|
||||
|
||||
return ((status1 != 0) && (status2 != 0));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Return 1 for Yes, 0 for No */
|
||||
static int lvm2_is_labelled(struct labeller *l, struct device *dev)
|
||||
{
|
||||
struct label *label;
|
||||
int status;
|
||||
|
||||
status = lvm2_label_read(l, dev, &label);
|
||||
if (status) label_free(label);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/* Check the device is labelled and has the right format_type */
|
||||
static int _accept_format(struct dev_filter *f, struct device *dev)
|
||||
{
|
||||
struct label *l;
|
||||
int status;
|
||||
struct filter_private *fp = (struct filter_private *) f->private;
|
||||
|
||||
status = lvm2_label_read(NULL, dev, &l);
|
||||
|
||||
if (status)
|
||||
{
|
||||
if (strcmp(l->volume_type, fp->disk_type) == 0)
|
||||
{
|
||||
switch (fp->version_match)
|
||||
{
|
||||
case VERSION_MATCH_EQUAL:
|
||||
if (l->version[0] == fp->version[0] &&
|
||||
l->version[1] == fp->version[1] &&
|
||||
l->version[2] == fp->version[2])
|
||||
return 1;
|
||||
break;
|
||||
|
||||
case VERSION_MATCH_LESSTHAN:
|
||||
if (l->version[0] == fp->version[0] &&
|
||||
l->version[1] < fp->version[1])
|
||||
return 1;
|
||||
break;
|
||||
|
||||
case VERSION_MATCH_LESSEQUAL:
|
||||
if (l->version[0] == fp->version[0] &&
|
||||
l->version[1] <= fp->version[1])
|
||||
return 1;
|
||||
break;
|
||||
|
||||
case VERSION_MATCH_ANY:
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
label_free(l);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* We just want to know if it's labelled or not */
|
||||
static int _accept_label(struct dev_filter *f, struct device *dev)
|
||||
{
|
||||
return lvm2_is_labelled(NULL, dev);
|
||||
}
|
||||
|
||||
static void _destroy(struct dev_filter *f)
|
||||
{
|
||||
struct filter_private *fp = (struct filter_private *) f->private;
|
||||
}
|
||||
|
||||
/* A filter to find devices with a particular label type on them */
|
||||
struct dev_filter *lvm2_label_format_filter_create(char *disk_type, uint32_t version[3], int match_type)
|
||||
{
|
||||
struct pool *mem;
|
||||
struct filter_private *fp;
|
||||
struct dev_filter *f;
|
||||
|
||||
/* Validate the match type */
|
||||
if (match_type != VERSION_MATCH_EQUAL &&
|
||||
match_type != VERSION_MATCH_LESSTHAN &&
|
||||
match_type != VERSION_MATCH_LESSEQUAL &&
|
||||
match_type != VERSION_MATCH_ANY)
|
||||
return 0;
|
||||
|
||||
mem = pool_create(10 * 1024);
|
||||
if (!mem) {
|
||||
stack;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(f = pool_zalloc(mem, sizeof(*f)))) {
|
||||
stack;
|
||||
goto bad;
|
||||
}
|
||||
|
||||
if (!(fp = pool_zalloc(mem, sizeof(*fp)))) {
|
||||
stack;
|
||||
goto bad;
|
||||
}
|
||||
|
||||
fp->mem = mem;
|
||||
strcpy(fp->disk_type, disk_type);
|
||||
fp->version[0] = version[0];
|
||||
fp->version[1] = version[1];
|
||||
fp->version[2] = version[2];
|
||||
fp->version_match = match_type;
|
||||
f->passes_filter = _accept_format;
|
||||
f->destroy = _destroy;
|
||||
f->private = fp;
|
||||
|
||||
return f;
|
||||
|
||||
bad:
|
||||
pool_destroy(mem);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* A filter to find devices with any label on them */
|
||||
struct dev_filter *lvm2_label_filter_create()
|
||||
{
|
||||
struct pool *mem = pool_create(10 * 1024);
|
||||
struct filter_private *fp;
|
||||
struct dev_filter *f;
|
||||
|
||||
if (!mem) {
|
||||
stack;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(f = pool_zalloc(mem, sizeof(*f)))) {
|
||||
stack;
|
||||
goto bad;
|
||||
}
|
||||
|
||||
if (!(fp = pool_zalloc(mem, sizeof(*fp)))) {
|
||||
stack;
|
||||
goto bad;
|
||||
}
|
||||
|
||||
fp->mem = mem;
|
||||
f->passes_filter = _accept_label;
|
||||
f->destroy = _destroy;
|
||||
f->private = fp;
|
||||
|
||||
return f;
|
||||
|
||||
bad:
|
||||
pool_destroy(mem);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Return 1 if both labels are identical, 0 if not or there was an error */
|
||||
static int lvm2_labels_match(struct labeller *l, struct device *dev)
|
||||
{
|
||||
uint64_t size;
|
||||
uint32_t sectsize;
|
||||
char *block1;
|
||||
char *block2;
|
||||
struct label_ondisk *ondisk1;
|
||||
struct label_ondisk *ondisk2;
|
||||
int status = 0;
|
||||
long offset[2];
|
||||
|
||||
if (!dev_get_size(dev, &size))
|
||||
return 0;
|
||||
|
||||
if (!dev_get_sectsize(dev, §size))
|
||||
return 0;
|
||||
|
||||
/* Allocate some space for the blocks we are going to read in */
|
||||
block1 = dbg_malloc(sectsize);
|
||||
if (!block1)
|
||||
{
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
block2 = dbg_malloc(sectsize);
|
||||
if (!block2)
|
||||
{
|
||||
stack;
|
||||
dbg_free(block1);
|
||||
return 0;
|
||||
}
|
||||
ondisk1 = (struct label_ondisk *)block1;
|
||||
ondisk2 = (struct label_ondisk *)block2;
|
||||
|
||||
get_label_locations(size, sectsize, &offset[0], &offset[1]);
|
||||
|
||||
/* Fetch em */
|
||||
if (!dev_open(dev, O_RDONLY))
|
||||
goto finish;
|
||||
|
||||
if (!dev_read(dev, offset[0], sectsize, block1))
|
||||
goto finish;
|
||||
|
||||
if (!dev_read(dev, offset[1], sectsize, block2))
|
||||
goto finish;
|
||||
|
||||
dev_close(dev);
|
||||
|
||||
/* Is it labelled? */
|
||||
if (xlate32(ondisk1->magic) != LABEL_MAGIC)
|
||||
goto finish;
|
||||
|
||||
/* Compare the whole structs */
|
||||
if (memcmp(ondisk1, ondisk2, sizeof(struct label_ondisk)) != 0)
|
||||
goto finish;
|
||||
|
||||
/* OK, check the data area */
|
||||
if (memcmp(block1 + sizeof(struct label_ondisk),
|
||||
block2 + sizeof(struct label_ondisk),
|
||||
xlate16(ondisk1->datalen)) != 0)
|
||||
goto finish;
|
||||
|
||||
/* They match !! */
|
||||
status = 1;
|
||||
|
||||
finish:
|
||||
dbg_free(block2);
|
||||
dbg_free(block1);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
static int lvm2_label_remove(struct labeller *l, struct device *dev)
|
||||
{
|
||||
uint64_t size;
|
||||
uint32_t sectsize;
|
||||
char block[BLOCK_SIZE];
|
||||
int status1, status2;
|
||||
long offset[2];
|
||||
|
||||
if (!dev_get_size(dev, &size))
|
||||
return 0;
|
||||
|
||||
if (!dev_get_sectsize(dev, §size))
|
||||
return 0;
|
||||
|
||||
if (!dev_open(dev, O_RDWR))
|
||||
{
|
||||
dbg_free(block);
|
||||
return 0;
|
||||
}
|
||||
|
||||
get_label_locations(size, sectsize, &offset[0], &offset[1]);
|
||||
memset(block, 0, BLOCK_SIZE);
|
||||
|
||||
/* Blank out the first label */
|
||||
status1 = dev_write(dev, offset[0], BLOCK_SIZE, block);
|
||||
if (!status1)
|
||||
log_error("Error erasing label 1\n");
|
||||
|
||||
/* ...and the other at the end of the device */
|
||||
status2 = dev_write(dev, offset[1], BLOCK_SIZE, block);
|
||||
if (!status2)
|
||||
log_error("Error erasing label 2\n");
|
||||
|
||||
dev_close(dev);
|
||||
|
||||
return ((status1 != 0) && (status2 != 0));
|
||||
}
|
||||
|
||||
static void lvm2_label_destroy(struct labeller *l)
|
||||
{
|
||||
}
|
||||
|
||||
static struct label_ops handler_ops =
|
||||
{
|
||||
can_handle: lvm2_is_labelled,
|
||||
write: lvm2_label_write,
|
||||
remove: lvm2_label_remove,
|
||||
read: lvm2_label_read,
|
||||
verify: lvm2_labels_match,
|
||||
destroy: lvm2_label_destroy,
|
||||
};
|
||||
|
||||
static struct labeller this_labeller =
|
||||
{
|
||||
private : NULL,
|
||||
ops : &handler_ops,
|
||||
};
|
||||
|
||||
/* Don't know how this gets called... */
|
||||
void lvm2_label_init()
|
||||
{
|
||||
label_register_handler("LVM2", &this_labeller);
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user