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
[])
53 int max_disks
= MD_SB_DISKS
;
55 struct mddev_ident_s ident
;
56 char *configfile
= NULL
;
65 char *bitmap_file
= NULL
;
66 int bitmap_chunk
= UnSet
;
68 mddev_dev_t devlist
= NULL
;
69 mddev_dev_t
*devlistend
= & devlist
;
77 int autof
= 0; /* -2 means create device based on name:
78 * if it ends mdN, then non-partitioned array N
79 * if it ends dN, then partitions array N
80 * -1 means create non-partitioned, choose N
81 * 1 or more to create partitioned
82 * If -1 or 1 and name is a 'standard' name, then
83 * insist on a match of type and number.
86 char *mailaddr
= NULL
;
92 struct supertype
*ss
= NULL
;
99 srandom(time(0) ^ getpid());
103 ident
.raid_disks
= UnSet
;
104 ident
.super_minor
= UnSet
;
106 ident
.spare_group
= NULL
;
109 ident
.bitmap_fd
= -1;
111 while ((option_index
= -1) ,
112 (opt
=getopt_long(argc
, argv
,
113 short_options
, long_options
,
114 &option_index
)) != -1) {
116 /* firstly, so mode-independant options */
120 if (option_index
> 0 &&
121 strcmp(long_options
[option_index
].name
, "help-options")==0)
122 help_text
= OptionHelp
;
125 case ASSEMBLE
: help_text
= Help_assemble
; break;
126 case BUILD
: help_text
= Help_build
; break;
127 case CREATE
: help_text
= Help_create
; break;
128 case MANAGE
: help_text
= Help_manage
; break;
129 case MISC
: help_text
= Help_misc
; break;
130 case MONITOR
: help_text
= Help_monitor
; break;
131 case GROW
: help_text
= Help_grow
; break;
133 fputs(help_text
,stderr
);
137 fputs(Version
, stderr
);
144 if (mode
== ASSEMBLE
|| mode
== BUILD
|| mode
== CREATE
|| mode
== GROW
)
145 break; /* b means bitmap */
151 fputs(Usage
, stderr
);
154 /* second, figure out the mode.
155 * Some options force the mode. Others
156 * set the mode if it isn't already
160 case '@': /* just incase they say --manage */
161 newmode
= MANAGE
; break;
165 if (!mode
) newmode
= MANAGE
;
168 case 'A': newmode
= ASSEMBLE
; break;
169 case 'B': newmode
= BUILD
; break;
170 case 'C': newmode
= CREATE
; break;
171 case 'F': newmode
= MONITOR
;break;
172 case 'G': newmode
= GROW
; break;
178 case 'Q': newmode
= MISC
; break;
183 case 'K': if (!mode
) newmode
= MISC
; break;
185 if (mode
&& newmode
== mode
) {
186 /* everybody happy ! */
187 } else if (mode
&& newmode
!= mode
) {
189 fprintf(stderr
, Name
": ");
190 if (option_index
>= 0)
191 fprintf(stderr
, "--%s", long_options
[option_index
].name
);
193 fprintf(stderr
, "-%c", opt
);
194 fprintf(stderr
, " would set mdadm mode to \"%s\", but it is already set to \"%s\".\n",
195 map_num(modes
, newmode
),
196 map_num(modes
, mode
));
198 } else if (!mode
&& newmode
) {
201 /* special case of -c --help */
203 ( strncmp(optarg
, "--h", 3)==0 ||
204 strncmp(optarg
, "-h", 2)==0)) {
205 fputs(Help_config
, stderr
);
209 /* If first option is a device, don't force the mode yet */
211 if (devs_found
== 0) {
212 dv
= malloc(sizeof(*dv
));
214 fprintf(stderr
, Name
": malloc failed\n");
217 dv
->devname
= optarg
;
218 dv
->disposition
= devmode
;
219 dv
->writemostly
= writemostly
;
222 devlistend
= &dv
->next
;
227 /* No mode yet, and this is the second device ... */
228 fprintf(stderr
, Name
": An option must be given to set the mode before a second device is listed\n");
231 if (option_index
>= 0)
232 fprintf(stderr
, Name
": --%s", long_options
[option_index
].name
);
234 fprintf(stderr
, Name
": -%c", opt
);
235 fprintf(stderr
, " does not set the mode, and so cannot be the first option.\n");
239 /* if we just set the mode, then done */
251 /* an undecorated option - must be a device name.
253 if (devs_found
> 0 && mode
== '@' && !devmode
) {
254 fprintf(stderr
, Name
": Must give one of -a/-r/-f for subsequent devices at %s\n", optarg
);
257 if (devs_found
> 0 && mode
== 'G' && !devmode
) {
258 fprintf(stderr
, Name
": Must give one of -a for devices do add: %s\n", optarg
);
261 dv
= malloc(sizeof(*dv
));
263 fprintf(stderr
, Name
": malloc failed\n");
266 dv
->devname
= optarg
;
267 dv
->disposition
= devmode
;
268 dv
->writemostly
= writemostly
;
271 devlistend
= &dv
->next
;
277 /* We've got a mode, and opt is now something else which
278 * could depend on the mode */
279 #define O(a,b) ((a<<8)|b)
280 switch (O(mode
,opt
)) {
282 case O(BUILD
,'c'): /* chunk or rounding */
284 fprintf(stderr
, Name
": chunk/rounding may only be specified once. "
285 "Second value is %s.\n", optarg
);
288 chunk
= strtol(optarg
, &c
, 10);
289 if (!optarg
[0] || *c
|| chunk
<4 || ((chunk
-1)&chunk
)) {
290 fprintf(stderr
, Name
": invalid chunk/rounding value: %s\n",
297 case O(ASSEMBLE
,'e'):
298 case O(MISC
,'e'): /* set metadata (superblock) information */
300 fprintf(stderr
, Name
": metadata information already given\n");
303 for(i
=0; !ss
&& superlist
[i
]; i
++)
304 ss
= superlist
[i
]->match_metadata_desc(optarg
);
307 fprintf(stderr
, Name
": unrecognised metadata identifier: %s\n", optarg
);
310 max_disks
= ss
->max_devs
;
316 /* set write-mostly for following devices */
321 case O(CREATE
,'z'): /* size */
323 fprintf(stderr
, Name
": size may only be specified once. "
324 "Second value is %s.\n", optarg
);
327 if (strcmp(optarg
, "max")==0)
330 size
= strtol(optarg
, &c
, 10);
331 if (!optarg
[0] || *c
|| size
< 4) {
332 fprintf(stderr
, Name
": invalid size: %s\n",
339 case O(GROW
,'l'): /* hack - needed to understand layout */
341 case O(BUILD
,'l'): /* set raid level*/
342 if (level
!= UnSet
) {
343 fprintf(stderr
, Name
": raid level may only be set once. "
344 "Second value is %s.\n", optarg
);
347 level
= map_name(pers
, optarg
);
348 if (level
== UnSet
) {
349 fprintf(stderr
, Name
": invalid raid level: %s\n",
353 if (level
!= 0 && level
!= -1 && level
!= 1 && level
!= -4 && level
!= -5 && mode
== BUILD
) {
354 fprintf(stderr
, Name
": Raid level %s not permitted with --build.\n",
358 if (sparedisks
> 0 && level
< 1 && level
>= -1) {
359 fprintf(stderr
, Name
": raid level %s is incompatible with spare-devices setting.\n",
366 case O(CREATE
,'p'): /* raid5 layout */
367 case O(BUILD
,'p'): /* faulty layout */
368 case O(GROW
, 'p'): /* faulty reconfig */
369 if (layout
!= UnSet
) {
370 fprintf(stderr
,Name
": layout may only be sent once. "
371 "Second value was %s\n", optarg
);
376 fprintf(stderr
, Name
": layout not meaningful for %s arrays.\n",
377 map_num(pers
, level
));
380 fprintf(stderr
, Name
": raid level must be given before layout.\n");
385 layout
= map_name(r5layout
, optarg
);
387 fprintf(stderr
, Name
": layout %s not understood for raid5.\n",
394 /* 'f' or 'n' followed by a number <= raid_disks */
395 if ((optarg
[0] != 'n' && optarg
[0] != 'f') ||
396 (copies
= strtoul(optarg
+1, &cp
, 10)) < 1 ||
399 fprintf(stderr
, Name
": layout for raid10 must be 'nNN' or 'fNN' where NN is a number, not %s\n", optarg
);
402 if (optarg
[0] == 'n')
403 layout
= 256 + copies
;
405 layout
= 1 + (copies
<<8);
412 int ln
= strcspn(optarg
, "0123456789");
413 char *m
= strdup(optarg
);
416 mode
= map_name(faultylayout
, m
);
418 fprintf(stderr
, Name
": layout %s not understood for faulty.\n",
422 layout
= mode
| (atoi(optarg
+ln
)<< ModeShift
);
428 case O(BUILD
,3): /* assume clean */
434 case O(BUILD
,'n'): /* number of raid disks */
436 fprintf(stderr
, Name
": raid-devices set twice: %d and %s\n",
440 raiddisks
= strtol(optarg
, &c
, 10);
441 if (!optarg
[0] || *c
|| raiddisks
<=0) {
442 fprintf(stderr
, Name
": invalid number of raid devices: %s\n",
446 ident
.raid_disks
= raiddisks
;
449 case O(CREATE
,'x'): /* number of spare (eXtra) discs */
451 fprintf(stderr
,Name
": spare-devices set twice: %d and %s\n",
455 if (level
!= UnSet
&& level
<= 0 && level
>= -1) {
456 fprintf(stderr
, Name
": spare-devices setting is incompatible with raid level %d\n",
460 sparedisks
= strtol(optarg
, &c
, 10);
461 if (!optarg
[0] || *c
|| sparedisks
< 0) {
462 fprintf(stderr
, Name
": invalid number of spare-devices: %s\n",
470 case O(ASSEMBLE
,'a'): /* auto-creation of device node */
473 else if (strcasecmp(optarg
,"no")==0)
475 else if (strcasecmp(optarg
,"yes")==0)
477 else if (strcasecmp(optarg
,"md")==0)
480 /* There might be digits, and maybe a hypen, at the end */
481 char *e
= optarg
+ strlen(optarg
);
484 while (e
> optarg
&& isdigit(e
[-1]))
488 if (num
<= 0) num
= 1;
490 if (e
> optarg
&& e
[-1] == '-')
493 if ((len
== 3 && strncasecmp(optarg
,"mdp",3)==0) ||
494 (len
== 1 && strncasecmp(optarg
,"p",1)==0) ||
495 (len
>= 4 && strncasecmp(optarg
,"part",4)==0))
498 fprintf(stderr
, Name
": --auto flag arg of \"%s\" unrecognised: use no,yes,md,mdp,part\n"
499 " optionally followed by a number.\n",
506 case O(BUILD
,'f'): /* force honouring '-n 1' */
507 case O(GROW
,'f'): /* ditto */
508 case O(CREATE
,'f'): /* force honouring of device list */
509 case O(ASSEMBLE
,'f'): /* force assembly */
510 case O(MISC
,'f'): /* force zero */
514 /* now for the Assemble options */
515 case O(ASSEMBLE
,'u'): /* uuid of array */
516 if (ident
.uuid_set
) {
517 fprintf(stderr
, Name
": uuid cannot be set twice. "
518 "Second value %s.\n", optarg
);
521 if (parse_uuid(optarg
, ident
.uuid
))
524 fprintf(stderr
,Name
": Bad uuid: %s\n", 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
, "byteorder")==0) {
563 fprintf(stderr
, Name
": must not set metadata type with --update=byteorder.\n");
566 for(i
=0; !ss
&& superlist
[i
]; i
++)
567 ss
= superlist
[i
]->match_metadata_desc("0.swap");
569 fprintf(stderr
, Name
": INTERNAL ERROR cannot find 0.swap\n");
575 fprintf(stderr
, Name
": '--update %s' invalid. Only 'sparc2.2', 'super-minor', 'resync' or 'summaries' supported\n",update
);
578 case O(ASSEMBLE
,'c'): /* config file */
582 fprintf(stderr
, Name
": configfile cannot be set twice. "
583 "Second value is %s.\n", optarg
);
587 /* FIXME possibly check that config file exists. Even parse it */
589 case O(ASSEMBLE
,'s'): /* scan */
595 case O(MONITOR
,'m'): /* mail address */
597 fprintf(stderr
, Name
": only specify one mailaddress. %s ignored.\n",
603 case O(MONITOR
,'p'): /* alert program */
605 fprintf(stderr
, Name
": only specify one alter program. %s ignored.\n",
611 case O(MONITOR
,'d'): /* delay in seconds */
613 case O(BUILD
,'d'): /* delay for bitmap updates */
616 fprintf(stderr
, Name
": only specify delay once. %s ignored.\n",
619 delay
= strtol(optarg
, &c
, 10);
620 if (!optarg
[0] || *c
|| delay
<1) {
621 fprintf(stderr
, Name
": invalid delay: %s\n",
627 case O(MONITOR
,'f'): /* daemonise */
630 case O(MONITOR
,'i'): /* pid */
632 fprintf(stderr
, Name
": only specify one pid file. %s ignored.\n",
637 case O(MONITOR
,'1'): /* oneshot */
640 case O(MONITOR
,'t'): /* test */
644 /* now the general management options. Some are applicable
645 * to other modes. None have arguments.
648 case O(MANAGE
,'a'): /* add a drive */
651 case O(MANAGE
,'r'): /* remove a drive */
654 case O(MANAGE
,'f'): /* set faulty */
658 case O(ASSEMBLE
,'R'):
660 case O(CREATE
,'R'): /* Run the array */
662 fprintf(stderr
, Name
": Cannot both Stop and Run an array\n");
669 fprintf(stderr
, Name
": Cannot both Run and Stop an array\n");
677 fprintf(stderr
, Name
": Cannot have both readonly and readwrite\n");
684 fprintf(stderr
, Name
": Cannot have both readwrite and readonly.\n");
699 if (devmode
&& devmode
!= opt
&&
700 (devmode
== 'E' || (opt
== 'E' && devmode
!= 'Q'))) {
701 fprintf(stderr
, Name
": --examine/-E cannot be given with -%c\n",
702 devmode
=='E'?opt
:devmode
);
712 if (devmode
!= 'E') {
713 fprintf(stderr
, Name
": --sparc2.2 only allowed with --examine\n");
719 case O(ASSEMBLE
,'b'): /* here we simply set the bitmap file */
721 fprintf(stderr
, Name
": bitmap file needed with -b in --assemble mode\n");
724 if (strcmp(optarg
, "internal")==0) {
725 fprintf(stderr
, Name
": there is no need to specify --bitmap when assembling arrays with internal bitmaps\n");
728 bitmap_fd
= open(optarg
, O_RDWR
);
729 if (!*optarg
|| bitmap_fd
< 0) {
730 fprintf(stderr
, Name
": cannot open bitmap file %s: %s\n", optarg
, strerror(errno
));
733 ident
.bitmap_fd
= bitmap_fd
; /* for Assemble */
738 case O(CREATE
,'b'): /* here we create the bitmap */
739 bitmap_file
= optarg
;
744 case O(CREATE
,4): /* bitmap chunksize */
745 bitmap_chunk
= strtol(optarg
, &c
, 10);
746 if (!optarg
[0] || *c
|| bitmap_chunk
< 0 ||
747 bitmap_chunk
& (bitmap_chunk
- 1)) {
748 fprintf(stderr
, Name
": invalid bitmap chunksize: %s\n",
752 /* convert K to B, chunk of 0K means 512B */
753 bitmap_chunk
= bitmap_chunk
? bitmap_chunk
* 1024 : 512;
757 case O(CREATE
, 5): /* write-behind mode */
758 write_behind
= DEFAULT_MAX_WRITE_BEHIND
;
760 write_behind
= strtol(optarg
, &c
, 10);
761 if (write_behind
< 0 || *c
||
762 write_behind
> 16383) {
763 fprintf(stderr
, Name
": Invalid value for maximum outstanding write-behind writes: %s.\n\tMust be between 0 and 16383.\n", optarg
);
769 /* We have now processed all the valid options. Anything else is
772 fprintf(stderr
, Name
": option %c not valid in %s mode\n",
773 opt
, map_num(modes
, mode
));
778 if (!mode
&& devs_found
) {
781 if (devlist
->disposition
== 0)
782 devlist
->disposition
= devmode
;
785 fputs(Usage
, stderr
);
788 /* Ok, got the option parsing out of the way
789 * hopefully it's mostly right but there might be some stuff
792 * That is mosty checked in the per-mode stuff but...
794 * For @,B,C and A without -s, the first device listed must be an md device
795 * we check that here and open it.
798 if (mode
==MANAGE
|| mode
== BUILD
|| mode
== CREATE
|| mode
== GROW
||
799 (mode
== ASSEMBLE
&& ! scan
)) {
800 if (devs_found
< 1) {
801 fprintf(stderr
, Name
": an md device must be given in this mode\n");
804 if ((int)ident
.super_minor
== -2 && autof
) {
805 fprintf(stderr
, Name
": --super-minor=dev is incompatible with --auto\n");
808 mdfd
= open_mddev(devlist
->devname
, autof
);
811 if ((int)ident
.super_minor
== -2) {
814 ident
.super_minor
= minor(stb
.st_rdev
);
819 if (raiddisks
> max_disks
) {
820 fprintf(stderr
, Name
": invalid number of raid devices: %d\n",
824 if (raiddisks
== 1 && !force
&& level
!= -5) {
825 fprintf(stderr
, Name
": '1' is an unusual number of drives for an array, so it is probably\n"
826 " a mistake. If you really mean it you will need to specify --force before\n"
827 " setting the number of drives.\n");
832 if ( sparedisks
> max_disks
- raiddisks
) {
833 fprintf(stderr
, Name
": invalid number of spare-devices: %d\n",
842 /* readonly, add/remove, readwrite, runstop */
844 rv
= Manage_ro(devlist
->devname
, mdfd
, readonly
);
845 if (!rv
&& devs_found
>1)
846 rv
= Manage_subdevs(devlist
->devname
, mdfd
,
848 if (!rv
&& readonly
< 0)
849 rv
= Manage_ro(devlist
->devname
, mdfd
, readonly
);
851 rv
= Manage_runstop(devlist
->devname
, mdfd
, runstop
, 0);
854 if (devs_found
== 1 && ident
.uuid_set
== 0 &&
855 ident
.super_minor
== UnSet
&& !scan
) {
856 /* Only a device has been given, so get details from config file */
857 mddev_ident_t array_ident
= conf_get_ident(configfile
, devlist
->devname
);
858 if (array_ident
== NULL
) {
859 fprintf(stderr
, Name
": %s not identified in config file.\n",
863 mdfd
= open_mddev(devlist
->devname
,
864 array_ident
->autof
? array_ident
->autof
: autof
);
868 rv
|= Assemble(ss
, devlist
->devname
, mdfd
, array_ident
, configfile
,
870 readonly
, runstop
, update
, verbose
, force
);
875 rv
= Assemble(ss
, devlist
->devname
, mdfd
, &ident
, configfile
,
877 readonly
, runstop
, update
, verbose
, force
);
878 else if (devs_found
>0) {
879 if (update
&& devs_found
> 1) {
880 fprintf(stderr
, Name
": can only update a single array at a time\n");
883 for (dv
= devlist
; dv
; dv
=dv
->next
) {
884 mddev_ident_t array_ident
= conf_get_ident(configfile
, dv
->devname
);
885 if (array_ident
== NULL
) {
886 fprintf(stderr
, Name
": %s not identified in config file.\n",
891 mdfd
= open_mddev(dv
->devname
,
892 array_ident
->autof
?array_ident
->autof
: autof
);
897 rv
|= Assemble(ss
, dv
->devname
, mdfd
, array_ident
, configfile
,
899 readonly
, runstop
, update
, verbose
, force
);
903 mddev_ident_t array_list
= conf_get_ident(configfile
, NULL
);
905 fprintf(stderr
, Name
": No arrays found in config file\n");
908 for (; array_list
; array_list
= array_list
->next
) {
909 mdu_array_info_t array
;
910 mdfd
= open_mddev(array_list
->devname
,
911 array_list
->autof
? array_list
->autof
: autof
);
916 if (ioctl(mdfd
, GET_ARRAY_INFO
, &array
)>=0)
917 /* already assembled, skip */
920 rv
|= Assemble(ss
, array_list
->devname
, mdfd
,
921 array_list
, configfile
,
923 readonly
, runstop
, NULL
, verbose
, force
);
929 if (bitmap_chunk
== UnSet
) bitmap_chunk
= DEFAULT_BITMAP_CHUNK
;
930 if (delay
== 0) delay
= DEFAULT_BITMAP_DELAY
;
931 if (write_behind
&& !bitmap_file
) {
932 fprintf(stderr
, Name
": write-behind mode requires a bitmap.\n");
938 if (strcmp(bitmap_file
, "internal")==0) {
939 fprintf(stderr
, Name
": 'internal' bitmaps not supported with --build\n");
943 bitmap_fd
= open(bitmap_file
, O_RDWR
,0);
944 if (bitmap_fd
< 0 && errno
!= ENOENT
) {
945 perror(Name
": cannot create bitmap file");
950 bitmap_fd
= CreateBitmap(bitmap_file
, force
, NULL
,
951 bitmap_chunk
, delay
, write_behind
, size
);
954 rv
= Build(devlist
->devname
, mdfd
, chunk
, level
, layout
,
955 raiddisks
, devlist
->next
, assume_clean
,
956 bitmap_file
, bitmap_chunk
, write_behind
, delay
);
959 if (delay
== 0) delay
= DEFAULT_BITMAP_DELAY
;
960 if (write_behind
&& !bitmap_file
) {
961 fprintf(stderr
, Name
": write-behind mode requires a bitmap.\n");
966 for(i
=0; !ss
&& superlist
[i
]; i
++)
967 ss
= superlist
[i
]->match_metadata_desc("default");
970 fprintf(stderr
, Name
": internal error - no default metadata style\n");
974 rv
= Create(ss
, devlist
->devname
, mdfd
, chunk
, level
, layout
, size
<0 ? 0 : size
,
975 raiddisks
, sparedisks
,
976 devs_found
-1, devlist
->next
, runstop
, verbose
, force
,
977 bitmap_file
, bitmap_chunk
, write_behind
, delay
);
981 if (devmode
== 'E') {
982 if (devlist
== NULL
&& !scan
) {
983 fprintf(stderr
, Name
": No devices to examine\n");
987 devlist
= conf_get_devs(configfile
);
988 if (devlist
== NULL
) {
989 fprintf(stderr
, Name
": No devices listed in %s\n", configfile
?configfile
:DefaultConfFile
);
992 rv
= Examine(devlist
, scan
?(verbose
>1?0:verbose
+1):brief
, scan
, SparcAdjust
, ss
);
994 if (devlist
== NULL
) {
995 if (devmode
=='D' && scan
) {
996 /* apply --detail to all devices in /proc/mdstat */
997 struct mdstat_ent
*ms
= mdstat_read(0);
998 struct mdstat_ent
*e
;
999 for (e
=ms
; e
; e
=e
->next
) {
1000 char *name
= get_md_name(e
->devnum
);
1003 fprintf(stderr
, Name
": cannot find device file for %s\n",
1007 rv
|= Detail(name
, verbose
>1?0:verbose
+1, test
);
1010 } else if (devmode
== 'S' && scan
) {
1011 /* apply --stop to all devices in /proc/mdstat */
1012 /* Due to possible stacking of devices, repeat until
1013 * nothing more can be stopped
1015 int progress
=1, err
;
1018 struct mdstat_ent
*ms
= mdstat_read(0);
1019 struct mdstat_ent
*e
;
1021 if (!progress
) last
= 1;
1022 progress
= 0; err
= 0;
1023 for (e
=ms
; e
; e
=e
->next
) {
1024 char *name
= get_md_name(e
->devnum
);
1027 fprintf(stderr
, Name
": cannot find device file for %s\n",
1031 mdfd
= open_mddev(name
, 0);
1033 if (Manage_runstop(name
, mdfd
, -1, !last
))
1042 } while (!last
&& err
);
1044 fprintf(stderr
, Name
": No devices given.\n");
1048 for (dv
=devlist
; dv
; dv
=dv
->next
) {
1049 switch(dv
->disposition
) {
1051 rv
|= Detail(dv
->devname
, brief
?1+verbose
:0, test
); continue;
1052 case 'K': /* Zero superblock */
1053 rv
|= Kill(dv
->devname
, force
); continue;
1055 rv
|= Query(dv
->devname
); continue;
1057 rv
|= ExamineBitmap(dv
->devname
, brief
, ss
); continue;
1059 mdfd
= open_mddev(dv
->devname
, 0);
1061 switch(dv
->disposition
) {
1063 rv
|= Manage_runstop(dv
->devname
, mdfd
, 1, 0); break;
1065 rv
|= Manage_runstop(dv
->devname
, mdfd
, -1, 0); break;
1067 rv
|= Manage_ro(dv
->devname
, mdfd
, 1); break;
1069 rv
|= Manage_ro(dv
->devname
, mdfd
, -1); break;
1077 if (!devlist
&& !scan
) {
1078 fprintf(stderr
, Name
": Cannot monitor: need --scan or at least one device\n");
1082 if (pidfile
&& !daemonise
) {
1083 fprintf(stderr
, Name
": Cannot write a pid file when not in daemon mode\n");
1087 rv
= Monitor(devlist
, mailaddr
, program
,
1088 delay
?delay
:60, daemonise
, scan
, oneshot
, configfile
, test
, pidfile
);
1092 if (devs_found
> 1) {
1095 if (size
>= 0 || raiddisks
) {
1096 fprintf(stderr
, Name
": --size, --raiddisks, and --add are exclusing in --grow mode\n");
1100 for (dv
=devlist
->next
; dv
; dv
=dv
->next
) {
1101 rv
= Grow_Add_device(devlist
->devname
, mdfd
, dv
->devname
);
1105 } else if ((size
>= 0) + (raiddisks
!= 0) + (layout
!= UnSet
) + (bitmap_file
!= NULL
)> 1) {
1106 fprintf(stderr
, Name
": can change at most one of size, raiddisks, bitmap, and layout\n");
1109 } else if (layout
!= UnSet
)
1110 rv
= Manage_reconfig(devlist
->devname
, mdfd
, layout
);
1111 else if (size
>= 0 || raiddisks
)
1112 rv
= Manage_resize(devlist
->devname
, mdfd
, size
, raiddisks
);
1113 else if (bitmap_file
) {
1114 if (delay
== 0) delay
= DEFAULT_BITMAP_DELAY
;
1115 rv
= Grow_addbitmap(devlist
->devname
, mdfd
, bitmap_file
,
1116 bitmap_chunk
, delay
, write_behind
);
1118 fprintf(stderr
, Name
": no changes to --grow\n");