]>
Commit | Line | Data |
---|---|---|
64c4757e NB |
1 | /* |
2 | * mdctl - manage Linux "md" devices aka RAID arrays. | |
3 | * | |
4 | * Copyright (C) 2001 Neil Brown <neilb@cse.unsw.edu.au> | |
5 | * | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License as published by | |
9 | * the Free Software Foundation; either version 2 of the License, or | |
10 | * (at your option) any later version. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | * GNU General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
18 | * along with this program; if not, write to the Free Software | |
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
20 | * | |
21 | * Author: Neil Brown | |
22 | * Email: <neilb@cse.unsw.edu.au> | |
23 | * Paper: Neil Brown | |
24 | * School of Computer Science and Engineering | |
25 | * The University of New South Wales | |
26 | * Sydney, 2052 | |
27 | * Australia | |
28 | */ | |
29 | ||
30 | #include "mdctl.h" | |
31 | ||
5e52ae9e | 32 | char Version[] = Name " - v0.4.1 - 26 July 2001\n"; |
64c4757e NB |
33 | /* |
34 | * File: ReadMe.c | |
35 | * | |
36 | * This file contains general comments about the implementation | |
37 | * and the various usage messages that can be displayed by mdctl | |
38 | * | |
39 | * mdctl is a single program that can be used to control Linux md devices. | |
40 | * It is intended to provide all the functionality of the mdtools and | |
41 | * raidtools but with a very different interface. | |
42 | * mdctl can perform all functions without a configuration file. | |
43 | * There is the option of using a configuration file, but not in the same | |
44 | * way that raidtools uses one | |
45 | * raidtools uses a configuration file to describe how to create a RAID | |
46 | * array, and also uses this file partially to start a previously | |
47 | * created RAID array. Further, raidtools requires the configuration | |
48 | * file for such things as stopping a raid array which needs to know | |
49 | * nothing about the array. | |
50 | * | |
51 | * The configuration file that can be used by mdctl lists two | |
52 | * different things: | |
53 | * 1/ a mapping from uuid to md device to identify which arrays are | |
54 | * expect and what names (numbers) they should be given | |
55 | * 2/ a list of devices that should be scanned for md sub-devices | |
56 | * | |
57 | * | |
58 | */ | |
59 | ||
60 | /* | |
61 | * mdctl has 4 major modes of operation: | |
62 | * 1/ Create | |
63 | * This mode is used to create a new array with a superbock | |
64 | * It can progress in several step create-add-add-run | |
65 | * or it can all happen with one command | |
66 | * 2/ Assemble | |
67 | * This mode is used to assemble the parts of a previously created | |
68 | * array into an active array. Components can be explicitly given | |
69 | * or can be searched for. mdctl (optionally) check that the components | |
70 | * do form a bonafide array, and can, on request, fiddle superblock | |
71 | * version numbers so as to assemble a faulty array. | |
72 | * 3/ Build | |
73 | * This is for building legacy arrays without superblocks | |
74 | * 4/ Manage | |
75 | * This is for odd bits an pieces like hotadd, hotremove, setfaulty, | |
76 | * stop, readonly,readwrite | |
77 | * If an array is only partially setup by the Create/Assemble/Build | |
78 | * command, subsequent Manage commands can finish the job. | |
79 | */ | |
80 | ||
682c7051 | 81 | char short_options[]="-ABCDEhVvc:l:p:n:x:u:c:z:sarfRSow"; |
64c4757e NB |
82 | struct option long_options[] = { |
83 | {"manage", 0, 0, '@'}, | |
84 | {"assemble", 0, 0, 'A'}, | |
85 | {"build", 0, 0, 'B'}, | |
86 | {"create", 0, 0, 'C'}, | |
87 | {"detail", 0, 0, 'D'}, | |
88 | {"examine", 0, 0, 'E'}, | |
89 | /* after those will normally come the name of the md device */ | |
90 | {"help", 0, 0, 'h'}, | |
91 | {"version", 0, 0, 'V'}, | |
92 | {"verbose", 0, 0, 'v'}, | |
93 | ||
94 | /* For create or build: */ | |
95 | {"chunk", 1, 0, 'c'}, | |
96 | {"rounding", 1, 0, 'c'}, /* for linear, chunk is really a rounding number */ | |
97 | {"level", 1, 0, 'l'}, /* 0,1,4,5,linear */ | |
98 | {"parity", 1, 0, 'p'}, /* {left,right}-{a,}symetric */ | |
99 | {"layout", 1, 0, 'p'}, | |
100 | {"raid-disks",1, 0, 'n'}, | |
101 | {"spare-disks",1,0, 'x'}, | |
682c7051 | 102 | {"size" ,1, 0, 'z'}, |
64c4757e NB |
103 | |
104 | /* For assemble */ | |
105 | {"uuid", 1, 0, 'u'}, | |
106 | {"config", 1, 0, 'c'}, | |
107 | {"scan", 0, 0, 's'}, | |
108 | {"force", 0, 0, 'f'}, | |
109 | /* Management */ | |
110 | {"add", 0, 0, 'a'}, | |
111 | {"remove", 0, 0, 'r'}, | |
112 | {"fail", 0, 0, 'f'}, | |
113 | {"set-faulty",0, 0, 'f'}, | |
114 | {"run", 0, 0, 'R'}, | |
115 | {"stop", 0, 0, 'S'}, | |
116 | {"readonly", 0, 0, 'o'}, | |
117 | {"readwrite", 0, 0, 'w'}, | |
118 | ||
119 | {0, 0, 0, 0} | |
120 | }; | |
121 | ||
122 | char Usage[] = | |
123 | "Usage: mdctl --help\n" | |
124 | " for help\n" | |
125 | ; | |
126 | ||
127 | char Help[] = | |
128 | "Usage: mdctl --create device options...\n" | |
129 | " mdctl --assemble device options...\n" | |
130 | " mdctl --build device options...\n" | |
131 | " mdctl --detail device\n" | |
132 | " mdctl --examine device\n" | |
133 | " mdctl device options...\n" | |
134 | " mdctl is used for controlling Linux md devices (aka RAID arrays)\n" | |
135 | " For detail help on major modes use, e.g.\n" | |
136 | " mdctl --assemble --help\n" | |
137 | "\n" | |
138 | "Any parameter that does not start with '-' is treated as a device name\n" | |
139 | "The first such name is normally the name of an md device. Subsequent\n" | |
140 | "names are names of component devices." | |
141 | "\n" | |
142 | "Available options are:\n" | |
143 | " --create -C : Create a new array\n" | |
144 | " --assemble -A : Assemble an existing array\n" | |
145 | " --build -B : Build a legacy array without superblock\n" | |
146 | " --detail -D : Print detail of a given md array\n" | |
147 | " --examine -E : Print content of md superblock on device\n" | |
148 | " --help -h : This help message or, after above option,\n" | |
149 | " mode specific help message\n" | |
150 | " --version -V : Print version information for mdctl\n" | |
151 | " --verbose -v : Be more verbose about what is happening\n" | |
152 | "\n" | |
153 | " For create or build:\n" | |
154 | " --chunk= -c : chunk size of kibibytes\n" | |
155 | " --rounding= : rounding factor for linear array (==chunck size)\n" | |
156 | " --level= -l : raid level: 0,1,4,5,linear. 0 or linear for build\n" | |
157 | " --paritiy= -p : raid5 parity algorith: {left,right}-{,a}symmetric\n" | |
158 | " --layout= : same as --parity\n" | |
159 | " --raid-disks= -n : number of active devices in array\n" | |
160 | " --spare-disks= -x : number of spares (eXtras) to allow space for\n" | |
682c7051 | 161 | " --size= -z : Size (in K) of each drive in RAID1/4/5 - optional\n" |
64c4757e NB |
162 | "\n" |
163 | " For assemble:\n" | |
164 | " --uuid= -u : uuid of array to assemble. Devices which don't\n" | |
165 | " have this uuid are excluded\n" | |
166 | " --config= -c : config file\n" | |
167 | " --scan -s : scan config file for missing information\n" | |
168 | " --force -f : Assemble the array even if some superblocks appear out-of-date\n" | |
169 | "\n" | |
170 | " General management:\n" | |
171 | " --add -a : add, or hotadd subsequent devices\n" | |
172 | " --remove -r : remove subsequent devices\n" | |
173 | " --fail -f : mark subsequent devices a faulty\n" | |
174 | " --set-faulty : same as --fail\n" | |
175 | " --run -R : start a partially built array\n" | |
176 | " --stop -S : deactive array, releasing all resources\n" | |
177 | " --readonly -o : mark array as readonly\n" | |
178 | " --readwrite -w : mark array as readwrite\n" | |
179 | ; | |
180 | ||
181 | ||
182 | char Help_create[] = | |
183 | "Usage: mdctl --create device -chunk=X --level=Y --raid-disks=Z devices\n" | |
184 | "\n" | |
185 | " This usage will initialise a new md array and possibly associate some\n" | |
186 | " devices with it. If enough devices are given to complete the array,\n" | |
187 | " the array will be activated. Otherwise it will be left inactive\n" | |
188 | " to be competed and activated by subsequent management commands.\n" | |
189 | "\n" | |
190 | " As devices are added, they are checked to see if they contain\n" | |
191 | " raid superblock or filesystems. They are also check to see if\n" | |
192 | " the variance in device size exceeds 1%.\n" | |
193 | " If any discrepancy is found, the array will not automatically\n" | |
194 | " be run, though the presence of a '--run' can override this\n" | |
195 | " caution.\n" | |
196 | "\n" | |
682c7051 NB |
197 | " If the --size option is given, it is not necessary to list any subdevices\n" |
198 | " in this command. They can be added later, before a --run.\n" | |
199 | " If no --size is given, the apparent size of the smallest drive given\n" | |
200 | " is used.\n" | |
201 | "\n" | |
64c4757e NB |
202 | " The General management options that are valid with --create are:\n" |
203 | " --run : insist of running the array even if not all devices\n" | |
204 | " are present or some look odd.\n" | |
205 | " --readonly: start the array readonly - not supported yet.\n" | |
206 | "\n" | |
207 | ; | |
208 | ||
209 | char Help_build[] = | |
210 | "Usage: mdctl --build device -chunk=X --level=Y --raid-disks=Z devices\n" | |
211 | "\n" | |
212 | " This usage is similar to --create. The difference is that it creates\n" | |
213 | " a legacy array with a superblock. With these arrays there is no\n" | |
214 | " different between initially creating the array and subsequently\n" | |
215 | " assembling the array, except that hopefully there is useful data\n" | |
216 | " there in the second case.\n" | |
217 | "\n" | |
218 | " The level may only be 0 or linear.\n" | |
219 | " All devices must be listed and the array will be started once complete.\n" | |
220 | ; | |
221 | ||
222 | char Help_assemble[] = | |
223 | "Usage: mdctl --assemble device options...\n" | |
224 | " mdctl --assemble --scan options...\n" | |
225 | "\n" | |
226 | "This usage assembles one or more raid arrays from pre-existing\n" | |
227 | "components.\n" | |
228 | "For each array, mdctl needs to know the md device, the uuid, and\n" | |
229 | "a number of sub devices. These can be found in a number of ways.\n" | |
230 | "\n" | |
231 | "The md device is either given before --scan or is found from the\n" | |
232 | "config file. In the latter case, multiple md devices can be started\n" | |
233 | "with a single mdctl command.\n" | |
234 | "\n" | |
235 | "The uuid can be given with the --uuid option, or can be found in\n" | |
236 | "in the config file, or will be taken from the super block on the first\n" | |
237 | "subdevice listed on the command line or in a subsequent --add command.\n" | |
238 | "\n" | |
239 | "Devices can be given on the --assemble command line, on subsequent\n" | |
240 | "'mdctl --add' command lines, or from the config file. Only devices\n" | |
241 | "which have an md superblock which contains the right uuid will be\n" | |
242 | "considered for any device.\n" | |
243 | "\n" | |
244 | "The config file is only used if explicitly named with --config or\n" | |
245 | "requested with --scan. In the later case, '/etc/md.conf' is used.\n" | |
246 | "\n" | |
247 | "If --scan is not given, then the config file will only be used\n" | |
248 | "to find uuids for md arrays.\n" | |
249 | "\n" | |
250 | "The format of the config file is:\n" | |
251 | " not yet documented\n" | |
252 | "\n" | |
253 | ; | |
682c7051 NB |
254 | |
255 | ||
256 | /* name/number mappings */ | |
257 | ||
258 | mapping_t r5layout[] = { | |
259 | { "left_asymmetric", 0}, | |
260 | { "right_asymmetric", 1}, | |
261 | { "left_symmetric", 2}, | |
262 | { "right_symmetric", 3}, | |
263 | ||
264 | { "default", 2}, | |
265 | { "la", 0}, | |
266 | { "ra", 1}, | |
267 | { "ls", 2}, | |
268 | { "rs", 3}, | |
269 | { NULL, 0} | |
270 | }; | |
271 | ||
272 | mapping_t pers[] = { | |
273 | { "linear", -1}, | |
274 | { "raid0", 0}, | |
275 | { "0", 0}, | |
276 | { "stripe", 0}, | |
277 | { "raid1", 1}, | |
278 | { "1", 1}, | |
279 | { "mirror", 1}, | |
280 | { "raid4", 4}, | |
281 | { "4", 4}, | |
282 | { "raid5", 5}, | |
283 | { "5", 5}, | |
284 | { NULL, 0} | |
285 | }; |