]>
Commit | Line | Data |
---|---|---|
64c4757e | 1 | /* |
9a9dab36 | 2 | * mdadm - manage Linux "md" devices aka RAID arrays. |
64c4757e | 3 | * |
6f02172d | 4 | * Copyright (C) 2001-2013 Neil Brown <neilb@suse.de> |
64c4757e NB |
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 | |
e736b623 | 22 | * Email: <neilb@suse.de> |
c82f047c | 23 | * |
aba69144 | 24 | * Additions for bitmap and write-behind RAID options, Copyright (C) 2003-2004, |
c82f047c | 25 | * Paul Clements, SteelEye Technology, Inc. |
64c4757e NB |
26 | */ |
27 | ||
9a9dab36 | 28 | #include "mdadm.h" |
64c4757e | 29 | #include "md_p.h" |
dd0781e5 | 30 | #include <ctype.h> |
64c4757e | 31 | |
4977146a N |
32 | static int scan_assemble(struct supertype *ss, |
33 | struct context *c, | |
34 | struct mddev_ident *ident); | |
ef898ce6 | 35 | static int misc_scan(char devmode, struct context *c); |
ba728be7 | 36 | static int stop_scan(int verbose); |
7d27d1c0 | 37 | static int misc_list(struct mddev_dev *devlist, |
86da243f | 38 | struct mddev_ident *ident, |
74db60b0 | 39 | char *dump_directory, |
86da243f | 40 | struct supertype *ss, struct context *c); |
d56dd607 | 41 | const char Name[] = "mdadm"; |
7d27d1c0 | 42 | |
52826846 NB |
43 | int main(int argc, char *argv[]) |
44 | { | |
e0d19036 | 45 | int mode = 0; |
52826846 | 46 | int opt; |
e0d19036 | 47 | int option_index; |
52826846 | 48 | int rv; |
f9ce90ba | 49 | int i; |
52826846 | 50 | |
a93f8c65 | 51 | unsigned long long array_size = 0; |
40c9a66a | 52 | unsigned long long data_offset = INVALID_SECTORS; |
fa56eddb | 53 | struct mddev_ident ident; |
52826846 | 54 | char *configfile = NULL; |
1c7a808c | 55 | int devmode = 0; |
c82f047c | 56 | int bitmap_fd = -1; |
a655e550 N |
57 | struct mddev_dev *devlist = NULL; |
58 | struct mddev_dev **devlistend = & devlist; | |
59 | struct mddev_dev *dv; | |
52826846 | 60 | int devs_found = 0; |
38098016 | 61 | char *symlinks = NULL; |
2dddadb0 | 62 | int grow_continue = 0; |
f1ae21c4 NB |
63 | /* autof indicates whether and how to create device node. |
64 | * bottom 3 bits are style. Rest (when shifted) are number of parts | |
65 | * 0 - unset | |
66 | * 1 - don't create (no) | |
67 | * 2 - if is_standard, then create (yes) | |
68 | * 3 - create as 'md' - reject is_standard mdp (md) | |
69 | * 4 - create as 'mdp' - reject is_standard md (mdp) | |
70 | * 5 - default to md if not is_standard (md in config file) | |
71 | * 6 - default to mdp if not is_standard (part, or mdp in config file) | |
72 | */ | |
9e33d556 N |
73 | struct context c = { |
74 | .require_homehost = 1, | |
75 | }; | |
e705e81b N |
76 | struct shape s = { |
77 | .level = UnSet, | |
78 | .layout = UnSet, | |
79 | .bitmap_chunk = UnSet, | |
80 | }; | |
52826846 | 81 | |
05697ec1 | 82 | char sys_hostname[256]; |
52826846 NB |
83 | char *mailaddr = NULL; |
84 | char *program = NULL; | |
9a36a9b7 | 85 | int increments = 20; |
d013a55e | 86 | int daemonise = 0; |
b5e64645 | 87 | char *pidfile = NULL; |
aa88f531 | 88 | int oneshot = 0; |
edde9560 | 89 | int spare_sharing = 1; |
82d9eba6 | 90 | struct supertype *ss = NULL; |
dfd4d8ee | 91 | int writemostly = 0; |
c06487ce | 92 | char *shortopt = short_options; |
773135f5 | 93 | int dosyslog = 0; |
8382f19b | 94 | int rebuild_map = 0; |
950bc344 | 95 | char *remove_path = NULL; |
20b60dcd | 96 | char *udev_filename = NULL; |
74db60b0 | 97 | char *dump_directory = NULL; |
52826846 | 98 | |
3d4064cc | 99 | int print_help = 0; |
0047d254 | 100 | FILE *outf; |
e5329c37 | 101 | |
52826846 NB |
102 | int mdfd = -1; |
103 | ||
dfe47e00 NB |
104 | srandom(time(0) ^ getpid()); |
105 | ||
52826846 | 106 | ident.uuid_set=0; |
98c6faba NB |
107 | ident.level = UnSet; |
108 | ident.raid_disks = UnSet; | |
109 | ident.super_minor= UnSet; | |
52826846 | 110 | ident.devices=0; |
a75f2fbc NB |
111 | ident.spare_group = NULL; |
112 | ident.autof = 0; | |
a825febc | 113 | ident.st = NULL; |
c82f047c | 114 | ident.bitmap_fd = -1; |
7ef02d01 | 115 | ident.bitmap_file = NULL; |
947fd4dd | 116 | ident.name[0] = 0; |
aef35714 N |
117 | ident.container = NULL; |
118 | ident.member = NULL; | |
52826846 | 119 | |
e0d19036 NB |
120 | while ((option_index = -1) , |
121 | (opt=getopt_long(argc, argv, | |
c06487ce | 122 | shortopt, long_options, |
e0d19036 NB |
123 | &option_index)) != -1) { |
124 | int newmode = mode; | |
35904960 | 125 | /* firstly, some mode-independent options */ |
52826846 | 126 | switch(opt) { |
1c7a808c N |
127 | case HelpOptions: |
128 | print_help = 2; | |
129 | continue; | |
52826846 | 130 | case 'h': |
1c7a808c | 131 | print_help = 1; |
3d4064cc | 132 | continue; |
52826846 NB |
133 | |
134 | case 'V': | |
135 | fputs(Version, stderr); | |
136 | exit(0); | |
137 | ||
9e33d556 | 138 | case 'v': c.verbose++; |
52826846 NB |
139 | continue; |
140 | ||
0937132d | 141 | case 'q': c.verbose--; |
dab6685f NB |
142 | continue; |
143 | ||
c82f047c | 144 | case 'b': |
1c7a808c N |
145 | if (mode == ASSEMBLE || mode == BUILD || mode == CREATE |
146 | || mode == GROW || mode == INCREMENTAL | |
147 | || mode == MANAGE) | |
c82f047c | 148 | break; /* b means bitmap */ |
1c7a808c | 149 | case Brief: |
9e33d556 | 150 | c.brief = 1; |
cd29a5c8 NB |
151 | continue; |
152 | ||
9e33d556 | 153 | case 'Y': c.export++; |
54bad364 KS |
154 | continue; |
155 | ||
997aed5d | 156 | case HomeHost: |
0ac91628 | 157 | if (strcasecmp(optarg, "<ignore>") == 0) |
9e33d556 | 158 | c.require_homehost = 0; |
0ac91628 | 159 | else |
9e33d556 | 160 | c.homehost = optarg; |
997aed5d NB |
161 | continue; |
162 | ||
08ca2adf | 163 | case OffRootOpt: |
3e23ba9d | 164 | /* Silently ignore old option */ |
08ca2adf JS |
165 | continue; |
166 | ||
c2ecf5f6 | 167 | case Prefer: |
9e33d556 N |
168 | if (c.prefer) |
169 | free(c.prefer); | |
170 | if (asprintf(&c.prefer, "/%s/", optarg) <= 0) | |
171 | c.prefer = NULL; | |
c2ecf5f6 N |
172 | continue; |
173 | ||
e0d19036 NB |
174 | case ':': |
175 | case '?': | |
176 | fputs(Usage, stderr); | |
177 | exit(2); | |
178 | } | |
179 | /* second, figure out the mode. | |
180 | * Some options force the mode. Others | |
aba69144 | 181 | * set the mode if it isn't already |
e0d19036 NB |
182 | */ |
183 | ||
184 | switch(opt) { | |
1c7a808c | 185 | case ManageOpt: |
c06487ce | 186 | newmode = MANAGE; |
024768c4 | 187 | shortopt = short_bitmap_options; |
c06487ce | 188 | break; |
e0d19036 | 189 | case 'a': |
1c7a808c | 190 | case Add: |
f33a71f1 | 191 | case AddSpare: |
e0d19036 | 192 | case 'r': |
1c7a808c | 193 | case Remove: |
70c55e36 N |
194 | case Replace: |
195 | case With: | |
e0d19036 | 196 | case 'f': |
1c7a808c | 197 | case Fail: |
41a3b72a | 198 | case ReAdd: /* re-add */ |
c06487ce NB |
199 | if (!mode) { |
200 | newmode = MANAGE; | |
024768c4 | 201 | shortopt = short_bitmap_options; |
c06487ce | 202 | } |
0320ea45 | 203 | break; |
e0d19036 | 204 | |
18361a1a N |
205 | case 'A': newmode = ASSEMBLE; |
206 | shortopt = short_bitmap_auto_options; | |
207 | break; | |
208 | case 'B': newmode = BUILD; | |
209 | shortopt = short_bitmap_auto_options; | |
210 | break; | |
211 | case 'C': newmode = CREATE; | |
212 | shortopt = short_bitmap_auto_options; | |
213 | break; | |
214 | case 'F': newmode = MONITOR; | |
215 | break; | |
024768c4 DL |
216 | case 'G': newmode = GROW; |
217 | shortopt = short_bitmap_options; | |
218 | break; | |
95b79df0 | 219 | case 'I': newmode = INCREMENTAL; |
18361a1a N |
220 | shortopt = short_bitmap_auto_options; |
221 | break; | |
1f48664b | 222 | case AutoDetect: |
5a53aeec JS |
223 | newmode = AUTODETECT; |
224 | break; | |
e0d19036 | 225 | |
1c7a808c | 226 | case MiscOpt: |
e0d19036 NB |
227 | case 'D': |
228 | case 'E': | |
c82f047c | 229 | case 'X': |
5a53aeec | 230 | case 'Q': |
6d388a88 | 231 | case ExamineBB: |
74db60b0 N |
232 | case Dump: |
233 | case Restore: | |
a740cf64 | 234 | case Action: |
5a53aeec JS |
235 | newmode = MISC; |
236 | break; | |
237 | ||
e0d19036 NB |
238 | case 'R': |
239 | case 'S': | |
240 | case 'o': | |
241 | case 'w': | |
b90c0e9a | 242 | case 'W': |
1c7a808c | 243 | case WaitOpt: |
1770662b | 244 | case Waitclean: |
4cce4069 | 245 | case DetailPlatform: |
33414a01 | 246 | case KillSubarray: |
aa534678 | 247 | case UpdateSubarray: |
20b60dcd | 248 | case UdevRules: |
f7d3febc | 249 | case KillOpt: |
5a53aeec JS |
250 | if (!mode) |
251 | newmode = MISC; | |
252 | break; | |
253 | ||
254 | case NoSharing: | |
255 | newmode = MONITOR; | |
256 | break; | |
e0d19036 NB |
257 | } |
258 | if (mode && newmode == mode) { | |
259 | /* everybody happy ! */ | |
260 | } else if (mode && newmode != mode) { | |
261 | /* not allowed.. */ | |
e7b84f9d | 262 | pr_err(""); |
e0d19036 NB |
263 | if (option_index >= 0) |
264 | fprintf(stderr, "--%s", long_options[option_index].name); | |
265 | else | |
266 | fprintf(stderr, "-%c", opt); | |
e6b64cd0 | 267 | fprintf(stderr, " would set mdadm mode to \"%s\", but it is already set to \"%s\".\n", |
e0d19036 NB |
268 | map_num(modes, newmode), |
269 | map_num(modes, mode)); | |
270 | exit(2); | |
271 | } else if (!mode && newmode) { | |
272 | mode = newmode; | |
dec18cae | 273 | if (mode == MISC && devs_found) { |
e7b84f9d | 274 | pr_err("No action given for %s in --misc mode\n", |
dec18cae | 275 | devlist->devname); |
d33f1518 | 276 | cont_err("Action options must come before device names\n"); |
dec18cae N |
277 | exit(2); |
278 | } | |
e0d19036 NB |
279 | } else { |
280 | /* special case of -c --help */ | |
1c7a808c | 281 | if ((opt == 'c' || opt == ConfigFile) && |
e0d19036 NB |
282 | ( strncmp(optarg, "--h", 3)==0 || |
283 | strncmp(optarg, "-h", 2)==0)) { | |
0047d254 | 284 | fputs(Help_config, stdout); |
e0d19036 | 285 | exit(0); |
cd29a5c8 | 286 | } |
0320ea45 NB |
287 | |
288 | /* If first option is a device, don't force the mode yet */ | |
289 | if (opt == 1) { | |
290 | if (devs_found == 0) { | |
503975b9 | 291 | dv = xmalloc(sizeof(*dv)); |
0320ea45 NB |
292 | dv->devname = optarg; |
293 | dv->disposition = devmode; | |
dfd4d8ee | 294 | dv->writemostly = writemostly; |
da6b5ca9 | 295 | dv->used = 0; |
0320ea45 NB |
296 | dv->next = NULL; |
297 | *devlistend = dv; | |
298 | devlistend = &dv->next; | |
aba69144 | 299 | |
0320ea45 NB |
300 | devs_found++; |
301 | continue; | |
302 | } | |
303 | /* No mode yet, and this is the second device ... */ | |
e7b84f9d | 304 | pr_err("An option must be given to set the mode before a second device\n" |
a1331cc4 | 305 | " (%s) is listed\n", optarg); |
0320ea45 NB |
306 | exit(2); |
307 | } | |
e0d19036 | 308 | if (option_index >= 0) |
e7b84f9d | 309 | pr_err("--%s", long_options[option_index].name); |
e0d19036 | 310 | else |
e7b84f9d | 311 | pr_err("-%c", opt); |
0320ea45 | 312 | fprintf(stderr, " does not set the mode, and so cannot be the first option.\n"); |
e0d19036 NB |
313 | exit(2); |
314 | } | |
315 | ||
316 | /* if we just set the mode, then done */ | |
317 | switch(opt) { | |
1c7a808c N |
318 | case ManageOpt: |
319 | case MiscOpt: | |
e0d19036 NB |
320 | case 'A': |
321 | case 'B': | |
322 | case 'C': | |
323 | case 'F': | |
dd0781e5 | 324 | case 'G': |
8382f19b | 325 | case 'I': |
1f48664b | 326 | case AutoDetect: |
e0d19036 NB |
327 | continue; |
328 | } | |
329 | if (opt == 1) { | |
9eafa1de | 330 | /* an undecorated option - must be a device name. |
e0d19036 | 331 | */ |
9eafa1de MN |
332 | |
333 | if (devs_found > 0 && devmode == DetailPlatform) { | |
334 | pr_err("controller may only be specified once. %s ignored\n", | |
335 | optarg); | |
336 | continue; | |
337 | } | |
338 | ||
1c7a808c | 339 | if (devs_found > 0 && mode == MANAGE && !devmode) { |
e7b84f9d | 340 | pr_err("Must give one of -a/-r/-f" |
1c7a808c | 341 | " for subsequent devices at %s\n", optarg); |
52826846 NB |
342 | exit(2); |
343 | } | |
1c7a808c | 344 | if (devs_found > 0 && mode == GROW && !devmode) { |
e7b84f9d N |
345 | pr_err("Must give -a/--add for" |
346 | " devices to add: %s\n", optarg); | |
e5329c37 NB |
347 | exit(2); |
348 | } | |
503975b9 | 349 | dv = xmalloc(sizeof(*dv)); |
cd29a5c8 NB |
350 | dv->devname = optarg; |
351 | dv->disposition = devmode; | |
dfd4d8ee | 352 | dv->writemostly = writemostly; |
9008ed1c | 353 | dv->used = 0; |
cd29a5c8 NB |
354 | dv->next = NULL; |
355 | *devlistend = dv; | |
356 | devlistend = &dv->next; | |
aba69144 | 357 | |
52826846 NB |
358 | devs_found++; |
359 | continue; | |
682c7051 | 360 | } |
682c7051 | 361 | |
52826846 NB |
362 | /* We've got a mode, and opt is now something else which |
363 | * could depend on the mode */ | |
1c7a808c | 364 | #define O(a,b) ((a<<16)|b) |
52826846 | 365 | switch (O(mode,opt)) { |
7236ee7a | 366 | case O(GROW,'c'): |
1c7a808c | 367 | case O(GROW,ChunkSize): |
e0d19036 | 368 | case O(CREATE,'c'): |
1c7a808c | 369 | case O(CREATE,ChunkSize): |
e0d19036 | 370 | case O(BUILD,'c'): /* chunk or rounding */ |
1c7a808c | 371 | case O(BUILD,ChunkSize): /* chunk or rounding */ |
e705e81b | 372 | if (s.chunk) { |
e7b84f9d | 373 | pr_err("chunk/rounding may only be specified once. " |
52826846 NB |
374 | "Second value is %s.\n", optarg); |
375 | exit(2); | |
376 | } | |
e705e81b | 377 | s.chunk = parse_size(optarg); |
822e393a N |
378 | if (s.chunk == INVALID_SECTORS || |
379 | s.chunk < 8 || (s.chunk&1)) { | |
e7b84f9d | 380 | pr_err("invalid chunk/rounding value: %s\n", |
52826846 NB |
381 | optarg); |
382 | exit(2); | |
383 | } | |
a252c078 | 384 | /* Convert sectors to K */ |
e705e81b | 385 | s.chunk /= 2; |
52826846 | 386 | continue; |
64c4757e | 387 | |
8382f19b | 388 | case O(INCREMENTAL, 'e'): |
f9ce90ba NB |
389 | case O(CREATE,'e'): |
390 | case O(ASSEMBLE,'e'): | |
391 | case O(MISC,'e'): /* set metadata (superblock) information */ | |
392 | if (ss) { | |
e7b84f9d | 393 | pr_err("metadata information already given\n"); |
f9ce90ba NB |
394 | exit(2); |
395 | } | |
aba69144 | 396 | for(i=0; !ss && superlist[i]; i++) |
82d9eba6 NB |
397 | ss = superlist[i]->match_metadata_desc(optarg); |
398 | ||
f9ce90ba | 399 | if (!ss) { |
e7b84f9d | 400 | pr_err("unrecognised metadata identifier: %s\n", optarg); |
f9ce90ba NB |
401 | exit(2); |
402 | } | |
403 | continue; | |
404 | ||
dfd4d8ee | 405 | case O(MANAGE,'W'): |
1c7a808c | 406 | case O(MANAGE,WriteMostly): |
dfd4d8ee | 407 | case O(BUILD,'W'): |
1c7a808c | 408 | case O(BUILD,WriteMostly): |
dfd4d8ee | 409 | case O(CREATE,'W'): |
1c7a808c | 410 | case O(CREATE,WriteMostly): |
dfd4d8ee NB |
411 | /* set write-mostly for following devices */ |
412 | writemostly = 1; | |
413 | continue; | |
414 | ||
b3d31955 N |
415 | case O(MANAGE,'w'): |
416 | /* clear write-mostly for following devices */ | |
417 | writemostly = 2; | |
418 | continue; | |
419 | ||
dd0781e5 | 420 | case O(GROW,'z'): |
25affb56 PC |
421 | case O(CREATE,'z'): |
422 | case O(BUILD,'z'): /* size */ | |
e705e81b | 423 | if (s.size > 0) { |
e7b84f9d | 424 | pr_err("size may only be specified once. " |
52826846 NB |
425 | "Second value is %s.\n", optarg); |
426 | exit(2); | |
427 | } | |
dd0781e5 | 428 | if (strcmp(optarg, "max")==0) |
e705e81b | 429 | s.size = MAX_SIZE; |
dd0781e5 | 430 | else { |
e705e81b | 431 | s.size = parse_size(optarg); |
822e393a N |
432 | if (s.size == INVALID_SECTORS || |
433 | s.size < 8) { | |
e7b84f9d | 434 | pr_err("invalid size: %s\n", |
dd0781e5 NB |
435 | optarg); |
436 | exit(2); | |
437 | } | |
5f4fc0e1 | 438 | /* convert sectors to K */ |
e705e81b | 439 | s.size /= 2; |
52826846 NB |
440 | } |
441 | continue; | |
64c4757e | 442 | |
84e11361 | 443 | case O(GROW,'Z'): /* array size */ |
a93f8c65 | 444 | if (array_size > 0) { |
e7b84f9d | 445 | pr_err("array-size may only be specified once. " |
84e11361 N |
446 | "Second value is %s.\n", optarg); |
447 | exit(2); | |
448 | } | |
449 | if (strcmp(optarg, "max") == 0) | |
a93f8c65 | 450 | array_size = MAX_SIZE; |
84e11361 N |
451 | else { |
452 | array_size = parse_size(optarg); | |
822e393a N |
453 | if (array_size == 0 || |
454 | array_size == INVALID_SECTORS) { | |
e7b84f9d | 455 | pr_err("invalid array size: %s\n", |
84e11361 N |
456 | optarg); |
457 | exit(2); | |
458 | } | |
459 | } | |
460 | continue; | |
461 | ||
40c9a66a N |
462 | case O(CREATE,DataOffset): |
463 | case O(GROW,DataOffset): | |
464 | if (data_offset != INVALID_SECTORS) { | |
ed503f89 | 465 | pr_err("data-offset may only be specified one. " |
40c9a66a N |
466 | "Second value is %s.\n", optarg); |
467 | exit(2); | |
468 | } | |
72ca9bcf N |
469 | if (mode == CREATE && |
470 | strcmp(optarg, "variable") == 0) | |
471 | data_offset = VARIABLE_OFFSET; | |
472 | else | |
473 | data_offset = parse_size(optarg); | |
40c9a66a | 474 | if (data_offset == INVALID_SECTORS) { |
ed503f89 | 475 | pr_err("invalid data-offset: %s\n", |
40c9a66a N |
476 | optarg); |
477 | exit(2); | |
478 | } | |
479 | continue; | |
480 | ||
7236ee7a | 481 | case O(GROW,'l'): |
e0d19036 NB |
482 | case O(CREATE,'l'): |
483 | case O(BUILD,'l'): /* set raid level*/ | |
e705e81b | 484 | if (s.level != UnSet) { |
e7b84f9d | 485 | pr_err("raid level may only be set once. " |
52826846 NB |
486 | "Second value is %s.\n", optarg); |
487 | exit(2); | |
488 | } | |
e705e81b N |
489 | s.level = map_name(pers, optarg); |
490 | if (s.level == UnSet) { | |
e7b84f9d | 491 | pr_err("invalid raid level: %s\n", |
52826846 NB |
492 | optarg); |
493 | exit(2); | |
494 | } | |
e705e81b N |
495 | if (s.level != 0 && s.level != LEVEL_LINEAR && s.level != 1 && |
496 | s.level != LEVEL_MULTIPATH && s.level != LEVEL_FAULTY && | |
497 | s.level != 10 && | |
e0fe762a | 498 | mode == BUILD) { |
e7b84f9d | 499 | pr_err("Raid level %s not permitted with --build.\n", |
52826846 NB |
500 | optarg); |
501 | exit(2); | |
502 | } | |
e705e81b | 503 | if (s.sparedisks > 0 && s.level < 1 && s.level >= -1) { |
e7b84f9d | 504 | pr_err("raid level %s is incompatible with spare-devices setting.\n", |
52826846 NB |
505 | optarg); |
506 | exit(2); | |
507 | } | |
e705e81b | 508 | ident.level = s.level; |
52826846 | 509 | continue; |
64c4757e | 510 | |
19678e53 | 511 | case O(GROW, 'p'): /* new layout */ |
1c7a808c | 512 | case O(GROW, Layout): |
e705e81b | 513 | if (s.layout_str) { |
e7b84f9d N |
514 | pr_err("layout may only be sent once. " |
515 | "Second value was %s\n", optarg); | |
19678e53 N |
516 | exit(2); |
517 | } | |
e705e81b | 518 | s.layout_str = optarg; |
19678e53 N |
519 | /* 'Grow' will parse the value */ |
520 | continue; | |
521 | ||
e0d19036 | 522 | case O(CREATE,'p'): /* raid5 layout */ |
1c7a808c | 523 | case O(CREATE,Layout): |
b5e64645 | 524 | case O(BUILD,'p'): /* faulty layout */ |
1c7a808c | 525 | case O(BUILD,Layout): |
e705e81b | 526 | if (s.layout != UnSet) { |
e7b84f9d N |
527 | pr_err("layout may only be sent once. " |
528 | "Second value was %s\n", optarg); | |
52826846 NB |
529 | exit(2); |
530 | } | |
e705e81b | 531 | switch(s.level) { |
52826846 | 532 | default: |
e7b84f9d | 533 | pr_err("layout not meaningful for %s arrays.\n", |
e705e81b | 534 | map_num(pers, s.level)); |
52826846 | 535 | exit(2); |
98c6faba | 536 | case UnSet: |
e7b84f9d | 537 | pr_err("raid level must be given before layout.\n"); |
52826846 NB |
538 | exit(2); |
539 | ||
540 | case 5: | |
e705e81b N |
541 | s.layout = map_name(r5layout, optarg); |
542 | if (s.layout==UnSet) { | |
e7b84f9d | 543 | pr_err("layout %s not understood for raid5.\n", |
52826846 NB |
544 | optarg); |
545 | exit(2); | |
546 | } | |
547 | break; | |
b640a252 | 548 | case 6: |
e705e81b N |
549 | s.layout = map_name(r6layout, optarg); |
550 | if (s.layout==UnSet) { | |
e7b84f9d | 551 | pr_err("layout %s not understood for raid6.\n", |
b640a252 N |
552 | optarg); |
553 | exit(2); | |
554 | } | |
555 | break; | |
e5329c37 NB |
556 | |
557 | case 10: | |
e705e81b N |
558 | s.layout = parse_layout_10(optarg); |
559 | if (s.layout < 0) { | |
e7b84f9d | 560 | pr_err("layout for raid10 must be 'nNN', 'oNN' or 'fNN' where NN is a number, not %s\n", optarg); |
e5329c37 NB |
561 | exit(2); |
562 | } | |
e5329c37 | 563 | break; |
19678e53 N |
564 | case LEVEL_FAULTY: |
565 | /* Faulty | |
566 | * modeNNN | |
567 | */ | |
e705e81b N |
568 | s.layout = parse_layout_faulty(optarg); |
569 | if (s.layout == -1) { | |
e7b84f9d | 570 | pr_err("layout %s not understood for faulty.\n", |
b5e64645 NB |
571 | optarg); |
572 | exit(2); | |
573 | } | |
4a06e2c2 | 574 | break; |
52826846 NB |
575 | } |
576 | continue; | |
577 | ||
997aed5d NB |
578 | case O(CREATE,AssumeClean): |
579 | case O(BUILD,AssumeClean): /* assume clean */ | |
ce52f92f | 580 | case O(GROW,AssumeClean): |
e705e81b | 581 | s.assume_clean = 1; |
dd0781e5 NB |
582 | continue; |
583 | ||
584 | case O(GROW,'n'): | |
e0d19036 NB |
585 | case O(CREATE,'n'): |
586 | case O(BUILD,'n'): /* number of raid disks */ | |
e705e81b | 587 | if (s.raiddisks) { |
e7b84f9d | 588 | pr_err("raid-devices set twice: %d and %s\n", |
e705e81b | 589 | s.raiddisks, optarg); |
52826846 NB |
590 | exit(2); |
591 | } | |
e705e81b N |
592 | s.raiddisks = parse_num(optarg); |
593 | if (s.raiddisks <= 0) { | |
e7b84f9d | 594 | pr_err("invalid number of raid devices: %s\n", |
52826846 NB |
595 | optarg); |
596 | exit(2); | |
597 | } | |
e705e81b | 598 | ident.raid_disks = s.raiddisks; |
52826846 NB |
599 | continue; |
600 | ||
18361a1a | 601 | case O(CREATE,'x'): /* number of spare (eXtra) disks */ |
e705e81b | 602 | if (s.sparedisks) { |
e7b84f9d | 603 | pr_err("spare-devices set twice: %d and %s\n", |
e705e81b | 604 | s.sparedisks, optarg); |
52826846 NB |
605 | exit(2); |
606 | } | |
e705e81b | 607 | if (s.level != UnSet && s.level <= 0 && s.level >= -1) { |
e7b84f9d | 608 | pr_err("spare-devices setting is incompatible with raid level %d\n", |
e705e81b | 609 | s.level); |
52826846 NB |
610 | exit(2); |
611 | } | |
e705e81b N |
612 | s.sparedisks = parse_num(optarg); |
613 | if (s.sparedisks < 0) { | |
e7b84f9d | 614 | pr_err("invalid number of spare-devices: %s\n", |
52826846 NB |
615 | optarg); |
616 | exit(2); | |
617 | } | |
618 | continue; | |
dd0781e5 NB |
619 | |
620 | case O(CREATE,'a'): | |
1c7a808c | 621 | case O(CREATE,Auto): |
dd0781e5 | 622 | case O(BUILD,'a'): |
1c7a808c | 623 | case O(BUILD,Auto): |
95b79df0 | 624 | case O(INCREMENTAL,'a'): |
1c7a808c N |
625 | case O(INCREMENTAL,Auto): |
626 | case O(ASSEMBLE,'a'): | |
627 | case O(ASSEMBLE,Auto): /* auto-creation of device node */ | |
9e33d556 | 628 | c.autof = parse_auto(optarg, "--auto flag", 0); |
dd0781e5 NB |
629 | continue; |
630 | ||
38098016 NB |
631 | case O(CREATE,Symlinks): |
632 | case O(BUILD,Symlinks): | |
633 | case O(ASSEMBLE,Symlinks): /* auto creation of symlinks in /dev to /dev/md */ | |
634 | symlinks = optarg; | |
635 | continue; | |
636 | ||
aa88f531 | 637 | case O(BUILD,'f'): /* force honouring '-n 1' */ |
1c7a808c | 638 | case O(BUILD,Force): /* force honouring '-n 1' */ |
bd72c2b2 | 639 | case O(GROW,'f'): /* ditto */ |
1c7a808c | 640 | case O(GROW,Force): /* ditto */ |
e0d19036 | 641 | case O(CREATE,'f'): /* force honouring of device list */ |
1c7a808c | 642 | case O(CREATE,Force): /* force honouring of device list */ |
e0d19036 | 643 | case O(ASSEMBLE,'f'): /* force assembly */ |
1c7a808c | 644 | case O(ASSEMBLE,Force): /* force assembly */ |
e0d19036 | 645 | case O(MISC,'f'): /* force zero */ |
1c7a808c | 646 | case O(MISC,Force): /* force zero */ |
11b391ec | 647 | case O(MANAGE,Force): /* add device which is too large */ |
9e33d556 | 648 | c.force=1; |
52826846 | 649 | continue; |
52826846 | 650 | /* now for the Assemble options */ |
b76b30e0 AK |
651 | case O(ASSEMBLE, FreezeReshape): /* Freeze reshape during |
652 | * initrd phase */ | |
653 | case O(INCREMENTAL, FreezeReshape): | |
9e33d556 | 654 | c.freeze_reshape = 1; |
b76b30e0 | 655 | continue; |
3d3dd91e | 656 | case O(CREATE,'u'): /* uuid of array */ |
e0d19036 | 657 | case O(ASSEMBLE,'u'): /* uuid of array */ |
52826846 | 658 | if (ident.uuid_set) { |
e7b84f9d | 659 | pr_err("uuid cannot be set twice. " |
52826846 NB |
660 | "Second value %s.\n", optarg); |
661 | exit(2); | |
662 | } | |
663 | if (parse_uuid(optarg, ident.uuid)) | |
664 | ident.uuid_set = 1; | |
665 | else { | |
e7b84f9d | 666 | pr_err("Bad uuid: %s\n", optarg); |
52826846 NB |
667 | exit(2); |
668 | } | |
669 | continue; | |
670 | ||
947fd4dd NB |
671 | case O(CREATE,'N'): |
672 | case O(ASSEMBLE,'N'): | |
aa534678 | 673 | case O(MISC,'N'): |
947fd4dd | 674 | if (ident.name[0]) { |
e7b84f9d | 675 | pr_err("name cannot be set twice. " |
947fd4dd NB |
676 | "Second value %s.\n", optarg); |
677 | exit(2); | |
678 | } | |
9e33d556 | 679 | if (mode == MISC && !c.subarray) { |
e7b84f9d | 680 | pr_err("-N/--name only valid with --update-subarray in misc mode\n"); |
aa534678 DW |
681 | exit(2); |
682 | } | |
947fd4dd | 683 | if (strlen(optarg) > 32) { |
e7b84f9d | 684 | pr_err("name '%s' is too long, 32 chars max.\n", |
947fd4dd NB |
685 | optarg); |
686 | exit(2); | |
687 | } | |
688 | strcpy(ident.name, optarg); | |
689 | continue; | |
690 | ||
e0d19036 | 691 | case O(ASSEMBLE,'m'): /* super-minor for array */ |
1c7a808c | 692 | case O(ASSEMBLE,SuperMinor): |
98c6faba | 693 | if (ident.super_minor != UnSet) { |
e7b84f9d | 694 | pr_err("super-minor cannot be set twice. " |
cd29a5c8 NB |
695 | "Second value: %s.\n", optarg); |
696 | exit(2); | |
697 | } | |
d013a55e NB |
698 | if (strcmp(optarg, "dev")==0) |
699 | ident.super_minor = -2; | |
700 | else { | |
79868890 N |
701 | ident.super_minor = parse_num(optarg); |
702 | if (ident.super_minor < 0) { | |
e7b84f9d | 703 | pr_err("Bad super-minor number: %s.\n", optarg); |
d013a55e NB |
704 | exit(2); |
705 | } | |
cd29a5c8 NB |
706 | } |
707 | continue; | |
708 | ||
0ea8f5b1 N |
709 | case O(ASSEMBLE,'o'): |
710 | case O(MANAGE,'o'): | |
711 | case O(CREATE,'o'): | |
9e33d556 | 712 | c.readonly = 1; |
0ea8f5b1 N |
713 | continue; |
714 | ||
5787fa49 | 715 | case O(ASSEMBLE,'U'): /* update the superblock */ |
aa534678 | 716 | case O(MISC,'U'): |
9e33d556 | 717 | if (c.update) { |
e7b84f9d | 718 | pr_err("Can only update one aspect" |
833bb0f8 | 719 | " of superblock, both %s and %s given.\n", |
9e33d556 | 720 | c.update, optarg); |
5787fa49 NB |
721 | exit(2); |
722 | } | |
9e33d556 | 723 | if (mode == MISC && !c.subarray) { |
e7b84f9d | 724 | pr_err("Only subarrays can be" |
833bb0f8 | 725 | " updated in misc mode\n"); |
aa534678 DW |
726 | exit(2); |
727 | } | |
9e33d556 N |
728 | c.update = optarg; |
729 | if (strcmp(c.update, "sparc2.2")==0) | |
e5329c37 | 730 | continue; |
9e33d556 | 731 | if (strcmp(c.update, "super-minor") == 0) |
5787fa49 | 732 | continue; |
9e33d556 | 733 | if (strcmp(c.update, "summaries")==0) |
feb716e9 | 734 | continue; |
9e33d556 | 735 | if (strcmp(c.update, "resync")==0) |
e5329c37 | 736 | continue; |
9e33d556 | 737 | if (strcmp(c.update, "uuid")==0) |
7d99579f | 738 | continue; |
9e33d556 | 739 | if (strcmp(c.update, "name")==0) |
c4f12c13 | 740 | continue; |
9e33d556 | 741 | if (strcmp(c.update, "homehost")==0) |
0237e0ca | 742 | continue; |
9e33d556 | 743 | if (strcmp(c.update, "devicesize")==0) |
bee8ec56 | 744 | continue; |
9e33d556 | 745 | if (strcmp(c.update, "no-bitmap")==0) |
5a31170d | 746 | continue; |
688e99a7 N |
747 | if (strcmp(c.update, "bbl") == 0) |
748 | continue; | |
749 | if (strcmp(c.update, "no-bbl") == 0) | |
750 | continue; | |
afa368f4 N |
751 | if (strcmp(c.update, "metadata") == 0) |
752 | continue; | |
199f1a1f N |
753 | if (strcmp(c.update, "revert-reshape") == 0) |
754 | continue; | |
9e33d556 | 755 | if (strcmp(c.update, "byteorder")==0) { |
586ed405 | 756 | if (ss) { |
e7b84f9d N |
757 | pr_err("must not set metadata" |
758 | " type with --update=byteorder.\n"); | |
586ed405 NB |
759 | exit(2); |
760 | } | |
aba69144 | 761 | for(i=0; !ss && superlist[i]; i++) |
833bb0f8 N |
762 | ss = superlist[i]->match_metadata_desc( |
763 | "0.swap"); | |
586ed405 | 764 | if (!ss) { |
e7b84f9d | 765 | pr_err("INTERNAL ERROR" |
833bb0f8 | 766 | " cannot find 0.swap\n"); |
586ed405 NB |
767 | exit(2); |
768 | } | |
769 | ||
770 | continue; | |
771 | } | |
9e33d556 N |
772 | if (strcmp(c.update,"?") == 0 || |
773 | strcmp(c.update, "help") == 0) { | |
0047d254 | 774 | outf = stdout; |
d56dd607 | 775 | fprintf(outf, "%s: ", Name); |
0047d254 NB |
776 | } else { |
777 | outf = stderr; | |
778 | fprintf(outf, | |
d56dd607 PB |
779 | "%s: '--update=%s' is invalid. ", |
780 | Name, c.update); | |
0047d254 NB |
781 | } |
782 | fprintf(outf, "Valid --update options are:\n" | |
bee8ec56 | 783 | " 'sparc2.2', 'super-minor', 'uuid', 'name', 'resync',\n" |
5a31170d | 784 | " 'summaries', 'homehost', 'byteorder', 'devicesize',\n" |
c60495c8 N |
785 | " 'no-bitmap', 'metadata', 'revert-reshape'\n" |
786 | " 'bbl', 'no-bbl'\n" | |
787 | ); | |
0047d254 | 788 | exit(outf == stdout ? 0 : 2); |
5787fa49 | 789 | |
833bb0f8 N |
790 | case O(MANAGE,'U'): |
791 | /* update=devicesize is allowed with --re-add */ | |
c8e1a230 | 792 | if (devmode != 'A') { |
e7b84f9d | 793 | pr_err("--update in Manage mode only" |
833bb0f8 N |
794 | " allowed with --re-add.\n"); |
795 | exit(1); | |
796 | } | |
9e33d556 | 797 | if (c.update) { |
e7b84f9d | 798 | pr_err("Can only update one aspect" |
833bb0f8 | 799 | " of superblock, both %s and %s given.\n", |
9e33d556 | 800 | c.update, optarg); |
833bb0f8 N |
801 | exit(2); |
802 | } | |
9e33d556 | 803 | c.update = optarg; |
688e99a7 N |
804 | if (strcmp(c.update, "devicesize") != 0 && |
805 | strcmp(c.update, "bbl") != 0 && | |
806 | strcmp(c.update, "no-bbl") != 0) { | |
807 | pr_err("only 'devicesize', 'bbl' and 'no-bbl' can be" | |
833bb0f8 N |
808 | " updated with --re-add\n"); |
809 | exit(2); | |
810 | } | |
811 | continue; | |
812 | ||
172356c9 | 813 | case O(INCREMENTAL,NoDegraded): |
e7b84f9d | 814 | pr_err("--no-degraded is deprecated in Incremental mode\n"); |
997aed5d | 815 | case O(ASSEMBLE,NoDegraded): /* --no-degraded */ |
9e33d556 N |
816 | c.runstop = -1; /* --stop isn't allowed for --assemble, |
817 | * so we overload slightly */ | |
b8a8ccf9 NB |
818 | continue; |
819 | ||
1c7a808c N |
820 | case O(ASSEMBLE,'c'): |
821 | case O(ASSEMBLE,ConfigFile): | |
7b187ed7 | 822 | case O(INCREMENTAL, 'c'): |
1c7a808c | 823 | case O(INCREMENTAL, ConfigFile): |
2d465520 | 824 | case O(MISC, 'c'): |
1c7a808c | 825 | case O(MISC, ConfigFile): |
e0d19036 | 826 | case O(MONITOR,'c'): |
1c7a808c | 827 | case O(MONITOR,ConfigFile): |
9ccfd3be | 828 | case O(CREATE,ConfigFile): |
52826846 | 829 | if (configfile) { |
e7b84f9d | 830 | pr_err("configfile cannot be set twice. " |
52826846 NB |
831 | "Second value is %s.\n", optarg); |
832 | exit(2); | |
833 | } | |
834 | configfile = optarg; | |
8aec876d | 835 | set_conffile(configfile); |
52826846 NB |
836 | /* FIXME possibly check that config file exists. Even parse it */ |
837 | continue; | |
e0d19036 NB |
838 | case O(ASSEMBLE,'s'): /* scan */ |
839 | case O(MISC,'s'): | |
840 | case O(MONITOR,'s'): | |
8382f19b | 841 | case O(INCREMENTAL,'s'): |
9e33d556 | 842 | c.scan = 1; |
52826846 NB |
843 | continue; |
844 | ||
e0d19036 | 845 | case O(MONITOR,'m'): /* mail address */ |
1c7a808c | 846 | case O(MONITOR,EMail): |
52826846 | 847 | if (mailaddr) |
e7b84f9d | 848 | pr_err("only specify one mailaddress. %s ignored.\n", |
52826846 NB |
849 | optarg); |
850 | else | |
851 | mailaddr = optarg; | |
852 | continue; | |
853 | ||
e0d19036 | 854 | case O(MONITOR,'p'): /* alert program */ |
1c7a808c | 855 | case O(MONITOR,ProgramOpt): /* alert program */ |
52826846 | 856 | if (program) |
e7b84f9d | 857 | pr_err("only specify one alter program. %s ignored.\n", |
52826846 NB |
858 | optarg); |
859 | else | |
860 | program = optarg; | |
861 | continue; | |
64c4757e | 862 | |
9a36a9b7 | 863 | case O(MONITOR,'r'): /* rebuild increments */ |
1c7a808c | 864 | case O(MONITOR,Increment): |
9a36a9b7 | 865 | increments = atoi(optarg); |
18361a1a | 866 | if (increments > 99 || increments < 1) { |
e7b84f9d | 867 | pr_err("please specify positive integer between 1 and 99 as rebuild increments.\n"); |
9a36a9b7 ZB |
868 | exit(2); |
869 | } | |
870 | continue; | |
871 | ||
e0d19036 | 872 | case O(MONITOR,'d'): /* delay in seconds */ |
f5e166fe | 873 | case O(GROW, 'd'): |
c82f047c NB |
874 | case O(BUILD,'d'): /* delay for bitmap updates */ |
875 | case O(CREATE,'d'): | |
9e33d556 | 876 | if (c.delay) |
e7b84f9d | 877 | pr_err("only specify delay once. %s ignored.\n", |
52826846 NB |
878 | optarg); |
879 | else { | |
9e33d556 N |
880 | c.delay = parse_num(optarg); |
881 | if (c.delay < 1) { | |
e7b84f9d | 882 | pr_err("invalid delay: %s\n", |
52826846 NB |
883 | optarg); |
884 | exit(2); | |
885 | } | |
886 | } | |
887 | continue; | |
d013a55e | 888 | case O(MONITOR,'f'): /* daemonise */ |
1c7a808c | 889 | case O(MONITOR,Fork): |
d013a55e NB |
890 | daemonise = 1; |
891 | continue; | |
b5e64645 NB |
892 | case O(MONITOR,'i'): /* pid */ |
893 | if (pidfile) | |
e7b84f9d | 894 | pr_err("only specify one pid file. %s ignored.\n", |
b5e64645 NB |
895 | optarg); |
896 | else | |
897 | pidfile = optarg; | |
898 | continue; | |
aa88f531 NB |
899 | case O(MONITOR,'1'): /* oneshot */ |
900 | oneshot = 1; | |
3f555346 | 901 | spare_sharing = 0; |
aa88f531 | 902 | continue; |
98c6faba | 903 | case O(MONITOR,'t'): /* test */ |
9e33d556 | 904 | c.test = 1; |
98c6faba | 905 | continue; |
773135f5 | 906 | case O(MONITOR,'y'): /* log messages to syslog */ |
6ac8aac2 | 907 | openlog("mdadm", LOG_PID, SYSLOG_FACILITY); |
773135f5 NB |
908 | dosyslog = 1; |
909 | continue; | |
edde9560 AC |
910 | case O(MONITOR, NoSharing): |
911 | spare_sharing = 0; | |
912 | continue; | |
18361a1a | 913 | |
52826846 NB |
914 | /* now the general management options. Some are applicable |
915 | * to other modes. None have arguments. | |
916 | */ | |
e5329c37 | 917 | case O(GROW,'a'): |
1c7a808c N |
918 | case O(GROW,Add): |
919 | case O(MANAGE,'a'): | |
920 | case O(MANAGE,Add): /* add a drive */ | |
52826846 | 921 | devmode = 'a'; |
fe80f49b | 922 | continue; |
f33a71f1 N |
923 | case O(MANAGE,AddSpare): /* add drive - never re-add */ |
924 | devmode = 'S'; | |
925 | continue; | |
997aed5d | 926 | case O(MANAGE,ReAdd): |
c8e1a230 | 927 | devmode = 'A'; |
52826846 | 928 | continue; |
e0d19036 | 929 | case O(MANAGE,'r'): /* remove a drive */ |
1c7a808c | 930 | case O(MANAGE,Remove): |
52826846 NB |
931 | devmode = 'r'; |
932 | continue; | |
e0d19036 | 933 | case O(MANAGE,'f'): /* set faulty */ |
1c7a808c N |
934 | case O(MANAGE,Fail): |
935 | case O(INCREMENTAL,'f'): | |
936 | case O(INCREMENTAL,Remove): | |
937 | case O(INCREMENTAL,Fail): /* r for incremental is taken, use f | |
7d27d1c0 N |
938 | * even though we will both fail and |
939 | * remove the device */ | |
52826846 NB |
940 | devmode = 'f'; |
941 | continue; | |
70c55e36 N |
942 | case O(MANAGE,Replace): |
943 | /* Mark these devices for replacement */ | |
944 | devmode = 'R'; | |
945 | continue; | |
946 | case O(MANAGE,With): | |
947 | /* These are the replacements to use */ | |
948 | if (devmode != 'R') { | |
949 | pr_err("--with must follow --replace\n"); | |
950 | exit(2); | |
951 | } | |
952 | devmode = 'W'; | |
953 | continue; | |
8382f19b | 954 | case O(INCREMENTAL,'R'): |
e0d19036 NB |
955 | case O(MANAGE,'R'): |
956 | case O(ASSEMBLE,'R'): | |
957 | case O(BUILD,'R'): | |
958 | case O(CREATE,'R'): /* Run the array */ | |
9e33d556 | 959 | if (c.runstop < 0) { |
e7b84f9d | 960 | pr_err("Cannot both Stop and Run an array\n"); |
52826846 NB |
961 | exit(2); |
962 | } | |
9e33d556 | 963 | c.runstop = 1; |
52826846 | 964 | continue; |
e0d19036 | 965 | case O(MANAGE,'S'): |
9e33d556 | 966 | if (c.runstop > 0) { |
e7b84f9d | 967 | pr_err("Cannot both Run and Stop an array\n"); |
52826846 NB |
968 | exit(2); |
969 | } | |
9e33d556 | 970 | c.runstop = -1; |
52826846 | 971 | continue; |
7d2e6486 | 972 | case O(MANAGE,'t'): |
9e33d556 | 973 | c.test = 1; |
7d2e6486 | 974 | continue; |
52826846 | 975 | |
e0d19036 NB |
976 | case O(MISC,'Q'): |
977 | case O(MISC,'D'): | |
978 | case O(MISC,'E'): | |
f7d3febc | 979 | case O(MISC,KillOpt): |
e0d19036 NB |
980 | case O(MISC,'R'): |
981 | case O(MISC,'S'): | |
c82f047c | 982 | case O(MISC,'X'): |
6d388a88 | 983 | case O(MISC, ExamineBB): |
e0d19036 NB |
984 | case O(MISC,'o'): |
985 | case O(MISC,'w'): | |
b90c0e9a | 986 | case O(MISC,'W'): |
1c7a808c | 987 | case O(MISC, WaitOpt): |
1770662b | 988 | case O(MISC, Waitclean): |
4cce4069 | 989 | case O(MISC, DetailPlatform): |
33414a01 | 990 | case O(MISC, KillSubarray): |
aa534678 | 991 | case O(MISC, UpdateSubarray): |
74db60b0 N |
992 | case O(MISC, Dump): |
993 | case O(MISC, Restore): | |
a740cf64 | 994 | case O(MISC ,Action): |
5a53aeec | 995 | if (opt == KillSubarray || opt == UpdateSubarray) { |
9e33d556 | 996 | if (c.subarray) { |
e7b84f9d | 997 | pr_err("subarray can only" |
5a53aeec JS |
998 | " be specified once\n"); |
999 | exit(2); | |
1000 | } | |
9e33d556 | 1001 | c.subarray = optarg; |
5a53aeec | 1002 | } |
a740cf64 N |
1003 | if (opt == Action) { |
1004 | if (c.action) { | |
1005 | pr_err("Only one --action can be specified\n"); | |
1006 | exit(2); | |
1007 | } | |
1008 | if (strcmp(optarg, "idle") == 0 || | |
1009 | strcmp(optarg, "frozen") == 0 || | |
1010 | strcmp(optarg, "check") == 0 || | |
1011 | strcmp(optarg, "repair") == 0) | |
1012 | c.action = optarg; | |
1013 | else { | |
1014 | pr_err("action must be one of idle, frozen, check, repair\n"); | |
1015 | exit(2); | |
1016 | } | |
1017 | } | |
e0d19036 NB |
1018 | if (devmode && devmode != opt && |
1019 | (devmode == 'E' || (opt == 'E' && devmode != 'Q'))) { | |
e7b84f9d | 1020 | pr_err("--examine/-E cannot be given with "); |
aa534678 DW |
1021 | if (devmode == 'E') { |
1022 | if (option_index >= 0) | |
1023 | fprintf(stderr, "--%s\n", | |
1024 | long_options[option_index].name); | |
1025 | else | |
1026 | fprintf(stderr, "-%c\n", opt); | |
1027 | } else if (isalpha(devmode)) | |
1028 | fprintf(stderr, "-%c\n", devmode); | |
1029 | else | |
1030 | fprintf(stderr, "previous option\n"); | |
e0d19036 NB |
1031 | exit(2); |
1032 | } | |
1033 | devmode = opt; | |
74db60b0 N |
1034 | if (opt == Dump || opt == Restore) { |
1035 | if (dump_directory != NULL) { | |
1036 | pr_err("dump/restore directory specified twice: %s and %s\n", | |
1037 | dump_directory, optarg); | |
1038 | exit(2); | |
1039 | } | |
1040 | dump_directory = optarg; | |
1041 | } | |
e0d19036 | 1042 | continue; |
7d27d1c0 N |
1043 | case O(MISC, UdevRules): |
1044 | if (devmode && devmode != opt) { | |
e7b84f9d N |
1045 | pr_err("--udev-rules must" |
1046 | " be the only option.\n"); | |
7d27d1c0 N |
1047 | } else { |
1048 | if (udev_filename) | |
e7b84f9d | 1049 | pr_err("only specify one udev " |
7d27d1c0 N |
1050 | "rule filename. %s ignored.\n", |
1051 | optarg); | |
1052 | else | |
1053 | udev_filename = optarg; | |
1054 | } | |
1055 | devmode = opt; | |
1056 | continue; | |
feb716e9 | 1057 | case O(MISC,'t'): |
9e33d556 | 1058 | c.test = 1; |
feb716e9 | 1059 | continue; |
e0d19036 | 1060 | |
997aed5d | 1061 | case O(MISC, Sparc22): |
bd526cee | 1062 | if (devmode != 'E') { |
e7b84f9d | 1063 | pr_err("--sparc2.2 only allowed with --examine\n"); |
bd526cee NB |
1064 | exit(2); |
1065 | } | |
9e33d556 | 1066 | c.SparcAdjust = 1; |
bd526cee | 1067 | continue; |
c82f047c NB |
1068 | |
1069 | case O(ASSEMBLE,'b'): /* here we simply set the bitmap file */ | |
1c7a808c | 1070 | case O(ASSEMBLE,Bitmap): |
c82f047c | 1071 | if (!optarg) { |
e7b84f9d | 1072 | pr_err("bitmap file needed with -b in --assemble mode\n"); |
c82f047c NB |
1073 | exit(2); |
1074 | } | |
55935d51 | 1075 | if (strcmp(optarg, "internal")==0) { |
e7b84f9d | 1076 | pr_err("there is no need to specify --bitmap when assembling arrays with internal bitmaps\n"); |
55935d51 NB |
1077 | continue; |
1078 | } | |
c82f047c NB |
1079 | bitmap_fd = open(optarg, O_RDWR); |
1080 | if (!*optarg || bitmap_fd < 0) { | |
e7b84f9d | 1081 | pr_err("cannot open bitmap file %s: %s\n", optarg, strerror(errno)); |
c82f047c NB |
1082 | exit(2); |
1083 | } | |
1084 | ident.bitmap_fd = bitmap_fd; /* for Assemble */ | |
1085 | continue; | |
f5e166fe | 1086 | |
997aed5d NB |
1087 | case O(ASSEMBLE, BackupFile): |
1088 | case O(GROW, BackupFile): | |
06b0d786 NB |
1089 | /* Specify a file into which grow might place a backup, |
1090 | * or from which assemble might recover a backup | |
1091 | */ | |
9e33d556 | 1092 | if (c.backup_file) { |
e7b84f9d | 1093 | pr_err("backup file already specified, rejecting %s\n", optarg); |
06b0d786 NB |
1094 | exit(2); |
1095 | } | |
9e33d556 | 1096 | c.backup_file = optarg; |
06b0d786 NB |
1097 | continue; |
1098 | ||
2dddadb0 AK |
1099 | case O(GROW, Continue): |
1100 | /* Continue interrupted grow | |
1101 | */ | |
1102 | grow_continue = 1; | |
1103 | continue; | |
87f26d14 N |
1104 | case O(ASSEMBLE, InvalidBackup): |
1105 | /* Acknowledge that the backupfile is invalid, but ask | |
1106 | * to continue anyway | |
1107 | */ | |
9e33d556 | 1108 | c.invalid_backup = 1; |
87f26d14 N |
1109 | continue; |
1110 | ||
c82f047c | 1111 | case O(BUILD,'b'): |
1c7a808c N |
1112 | case O(BUILD,Bitmap): |
1113 | case O(CREATE,'b'): | |
1114 | case O(CREATE,Bitmap): /* here we create the bitmap */ | |
85375d6d | 1115 | case O(GROW,'b'): |
1c7a808c | 1116 | case O(GROW,Bitmap): |
1e0d770c NB |
1117 | if (strcmp(optarg, "internal")== 0 || |
1118 | strcmp(optarg, "none")== 0 || | |
1119 | strchr(optarg, '/') != NULL) { | |
e705e81b | 1120 | s.bitmap_file = optarg; |
1e0d770c NB |
1121 | continue; |
1122 | } | |
1123 | /* probable typo */ | |
e7b84f9d | 1124 | pr_err("bitmap file must contain a '/', or be 'internal', or 'none'\n" |
a1331cc4 | 1125 | " not '%s'\n", optarg); |
1e0d770c | 1126 | exit(2); |
c82f047c | 1127 | |
997aed5d NB |
1128 | case O(GROW,BitmapChunk): |
1129 | case O(BUILD,BitmapChunk): | |
1130 | case O(CREATE,BitmapChunk): /* bitmap chunksize */ | |
e705e81b | 1131 | s.bitmap_chunk = parse_size(optarg); |
822e393a N |
1132 | if (s.bitmap_chunk == 0 || |
1133 | s.bitmap_chunk == INVALID_SECTORS || | |
e705e81b | 1134 | s.bitmap_chunk & (s.bitmap_chunk - 1)) { |
e7b84f9d N |
1135 | pr_err("invalid bitmap chunksize: %s\n", |
1136 | optarg); | |
c82f047c NB |
1137 | exit(2); |
1138 | } | |
e705e81b | 1139 | s.bitmap_chunk = s.bitmap_chunk * 512; |
c82f047c | 1140 | continue; |
dfd4d8ee | 1141 | |
7d19ad0d | 1142 | case O(GROW, WriteBehind): |
997aed5d NB |
1143 | case O(BUILD, WriteBehind): |
1144 | case O(CREATE, WriteBehind): /* write-behind mode */ | |
e705e81b | 1145 | s.write_behind = DEFAULT_MAX_WRITE_BEHIND; |
dfd4d8ee | 1146 | if (optarg) { |
e705e81b N |
1147 | s.write_behind = parse_num(optarg); |
1148 | if (s.write_behind < 0 || | |
1149 | s.write_behind > 16383) { | |
e7b84f9d | 1150 | pr_err("Invalid value for maximum outstanding write-behind writes: %s.\n\tMust be between 0 and 16383.\n", optarg); |
dfd4d8ee NB |
1151 | exit(2); |
1152 | } | |
1153 | } | |
1154 | continue; | |
8382f19b NB |
1155 | |
1156 | case O(INCREMENTAL, 'r'): | |
1c7a808c | 1157 | case O(INCREMENTAL, RebuildMapOpt): |
8382f19b NB |
1158 | rebuild_map = 1; |
1159 | continue; | |
950bc344 PC |
1160 | case O(INCREMENTAL, IncrementalPath): |
1161 | remove_path = optarg; | |
1162 | continue; | |
52826846 NB |
1163 | } |
1164 | /* We have now processed all the valid options. Anything else is | |
1165 | * an error | |
1166 | */ | |
06b0d786 | 1167 | if (option_index > 0) |
e7b84f9d | 1168 | pr_err(":option --%s not valid in %s mode\n", |
06b0d786 NB |
1169 | long_options[option_index].name, |
1170 | map_num(modes, mode)); | |
1171 | else | |
e7b84f9d | 1172 | pr_err("option -%c not valid in %s mode\n", |
06b0d786 | 1173 | opt, map_num(modes, mode)); |
64c4757e | 1174 | exit(2); |
52826846 NB |
1175 | |
1176 | } | |
1177 | ||
3d4064cc | 1178 | if (print_help) { |
5187a385 | 1179 | char *help_text; |
3d4064cc NB |
1180 | if (print_help == 2) |
1181 | help_text = OptionHelp; | |
1182 | else | |
5187a385 N |
1183 | help_text = mode_help[mode]; |
1184 | if (help_text == NULL) | |
1185 | help_text = Help; | |
0047d254 | 1186 | fputs(help_text,stdout); |
3d4064cc NB |
1187 | exit(0); |
1188 | } | |
1189 | ||
0320ea45 NB |
1190 | if (!mode && devs_found) { |
1191 | mode = MISC; | |
1192 | devmode = 'Q'; | |
1193 | if (devlist->disposition == 0) | |
1194 | devlist->disposition = devmode; | |
1195 | } | |
52826846 NB |
1196 | if (!mode) { |
1197 | fputs(Usage, stderr); | |
64c4757e | 1198 | exit(2); |
64c4757e | 1199 | } |
38098016 NB |
1200 | |
1201 | if (symlinks) { | |
1202 | struct createinfo *ci = conf_get_create_info(); | |
1203 | ||
1204 | if (strcasecmp(symlinks, "yes") == 0) | |
1205 | ci->symlinks = 1; | |
1206 | else if (strcasecmp(symlinks, "no") == 0) | |
1207 | ci->symlinks = 0; | |
1208 | else { | |
e7b84f9d | 1209 | pr_err("option --symlinks must be 'no' or 'yes'\n"); |
38098016 NB |
1210 | exit(2); |
1211 | } | |
1212 | } | |
52826846 NB |
1213 | /* Ok, got the option parsing out of the way |
1214 | * hopefully it's mostly right but there might be some stuff | |
1215 | * missing | |
1216 | * | |
e0d19036 | 1217 | * That is mosty checked in the per-mode stuff but... |
52826846 | 1218 | * |
18361a1a N |
1219 | * For @,B,C and A without -s, the first device listed must be |
1220 | * an md device. We check that here and open it. | |
64c4757e | 1221 | */ |
52826846 | 1222 | |
18361a1a N |
1223 | if (mode == MANAGE || mode == BUILD || mode == CREATE |
1224 | || mode == GROW | |
9e33d556 | 1225 | || (mode == ASSEMBLE && ! c.scan)) { |
52826846 | 1226 | if (devs_found < 1) { |
e7b84f9d | 1227 | pr_err("an md device must be given in this mode\n"); |
52826846 NB |
1228 | exit(2); |
1229 | } | |
9e33d556 | 1230 | if ((int)ident.super_minor == -2 && c.autof) { |
e7b84f9d | 1231 | pr_err("--super-minor=dev is incompatible with --auto\n"); |
dd0781e5 NB |
1232 | exit(2); |
1233 | } | |
7f91af49 | 1234 | if (mode == MANAGE || mode == GROW) { |
6be1d39d | 1235 | mdfd = open_mddev(devlist->devname, 1); |
7f91af49 N |
1236 | if (mdfd < 0) |
1237 | exit(1); | |
1238 | } else | |
1239 | /* non-existent device is OK */ | |
1240 | mdfd = open_mddev(devlist->devname, 0); | |
1241 | if (mdfd == -2) { | |
e7b84f9d | 1242 | pr_err("device %s exists but is not an " |
7f91af49 | 1243 | "md array.\n", devlist->devname); |
52826846 | 1244 | exit(1); |
7f91af49 | 1245 | } |
98c6faba | 1246 | if ((int)ident.super_minor == -2) { |
d013a55e | 1247 | struct stat stb; |
7f91af49 | 1248 | if (mdfd < 0) { |
e7b84f9d | 1249 | pr_err("--super-minor=dev given, and " |
7f91af49 N |
1250 | "listed device %s doesn't exist.\n", |
1251 | devlist->devname); | |
1252 | exit(1); | |
1253 | } | |
d013a55e | 1254 | fstat(mdfd, &stb); |
0df46c2a | 1255 | ident.super_minor = minor(stb.st_rdev); |
d013a55e | 1256 | } |
7f91af49 N |
1257 | if (mdfd >= 0 && mode != MANAGE && mode != GROW) { |
1258 | /* We don't really want this open yet, we just might | |
1259 | * have wanted to check some things | |
1260 | */ | |
1261 | close(mdfd); | |
1262 | mdfd = -1; | |
1263 | } | |
64c4757e | 1264 | } |
52826846 | 1265 | |
e705e81b N |
1266 | if (s.raiddisks) { |
1267 | if (s.raiddisks == 1 && !c.force && s.level != LEVEL_FAULTY) { | |
e7b84f9d | 1268 | pr_err("'1' is an unusual number of drives for an array, so it is probably\n" |
e4c4352e NB |
1269 | " a mistake. If you really mean it you will need to specify --force before\n" |
1270 | " setting the number of drives.\n"); | |
1271 | exit(2); | |
1272 | } | |
1273 | } | |
c82f047c | 1274 | |
9e33d556 N |
1275 | if (c.homehost == NULL) |
1276 | c.homehost = conf_get_homehost(&c.require_homehost); | |
1277 | if (c.homehost == NULL || strcasecmp(c.homehost, "<system>")==0) { | |
05697ec1 NB |
1278 | if (gethostname(sys_hostname, sizeof(sys_hostname)) == 0) { |
1279 | sys_hostname[sizeof(sys_hostname)-1] = 0; | |
9e33d556 | 1280 | c.homehost = sys_hostname; |
05697ec1 NB |
1281 | } |
1282 | } | |
9e33d556 N |
1283 | if (c.homehost && (!c.homehost[0] || strcasecmp(c.homehost, "<none>") == 0)) { |
1284 | c.homehost = NULL; | |
1285 | c.require_homehost = 0; | |
0f23aa88 | 1286 | } |
997aed5d | 1287 | |
8192902f N |
1288 | if (c.backup_file && data_offset != INVALID_SECTORS) { |
1289 | pr_err("--backup-file and --data-offset are incompatible\n"); | |
1290 | exit(2); | |
1291 | } | |
1292 | ||
18361a1a N |
1293 | if ((mode == MISC && devmode == 'E') |
1294 | || (mode == MONITOR && spare_sharing == 0)) | |
1295 | /* Anyone may try this */; | |
1296 | else if (geteuid() != 0) { | |
e7b84f9d | 1297 | pr_err("must be super-user to perform this action\n"); |
ac5678dd N |
1298 | exit(1); |
1299 | } | |
1300 | ||
9e33d556 | 1301 | ident.autof = c.autof; |
7f91af49 | 1302 | |
265460ab N |
1303 | if (c.scan && c.verbose < 2) |
1304 | /* --scan implied --brief unless -vv */ | |
1305 | c.brief = 1; | |
1306 | ||
52826846 NB |
1307 | rv = 0; |
1308 | switch(mode) { | |
e0d19036 | 1309 | case MANAGE: |
52826846 | 1310 | /* readonly, add/remove, readwrite, runstop */ |
9e33d556 N |
1311 | if (c.readonly > 0) |
1312 | rv = Manage_ro(devlist->devname, mdfd, c.readonly); | |
52826846 | 1313 | if (!rv && devs_found>1) |
cd29a5c8 | 1314 | rv = Manage_subdevs(devlist->devname, mdfd, |
0937132d | 1315 | devlist->next, c.verbose, c.test, |
9e33d556 N |
1316 | c.update, c.force); |
1317 | if (!rv && c.readonly < 0) | |
1318 | rv = Manage_ro(devlist->devname, mdfd, c.readonly); | |
fe7e0e64 | 1319 | if (!rv && c.runstop > 0) |
d5a40416 | 1320 | rv = Manage_run(devlist->devname, mdfd, &c); |
fe7e0e64 N |
1321 | if (!rv && c.runstop < 0) |
1322 | rv = Manage_stop(devlist->devname, mdfd, c.verbose, 0); | |
52826846 | 1323 | break; |
e0d19036 | 1324 | case ASSEMBLE: |
d013a55e | 1325 | if (devs_found == 1 && ident.uuid_set == 0 && |
9e33d556 | 1326 | ident.super_minor == UnSet && ident.name[0] == 0 && !c.scan ) { |
d013a55e | 1327 | /* Only a device has been given, so get details from config file */ |
fa56eddb | 1328 | struct mddev_ident *array_ident = conf_get_ident(devlist->devname); |
b5e64645 | 1329 | if (array_ident == NULL) { |
e7b84f9d | 1330 | pr_err("%s not identified in config file.\n", |
b5e64645 | 1331 | devlist->devname); |
d013a55e | 1332 | rv |= 1; |
7f91af49 N |
1333 | if (mdfd >= 0) |
1334 | close(mdfd); | |
b5e64645 | 1335 | } else { |
7f91af49 | 1336 | if (array_ident->autof == 0) |
9e33d556 | 1337 | array_ident->autof = c.autof; |
7f91af49 | 1338 | rv |= Assemble(ss, devlist->devname, array_ident, |
4977146a | 1339 | NULL, &c); |
d013a55e | 1340 | } |
9e33d556 | 1341 | } else if (!c.scan) |
7f91af49 | 1342 | rv = Assemble(ss, devlist->devname, &ident, |
4977146a | 1343 | devlist->next, &c); |
18361a1a | 1344 | else if (devs_found > 0) { |
9e33d556 | 1345 | if (c.update && devs_found > 1) { |
e7b84f9d | 1346 | pr_err("can only update a single array at a time\n"); |
5787fa49 NB |
1347 | exit(1); |
1348 | } | |
9e33d556 | 1349 | if (c.backup_file && devs_found > 1) { |
e7b84f9d | 1350 | pr_err("can only assemble a single array when providing a backup file.\n"); |
06b0d786 NB |
1351 | exit(1); |
1352 | } | |
cd29a5c8 | 1353 | for (dv = devlist ; dv ; dv=dv->next) { |
fa56eddb | 1354 | struct mddev_ident *array_ident = conf_get_ident(dv->devname); |
52826846 | 1355 | if (array_ident == NULL) { |
e7b84f9d | 1356 | pr_err("%s not identified in config file.\n", |
cd29a5c8 | 1357 | dv->devname); |
52826846 NB |
1358 | rv |= 1; |
1359 | continue; | |
1360 | } | |
7f91af49 | 1361 | if (array_ident->autof == 0) |
9e33d556 | 1362 | array_ident->autof = c.autof; |
7f91af49 | 1363 | rv |= Assemble(ss, dv->devname, array_ident, |
4977146a | 1364 | NULL, &c); |
52826846 | 1365 | } |
5787fa49 | 1366 | } else { |
9e33d556 | 1367 | if (c.update) { |
e7b84f9d | 1368 | pr_err("--update not meaningful with a --scan assembly.\n"); |
da6b5ca9 NB |
1369 | exit(1); |
1370 | } | |
9e33d556 | 1371 | if (c.backup_file) { |
e7b84f9d | 1372 | pr_err("--backup_file not meaningful with a --scan assembly.\n"); |
da6b5ca9 NB |
1373 | exit(1); |
1374 | } | |
4977146a | 1375 | rv = scan_assemble(ss, &c, &ident); |
52826846 | 1376 | } |
3cbc4d12 | 1377 | |
52826846 | 1378 | break; |
e0d19036 | 1379 | case BUILD: |
9e33d556 N |
1380 | if (c.delay == 0) |
1381 | c.delay = DEFAULT_BITMAP_DELAY; | |
e705e81b | 1382 | if (s.write_behind && !s.bitmap_file) { |
e7b84f9d | 1383 | pr_err("write-behind mode requires a bitmap.\n"); |
dfd4d8ee NB |
1384 | rv = 1; |
1385 | break; | |
1386 | } | |
e705e81b | 1387 | if (s.raiddisks == 0) { |
e7b84f9d | 1388 | pr_err("no raid-devices specified.\n"); |
5b28bd56 NB |
1389 | rv = 1; |
1390 | break; | |
1391 | } | |
dfd4d8ee | 1392 | |
e705e81b N |
1393 | if (s.bitmap_file) { |
1394 | if (strcmp(s.bitmap_file, "internal")==0) { | |
e7b84f9d | 1395 | pr_err("'internal' bitmaps not supported with --build\n"); |
55935d51 NB |
1396 | rv |= 1; |
1397 | break; | |
1398 | } | |
c82f047c | 1399 | } |
a4e8316a | 1400 | rv = Build(devlist->devname, devlist->next, &s, &c); |
52826846 | 1401 | break; |
e0d19036 | 1402 | case CREATE: |
9e33d556 N |
1403 | if (c.delay == 0) |
1404 | c.delay = DEFAULT_BITMAP_DELAY; | |
e705e81b | 1405 | if (s.write_behind && !s.bitmap_file) { |
e7b84f9d | 1406 | pr_err("write-behind mode requires a bitmap.\n"); |
dfd4d8ee NB |
1407 | rv = 1; |
1408 | break; | |
1409 | } | |
e705e81b | 1410 | if (s.raiddisks == 0) { |
e7b84f9d | 1411 | pr_err("no raid-devices specified.\n"); |
5b28bd56 NB |
1412 | rv = 1; |
1413 | break; | |
1414 | } | |
f9ce90ba | 1415 | |
99cc42f4 N |
1416 | rv = Create(ss, devlist->devname, |
1417 | ident.name, ident.uuid_set ? ident.uuid : NULL, | |
171dccc8 | 1418 | devs_found-1, devlist->next, |
40c9a66a | 1419 | &s, &c, data_offset); |
52826846 | 1420 | break; |
e0d19036 | 1421 | case MISC: |
e0d19036 | 1422 | if (devmode == 'E') { |
9e33d556 | 1423 | if (devlist == NULL && !c.scan) { |
e7b84f9d | 1424 | pr_err("No devices to examine\n"); |
e0d19036 NB |
1425 | exit(2); |
1426 | } | |
1427 | if (devlist == NULL) | |
8aec876d | 1428 | devlist = conf_get_devs(); |
e0d19036 | 1429 | if (devlist == NULL) { |
e7b84f9d | 1430 | pr_err("No devices listed in %s\n", configfile?configfile:DefaultConfFile); |
e0d19036 NB |
1431 | exit(1); |
1432 | } | |
eec3f887 | 1433 | rv = Examine(devlist, &c, ss); |
4cce4069 | 1434 | } else if (devmode == DetailPlatform) { |
9eafa1de MN |
1435 | rv = Detail_Platform(ss ? ss->ss : NULL, ss ? c.scan : 1, |
1436 | c.verbose, c.export, | |
1437 | devlist ? devlist->devname : NULL); | |
7d27d1c0 | 1438 | } else if (devlist == NULL) { |
9e33d556 | 1439 | if (devmode == 'S' && c.scan) |
0937132d | 1440 | rv = stop_scan(c.verbose); |
9e33d556 | 1441 | else if ((devmode == 'D' || devmode == Waitclean) && c.scan) |
ef898ce6 | 1442 | rv = misc_scan(devmode, &c); |
7d27d1c0 N |
1443 | else if (devmode == UdevRules) |
1444 | rv = Write_rules(udev_filename); | |
1445 | else { | |
e7b84f9d | 1446 | pr_err("No devices given.\n"); |
7d27d1c0 | 1447 | exit(2); |
e0d19036 | 1448 | } |
7d27d1c0 | 1449 | } else |
74db60b0 | 1450 | rv = misc_list(devlist, &ident, dump_directory, ss, &c); |
9a9dab36 | 1451 | break; |
e0d19036 | 1452 | case MONITOR: |
9e33d556 | 1453 | if (!devlist && !c.scan) { |
e7b84f9d | 1454 | pr_err("Cannot monitor: need --scan or at least one device\n"); |
e0d19036 NB |
1455 | rv = 1; |
1456 | break; | |
1457 | } | |
b5e64645 | 1458 | if (pidfile && !daemonise) { |
e7b84f9d | 1459 | pr_err("Cannot write a pid file when not in daemon mode\n"); |
b5e64645 NB |
1460 | rv = 1; |
1461 | break; | |
1462 | } | |
9e33d556 | 1463 | if (c.delay == 0) { |
3e82d76d | 1464 | if (get_linux_version() > 2006016) |
ddc7201f | 1465 | /* mdstat responds to poll */ |
9e33d556 | 1466 | c.delay = 1000; |
ddc7201f | 1467 | else |
9e33d556 | 1468 | c.delay = 60; |
ddc7201f | 1469 | } |
95c50205 N |
1470 | if (c.delay == 0) |
1471 | c.delay = 60; | |
d013a55e | 1472 | rv= Monitor(devlist, mailaddr, program, |
95c50205 N |
1473 | &c, daemonise, oneshot, |
1474 | dosyslog, pidfile, increments, | |
1475 | spare_sharing); | |
9a9dab36 | 1476 | break; |
dd0781e5 NB |
1477 | |
1478 | case GROW: | |
a93f8c65 | 1479 | if (array_size > 0) { |
84e11361 N |
1480 | /* alway impose array size first, independent of |
1481 | * anything else | |
9ce510be N |
1482 | * Do not allow level or raid_disks changes at the |
1483 | * same time as that can be irreversibly destructive. | |
84e11361 N |
1484 | */ |
1485 | struct mdinfo sra; | |
1486 | int err; | |
e705e81b | 1487 | if (s.raiddisks || s.level != UnSet) { |
e7b84f9d | 1488 | pr_err("cannot change array size in same operation " |
9ce510be N |
1489 | "as changing raiddisks or level.\n" |
1490 | " Change size first, then check that data is still intact.\n"); | |
1491 | rv = 1; | |
1492 | break; | |
1493 | } | |
4dd2df09 | 1494 | sysfs_init(&sra, mdfd, NULL); |
a93f8c65 | 1495 | if (array_size == MAX_SIZE) |
84e11361 N |
1496 | err = sysfs_set_str(&sra, NULL, "array_size", "default"); |
1497 | else | |
1498 | err = sysfs_set_num(&sra, NULL, "array_size", array_size / 2); | |
1499 | if (err < 0) { | |
1500 | if (errno == E2BIG) | |
e7b84f9d | 1501 | pr_err("--array-size setting" |
84e11361 N |
1502 | " is too large.\n"); |
1503 | else | |
e7b84f9d | 1504 | pr_err("current kernel does" |
84e11361 N |
1505 | " not support setting --array-size\n"); |
1506 | rv = 1; | |
1507 | break; | |
1508 | } | |
1509 | } | |
1c8b90df | 1510 | if (devs_found > 1 && s.raiddisks == 0 && s.level == UnSet) { |
e5329c37 | 1511 | /* must be '-a'. */ |
e705e81b | 1512 | if (s.size > 0 || s.chunk || s.layout_str != NULL || s.bitmap_file) { |
e7b84f9d | 1513 | pr_err("--add cannot be used with " |
e2e53a2d | 1514 | "other geometry changes in --grow mode\n"); |
e5329c37 NB |
1515 | rv = 1; |
1516 | break; | |
1517 | } | |
1518 | for (dv=devlist->next; dv ; dv=dv->next) { | |
e2e53a2d N |
1519 | rv = Grow_Add_device(devlist->devname, mdfd, |
1520 | dv->devname); | |
e5329c37 NB |
1521 | if (rv) |
1522 | break; | |
1523 | } | |
e705e81b N |
1524 | } else if (s.bitmap_file) { |
1525 | if (s.size > 0 || s.raiddisks || s.chunk || | |
1526 | s.layout_str != NULL || devs_found > 1) { | |
e7b84f9d | 1527 | pr_err("--bitmap changes cannot be " |
e2e53a2d N |
1528 | "used with other geometry changes " |
1529 | "in --grow mode\n"); | |
7236ee7a N |
1530 | rv = 1; |
1531 | break; | |
1532 | } | |
9e33d556 N |
1533 | if (c.delay == 0) |
1534 | c.delay = DEFAULT_BITMAP_DELAY; | |
50f01ba5 | 1535 | rv = Grow_addbitmap(devlist->devname, mdfd, &c, &s); |
2dddadb0 AK |
1536 | } else if (grow_continue) |
1537 | rv = Grow_continue_command(devlist->devname, | |
9e33d556 | 1538 | mdfd, c.backup_file, |
0937132d | 1539 | c.verbose); |
e705e81b | 1540 | else if (s.size > 0 || s.raiddisks || s.layout_str != NULL |
8876bf0b N |
1541 | || s.chunk != 0 || s.level != UnSet |
1542 | || data_offset != INVALID_SECTORS) { | |
32754b7d | 1543 | rv = Grow_reshape(devlist->devname, mdfd, |
40c9a66a N |
1544 | devlist->next, |
1545 | data_offset, &c, &s); | |
a93f8c65 | 1546 | } else if (array_size == 0) |
e7b84f9d | 1547 | pr_err("no changes to --grow\n"); |
dd0781e5 | 1548 | break; |
8382f19b NB |
1549 | case INCREMENTAL: |
1550 | if (rebuild_map) { | |
1551 | RebuildMap(); | |
1552 | } | |
9e33d556 | 1553 | if (c.scan) { |
9eaf410f N |
1554 | rv = 1; |
1555 | if (devlist) { | |
1556 | pr_err("In --incremental mode, a device cannot be given with --scan.\n"); | |
1557 | break; | |
1558 | } | |
9e33d556 | 1559 | if (c.runstop <= 0) { |
e7b84f9d | 1560 | pr_err("--incremental --scan meaningless without --run.\n"); |
8382f19b NB |
1561 | break; |
1562 | } | |
29ba4804 | 1563 | if (devmode == 'f') { |
e7b84f9d | 1564 | pr_err("--incremental --scan --fail not supported.\n"); |
29ba4804 N |
1565 | break; |
1566 | } | |
d5a40416 | 1567 | rv = IncrementalScan(&c, NULL); |
8382f19b NB |
1568 | } |
1569 | if (!devlist) { | |
9e33d556 | 1570 | if (!rebuild_map && !c.scan) { |
e7b84f9d | 1571 | pr_err("--incremental requires a device.\n"); |
8382f19b NB |
1572 | rv = 1; |
1573 | } | |
1574 | break; | |
1575 | } | |
b11fe74d N |
1576 | if (devmode == 'f') { |
1577 | if (devlist->next) { | |
1578 | pr_err("'--incremental --fail' can only handle one device.\n"); | |
1579 | rv = 1; | |
1580 | break; | |
1581 | } | |
950bc344 | 1582 | rv = IncrementalRemove(devlist->devname, remove_path, |
0937132d | 1583 | c.verbose); |
b11fe74d N |
1584 | } else |
1585 | rv = Incremental(devlist, &c, ss); | |
1f48664b NB |
1586 | break; |
1587 | case AUTODETECT: | |
1588 | autodetect(); | |
1589 | break; | |
64c4757e | 1590 | } |
52826846 | 1591 | exit(rv); |
64c4757e | 1592 | } |
3cbc4d12 | 1593 | |
4977146a N |
1594 | static int scan_assemble(struct supertype *ss, |
1595 | struct context *c, | |
1596 | struct mddev_ident *ident) | |
3cbc4d12 N |
1597 | { |
1598 | struct mddev_ident *a, *array_list = conf_get_ident(NULL); | |
1599 | struct mddev_dev *devlist = conf_get_devs(); | |
1600 | struct map_ent *map = NULL; | |
1601 | int cnt = 0; | |
1602 | int rv = 0; | |
1603 | int failures, successes; | |
1604 | ||
1605 | if (conf_verify_devnames(array_list)) { | |
e7b84f9d N |
1606 | pr_err("Duplicate MD device names in " |
1607 | "conf file were found.\n"); | |
3cbc4d12 N |
1608 | return 1; |
1609 | } | |
1610 | if (devlist == NULL) { | |
e7b84f9d | 1611 | pr_err("No devices listed in conf file were found.\n"); |
3cbc4d12 N |
1612 | return 1; |
1613 | } | |
1614 | for (a = array_list; a ; a = a->next) { | |
1615 | a->assembled = 0; | |
1616 | if (a->autof == 0) | |
4977146a | 1617 | a->autof = c->autof; |
3cbc4d12 N |
1618 | } |
1619 | if (map_lock(&map)) | |
1ade5cc1 | 1620 | pr_err("failed to get exclusive lock on mapfile\n"); |
3cbc4d12 N |
1621 | do { |
1622 | failures = 0; | |
1623 | successes = 0; | |
1624 | rv = 0; | |
1625 | for (a = array_list; a ; a = a->next) { | |
1626 | int r; | |
1627 | if (a->assembled) | |
1628 | continue; | |
1629 | if (a->devname && | |
1630 | strcasecmp(a->devname, "<ignore>") == 0) | |
1631 | continue; | |
1011e834 | 1632 | |
3cbc4d12 | 1633 | r = Assemble(ss, a->devname, |
4977146a | 1634 | a, NULL, c); |
3cbc4d12 N |
1635 | if (r == 0) { |
1636 | a->assembled = 1; | |
1637 | successes++; | |
1638 | } else | |
1639 | failures++; | |
1640 | rv |= r; | |
1641 | cnt++; | |
1642 | } | |
1643 | } while (failures && successes); | |
4977146a | 1644 | if (c->homehost && cnt == 0) { |
3cbc4d12 N |
1645 | /* Maybe we can auto-assemble something. |
1646 | * Repeatedly call Assemble in auto-assemble mode | |
1647 | * until it fails | |
1648 | */ | |
1649 | int rv2; | |
1650 | int acnt; | |
4977146a | 1651 | ident->autof = c->autof; |
3cbc4d12 N |
1652 | do { |
1653 | struct mddev_dev *devlist = conf_get_devs(); | |
1654 | acnt = 0; | |
1655 | do { | |
1656 | rv2 = Assemble(ss, NULL, | |
1657 | ident, | |
4977146a | 1658 | devlist, c); |
3cbc4d12 N |
1659 | if (rv2==0) { |
1660 | cnt++; | |
1661 | acnt++; | |
1662 | } | |
1663 | } while (rv2!=2); | |
1664 | /* Incase there are stacked devices, we need to go around again */ | |
1665 | } while (acnt); | |
1666 | if (cnt == 0 && rv == 0) { | |
e7b84f9d | 1667 | pr_err("No arrays found in config file or automatically\n"); |
3cbc4d12 N |
1668 | rv = 1; |
1669 | } else if (cnt) | |
1670 | rv = 0; | |
1671 | } else if (cnt == 0 && rv == 0) { | |
e7b84f9d | 1672 | pr_err("No arrays found in config file\n"); |
3cbc4d12 N |
1673 | rv = 1; |
1674 | } | |
1675 | map_unlock(&map); | |
1676 | return rv; | |
1677 | } | |
7d27d1c0 | 1678 | |
ef898ce6 | 1679 | static int misc_scan(char devmode, struct context *c) |
7d27d1c0 N |
1680 | { |
1681 | /* apply --detail or --wait-clean to | |
1682 | * all devices in /proc/mdstat | |
1683 | */ | |
1684 | struct mdstat_ent *ms = mdstat_read(0, 1); | |
1685 | struct mdstat_ent *e; | |
1686 | struct map_ent *map = NULL; | |
1687 | int members; | |
7d27d1c0 N |
1688 | int rv = 0; |
1689 | ||
1690 | for (members = 0; members <= 1; members++) { | |
1691 | for (e=ms ; e ; e=e->next) { | |
743eaf8b | 1692 | char *name = NULL; |
7d27d1c0 | 1693 | struct map_ent *me; |
743eaf8b | 1694 | struct stat stb; |
7d27d1c0 N |
1695 | int member = e->metadata_version && |
1696 | strncmp(e->metadata_version, | |
1697 | "external:/", 10) == 0; | |
1698 | if (members != member) | |
1699 | continue; | |
4dd2df09 | 1700 | me = map_by_devnm(&map, e->devnm); |
7d27d1c0 N |
1701 | if (me && me->path |
1702 | && strcmp(me->path, "/unknown") != 0) | |
1703 | name = me->path; | |
743eaf8b N |
1704 | if (name == NULL || |
1705 | stat(name, &stb) != 0) | |
4dd2df09 | 1706 | name = get_md_name(e->devnm); |
7d27d1c0 N |
1707 | |
1708 | if (!name) { | |
e7b84f9d | 1709 | pr_err("cannot find device file for %s\n", |
7d27d1c0 N |
1710 | e->dev); |
1711 | continue; | |
1712 | } | |
1713 | if (devmode == 'D') | |
ef898ce6 | 1714 | rv |= Detail(name, c); |
7d27d1c0 | 1715 | else |
ef898ce6 | 1716 | rv |= WaitClean(name, -1, c->verbose); |
7d27d1c0 N |
1717 | put_md_name(name); |
1718 | } | |
1719 | } | |
1720 | free_mdstat(ms); | |
1721 | return rv; | |
1722 | } | |
1723 | ||
ba728be7 | 1724 | static int stop_scan(int verbose) |
7d27d1c0 N |
1725 | { |
1726 | /* apply --stop to all devices in /proc/mdstat */ | |
1727 | /* Due to possible stacking of devices, repeat until | |
1728 | * nothing more can be stopped | |
1729 | */ | |
1730 | int progress=1, err; | |
1731 | int last = 0; | |
1732 | int rv = 0; | |
1733 | do { | |
1734 | struct mdstat_ent *ms = mdstat_read(0, 0); | |
1735 | struct mdstat_ent *e; | |
1736 | ||
1737 | if (!progress) last = 1; | |
1738 | progress = 0; err = 0; | |
1739 | for (e=ms ; e ; e=e->next) { | |
4dd2df09 | 1740 | char *name = get_md_name(e->devnm); |
7d27d1c0 N |
1741 | int mdfd; |
1742 | ||
1743 | if (!name) { | |
e7b84f9d | 1744 | pr_err("cannot find device file for %s\n", |
7d27d1c0 N |
1745 | e->dev); |
1746 | continue; | |
1747 | } | |
1748 | mdfd = open_mddev(name, 1); | |
1749 | if (mdfd >= 0) { | |
fe7e0e64 | 1750 | if (Manage_stop(name, mdfd, verbose, !last)) |
7d27d1c0 N |
1751 | err = 1; |
1752 | else | |
1753 | progress = 1; | |
1754 | close(mdfd); | |
1755 | } | |
1756 | ||
1757 | put_md_name(name); | |
1758 | } | |
1759 | free_mdstat(ms); | |
1760 | } while (!last && err); | |
1761 | if (err) | |
1762 | rv |= 1; | |
1763 | return rv; | |
1764 | } | |
1765 | ||
1766 | static int misc_list(struct mddev_dev *devlist, | |
86da243f | 1767 | struct mddev_ident *ident, |
74db60b0 | 1768 | char *dump_directory, |
86da243f | 1769 | struct supertype *ss, struct context *c) |
7d27d1c0 N |
1770 | { |
1771 | struct mddev_dev *dv; | |
1772 | int rv = 0; | |
1773 | ||
74db60b0 | 1774 | for (dv=devlist ; dv; dv=(rv & 16) ? NULL : dv->next) { |
7d27d1c0 N |
1775 | int mdfd; |
1776 | ||
1777 | switch(dv->disposition) { | |
1778 | case 'D': | |
ef898ce6 | 1779 | rv |= Detail(dv->devname, c); |
7d27d1c0 N |
1780 | continue; |
1781 | case KillOpt: /* Zero superblock */ | |
1782 | if (ss) | |
86da243f | 1783 | rv |= Kill(dv->devname, ss, c->force, c->verbose,0); |
7d27d1c0 | 1784 | else { |
86da243f | 1785 | int v = c->verbose; |
7d27d1c0 | 1786 | do { |
86da243f | 1787 | rv |= Kill(dv->devname, NULL, c->force, v, 0); |
ba728be7 | 1788 | v = -1; |
7d27d1c0 N |
1789 | } while (rv == 0); |
1790 | rv &= ~2; | |
1791 | } | |
1792 | continue; | |
1793 | case 'Q': | |
1794 | rv |= Query(dv->devname); continue; | |
1795 | case 'X': | |
86da243f | 1796 | rv |= ExamineBitmap(dv->devname, c->brief, ss); continue; |
6d388a88 N |
1797 | case ExamineBB: |
1798 | rv |= ExamineBadblocks(dv->devname, c->brief, ss); continue; | |
7d27d1c0 N |
1799 | case 'W': |
1800 | case WaitOpt: | |
1801 | rv |= Wait(dv->devname); continue; | |
1802 | case Waitclean: | |
86da243f | 1803 | rv |= WaitClean(dv->devname, -1, c->verbose); continue; |
7d27d1c0 | 1804 | case KillSubarray: |
86da243f | 1805 | rv |= Kill_subarray(dv->devname, c->subarray, c->verbose); |
7d27d1c0 N |
1806 | continue; |
1807 | case UpdateSubarray: | |
86da243f | 1808 | if (c->update == NULL) { |
e7b84f9d | 1809 | pr_err("-U/--update must be specified with --update-subarray\n"); |
7d27d1c0 N |
1810 | rv |= 1; |
1811 | continue; | |
1812 | } | |
86da243f N |
1813 | rv |= Update_subarray(dv->devname, c->subarray, |
1814 | c->update, ident, c->verbose); | |
7d27d1c0 | 1815 | continue; |
74db60b0 N |
1816 | case Dump: |
1817 | rv |= Dump_metadata(dv->devname, dump_directory, c, ss); | |
1818 | continue; | |
1819 | case Restore: | |
1820 | rv |= Restore_metadata(dv->devname, dump_directory, c, ss, | |
1821 | (dv == devlist && dv->next == NULL)); | |
1822 | continue; | |
a740cf64 N |
1823 | case Action: |
1824 | rv |= SetAction(dv->devname, c->action); | |
1825 | continue; | |
7d27d1c0 | 1826 | } |
e6dd89da N |
1827 | if (dv->devname[0] == '/') |
1828 | mdfd = open_mddev(dv->devname, 1); | |
1829 | else { | |
1830 | mdfd = open_dev(dv->devname); | |
1831 | if (mdfd < 0) | |
1832 | pr_err("Cannot open %s\n", dv->devname); | |
1833 | } | |
7d27d1c0 N |
1834 | if (mdfd>=0) { |
1835 | switch(dv->disposition) { | |
1836 | case 'R': | |
d5a40416 N |
1837 | c->runstop = 1; |
1838 | rv |= Manage_run(dv->devname, mdfd, c); break; | |
7d27d1c0 | 1839 | case 'S': |
fe7e0e64 | 1840 | rv |= Manage_stop(dv->devname, mdfd, c->verbose, 0); break; |
7d27d1c0 N |
1841 | case 'o': |
1842 | rv |= Manage_ro(dv->devname, mdfd, 1); break; | |
1843 | case 'w': | |
1844 | rv |= Manage_ro(dv->devname, mdfd, -1); break; | |
1845 | } | |
1846 | close(mdfd); | |
1847 | } else | |
1848 | rv |= 1; | |
1849 | } | |
1850 | return rv; | |
1851 | } | |
a740cf64 N |
1852 | |
1853 | int SetAction(char *dev, char *action) | |
1854 | { | |
1855 | int fd = open(dev, O_RDONLY); | |
1856 | struct mdinfo mdi; | |
1857 | if (fd < 0) { | |
1858 | pr_err("Couldn't open %s: %s\n", dev, strerror(errno)); | |
1859 | return 1; | |
1860 | } | |
1861 | sysfs_init(&mdi, fd, NULL); | |
1862 | close(fd); | |
1863 | if (!mdi.sys_name[0]) { | |
1864 | pr_err("%s is no an md array\n", dev); | |
1865 | return 1; | |
1866 | } | |
1867 | ||
1868 | if (sysfs_set_str(&mdi, NULL, "sync_action", action) < 0) { | |
1869 | pr_err("Count not set action for %s to %s: %s\n", | |
1870 | dev, action, strerror(errno)); | |
1871 | return 1; | |
1872 | } | |
1873 | return 0; | |
1874 | } |