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