]> git.ipfire.org Git - thirdparty/mdadm.git/blob - mdadm.c
Detail: list containers before members.
[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 int level = UnSet;
45 int layout = UnSet;
46 int raiddisks = 0;
47 int max_disks = MD_SB_DISKS; /* just a default */
48 int sparedisks = 0;
49 struct mddev_ident_s ident;
50 char *configfile = NULL;
51 char *cp;
52 char *update = NULL;
53 int scan = 0;
54 char devmode = 0;
55 int runstop = 0;
56 int readonly = 0;
57 int write_behind = 0;
58 int bitmap_fd = -1;
59 char *bitmap_file = NULL;
60 char *backup_file = NULL;
61 int bitmap_chunk = UnSet;
62 int SparcAdjust = 0;
63 mddev_dev_t devlist = NULL;
64 mddev_dev_t *devlistend = & devlist;
65 mddev_dev_t dv;
66 int devs_found = 0;
67 int verbose = 0;
68 int quiet = 0;
69 int brief = 0;
70 int force = 0;
71 int test = 0;
72 int export = 0;
73 int assume_clean = 0;
74 char *symlinks = NULL;
75 /* autof indicates whether and how to create device node.
76 * bottom 3 bits are style. Rest (when shifted) are number of parts
77 * 0 - unset
78 * 1 - don't create (no)
79 * 2 - if is_standard, then create (yes)
80 * 3 - create as 'md' - reject is_standard mdp (md)
81 * 4 - create as 'mdp' - reject is_standard md (mdp)
82 * 5 - default to md if not is_standard (md in config file)
83 * 6 - default to mdp if not is_standard (part, or mdp in config file)
84 */
85 int autof = 0;
86
87 char *homehost = NULL;
88 char sys_hostname[256];
89 int require_homehost = 1;
90 char *mailaddr = NULL;
91 char *program = NULL;
92 int increments = 20;
93 int delay = 0;
94 int daemonise = 0;
95 char *pidfile = NULL;
96 int oneshot = 0;
97 struct supertype *ss = NULL;
98 int writemostly = 0;
99 int re_add = 0;
100 char *shortopt = short_options;
101 int dosyslog = 0;
102 int rebuild_map = 0;
103 int auto_update_home = 0;
104
105 int copies;
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(CREATE,'c'):
328 case O(BUILD,'c'): /* chunk or rounding */
329 if (chunk) {
330 fprintf(stderr, Name ": chunk/rounding may only be specified once. "
331 "Second value is %s.\n", optarg);
332 exit(2);
333 }
334 chunk = strtol(optarg, &c, 10);
335 if (!optarg[0] || *c || chunk<4 || ((chunk-1)&chunk)) {
336 fprintf(stderr, Name ": invalid chunk/rounding value: %s\n",
337 optarg);
338 exit(2);
339 }
340 continue;
341
342 #if 0
343 case O(ASSEMBLE,AutoHomeHost):
344 auto_update_home = 1;
345 continue;
346 #endif
347 case O(INCREMENTAL, 'e'):
348 case O(CREATE,'e'):
349 case O(ASSEMBLE,'e'):
350 case O(MISC,'e'): /* set metadata (superblock) information */
351 if (ss) {
352 fprintf(stderr, Name ": metadata information already given\n");
353 exit(2);
354 }
355 for(i=0; !ss && superlist[i]; i++)
356 ss = superlist[i]->match_metadata_desc(optarg);
357
358 if (!ss) {
359 fprintf(stderr, Name ": unrecognised metadata identifier: %s\n", optarg);
360 exit(2);
361 }
362 max_disks = ss->max_devs;
363 continue;
364
365 case O(MANAGE,'W'):
366 case O(BUILD,'W'):
367 case O(CREATE,'W'):
368 /* set write-mostly for following devices */
369 writemostly = 1;
370 continue;
371
372 case O(MANAGE,'w'):
373 /* clear write-mostly for following devices */
374 writemostly = 2;
375 continue;
376
377
378 case O(GROW,'z'):
379 case O(CREATE,'z'):
380 case O(BUILD,'z'): /* size */
381 if (size >= 0) {
382 fprintf(stderr, Name ": size may only be specified once. "
383 "Second value is %s.\n", optarg);
384 exit(2);
385 }
386 if (strcmp(optarg, "max")==0)
387 size = 0;
388 else {
389 size = strtoll(optarg, &c, 10);
390 if (!optarg[0] || *c || size < 4) {
391 fprintf(stderr, Name ": invalid size: %s\n",
392 optarg);
393 exit(2);
394 }
395 }
396 continue;
397
398 case O(GROW,'l'): /* hack - needed to understand layout */
399 case O(CREATE,'l'):
400 case O(BUILD,'l'): /* set raid level*/
401 if (level != UnSet) {
402 fprintf(stderr, Name ": raid level may only be set once. "
403 "Second value is %s.\n", optarg);
404 exit(2);
405 }
406 level = map_name(pers, optarg);
407 if (level == UnSet) {
408 fprintf(stderr, Name ": invalid raid level: %s\n",
409 optarg);
410 exit(2);
411 }
412 if (level != 0 && level != LEVEL_LINEAR && level != 1 &&
413 level != LEVEL_MULTIPATH && level != LEVEL_FAULTY &&
414 level != 10 &&
415 mode == BUILD) {
416 fprintf(stderr, Name ": Raid level %s not permitted with --build.\n",
417 optarg);
418 exit(2);
419 }
420 if (sparedisks > 0 && level < 1 && level >= -1) {
421 fprintf(stderr, Name ": raid level %s is incompatible with spare-devices setting.\n",
422 optarg);
423 exit(2);
424 }
425 ident.level = level;
426 continue;
427
428 case O(CREATE,'p'): /* raid5 layout */
429 case O(BUILD,'p'): /* faulty layout */
430 case O(GROW, 'p'): /* faulty reconfig */
431 if (layout != UnSet) {
432 fprintf(stderr,Name ": layout may only be sent once. "
433 "Second value was %s\n", optarg);
434 exit(2);
435 }
436 switch(level) {
437 default:
438 fprintf(stderr, Name ": layout not meaningful for %s arrays.\n",
439 map_num(pers, level));
440 exit(2);
441 case UnSet:
442 fprintf(stderr, Name ": raid level must be given before layout.\n");
443 exit(2);
444
445 case 5:
446 layout = map_name(r5layout, optarg);
447 if (layout==UnSet) {
448 fprintf(stderr, Name ": layout %s not understood for raid5.\n",
449 optarg);
450 exit(2);
451 }
452 break;
453 case 6:
454 layout = map_name(r6layout, optarg);
455 if (layout==UnSet) {
456 fprintf(stderr, Name ": layout %s not understood for raid6.\n",
457 optarg);
458 exit(2);
459 }
460 break;
461
462 case 10:
463 /* 'f', 'o' or 'n' followed by a number <= raid_disks */
464 if ((optarg[0] != 'n' && optarg[0] != 'f' && optarg[0] != 'o') ||
465 (copies = strtoul(optarg+1, &cp, 10)) < 1 ||
466 copies > 200 ||
467 *cp) {
468 fprintf(stderr, Name ": layout for raid10 must be 'nNN', 'oNN' or 'fNN' where NN is a number, not %s\n", optarg);
469 exit(2);
470 }
471 if (optarg[0] == 'n')
472 layout = 256 + copies;
473 else if (optarg[0] == 'o')
474 layout = 0x10000 + (copies<<8) + 1;
475 else
476 layout = 1 + (copies<<8);
477 break;
478 case -5: /* Faulty
479 * modeNNN
480 */
481
482 {
483 int ln = strcspn(optarg, "0123456789");
484 char *m = strdup(optarg);
485 int mode;
486 m[ln] = 0;
487 mode = map_name(faultylayout, m);
488 if (mode == UnSet) {
489 fprintf(stderr, Name ": layout %s not understood for faulty.\n",
490 optarg);
491 exit(2);
492 }
493 layout = mode | (atoi(optarg+ln)<< ModeShift);
494 }
495 }
496 continue;
497
498 case O(CREATE,AssumeClean):
499 case O(BUILD,AssumeClean): /* assume clean */
500 assume_clean = 1;
501 continue;
502
503 case O(GROW,'n'):
504 case O(CREATE,'n'):
505 case O(BUILD,'n'): /* number of raid disks */
506 if (raiddisks) {
507 fprintf(stderr, Name ": raid-devices set twice: %d and %s\n",
508 raiddisks, optarg);
509 exit(2);
510 }
511 raiddisks = strtol(optarg, &c, 10);
512 if (!optarg[0] || *c || raiddisks<=0) {
513 fprintf(stderr, Name ": invalid number of raid devices: %s\n",
514 optarg);
515 exit(2);
516 }
517 ident.raid_disks = raiddisks;
518 continue;
519
520 case O(CREATE,'x'): /* number of spare (eXtra) discs */
521 if (sparedisks) {
522 fprintf(stderr,Name ": spare-devices set twice: %d and %s\n",
523 sparedisks, optarg);
524 exit(2);
525 }
526 if (level != UnSet && level <= 0 && level >= -1) {
527 fprintf(stderr, Name ": spare-devices setting is incompatible with raid level %d\n",
528 level);
529 exit(2);
530 }
531 sparedisks = strtol(optarg, &c, 10);
532 if (!optarg[0] || *c || sparedisks < 0) {
533 fprintf(stderr, Name ": invalid number of spare-devices: %s\n",
534 optarg);
535 exit(2);
536 }
537 continue;
538
539 case O(CREATE,'a'):
540 case O(BUILD,'a'):
541 case O(INCREMENTAL,'a'):
542 case O(ASSEMBLE,'a'): /* auto-creation of device node */
543 autof = parse_auto(optarg, "--auto flag", 0);
544 continue;
545
546 case O(CREATE,Symlinks):
547 case O(BUILD,Symlinks):
548 case O(ASSEMBLE,Symlinks): /* auto creation of symlinks in /dev to /dev/md */
549 symlinks = optarg;
550 continue;
551
552 case O(BUILD,'f'): /* force honouring '-n 1' */
553 case O(GROW,'f'): /* ditto */
554 case O(CREATE,'f'): /* force honouring of device list */
555 case O(ASSEMBLE,'f'): /* force assembly */
556 case O(MISC,'f'): /* force zero */
557 force=1;
558 continue;
559
560 /* now for the Assemble options */
561 case O(CREATE,'u'): /* uuid of array */
562 case O(ASSEMBLE,'u'): /* uuid of array */
563 if (ident.uuid_set) {
564 fprintf(stderr, Name ": uuid cannot be set twice. "
565 "Second value %s.\n", optarg);
566 exit(2);
567 }
568 if (parse_uuid(optarg, ident.uuid))
569 ident.uuid_set = 1;
570 else {
571 fprintf(stderr,Name ": Bad uuid: %s\n", optarg);
572 exit(2);
573 }
574 continue;
575
576 case O(CREATE,'N'):
577 case O(ASSEMBLE,'N'):
578 if (ident.name[0]) {
579 fprintf(stderr, Name ": name cannot be set twice. "
580 "Second value %s.\n", optarg);
581 exit(2);
582 }
583 if (strlen(optarg) > 32) {
584 fprintf(stderr, Name ": name '%s' is too long, 32 chars max.\n",
585 optarg);
586 exit(2);
587 }
588 strcpy(ident.name, optarg);
589 continue;
590
591 case O(ASSEMBLE,'m'): /* super-minor for array */
592 if (ident.super_minor != UnSet) {
593 fprintf(stderr, Name ": super-minor cannot be set twice. "
594 "Second value: %s.\n", optarg);
595 exit(2);
596 }
597 if (strcmp(optarg, "dev")==0)
598 ident.super_minor = -2;
599 else {
600 ident.super_minor = strtoul(optarg, &cp, 10);
601 if (!optarg[0] || *cp) {
602 fprintf(stderr, Name ": Bad super-minor number: %s.\n", optarg);
603 exit(2);
604 }
605 }
606 continue;
607
608 case O(ASSEMBLE,'U'): /* update the superblock */
609 if (update) {
610 fprintf(stderr, Name ": Can only update one aspect of superblock, both %s and %s given.\n",
611 update, optarg);
612 exit(2);
613 }
614 update = optarg;
615 if (strcmp(update, "sparc2.2")==0)
616 continue;
617 if (strcmp(update, "super-minor") == 0)
618 continue;
619 if (strcmp(update, "summaries")==0)
620 continue;
621 if (strcmp(update, "resync")==0)
622 continue;
623 if (strcmp(update, "uuid")==0)
624 continue;
625 if (strcmp(update, "name")==0)
626 continue;
627 if (strcmp(update, "homehost")==0)
628 continue;
629 if (strcmp(update, "devicesize")==0)
630 continue;
631 if (strcmp(update, "byteorder")==0) {
632 if (ss) {
633 fprintf(stderr, Name ": must not set metadata type with --update=byteorder.\n");
634 exit(2);
635 }
636 for(i=0; !ss && superlist[i]; i++)
637 ss = superlist[i]->match_metadata_desc("0.swap");
638 if (!ss) {
639 fprintf(stderr, Name ": INTERNAL ERROR cannot find 0.swap\n");
640 exit(2);
641 }
642
643 continue;
644 }
645 if (strcmp(update,"?") == 0 ||
646 strcmp(update, "help") == 0) {
647 outf = stdout;
648 fprintf(outf, Name ": ");
649 } else {
650 outf = stderr;
651 fprintf(outf,
652 Name ": '--update=%s' is invalid. ",
653 update);
654 }
655 fprintf(outf, "Valid --update options are:\n"
656 " 'sparc2.2', 'super-minor', 'uuid', 'name', 'resync',\n"
657 " 'summaries', 'homehost', 'byteorder', 'devicesize'.\n");
658 exit(outf == stdout ? 0 : 2);
659
660 case O(INCREMENTAL,NoDegraded):
661 case O(ASSEMBLE,NoDegraded): /* --no-degraded */
662 runstop = -1; /* --stop isn't allowed for --assemble,
663 * so we overload slightly */
664 continue;
665
666 case O(ASSEMBLE,'c'): /* config file */
667 case O(INCREMENTAL, 'c'):
668 case O(MISC, 'c'):
669 case O(MONITOR,'c'):
670 if (configfile) {
671 fprintf(stderr, Name ": configfile cannot be set twice. "
672 "Second value is %s.\n", optarg);
673 exit(2);
674 }
675 configfile = optarg;
676 set_conffile(configfile);
677 /* FIXME possibly check that config file exists. Even parse it */
678 continue;
679 case O(ASSEMBLE,'s'): /* scan */
680 case O(MISC,'s'):
681 case O(MONITOR,'s'):
682 case O(INCREMENTAL,'s'):
683 scan = 1;
684 continue;
685
686 case O(MONITOR,'m'): /* mail address */
687 if (mailaddr)
688 fprintf(stderr, Name ": only specify one mailaddress. %s ignored.\n",
689 optarg);
690 else
691 mailaddr = optarg;
692 continue;
693
694 case O(MONITOR,'p'): /* alert program */
695 if (program)
696 fprintf(stderr, Name ": only specify one alter program. %s ignored.\n",
697 optarg);
698 else
699 program = optarg;
700 continue;
701
702 case O(MONITOR,'r'): /* rebuild increments */
703 increments = atoi(optarg);
704 if (increments>99 || increments<1) {
705 fprintf(stderr, Name ": please specify positive integer between 1 and 99 as rebuild increments.\n");
706 exit(2);
707 }
708 continue;
709
710 case O(MONITOR,'d'): /* delay in seconds */
711 case O(GROW, 'd'):
712 case O(BUILD,'d'): /* delay for bitmap updates */
713 case O(CREATE,'d'):
714 if (delay)
715 fprintf(stderr, Name ": only specify delay once. %s ignored.\n",
716 optarg);
717 else {
718 delay = strtol(optarg, &c, 10);
719 if (!optarg[0] || *c || delay<1) {
720 fprintf(stderr, Name ": invalid delay: %s\n",
721 optarg);
722 exit(2);
723 }
724 }
725 continue;
726 case O(MONITOR,'f'): /* daemonise */
727 daemonise = 1;
728 continue;
729 case O(MONITOR,'i'): /* pid */
730 if (pidfile)
731 fprintf(stderr, Name ": only specify one pid file. %s ignored.\n",
732 optarg);
733 else
734 pidfile = optarg;
735 continue;
736 case O(MONITOR,'1'): /* oneshot */
737 oneshot = 1;
738 continue;
739 case O(MONITOR,'t'): /* test */
740 test = 1;
741 continue;
742 case O(MONITOR,'y'): /* log messages to syslog */
743 openlog("mdadm", LOG_PID, SYSLOG_FACILITY);
744 dosyslog = 1;
745 continue;
746
747 /* now the general management options. Some are applicable
748 * to other modes. None have arguments.
749 */
750 case O(GROW,'a'):
751 case O(MANAGE,'a'): /* add a drive */
752 devmode = 'a';
753 re_add = 0;
754 continue;
755 case O(MANAGE,ReAdd):
756 devmode = 'a';
757 re_add = 1;
758 continue;
759 case O(MANAGE,'r'): /* remove a drive */
760 devmode = 'r';
761 continue;
762 case O(MANAGE,'f'): /* set faulty */
763 devmode = 'f';
764 continue;
765 case O(INCREMENTAL,'R'):
766 case O(MANAGE,'R'):
767 case O(ASSEMBLE,'R'):
768 case O(BUILD,'R'):
769 case O(CREATE,'R'): /* Run the array */
770 if (runstop < 0) {
771 fprintf(stderr, Name ": Cannot both Stop and Run an array\n");
772 exit(2);
773 }
774 runstop = 1;
775 continue;
776 case O(MANAGE,'S'):
777 if (runstop > 0) {
778 fprintf(stderr, Name ": Cannot both Run and Stop an array\n");
779 exit(2);
780 }
781 runstop = -1;
782 continue;
783
784 case O(MISC,'Q'):
785 case O(MISC,'D'):
786 case O(MISC,'E'):
787 case O(MISC,'K'):
788 case O(MISC,'R'):
789 case O(MISC,'S'):
790 case O(MISC,'X'):
791 case O(MISC,'o'):
792 case O(MISC,'w'):
793 case O(MISC,'W'):
794 case O(MISC, Waitclean):
795 case O(MISC, DetailPlatform):
796 if (devmode && devmode != opt &&
797 (devmode == 'E' || (opt == 'E' && devmode != 'Q'))) {
798 fprintf(stderr, Name ": --examine/-E cannot be given with -%c\n",
799 devmode =='E'?opt:devmode);
800 exit(2);
801 }
802 devmode = opt;
803 continue;
804 case O(MISC,'t'):
805 test = 1;
806 continue;
807
808 case O(MISC, Sparc22):
809 if (devmode != 'E') {
810 fprintf(stderr, Name ": --sparc2.2 only allowed with --examine\n");
811 exit(2);
812 }
813 SparcAdjust = 1;
814 continue;
815
816 case O(ASSEMBLE,'b'): /* here we simply set the bitmap file */
817 if (!optarg) {
818 fprintf(stderr, Name ": bitmap file needed with -b in --assemble mode\n");
819 exit(2);
820 }
821 if (strcmp(optarg, "internal")==0) {
822 fprintf(stderr, Name ": there is no need to specify --bitmap when assembling arrays with internal bitmaps\n");
823 continue;
824 }
825 bitmap_fd = open(optarg, O_RDWR);
826 if (!*optarg || bitmap_fd < 0) {
827 fprintf(stderr, Name ": cannot open bitmap file %s: %s\n", optarg, strerror(errno));
828 exit(2);
829 }
830 ident.bitmap_fd = bitmap_fd; /* for Assemble */
831 continue;
832
833 case O(ASSEMBLE, BackupFile):
834 case O(GROW, BackupFile):
835 /* Specify a file into which grow might place a backup,
836 * or from which assemble might recover a backup
837 */
838 if (backup_file) {
839 fprintf(stderr, Name ": backup file already specified, rejecting %s\n", optarg);
840 exit(2);
841 }
842 backup_file = optarg;
843 continue;
844
845 case O(BUILD,'b'):
846 case O(CREATE,'b'): /* here we create the bitmap */
847 if (strcmp(optarg, "none") == 0) {
848 fprintf(stderr, Name ": '--bitmap none' only"
849 " support for --grow\n");
850 exit(2);
851 }
852 /* FALL THROUGH */
853 case O(GROW,'b'):
854 if (strcmp(optarg, "internal")== 0 ||
855 strcmp(optarg, "none")== 0 ||
856 strchr(optarg, '/') != NULL) {
857 bitmap_file = optarg;
858 continue;
859 }
860 /* probable typo */
861 fprintf(stderr, Name ": bitmap file must contain a '/', or be 'internal', or 'none'\n");
862 exit(2);
863
864 case O(GROW,BitmapChunk):
865 case O(BUILD,BitmapChunk):
866 case O(CREATE,BitmapChunk): /* bitmap chunksize */
867 bitmap_chunk = strtol(optarg, &c, 10);
868 if (!optarg[0] || *c || bitmap_chunk < 0 ||
869 bitmap_chunk & (bitmap_chunk - 1)) {
870 fprintf(stderr, Name ": invalid bitmap chunksize: %s\n",
871 optarg);
872 exit(2);
873 }
874 /* convert K to B, chunk of 0K means 512B */
875 bitmap_chunk = bitmap_chunk ? bitmap_chunk * 1024 : 512;
876 continue;
877
878 case O(GROW, WriteBehind):
879 case O(BUILD, WriteBehind):
880 case O(CREATE, WriteBehind): /* write-behind mode */
881 write_behind = DEFAULT_MAX_WRITE_BEHIND;
882 if (optarg) {
883 write_behind = strtol(optarg, &c, 10);
884 if (write_behind < 0 || *c ||
885 write_behind > 16383) {
886 fprintf(stderr, Name ": Invalid value for maximum outstanding write-behind writes: %s.\n\tMust be between 0 and 16383.\n", optarg);
887 exit(2);
888 }
889 }
890 continue;
891
892 case O(INCREMENTAL, 'r'):
893 rebuild_map = 1;
894 continue;
895 }
896 /* We have now processed all the valid options. Anything else is
897 * an error
898 */
899 if (option_index > 0)
900 fprintf(stderr, Name ":option --%s not valid in %s mode\n",
901 long_options[option_index].name,
902 map_num(modes, mode));
903 else
904 fprintf(stderr, Name ": option -%c not valid in %s mode\n",
905 opt, map_num(modes, mode));
906 exit(2);
907
908 }
909
910 if (print_help) {
911 char *help_text = Help;
912 if (print_help == 2)
913 help_text = OptionHelp;
914 else
915 switch (mode) {
916 case ASSEMBLE : help_text = Help_assemble; break;
917 case BUILD : help_text = Help_build; break;
918 case CREATE : help_text = Help_create; break;
919 case MANAGE : help_text = Help_manage; break;
920 case MISC : help_text = Help_misc; break;
921 case MONITOR : help_text = Help_monitor; break;
922 case GROW : help_text = Help_grow; break;
923 case INCREMENTAL:help_text= Help_incr; break;
924 }
925 fputs(help_text,stdout);
926 exit(0);
927 }
928
929 if (!mode && devs_found) {
930 mode = MISC;
931 devmode = 'Q';
932 if (devlist->disposition == 0)
933 devlist->disposition = devmode;
934 }
935 if (!mode) {
936 fputs(Usage, stderr);
937 exit(2);
938 }
939
940 if (symlinks) {
941 struct createinfo *ci = conf_get_create_info();
942
943 if (strcasecmp(symlinks, "yes") == 0)
944 ci->symlinks = 1;
945 else if (strcasecmp(symlinks, "no") == 0)
946 ci->symlinks = 0;
947 else {
948 fprintf(stderr, Name ": option --symlinks must be 'no' or 'yes'\n");
949 exit(2);
950 }
951 }
952 /* Ok, got the option parsing out of the way
953 * hopefully it's mostly right but there might be some stuff
954 * missing
955 *
956 * That is mosty checked in the per-mode stuff but...
957 *
958 * For @,B,C and A without -s, the first device listed must be an md device
959 * we check that here and open it.
960 */
961
962 if (mode==MANAGE || mode == BUILD || mode == CREATE || mode == GROW ||
963 (mode == ASSEMBLE && ! scan)) {
964 if (devs_found < 1) {
965 fprintf(stderr, Name ": an md device must be given in this mode\n");
966 exit(2);
967 }
968 if ((int)ident.super_minor == -2 && autof) {
969 fprintf(stderr, Name ": --super-minor=dev is incompatible with --auto\n");
970 exit(2);
971 }
972 if (mode == MANAGE || mode == GROW) {
973 mdfd = open_mddev(devlist->devname, 1);
974 if (mdfd < 0)
975 exit(1);
976 } else
977 /* non-existent device is OK */
978 mdfd = open_mddev(devlist->devname, 0);
979 if (mdfd == -2) {
980 fprintf(stderr, Name ": device %s exists but is not an "
981 "md array.\n", devlist->devname);
982 exit(1);
983 }
984 if ((int)ident.super_minor == -2) {
985 struct stat stb;
986 if (mdfd < 0) {
987 fprintf(stderr, Name ": --super-minor=dev given, and "
988 "listed device %s doesn't exist.\n",
989 devlist->devname);
990 exit(1);
991 }
992 fstat(mdfd, &stb);
993 ident.super_minor = minor(stb.st_rdev);
994 }
995 if (mdfd >= 0 && mode != MANAGE && mode != GROW) {
996 /* We don't really want this open yet, we just might
997 * have wanted to check some things
998 */
999 close(mdfd);
1000 mdfd = -1;
1001 }
1002 }
1003
1004 if (raiddisks) {
1005 if (raiddisks > max_disks) {
1006 fprintf(stderr, Name ": invalid number of raid devices: %d\n",
1007 raiddisks);
1008 exit(2);
1009 }
1010 if (raiddisks == 1 && !force && level != -5) {
1011 fprintf(stderr, Name ": '1' is an unusual number of drives for an array, so it is probably\n"
1012 " a mistake. If you really mean it you will need to specify --force before\n"
1013 " setting the number of drives.\n");
1014 exit(2);
1015 }
1016 }
1017 if (sparedisks) {
1018 if ( sparedisks > max_disks - raiddisks) {
1019 fprintf(stderr, Name ": invalid number of spare-devices: %d\n",
1020 sparedisks);
1021 exit(2);
1022 }
1023 }
1024
1025 if (homehost == NULL)
1026 homehost = conf_get_homehost(&require_homehost);
1027 if (homehost == NULL || strcmp(homehost, "<system>")==0) {
1028 if (gethostname(sys_hostname, sizeof(sys_hostname)) == 0) {
1029 sys_hostname[sizeof(sys_hostname)-1] = 0;
1030 homehost = sys_hostname;
1031 }
1032 }
1033
1034 ident.autof = autof;
1035
1036 rv = 0;
1037 switch(mode) {
1038 case MANAGE:
1039 /* readonly, add/remove, readwrite, runstop */
1040 if (readonly>0)
1041 rv = Manage_ro(devlist->devname, mdfd, readonly);
1042 if (!rv && devs_found>1)
1043 rv = Manage_subdevs(devlist->devname, mdfd,
1044 devlist->next, verbose-quiet);
1045 if (!rv && readonly < 0)
1046 rv = Manage_ro(devlist->devname, mdfd, readonly);
1047 if (!rv && runstop)
1048 rv = Manage_runstop(devlist->devname, mdfd, runstop, quiet);
1049 break;
1050 case ASSEMBLE:
1051 if (devs_found == 1 && ident.uuid_set == 0 &&
1052 ident.super_minor == UnSet && ident.name[0] == 0 && !scan ) {
1053 /* Only a device has been given, so get details from config file */
1054 mddev_ident_t array_ident = conf_get_ident(devlist->devname);
1055 if (array_ident == NULL) {
1056 fprintf(stderr, Name ": %s not identified in config file.\n",
1057 devlist->devname);
1058 rv |= 1;
1059 if (mdfd >= 0)
1060 close(mdfd);
1061 } else {
1062 if (array_ident->autof == 0)
1063 array_ident->autof = autof;
1064 rv |= Assemble(ss, devlist->devname, array_ident,
1065 NULL, backup_file,
1066 readonly, runstop, update,
1067 homehost, require_homehost,
1068 verbose-quiet, force);
1069 }
1070 } else if (!scan)
1071 rv = Assemble(ss, devlist->devname, &ident,
1072 devlist->next, backup_file,
1073 readonly, runstop, update,
1074 homehost, require_homehost,
1075 verbose-quiet, force);
1076 else if (devs_found>0) {
1077 if (update && devs_found > 1) {
1078 fprintf(stderr, Name ": can only update a single array at a time\n");
1079 exit(1);
1080 }
1081 if (backup_file && devs_found > 1) {
1082 fprintf(stderr, Name ": can only assemble a single array when providing a backup file.\n");
1083 exit(1);
1084 }
1085 for (dv = devlist ; dv ; dv=dv->next) {
1086 mddev_ident_t array_ident = conf_get_ident(dv->devname);
1087 if (array_ident == NULL) {
1088 fprintf(stderr, Name ": %s not identified in config file.\n",
1089 dv->devname);
1090 rv |= 1;
1091 continue;
1092 }
1093 if (array_ident->autof == 0)
1094 array_ident->autof = autof;
1095 rv |= Assemble(ss, dv->devname, array_ident,
1096 NULL, backup_file,
1097 readonly, runstop, update,
1098 homehost, require_homehost,
1099 verbose-quiet, force);
1100 }
1101 } else {
1102 mddev_ident_t array_list = conf_get_ident(NULL);
1103 mddev_dev_t devlist = conf_get_devs();
1104 int cnt = 0;
1105 if (devlist == NULL) {
1106 fprintf(stderr, Name ": No devices listed in conf file were found.\n");
1107 exit(1);
1108 }
1109 if (update) {
1110 fprintf(stderr, Name ": --update not meaningful with a --scan assembly.\n");
1111 exit(1);
1112 }
1113 if (backup_file) {
1114 fprintf(stderr, Name ": --backup_file not meaningful with a --scan assembly.\n");
1115 exit(1);
1116 }
1117 for (; array_list; array_list = array_list->next) {
1118 if (array_list->devname &&
1119 strcasecmp(array_list->devname, "<ignore>") == 0)
1120 continue;
1121 if (array_list->autof == 0)
1122 array_list->autof = autof;
1123
1124 rv |= Assemble(ss, array_list->devname,
1125 array_list,
1126 NULL, NULL,
1127 readonly, runstop, NULL,
1128 homehost, require_homehost,
1129 verbose-quiet, force);
1130 cnt++;
1131 }
1132 if (homehost && cnt == 0) {
1133 /* Maybe we can auto-assemble something.
1134 * Repeatedly call Assemble in auto-assemble mode
1135 * until it fails
1136 */
1137 int rv2;
1138 int acnt;
1139 ident.autof = autof;
1140 do {
1141 mddev_dev_t devlist = conf_get_devs();
1142 acnt = 0;
1143 do {
1144 rv2 = Assemble(ss, NULL,
1145 &ident,
1146 devlist, NULL,
1147 readonly, runstop, NULL,
1148 homehost, require_homehost,
1149 verbose-quiet, force);
1150 if (rv2==0) {
1151 cnt++;
1152 acnt++;
1153 }
1154 if (rv2 == 1)
1155 /* found something so even though assembly failed we
1156 * want to avoid auto-updates
1157 */
1158 auto_update_home = 0;
1159 } while (rv2!=2);
1160 /* Incase there are stacked devices, we need to go around again */
1161 } while (acnt);
1162 #if 0
1163 if (cnt == 0 && auto_update_home && homehost) {
1164 /* Nothing found, maybe we need to bootstrap homehost info */
1165 do {
1166 acnt = 0;
1167 do {
1168 rv2 = Assemble(ss, NULL,
1169 &ident,
1170 NULL, NULL,
1171 readonly, runstop, "homehost",
1172 homehost, require_homehost,
1173 verbose-quiet, force);
1174 if (rv2==0) {
1175 cnt++;
1176 acnt++;
1177 }
1178 } while (rv2!=2);
1179 /* Incase there are stacked devices, we need to go around again */
1180 } while (acnt);
1181 }
1182 #endif
1183 if (cnt == 0 && rv == 0) {
1184 fprintf(stderr, Name ": No arrays found in config file or automatically\n");
1185 rv = 1;
1186 } else if (cnt)
1187 rv = 0;
1188 } else if (cnt == 0 && rv == 0) {
1189 fprintf(stderr, Name ": No arrays found in config file\n");
1190 rv = 1;
1191 }
1192 }
1193 break;
1194 case BUILD:
1195 if (delay == 0) delay = DEFAULT_BITMAP_DELAY;
1196 if (write_behind && !bitmap_file) {
1197 fprintf(stderr, Name ": write-behind mode requires a bitmap.\n");
1198 rv = 1;
1199 break;
1200 }
1201 if (raiddisks == 0) {
1202 fprintf(stderr, Name ": no raid-devices specified.\n");
1203 rv = 1;
1204 break;
1205 }
1206
1207 if (bitmap_file) {
1208 if (strcmp(bitmap_file, "internal")==0) {
1209 fprintf(stderr, Name ": 'internal' bitmaps not supported with --build\n");
1210 rv |= 1;
1211 break;
1212 }
1213 }
1214 rv = Build(devlist->devname, chunk, level, layout,
1215 raiddisks, devlist->next, assume_clean,
1216 bitmap_file, bitmap_chunk, write_behind,
1217 delay, verbose-quiet, autof, size);
1218 break;
1219 case CREATE:
1220 if (delay == 0) delay = DEFAULT_BITMAP_DELAY;
1221 if (write_behind && !bitmap_file) {
1222 fprintf(stderr, Name ": write-behind mode requires a bitmap.\n");
1223 rv = 1;
1224 break;
1225 }
1226 if (raiddisks == 0) {
1227 fprintf(stderr, Name ": no raid-devices specified.\n");
1228 rv = 1;
1229 break;
1230 }
1231
1232 rv = Create(ss, devlist->devname, chunk, level, layout, size<0 ? 0 : size,
1233 raiddisks, sparedisks, ident.name, homehost,
1234 ident.uuid_set ? ident.uuid : NULL,
1235 devs_found-1, devlist->next, runstop, verbose-quiet, force, assume_clean,
1236 bitmap_file, bitmap_chunk, write_behind, delay, autof);
1237 break;
1238 case MISC:
1239 if (devmode == 'E') {
1240 if (devlist == NULL && !scan) {
1241 fprintf(stderr, Name ": No devices to examine\n");
1242 exit(2);
1243 }
1244 if (devlist == NULL)
1245 devlist = conf_get_devs();
1246 if (devlist == NULL) {
1247 fprintf(stderr, Name ": No devices listed in %s\n", configfile?configfile:DefaultConfFile);
1248 exit(1);
1249 }
1250 if (brief && verbose)
1251 brief = 2;
1252 rv = Examine(devlist, scan?(verbose>1?0:verbose+1):brief,
1253 export, scan,
1254 SparcAdjust, ss, homehost);
1255 } else if (devmode == DetailPlatform) {
1256 rv = Detail_Platform(ss ? ss->ss : NULL, ss ? scan : 1, verbose);
1257 } else {
1258 if (devlist == NULL) {
1259 if ((devmode=='D' || devmode == Waitclean) && scan) {
1260 /* apply --detail or --wait-clean to
1261 * all devices in /proc/mdstat
1262 */
1263 struct mdstat_ent *ms = mdstat_read(0, 1);
1264 struct mdstat_ent *e;
1265 struct map_ent *map = NULL;
1266 int members;
1267 int v = verbose>1?0:verbose+1;
1268
1269 for (members = 0; members <= 1; members++) {
1270 for (e=ms ; e ; e=e->next) {
1271 char *name;
1272 struct map_ent *me;
1273 int member = e->metadata_version &&
1274 strncmp(e->metadata_version,
1275 "external:/", 10) == 0;
1276 if (members != member)
1277 continue;
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, -1, v);
1296 put_md_name(name);
1297 }
1298 }
1299 free_mdstat(ms);
1300 } else if (devmode == 'S' && scan) {
1301 /* apply --stop to all devices in /proc/mdstat */
1302 /* Due to possible stacking of devices, repeat until
1303 * nothing more can be stopped
1304 */
1305 int progress=1, err;
1306 int last = 0;
1307 do {
1308 struct mdstat_ent *ms = mdstat_read(0, 0);
1309 struct mdstat_ent *e;
1310
1311 if (!progress) last = 1;
1312 progress = 0; err = 0;
1313 for (e=ms ; e ; e=e->next) {
1314 char *name = get_md_name(e->devnum);
1315
1316 if (!name) {
1317 fprintf(stderr, Name ": cannot find device file for %s\n",
1318 e->dev);
1319 continue;
1320 }
1321 mdfd = open_mddev(name, 1);
1322 if (mdfd >= 0) {
1323 if (Manage_runstop(name, mdfd, -1, quiet?1:last?0:-1))
1324 err = 1;
1325 else
1326 progress = 1;
1327 close(mdfd);
1328 }
1329
1330 put_md_name(name);
1331 }
1332 free_mdstat(ms);
1333 } while (!last && err);
1334 if (err) rv |= 1;
1335 } else {
1336 fprintf(stderr, Name ": No devices given.\n");
1337 exit(2);
1338 }
1339 }
1340 for (dv=devlist ; dv; dv=dv->next) {
1341 switch(dv->disposition) {
1342 case 'D':
1343 rv |= Detail(dv->devname,
1344 brief?1+verbose:0,
1345 export, test, homehost);
1346 continue;
1347 case 'K': /* Zero superblock */
1348 rv |= Kill(dv->devname, force, quiet,0);
1349 continue;
1350 case 'Q':
1351 rv |= Query(dv->devname); continue;
1352 case 'X':
1353 rv |= ExamineBitmap(dv->devname, brief, ss); continue;
1354 case 'W':
1355 rv |= Wait(dv->devname); continue;
1356 case Waitclean:
1357 rv |= WaitClean(dv->devname, -1, verbose-quiet); continue;
1358 }
1359 mdfd = open_mddev(dv->devname, 1);
1360 if (mdfd>=0) {
1361 switch(dv->disposition) {
1362 case 'R':
1363 rv |= Manage_runstop(dv->devname, mdfd, 1, quiet); break;
1364 case 'S':
1365 rv |= Manage_runstop(dv->devname, mdfd, -1, quiet); break;
1366 case 'o':
1367 rv |= Manage_ro(dv->devname, mdfd, 1); break;
1368 case 'w':
1369 rv |= Manage_ro(dv->devname, mdfd, -1); break;
1370 }
1371 close(mdfd);
1372 } else
1373 rv |= 1;
1374 }
1375 }
1376 break;
1377 case MONITOR:
1378 if (!devlist && !scan) {
1379 fprintf(stderr, Name ": Cannot monitor: need --scan or at least one device\n");
1380 rv = 1;
1381 break;
1382 }
1383 if (pidfile && !daemonise) {
1384 fprintf(stderr, Name ": Cannot write a pid file when not in daemon mode\n");
1385 rv = 1;
1386 break;
1387 }
1388 if (delay == 0) {
1389 if (get_linux_version() > 20616)
1390 /* mdstat responds to poll */
1391 delay = 1000;
1392 else
1393 delay = 60;
1394 }
1395 rv= Monitor(devlist, mailaddr, program,
1396 delay?delay:60, daemonise, scan, oneshot,
1397 dosyslog, test, pidfile, increments);
1398 break;
1399
1400 case GROW:
1401 if (devs_found > 1) {
1402
1403 /* must be '-a'. */
1404 if (size >= 0 || raiddisks) {
1405 fprintf(stderr, Name ": --size, --raiddisks, and --add are exclusing in --grow mode\n");
1406 rv = 1;
1407 break;
1408 }
1409 for (dv=devlist->next; dv ; dv=dv->next) {
1410 rv = Grow_Add_device(devlist->devname, mdfd, dv->devname);
1411 if (rv)
1412 break;
1413 }
1414 } else if ((size >= 0) + (raiddisks != 0) + (layout != UnSet) + (bitmap_file != NULL)> 1) {
1415 fprintf(stderr, Name ": can change at most one of size, raiddisks, bitmap, and layout\n");
1416 rv = 1;
1417 break;
1418 } else if (layout != UnSet)
1419 rv = Manage_reconfig(devlist->devname, mdfd, layout);
1420 else if (size >= 0 || raiddisks)
1421 rv = Grow_reshape(devlist->devname, mdfd, quiet, backup_file,
1422 size, level, layout, chunk, raiddisks);
1423 else if (bitmap_file) {
1424 if (delay == 0) delay = DEFAULT_BITMAP_DELAY;
1425 rv = Grow_addbitmap(devlist->devname, mdfd, bitmap_file,
1426 bitmap_chunk, delay, write_behind, force);
1427 } else
1428 fprintf(stderr, Name ": no changes to --grow\n");
1429 break;
1430 case INCREMENTAL:
1431 if (rebuild_map) {
1432 RebuildMap();
1433 }
1434 if (scan) {
1435 if (runstop <= 0) {
1436 fprintf(stderr, Name
1437 ": --incremental --scan meaningless without --run.\n");
1438 break;
1439 }
1440 rv = IncrementalScan(verbose);
1441 }
1442 if (!devlist) {
1443 if (!rebuild_map && !scan) {
1444 fprintf(stderr, Name
1445 ": --incremental requires a device.\n");
1446 rv = 1;
1447 }
1448 break;
1449 }
1450 if (devlist->next) {
1451 fprintf(stderr, Name
1452 ": --incremental can only handle one device.\n");
1453 rv = 1;
1454 break;
1455 }
1456 rv = Incremental(devlist->devname, verbose-quiet, runstop,
1457 ss, homehost, require_homehost, autof);
1458 break;
1459 case AUTODETECT:
1460 autodetect();
1461 break;
1462 }
1463 exit(rv);
1464 }