2 * mdadm - manage Linux "md" devices aka RAID arrays.
4 * Copyright (C) 2001-2002 Neil Brown <neilb@cse.unsw.edu.au>
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 int autof
= 0; /* -2 means create device based on name:
79 * if it ends mdN, then non-partitioned array N
80 * if it ends dN, then partitions array N
81 * -1 means create non-partitioned, choose N
82 * 1 or more to create partitioned
83 * If -1 or 1 and name is a 'standard' name, then
84 * insist on a match of type and number.
87 char *mailaddr
= NULL
;
93 struct supertype
*ss
= NULL
;
96 char *shortopt
= short_options
;
104 srandom(time(0) ^ getpid());
108 ident
.raid_disks
= UnSet
;
109 ident
.super_minor
= UnSet
;
111 ident
.spare_group
= NULL
;
114 ident
.bitmap_fd
= -1;
115 ident
.bitmap_file
= NULL
;
118 while ((option_index
= -1) ,
119 (opt
=getopt_long(argc
, argv
,
120 shortopt
, long_options
,
121 &option_index
)) != -1) {
123 /* firstly, some mode-independant options */
126 if (option_index
> 0 &&
127 strcmp(long_options
[option_index
].name
, "help-options")==0)
134 fputs(Version
, stderr
);
144 if (mode
== ASSEMBLE
|| mode
== BUILD
|| mode
== CREATE
|| mode
== GROW
)
145 break; /* b means bitmap */
148 fprintf(stderr
, Name
": -b cannot have any extra immediately after it, sorry.\n");
155 fputs(Usage
, stderr
);
158 /* second, figure out the mode.
159 * Some options force the mode. Others
160 * set the mode if it isn't already
164 case '@': /* just incase they say --manage */
166 shortopt
= short_bitmap_auto_options
;
174 shortopt
= short_bitmap_auto_options
;
178 case 'A': newmode
= ASSEMBLE
; shortopt
= short_bitmap_auto_options
; break;
179 case 'B': newmode
= BUILD
; shortopt
= short_bitmap_auto_options
; break;
180 case 'C': newmode
= CREATE
; shortopt
= short_bitmap_auto_options
; break;
181 case 'F': newmode
= MONITOR
;break;
182 case 'G': newmode
= GROW
; shortopt
= short_bitmap_auto_options
; break;
188 case 'Q': newmode
= MISC
; break;
193 case 'K': if (!mode
) newmode
= MISC
; break;
195 if (mode
&& newmode
== mode
) {
196 /* everybody happy ! */
197 } else if (mode
&& newmode
!= mode
) {
199 fprintf(stderr
, Name
": ");
200 if (option_index
>= 0)
201 fprintf(stderr
, "--%s", long_options
[option_index
].name
);
203 fprintf(stderr
, "-%c", opt
);
204 fprintf(stderr
, " would set mdadm mode to \"%s\", but it is already set to \"%s\".\n",
205 map_num(modes
, newmode
),
206 map_num(modes
, mode
));
208 } else if (!mode
&& newmode
) {
211 /* special case of -c --help */
213 ( strncmp(optarg
, "--h", 3)==0 ||
214 strncmp(optarg
, "-h", 2)==0)) {
215 fputs(Help_config
, stderr
);
219 /* If first option is a device, don't force the mode yet */
221 if (devs_found
== 0) {
222 dv
= malloc(sizeof(*dv
));
224 fprintf(stderr
, Name
": malloc failed\n");
227 dv
->devname
= optarg
;
228 dv
->disposition
= devmode
;
229 dv
->writemostly
= writemostly
;
233 devlistend
= &dv
->next
;
238 /* No mode yet, and this is the second device ... */
239 fprintf(stderr
, Name
": An option must be given to set the mode before a second device is listed\n");
242 if (option_index
>= 0)
243 fprintf(stderr
, Name
": --%s", long_options
[option_index
].name
);
245 fprintf(stderr
, Name
": -%c", opt
);
246 fprintf(stderr
, " does not set the mode, and so cannot be the first option.\n");
250 /* if we just set the mode, then done */
262 /* an undecorated option - must be a device name.
264 if (devs_found
> 0 && mode
== '@' && !devmode
) {
265 fprintf(stderr
, Name
": Must give one of -a/-r/-f for subsequent devices at %s\n", optarg
);
268 if (devs_found
> 0 && mode
== 'G' && !devmode
) {
269 fprintf(stderr
, Name
": Must give one of -a for devices do add: %s\n", optarg
);
272 dv
= malloc(sizeof(*dv
));
274 fprintf(stderr
, Name
": malloc failed\n");
277 dv
->devname
= optarg
;
278 dv
->disposition
= devmode
;
279 dv
->writemostly
= writemostly
;
283 devlistend
= &dv
->next
;
289 /* We've got a mode, and opt is now something else which
290 * could depend on the mode */
291 #define O(a,b) ((a<<8)|b)
292 switch (O(mode
,opt
)) {
294 case O(BUILD
,'c'): /* chunk or rounding */
296 fprintf(stderr
, Name
": chunk/rounding may only be specified once. "
297 "Second value is %s.\n", optarg
);
300 chunk
= strtol(optarg
, &c
, 10);
301 if (!optarg
[0] || *c
|| chunk
<4 || ((chunk
-1)&chunk
)) {
302 fprintf(stderr
, Name
": invalid chunk/rounding value: %s\n",
309 case O(ASSEMBLE
,'e'):
310 case O(MISC
,'e'): /* set metadata (superblock) information */
312 fprintf(stderr
, Name
": metadata information already given\n");
315 for(i
=0; !ss
&& superlist
[i
]; i
++)
316 ss
= superlist
[i
]->match_metadata_desc(optarg
);
319 fprintf(stderr
, Name
": unrecognised metadata identifier: %s\n", optarg
);
322 max_disks
= ss
->max_devs
;
328 /* set write-mostly for following devices */
333 case O(CREATE
,'z'): /* size */
335 fprintf(stderr
, Name
": size may only be specified once. "
336 "Second value is %s.\n", optarg
);
339 if (strcmp(optarg
, "max")==0)
342 size
= strtoll(optarg
, &c
, 10);
343 if (!optarg
[0] || *c
|| size
< 4) {
344 fprintf(stderr
, Name
": invalid size: %s\n",
351 case O(GROW
,'l'): /* hack - needed to understand layout */
353 case O(BUILD
,'l'): /* set raid level*/
354 if (level
!= UnSet
) {
355 fprintf(stderr
, Name
": raid level may only be set once. "
356 "Second value is %s.\n", optarg
);
359 level
= map_name(pers
, optarg
);
360 if (level
== UnSet
) {
361 fprintf(stderr
, Name
": invalid raid level: %s\n",
365 if (level
!= 0 && level
!= -1 && level
!= 1 && level
!= -4 && level
!= -5 && mode
== BUILD
) {
366 fprintf(stderr
, Name
": Raid level %s not permitted with --build.\n",
370 if (sparedisks
> 0 && level
< 1 && level
>= -1) {
371 fprintf(stderr
, Name
": raid level %s is incompatible with spare-devices setting.\n",
378 case O(CREATE
,'p'): /* raid5 layout */
379 case O(BUILD
,'p'): /* faulty layout */
380 case O(GROW
, 'p'): /* faulty reconfig */
381 if (layout
!= UnSet
) {
382 fprintf(stderr
,Name
": layout may only be sent once. "
383 "Second value was %s\n", optarg
);
388 fprintf(stderr
, Name
": layout not meaningful for %s arrays.\n",
389 map_num(pers
, level
));
392 fprintf(stderr
, Name
": raid level must be given before layout.\n");
397 layout
= map_name(r5layout
, optarg
);
399 fprintf(stderr
, Name
": layout %s not understood for raid5.\n",
406 /* 'f' or 'n' followed by a number <= raid_disks */
407 if ((optarg
[0] != 'n' && optarg
[0] != 'f') ||
408 (copies
= strtoul(optarg
+1, &cp
, 10)) < 1 ||
411 fprintf(stderr
, Name
": layout for raid10 must be 'nNN' or 'fNN' where NN is a number, not %s\n", optarg
);
414 if (optarg
[0] == 'n')
415 layout
= 256 + copies
;
417 layout
= 1 + (copies
<<8);
424 int ln
= strcspn(optarg
, "0123456789");
425 char *m
= strdup(optarg
);
428 mode
= map_name(faultylayout
, m
);
430 fprintf(stderr
, Name
": layout %s not understood for faulty.\n",
434 layout
= mode
| (atoi(optarg
+ln
)<< ModeShift
);
440 case O(BUILD
,3): /* assume clean */
446 case O(BUILD
,'n'): /* number of raid disks */
448 fprintf(stderr
, Name
": raid-devices set twice: %d and %s\n",
452 raiddisks
= strtol(optarg
, &c
, 10);
453 if (!optarg
[0] || *c
|| raiddisks
<=0) {
454 fprintf(stderr
, Name
": invalid number of raid devices: %s\n",
458 ident
.raid_disks
= raiddisks
;
461 case O(CREATE
,'x'): /* number of spare (eXtra) discs */
463 fprintf(stderr
,Name
": spare-devices set twice: %d and %s\n",
467 if (level
!= UnSet
&& level
<= 0 && level
>= -1) {
468 fprintf(stderr
, Name
": spare-devices setting is incompatible with raid level %d\n",
472 sparedisks
= strtol(optarg
, &c
, 10);
473 if (!optarg
[0] || *c
|| sparedisks
< 0) {
474 fprintf(stderr
, Name
": invalid number of spare-devices: %s\n",
482 case O(ASSEMBLE
,'a'): /* auto-creation of device node */
485 else if (strcasecmp(optarg
,"no")==0)
487 else if (strcasecmp(optarg
,"yes")==0)
489 else if (strcasecmp(optarg
,"md")==0)
492 /* There might be digits, and maybe a hypen, at the end */
493 char *e
= optarg
+ strlen(optarg
);
496 while (e
> optarg
&& isdigit(e
[-1]))
500 if (num
<= 0) num
= 1;
502 if (e
> optarg
&& e
[-1] == '-')
505 if ((len
== 3 && strncasecmp(optarg
,"mdp",3)==0) ||
506 (len
== 1 && strncasecmp(optarg
,"p",1)==0) ||
507 (len
>= 4 && strncasecmp(optarg
,"part",4)==0))
510 fprintf(stderr
, Name
": --auto flag arg of \"%s\" unrecognised: use no,yes,md,mdp,part\n"
511 " optionally followed by a number.\n",
518 case O(BUILD
,'f'): /* force honouring '-n 1' */
519 case O(GROW
,'f'): /* ditto */
520 case O(CREATE
,'f'): /* force honouring of device list */
521 case O(ASSEMBLE
,'f'): /* force assembly */
522 case O(MISC
,'f'): /* force zero */
526 /* now for the Assemble options */
527 case O(ASSEMBLE
,'u'): /* uuid of array */
528 if (ident
.uuid_set
) {
529 fprintf(stderr
, Name
": uuid cannot be set twice. "
530 "Second value %s.\n", optarg
);
533 if (parse_uuid(optarg
, ident
.uuid
))
536 fprintf(stderr
,Name
": Bad uuid: %s\n", optarg
);
542 case O(ASSEMBLE
,'N'):
544 fprintf(stderr
, Name
": name cannot be set twice. "
545 "Second value %s.\n", optarg
);
548 if (strlen(optarg
) > 32) {
549 fprintf(stderr
, Name
": name '%s' is too long, 32 chars max.\n",
553 strcpy(ident
.name
, optarg
);
556 case O(ASSEMBLE
,'m'): /* super-minor for array */
557 if (ident
.super_minor
!= UnSet
) {
558 fprintf(stderr
, Name
": super-minor cannot be set twice. "
559 "Second value: %s.\n", optarg
);
562 if (strcmp(optarg
, "dev")==0)
563 ident
.super_minor
= -2;
565 ident
.super_minor
= strtoul(optarg
, &cp
, 10);
566 if (!optarg
[0] || *cp
) {
567 fprintf(stderr
, Name
": Bad super-minor number: %s.\n", optarg
);
573 case O(ASSEMBLE
,'U'): /* update the superblock */
575 fprintf(stderr
, Name
": Can only update one aspect of superblock, both %s and %s given.\n",
580 if (strcmp(update
, "sparc2.2")==0)
582 if (strcmp(update
, "super-minor") == 0)
584 if (strcmp(update
, "summaries")==0)
586 if (strcmp(update
, "resync")==0)
588 if (strcmp(update
, "uuid")==0)
590 if (strcmp(update
, "byteorder")==0) {
592 fprintf(stderr
, Name
": must not set metadata type with --update=byteorder.\n");
595 for(i
=0; !ss
&& superlist
[i
]; i
++)
596 ss
= superlist
[i
]->match_metadata_desc("0.swap");
598 fprintf(stderr
, Name
": INTERNAL ERROR cannot find 0.swap\n");
604 fprintf(stderr
, Name
": '--update %s' invalid. Only 'sparc2.2', 'super-minor', 'uuid', 'resync' or 'summaries' supported\n",update
);
607 case O(ASSEMBLE
,'c'): /* config file */
611 fprintf(stderr
, Name
": configfile cannot be set twice. "
612 "Second value is %s.\n", optarg
);
616 /* FIXME possibly check that config file exists. Even parse it */
618 case O(ASSEMBLE
,'s'): /* scan */
624 case O(MONITOR
,'m'): /* mail address */
626 fprintf(stderr
, Name
": only specify one mailaddress. %s ignored.\n",
632 case O(MONITOR
,'p'): /* alert program */
634 fprintf(stderr
, Name
": only specify one alter program. %s ignored.\n",
640 case O(MONITOR
,'d'): /* delay in seconds */
642 case O(BUILD
,'d'): /* delay for bitmap updates */
645 fprintf(stderr
, Name
": only specify delay once. %s ignored.\n",
648 delay
= strtol(optarg
, &c
, 10);
649 if (!optarg
[0] || *c
|| delay
<1) {
650 fprintf(stderr
, Name
": invalid delay: %s\n",
656 case O(MONITOR
,'f'): /* daemonise */
659 case O(MONITOR
,'i'): /* pid */
661 fprintf(stderr
, Name
": only specify one pid file. %s ignored.\n",
666 case O(MONITOR
,'1'): /* oneshot */
669 case O(MONITOR
,'t'): /* test */
672 case O(MONITOR
,'y'): /* log messages to syslog */
673 openlog("mdadm", 0, SYSLOG_FACILITY
);
677 /* now the general management options. Some are applicable
678 * to other modes. None have arguments.
681 case O(MANAGE
,'a'): /* add a drive */
689 case O(MANAGE
,'r'): /* remove a drive */
692 case O(MANAGE
,'f'): /* set faulty */
696 case O(ASSEMBLE
,'R'):
698 case O(CREATE
,'R'): /* Run the array */
700 fprintf(stderr
, Name
": Cannot both Stop and Run an array\n");
707 fprintf(stderr
, Name
": Cannot both Run and Stop an array\n");
715 fprintf(stderr
, Name
": Cannot have both readonly and readwrite\n");
722 fprintf(stderr
, Name
": Cannot have both readwrite and readonly.\n");
737 if (devmode
&& devmode
!= opt
&&
738 (devmode
== 'E' || (opt
== 'E' && devmode
!= 'Q'))) {
739 fprintf(stderr
, Name
": --examine/-E cannot be given with -%c\n",
740 devmode
=='E'?opt
:devmode
);
750 if (devmode
!= 'E') {
751 fprintf(stderr
, Name
": --sparc2.2 only allowed with --examine\n");
757 case O(ASSEMBLE
,'b'): /* here we simply set the bitmap file */
759 fprintf(stderr
, Name
": bitmap file needed with -b in --assemble mode\n");
762 if (strcmp(optarg
, "internal")==0) {
763 fprintf(stderr
, Name
": there is no need to specify --bitmap when assembling arrays with internal bitmaps\n");
766 bitmap_fd
= open(optarg
, O_RDWR
);
767 if (!*optarg
|| bitmap_fd
< 0) {
768 fprintf(stderr
, Name
": cannot open bitmap file %s: %s\n", optarg
, strerror(errno
));
771 ident
.bitmap_fd
= bitmap_fd
; /* for Assemble */
776 /* Specify a file into which grow might place a backup,
777 * or from which assemble might recover a backup
780 fprintf(stderr
, Name
": backup file already specified, rejecting %s\n", optarg
);
783 backup_file
= optarg
;
788 case O(CREATE
,'b'): /* here we create the bitmap */
789 if (strcmp(optarg
, "internal")== 0 ||
790 strcmp(optarg
, "none")== 0 ||
791 strchr(optarg
, '/') != NULL
) {
792 bitmap_file
= optarg
;
796 fprintf(stderr
, Name
": bitmap file must contain a '/', or be 'internal', or 'none'\n");
801 case O(CREATE
,4): /* bitmap chunksize */
802 bitmap_chunk
= strtol(optarg
, &c
, 10);
803 if (!optarg
[0] || *c
|| bitmap_chunk
< 0 ||
804 bitmap_chunk
& (bitmap_chunk
- 1)) {
805 fprintf(stderr
, Name
": invalid bitmap chunksize: %s\n",
809 /* convert K to B, chunk of 0K means 512B */
810 bitmap_chunk
= bitmap_chunk
? bitmap_chunk
* 1024 : 512;
814 case O(CREATE
, 5): /* write-behind mode */
815 write_behind
= DEFAULT_MAX_WRITE_BEHIND
;
817 write_behind
= strtol(optarg
, &c
, 10);
818 if (write_behind
< 0 || *c
||
819 write_behind
> 16383) {
820 fprintf(stderr
, Name
": Invalid value for maximum outstanding write-behind writes: %s.\n\tMust be between 0 and 16383.\n", optarg
);
826 /* We have now processed all the valid options. Anything else is
829 if (option_index
> 0)
830 fprintf(stderr
, Name
":option --%s not valid in %s mode\n",
831 long_options
[option_index
].name
,
832 map_num(modes
, mode
));
834 fprintf(stderr
, Name
": option -%c not valid in %s mode\n",
835 opt
, map_num(modes
, mode
));
841 char *help_text
= Help
;
843 help_text
= OptionHelp
;
846 case ASSEMBLE
: help_text
= Help_assemble
; break;
847 case BUILD
: help_text
= Help_build
; break;
848 case CREATE
: help_text
= Help_create
; break;
849 case MANAGE
: help_text
= Help_manage
; break;
850 case MISC
: help_text
= Help_misc
; break;
851 case MONITOR
: help_text
= Help_monitor
; break;
852 case GROW
: help_text
= Help_grow
; break;
854 fputs(help_text
,stderr
);
858 if (!mode
&& devs_found
) {
861 if (devlist
->disposition
== 0)
862 devlist
->disposition
= devmode
;
865 fputs(Usage
, stderr
);
868 /* Ok, got the option parsing out of the way
869 * hopefully it's mostly right but there might be some stuff
872 * That is mosty checked in the per-mode stuff but...
874 * For @,B,C and A without -s, the first device listed must be an md device
875 * we check that here and open it.
878 if (mode
==MANAGE
|| mode
== BUILD
|| mode
== CREATE
|| mode
== GROW
||
879 (mode
== ASSEMBLE
&& ! scan
)) {
880 if (devs_found
< 1) {
881 fprintf(stderr
, Name
": an md device must be given in this mode\n");
884 if ((int)ident
.super_minor
== -2 && autof
) {
885 fprintf(stderr
, Name
": --super-minor=dev is incompatible with --auto\n");
888 mdfd
= open_mddev(devlist
->devname
, autof
);
891 if ((int)ident
.super_minor
== -2) {
894 ident
.super_minor
= minor(stb
.st_rdev
);
899 if (raiddisks
> max_disks
) {
900 fprintf(stderr
, Name
": invalid number of raid devices: %d\n",
904 if (raiddisks
== 1 && !force
&& level
!= -5) {
905 fprintf(stderr
, Name
": '1' is an unusual number of drives for an array, so it is probably\n"
906 " a mistake. If you really mean it you will need to specify --force before\n"
907 " setting the number of drives.\n");
912 if ( sparedisks
> max_disks
- raiddisks
) {
913 fprintf(stderr
, Name
": invalid number of spare-devices: %d\n",
922 /* readonly, add/remove, readwrite, runstop */
924 rv
= Manage_ro(devlist
->devname
, mdfd
, readonly
);
925 if (!rv
&& devs_found
>1)
926 rv
= Manage_subdevs(devlist
->devname
, mdfd
,
927 devlist
->next
, verbose
-quiet
);
928 if (!rv
&& readonly
< 0)
929 rv
= Manage_ro(devlist
->devname
, mdfd
, readonly
);
931 rv
= Manage_runstop(devlist
->devname
, mdfd
, runstop
, 0);
934 if (devs_found
== 1 && ident
.uuid_set
== 0 &&
935 ident
.super_minor
== UnSet
&& ident
.name
[0] == 0 && !scan
) {
936 /* Only a device has been given, so get details from config file */
937 mddev_ident_t array_ident
= conf_get_ident(configfile
, devlist
->devname
);
938 if (array_ident
== NULL
) {
939 fprintf(stderr
, Name
": %s not identified in config file.\n",
943 mdfd
= open_mddev(devlist
->devname
,
944 array_ident
->autof
? array_ident
->autof
: autof
);
948 rv
|= Assemble(ss
, devlist
->devname
, mdfd
, array_ident
, configfile
,
950 readonly
, runstop
, update
, verbose
-quiet
, force
);
955 rv
= Assemble(ss
, devlist
->devname
, mdfd
, &ident
, configfile
,
956 devlist
->next
, backup_file
,
957 readonly
, runstop
, update
, verbose
-quiet
, force
);
958 else if (devs_found
>0) {
959 if (update
&& devs_found
> 1) {
960 fprintf(stderr
, Name
": can only update a single array at a time\n");
963 if (backup_file
&& devs_found
> 1) {
964 fprintf(stderr
, Name
": can only assemble a single array when providing a backup file.\n");
967 for (dv
= devlist
; dv
; dv
=dv
->next
) {
968 mddev_ident_t array_ident
= conf_get_ident(configfile
, dv
->devname
);
969 if (array_ident
== NULL
) {
970 fprintf(stderr
, Name
": %s not identified in config file.\n",
975 mdfd
= open_mddev(dv
->devname
,
976 array_ident
->autof
?array_ident
->autof
: autof
);
981 rv
|= Assemble(ss
, dv
->devname
, mdfd
, array_ident
, configfile
,
983 readonly
, runstop
, update
, verbose
-quiet
, force
);
987 mddev_ident_t array_list
= conf_get_ident(configfile
, NULL
);
989 fprintf(stderr
, Name
": No arrays found in config file\n");
993 fprintf(stderr
, Name
": --update not meaningful with a --scan assembly.\n");
997 fprintf(stderr
, Name
": --backup_file not meaningful with a --scan assembly.\n");
1000 for (; array_list
; array_list
= array_list
->next
) {
1001 mdu_array_info_t array
;
1002 mdfd
= open_mddev(array_list
->devname
,
1003 array_list
->autof
? array_list
->autof
: autof
);
1008 if (ioctl(mdfd
, GET_ARRAY_INFO
, &array
)>=0)
1009 /* already assembled, skip */
1012 rv
|= Assemble(ss
, array_list
->devname
, mdfd
,
1013 array_list
, configfile
,
1015 readonly
, runstop
, NULL
, verbose
-quiet
, force
);
1021 if (bitmap_chunk
== UnSet
) bitmap_chunk
= DEFAULT_BITMAP_CHUNK
;
1022 if (delay
== 0) delay
= DEFAULT_BITMAP_DELAY
;
1023 if (write_behind
&& !bitmap_file
) {
1024 fprintf(stderr
, Name
": write-behind mode requires a bitmap.\n");
1030 if (strcmp(bitmap_file
, "internal")==0) {
1031 fprintf(stderr
, Name
": 'internal' bitmaps not supported with --build\n");
1036 rv
= Build(devlist
->devname
, mdfd
, chunk
, level
, layout
,
1037 raiddisks
, devlist
->next
, assume_clean
,
1038 bitmap_file
, bitmap_chunk
, write_behind
, delay
, verbose
-quiet
);
1041 if (delay
== 0) delay
= DEFAULT_BITMAP_DELAY
;
1042 if (write_behind
&& !bitmap_file
) {
1043 fprintf(stderr
, Name
": write-behind mode requires a bitmap.\n");
1048 rv
= Create(ss
, devlist
->devname
, mdfd
, chunk
, level
, layout
, size
<0 ? 0 : size
,
1049 raiddisks
, sparedisks
, ident
.name
,
1050 devs_found
-1, devlist
->next
, runstop
, verbose
-quiet
, force
, assume_clean
,
1051 bitmap_file
, bitmap_chunk
, write_behind
, delay
);
1055 if (devmode
== 'E') {
1056 if (devlist
== NULL
&& !scan
) {
1057 fprintf(stderr
, Name
": No devices to examine\n");
1060 if (devlist
== NULL
)
1061 devlist
= conf_get_devs(configfile
);
1062 if (devlist
== NULL
) {
1063 fprintf(stderr
, Name
": No devices listed in %s\n", configfile
?configfile
:DefaultConfFile
);
1066 rv
= Examine(devlist
, scan
?(verbose
>1?0:verbose
+1):brief
, scan
, SparcAdjust
, ss
);
1068 if (devlist
== NULL
) {
1069 if (devmode
=='D' && scan
) {
1070 /* apply --detail to all devices in /proc/mdstat */
1071 struct mdstat_ent
*ms
= mdstat_read(0, 1);
1072 struct mdstat_ent
*e
;
1073 for (e
=ms
; e
; e
=e
->next
) {
1074 char *name
= get_md_name(e
->devnum
);
1077 fprintf(stderr
, Name
": cannot find device file for %s\n",
1081 rv
|= Detail(name
, verbose
>1?0:verbose
+1, test
);
1084 } else if (devmode
== 'S' && scan
) {
1085 /* apply --stop to all devices in /proc/mdstat */
1086 /* Due to possible stacking of devices, repeat until
1087 * nothing more can be stopped
1089 int progress
=1, err
;
1092 struct mdstat_ent
*ms
= mdstat_read(0, 0);
1093 struct mdstat_ent
*e
;
1095 if (!progress
) last
= 1;
1096 progress
= 0; err
= 0;
1097 for (e
=ms
; e
; e
=e
->next
) {
1098 char *name
= get_md_name(e
->devnum
);
1101 fprintf(stderr
, Name
": cannot find device file for %s\n",
1105 mdfd
= open_mddev(name
, 0);
1107 if (Manage_runstop(name
, mdfd
, -1, !last
))
1116 } while (!last
&& err
);
1119 fprintf(stderr
, Name
": No devices given.\n");
1123 for (dv
=devlist
; dv
; dv
=dv
->next
) {
1124 switch(dv
->disposition
) {
1126 rv
|= Detail(dv
->devname
, brief
?1+verbose
:0, test
); continue;
1127 case 'K': /* Zero superblock */
1128 rv
|= Kill(dv
->devname
, force
, quiet
); continue;
1130 rv
|= Query(dv
->devname
); continue;
1132 rv
|= ExamineBitmap(dv
->devname
, brief
, ss
); continue;
1134 mdfd
= open_mddev(dv
->devname
, 0);
1136 switch(dv
->disposition
) {
1138 rv
|= Manage_runstop(dv
->devname
, mdfd
, 1, 0); break;
1140 rv
|= Manage_runstop(dv
->devname
, mdfd
, -1, 0); break;
1142 rv
|= Manage_ro(dv
->devname
, mdfd
, 1); break;
1144 rv
|= Manage_ro(dv
->devname
, mdfd
, -1); break;
1153 if (!devlist
&& !scan
) {
1154 fprintf(stderr
, Name
": Cannot monitor: need --scan or at least one device\n");
1158 if (pidfile
&& !daemonise
) {
1159 fprintf(stderr
, Name
": Cannot write a pid file when not in daemon mode\n");
1163 rv
= Monitor(devlist
, mailaddr
, program
,
1164 delay
?delay
:60, daemonise
, scan
, oneshot
,
1165 dosyslog
, configfile
, test
, pidfile
);
1169 if (devs_found
> 1) {
1172 if (size
>= 0 || raiddisks
) {
1173 fprintf(stderr
, Name
": --size, --raiddisks, and --add are exclusing in --grow mode\n");
1177 for (dv
=devlist
->next
; dv
; dv
=dv
->next
) {
1178 rv
= Grow_Add_device(devlist
->devname
, mdfd
, dv
->devname
);
1182 } else if ((size
>= 0) + (raiddisks
!= 0) + (layout
!= UnSet
) + (bitmap_file
!= NULL
)> 1) {
1183 fprintf(stderr
, Name
": can change at most one of size, raiddisks, bitmap, and layout\n");
1186 } else if (layout
!= UnSet
)
1187 rv
= Manage_reconfig(devlist
->devname
, mdfd
, layout
);
1188 else if (size
>= 0 || raiddisks
)
1189 rv
= Grow_reshape(devlist
->devname
, mdfd
, quiet
, backup_file
,
1190 size
, level
, layout
, chunk
, raiddisks
);
1191 else if (bitmap_file
) {
1192 if (delay
== 0) delay
= DEFAULT_BITMAP_DELAY
;
1193 rv
= Grow_addbitmap(devlist
->devname
, mdfd
, bitmap_file
,
1194 bitmap_chunk
, delay
, write_behind
, force
);
1196 fprintf(stderr
, Name
": no changes to --grow\n");