2 * mdadm - manage Linux "md" devices aka RAID arrays.
4 * Copyright (C) 2001-2006 Neil Brown <neilb@suse.de>
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.
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.
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
22 * Email: <neilb@cse.unsw.edu.au>
24 * School of Computer Science and Engineering
25 * The University of New South Wales
29 * Additions for bitmap and write-behind RAID options, Copyright (C) 2003-2004,
30 * Paul Clements, SteelEye Technology, Inc.
38 int main(int argc
, char *argv
[])
52 int max_disks
= MD_SB_DISKS
; /* just a default */
54 struct mddev_ident_s ident
;
55 char *configfile
= NULL
;
64 char *bitmap_file
= NULL
;
65 char *backup_file
= NULL
;
66 int bitmap_chunk
= UnSet
;
68 mddev_dev_t devlist
= NULL
;
69 mddev_dev_t
*devlistend
= & devlist
;
78 /* autof indicates whether and how to create device node.
79 * bottom 3 bits are style. Rest (when shifted) are number of parts
81 * 1 - don't create (no)
82 * 2 - if is_standard, then create (yes)
83 * 3 - create as 'md' - reject is_standard mdp (md)
84 * 4 - create as 'mdp' - reject is_standard md (mdp)
85 * 5 - default to md if not is_standard (md in config file)
86 * 6 - default to mdp if not is_standard (part, or mdp in config file)
90 char *homehost
= NULL
;
91 char *mailaddr
= NULL
;
97 struct supertype
*ss
= NULL
;
100 char *shortopt
= short_options
;
108 srandom(time(0) ^ getpid());
112 ident
.raid_disks
= UnSet
;
113 ident
.super_minor
= UnSet
;
115 ident
.spare_group
= NULL
;
118 ident
.bitmap_fd
= -1;
119 ident
.bitmap_file
= NULL
;
122 while ((option_index
= -1) ,
123 (opt
=getopt_long(argc
, argv
,
124 shortopt
, long_options
,
125 &option_index
)) != -1) {
127 /* firstly, some mode-independant options */
130 if (option_index
> 0 &&
131 strcmp(long_options
[option_index
].name
, "help-options")==0)
138 fputs(Version
, stderr
);
148 if (mode
== ASSEMBLE
|| mode
== BUILD
|| mode
== CREATE
|| mode
== GROW
)
149 break; /* b means bitmap */
152 fprintf(stderr
, Name
": -b cannot have any extra immediately after it, sorry.\n");
163 fputs(Usage
, stderr
);
166 /* second, figure out the mode.
167 * Some options force the mode. Others
168 * set the mode if it isn't already
172 case '@': /* just incase they say --manage */
174 shortopt
= short_bitmap_auto_options
;
182 shortopt
= short_bitmap_auto_options
;
186 case 'A': newmode
= ASSEMBLE
; shortopt
= short_bitmap_auto_options
; break;
187 case 'B': newmode
= BUILD
; shortopt
= short_bitmap_auto_options
; break;
188 case 'C': newmode
= CREATE
; shortopt
= short_bitmap_auto_options
; break;
189 case 'F': newmode
= MONITOR
;break;
190 case 'G': newmode
= GROW
; shortopt
= short_bitmap_auto_options
; break;
196 case 'Q': newmode
= MISC
; break;
201 case 'K': if (!mode
) newmode
= MISC
; break;
203 if (mode
&& newmode
== mode
) {
204 /* everybody happy ! */
205 } else if (mode
&& newmode
!= mode
) {
207 fprintf(stderr
, Name
": ");
208 if (option_index
>= 0)
209 fprintf(stderr
, "--%s", long_options
[option_index
].name
);
211 fprintf(stderr
, "-%c", opt
);
212 fprintf(stderr
, " would set mdadm mode to \"%s\", but it is already set to \"%s\".\n",
213 map_num(modes
, newmode
),
214 map_num(modes
, mode
));
216 } else if (!mode
&& newmode
) {
219 /* special case of -c --help */
221 ( strncmp(optarg
, "--h", 3)==0 ||
222 strncmp(optarg
, "-h", 2)==0)) {
223 fputs(Help_config
, stderr
);
227 /* If first option is a device, don't force the mode yet */
229 if (devs_found
== 0) {
230 dv
= malloc(sizeof(*dv
));
232 fprintf(stderr
, Name
": malloc failed\n");
235 dv
->devname
= optarg
;
236 dv
->disposition
= devmode
;
237 dv
->writemostly
= writemostly
;
241 devlistend
= &dv
->next
;
246 /* No mode yet, and this is the second device ... */
247 fprintf(stderr
, Name
": An option must be given to set the mode before a second device is listed\n");
250 if (option_index
>= 0)
251 fprintf(stderr
, Name
": --%s", long_options
[option_index
].name
);
253 fprintf(stderr
, Name
": -%c", opt
);
254 fprintf(stderr
, " does not set the mode, and so cannot be the first option.\n");
258 /* if we just set the mode, then done */
270 /* an undecorated option - must be a device name.
272 if (devs_found
> 0 && mode
== '@' && !devmode
) {
273 fprintf(stderr
, Name
": Must give one of -a/-r/-f for subsequent devices at %s\n", optarg
);
276 if (devs_found
> 0 && mode
== 'G' && !devmode
) {
277 fprintf(stderr
, Name
": Must give one of -a for devices do add: %s\n", optarg
);
280 dv
= malloc(sizeof(*dv
));
282 fprintf(stderr
, Name
": malloc failed\n");
285 dv
->devname
= optarg
;
286 dv
->disposition
= devmode
;
287 dv
->writemostly
= writemostly
;
291 devlistend
= &dv
->next
;
297 /* We've got a mode, and opt is now something else which
298 * could depend on the mode */
299 #define O(a,b) ((a<<8)|b)
300 switch (O(mode
,opt
)) {
302 case O(BUILD
,'c'): /* chunk or rounding */
304 fprintf(stderr
, Name
": chunk/rounding may only be specified once. "
305 "Second value is %s.\n", optarg
);
308 chunk
= strtol(optarg
, &c
, 10);
309 if (!optarg
[0] || *c
|| chunk
<4 || ((chunk
-1)&chunk
)) {
310 fprintf(stderr
, Name
": invalid chunk/rounding value: %s\n",
317 case O(ASSEMBLE
,'e'):
318 case O(MISC
,'e'): /* set metadata (superblock) information */
320 fprintf(stderr
, Name
": metadata information already given\n");
323 for(i
=0; !ss
&& superlist
[i
]; i
++)
324 ss
= superlist
[i
]->match_metadata_desc(optarg
);
327 fprintf(stderr
, Name
": unrecognised metadata identifier: %s\n", optarg
);
330 max_disks
= ss
->max_devs
;
336 /* set write-mostly for following devices */
341 case O(CREATE
,'z'): /* size */
343 fprintf(stderr
, Name
": size may only be specified once. "
344 "Second value is %s.\n", optarg
);
347 if (strcmp(optarg
, "max")==0)
350 size
= strtoll(optarg
, &c
, 10);
351 if (!optarg
[0] || *c
|| size
< 4) {
352 fprintf(stderr
, Name
": invalid size: %s\n",
359 case O(GROW
,'l'): /* hack - needed to understand layout */
361 case O(BUILD
,'l'): /* set raid level*/
362 if (level
!= UnSet
) {
363 fprintf(stderr
, Name
": raid level may only be set once. "
364 "Second value is %s.\n", optarg
);
367 level
= map_name(pers
, optarg
);
368 if (level
== UnSet
) {
369 fprintf(stderr
, Name
": invalid raid level: %s\n",
373 if (level
!= 0 && level
!= -1 && level
!= 1 && level
!= -4 && level
!= -5 && mode
== BUILD
) {
374 fprintf(stderr
, Name
": Raid level %s not permitted with --build.\n",
378 if (sparedisks
> 0 && level
< 1 && level
>= -1) {
379 fprintf(stderr
, Name
": raid level %s is incompatible with spare-devices setting.\n",
386 case O(CREATE
,'p'): /* raid5 layout */
387 case O(BUILD
,'p'): /* faulty layout */
388 case O(GROW
, 'p'): /* faulty reconfig */
389 if (layout
!= UnSet
) {
390 fprintf(stderr
,Name
": layout may only be sent once. "
391 "Second value was %s\n", optarg
);
396 fprintf(stderr
, Name
": layout not meaningful for %s arrays.\n",
397 map_num(pers
, level
));
400 fprintf(stderr
, Name
": raid level must be given before layout.\n");
405 layout
= map_name(r5layout
, optarg
);
407 fprintf(stderr
, Name
": layout %s not understood for raid5.\n",
414 /* 'f', 'o' or 'n' followed by a number <= raid_disks */
415 if ((optarg
[0] != 'n' && optarg
[0] != 'f' && optarg
[0] != 'o') ||
416 (copies
= strtoul(optarg
+1, &cp
, 10)) < 1 ||
419 fprintf(stderr
, Name
": layout for raid10 must be 'nNN', 'oNN' or 'fNN' where NN is a number, not %s\n", optarg
);
422 if (optarg
[0] == 'n')
423 layout
= 256 + copies
;
424 else if (optarg
[0] == 'o')
425 layout
= 0x10000 + (copies
<<8) + 1;
427 layout
= 1 + (copies
<<8);
434 int ln
= strcspn(optarg
, "0123456789");
435 char *m
= strdup(optarg
);
438 mode
= map_name(faultylayout
, m
);
440 fprintf(stderr
, Name
": layout %s not understood for faulty.\n",
444 layout
= mode
| (atoi(optarg
+ln
)<< ModeShift
);
449 case O(CREATE
,AssumeClean
):
450 case O(BUILD
,AssumeClean
): /* assume clean */
456 case O(BUILD
,'n'): /* number of raid disks */
458 fprintf(stderr
, Name
": raid-devices set twice: %d and %s\n",
462 raiddisks
= strtol(optarg
, &c
, 10);
463 if (!optarg
[0] || *c
|| raiddisks
<=0) {
464 fprintf(stderr
, Name
": invalid number of raid devices: %s\n",
468 ident
.raid_disks
= raiddisks
;
471 case O(CREATE
,'x'): /* number of spare (eXtra) discs */
473 fprintf(stderr
,Name
": spare-devices set twice: %d and %s\n",
477 if (level
!= UnSet
&& level
<= 0 && level
>= -1) {
478 fprintf(stderr
, Name
": spare-devices setting is incompatible with raid level %d\n",
482 sparedisks
= strtol(optarg
, &c
, 10);
483 if (!optarg
[0] || *c
|| sparedisks
< 0) {
484 fprintf(stderr
, Name
": invalid number of spare-devices: %s\n",
492 case O(ASSEMBLE
,'a'): /* auto-creation of device node */
493 autof
= parse_auto(optarg
, "--auto flag", 0);
496 case O(BUILD
,'f'): /* force honouring '-n 1' */
497 case O(GROW
,'f'): /* ditto */
498 case O(CREATE
,'f'): /* force honouring of device list */
499 case O(ASSEMBLE
,'f'): /* force assembly */
500 case O(MISC
,'f'): /* force zero */
504 /* now for the Assemble options */
505 case O(ASSEMBLE
,'u'): /* uuid of array */
506 if (ident
.uuid_set
) {
507 fprintf(stderr
, Name
": uuid cannot be set twice. "
508 "Second value %s.\n", optarg
);
511 if (parse_uuid(optarg
, ident
.uuid
))
514 fprintf(stderr
,Name
": Bad uuid: %s\n", optarg
);
520 case O(ASSEMBLE
,'N'):
522 fprintf(stderr
, Name
": name cannot be set twice. "
523 "Second value %s.\n", optarg
);
526 if (strlen(optarg
) > 32) {
527 fprintf(stderr
, Name
": name '%s' is too long, 32 chars max.\n",
531 strcpy(ident
.name
, optarg
);
534 case O(ASSEMBLE
,'m'): /* super-minor for array */
535 if (ident
.super_minor
!= UnSet
) {
536 fprintf(stderr
, Name
": super-minor cannot be set twice. "
537 "Second value: %s.\n", optarg
);
540 if (strcmp(optarg
, "dev")==0)
541 ident
.super_minor
= -2;
543 ident
.super_minor
= strtoul(optarg
, &cp
, 10);
544 if (!optarg
[0] || *cp
) {
545 fprintf(stderr
, Name
": Bad super-minor number: %s.\n", optarg
);
551 case O(ASSEMBLE
,'U'): /* update the superblock */
553 fprintf(stderr
, Name
": Can only update one aspect of superblock, both %s and %s given.\n",
558 if (strcmp(update
, "sparc2.2")==0)
560 if (strcmp(update
, "super-minor") == 0)
562 if (strcmp(update
, "summaries")==0)
564 if (strcmp(update
, "resync")==0)
566 if (strcmp(update
, "uuid")==0)
568 if (strcmp(update
, "byteorder")==0) {
570 fprintf(stderr
, Name
": must not set metadata type with --update=byteorder.\n");
573 for(i
=0; !ss
&& superlist
[i
]; i
++)
574 ss
= superlist
[i
]->match_metadata_desc("0.swap");
576 fprintf(stderr
, Name
": INTERNAL ERROR cannot find 0.swap\n");
582 fprintf(stderr
, Name
": '--update %s' invalid. Only 'sparc2.2', 'super-minor', 'uuid', 'resync' or 'summaries' supported\n",update
);
585 case O(ASSEMBLE
,NoDegraded
): /* --no-degraded */
586 runstop
= -1; /* --stop isn't allowed for --assemble, so we overload slightly */
589 case O(ASSEMBLE
,'c'): /* config file */
593 fprintf(stderr
, Name
": configfile cannot be set twice. "
594 "Second value is %s.\n", optarg
);
598 /* FIXME possibly check that config file exists. Even parse it */
600 case O(ASSEMBLE
,'s'): /* scan */
606 case O(MONITOR
,'m'): /* mail address */
608 fprintf(stderr
, Name
": only specify one mailaddress. %s ignored.\n",
614 case O(MONITOR
,'p'): /* alert program */
616 fprintf(stderr
, Name
": only specify one alter program. %s ignored.\n",
622 case O(MONITOR
,'d'): /* delay in seconds */
624 case O(BUILD
,'d'): /* delay for bitmap updates */
627 fprintf(stderr
, Name
": only specify delay once. %s ignored.\n",
630 delay
= strtol(optarg
, &c
, 10);
631 if (!optarg
[0] || *c
|| delay
<1) {
632 fprintf(stderr
, Name
": invalid delay: %s\n",
638 case O(MONITOR
,'f'): /* daemonise */
641 case O(MONITOR
,'i'): /* pid */
643 fprintf(stderr
, Name
": only specify one pid file. %s ignored.\n",
648 case O(MONITOR
,'1'): /* oneshot */
651 case O(MONITOR
,'t'): /* test */
654 case O(MONITOR
,'y'): /* log messages to syslog */
655 openlog("mdadm", 0, SYSLOG_FACILITY
);
659 /* now the general management options. Some are applicable
660 * to other modes. None have arguments.
663 case O(MANAGE
,'a'): /* add a drive */
667 case O(MANAGE
,ReAdd
):
671 case O(MANAGE
,'r'): /* remove a drive */
674 case O(MANAGE
,'f'): /* set faulty */
678 case O(ASSEMBLE
,'R'):
680 case O(CREATE
,'R'): /* Run the array */
682 fprintf(stderr
, Name
": Cannot both Stop and Run an array\n");
689 fprintf(stderr
, Name
": Cannot both Run and Stop an array\n");
697 fprintf(stderr
, Name
": Cannot have both readonly and readwrite\n");
704 fprintf(stderr
, Name
": Cannot have both readwrite and readonly.\n");
719 if (devmode
&& devmode
!= opt
&&
720 (devmode
== 'E' || (opt
== 'E' && devmode
!= 'Q'))) {
721 fprintf(stderr
, Name
": --examine/-E cannot be given with -%c\n",
722 devmode
=='E'?opt
:devmode
);
731 case O(MISC
, Sparc22
):
732 if (devmode
!= 'E') {
733 fprintf(stderr
, Name
": --sparc2.2 only allowed with --examine\n");
739 case O(ASSEMBLE
,'b'): /* here we simply set the bitmap file */
741 fprintf(stderr
, Name
": bitmap file needed with -b in --assemble mode\n");
744 if (strcmp(optarg
, "internal")==0) {
745 fprintf(stderr
, Name
": there is no need to specify --bitmap when assembling arrays with internal bitmaps\n");
748 bitmap_fd
= open(optarg
, O_RDWR
);
749 if (!*optarg
|| bitmap_fd
< 0) {
750 fprintf(stderr
, Name
": cannot open bitmap file %s: %s\n", optarg
, strerror(errno
));
753 ident
.bitmap_fd
= bitmap_fd
; /* for Assemble */
756 case O(ASSEMBLE
, BackupFile
):
757 case O(GROW
, BackupFile
):
758 /* Specify a file into which grow might place a backup,
759 * or from which assemble might recover a backup
762 fprintf(stderr
, Name
": backup file already specified, rejecting %s\n", optarg
);
765 backup_file
= optarg
;
770 case O(CREATE
,'b'): /* here we create the bitmap */
771 if (strcmp(optarg
, "internal")== 0 ||
772 strcmp(optarg
, "none")== 0 ||
773 strchr(optarg
, '/') != NULL
) {
774 bitmap_file
= optarg
;
778 fprintf(stderr
, Name
": bitmap file must contain a '/', or be 'internal', or 'none'\n");
781 case O(GROW
,BitmapChunk
):
782 case O(BUILD
,BitmapChunk
):
783 case O(CREATE
,BitmapChunk
): /* bitmap chunksize */
784 bitmap_chunk
= strtol(optarg
, &c
, 10);
785 if (!optarg
[0] || *c
|| bitmap_chunk
< 0 ||
786 bitmap_chunk
& (bitmap_chunk
- 1)) {
787 fprintf(stderr
, Name
": invalid bitmap chunksize: %s\n",
791 /* convert K to B, chunk of 0K means 512B */
792 bitmap_chunk
= bitmap_chunk
? bitmap_chunk
* 1024 : 512;
795 case O(BUILD
, WriteBehind
):
796 case O(CREATE
, WriteBehind
): /* write-behind mode */
797 write_behind
= DEFAULT_MAX_WRITE_BEHIND
;
799 write_behind
= strtol(optarg
, &c
, 10);
800 if (write_behind
< 0 || *c
||
801 write_behind
> 16383) {
802 fprintf(stderr
, Name
": Invalid value for maximum outstanding write-behind writes: %s.\n\tMust be between 0 and 16383.\n", optarg
);
808 /* We have now processed all the valid options. Anything else is
811 if (option_index
> 0)
812 fprintf(stderr
, Name
":option --%s not valid in %s mode\n",
813 long_options
[option_index
].name
,
814 map_num(modes
, mode
));
816 fprintf(stderr
, Name
": option -%c not valid in %s mode\n",
817 opt
, map_num(modes
, mode
));
823 char *help_text
= Help
;
825 help_text
= OptionHelp
;
828 case ASSEMBLE
: help_text
= Help_assemble
; break;
829 case BUILD
: help_text
= Help_build
; break;
830 case CREATE
: help_text
= Help_create
; break;
831 case MANAGE
: help_text
= Help_manage
; break;
832 case MISC
: help_text
= Help_misc
; break;
833 case MONITOR
: help_text
= Help_monitor
; break;
834 case GROW
: help_text
= Help_grow
; break;
836 fputs(help_text
,stderr
);
840 if (!mode
&& devs_found
) {
843 if (devlist
->disposition
== 0)
844 devlist
->disposition
= devmode
;
847 fputs(Usage
, stderr
);
850 /* Ok, got the option parsing out of the way
851 * hopefully it's mostly right but there might be some stuff
854 * That is mosty checked in the per-mode stuff but...
856 * For @,B,C and A without -s, the first device listed must be an md device
857 * we check that here and open it.
860 if (mode
==MANAGE
|| mode
== BUILD
|| mode
== CREATE
|| mode
== GROW
||
861 (mode
== ASSEMBLE
&& ! scan
)) {
862 if (devs_found
< 1) {
863 fprintf(stderr
, Name
": an md device must be given in this mode\n");
866 if ((int)ident
.super_minor
== -2 && autof
) {
867 fprintf(stderr
, Name
": --super-minor=dev is incompatible with --auto\n");
870 mdfd
= open_mddev(devlist
->devname
, autof
);
873 if ((int)ident
.super_minor
== -2) {
876 ident
.super_minor
= minor(stb
.st_rdev
);
881 if (raiddisks
> max_disks
) {
882 fprintf(stderr
, Name
": invalid number of raid devices: %d\n",
886 if (raiddisks
== 1 && !force
&& level
!= -5) {
887 fprintf(stderr
, Name
": '1' is an unusual number of drives for an array, so it is probably\n"
888 " a mistake. If you really mean it you will need to specify --force before\n"
889 " setting the number of drives.\n");
894 if ( sparedisks
> max_disks
- raiddisks
) {
895 fprintf(stderr
, Name
": invalid number of spare-devices: %d\n",
901 if (homehost
== NULL
)
902 homehost
= conf_get_homehost(configfile
);
907 /* readonly, add/remove, readwrite, runstop */
909 rv
= Manage_ro(devlist
->devname
, mdfd
, readonly
);
910 if (!rv
&& devs_found
>1)
911 rv
= Manage_subdevs(devlist
->devname
, mdfd
,
912 devlist
->next
, verbose
-quiet
);
913 if (!rv
&& readonly
< 0)
914 rv
= Manage_ro(devlist
->devname
, mdfd
, readonly
);
916 rv
= Manage_runstop(devlist
->devname
, mdfd
, runstop
, 0);
919 if (devs_found
== 1 && ident
.uuid_set
== 0 &&
920 ident
.super_minor
== UnSet
&& ident
.name
[0] == 0 && !scan
) {
921 /* Only a device has been given, so get details from config file */
922 mddev_ident_t array_ident
= conf_get_ident(configfile
, devlist
->devname
);
923 if (array_ident
== NULL
) {
924 fprintf(stderr
, Name
": %s not identified in config file.\n",
928 mdfd
= open_mddev(devlist
->devname
,
929 array_ident
->autof
? array_ident
->autof
: autof
);
933 rv
|= Assemble(ss
, devlist
->devname
, mdfd
, array_ident
, configfile
,
935 readonly
, runstop
, update
, verbose
-quiet
, force
);
940 rv
= Assemble(ss
, devlist
->devname
, mdfd
, &ident
, configfile
,
941 devlist
->next
, backup_file
,
942 readonly
, runstop
, update
, verbose
-quiet
, force
);
943 else if (devs_found
>0) {
944 if (update
&& devs_found
> 1) {
945 fprintf(stderr
, Name
": can only update a single array at a time\n");
948 if (backup_file
&& devs_found
> 1) {
949 fprintf(stderr
, Name
": can only assemble a single array when providing a backup file.\n");
952 for (dv
= devlist
; dv
; dv
=dv
->next
) {
953 mddev_ident_t array_ident
= conf_get_ident(configfile
, dv
->devname
);
954 if (array_ident
== NULL
) {
955 fprintf(stderr
, Name
": %s not identified in config file.\n",
960 mdfd
= open_mddev(dv
->devname
,
961 array_ident
->autof
?array_ident
->autof
: autof
);
966 rv
|= Assemble(ss
, dv
->devname
, mdfd
, array_ident
, configfile
,
968 readonly
, runstop
, update
, verbose
-quiet
, force
);
972 mddev_ident_t array_list
= conf_get_ident(configfile
, NULL
);
974 fprintf(stderr
, Name
": No arrays found in config file\n");
978 fprintf(stderr
, Name
": --update not meaningful with a --scan assembly.\n");
982 fprintf(stderr
, Name
": --backup_file not meaningful with a --scan assembly.\n");
985 for (; array_list
; array_list
= array_list
->next
) {
986 mdu_array_info_t array
;
987 mdfd
= open_mddev(array_list
->devname
,
988 array_list
->autof
? array_list
->autof
: autof
);
993 if (ioctl(mdfd
, GET_ARRAY_INFO
, &array
)>=0)
994 /* already assembled, skip */
997 rv
|= Assemble(ss
, array_list
->devname
, mdfd
,
998 array_list
, configfile
,
1000 readonly
, runstop
, NULL
, verbose
-quiet
, force
);
1006 if (delay
== 0) delay
= DEFAULT_BITMAP_DELAY
;
1007 if (write_behind
&& !bitmap_file
) {
1008 fprintf(stderr
, Name
": write-behind mode requires a bitmap.\n");
1014 if (strcmp(bitmap_file
, "internal")==0) {
1015 fprintf(stderr
, Name
": 'internal' bitmaps not supported with --build\n");
1020 rv
= Build(devlist
->devname
, mdfd
, chunk
, level
, layout
,
1021 raiddisks
, devlist
->next
, assume_clean
,
1022 bitmap_file
, bitmap_chunk
, write_behind
, delay
, verbose
-quiet
);
1025 if (delay
== 0) delay
= DEFAULT_BITMAP_DELAY
;
1026 if (write_behind
&& !bitmap_file
) {
1027 fprintf(stderr
, Name
": write-behind mode requires a bitmap.\n");
1032 rv
= Create(ss
, devlist
->devname
, mdfd
, chunk
, level
, layout
, size
<0 ? 0 : size
,
1033 raiddisks
, sparedisks
, ident
.name
,
1034 devs_found
-1, devlist
->next
, runstop
, verbose
-quiet
, force
, assume_clean
,
1035 bitmap_file
, bitmap_chunk
, write_behind
, delay
);
1039 if (devmode
== 'E') {
1040 if (devlist
== NULL
&& !scan
) {
1041 fprintf(stderr
, Name
": No devices to examine\n");
1044 if (devlist
== NULL
)
1045 devlist
= conf_get_devs(configfile
);
1046 if (devlist
== NULL
) {
1047 fprintf(stderr
, Name
": No devices listed in %s\n", configfile
?configfile
:DefaultConfFile
);
1050 rv
= Examine(devlist
, scan
?(verbose
>1?0:verbose
+1):brief
, scan
, SparcAdjust
, ss
);
1052 if (devlist
== NULL
) {
1053 if (devmode
=='D' && scan
) {
1054 /* apply --detail to all devices in /proc/mdstat */
1055 struct mdstat_ent
*ms
= mdstat_read(0, 1);
1056 struct mdstat_ent
*e
;
1057 for (e
=ms
; e
; e
=e
->next
) {
1058 char *name
= get_md_name(e
->devnum
);
1061 fprintf(stderr
, Name
": cannot find device file for %s\n",
1065 rv
|= Detail(name
, verbose
>1?0:verbose
+1, test
);
1068 } else if (devmode
== 'S' && scan
) {
1069 /* apply --stop to all devices in /proc/mdstat */
1070 /* Due to possible stacking of devices, repeat until
1071 * nothing more can be stopped
1073 int progress
=1, err
;
1076 struct mdstat_ent
*ms
= mdstat_read(0, 0);
1077 struct mdstat_ent
*e
;
1079 if (!progress
) last
= 1;
1080 progress
= 0; err
= 0;
1081 for (e
=ms
; e
; e
=e
->next
) {
1082 char *name
= get_md_name(e
->devnum
);
1085 fprintf(stderr
, Name
": cannot find device file for %s\n",
1089 mdfd
= open_mddev(name
, 0);
1091 if (Manage_runstop(name
, mdfd
, -1, !last
))
1100 } while (!last
&& err
);
1103 fprintf(stderr
, Name
": No devices given.\n");
1107 for (dv
=devlist
; dv
; dv
=dv
->next
) {
1108 switch(dv
->disposition
) {
1110 rv
|= Detail(dv
->devname
, brief
?1+verbose
:0, test
); continue;
1111 case 'K': /* Zero superblock */
1112 rv
|= Kill(dv
->devname
, force
, quiet
); continue;
1114 rv
|= Query(dv
->devname
); continue;
1116 rv
|= ExamineBitmap(dv
->devname
, brief
, ss
); continue;
1118 mdfd
= open_mddev(dv
->devname
, 0);
1120 switch(dv
->disposition
) {
1122 rv
|= Manage_runstop(dv
->devname
, mdfd
, 1, 0); break;
1124 rv
|= Manage_runstop(dv
->devname
, mdfd
, -1, 0); break;
1126 rv
|= Manage_ro(dv
->devname
, mdfd
, 1); break;
1128 rv
|= Manage_ro(dv
->devname
, mdfd
, -1); break;
1137 if (!devlist
&& !scan
) {
1138 fprintf(stderr
, Name
": Cannot monitor: need --scan or at least one device\n");
1142 if (pidfile
&& !daemonise
) {
1143 fprintf(stderr
, Name
": Cannot write a pid file when not in daemon mode\n");
1147 rv
= Monitor(devlist
, mailaddr
, program
,
1148 delay
?delay
:60, daemonise
, scan
, oneshot
,
1149 dosyslog
, configfile
, test
, pidfile
);
1153 if (devs_found
> 1) {
1156 if (size
>= 0 || raiddisks
) {
1157 fprintf(stderr
, Name
": --size, --raiddisks, and --add are exclusing in --grow mode\n");
1161 for (dv
=devlist
->next
; dv
; dv
=dv
->next
) {
1162 rv
= Grow_Add_device(devlist
->devname
, mdfd
, dv
->devname
);
1166 } else if ((size
>= 0) + (raiddisks
!= 0) + (layout
!= UnSet
) + (bitmap_file
!= NULL
)> 1) {
1167 fprintf(stderr
, Name
": can change at most one of size, raiddisks, bitmap, and layout\n");
1170 } else if (layout
!= UnSet
)
1171 rv
= Manage_reconfig(devlist
->devname
, mdfd
, layout
);
1172 else if (size
>= 0 || raiddisks
)
1173 rv
= Grow_reshape(devlist
->devname
, mdfd
, quiet
, backup_file
,
1174 size
, level
, layout
, chunk
, raiddisks
);
1175 else if (bitmap_file
) {
1176 if (delay
== 0) delay
= DEFAULT_BITMAP_DELAY
;
1177 rv
= Grow_addbitmap(devlist
->devname
, mdfd
, bitmap_file
,
1178 bitmap_chunk
, delay
, write_behind
, force
);
1180 fprintf(stderr
, Name
": no changes to --grow\n");