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