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