]> git.ipfire.org Git - thirdparty/mdadm.git/blob - mdadm.c
Add missing 'continue' in Grow_restart.
[thirdparty/mdadm.git] / mdadm.c
1 /*
2 * mdadm - manage Linux "md" devices aka RAID arrays.
3 *
4 * Copyright (C) 2001-2009 Neil Brown <neilb@suse.de>
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
22 * Email: <neilb@suse.de>
23 *
24 * Additions for bitmap and write-behind RAID options, Copyright (C) 2003-2004,
25 * Paul Clements, SteelEye Technology, Inc.
26 */
27
28 #include "mdadm.h"
29 #include "md_p.h"
30 #include <ctype.h>
31
32
33 int main(int argc, char *argv[])
34 {
35 int mode = 0;
36 int opt;
37 int option_index;
38 char *c;
39 int rv;
40 int i;
41
42 int chunk = 0;
43 long long size = -1;
44 long long array_size = -1;
45 int level = UnSet;
46 int layout = UnSet;
47 char *layout_str = NULL;
48 int raiddisks = 0;
49 int max_disks = MD_SB_DISKS; /* just a default */
50 int sparedisks = 0;
51 struct mddev_ident_s ident;
52 char *configfile = NULL;
53 char *cp;
54 char *update = NULL;
55 int scan = 0;
56 char devmode = 0;
57 int runstop = 0;
58 int readonly = 0;
59 int write_behind = 0;
60 int bitmap_fd = -1;
61 char *bitmap_file = NULL;
62 char *backup_file = NULL;
63 int bitmap_chunk = UnSet;
64 int SparcAdjust = 0;
65 mddev_dev_t devlist = NULL;
66 mddev_dev_t *devlistend = & devlist;
67 mddev_dev_t dv;
68 int devs_found = 0;
69 int verbose = 0;
70 int quiet = 0;
71 int brief = 0;
72 int force = 0;
73 int test = 0;
74 int export = 0;
75 int assume_clean = 0;
76 char *symlinks = NULL;
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;
88
89 char *homehost = NULL;
90 char sys_hostname[256];
91 int require_homehost = 1;
92 char *mailaddr = NULL;
93 char *program = NULL;
94 int delay = 0;
95 int daemonise = 0;
96 char *pidfile = NULL;
97 int oneshot = 0;
98 struct supertype *ss = NULL;
99 int writemostly = 0;
100 int re_add = 0;
101 char *shortopt = short_options;
102 int dosyslog = 0;
103 int rebuild_map = 0;
104 int auto_update_home = 0;
105
106 int print_help = 0;
107 FILE *outf;
108
109 int mdfd = -1;
110
111 srandom(time(0) ^ getpid());
112
113 ident.uuid_set=0;
114 ident.level = UnSet;
115 ident.raid_disks = UnSet;
116 ident.super_minor= UnSet;
117 ident.devices=0;
118 ident.spare_group = NULL;
119 ident.autof = 0;
120 ident.st = NULL;
121 ident.bitmap_fd = -1;
122 ident.bitmap_file = NULL;
123 ident.name[0] = 0;
124 ident.container = NULL;
125 ident.member = NULL;
126
127 while ((option_index = -1) ,
128 (opt=getopt_long(argc, argv,
129 shortopt, long_options,
130 &option_index)) != -1) {
131 int newmode = mode;
132 /* firstly, some mode-independent options */
133 switch(opt) {
134 case 'h':
135 if (option_index > 0 &&
136 strcmp(long_options[option_index].name, "help-options")==0)
137 print_help = 2;
138 else
139 print_help = 1;
140 continue;
141
142 case 'V':
143 fputs(Version, stderr);
144 exit(0);
145
146 case 'v': verbose++;
147 continue;
148
149 case 'q': quiet++;
150 continue;
151
152 case 'b':
153 if (mode == ASSEMBLE || mode == BUILD || mode == CREATE || mode == GROW)
154 break; /* b means bitmap */
155 brief = 1;
156 if (optarg) {
157 fprintf(stderr, Name ": -b cannot have any extra immediately after it, sorry.\n");
158 exit(2);
159 }
160 continue;
161
162 case 'Y': export++;
163 continue;
164
165 case HomeHost:
166 if (strcasecmp(optarg, "<ignore>") == 0)
167 require_homehost = 0;
168 else
169 homehost = optarg;
170 continue;
171
172 case ':':
173 case '?':
174 fputs(Usage, stderr);
175 exit(2);
176 }
177 /* second, figure out the mode.
178 * Some options force the mode. Others
179 * set the mode if it isn't already
180 */
181
182 switch(opt) {
183 case '@': /* just incase they say --manage */
184 newmode = MANAGE;
185 shortopt = short_bitmap_options;
186 break;
187 case 'a':
188 case 'r':
189 case 'f':
190 case ReAdd: /* re-add */
191 if (!mode) {
192 newmode = MANAGE;
193 shortopt = short_bitmap_options;
194 }
195 break;
196
197 case 'A': newmode = ASSEMBLE; shortopt = short_bitmap_auto_options; break;
198 case 'B': newmode = BUILD; shortopt = short_bitmap_auto_options; break;
199 case 'C': newmode = CREATE; shortopt = short_bitmap_auto_options; break;
200 case 'F': newmode = MONITOR;break;
201 case 'G': newmode = GROW;
202 shortopt = short_bitmap_options;
203 break;
204 case 'I': newmode = INCREMENTAL;
205 shortopt = short_bitmap_auto_options; break;
206 case AutoDetect:
207 newmode = AUTODETECT; break;
208
209 case '#':
210 case 'D':
211 case 'E':
212 case 'X':
213 case 'Q': newmode = MISC; break;
214 case 'R':
215 case 'S':
216 case 'o':
217 case 'w':
218 case 'W':
219 case Waitclean:
220 case DetailPlatform:
221 case 'K': if (!mode) newmode = MISC; break;
222 }
223 if (mode && newmode == mode) {
224 /* everybody happy ! */
225 } else if (mode && newmode != mode) {
226 /* not allowed.. */
227 fprintf(stderr, Name ": ");
228 if (option_index >= 0)
229 fprintf(stderr, "--%s", long_options[option_index].name);
230 else
231 fprintf(stderr, "-%c", opt);
232 fprintf(stderr, " would set mdadm mode to \"%s\", but it is already set to \"%s\".\n",
233 map_num(modes, newmode),
234 map_num(modes, mode));
235 exit(2);
236 } else if (!mode && newmode) {
237 mode = newmode;
238 } else {
239 /* special case of -c --help */
240 if (opt == 'c' &&
241 ( strncmp(optarg, "--h", 3)==0 ||
242 strncmp(optarg, "-h", 2)==0)) {
243 fputs(Help_config, stdout);
244 exit(0);
245 }
246
247 /* If first option is a device, don't force the mode yet */
248 if (opt == 1) {
249 if (devs_found == 0) {
250 dv = malloc(sizeof(*dv));
251 if (dv == NULL) {
252 fprintf(stderr, Name ": malloc failed\n");
253 exit(3);
254 }
255 dv->devname = optarg;
256 dv->disposition = devmode;
257 dv->writemostly = writemostly;
258 dv->re_add = re_add;
259 dv->used = 0;
260 dv->content = NULL;
261 dv->next = NULL;
262 *devlistend = dv;
263 devlistend = &dv->next;
264
265 devs_found++;
266 continue;
267 }
268 /* No mode yet, and this is the second device ... */
269 fprintf(stderr, Name ": An option must be given to set the mode before a second device is listed\n");
270 exit(2);
271 }
272 if (option_index >= 0)
273 fprintf(stderr, Name ": --%s", long_options[option_index].name);
274 else
275 fprintf(stderr, Name ": -%c", opt);
276 fprintf(stderr, " does not set the mode, and so cannot be the first option.\n");
277 exit(2);
278 }
279
280 /* if we just set the mode, then done */
281 switch(opt) {
282 case '@':
283 case '#':
284 case 'A':
285 case 'B':
286 case 'C':
287 case 'F':
288 case 'G':
289 case 'I':
290 case AutoDetect:
291 continue;
292 }
293 if (opt == 1) {
294 /* an undecorated option - must be a device name.
295 */
296 if (devs_found > 0 && mode == '@' && !devmode) {
297 fprintf(stderr, Name ": Must give one of -a/-r/-f for subsequent devices at %s\n", optarg);
298 exit(2);
299 }
300 if (devs_found > 0 && mode == 'G' && !devmode) {
301 fprintf(stderr, Name ": Must give one of -a for devices do add: %s\n", optarg);
302 exit(2);
303 }
304 dv = malloc(sizeof(*dv));
305 if (dv == NULL) {
306 fprintf(stderr, Name ": malloc failed\n");
307 exit(3);
308 }
309 dv->devname = optarg;
310 dv->disposition = devmode;
311 dv->writemostly = writemostly;
312 dv->re_add = re_add;
313 dv->used = 0;
314 dv->content = NULL;
315 dv->next = NULL;
316 *devlistend = dv;
317 devlistend = &dv->next;
318
319 devs_found++;
320 continue;
321 }
322
323 /* We've got a mode, and opt is now something else which
324 * could depend on the mode */
325 #define O(a,b) ((a<<8)|b)
326 switch (O(mode,opt)) {
327 case O(GROW,'c'):
328 case O(CREATE,'c'):
329 case O(BUILD,'c'): /* chunk or rounding */
330 if (chunk) {
331 fprintf(stderr, Name ": chunk/rounding may only be specified once. "
332 "Second value is %s.\n", optarg);
333 exit(2);
334 }
335 chunk = strtol(optarg, &c, 10);
336 if (!optarg[0] || *c || chunk<4 || ((chunk-1)&chunk)) {
337 fprintf(stderr, Name ": invalid chunk/rounding value: %s\n",
338 optarg);
339 exit(2);
340 }
341 continue;
342
343 #if 0
344 case O(ASSEMBLE,AutoHomeHost):
345 auto_update_home = 1;
346 continue;
347 #endif
348 case O(INCREMENTAL, 'e'):
349 case O(CREATE,'e'):
350 case O(ASSEMBLE,'e'):
351 case O(MISC,'e'): /* set metadata (superblock) information */
352 if (ss) {
353 fprintf(stderr, Name ": metadata information already given\n");
354 exit(2);
355 }
356 for(i=0; !ss && superlist[i]; i++)
357 ss = superlist[i]->match_metadata_desc(optarg);
358
359 if (!ss) {
360 fprintf(stderr, Name ": unrecognised metadata identifier: %s\n", optarg);
361 exit(2);
362 }
363 max_disks = ss->max_devs;
364 continue;
365
366 case O(MANAGE,'W'):
367 case O(BUILD,'W'):
368 case O(CREATE,'W'):
369 /* set write-mostly for following devices */
370 writemostly = 1;
371 continue;
372
373 case O(MANAGE,'w'):
374 /* clear write-mostly for following devices */
375 writemostly = 2;
376 continue;
377
378
379 case O(GROW,'z'):
380 case O(CREATE,'z'):
381 case O(BUILD,'z'): /* size */
382 if (size >= 0) {
383 fprintf(stderr, Name ": size may only be specified once. "
384 "Second value is %s.\n", optarg);
385 exit(2);
386 }
387 if (strcmp(optarg, "max")==0)
388 size = 0;
389 else {
390 size = parse_size(optarg);
391 if (size < 8) {
392 fprintf(stderr, Name ": invalid size: %s\n",
393 optarg);
394 exit(2);
395 }
396 /* convert sectors to K */
397 size /= 2;
398 }
399 continue;
400
401 case O(GROW,'Z'): /* array size */
402 if (array_size >= 0) {
403 fprintf(stderr, Name ": array-size may only be specified once. "
404 "Second value is %s.\n", optarg);
405 exit(2);
406 }
407 if (strcmp(optarg, "max") == 0)
408 array_size = 0;
409 else {
410 array_size = parse_size(optarg);
411 if (array_size <= 0) {
412 fprintf(stderr, Name ": invalid array size: %s\n",
413 optarg);
414 exit(2);
415 }
416 }
417 continue;
418
419 case O(GROW,'l'):
420 case O(CREATE,'l'):
421 case O(BUILD,'l'): /* set raid level*/
422 if (level != UnSet) {
423 fprintf(stderr, Name ": raid level may only be set once. "
424 "Second value is %s.\n", optarg);
425 exit(2);
426 }
427 level = map_name(pers, optarg);
428 if (level == UnSet) {
429 fprintf(stderr, Name ": invalid raid level: %s\n",
430 optarg);
431 exit(2);
432 }
433 if (level != 0 && level != LEVEL_LINEAR && level != 1 &&
434 level != LEVEL_MULTIPATH && level != LEVEL_FAULTY &&
435 level != 10 &&
436 mode == BUILD) {
437 fprintf(stderr, Name ": Raid level %s not permitted with --build.\n",
438 optarg);
439 exit(2);
440 }
441 if (sparedisks > 0 && level < 1 && level >= -1) {
442 fprintf(stderr, Name ": raid level %s is incompatible with spare-devices setting.\n",
443 optarg);
444 exit(2);
445 }
446 ident.level = level;
447 continue;
448
449 case O(GROW, 'p'): /* new layout */
450 if (layout_str) {
451 fprintf(stderr,Name ": layout may only be sent once. "
452 "Second value was %s\n", optarg);
453 exit(2);
454 }
455 layout_str = optarg;
456 /* 'Grow' will parse the value */
457 continue;
458
459 case O(CREATE,'p'): /* raid5 layout */
460 case O(BUILD,'p'): /* faulty layout */
461 if (layout != UnSet) {
462 fprintf(stderr,Name ": layout may only be sent once. "
463 "Second value was %s\n", optarg);
464 exit(2);
465 }
466 switch(level) {
467 default:
468 fprintf(stderr, Name ": layout not meaningful for %s arrays.\n",
469 map_num(pers, level));
470 exit(2);
471 case UnSet:
472 fprintf(stderr, Name ": raid level must be given before layout.\n");
473 exit(2);
474
475 case 5:
476 layout = map_name(r5layout, optarg);
477 if (layout==UnSet) {
478 fprintf(stderr, Name ": layout %s not understood for raid5.\n",
479 optarg);
480 exit(2);
481 }
482 break;
483 case 6:
484 layout = map_name(r6layout, optarg);
485 if (layout==UnSet) {
486 fprintf(stderr, Name ": layout %s not understood for raid6.\n",
487 optarg);
488 exit(2);
489 }
490 break;
491
492 case 10:
493 layout = parse_layout_10(optarg);
494 if (layout < 0) {
495 fprintf(stderr, Name ": layout for raid10 must be 'nNN', 'oNN' or 'fNN' where NN is a number, not %s\n", optarg);
496 exit(2);
497 }
498 break;
499 case LEVEL_FAULTY:
500 /* Faulty
501 * modeNNN
502 */
503 layout = parse_layout_faulty(optarg);
504 if (layout == -1) {
505 fprintf(stderr, Name ": layout %s not understood for faulty.\n",
506 optarg);
507 exit(2);
508 }
509 break;
510 }
511 continue;
512
513 case O(CREATE,AssumeClean):
514 case O(BUILD,AssumeClean): /* assume clean */
515 assume_clean = 1;
516 continue;
517
518 case O(GROW,'n'):
519 case O(CREATE,'n'):
520 case O(BUILD,'n'): /* number of raid disks */
521 if (raiddisks) {
522 fprintf(stderr, Name ": raid-devices set twice: %d and %s\n",
523 raiddisks, optarg);
524 exit(2);
525 }
526 raiddisks = strtol(optarg, &c, 10);
527 if (!optarg[0] || *c || raiddisks<=0) {
528 fprintf(stderr, Name ": invalid number of raid devices: %s\n",
529 optarg);
530 exit(2);
531 }
532 ident.raid_disks = raiddisks;
533 continue;
534
535 case O(CREATE,'x'): /* number of spare (eXtra) discs */
536 if (sparedisks) {
537 fprintf(stderr,Name ": spare-devices set twice: %d and %s\n",
538 sparedisks, optarg);
539 exit(2);
540 }
541 if (level != UnSet && level <= 0 && level >= -1) {
542 fprintf(stderr, Name ": spare-devices setting is incompatible with raid level %d\n",
543 level);
544 exit(2);
545 }
546 sparedisks = strtol(optarg, &c, 10);
547 if (!optarg[0] || *c || sparedisks < 0) {
548 fprintf(stderr, Name ": invalid number of spare-devices: %s\n",
549 optarg);
550 exit(2);
551 }
552 continue;
553
554 case O(CREATE,'a'):
555 case O(BUILD,'a'):
556 case O(INCREMENTAL,'a'):
557 case O(ASSEMBLE,'a'): /* auto-creation of device node */
558 autof = parse_auto(optarg, "--auto flag", 0);
559 continue;
560
561 case O(CREATE,Symlinks):
562 case O(BUILD,Symlinks):
563 case O(ASSEMBLE,Symlinks): /* auto creation of symlinks in /dev to /dev/md */
564 symlinks = optarg;
565 continue;
566
567 case O(BUILD,'f'): /* force honouring '-n 1' */
568 case O(GROW,'f'): /* ditto */
569 case O(CREATE,'f'): /* force honouring of device list */
570 case O(ASSEMBLE,'f'): /* force assembly */
571 case O(MISC,'f'): /* force zero */
572 force=1;
573 continue;
574
575 /* now for the Assemble options */
576 case O(CREATE,'u'): /* uuid of array */
577 case O(ASSEMBLE,'u'): /* uuid of array */
578 if (ident.uuid_set) {
579 fprintf(stderr, Name ": uuid cannot be set twice. "
580 "Second value %s.\n", optarg);
581 exit(2);
582 }
583 if (parse_uuid(optarg, ident.uuid))
584 ident.uuid_set = 1;
585 else {
586 fprintf(stderr,Name ": Bad uuid: %s\n", optarg);
587 exit(2);
588 }
589 continue;
590
591 case O(CREATE,'N'):
592 case O(ASSEMBLE,'N'):
593 if (ident.name[0]) {
594 fprintf(stderr, Name ": name cannot be set twice. "
595 "Second value %s.\n", optarg);
596 exit(2);
597 }
598 if (strlen(optarg) > 32) {
599 fprintf(stderr, Name ": name '%s' is too long, 32 chars max.\n",
600 optarg);
601 exit(2);
602 }
603 strcpy(ident.name, optarg);
604 continue;
605
606 case O(ASSEMBLE,'m'): /* super-minor for array */
607 if (ident.super_minor != UnSet) {
608 fprintf(stderr, Name ": super-minor cannot be set twice. "
609 "Second value: %s.\n", optarg);
610 exit(2);
611 }
612 if (strcmp(optarg, "dev")==0)
613 ident.super_minor = -2;
614 else {
615 ident.super_minor = strtoul(optarg, &cp, 10);
616 if (!optarg[0] || *cp) {
617 fprintf(stderr, Name ": Bad super-minor number: %s.\n", optarg);
618 exit(2);
619 }
620 }
621 continue;
622
623 case O(ASSEMBLE,'U'): /* update the superblock */
624 if (update) {
625 fprintf(stderr, Name ": Can only update one aspect of superblock, both %s and %s given.\n",
626 update, optarg);
627 exit(2);
628 }
629 update = optarg;
630 if (strcmp(update, "sparc2.2")==0)
631 continue;
632 if (strcmp(update, "super-minor") == 0)
633 continue;
634 if (strcmp(update, "summaries")==0)
635 continue;
636 if (strcmp(update, "resync")==0)
637 continue;
638 if (strcmp(update, "uuid")==0)
639 continue;
640 if (strcmp(update, "name")==0)
641 continue;
642 if (strcmp(update, "homehost")==0)
643 continue;
644 if (strcmp(update, "devicesize")==0)
645 continue;
646 if (strcmp(update, "byteorder")==0) {
647 if (ss) {
648 fprintf(stderr, Name ": must not set metadata type with --update=byteorder.\n");
649 exit(2);
650 }
651 for(i=0; !ss && superlist[i]; i++)
652 ss = superlist[i]->match_metadata_desc("0.swap");
653 if (!ss) {
654 fprintf(stderr, Name ": INTERNAL ERROR cannot find 0.swap\n");
655 exit(2);
656 }
657
658 continue;
659 }
660 if (strcmp(update,"?") == 0 ||
661 strcmp(update, "help") == 0) {
662 outf = stdout;
663 fprintf(outf, Name ": ");
664 } else {
665 outf = stderr;
666 fprintf(outf,
667 Name ": '--update=%s' is invalid. ",
668 update);
669 }
670 fprintf(outf, "Valid --update options are:\n"
671 " 'sparc2.2', 'super-minor', 'uuid', 'name', 'resync',\n"
672 " 'summaries', 'homehost', 'byteorder', 'devicesize'.\n");
673 exit(outf == stdout ? 0 : 2);
674
675 case O(INCREMENTAL,NoDegraded):
676 case O(ASSEMBLE,NoDegraded): /* --no-degraded */
677 runstop = -1; /* --stop isn't allowed for --assemble,
678 * so we overload slightly */
679 continue;
680
681 case O(ASSEMBLE,'c'): /* config file */
682 case O(INCREMENTAL, 'c'):
683 case O(MISC, 'c'):
684 case O(MONITOR,'c'):
685 if (configfile) {
686 fprintf(stderr, Name ": configfile cannot be set twice. "
687 "Second value is %s.\n", optarg);
688 exit(2);
689 }
690 configfile = optarg;
691 set_conffile(configfile);
692 /* FIXME possibly check that config file exists. Even parse it */
693 continue;
694 case O(ASSEMBLE,'s'): /* scan */
695 case O(MISC,'s'):
696 case O(MONITOR,'s'):
697 case O(INCREMENTAL,'s'):
698 scan = 1;
699 continue;
700
701 case O(MONITOR,'m'): /* mail address */
702 if (mailaddr)
703 fprintf(stderr, Name ": only specify one mailaddress. %s ignored.\n",
704 optarg);
705 else
706 mailaddr = optarg;
707 continue;
708
709 case O(MONITOR,'p'): /* alert program */
710 if (program)
711 fprintf(stderr, Name ": only specify one alter program. %s ignored.\n",
712 optarg);
713 else
714 program = optarg;
715 continue;
716
717 case O(MONITOR,'d'): /* delay in seconds */
718 case O(GROW, 'd'):
719 case O(BUILD,'d'): /* delay for bitmap updates */
720 case O(CREATE,'d'):
721 if (delay)
722 fprintf(stderr, Name ": only specify delay once. %s ignored.\n",
723 optarg);
724 else {
725 delay = strtol(optarg, &c, 10);
726 if (!optarg[0] || *c || delay<1) {
727 fprintf(stderr, Name ": invalid delay: %s\n",
728 optarg);
729 exit(2);
730 }
731 }
732 continue;
733 case O(MONITOR,'f'): /* daemonise */
734 daemonise = 1;
735 continue;
736 case O(MONITOR,'i'): /* pid */
737 if (pidfile)
738 fprintf(stderr, Name ": only specify one pid file. %s ignored.\n",
739 optarg);
740 else
741 pidfile = optarg;
742 continue;
743 case O(MONITOR,'1'): /* oneshot */
744 oneshot = 1;
745 continue;
746 case O(MONITOR,'t'): /* test */
747 test = 1;
748 continue;
749 case O(MONITOR,'y'): /* log messages to syslog */
750 openlog("mdadm", LOG_PID, SYSLOG_FACILITY);
751 dosyslog = 1;
752 continue;
753
754 /* now the general management options. Some are applicable
755 * to other modes. None have arguments.
756 */
757 case O(GROW,'a'):
758 case O(MANAGE,'a'): /* add a drive */
759 devmode = 'a';
760 re_add = 0;
761 continue;
762 case O(MANAGE,ReAdd):
763 devmode = 'a';
764 re_add = 1;
765 continue;
766 case O(MANAGE,'r'): /* remove a drive */
767 devmode = 'r';
768 continue;
769 case O(MANAGE,'f'): /* set faulty */
770 devmode = 'f';
771 continue;
772 case O(INCREMENTAL,'R'):
773 case O(MANAGE,'R'):
774 case O(ASSEMBLE,'R'):
775 case O(BUILD,'R'):
776 case O(CREATE,'R'): /* Run the array */
777 if (runstop < 0) {
778 fprintf(stderr, Name ": Cannot both Stop and Run an array\n");
779 exit(2);
780 }
781 runstop = 1;
782 continue;
783 case O(MANAGE,'S'):
784 if (runstop > 0) {
785 fprintf(stderr, Name ": Cannot both Run and Stop an array\n");
786 exit(2);
787 }
788 runstop = -1;
789 continue;
790
791 case O(MISC,'Q'):
792 case O(MISC,'D'):
793 case O(MISC,'E'):
794 case O(MISC,'K'):
795 case O(MISC,'R'):
796 case O(MISC,'S'):
797 case O(MISC,'X'):
798 case O(MISC,'o'):
799 case O(MISC,'w'):
800 case O(MISC,'W'):
801 case O(MISC, Waitclean):
802 case O(MISC, DetailPlatform):
803 if (devmode && devmode != opt &&
804 (devmode == 'E' || (opt == 'E' && devmode != 'Q'))) {
805 fprintf(stderr, Name ": --examine/-E cannot be given with -%c\n",
806 devmode =='E'?opt:devmode);
807 exit(2);
808 }
809 devmode = opt;
810 continue;
811 case O(MISC,'t'):
812 test = 1;
813 continue;
814
815 case O(MISC, Sparc22):
816 if (devmode != 'E') {
817 fprintf(stderr, Name ": --sparc2.2 only allowed with --examine\n");
818 exit(2);
819 }
820 SparcAdjust = 1;
821 continue;
822
823 case O(ASSEMBLE,'b'): /* here we simply set the bitmap file */
824 if (!optarg) {
825 fprintf(stderr, Name ": bitmap file needed with -b in --assemble mode\n");
826 exit(2);
827 }
828 if (strcmp(optarg, "internal")==0) {
829 fprintf(stderr, Name ": there is no need to specify --bitmap when assembling arrays with internal bitmaps\n");
830 continue;
831 }
832 bitmap_fd = open(optarg, O_RDWR);
833 if (!*optarg || bitmap_fd < 0) {
834 fprintf(stderr, Name ": cannot open bitmap file %s: %s\n", optarg, strerror(errno));
835 exit(2);
836 }
837 ident.bitmap_fd = bitmap_fd; /* for Assemble */
838 continue;
839
840 case O(ASSEMBLE, BackupFile):
841 case O(GROW, BackupFile):
842 /* Specify a file into which grow might place a backup,
843 * or from which assemble might recover a backup
844 */
845 if (backup_file) {
846 fprintf(stderr, Name ": backup file already specified, rejecting %s\n", optarg);
847 exit(2);
848 }
849 backup_file = optarg;
850 continue;
851
852 case O(BUILD,'b'):
853 case O(CREATE,'b'): /* here we create the bitmap */
854 if (strcmp(optarg, "none") == 0) {
855 fprintf(stderr, Name ": '--bitmap none' only"
856 " support for --grow\n");
857 exit(2);
858 }
859 /* FALL THROUGH */
860 case O(GROW,'b'):
861 if (strcmp(optarg, "internal")== 0 ||
862 strcmp(optarg, "none")== 0 ||
863 strchr(optarg, '/') != NULL) {
864 bitmap_file = optarg;
865 continue;
866 }
867 /* probable typo */
868 fprintf(stderr, Name ": bitmap file must contain a '/', or be 'internal', or 'none'\n");
869 exit(2);
870
871 case O(GROW,BitmapChunk):
872 case O(BUILD,BitmapChunk):
873 case O(CREATE,BitmapChunk): /* bitmap chunksize */
874 bitmap_chunk = strtol(optarg, &c, 10);
875 if (!optarg[0] || *c || bitmap_chunk < 0 ||
876 bitmap_chunk & (bitmap_chunk - 1)) {
877 fprintf(stderr, Name ": invalid bitmap chunksize: %s\n",
878 optarg);
879 exit(2);
880 }
881 /* convert K to B, chunk of 0K means 512B */
882 bitmap_chunk = bitmap_chunk ? bitmap_chunk * 1024 : 512;
883 continue;
884
885 case O(GROW, WriteBehind):
886 case O(BUILD, WriteBehind):
887 case O(CREATE, WriteBehind): /* write-behind mode */
888 write_behind = DEFAULT_MAX_WRITE_BEHIND;
889 if (optarg) {
890 write_behind = strtol(optarg, &c, 10);
891 if (write_behind < 0 || *c ||
892 write_behind > 16383) {
893 fprintf(stderr, Name ": Invalid value for maximum outstanding write-behind writes: %s.\n\tMust be between 0 and 16383.\n", optarg);
894 exit(2);
895 }
896 }
897 continue;
898
899 case O(INCREMENTAL, 'r'):
900 rebuild_map = 1;
901 continue;
902 }
903 /* We have now processed all the valid options. Anything else is
904 * an error
905 */
906 if (option_index > 0)
907 fprintf(stderr, Name ":option --%s not valid in %s mode\n",
908 long_options[option_index].name,
909 map_num(modes, mode));
910 else
911 fprintf(stderr, Name ": option -%c not valid in %s mode\n",
912 opt, map_num(modes, mode));
913 exit(2);
914
915 }
916
917 if (print_help) {
918 char *help_text = Help;
919 if (print_help == 2)
920 help_text = OptionHelp;
921 else
922 switch (mode) {
923 case ASSEMBLE : help_text = Help_assemble; break;
924 case BUILD : help_text = Help_build; break;
925 case CREATE : help_text = Help_create; break;
926 case MANAGE : help_text = Help_manage; break;
927 case MISC : help_text = Help_misc; break;
928 case MONITOR : help_text = Help_monitor; break;
929 case GROW : help_text = Help_grow; break;
930 case INCREMENTAL:help_text= Help_incr; break;
931 }
932 fputs(help_text,stdout);
933 exit(0);
934 }
935
936 if (!mode && devs_found) {
937 mode = MISC;
938 devmode = 'Q';
939 if (devlist->disposition == 0)
940 devlist->disposition = devmode;
941 }
942 if (!mode) {
943 fputs(Usage, stderr);
944 exit(2);
945 }
946
947 if (symlinks) {
948 struct createinfo *ci = conf_get_create_info();
949
950 if (strcasecmp(symlinks, "yes") == 0)
951 ci->symlinks = 1;
952 else if (strcasecmp(symlinks, "no") == 0)
953 ci->symlinks = 0;
954 else {
955 fprintf(stderr, Name ": option --symlinks must be 'no' or 'yes'\n");
956 exit(2);
957 }
958 }
959 /* Ok, got the option parsing out of the way
960 * hopefully it's mostly right but there might be some stuff
961 * missing
962 *
963 * That is mosty checked in the per-mode stuff but...
964 *
965 * For @,B,C and A without -s, the first device listed must be an md device
966 * we check that here and open it.
967 */
968
969 if (mode==MANAGE || mode == BUILD || mode == CREATE || mode == GROW ||
970 (mode == ASSEMBLE && ! scan)) {
971 if (devs_found < 1) {
972 fprintf(stderr, Name ": an md device must be given in this mode\n");
973 exit(2);
974 }
975 if ((int)ident.super_minor == -2 && autof) {
976 fprintf(stderr, Name ": --super-minor=dev is incompatible with --auto\n");
977 exit(2);
978 }
979 if (mode == MANAGE || mode == GROW) {
980 mdfd = open_mddev(devlist->devname, 1);
981 if (mdfd < 0)
982 exit(1);
983 } else
984 /* non-existent device is OK */
985 mdfd = open_mddev(devlist->devname, 0);
986 if (mdfd == -2) {
987 fprintf(stderr, Name ": device %s exists but is not an "
988 "md array.\n", devlist->devname);
989 exit(1);
990 }
991 if ((int)ident.super_minor == -2) {
992 struct stat stb;
993 if (mdfd < 0) {
994 fprintf(stderr, Name ": --super-minor=dev given, and "
995 "listed device %s doesn't exist.\n",
996 devlist->devname);
997 exit(1);
998 }
999 fstat(mdfd, &stb);
1000 ident.super_minor = minor(stb.st_rdev);
1001 }
1002 if (mdfd >= 0 && mode != MANAGE && mode != GROW) {
1003 /* We don't really want this open yet, we just might
1004 * have wanted to check some things
1005 */
1006 close(mdfd);
1007 mdfd = -1;
1008 }
1009 }
1010
1011 if (raiddisks) {
1012 if (raiddisks > max_disks) {
1013 fprintf(stderr, Name ": invalid number of raid devices: %d\n",
1014 raiddisks);
1015 exit(2);
1016 }
1017 if (raiddisks == 1 && !force && level != -5) {
1018 fprintf(stderr, Name ": '1' is an unusual number of drives for an array, so it is probably\n"
1019 " a mistake. If you really mean it you will need to specify --force before\n"
1020 " setting the number of drives.\n");
1021 exit(2);
1022 }
1023 }
1024 if (sparedisks) {
1025 if ( sparedisks > max_disks - raiddisks) {
1026 fprintf(stderr, Name ": invalid number of spare-devices: %d\n",
1027 sparedisks);
1028 exit(2);
1029 }
1030 }
1031
1032 if (homehost == NULL)
1033 homehost = conf_get_homehost(&require_homehost);
1034 if (homehost == NULL || strcmp(homehost, "<system>")==0) {
1035 if (gethostname(sys_hostname, sizeof(sys_hostname)) == 0) {
1036 sys_hostname[sizeof(sys_hostname)-1] = 0;
1037 homehost = sys_hostname;
1038 }
1039 }
1040
1041 ident.autof = autof;
1042
1043 rv = 0;
1044 switch(mode) {
1045 case MANAGE:
1046 /* readonly, add/remove, readwrite, runstop */
1047 if (readonly>0)
1048 rv = Manage_ro(devlist->devname, mdfd, readonly);
1049 if (!rv && devs_found>1)
1050 rv = Manage_subdevs(devlist->devname, mdfd,
1051 devlist->next, verbose-quiet);
1052 if (!rv && readonly < 0)
1053 rv = Manage_ro(devlist->devname, mdfd, readonly);
1054 if (!rv && runstop)
1055 rv = Manage_runstop(devlist->devname, mdfd, runstop, quiet);
1056 break;
1057 case ASSEMBLE:
1058 if (devs_found == 1 && ident.uuid_set == 0 &&
1059 ident.super_minor == UnSet && ident.name[0] == 0 && !scan ) {
1060 /* Only a device has been given, so get details from config file */
1061 mddev_ident_t array_ident = conf_get_ident(devlist->devname);
1062 if (array_ident == NULL) {
1063 fprintf(stderr, Name ": %s not identified in config file.\n",
1064 devlist->devname);
1065 rv |= 1;
1066 if (mdfd >= 0)
1067 close(mdfd);
1068 } else {
1069 if (array_ident->autof == 0)
1070 array_ident->autof = autof;
1071 rv |= Assemble(ss, devlist->devname, array_ident,
1072 NULL, backup_file,
1073 readonly, runstop, update,
1074 homehost, require_homehost,
1075 verbose-quiet, force);
1076 }
1077 } else if (!scan)
1078 rv = Assemble(ss, devlist->devname, &ident,
1079 devlist->next, backup_file,
1080 readonly, runstop, update,
1081 homehost, require_homehost,
1082 verbose-quiet, force);
1083 else if (devs_found>0) {
1084 if (update && devs_found > 1) {
1085 fprintf(stderr, Name ": can only update a single array at a time\n");
1086 exit(1);
1087 }
1088 if (backup_file && devs_found > 1) {
1089 fprintf(stderr, Name ": can only assemble a single array when providing a backup file.\n");
1090 exit(1);
1091 }
1092 for (dv = devlist ; dv ; dv=dv->next) {
1093 mddev_ident_t array_ident = conf_get_ident(dv->devname);
1094 if (array_ident == NULL) {
1095 fprintf(stderr, Name ": %s not identified in config file.\n",
1096 dv->devname);
1097 rv |= 1;
1098 continue;
1099 }
1100 if (array_ident->autof == 0)
1101 array_ident->autof = autof;
1102 rv |= Assemble(ss, dv->devname, array_ident,
1103 NULL, backup_file,
1104 readonly, runstop, update,
1105 homehost, require_homehost,
1106 verbose-quiet, force);
1107 }
1108 } else {
1109 mddev_ident_t array_list = conf_get_ident(NULL);
1110 mddev_dev_t devlist = conf_get_devs();
1111 int cnt = 0;
1112 if (devlist == NULL) {
1113 fprintf(stderr, Name ": No devices listed in conf file were found.\n");
1114 exit(1);
1115 }
1116 if (update) {
1117 fprintf(stderr, Name ": --update not meaningful with a --scan assembly.\n");
1118 exit(1);
1119 }
1120 if (backup_file) {
1121 fprintf(stderr, Name ": --backup_file not meaningful with a --scan assembly.\n");
1122 exit(1);
1123 }
1124 for (; array_list; array_list = array_list->next) {
1125 if (array_list->devname &&
1126 strcasecmp(array_list->devname, "<ignore>") == 0)
1127 continue;
1128 if (array_list->autof == 0)
1129 array_list->autof = autof;
1130
1131 rv |= Assemble(ss, array_list->devname,
1132 array_list,
1133 NULL, NULL,
1134 readonly, runstop, NULL,
1135 homehost, require_homehost,
1136 verbose-quiet, force);
1137 cnt++;
1138 }
1139 if (homehost && cnt == 0) {
1140 /* Maybe we can auto-assemble something.
1141 * Repeatedly call Assemble in auto-assemble mode
1142 * until it fails
1143 */
1144 int rv2;
1145 int acnt;
1146 ident.autof = autof;
1147 do {
1148 mddev_dev_t devlist = conf_get_devs();
1149 acnt = 0;
1150 do {
1151 rv2 = Assemble(ss, NULL,
1152 &ident,
1153 devlist, NULL,
1154 readonly, runstop, NULL,
1155 homehost, require_homehost,
1156 verbose-quiet, force);
1157 if (rv2==0) {
1158 cnt++;
1159 acnt++;
1160 }
1161 if (rv2 == 1)
1162 /* found something so even though assembly failed we
1163 * want to avoid auto-updates
1164 */
1165 auto_update_home = 0;
1166 } while (rv2!=2);
1167 /* Incase there are stacked devices, we need to go around again */
1168 } while (acnt);
1169 #if 0
1170 if (cnt == 0 && auto_update_home && homehost) {
1171 /* Nothing found, maybe we need to bootstrap homehost info */
1172 do {
1173 acnt = 0;
1174 do {
1175 rv2 = Assemble(ss, NULL,
1176 &ident,
1177 NULL, NULL,
1178 readonly, runstop, "homehost",
1179 homehost, require_homehost,
1180 verbose-quiet, force);
1181 if (rv2==0) {
1182 cnt++;
1183 acnt++;
1184 }
1185 } while (rv2!=2);
1186 /* Incase there are stacked devices, we need to go around again */
1187 } while (acnt);
1188 }
1189 #endif
1190 if (cnt == 0 && rv == 0) {
1191 fprintf(stderr, Name ": No arrays found in config file or automatically\n");
1192 rv = 1;
1193 } else if (cnt)
1194 rv = 0;
1195 } else if (cnt == 0 && rv == 0) {
1196 fprintf(stderr, Name ": No arrays found in config file\n");
1197 rv = 1;
1198 }
1199 }
1200 break;
1201 case BUILD:
1202 if (delay == 0) delay = DEFAULT_BITMAP_DELAY;
1203 if (write_behind && !bitmap_file) {
1204 fprintf(stderr, Name ": write-behind mode requires a bitmap.\n");
1205 rv = 1;
1206 break;
1207 }
1208 if (raiddisks == 0) {
1209 fprintf(stderr, Name ": no raid-devices specified.\n");
1210 rv = 1;
1211 break;
1212 }
1213
1214 if (bitmap_file) {
1215 if (strcmp(bitmap_file, "internal")==0) {
1216 fprintf(stderr, Name ": 'internal' bitmaps not supported with --build\n");
1217 rv |= 1;
1218 break;
1219 }
1220 }
1221 rv = Build(devlist->devname, chunk, level, layout,
1222 raiddisks, devlist->next, assume_clean,
1223 bitmap_file, bitmap_chunk, write_behind,
1224 delay, verbose-quiet, autof, size);
1225 break;
1226 case CREATE:
1227 if (delay == 0) delay = DEFAULT_BITMAP_DELAY;
1228 if (write_behind && !bitmap_file) {
1229 fprintf(stderr, Name ": write-behind mode requires a bitmap.\n");
1230 rv = 1;
1231 break;
1232 }
1233 if (raiddisks == 0) {
1234 fprintf(stderr, Name ": no raid-devices specified.\n");
1235 rv = 1;
1236 break;
1237 }
1238
1239 rv = Create(ss, devlist->devname, chunk, level, layout, size<0 ? 0 : size,
1240 raiddisks, sparedisks, ident.name, homehost,
1241 ident.uuid_set ? ident.uuid : NULL,
1242 devs_found-1, devlist->next, runstop, verbose-quiet, force, assume_clean,
1243 bitmap_file, bitmap_chunk, write_behind, delay, autof);
1244 break;
1245 case MISC:
1246 if (devmode == 'E') {
1247 if (devlist == NULL && !scan) {
1248 fprintf(stderr, Name ": No devices to examine\n");
1249 exit(2);
1250 }
1251 if (devlist == NULL)
1252 devlist = conf_get_devs();
1253 if (devlist == NULL) {
1254 fprintf(stderr, Name ": No devices listed in %s\n", configfile?configfile:DefaultConfFile);
1255 exit(1);
1256 }
1257 if (brief && verbose)
1258 brief = 2;
1259 rv = Examine(devlist, scan?(verbose>1?0:verbose+1):brief,
1260 export, scan,
1261 SparcAdjust, ss, homehost);
1262 } else if (devmode == DetailPlatform) {
1263 rv = Detail_Platform(ss ? ss->ss : NULL, ss ? scan : 1, verbose);
1264 } else {
1265 if (devlist == NULL) {
1266 if ((devmode=='D' || devmode == Waitclean) && scan) {
1267 /* apply --detail or --wait-clean to
1268 * all devices in /proc/mdstat
1269 */
1270 struct mdstat_ent *ms = mdstat_read(0, 1);
1271 struct mdstat_ent *e;
1272 struct map_ent *map = NULL;
1273 int v = verbose>1?0:verbose+1;
1274
1275 for (e=ms ; e ; e=e->next) {
1276 char *name;
1277 struct map_ent *me;
1278 me = map_by_devnum(&map, e->devnum);
1279 if (me && me->path
1280 && strcmp(me->path, "/unknown") != 0)
1281 name = me->path;
1282 else
1283 name = get_md_name(e->devnum);
1284
1285 if (!name) {
1286 fprintf(stderr, Name ": cannot find device file for %s\n",
1287 e->dev);
1288 continue;
1289 }
1290 if (devmode == 'D')
1291 rv |= Detail(name, v,
1292 export, test,
1293 homehost);
1294 else
1295 rv |= WaitClean(name, v);
1296 put_md_name(name);
1297 }
1298 free_mdstat(ms);
1299 } else if (devmode == 'S' && scan) {
1300 /* apply --stop to all devices in /proc/mdstat */
1301 /* Due to possible stacking of devices, repeat until
1302 * nothing more can be stopped
1303 */
1304 int progress=1, err;
1305 int last = 0;
1306 do {
1307 struct mdstat_ent *ms = mdstat_read(0, 0);
1308 struct mdstat_ent *e;
1309
1310 if (!progress) last = 1;
1311 progress = 0; err = 0;
1312 for (e=ms ; e ; e=e->next) {
1313 char *name = get_md_name(e->devnum);
1314
1315 if (!name) {
1316 fprintf(stderr, Name ": cannot find device file for %s\n",
1317 e->dev);
1318 continue;
1319 }
1320 mdfd = open_mddev(name, 1);
1321 if (mdfd >= 0) {
1322 if (Manage_runstop(name, mdfd, -1, quiet?1:last?0:-1))
1323 err = 1;
1324 else
1325 progress = 1;
1326 close(mdfd);
1327 }
1328
1329 put_md_name(name);
1330 }
1331 free_mdstat(ms);
1332 } while (!last && err);
1333 if (err) rv |= 1;
1334 } else {
1335 fprintf(stderr, Name ": No devices given.\n");
1336 exit(2);
1337 }
1338 }
1339 for (dv=devlist ; dv; dv=dv->next) {
1340 switch(dv->disposition) {
1341 case 'D':
1342 rv |= Detail(dv->devname,
1343 brief?1+verbose:0,
1344 export, test, homehost);
1345 continue;
1346 case 'K': /* Zero superblock */
1347 rv |= Kill(dv->devname, force, quiet,0);
1348 continue;
1349 case 'Q':
1350 rv |= Query(dv->devname); continue;
1351 case 'X':
1352 rv |= ExamineBitmap(dv->devname, brief, ss); continue;
1353 case 'W':
1354 rv |= Wait(dv->devname); continue;
1355 case Waitclean:
1356 rv |= WaitClean(dv->devname, verbose-quiet); continue;
1357 }
1358 mdfd = open_mddev(dv->devname, 1);
1359 if (mdfd>=0) {
1360 switch(dv->disposition) {
1361 case 'R':
1362 rv |= Manage_runstop(dv->devname, mdfd, 1, quiet); break;
1363 case 'S':
1364 rv |= Manage_runstop(dv->devname, mdfd, -1, quiet); break;
1365 case 'o':
1366 rv |= Manage_ro(dv->devname, mdfd, 1); break;
1367 case 'w':
1368 rv |= Manage_ro(dv->devname, mdfd, -1); break;
1369 }
1370 close(mdfd);
1371 } else
1372 rv |= 1;
1373 }
1374 }
1375 break;
1376 case MONITOR:
1377 if (!devlist && !scan) {
1378 fprintf(stderr, Name ": Cannot monitor: need --scan or at least one device\n");
1379 rv = 1;
1380 break;
1381 }
1382 if (pidfile && !daemonise) {
1383 fprintf(stderr, Name ": Cannot write a pid file when not in daemon mode\n");
1384 rv = 1;
1385 break;
1386 }
1387 if (delay == 0) {
1388 if (get_linux_version() > 20616)
1389 /* mdstat responds to poll */
1390 delay = 1000;
1391 else
1392 delay = 60;
1393 }
1394 rv= Monitor(devlist, mailaddr, program,
1395 delay?delay:60, daemonise, scan, oneshot,
1396 dosyslog, test, pidfile);
1397 break;
1398
1399 case GROW:
1400 if (array_size >= 0) {
1401 /* alway impose array size first, independent of
1402 * anything else
1403 */
1404 struct mdinfo sra;
1405 int err;
1406 sysfs_init(&sra, mdfd, 0);
1407 if (array_size == 0)
1408 err = sysfs_set_str(&sra, NULL, "array_size", "default");
1409 else
1410 err = sysfs_set_num(&sra, NULL, "array_size", array_size / 2);
1411 if (err < 0) {
1412 if (errno == E2BIG)
1413 fprintf(stderr, Name ": --array-size setting"
1414 " is too large.\n");
1415 else
1416 fprintf(stderr, Name ": current kernel does"
1417 " not support setting --array-size\n");
1418 rv = 1;
1419 break;
1420 }
1421 }
1422 if (devs_found > 1) {
1423
1424 /* must be '-a'. */
1425 if (size >= 0 || raiddisks || chunk || layout_str != NULL || bitmap_file) {
1426 fprintf(stderr, Name ": --add cannot be used with other geometry changes in --grow mode\n");
1427 rv = 1;
1428 break;
1429 }
1430 for (dv=devlist->next; dv ; dv=dv->next) {
1431 rv = Grow_Add_device(devlist->devname, mdfd, dv->devname);
1432 if (rv)
1433 break;
1434 }
1435 } else if (bitmap_file) {
1436 if (size >= 0 || raiddisks || chunk || layout_str != NULL) {
1437 fprintf(stderr, Name ": --bitmap changes cannot be used with other geometry changes in --grow mode\n");
1438 rv = 1;
1439 break;
1440 }
1441 if (delay == 0)
1442 delay = DEFAULT_BITMAP_DELAY;
1443 rv = Grow_addbitmap(devlist->devname, mdfd, bitmap_file,
1444 bitmap_chunk, delay, write_behind, force);
1445 } else if (size >= 0 || raiddisks != 0 || layout_str != NULL
1446 || chunk != 0 || level != UnSet) {
1447 rv = Grow_reshape(devlist->devname, mdfd, quiet, backup_file,
1448 size, level, layout_str, chunk, raiddisks);
1449 } else if (array_size < 0)
1450 fprintf(stderr, Name ": no changes to --grow\n");
1451 break;
1452 case INCREMENTAL:
1453 if (rebuild_map) {
1454 RebuildMap();
1455 }
1456 if (scan) {
1457 if (runstop <= 0) {
1458 fprintf(stderr, Name
1459 ": --incremental --scan meaningless without --run.\n");
1460 break;
1461 }
1462 rv = IncrementalScan(verbose);
1463 }
1464 if (!devlist) {
1465 if (!rebuild_map && !scan) {
1466 fprintf(stderr, Name
1467 ": --incremental requires a device.\n");
1468 rv = 1;
1469 }
1470 break;
1471 }
1472 if (devlist->next) {
1473 fprintf(stderr, Name
1474 ": --incremental can only handle one device.\n");
1475 rv = 1;
1476 break;
1477 }
1478 rv = Incremental(devlist->devname, verbose-quiet, runstop,
1479 ss, homehost, require_homehost, autof);
1480 break;
1481 case AUTODETECT:
1482 autodetect();
1483 break;
1484 }
1485 exit(rv);
1486 }