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