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