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