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