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 async RAID options, Copyright (C) 2003-2004,
30 * Paul Clements, SteelEye Technology, Inc.
38 int main(int argc
, char *argv
[])
53 int max_disks
= MD_SB_DISKS
;
55 struct mddev_ident_s ident
;
56 char *configfile
= NULL
;
64 char *bitmap_file
= NULL
;
65 int bitmap_chunk
= UnSet
;
67 mddev_dev_t devlist
= NULL
;
68 mddev_dev_t
*devlistend
= & devlist
;
76 int autof
= 0; /* -2 means create device based on name:
77 * if it ends mdN, then non-partitioned array N
78 * if it ends dN, then partitions array N
79 * -1 means create non-partitioned, choose N
80 * 1 or more to create partitioned
81 * If -1 or 1 and name is a 'standard' name, then
82 * insist on a match of type and number.
85 char *mailaddr
= NULL
;
91 struct supertype
*ss
= NULL
;
97 srandom(time(0) ^ getpid());
101 ident
.raid_disks
= UnSet
;
102 ident
.super_minor
= UnSet
;
104 ident
.spare_group
= NULL
;
107 ident
.bitmap_fd
= -1;
109 while ((option_index
= -1) ,
110 (opt
=getopt_long(argc
, argv
,
111 short_options
, long_options
,
112 &option_index
)) != -1) {
114 /* firstly, so mode-independant options */
118 if (option_index
> 0 &&
119 strcmp(long_options
[option_index
].name
, "help-options")==0)
120 help_text
= OptionHelp
;
123 case ASSEMBLE
: help_text
= Help_assemble
; break;
124 case BUILD
: help_text
= Help_build
; break;
125 case CREATE
: help_text
= Help_create
; break;
126 case MANAGE
: help_text
= Help_manage
; break;
127 case MISC
: help_text
= Help_misc
; break;
128 case MONITOR
: help_text
= Help_monitor
; break;
129 case GROW
: help_text
= Help_grow
; break;
131 fputs(help_text
,stderr
);
135 fputs(Version
, stderr
);
142 if (mode
== ASSEMBLE
|| mode
== BUILD
|| mode
== CREATE
|| mode
== GROW
)
143 break; /* b means bitmap */
149 fputs(Usage
, stderr
);
152 /* second, figure out the mode.
153 * Some options force the mode. Others
154 * set the mode if it isn't already
158 case '@': /* just incase they say --manage */
159 newmode
= MANAGE
; break;
163 if (!mode
) newmode
= MANAGE
;
166 case 'A': newmode
= ASSEMBLE
; break;
167 case 'B': newmode
= BUILD
; break;
168 case 'C': newmode
= CREATE
; break;
169 case 'F': newmode
= MONITOR
;break;
170 case 'G': newmode
= GROW
; break;
176 case 'Q': newmode
= MISC
; break;
181 case 'K': if (!mode
) newmode
= MISC
; break;
183 if (mode
&& newmode
== mode
) {
184 /* everybody happy ! */
185 } else if (mode
&& newmode
!= mode
) {
187 fprintf(stderr
, Name
": ");
188 if (option_index
>= 0)
189 fprintf(stderr
, "--%s", long_options
[option_index
].name
);
191 fprintf(stderr
, "-%c", opt
);
192 fprintf(stderr
, " would set mdadm mode to \"%s\", but it is already set to \"%s\".\n",
193 map_num(modes
, newmode
),
194 map_num(modes
, mode
));
196 } else if (!mode
&& newmode
) {
199 /* special case of -c --help */
201 ( strncmp(optarg
, "--h", 3)==0 ||
202 strncmp(optarg
, "-h", 2)==0)) {
203 fputs(Help_config
, stderr
);
207 /* If first option is a device, don't force the mode yet */
209 if (devs_found
== 0) {
210 dv
= malloc(sizeof(*dv
));
212 fprintf(stderr
, Name
": malloc failed\n");
215 dv
->devname
= optarg
;
216 dv
->disposition
= devmode
;
219 devlistend
= &dv
->next
;
224 /* No mode yet, and this is the second device ... */
225 fprintf(stderr
, Name
": An option must be given to set the mode before a second device is listed\n");
228 if (option_index
>= 0)
229 fprintf(stderr
, Name
": --%s", long_options
[option_index
].name
);
231 fprintf(stderr
, Name
": -%c", opt
);
232 fprintf(stderr
, " does not set the mode, and so cannot be the first option.\n");
236 /* if we just set the mode, then done */
248 /* an undecorated option - must be a device name.
250 if (devs_found
> 0 && mode
== '@' && !devmode
) {
251 fprintf(stderr
, Name
": Must give one of -a/-r/-f for subsequent devices at %s\n", optarg
);
254 if (devs_found
> 0 && mode
== 'G' && !devmode
) {
255 fprintf(stderr
, Name
": Must give one of -a for devices do add: %s\n", optarg
);
258 dv
= malloc(sizeof(*dv
));
260 fprintf(stderr
, Name
": malloc failed\n");
263 dv
->devname
= optarg
;
264 dv
->disposition
= devmode
;
267 devlistend
= &dv
->next
;
273 /* We've got a mode, and opt is now something else which
274 * could depend on the mode */
275 #define O(a,b) ((a<<8)|b)
276 switch (O(mode
,opt
)) {
278 case O(BUILD
,'c'): /* chunk or rounding */
280 fprintf(stderr
, Name
": chunk/rounding may only be specified once. "
281 "Second value is %s.\n", optarg
);
284 chunk
= strtol(optarg
, &c
, 10);
285 if (!optarg
[0] || *c
|| chunk
<4 || ((chunk
-1)&chunk
)) {
286 fprintf(stderr
, Name
": invalid chunk/rounding value: %s\n",
293 case O(ASSEMBLE
,'e'):
294 case O(MISC
,'e'): /* set metadata (superblock) information */
296 fprintf(stderr
, Name
": metadata information already given\n");
299 for(i
=0; !ss
&& superlist
[i
]; i
++)
300 ss
= superlist
[i
]->match_metadata_desc(optarg
);
303 fprintf(stderr
, Name
": unrecognised metadata identifier: %s\n", optarg
);
306 max_disks
= ss
->max_devs
;
310 case O(CREATE
,'z'): /* size */
312 fprintf(stderr
, Name
": size may only be specified once. "
313 "Second value is %s.\n", optarg
);
316 if (strcmp(optarg
, "max")==0)
319 size
= strtol(optarg
, &c
, 10);
320 if (!optarg
[0] || *c
|| size
< 4) {
321 fprintf(stderr
, Name
": invalid size: %s\n",
328 case O(GROW
,'l'): /* hack - needed to understand layout */
330 case O(BUILD
,'l'): /* set raid level*/
331 if (level
!= UnSet
) {
332 fprintf(stderr
, Name
": raid level may only be set once. "
333 "Second value is %s.\n", optarg
);
336 level
= map_name(pers
, optarg
);
337 if (level
== UnSet
) {
338 fprintf(stderr
, Name
": invalid raid level: %s\n",
342 if (level
!= 0 && level
!= -1 && level
!= 1 && level
!= -4 && level
!= -5 && mode
== BUILD
) {
343 fprintf(stderr
, Name
": Raid level %s not permitted with --build.\n",
347 if (sparedisks
> 0 && level
< 1 && level
>= -1) {
348 fprintf(stderr
, Name
": raid level %s is incompatible with spare-devices setting.\n",
355 case O(CREATE
,'p'): /* raid5 layout */
356 case O(BUILD
,'p'): /* faulty layout */
357 case O(GROW
, 'p'): /* faulty reconfig */
358 if (layout
!= UnSet
) {
359 fprintf(stderr
,Name
": layout may only be sent once. "
360 "Second value was %s\n", optarg
);
365 fprintf(stderr
, Name
": layout not meaningful for %s arrays.\n",
366 map_num(pers
, level
));
369 fprintf(stderr
, Name
": raid level must be given before layout.\n");
374 layout
= map_name(r5layout
, optarg
);
376 fprintf(stderr
, Name
": layout %s not understood for raid5.\n",
383 /* 'f' or 'n' followed by a number <= raid_disks */
384 if ((optarg
[0] != 'n' && optarg
[0] != 'f') ||
385 (copies
= strtoul(optarg
+1, &cp
, 10)) < 1 ||
388 fprintf(stderr
, Name
": layout for raid10 must be 'nNN' or 'fNN' where NN is a number, not %s\n", optarg
);
391 if (optarg
[0] == 'n')
392 layout
= 256 + copies
;
394 layout
= 1 + (copies
<<8);
401 int ln
= strcspn(optarg
, "0123456789");
402 char *m
= strdup(optarg
);
405 mode
= map_name(faultylayout
, m
);
407 fprintf(stderr
, Name
": layout %s not understood for faulty.\n",
411 layout
= mode
| (atoi(optarg
+ln
)<< ModeShift
);
417 case O(BUILD
,3): /* assume clean */
423 case O(BUILD
,'n'): /* number of raid disks */
425 fprintf(stderr
, Name
": raid-devices set twice: %d and %s\n",
429 raiddisks
= strtol(optarg
, &c
, 10);
430 if (!optarg
[0] || *c
|| raiddisks
<=0) {
431 fprintf(stderr
, Name
": invalid number of raid devices: %s\n",
435 ident
.raid_disks
= raiddisks
;
438 case O(CREATE
,'x'): /* number of spare (eXtra) discs */
440 fprintf(stderr
,Name
": spare-devices set twice: %d and %s\n",
444 if (level
!= UnSet
&& level
<= 0 && level
>= -1) {
445 fprintf(stderr
, Name
": spare-devices setting is incompatible with raid level %d\n",
449 sparedisks
= strtol(optarg
, &c
, 10);
450 if (!optarg
[0] || *c
|| sparedisks
< 0) {
451 fprintf(stderr
, Name
": invalid number of spare-devices: %s\n",
459 case O(ASSEMBLE
,'a'): /* auto-creation of device node */
462 else if (strcasecmp(optarg
,"no")==0)
464 else if (strcasecmp(optarg
,"yes")==0)
466 else if (strcasecmp(optarg
,"md")==0)
469 /* There might be digits, and maybe a hypen, at the end */
470 char *e
= optarg
+ strlen(optarg
);
473 while (e
> optarg
&& isdigit(e
[-1]))
477 if (num
<= 0) num
= 1;
479 if (e
> optarg
&& e
[-1] == '-')
482 if ((len
== 3 && strncasecmp(optarg
,"mdp",3)==0) ||
483 (len
== 1 && strncasecmp(optarg
,"p",1)==0) ||
484 (len
>= 4 && strncasecmp(optarg
,"part",4)==0))
487 fprintf(stderr
, Name
": --auto flag arg of \"%s\" unrecognised: use no,yes,md,mdp,part\n"
488 " optionally followed by a number.\n",
495 case O(BUILD
,'f'): /* force honouring '-n 1' */
496 case O(GROW
,'f'): /* ditto */
497 case O(CREATE
,'f'): /* force honouring of device list */
498 case O(ASSEMBLE
,'f'): /* force assembly */
499 case O(MISC
,'f'): /* force zero */
503 /* now for the Assemble options */
504 case O(ASSEMBLE
,'u'): /* uuid of array */
505 if (ident
.uuid_set
) {
506 fprintf(stderr
, Name
": uuid cannot be set twice. "
507 "Second value %s.\n", optarg
);
510 if (parse_uuid(optarg
, ident
.uuid
))
513 fprintf(stderr
,Name
": Bad uuid: %s\n", optarg
);
518 case O(ASSEMBLE
,'m'): /* super-minor for array */
519 if (ident
.super_minor
!= UnSet
) {
520 fprintf(stderr
, Name
": super-minor cannot be set twice. "
521 "Second value: %s.\n", optarg
);
524 if (strcmp(optarg
, "dev")==0)
525 ident
.super_minor
= -2;
527 ident
.super_minor
= strtoul(optarg
, &cp
, 10);
528 if (!optarg
[0] || *cp
) {
529 fprintf(stderr
, Name
": Bad super-minor number: %s.\n", optarg
);
535 case O(ASSEMBLE
,'U'): /* update the superblock */
537 fprintf(stderr
, Name
": Can only update one aspect of superblock, both %s and %s given.\n",
542 if (strcmp(update
, "sparc2.2")==0)
544 if (strcmp(update
, "super-minor") == 0)
546 if (strcmp(update
, "summaries")==0)
548 if (strcmp(update
, "resync")==0)
550 fprintf(stderr
, Name
": '--update %s' invalid. Only 'sparc2.2', 'super-minor', 'resync' or 'summaries' supported\n",update
);
553 case O(ASSEMBLE
,'c'): /* config file */
557 fprintf(stderr
, Name
": configfile cannot be set twice. "
558 "Second value is %s.\n", optarg
);
562 /* FIXME possibly check that config file exists. Even parse it */
564 case O(ASSEMBLE
,'s'): /* scan */
570 case O(MONITOR
,'m'): /* mail address */
572 fprintf(stderr
, Name
": only specify one mailaddress. %s ignored.\n",
578 case O(MONITOR
,'p'): /* alert program */
580 fprintf(stderr
, Name
": only specify one alter program. %s ignored.\n",
586 case O(MONITOR
,'d'): /* delay in seconds */
588 case O(BUILD
,'d'): /* delay for bitmap updates */
591 fprintf(stderr
, Name
": only specify delay once. %s ignored.\n",
594 delay
= strtol(optarg
, &c
, 10);
595 if (!optarg
[0] || *c
|| delay
<1) {
596 fprintf(stderr
, Name
": invalid delay: %s\n",
602 case O(MONITOR
,'f'): /* daemonise */
605 case O(MONITOR
,'i'): /* pid */
607 fprintf(stderr
, Name
": only specify one pid file. %s ignored.\n",
612 case O(MONITOR
,'1'): /* oneshot */
615 case O(MONITOR
,'t'): /* test */
619 /* now the general management options. Some are applicable
620 * to other modes. None have arguments.
623 case O(MANAGE
,'a'): /* add a drive */
626 case O(MANAGE
,'r'): /* remove a drive */
629 case O(MANAGE
,'f'): /* set faulty */
633 case O(ASSEMBLE
,'R'):
635 case O(CREATE
,'R'): /* Run the array */
637 fprintf(stderr
, Name
": Cannot both Stop and Run an array\n");
644 fprintf(stderr
, Name
": Cannot both Run and Stop an array\n");
652 fprintf(stderr
, Name
": Cannot have both readonly and readwrite\n");
659 fprintf(stderr
, Name
": Cannot have both readwrite and readonly.\n");
674 if (devmode
&& devmode
!= opt
&&
675 (devmode
== 'E' || (opt
== 'E' && devmode
!= 'Q'))) {
676 fprintf(stderr
, Name
": --examine/-E cannot be given with -%c\n",
677 devmode
=='E'?opt
:devmode
);
687 if (devmode
!= 'E') {
688 fprintf(stderr
, Name
": --sparc2.2 only allowed with --examine\n");
694 case O(ASSEMBLE
,'b'): /* here we simply set the bitmap file */
696 fprintf(stderr
, Name
": bitmap file needed with -b in --assemble mode\n");
699 if (strcmp(optarg
, "internal")==0) {
700 fprintf(stderr
, Name
": there is no need to specify --bitmap when assembling arrays with internal bitmaps\n");
703 bitmap_fd
= open(optarg
, O_RDWR
);
704 if (!*optarg
|| bitmap_fd
< 0) {
705 fprintf(stderr
, Name
": cannot open bitmap file %s: %s\n", optarg
, strerror(errno
));
708 ident
.bitmap_fd
= bitmap_fd
; /* for Assemble */
713 case O(CREATE
,'b'): /* here we create the bitmap */
714 bitmap_file
= optarg
;
719 case O(CREATE
,4): /* bitmap chunksize */
720 bitmap_chunk
= strtol(optarg
, &c
, 10);
721 if (!optarg
[0] || *c
|| bitmap_chunk
< 0 ||
722 bitmap_chunk
& (bitmap_chunk
- 1)) {
723 fprintf(stderr
, Name
": invalid bitmap chunksize: %s\n",
727 /* convert K to B, chunk of 0K means 512B */
728 bitmap_chunk
= bitmap_chunk
? bitmap_chunk
* 1024 : 512;
731 /* We have now processed all the valid options. Anything else is
734 fprintf(stderr
, Name
": option %c not valid in %s mode\n",
735 opt
, map_num(modes
, mode
));
740 if (!mode
&& devs_found
) {
743 if (devlist
->disposition
== 0)
744 devlist
->disposition
= devmode
;
747 fputs(Usage
, stderr
);
750 /* Ok, got the option parsing out of the way
751 * hopefully it's mostly right but there might be some stuff
754 * That is mosty checked in the per-mode stuff but...
756 * For @,B,C and A without -s, the first device listed must be an md device
757 * we check that here and open it.
760 if (mode
==MANAGE
|| mode
== BUILD
|| mode
== CREATE
|| mode
== GROW
||
761 (mode
== ASSEMBLE
&& ! scan
)) {
762 if (devs_found
< 1) {
763 fprintf(stderr
, Name
": an md device must be given in this mode\n");
766 if ((int)ident
.super_minor
== -2 && autof
) {
767 fprintf(stderr
, Name
": --super-minor=dev is incompatible with --auto\n");
770 mdfd
= open_mddev(devlist
->devname
, autof
);
773 if ((int)ident
.super_minor
== -2) {
776 ident
.super_minor
= minor(stb
.st_rdev
);
781 if (raiddisks
> max_disks
) {
782 fprintf(stderr
, Name
": invalid number of raid devices: %d\n",
786 if (raiddisks
== 1 && !force
&& level
!= -5) {
787 fprintf(stderr
, Name
": '1' is an unusual number of drives for an array, so it is probably\n"
788 " a mistake. If you really mean it you will need to specify --force before\n"
789 " setting the number of drives.\n");
794 if ( sparedisks
> max_disks
- raiddisks
) {
795 fprintf(stderr
, Name
": invalid number of spare-devices: %d\n",
804 /* readonly, add/remove, readwrite, runstop */
806 rv
= Manage_ro(devlist
->devname
, mdfd
, readonly
);
807 if (!rv
&& devs_found
>1)
808 rv
= Manage_subdevs(devlist
->devname
, mdfd
,
810 if (!rv
&& readonly
< 0)
811 rv
= Manage_ro(devlist
->devname
, mdfd
, readonly
);
813 rv
= Manage_runstop(devlist
->devname
, mdfd
, runstop
, 0);
816 if (devs_found
== 1 && ident
.uuid_set
== 0 &&
817 ident
.super_minor
== UnSet
&& !scan
) {
818 /* Only a device has been given, so get details from config file */
819 mddev_ident_t array_ident
= conf_get_ident(configfile
, devlist
->devname
);
820 if (array_ident
== NULL
) {
821 fprintf(stderr
, Name
": %s not identified in config file.\n",
825 mdfd
= open_mddev(devlist
->devname
,
826 array_ident
->autof
? array_ident
->autof
: autof
);
830 rv
|= Assemble(ss
, devlist
->devname
, mdfd
, array_ident
, configfile
,
832 readonly
, runstop
, update
, verbose
, force
);
837 rv
= Assemble(ss
, devlist
->devname
, mdfd
, &ident
, configfile
,
839 readonly
, runstop
, update
, verbose
, force
);
840 else if (devs_found
>0) {
841 if (update
&& devs_found
> 1) {
842 fprintf(stderr
, Name
": can only update a single array at a time\n");
845 for (dv
= devlist
; dv
; dv
=dv
->next
) {
846 mddev_ident_t array_ident
= conf_get_ident(configfile
, dv
->devname
);
847 if (array_ident
== NULL
) {
848 fprintf(stderr
, Name
": %s not identified in config file.\n",
853 mdfd
= open_mddev(dv
->devname
,
854 array_ident
->autof
?array_ident
->autof
: autof
);
859 rv
|= Assemble(ss
, dv
->devname
, mdfd
, array_ident
, configfile
,
861 readonly
, runstop
, update
, verbose
, force
);
865 mddev_ident_t array_list
= conf_get_ident(configfile
, NULL
);
867 fprintf(stderr
, Name
": No arrays found in config file\n");
870 for (; array_list
; array_list
= array_list
->next
) {
871 mdu_array_info_t array
;
872 mdfd
= open_mddev(array_list
->devname
,
873 array_list
->autof
? array_list
->autof
: autof
);
878 if (ioctl(mdfd
, GET_ARRAY_INFO
, &array
)>=0)
879 /* already assembled, skip */
882 rv
|= Assemble(ss
, array_list
->devname
, mdfd
,
883 array_list
, configfile
,
885 readonly
, runstop
, NULL
, verbose
, force
);
891 if (bitmap_chunk
== UnSet
) bitmap_chunk
= DEFAULT_BITMAP_CHUNK
;
892 if (delay
== 0) delay
= DEFAULT_BITMAP_DELAY
;
894 if (strcmp(bitmap_file
, "internal")==0) {
895 fprintf(stderr
, Name
": 'internal' bitmaps not supported with --build\n");
899 bitmap_fd
= open(bitmap_file
, O_RDWR
,0);
900 if (bitmap_fd
< 0 && errno
!= ENOENT
) {
901 perror(Name
": cannot create bitmap file");
906 bitmap_fd
= CreateBitmap(bitmap_file
, force
, NULL
,
907 bitmap_chunk
, delay
, size
);
910 rv
= Build(devlist
->devname
, mdfd
, chunk
, level
, layout
,
911 raiddisks
, devlist
->next
, assume_clean
,
912 bitmap_file
, bitmap_chunk
, delay
);
915 if (delay
== 0) delay
= DEFAULT_BITMAP_DELAY
;
917 for(i
=0; !ss
&& superlist
[i
]; i
++)
918 ss
= superlist
[i
]->match_metadata_desc("default");
921 fprintf(stderr
, Name
": internal error - no default metadata style\n");
925 rv
= Create(ss
, devlist
->devname
, mdfd
, chunk
, level
, layout
, size
<0 ? 0 : size
,
926 raiddisks
, sparedisks
,
927 devs_found
-1, devlist
->next
, runstop
, verbose
, force
,
928 bitmap_file
, bitmap_chunk
, delay
);
932 if (devmode
== 'E') {
933 if (devlist
== NULL
&& !scan
) {
934 fprintf(stderr
, Name
": No devices to examine\n");
938 devlist
= conf_get_devs(configfile
);
939 if (devlist
== NULL
) {
940 fprintf(stderr
, Name
": No devices listed in %s\n", configfile
?configfile
:DefaultConfFile
);
943 rv
= Examine(devlist
, scan
?(verbose
>1?0:verbose
+1):brief
, scan
, SparcAdjust
, ss
);
945 if (devlist
== NULL
) {
946 if (devmode
=='D' && scan
) {
947 /* apply --detail to all devices in /proc/mdstat */
948 struct mdstat_ent
*ms
= mdstat_read(0);
949 struct mdstat_ent
*e
;
950 for (e
=ms
; e
; e
=e
->next
) {
951 char *name
= get_md_name(e
->devnum
);
954 fprintf(stderr
, Name
": cannot find device file for %s\n",
958 rv
|= Detail(name
, verbose
>1?0:verbose
+1, test
);
961 } else if (devmode
== 'S' && scan
) {
962 /* apply --stop to all devices in /proc/mdstat */
963 /* Due to possible stacking of devices, repeat until
964 * nothing more can be stopped
969 struct mdstat_ent
*ms
= mdstat_read(0);
970 struct mdstat_ent
*e
;
972 if (!progress
) last
= 1;
973 progress
= 0; err
= 0;
974 for (e
=ms
; e
; e
=e
->next
) {
975 char *name
= get_md_name(e
->devnum
);
978 fprintf(stderr
, Name
": cannot find device file for %s\n",
982 mdfd
= open_mddev(name
, 0);
984 if (Manage_runstop(name
, mdfd
, -1, !last
))
993 } while (!last
&& err
);
995 fprintf(stderr
, Name
": No devices given.\n");
999 for (dv
=devlist
; dv
; dv
=dv
->next
) {
1000 switch(dv
->disposition
) {
1002 rv
|= Detail(dv
->devname
, brief
?1+verbose
:0, test
); continue;
1003 case 'K': /* Zero superblock */
1004 rv
|= Kill(dv
->devname
, force
); continue;
1006 rv
|= Query(dv
->devname
); continue;
1008 rv
|= ExamineBitmap(dv
->devname
, brief
, ss
); continue;
1010 mdfd
= open_mddev(dv
->devname
, 0);
1012 switch(dv
->disposition
) {
1014 rv
|= Manage_runstop(dv
->devname
, mdfd
, 1, 0); break;
1016 rv
|= Manage_runstop(dv
->devname
, mdfd
, -1, 0); break;
1018 rv
|= Manage_ro(dv
->devname
, mdfd
, 1); break;
1020 rv
|= Manage_ro(dv
->devname
, mdfd
, -1); break;
1028 if (!devlist
&& !scan
) {
1029 fprintf(stderr
, Name
": Cannot monitor: need --scan or at least one device\n");
1033 if (pidfile
&& !daemonise
) {
1034 fprintf(stderr
, Name
": Cannot write a pid file when not in daemon mode\n");
1038 rv
= Monitor(devlist
, mailaddr
, program
,
1039 delay
?delay
:60, daemonise
, scan
, oneshot
, configfile
, test
, pidfile
);
1043 if (devs_found
> 1) {
1046 if (size
>= 0 || raiddisks
) {
1047 fprintf(stderr
, Name
": --size, --raiddisks, and --add are exclusing in --grow mode\n");
1051 for (dv
=devlist
->next
; dv
; dv
=dv
->next
) {
1052 rv
= Grow_Add_device(devlist
->devname
, mdfd
, dv
->devname
);
1056 } else if ((size
>= 0) + (raiddisks
!= 0) + (layout
!= UnSet
) + (bitmap_file
!= NULL
)> 1) {
1057 fprintf(stderr
, Name
": can change at most one of size, raiddisks, bitmap, and layout\n");
1060 } else if (layout
!= UnSet
)
1061 rv
= Manage_reconfig(devlist
->devname
, mdfd
, layout
);
1062 else if (size
>= 0 || raiddisks
)
1063 rv
= Manage_resize(devlist
->devname
, mdfd
, size
, raiddisks
);
1064 else if (bitmap_file
) {
1065 if (delay
== 0) delay
= DEFAULT_BITMAP_DELAY
;
1066 rv
= Grow_addbitmap(devlist
->devname
, mdfd
, bitmap_file
,
1067 bitmap_chunk
, delay
);
1069 fprintf(stderr
, Name
": no changes to --grow\n");