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 /* 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 *mailaddr
= NULL
;
96 struct supertype
*ss
= NULL
;
99 char *shortopt
= short_options
;
107 srandom(time(0) ^ getpid());
111 ident
.raid_disks
= UnSet
;
112 ident
.super_minor
= UnSet
;
114 ident
.spare_group
= NULL
;
117 ident
.bitmap_fd
= -1;
118 ident
.bitmap_file
= NULL
;
121 while ((option_index
= -1) ,
122 (opt
=getopt_long(argc
, argv
,
123 shortopt
, long_options
,
124 &option_index
)) != -1) {
126 /* firstly, some mode-independant options */
129 if (option_index
> 0 &&
130 strcmp(long_options
[option_index
].name
, "help-options")==0)
137 fputs(Version
, stderr
);
147 if (mode
== ASSEMBLE
|| mode
== BUILD
|| mode
== CREATE
|| mode
== GROW
)
148 break; /* b means bitmap */
151 fprintf(stderr
, Name
": -b cannot have any extra immediately after it, sorry.\n");
158 fputs(Usage
, stderr
);
161 /* second, figure out the mode.
162 * Some options force the mode. Others
163 * set the mode if it isn't already
167 case '@': /* just incase they say --manage */
169 shortopt
= short_bitmap_auto_options
;
177 shortopt
= short_bitmap_auto_options
;
181 case 'A': newmode
= ASSEMBLE
; shortopt
= short_bitmap_auto_options
; break;
182 case 'B': newmode
= BUILD
; shortopt
= short_bitmap_auto_options
; break;
183 case 'C': newmode
= CREATE
; shortopt
= short_bitmap_auto_options
; break;
184 case 'F': newmode
= MONITOR
;break;
185 case 'G': newmode
= GROW
; shortopt
= short_bitmap_auto_options
; break;
191 case 'Q': newmode
= MISC
; break;
196 case 'K': if (!mode
) newmode
= MISC
; break;
198 if (mode
&& newmode
== mode
) {
199 /* everybody happy ! */
200 } else if (mode
&& newmode
!= mode
) {
202 fprintf(stderr
, Name
": ");
203 if (option_index
>= 0)
204 fprintf(stderr
, "--%s", long_options
[option_index
].name
);
206 fprintf(stderr
, "-%c", opt
);
207 fprintf(stderr
, " would set mdadm mode to \"%s\", but it is already set to \"%s\".\n",
208 map_num(modes
, newmode
),
209 map_num(modes
, mode
));
211 } else if (!mode
&& newmode
) {
214 /* special case of -c --help */
216 ( strncmp(optarg
, "--h", 3)==0 ||
217 strncmp(optarg
, "-h", 2)==0)) {
218 fputs(Help_config
, stderr
);
222 /* If first option is a device, don't force the mode yet */
224 if (devs_found
== 0) {
225 dv
= malloc(sizeof(*dv
));
227 fprintf(stderr
, Name
": malloc failed\n");
230 dv
->devname
= optarg
;
231 dv
->disposition
= devmode
;
232 dv
->writemostly
= writemostly
;
236 devlistend
= &dv
->next
;
241 /* No mode yet, and this is the second device ... */
242 fprintf(stderr
, Name
": An option must be given to set the mode before a second device is listed\n");
245 if (option_index
>= 0)
246 fprintf(stderr
, Name
": --%s", long_options
[option_index
].name
);
248 fprintf(stderr
, Name
": -%c", opt
);
249 fprintf(stderr
, " does not set the mode, and so cannot be the first option.\n");
253 /* if we just set the mode, then done */
265 /* an undecorated option - must be a device name.
267 if (devs_found
> 0 && mode
== '@' && !devmode
) {
268 fprintf(stderr
, Name
": Must give one of -a/-r/-f for subsequent devices at %s\n", optarg
);
271 if (devs_found
> 0 && mode
== 'G' && !devmode
) {
272 fprintf(stderr
, Name
": Must give one of -a for devices do add: %s\n", optarg
);
275 dv
= malloc(sizeof(*dv
));
277 fprintf(stderr
, Name
": malloc failed\n");
280 dv
->devname
= optarg
;
281 dv
->disposition
= devmode
;
282 dv
->writemostly
= writemostly
;
286 devlistend
= &dv
->next
;
292 /* We've got a mode, and opt is now something else which
293 * could depend on the mode */
294 #define O(a,b) ((a<<8)|b)
295 switch (O(mode
,opt
)) {
297 case O(BUILD
,'c'): /* chunk or rounding */
299 fprintf(stderr
, Name
": chunk/rounding may only be specified once. "
300 "Second value is %s.\n", optarg
);
303 chunk
= strtol(optarg
, &c
, 10);
304 if (!optarg
[0] || *c
|| chunk
<4 || ((chunk
-1)&chunk
)) {
305 fprintf(stderr
, Name
": invalid chunk/rounding value: %s\n",
312 case O(ASSEMBLE
,'e'):
313 case O(MISC
,'e'): /* set metadata (superblock) information */
315 fprintf(stderr
, Name
": metadata information already given\n");
318 for(i
=0; !ss
&& superlist
[i
]; i
++)
319 ss
= superlist
[i
]->match_metadata_desc(optarg
);
322 fprintf(stderr
, Name
": unrecognised metadata identifier: %s\n", optarg
);
325 max_disks
= ss
->max_devs
;
331 /* set write-mostly for following devices */
336 case O(CREATE
,'z'): /* size */
338 fprintf(stderr
, Name
": size may only be specified once. "
339 "Second value is %s.\n", optarg
);
342 if (strcmp(optarg
, "max")==0)
345 size
= strtoll(optarg
, &c
, 10);
346 if (!optarg
[0] || *c
|| size
< 4) {
347 fprintf(stderr
, Name
": invalid size: %s\n",
354 case O(GROW
,'l'): /* hack - needed to understand layout */
356 case O(BUILD
,'l'): /* set raid level*/
357 if (level
!= UnSet
) {
358 fprintf(stderr
, Name
": raid level may only be set once. "
359 "Second value is %s.\n", optarg
);
362 level
= map_name(pers
, optarg
);
363 if (level
== UnSet
) {
364 fprintf(stderr
, Name
": invalid raid level: %s\n",
368 if (level
!= 0 && level
!= -1 && level
!= 1 && level
!= -4 && level
!= -5 && mode
== BUILD
) {
369 fprintf(stderr
, Name
": Raid level %s not permitted with --build.\n",
373 if (sparedisks
> 0 && level
< 1 && level
>= -1) {
374 fprintf(stderr
, Name
": raid level %s is incompatible with spare-devices setting.\n",
381 case O(CREATE
,'p'): /* raid5 layout */
382 case O(BUILD
,'p'): /* faulty layout */
383 case O(GROW
, 'p'): /* faulty reconfig */
384 if (layout
!= UnSet
) {
385 fprintf(stderr
,Name
": layout may only be sent once. "
386 "Second value was %s\n", optarg
);
391 fprintf(stderr
, Name
": layout not meaningful for %s arrays.\n",
392 map_num(pers
, level
));
395 fprintf(stderr
, Name
": raid level must be given before layout.\n");
400 layout
= map_name(r5layout
, optarg
);
402 fprintf(stderr
, Name
": layout %s not understood for raid5.\n",
409 /* 'f', 'o' or 'n' followed by a number <= raid_disks */
410 if ((optarg
[0] != 'n' && optarg
[0] != 'f' && optarg
[0] != 'o') ||
411 (copies
= strtoul(optarg
+1, &cp
, 10)) < 1 ||
414 fprintf(stderr
, Name
": layout for raid10 must be 'nNN', 'oNN' or 'fNN' where NN is a number, not %s\n", optarg
);
417 if (optarg
[0] == 'n')
418 layout
= 256 + copies
;
419 else if (optarg
[0] == 'o')
420 layout
= 0x10000 + (copies
<<8) + 1;
422 layout
= 1 + (copies
<<8);
429 int ln
= strcspn(optarg
, "0123456789");
430 char *m
= strdup(optarg
);
433 mode
= map_name(faultylayout
, m
);
435 fprintf(stderr
, Name
": layout %s not understood for faulty.\n",
439 layout
= mode
| (atoi(optarg
+ln
)<< ModeShift
);
445 case O(BUILD
,3): /* assume clean */
451 case O(BUILD
,'n'): /* number of raid disks */
453 fprintf(stderr
, Name
": raid-devices set twice: %d and %s\n",
457 raiddisks
= strtol(optarg
, &c
, 10);
458 if (!optarg
[0] || *c
|| raiddisks
<=0) {
459 fprintf(stderr
, Name
": invalid number of raid devices: %s\n",
463 ident
.raid_disks
= raiddisks
;
466 case O(CREATE
,'x'): /* number of spare (eXtra) discs */
468 fprintf(stderr
,Name
": spare-devices set twice: %d and %s\n",
472 if (level
!= UnSet
&& level
<= 0 && level
>= -1) {
473 fprintf(stderr
, Name
": spare-devices setting is incompatible with raid level %d\n",
477 sparedisks
= strtol(optarg
, &c
, 10);
478 if (!optarg
[0] || *c
|| sparedisks
< 0) {
479 fprintf(stderr
, Name
": invalid number of spare-devices: %s\n",
487 case O(ASSEMBLE
,'a'): /* auto-creation of device node */
488 autof
= parse_auto(optarg
, "--auto flag", 0);
491 case O(BUILD
,'f'): /* force honouring '-n 1' */
492 case O(GROW
,'f'): /* ditto */
493 case O(CREATE
,'f'): /* force honouring of device list */
494 case O(ASSEMBLE
,'f'): /* force assembly */
495 case O(MISC
,'f'): /* force zero */
499 /* now for the Assemble options */
500 case O(ASSEMBLE
,'u'): /* uuid of array */
501 if (ident
.uuid_set
) {
502 fprintf(stderr
, Name
": uuid cannot be set twice. "
503 "Second value %s.\n", optarg
);
506 if (parse_uuid(optarg
, ident
.uuid
))
509 fprintf(stderr
,Name
": Bad uuid: %s\n", optarg
);
515 case O(ASSEMBLE
,'N'):
517 fprintf(stderr
, Name
": name cannot be set twice. "
518 "Second value %s.\n", optarg
);
521 if (strlen(optarg
) > 32) {
522 fprintf(stderr
, Name
": name '%s' is too long, 32 chars max.\n",
526 strcpy(ident
.name
, optarg
);
529 case O(ASSEMBLE
,'m'): /* super-minor for array */
530 if (ident
.super_minor
!= UnSet
) {
531 fprintf(stderr
, Name
": super-minor cannot be set twice. "
532 "Second value: %s.\n", optarg
);
535 if (strcmp(optarg
, "dev")==0)
536 ident
.super_minor
= -2;
538 ident
.super_minor
= strtoul(optarg
, &cp
, 10);
539 if (!optarg
[0] || *cp
) {
540 fprintf(stderr
, Name
": Bad super-minor number: %s.\n", optarg
);
546 case O(ASSEMBLE
,'U'): /* update the superblock */
548 fprintf(stderr
, Name
": Can only update one aspect of superblock, both %s and %s given.\n",
553 if (strcmp(update
, "sparc2.2")==0)
555 if (strcmp(update
, "super-minor") == 0)
557 if (strcmp(update
, "summaries")==0)
559 if (strcmp(update
, "resync")==0)
561 if (strcmp(update
, "uuid")==0)
563 if (strcmp(update
, "byteorder")==0) {
565 fprintf(stderr
, Name
": must not set metadata type with --update=byteorder.\n");
568 for(i
=0; !ss
&& superlist
[i
]; i
++)
569 ss
= superlist
[i
]->match_metadata_desc("0.swap");
571 fprintf(stderr
, Name
": INTERNAL ERROR cannot find 0.swap\n");
577 fprintf(stderr
, Name
": '--update %s' invalid. Only 'sparc2.2', 'super-minor', 'uuid', 'resync' or 'summaries' supported\n",update
);
580 case O(ASSEMBLE
,4): /* --no-degraded */
581 runstop
= -1; /* --stop isn't allowed for --assemble, so we overload slightly */
584 case O(ASSEMBLE
,'c'): /* config file */
588 fprintf(stderr
, Name
": configfile cannot be set twice. "
589 "Second value is %s.\n", optarg
);
593 /* FIXME possibly check that config file exists. Even parse it */
595 case O(ASSEMBLE
,'s'): /* scan */
601 case O(MONITOR
,'m'): /* mail address */
603 fprintf(stderr
, Name
": only specify one mailaddress. %s ignored.\n",
609 case O(MONITOR
,'p'): /* alert program */
611 fprintf(stderr
, Name
": only specify one alter program. %s ignored.\n",
617 case O(MONITOR
,'d'): /* delay in seconds */
619 case O(BUILD
,'d'): /* delay for bitmap updates */
622 fprintf(stderr
, Name
": only specify delay once. %s ignored.\n",
625 delay
= strtol(optarg
, &c
, 10);
626 if (!optarg
[0] || *c
|| delay
<1) {
627 fprintf(stderr
, Name
": invalid delay: %s\n",
633 case O(MONITOR
,'f'): /* daemonise */
636 case O(MONITOR
,'i'): /* pid */
638 fprintf(stderr
, Name
": only specify one pid file. %s ignored.\n",
643 case O(MONITOR
,'1'): /* oneshot */
646 case O(MONITOR
,'t'): /* test */
649 case O(MONITOR
,'y'): /* log messages to syslog */
650 openlog("mdadm", 0, SYSLOG_FACILITY
);
654 /* now the general management options. Some are applicable
655 * to other modes. None have arguments.
658 case O(MANAGE
,'a'): /* add a drive */
666 case O(MANAGE
,'r'): /* remove a drive */
669 case O(MANAGE
,'f'): /* set faulty */
673 case O(ASSEMBLE
,'R'):
675 case O(CREATE
,'R'): /* Run the array */
677 fprintf(stderr
, Name
": Cannot both Stop and Run an array\n");
684 fprintf(stderr
, Name
": Cannot both Run and Stop an array\n");
692 fprintf(stderr
, Name
": Cannot have both readonly and readwrite\n");
699 fprintf(stderr
, Name
": Cannot have both readwrite and readonly.\n");
714 if (devmode
&& devmode
!= opt
&&
715 (devmode
== 'E' || (opt
== 'E' && devmode
!= 'Q'))) {
716 fprintf(stderr
, Name
": --examine/-E cannot be given with -%c\n",
717 devmode
=='E'?opt
:devmode
);
727 if (devmode
!= 'E') {
728 fprintf(stderr
, Name
": --sparc2.2 only allowed with --examine\n");
734 case O(ASSEMBLE
,'b'): /* here we simply set the bitmap file */
736 fprintf(stderr
, Name
": bitmap file needed with -b in --assemble mode\n");
739 if (strcmp(optarg
, "internal")==0) {
740 fprintf(stderr
, Name
": there is no need to specify --bitmap when assembling arrays with internal bitmaps\n");
743 bitmap_fd
= open(optarg
, O_RDWR
);
744 if (!*optarg
|| bitmap_fd
< 0) {
745 fprintf(stderr
, Name
": cannot open bitmap file %s: %s\n", optarg
, strerror(errno
));
748 ident
.bitmap_fd
= bitmap_fd
; /* for Assemble */
753 /* Specify a file into which grow might place a backup,
754 * or from which assemble might recover a backup
757 fprintf(stderr
, Name
": backup file already specified, rejecting %s\n", optarg
);
760 backup_file
= optarg
;
765 case O(CREATE
,'b'): /* here we create the bitmap */
766 if (strcmp(optarg
, "internal")== 0 ||
767 strcmp(optarg
, "none")== 0 ||
768 strchr(optarg
, '/') != NULL
) {
769 bitmap_file
= optarg
;
773 fprintf(stderr
, Name
": bitmap file must contain a '/', or be 'internal', or 'none'\n");
778 case O(CREATE
,4): /* bitmap chunksize */
779 bitmap_chunk
= strtol(optarg
, &c
, 10);
780 if (!optarg
[0] || *c
|| bitmap_chunk
< 0 ||
781 bitmap_chunk
& (bitmap_chunk
- 1)) {
782 fprintf(stderr
, Name
": invalid bitmap chunksize: %s\n",
786 /* convert K to B, chunk of 0K means 512B */
787 bitmap_chunk
= bitmap_chunk
? bitmap_chunk
* 1024 : 512;
791 case O(CREATE
, 5): /* write-behind mode */
792 write_behind
= DEFAULT_MAX_WRITE_BEHIND
;
794 write_behind
= strtol(optarg
, &c
, 10);
795 if (write_behind
< 0 || *c
||
796 write_behind
> 16383) {
797 fprintf(stderr
, Name
": Invalid value for maximum outstanding write-behind writes: %s.\n\tMust be between 0 and 16383.\n", optarg
);
803 /* We have now processed all the valid options. Anything else is
806 if (option_index
> 0)
807 fprintf(stderr
, Name
":option --%s not valid in %s mode\n",
808 long_options
[option_index
].name
,
809 map_num(modes
, mode
));
811 fprintf(stderr
, Name
": option -%c not valid in %s mode\n",
812 opt
, map_num(modes
, mode
));
818 char *help_text
= Help
;
820 help_text
= OptionHelp
;
823 case ASSEMBLE
: help_text
= Help_assemble
; break;
824 case BUILD
: help_text
= Help_build
; break;
825 case CREATE
: help_text
= Help_create
; break;
826 case MANAGE
: help_text
= Help_manage
; break;
827 case MISC
: help_text
= Help_misc
; break;
828 case MONITOR
: help_text
= Help_monitor
; break;
829 case GROW
: help_text
= Help_grow
; break;
831 fputs(help_text
,stderr
);
835 if (!mode
&& devs_found
) {
838 if (devlist
->disposition
== 0)
839 devlist
->disposition
= devmode
;
842 fputs(Usage
, stderr
);
845 /* Ok, got the option parsing out of the way
846 * hopefully it's mostly right but there might be some stuff
849 * That is mosty checked in the per-mode stuff but...
851 * For @,B,C and A without -s, the first device listed must be an md device
852 * we check that here and open it.
855 if (mode
==MANAGE
|| mode
== BUILD
|| mode
== CREATE
|| mode
== GROW
||
856 (mode
== ASSEMBLE
&& ! scan
)) {
857 if (devs_found
< 1) {
858 fprintf(stderr
, Name
": an md device must be given in this mode\n");
861 if ((int)ident
.super_minor
== -2 && autof
) {
862 fprintf(stderr
, Name
": --super-minor=dev is incompatible with --auto\n");
865 mdfd
= open_mddev(devlist
->devname
, autof
);
868 if ((int)ident
.super_minor
== -2) {
871 ident
.super_minor
= minor(stb
.st_rdev
);
876 if (raiddisks
> max_disks
) {
877 fprintf(stderr
, Name
": invalid number of raid devices: %d\n",
881 if (raiddisks
== 1 && !force
&& level
!= -5) {
882 fprintf(stderr
, Name
": '1' is an unusual number of drives for an array, so it is probably\n"
883 " a mistake. If you really mean it you will need to specify --force before\n"
884 " setting the number of drives.\n");
889 if ( sparedisks
> max_disks
- raiddisks
) {
890 fprintf(stderr
, Name
": invalid number of spare-devices: %d\n",
899 /* readonly, add/remove, readwrite, runstop */
901 rv
= Manage_ro(devlist
->devname
, mdfd
, readonly
);
902 if (!rv
&& devs_found
>1)
903 rv
= Manage_subdevs(devlist
->devname
, mdfd
,
904 devlist
->next
, verbose
-quiet
);
905 if (!rv
&& readonly
< 0)
906 rv
= Manage_ro(devlist
->devname
, mdfd
, readonly
);
908 rv
= Manage_runstop(devlist
->devname
, mdfd
, runstop
, 0);
911 if (devs_found
== 1 && ident
.uuid_set
== 0 &&
912 ident
.super_minor
== UnSet
&& ident
.name
[0] == 0 && !scan
) {
913 /* Only a device has been given, so get details from config file */
914 mddev_ident_t array_ident
= conf_get_ident(configfile
, devlist
->devname
);
915 if (array_ident
== NULL
) {
916 fprintf(stderr
, Name
": %s not identified in config file.\n",
920 mdfd
= open_mddev(devlist
->devname
,
921 array_ident
->autof
? array_ident
->autof
: autof
);
925 rv
|= Assemble(ss
, devlist
->devname
, mdfd
, array_ident
, configfile
,
927 readonly
, runstop
, update
, verbose
-quiet
, force
);
932 rv
= Assemble(ss
, devlist
->devname
, mdfd
, &ident
, configfile
,
933 devlist
->next
, backup_file
,
934 readonly
, runstop
, update
, verbose
-quiet
, force
);
935 else if (devs_found
>0) {
936 if (update
&& devs_found
> 1) {
937 fprintf(stderr
, Name
": can only update a single array at a time\n");
940 if (backup_file
&& devs_found
> 1) {
941 fprintf(stderr
, Name
": can only assemble a single array when providing a backup file.\n");
944 for (dv
= devlist
; dv
; dv
=dv
->next
) {
945 mddev_ident_t array_ident
= conf_get_ident(configfile
, dv
->devname
);
946 if (array_ident
== NULL
) {
947 fprintf(stderr
, Name
": %s not identified in config file.\n",
952 mdfd
= open_mddev(dv
->devname
,
953 array_ident
->autof
?array_ident
->autof
: autof
);
958 rv
|= Assemble(ss
, dv
->devname
, mdfd
, array_ident
, configfile
,
960 readonly
, runstop
, update
, verbose
-quiet
, force
);
964 mddev_ident_t array_list
= conf_get_ident(configfile
, NULL
);
966 fprintf(stderr
, Name
": No arrays found in config file\n");
970 fprintf(stderr
, Name
": --update not meaningful with a --scan assembly.\n");
974 fprintf(stderr
, Name
": --backup_file not meaningful with a --scan assembly.\n");
977 for (; array_list
; array_list
= array_list
->next
) {
978 mdu_array_info_t array
;
979 mdfd
= open_mddev(array_list
->devname
,
980 array_list
->autof
? array_list
->autof
: autof
);
985 if (ioctl(mdfd
, GET_ARRAY_INFO
, &array
)>=0)
986 /* already assembled, skip */
989 rv
|= Assemble(ss
, array_list
->devname
, mdfd
,
990 array_list
, configfile
,
992 readonly
, runstop
, NULL
, verbose
-quiet
, force
);
998 if (delay
== 0) delay
= DEFAULT_BITMAP_DELAY
;
999 if (write_behind
&& !bitmap_file
) {
1000 fprintf(stderr
, Name
": write-behind mode requires a bitmap.\n");
1006 if (strcmp(bitmap_file
, "internal")==0) {
1007 fprintf(stderr
, Name
": 'internal' bitmaps not supported with --build\n");
1012 rv
= Build(devlist
->devname
, mdfd
, chunk
, level
, layout
,
1013 raiddisks
, devlist
->next
, assume_clean
,
1014 bitmap_file
, bitmap_chunk
, write_behind
, delay
, verbose
-quiet
);
1017 if (delay
== 0) delay
= DEFAULT_BITMAP_DELAY
;
1018 if (write_behind
&& !bitmap_file
) {
1019 fprintf(stderr
, Name
": write-behind mode requires a bitmap.\n");
1024 rv
= Create(ss
, devlist
->devname
, mdfd
, chunk
, level
, layout
, size
<0 ? 0 : size
,
1025 raiddisks
, sparedisks
, ident
.name
,
1026 devs_found
-1, devlist
->next
, runstop
, verbose
-quiet
, force
, assume_clean
,
1027 bitmap_file
, bitmap_chunk
, write_behind
, delay
);
1031 if (devmode
== 'E') {
1032 if (devlist
== NULL
&& !scan
) {
1033 fprintf(stderr
, Name
": No devices to examine\n");
1036 if (devlist
== NULL
)
1037 devlist
= conf_get_devs(configfile
);
1038 if (devlist
== NULL
) {
1039 fprintf(stderr
, Name
": No devices listed in %s\n", configfile
?configfile
:DefaultConfFile
);
1042 rv
= Examine(devlist
, scan
?(verbose
>1?0:verbose
+1):brief
, scan
, SparcAdjust
, ss
);
1044 if (devlist
== NULL
) {
1045 if (devmode
=='D' && scan
) {
1046 /* apply --detail to all devices in /proc/mdstat */
1047 struct mdstat_ent
*ms
= mdstat_read(0, 1);
1048 struct mdstat_ent
*e
;
1049 for (e
=ms
; e
; e
=e
->next
) {
1050 char *name
= get_md_name(e
->devnum
);
1053 fprintf(stderr
, Name
": cannot find device file for %s\n",
1057 rv
|= Detail(name
, verbose
>1?0:verbose
+1, test
);
1060 } else if (devmode
== 'S' && scan
) {
1061 /* apply --stop to all devices in /proc/mdstat */
1062 /* Due to possible stacking of devices, repeat until
1063 * nothing more can be stopped
1065 int progress
=1, err
;
1068 struct mdstat_ent
*ms
= mdstat_read(0, 0);
1069 struct mdstat_ent
*e
;
1071 if (!progress
) last
= 1;
1072 progress
= 0; err
= 0;
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 mdfd
= open_mddev(name
, 0);
1083 if (Manage_runstop(name
, mdfd
, -1, !last
))
1092 } while (!last
&& err
);
1095 fprintf(stderr
, Name
": No devices given.\n");
1099 for (dv
=devlist
; dv
; dv
=dv
->next
) {
1100 switch(dv
->disposition
) {
1102 rv
|= Detail(dv
->devname
, brief
?1+verbose
:0, test
); continue;
1103 case 'K': /* Zero superblock */
1104 rv
|= Kill(dv
->devname
, force
, quiet
); continue;
1106 rv
|= Query(dv
->devname
); continue;
1108 rv
|= ExamineBitmap(dv
->devname
, brief
, ss
); continue;
1110 mdfd
= open_mddev(dv
->devname
, 0);
1112 switch(dv
->disposition
) {
1114 rv
|= Manage_runstop(dv
->devname
, mdfd
, 1, 0); break;
1116 rv
|= Manage_runstop(dv
->devname
, mdfd
, -1, 0); break;
1118 rv
|= Manage_ro(dv
->devname
, mdfd
, 1); break;
1120 rv
|= Manage_ro(dv
->devname
, mdfd
, -1); break;
1129 if (!devlist
&& !scan
) {
1130 fprintf(stderr
, Name
": Cannot monitor: need --scan or at least one device\n");
1134 if (pidfile
&& !daemonise
) {
1135 fprintf(stderr
, Name
": Cannot write a pid file when not in daemon mode\n");
1139 rv
= Monitor(devlist
, mailaddr
, program
,
1140 delay
?delay
:60, daemonise
, scan
, oneshot
,
1141 dosyslog
, configfile
, test
, pidfile
);
1145 if (devs_found
> 1) {
1148 if (size
>= 0 || raiddisks
) {
1149 fprintf(stderr
, Name
": --size, --raiddisks, and --add are exclusing in --grow mode\n");
1153 for (dv
=devlist
->next
; dv
; dv
=dv
->next
) {
1154 rv
= Grow_Add_device(devlist
->devname
, mdfd
, dv
->devname
);
1158 } else if ((size
>= 0) + (raiddisks
!= 0) + (layout
!= UnSet
) + (bitmap_file
!= NULL
)> 1) {
1159 fprintf(stderr
, Name
": can change at most one of size, raiddisks, bitmap, and layout\n");
1162 } else if (layout
!= UnSet
)
1163 rv
= Manage_reconfig(devlist
->devname
, mdfd
, layout
);
1164 else if (size
>= 0 || raiddisks
)
1165 rv
= Grow_reshape(devlist
->devname
, mdfd
, quiet
, backup_file
,
1166 size
, level
, layout
, chunk
, raiddisks
);
1167 else if (bitmap_file
) {
1168 if (delay
== 0) delay
= DEFAULT_BITMAP_DELAY
;
1169 rv
= Grow_addbitmap(devlist
->devname
, mdfd
, bitmap_file
,
1170 bitmap_chunk
, delay
, write_behind
, force
);
1172 fprintf(stderr
, Name
": no changes to --grow\n");