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
;
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
;
100 srandom(time(0) ^ getpid());
104 ident
.raid_disks
= UnSet
;
105 ident
.super_minor
= UnSet
;
107 ident
.spare_group
= NULL
;
110 ident
.bitmap_fd
= -1;
113 while ((option_index
= -1) ,
114 (opt
=getopt_long(argc
, argv
,
115 short_options
, long_options
,
116 &option_index
)) != -1) {
118 /* firstly, some mode-independant options */
122 if (option_index
> 0 &&
123 strcmp(long_options
[option_index
].name
, "help-options")==0)
124 help_text
= OptionHelp
;
127 case ASSEMBLE
: help_text
= Help_assemble
; break;
128 case BUILD
: help_text
= Help_build
; break;
129 case CREATE
: help_text
= Help_create
; break;
130 case MANAGE
: help_text
= Help_manage
; break;
131 case MISC
: help_text
= Help_misc
; break;
132 case MONITOR
: help_text
= Help_monitor
; break;
133 case GROW
: help_text
= Help_grow
; break;
135 fputs(help_text
,stderr
);
139 fputs(Version
, stderr
);
149 if (mode
== ASSEMBLE
|| mode
== BUILD
|| mode
== CREATE
|| mode
== GROW
)
150 break; /* b means bitmap */
156 fputs(Usage
, stderr
);
159 /* second, figure out the mode.
160 * Some options force the mode. Others
161 * set the mode if it isn't already
165 case '@': /* just incase they say --manage */
166 newmode
= MANAGE
; break;
170 if (!mode
) newmode
= MANAGE
;
173 case 'A': newmode
= ASSEMBLE
; break;
174 case 'B': newmode
= BUILD
; break;
175 case 'C': newmode
= CREATE
; break;
176 case 'F': newmode
= MONITOR
;break;
177 case 'G': newmode
= GROW
; break;
183 case 'Q': newmode
= MISC
; break;
188 case 'K': if (!mode
) newmode
= MISC
; break;
190 if (mode
&& newmode
== mode
) {
191 /* everybody happy ! */
192 } else if (mode
&& newmode
!= mode
) {
194 fprintf(stderr
, Name
": ");
195 if (option_index
>= 0)
196 fprintf(stderr
, "--%s", long_options
[option_index
].name
);
198 fprintf(stderr
, "-%c", opt
);
199 fprintf(stderr
, " would set mdadm mode to \"%s\", but it is already set to \"%s\".\n",
200 map_num(modes
, newmode
),
201 map_num(modes
, mode
));
203 } else if (!mode
&& newmode
) {
206 /* special case of -c --help */
208 ( strncmp(optarg
, "--h", 3)==0 ||
209 strncmp(optarg
, "-h", 2)==0)) {
210 fputs(Help_config
, stderr
);
214 /* If first option is a device, don't force the mode yet */
216 if (devs_found
== 0) {
217 dv
= malloc(sizeof(*dv
));
219 fprintf(stderr
, Name
": malloc failed\n");
222 dv
->devname
= optarg
;
223 dv
->disposition
= devmode
;
224 dv
->writemostly
= writemostly
;
227 devlistend
= &dv
->next
;
232 /* No mode yet, and this is the second device ... */
233 fprintf(stderr
, Name
": An option must be given to set the mode before a second device is listed\n");
236 if (option_index
>= 0)
237 fprintf(stderr
, Name
": --%s", long_options
[option_index
].name
);
239 fprintf(stderr
, Name
": -%c", opt
);
240 fprintf(stderr
, " does not set the mode, and so cannot be the first option.\n");
244 /* if we just set the mode, then done */
256 /* an undecorated option - must be a device name.
258 if (devs_found
> 0 && mode
== '@' && !devmode
) {
259 fprintf(stderr
, Name
": Must give one of -a/-r/-f for subsequent devices at %s\n", optarg
);
262 if (devs_found
> 0 && mode
== 'G' && !devmode
) {
263 fprintf(stderr
, Name
": Must give one of -a for devices do add: %s\n", optarg
);
266 dv
= malloc(sizeof(*dv
));
268 fprintf(stderr
, Name
": malloc failed\n");
271 dv
->devname
= optarg
;
272 dv
->disposition
= devmode
;
273 dv
->writemostly
= writemostly
;
276 devlistend
= &dv
->next
;
282 /* We've got a mode, and opt is now something else which
283 * could depend on the mode */
284 #define O(a,b) ((a<<8)|b)
285 switch (O(mode
,opt
)) {
287 case O(BUILD
,'c'): /* chunk or rounding */
289 fprintf(stderr
, Name
": chunk/rounding may only be specified once. "
290 "Second value is %s.\n", optarg
);
293 chunk
= strtol(optarg
, &c
, 10);
294 if (!optarg
[0] || *c
|| chunk
<4 || ((chunk
-1)&chunk
)) {
295 fprintf(stderr
, Name
": invalid chunk/rounding value: %s\n",
302 case O(ASSEMBLE
,'e'):
303 case O(MISC
,'e'): /* set metadata (superblock) information */
305 fprintf(stderr
, Name
": metadata information already given\n");
308 for(i
=0; !ss
&& superlist
[i
]; i
++)
309 ss
= superlist
[i
]->match_metadata_desc(optarg
);
312 fprintf(stderr
, Name
": unrecognised metadata identifier: %s\n", optarg
);
315 max_disks
= ss
->max_devs
;
321 /* set write-mostly for following devices */
326 case O(CREATE
,'z'): /* size */
328 fprintf(stderr
, Name
": size may only be specified once. "
329 "Second value is %s.\n", optarg
);
332 if (strcmp(optarg
, "max")==0)
335 size
= strtol(optarg
, &c
, 10);
336 if (!optarg
[0] || *c
|| size
< 4) {
337 fprintf(stderr
, Name
": invalid size: %s\n",
344 case O(GROW
,'l'): /* hack - needed to understand layout */
346 case O(BUILD
,'l'): /* set raid level*/
347 if (level
!= UnSet
) {
348 fprintf(stderr
, Name
": raid level may only be set once. "
349 "Second value is %s.\n", optarg
);
352 level
= map_name(pers
, optarg
);
353 if (level
== UnSet
) {
354 fprintf(stderr
, Name
": invalid raid level: %s\n",
358 if (level
!= 0 && level
!= -1 && level
!= 1 && level
!= -4 && level
!= -5 && mode
== BUILD
) {
359 fprintf(stderr
, Name
": Raid level %s not permitted with --build.\n",
363 if (sparedisks
> 0 && level
< 1 && level
>= -1) {
364 fprintf(stderr
, Name
": raid level %s is incompatible with spare-devices setting.\n",
371 case O(CREATE
,'p'): /* raid5 layout */
372 case O(BUILD
,'p'): /* faulty layout */
373 case O(GROW
, 'p'): /* faulty reconfig */
374 if (layout
!= UnSet
) {
375 fprintf(stderr
,Name
": layout may only be sent once. "
376 "Second value was %s\n", optarg
);
381 fprintf(stderr
, Name
": layout not meaningful for %s arrays.\n",
382 map_num(pers
, level
));
385 fprintf(stderr
, Name
": raid level must be given before layout.\n");
390 layout
= map_name(r5layout
, optarg
);
392 fprintf(stderr
, Name
": layout %s not understood for raid5.\n",
399 /* 'f' or 'n' followed by a number <= raid_disks */
400 if ((optarg
[0] != 'n' && optarg
[0] != 'f') ||
401 (copies
= strtoul(optarg
+1, &cp
, 10)) < 1 ||
404 fprintf(stderr
, Name
": layout for raid10 must be 'nNN' or 'fNN' where NN is a number, not %s\n", optarg
);
407 if (optarg
[0] == 'n')
408 layout
= 256 + copies
;
410 layout
= 1 + (copies
<<8);
417 int ln
= strcspn(optarg
, "0123456789");
418 char *m
= strdup(optarg
);
421 mode
= map_name(faultylayout
, m
);
423 fprintf(stderr
, Name
": layout %s not understood for faulty.\n",
427 layout
= mode
| (atoi(optarg
+ln
)<< ModeShift
);
433 case O(BUILD
,3): /* assume clean */
439 case O(BUILD
,'n'): /* number of raid disks */
441 fprintf(stderr
, Name
": raid-devices set twice: %d and %s\n",
445 raiddisks
= strtol(optarg
, &c
, 10);
446 if (!optarg
[0] || *c
|| raiddisks
<=0) {
447 fprintf(stderr
, Name
": invalid number of raid devices: %s\n",
451 ident
.raid_disks
= raiddisks
;
454 case O(CREATE
,'x'): /* number of spare (eXtra) discs */
456 fprintf(stderr
,Name
": spare-devices set twice: %d and %s\n",
460 if (level
!= UnSet
&& level
<= 0 && level
>= -1) {
461 fprintf(stderr
, Name
": spare-devices setting is incompatible with raid level %d\n",
465 sparedisks
= strtol(optarg
, &c
, 10);
466 if (!optarg
[0] || *c
|| sparedisks
< 0) {
467 fprintf(stderr
, Name
": invalid number of spare-devices: %s\n",
475 case O(ASSEMBLE
,'a'): /* auto-creation of device node */
478 else if (strcasecmp(optarg
,"no")==0)
480 else if (strcasecmp(optarg
,"yes")==0)
482 else if (strcasecmp(optarg
,"md")==0)
485 /* There might be digits, and maybe a hypen, at the end */
486 char *e
= optarg
+ strlen(optarg
);
489 while (e
> optarg
&& isdigit(e
[-1]))
493 if (num
<= 0) num
= 1;
495 if (e
> optarg
&& e
[-1] == '-')
498 if ((len
== 3 && strncasecmp(optarg
,"mdp",3)==0) ||
499 (len
== 1 && strncasecmp(optarg
,"p",1)==0) ||
500 (len
>= 4 && strncasecmp(optarg
,"part",4)==0))
503 fprintf(stderr
, Name
": --auto flag arg of \"%s\" unrecognised: use no,yes,md,mdp,part\n"
504 " optionally followed by a number.\n",
511 case O(BUILD
,'f'): /* force honouring '-n 1' */
512 case O(GROW
,'f'): /* ditto */
513 case O(CREATE
,'f'): /* force honouring of device list */
514 case O(ASSEMBLE
,'f'): /* force assembly */
515 case O(MISC
,'f'): /* force zero */
519 /* now for the Assemble options */
520 case O(ASSEMBLE
,'u'): /* uuid of array */
521 if (ident
.uuid_set
) {
522 fprintf(stderr
, Name
": uuid cannot be set twice. "
523 "Second value %s.\n", optarg
);
526 if (parse_uuid(optarg
, ident
.uuid
))
529 fprintf(stderr
,Name
": Bad uuid: %s\n", optarg
);
535 case O(ASSEMBLE
,'N'):
537 fprintf(stderr
, Name
": name cannot be set twice. "
538 "Second value %s.\n", optarg
);
541 if (strlen(optarg
) > 32) {
542 fprintf(stderr
, Name
": name '%s' is too long, 32 chars max.\n",
546 strcpy(ident
.name
, optarg
);
549 case O(ASSEMBLE
,'m'): /* super-minor for array */
550 if (ident
.super_minor
!= UnSet
) {
551 fprintf(stderr
, Name
": super-minor cannot be set twice. "
552 "Second value: %s.\n", optarg
);
555 if (strcmp(optarg
, "dev")==0)
556 ident
.super_minor
= -2;
558 ident
.super_minor
= strtoul(optarg
, &cp
, 10);
559 if (!optarg
[0] || *cp
) {
560 fprintf(stderr
, Name
": Bad super-minor number: %s.\n", optarg
);
566 case O(ASSEMBLE
,'U'): /* update the superblock */
568 fprintf(stderr
, Name
": Can only update one aspect of superblock, both %s and %s given.\n",
573 if (strcmp(update
, "sparc2.2")==0)
575 if (strcmp(update
, "super-minor") == 0)
577 if (strcmp(update
, "summaries")==0)
579 if (strcmp(update
, "resync")==0)
581 if (strcmp(update
, "byteorder")==0) {
583 fprintf(stderr
, Name
": must not set metadata type with --update=byteorder.\n");
586 for(i
=0; !ss
&& superlist
[i
]; i
++)
587 ss
= superlist
[i
]->match_metadata_desc("0.swap");
589 fprintf(stderr
, Name
": INTERNAL ERROR cannot find 0.swap\n");
595 fprintf(stderr
, Name
": '--update %s' invalid. Only 'sparc2.2', 'super-minor', 'resync' or 'summaries' supported\n",update
);
598 case O(ASSEMBLE
,'c'): /* config file */
602 fprintf(stderr
, Name
": configfile cannot be set twice. "
603 "Second value is %s.\n", optarg
);
607 /* FIXME possibly check that config file exists. Even parse it */
609 case O(ASSEMBLE
,'s'): /* scan */
615 case O(MONITOR
,'m'): /* mail address */
617 fprintf(stderr
, Name
": only specify one mailaddress. %s ignored.\n",
623 case O(MONITOR
,'p'): /* alert program */
625 fprintf(stderr
, Name
": only specify one alter program. %s ignored.\n",
631 case O(MONITOR
,'d'): /* delay in seconds */
633 case O(BUILD
,'d'): /* delay for bitmap updates */
636 fprintf(stderr
, Name
": only specify delay once. %s ignored.\n",
639 delay
= strtol(optarg
, &c
, 10);
640 if (!optarg
[0] || *c
|| delay
<1) {
641 fprintf(stderr
, Name
": invalid delay: %s\n",
647 case O(MONITOR
,'f'): /* daemonise */
650 case O(MONITOR
,'i'): /* pid */
652 fprintf(stderr
, Name
": only specify one pid file. %s ignored.\n",
657 case O(MONITOR
,'1'): /* oneshot */
660 case O(MONITOR
,'t'): /* test */
664 /* now the general management options. Some are applicable
665 * to other modes. None have arguments.
668 case O(MANAGE
,'a'): /* add a drive */
671 case O(MANAGE
,'r'): /* remove a drive */
674 case O(MANAGE
,'f'): /* set faulty */
678 case O(ASSEMBLE
,'R'):
680 case O(CREATE
,'R'): /* Run the array */
682 fprintf(stderr
, Name
": Cannot both Stop and Run an array\n");
689 fprintf(stderr
, Name
": Cannot both Run and Stop an array\n");
697 fprintf(stderr
, Name
": Cannot have both readonly and readwrite\n");
704 fprintf(stderr
, Name
": Cannot have both readwrite and readonly.\n");
719 if (devmode
&& devmode
!= opt
&&
720 (devmode
== 'E' || (opt
== 'E' && devmode
!= 'Q'))) {
721 fprintf(stderr
, Name
": --examine/-E cannot be given with -%c\n",
722 devmode
=='E'?opt
:devmode
);
732 if (devmode
!= 'E') {
733 fprintf(stderr
, Name
": --sparc2.2 only allowed with --examine\n");
739 case O(ASSEMBLE
,'b'): /* here we simply set the bitmap file */
741 fprintf(stderr
, Name
": bitmap file needed with -b in --assemble mode\n");
744 if (strcmp(optarg
, "internal")==0) {
745 fprintf(stderr
, Name
": there is no need to specify --bitmap when assembling arrays with internal bitmaps\n");
748 bitmap_fd
= open(optarg
, O_RDWR
);
749 if (!*optarg
|| bitmap_fd
< 0) {
750 fprintf(stderr
, Name
": cannot open bitmap file %s: %s\n", optarg
, strerror(errno
));
753 ident
.bitmap_fd
= bitmap_fd
; /* for Assemble */
758 case O(CREATE
,'b'): /* here we create the bitmap */
759 bitmap_file
= optarg
;
764 case O(CREATE
,4): /* bitmap chunksize */
765 bitmap_chunk
= strtol(optarg
, &c
, 10);
766 if (!optarg
[0] || *c
|| bitmap_chunk
< 0 ||
767 bitmap_chunk
& (bitmap_chunk
- 1)) {
768 fprintf(stderr
, Name
": invalid bitmap chunksize: %s\n",
772 /* convert K to B, chunk of 0K means 512B */
773 bitmap_chunk
= bitmap_chunk
? bitmap_chunk
* 1024 : 512;
777 case O(CREATE
, 5): /* write-behind mode */
778 write_behind
= DEFAULT_MAX_WRITE_BEHIND
;
780 write_behind
= strtol(optarg
, &c
, 10);
781 if (write_behind
< 0 || *c
||
782 write_behind
> 16383) {
783 fprintf(stderr
, Name
": Invalid value for maximum outstanding write-behind writes: %s.\n\tMust be between 0 and 16383.\n", optarg
);
789 /* We have now processed all the valid options. Anything else is
792 fprintf(stderr
, Name
": option %c not valid in %s mode\n",
793 opt
, map_num(modes
, mode
));
798 if (!mode
&& devs_found
) {
801 if (devlist
->disposition
== 0)
802 devlist
->disposition
= devmode
;
805 fputs(Usage
, stderr
);
808 /* Ok, got the option parsing out of the way
809 * hopefully it's mostly right but there might be some stuff
812 * That is mosty checked in the per-mode stuff but...
814 * For @,B,C and A without -s, the first device listed must be an md device
815 * we check that here and open it.
818 if (mode
==MANAGE
|| mode
== BUILD
|| mode
== CREATE
|| mode
== GROW
||
819 (mode
== ASSEMBLE
&& ! scan
)) {
820 if (devs_found
< 1) {
821 fprintf(stderr
, Name
": an md device must be given in this mode\n");
824 if ((int)ident
.super_minor
== -2 && autof
) {
825 fprintf(stderr
, Name
": --super-minor=dev is incompatible with --auto\n");
828 mdfd
= open_mddev(devlist
->devname
, autof
);
831 if ((int)ident
.super_minor
== -2) {
834 ident
.super_minor
= minor(stb
.st_rdev
);
839 if (raiddisks
> max_disks
) {
840 fprintf(stderr
, Name
": invalid number of raid devices: %d\n",
844 if (raiddisks
== 1 && !force
&& level
!= -5) {
845 fprintf(stderr
, Name
": '1' is an unusual number of drives for an array, so it is probably\n"
846 " a mistake. If you really mean it you will need to specify --force before\n"
847 " setting the number of drives.\n");
852 if ( sparedisks
> max_disks
- raiddisks
) {
853 fprintf(stderr
, Name
": invalid number of spare-devices: %d\n",
862 /* readonly, add/remove, readwrite, runstop */
864 rv
= Manage_ro(devlist
->devname
, mdfd
, readonly
);
865 if (!rv
&& devs_found
>1)
866 rv
= Manage_subdevs(devlist
->devname
, mdfd
,
867 devlist
->next
, verbose
-quiet
);
868 if (!rv
&& readonly
< 0)
869 rv
= Manage_ro(devlist
->devname
, mdfd
, readonly
);
871 rv
= Manage_runstop(devlist
->devname
, mdfd
, runstop
, 0);
874 if (devs_found
== 1 && ident
.uuid_set
== 0 &&
875 ident
.super_minor
== UnSet
&& ident
.name
[0] == 0 && !scan
) {
876 /* Only a device has been given, so get details from config file */
877 mddev_ident_t array_ident
= conf_get_ident(configfile
, devlist
->devname
);
878 if (array_ident
== NULL
) {
879 fprintf(stderr
, Name
": %s not identified in config file.\n",
883 mdfd
= open_mddev(devlist
->devname
,
884 array_ident
->autof
? array_ident
->autof
: autof
);
888 rv
|= Assemble(ss
, devlist
->devname
, mdfd
, array_ident
, configfile
,
890 readonly
, runstop
, update
, verbose
-quiet
, force
);
895 rv
= Assemble(ss
, devlist
->devname
, mdfd
, &ident
, configfile
,
897 readonly
, runstop
, update
, verbose
-quiet
, force
);
898 else if (devs_found
>0) {
899 if (update
&& devs_found
> 1) {
900 fprintf(stderr
, Name
": can only update a single array at a time\n");
903 for (dv
= devlist
; dv
; dv
=dv
->next
) {
904 mddev_ident_t array_ident
= conf_get_ident(configfile
, dv
->devname
);
905 if (array_ident
== NULL
) {
906 fprintf(stderr
, Name
": %s not identified in config file.\n",
911 mdfd
= open_mddev(dv
->devname
,
912 array_ident
->autof
?array_ident
->autof
: autof
);
917 rv
|= Assemble(ss
, dv
->devname
, mdfd
, array_ident
, configfile
,
919 readonly
, runstop
, update
, verbose
-quiet
, force
);
923 mddev_ident_t array_list
= conf_get_ident(configfile
, NULL
);
925 fprintf(stderr
, Name
": No arrays found in config file\n");
928 for (; array_list
; array_list
= array_list
->next
) {
929 mdu_array_info_t array
;
930 mdfd
= open_mddev(array_list
->devname
,
931 array_list
->autof
? array_list
->autof
: autof
);
936 if (ioctl(mdfd
, GET_ARRAY_INFO
, &array
)>=0)
937 /* already assembled, skip */
940 rv
|= Assemble(ss
, array_list
->devname
, mdfd
,
941 array_list
, configfile
,
943 readonly
, runstop
, NULL
, verbose
-quiet
, force
);
949 if (bitmap_chunk
== UnSet
) bitmap_chunk
= DEFAULT_BITMAP_CHUNK
;
950 if (delay
== 0) delay
= DEFAULT_BITMAP_DELAY
;
951 if (write_behind
&& !bitmap_file
) {
952 fprintf(stderr
, Name
": write-behind mode requires a bitmap.\n");
958 if (strcmp(bitmap_file
, "internal")==0) {
959 fprintf(stderr
, Name
": 'internal' bitmaps not supported with --build\n");
963 bitmap_fd
= open(bitmap_file
, O_RDWR
,0);
964 if (bitmap_fd
< 0 && errno
!= ENOENT
) {
965 perror(Name
": cannot create bitmap file");
970 bitmap_fd
= CreateBitmap(bitmap_file
, force
, NULL
,
971 bitmap_chunk
, delay
, write_behind
, size
);
974 rv
= Build(devlist
->devname
, mdfd
, chunk
, level
, layout
,
975 raiddisks
, devlist
->next
, assume_clean
,
976 bitmap_file
, bitmap_chunk
, write_behind
, delay
, verbose
-quiet
);
979 if (delay
== 0) delay
= DEFAULT_BITMAP_DELAY
;
980 if (write_behind
&& !bitmap_file
) {
981 fprintf(stderr
, Name
": write-behind mode requires a bitmap.\n");
986 for(i
=0; !ss
&& superlist
[i
]; i
++)
987 ss
= superlist
[i
]->match_metadata_desc("default");
990 fprintf(stderr
, Name
": internal error - no default metadata style\n");
994 rv
= Create(ss
, devlist
->devname
, mdfd
, chunk
, level
, layout
, size
<0 ? 0 : size
,
995 raiddisks
, sparedisks
, ident
.name
,
996 devs_found
-1, devlist
->next
, runstop
, verbose
-quiet
, force
,
997 bitmap_file
, bitmap_chunk
, write_behind
, delay
);
1001 if (devmode
== 'E') {
1002 if (devlist
== NULL
&& !scan
) {
1003 fprintf(stderr
, Name
": No devices to examine\n");
1006 if (devlist
== NULL
)
1007 devlist
= conf_get_devs(configfile
);
1008 if (devlist
== NULL
) {
1009 fprintf(stderr
, Name
": No devices listed in %s\n", configfile
?configfile
:DefaultConfFile
);
1012 rv
= Examine(devlist
, scan
?(verbose
>1?0:verbose
+1):brief
, scan
, SparcAdjust
, ss
);
1014 if (devlist
== NULL
) {
1015 if (devmode
=='D' && scan
) {
1016 /* apply --detail to all devices in /proc/mdstat */
1017 struct mdstat_ent
*ms
= mdstat_read(0);
1018 struct mdstat_ent
*e
;
1019 for (e
=ms
; e
; e
=e
->next
) {
1020 char *name
= get_md_name(e
->devnum
);
1023 fprintf(stderr
, Name
": cannot find device file for %s\n",
1027 rv
|= Detail(name
, verbose
>1?0:verbose
+1, test
);
1030 } else if (devmode
== 'S' && scan
) {
1031 /* apply --stop to all devices in /proc/mdstat */
1032 /* Due to possible stacking of devices, repeat until
1033 * nothing more can be stopped
1035 int progress
=1, err
;
1038 struct mdstat_ent
*ms
= mdstat_read(0);
1039 struct mdstat_ent
*e
;
1041 if (!progress
) last
= 1;
1042 progress
= 0; err
= 0;
1043 for (e
=ms
; e
; e
=e
->next
) {
1044 char *name
= get_md_name(e
->devnum
);
1047 fprintf(stderr
, Name
": cannot find device file for %s\n",
1051 mdfd
= open_mddev(name
, 0);
1053 if (Manage_runstop(name
, mdfd
, -1, !last
))
1062 } while (!last
&& err
);
1064 fprintf(stderr
, Name
": No devices given.\n");
1068 for (dv
=devlist
; dv
; dv
=dv
->next
) {
1069 switch(dv
->disposition
) {
1071 rv
|= Detail(dv
->devname
, brief
?1+verbose
:0, test
); continue;
1072 case 'K': /* Zero superblock */
1073 rv
|= Kill(dv
->devname
, force
); continue;
1075 rv
|= Query(dv
->devname
); continue;
1077 rv
|= ExamineBitmap(dv
->devname
, brief
, ss
); continue;
1079 mdfd
= open_mddev(dv
->devname
, 0);
1081 switch(dv
->disposition
) {
1083 rv
|= Manage_runstop(dv
->devname
, mdfd
, 1, 0); break;
1085 rv
|= Manage_runstop(dv
->devname
, mdfd
, -1, 0); break;
1087 rv
|= Manage_ro(dv
->devname
, mdfd
, 1); break;
1089 rv
|= Manage_ro(dv
->devname
, mdfd
, -1); break;
1097 if (!devlist
&& !scan
) {
1098 fprintf(stderr
, Name
": Cannot monitor: need --scan or at least one device\n");
1102 if (pidfile
&& !daemonise
) {
1103 fprintf(stderr
, Name
": Cannot write a pid file when not in daemon mode\n");
1107 rv
= Monitor(devlist
, mailaddr
, program
,
1108 delay
?delay
:60, daemonise
, scan
, oneshot
, configfile
, test
, pidfile
);
1112 if (devs_found
> 1) {
1115 if (size
>= 0 || raiddisks
) {
1116 fprintf(stderr
, Name
": --size, --raiddisks, and --add are exclusing in --grow mode\n");
1120 for (dv
=devlist
->next
; dv
; dv
=dv
->next
) {
1121 rv
= Grow_Add_device(devlist
->devname
, mdfd
, dv
->devname
);
1125 } else if ((size
>= 0) + (raiddisks
!= 0) + (layout
!= UnSet
) + (bitmap_file
!= NULL
)> 1) {
1126 fprintf(stderr
, Name
": can change at most one of size, raiddisks, bitmap, and layout\n");
1129 } else if (layout
!= UnSet
)
1130 rv
= Manage_reconfig(devlist
->devname
, mdfd
, layout
);
1131 else if (size
>= 0 || raiddisks
)
1132 rv
= Manage_resize(devlist
->devname
, mdfd
, size
, raiddisks
);
1133 else if (bitmap_file
) {
1134 if (delay
== 0) delay
= DEFAULT_BITMAP_DELAY
;
1135 rv
= Grow_addbitmap(devlist
->devname
, mdfd
, bitmap_file
,
1136 bitmap_chunk
, delay
, write_behind
);
1138 fprintf(stderr
, Name
": no changes to --grow\n");