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
;
96 char *shortopt
= short_options
;
102 srandom(time(0) ^ getpid());
106 ident
.raid_disks
= UnSet
;
107 ident
.super_minor
= UnSet
;
109 ident
.spare_group
= NULL
;
112 ident
.bitmap_fd
= -1;
115 while ((option_index
= -1) ,
116 (opt
=getopt_long(argc
, argv
,
117 shortopt
, long_options
,
118 &option_index
)) != -1) {
120 /* firstly, some mode-independant options */
124 if (option_index
> 0 &&
125 strcmp(long_options
[option_index
].name
, "help-options")==0)
126 help_text
= OptionHelp
;
129 case ASSEMBLE
: help_text
= Help_assemble
; break;
130 case BUILD
: help_text
= Help_build
; break;
131 case CREATE
: help_text
= Help_create
; break;
132 case MANAGE
: help_text
= Help_manage
; break;
133 case MISC
: help_text
= Help_misc
; break;
134 case MONITOR
: help_text
= Help_monitor
; break;
135 case GROW
: help_text
= Help_grow
; break;
137 fputs(help_text
,stderr
);
141 fputs(Version
, stderr
);
151 if (mode
== ASSEMBLE
|| mode
== BUILD
|| mode
== CREATE
|| mode
== GROW
)
152 break; /* b means bitmap */
155 fprintf(stderr
, Name
": -b cannot have any extra immediately after it, sorry.\n");
162 fputs(Usage
, stderr
);
165 /* second, figure out the mode.
166 * Some options force the mode. Others
167 * set the mode if it isn't already
171 case '@': /* just incase they say --manage */
173 shortopt
= short_bitmap_auto_options
;
181 shortopt
= short_bitmap_auto_options
;
185 case 'A': newmode
= ASSEMBLE
; shortopt
= short_bitmap_auto_options
; break;
186 case 'B': newmode
= BUILD
; shortopt
= short_bitmap_auto_options
; break;
187 case 'C': newmode
= CREATE
; shortopt
= short_bitmap_auto_options
; break;
188 case 'F': newmode
= MONITOR
;break;
189 case 'G': newmode
= GROW
; shortopt
= short_bitmap_auto_options
; break;
195 case 'Q': newmode
= MISC
; break;
200 case 'K': if (!mode
) newmode
= MISC
; break;
202 if (mode
&& newmode
== mode
) {
203 /* everybody happy ! */
204 } else if (mode
&& newmode
!= mode
) {
206 fprintf(stderr
, Name
": ");
207 if (option_index
>= 0)
208 fprintf(stderr
, "--%s", long_options
[option_index
].name
);
210 fprintf(stderr
, "-%c", opt
);
211 fprintf(stderr
, " would set mdadm mode to \"%s\", but it is already set to \"%s\".\n",
212 map_num(modes
, newmode
),
213 map_num(modes
, mode
));
215 } else if (!mode
&& newmode
) {
218 /* special case of -c --help */
220 ( strncmp(optarg
, "--h", 3)==0 ||
221 strncmp(optarg
, "-h", 2)==0)) {
222 fputs(Help_config
, stderr
);
226 /* If first option is a device, don't force the mode yet */
228 if (devs_found
== 0) {
229 dv
= malloc(sizeof(*dv
));
231 fprintf(stderr
, Name
": malloc failed\n");
234 dv
->devname
= optarg
;
235 dv
->disposition
= devmode
;
236 dv
->writemostly
= writemostly
;
240 devlistend
= &dv
->next
;
245 /* No mode yet, and this is the second device ... */
246 fprintf(stderr
, Name
": An option must be given to set the mode before a second device is listed\n");
249 if (option_index
>= 0)
250 fprintf(stderr
, Name
": --%s", long_options
[option_index
].name
);
252 fprintf(stderr
, Name
": -%c", opt
);
253 fprintf(stderr
, " does not set the mode, and so cannot be the first option.\n");
257 /* if we just set the mode, then done */
269 /* an undecorated option - must be a device name.
271 if (devs_found
> 0 && mode
== '@' && !devmode
) {
272 fprintf(stderr
, Name
": Must give one of -a/-r/-f for subsequent devices at %s\n", optarg
);
275 if (devs_found
> 0 && mode
== 'G' && !devmode
) {
276 fprintf(stderr
, Name
": Must give one of -a for devices do add: %s\n", optarg
);
279 dv
= malloc(sizeof(*dv
));
281 fprintf(stderr
, Name
": malloc failed\n");
284 dv
->devname
= optarg
;
285 dv
->disposition
= devmode
;
286 dv
->writemostly
= writemostly
;
290 devlistend
= &dv
->next
;
296 /* We've got a mode, and opt is now something else which
297 * could depend on the mode */
298 #define O(a,b) ((a<<8)|b)
299 switch (O(mode
,opt
)) {
301 case O(BUILD
,'c'): /* chunk or rounding */
303 fprintf(stderr
, Name
": chunk/rounding may only be specified once. "
304 "Second value is %s.\n", optarg
);
307 chunk
= strtol(optarg
, &c
, 10);
308 if (!optarg
[0] || *c
|| chunk
<4 || ((chunk
-1)&chunk
)) {
309 fprintf(stderr
, Name
": invalid chunk/rounding value: %s\n",
316 case O(ASSEMBLE
,'e'):
317 case O(MISC
,'e'): /* set metadata (superblock) information */
319 fprintf(stderr
, Name
": metadata information already given\n");
322 for(i
=0; !ss
&& superlist
[i
]; i
++)
323 ss
= superlist
[i
]->match_metadata_desc(optarg
);
326 fprintf(stderr
, Name
": unrecognised metadata identifier: %s\n", optarg
);
329 max_disks
= ss
->max_devs
;
335 /* set write-mostly for following devices */
340 case O(CREATE
,'z'): /* size */
342 fprintf(stderr
, Name
": size may only be specified once. "
343 "Second value is %s.\n", optarg
);
346 if (strcmp(optarg
, "max")==0)
349 size
= strtol(optarg
, &c
, 10);
350 if (!optarg
[0] || *c
|| size
< 4) {
351 fprintf(stderr
, Name
": invalid size: %s\n",
358 case O(GROW
,'l'): /* hack - needed to understand layout */
360 case O(BUILD
,'l'): /* set raid level*/
361 if (level
!= UnSet
) {
362 fprintf(stderr
, Name
": raid level may only be set once. "
363 "Second value is %s.\n", optarg
);
366 level
= map_name(pers
, optarg
);
367 if (level
== UnSet
) {
368 fprintf(stderr
, Name
": invalid raid level: %s\n",
372 if (level
!= 0 && level
!= -1 && level
!= 1 && level
!= -4 && level
!= -5 && mode
== BUILD
) {
373 fprintf(stderr
, Name
": Raid level %s not permitted with --build.\n",
377 if (sparedisks
> 0 && level
< 1 && level
>= -1) {
378 fprintf(stderr
, Name
": raid level %s is incompatible with spare-devices setting.\n",
385 case O(CREATE
,'p'): /* raid5 layout */
386 case O(BUILD
,'p'): /* faulty layout */
387 case O(GROW
, 'p'): /* faulty reconfig */
388 if (layout
!= UnSet
) {
389 fprintf(stderr
,Name
": layout may only be sent once. "
390 "Second value was %s\n", optarg
);
395 fprintf(stderr
, Name
": layout not meaningful for %s arrays.\n",
396 map_num(pers
, level
));
399 fprintf(stderr
, Name
": raid level must be given before layout.\n");
404 layout
= map_name(r5layout
, optarg
);
406 fprintf(stderr
, Name
": layout %s not understood for raid5.\n",
413 /* 'f' or 'n' followed by a number <= raid_disks */
414 if ((optarg
[0] != 'n' && optarg
[0] != 'f') ||
415 (copies
= strtoul(optarg
+1, &cp
, 10)) < 1 ||
418 fprintf(stderr
, Name
": layout for raid10 must be 'nNN' or 'fNN' where NN is a number, not %s\n", optarg
);
421 if (optarg
[0] == 'n')
422 layout
= 256 + copies
;
424 layout
= 1 + (copies
<<8);
431 int ln
= strcspn(optarg
, "0123456789");
432 char *m
= strdup(optarg
);
435 mode
= map_name(faultylayout
, m
);
437 fprintf(stderr
, Name
": layout %s not understood for faulty.\n",
441 layout
= mode
| (atoi(optarg
+ln
)<< ModeShift
);
447 case O(BUILD
,3): /* assume clean */
453 case O(BUILD
,'n'): /* number of raid disks */
455 fprintf(stderr
, Name
": raid-devices set twice: %d and %s\n",
459 raiddisks
= strtol(optarg
, &c
, 10);
460 if (!optarg
[0] || *c
|| raiddisks
<=0) {
461 fprintf(stderr
, Name
": invalid number of raid devices: %s\n",
465 ident
.raid_disks
= raiddisks
;
468 case O(CREATE
,'x'): /* number of spare (eXtra) discs */
470 fprintf(stderr
,Name
": spare-devices set twice: %d and %s\n",
474 if (level
!= UnSet
&& level
<= 0 && level
>= -1) {
475 fprintf(stderr
, Name
": spare-devices setting is incompatible with raid level %d\n",
479 sparedisks
= strtol(optarg
, &c
, 10);
480 if (!optarg
[0] || *c
|| sparedisks
< 0) {
481 fprintf(stderr
, Name
": invalid number of spare-devices: %s\n",
489 case O(ASSEMBLE
,'a'): /* auto-creation of device node */
492 else if (strcasecmp(optarg
,"no")==0)
494 else if (strcasecmp(optarg
,"yes")==0)
496 else if (strcasecmp(optarg
,"md")==0)
499 /* There might be digits, and maybe a hypen, at the end */
500 char *e
= optarg
+ strlen(optarg
);
503 while (e
> optarg
&& isdigit(e
[-1]))
507 if (num
<= 0) num
= 1;
509 if (e
> optarg
&& e
[-1] == '-')
512 if ((len
== 3 && strncasecmp(optarg
,"mdp",3)==0) ||
513 (len
== 1 && strncasecmp(optarg
,"p",1)==0) ||
514 (len
>= 4 && strncasecmp(optarg
,"part",4)==0))
517 fprintf(stderr
, Name
": --auto flag arg of \"%s\" unrecognised: use no,yes,md,mdp,part\n"
518 " optionally followed by a number.\n",
525 case O(BUILD
,'f'): /* force honouring '-n 1' */
526 case O(GROW
,'f'): /* ditto */
527 case O(CREATE
,'f'): /* force honouring of device list */
528 case O(ASSEMBLE
,'f'): /* force assembly */
529 case O(MISC
,'f'): /* force zero */
533 /* now for the Assemble options */
534 case O(ASSEMBLE
,'u'): /* uuid of array */
535 if (ident
.uuid_set
) {
536 fprintf(stderr
, Name
": uuid cannot be set twice. "
537 "Second value %s.\n", optarg
);
540 if (parse_uuid(optarg
, ident
.uuid
))
543 fprintf(stderr
,Name
": Bad uuid: %s\n", optarg
);
549 case O(ASSEMBLE
,'N'):
551 fprintf(stderr
, Name
": name cannot be set twice. "
552 "Second value %s.\n", optarg
);
555 if (strlen(optarg
) > 32) {
556 fprintf(stderr
, Name
": name '%s' is too long, 32 chars max.\n",
560 strcpy(ident
.name
, optarg
);
563 case O(ASSEMBLE
,'m'): /* super-minor for array */
564 if (ident
.super_minor
!= UnSet
) {
565 fprintf(stderr
, Name
": super-minor cannot be set twice. "
566 "Second value: %s.\n", optarg
);
569 if (strcmp(optarg
, "dev")==0)
570 ident
.super_minor
= -2;
572 ident
.super_minor
= strtoul(optarg
, &cp
, 10);
573 if (!optarg
[0] || *cp
) {
574 fprintf(stderr
, Name
": Bad super-minor number: %s.\n", optarg
);
580 case O(ASSEMBLE
,'U'): /* update the superblock */
582 fprintf(stderr
, Name
": Can only update one aspect of superblock, both %s and %s given.\n",
587 if (strcmp(update
, "sparc2.2")==0)
589 if (strcmp(update
, "super-minor") == 0)
591 if (strcmp(update
, "summaries")==0)
593 if (strcmp(update
, "resync")==0)
595 if (strcmp(update
, "byteorder")==0) {
597 fprintf(stderr
, Name
": must not set metadata type with --update=byteorder.\n");
600 for(i
=0; !ss
&& superlist
[i
]; i
++)
601 ss
= superlist
[i
]->match_metadata_desc("0.swap");
603 fprintf(stderr
, Name
": INTERNAL ERROR cannot find 0.swap\n");
609 fprintf(stderr
, Name
": '--update %s' invalid. Only 'sparc2.2', 'super-minor', 'resync' or 'summaries' supported\n",update
);
612 case O(ASSEMBLE
,'c'): /* config file */
616 fprintf(stderr
, Name
": configfile cannot be set twice. "
617 "Second value is %s.\n", optarg
);
621 /* FIXME possibly check that config file exists. Even parse it */
623 case O(ASSEMBLE
,'s'): /* scan */
629 case O(MONITOR
,'m'): /* mail address */
631 fprintf(stderr
, Name
": only specify one mailaddress. %s ignored.\n",
637 case O(MONITOR
,'p'): /* alert program */
639 fprintf(stderr
, Name
": only specify one alter program. %s ignored.\n",
645 case O(MONITOR
,'d'): /* delay in seconds */
647 case O(BUILD
,'d'): /* delay for bitmap updates */
650 fprintf(stderr
, Name
": only specify delay once. %s ignored.\n",
653 delay
= strtol(optarg
, &c
, 10);
654 if (!optarg
[0] || *c
|| delay
<1) {
655 fprintf(stderr
, Name
": invalid delay: %s\n",
661 case O(MONITOR
,'f'): /* daemonise */
664 case O(MONITOR
,'i'): /* pid */
666 fprintf(stderr
, Name
": only specify one pid file. %s ignored.\n",
671 case O(MONITOR
,'1'): /* oneshot */
674 case O(MONITOR
,'t'): /* test */
678 /* now the general management options. Some are applicable
679 * to other modes. None have arguments.
682 case O(MANAGE
,'a'): /* add a drive */
690 case O(MANAGE
,'r'): /* remove a drive */
693 case O(MANAGE
,'f'): /* set faulty */
697 case O(ASSEMBLE
,'R'):
699 case O(CREATE
,'R'): /* Run the array */
701 fprintf(stderr
, Name
": Cannot both Stop and Run an array\n");
708 fprintf(stderr
, Name
": Cannot both Run and Stop an array\n");
716 fprintf(stderr
, Name
": Cannot have both readonly and readwrite\n");
723 fprintf(stderr
, Name
": Cannot have both readwrite and readonly.\n");
738 if (devmode
&& devmode
!= opt
&&
739 (devmode
== 'E' || (opt
== 'E' && devmode
!= 'Q'))) {
740 fprintf(stderr
, Name
": --examine/-E cannot be given with -%c\n",
741 devmode
=='E'?opt
:devmode
);
751 if (devmode
!= 'E') {
752 fprintf(stderr
, Name
": --sparc2.2 only allowed with --examine\n");
758 case O(ASSEMBLE
,'b'): /* here we simply set the bitmap file */
760 fprintf(stderr
, Name
": bitmap file needed with -b in --assemble mode\n");
763 if (strcmp(optarg
, "internal")==0) {
764 fprintf(stderr
, Name
": there is no need to specify --bitmap when assembling arrays with internal bitmaps\n");
767 bitmap_fd
= open(optarg
, O_RDWR
);
768 if (!*optarg
|| bitmap_fd
< 0) {
769 fprintf(stderr
, Name
": cannot open bitmap file %s: %s\n", optarg
, strerror(errno
));
772 ident
.bitmap_fd
= bitmap_fd
; /* for Assemble */
777 case O(CREATE
,'b'): /* here we create the bitmap */
778 bitmap_file
= optarg
;
783 case O(CREATE
,4): /* bitmap chunksize */
784 bitmap_chunk
= strtol(optarg
, &c
, 10);
785 if (!optarg
[0] || *c
|| bitmap_chunk
< 0 ||
786 bitmap_chunk
& (bitmap_chunk
- 1)) {
787 fprintf(stderr
, Name
": invalid bitmap chunksize: %s\n",
791 /* convert K to B, chunk of 0K means 512B */
792 bitmap_chunk
= bitmap_chunk
? bitmap_chunk
* 1024 : 512;
796 case O(CREATE
, 5): /* write-behind mode */
797 write_behind
= DEFAULT_MAX_WRITE_BEHIND
;
799 write_behind
= strtol(optarg
, &c
, 10);
800 if (write_behind
< 0 || *c
||
801 write_behind
> 16383) {
802 fprintf(stderr
, Name
": Invalid value for maximum outstanding write-behind writes: %s.\n\tMust be between 0 and 16383.\n", optarg
);
808 /* We have now processed all the valid options. Anything else is
811 fprintf(stderr
, Name
": option %c not valid in %s mode\n",
812 opt
, map_num(modes
, mode
));
817 if (!mode
&& devs_found
) {
820 if (devlist
->disposition
== 0)
821 devlist
->disposition
= devmode
;
824 fputs(Usage
, stderr
);
827 /* Ok, got the option parsing out of the way
828 * hopefully it's mostly right but there might be some stuff
831 * That is mosty checked in the per-mode stuff but...
833 * For @,B,C and A without -s, the first device listed must be an md device
834 * we check that here and open it.
837 if (mode
==MANAGE
|| mode
== BUILD
|| mode
== CREATE
|| mode
== GROW
||
838 (mode
== ASSEMBLE
&& ! scan
)) {
839 if (devs_found
< 1) {
840 fprintf(stderr
, Name
": an md device must be given in this mode\n");
843 if ((int)ident
.super_minor
== -2 && autof
) {
844 fprintf(stderr
, Name
": --super-minor=dev is incompatible with --auto\n");
847 mdfd
= open_mddev(devlist
->devname
, autof
);
850 if ((int)ident
.super_minor
== -2) {
853 ident
.super_minor
= minor(stb
.st_rdev
);
858 if (raiddisks
> max_disks
) {
859 fprintf(stderr
, Name
": invalid number of raid devices: %d\n",
863 if (raiddisks
== 1 && !force
&& level
!= -5) {
864 fprintf(stderr
, Name
": '1' is an unusual number of drives for an array, so it is probably\n"
865 " a mistake. If you really mean it you will need to specify --force before\n"
866 " setting the number of drives.\n");
871 if ( sparedisks
> max_disks
- raiddisks
) {
872 fprintf(stderr
, Name
": invalid number of spare-devices: %d\n",
881 /* readonly, add/remove, readwrite, runstop */
883 rv
= Manage_ro(devlist
->devname
, mdfd
, readonly
);
884 if (!rv
&& devs_found
>1)
885 rv
= Manage_subdevs(devlist
->devname
, mdfd
,
886 devlist
->next
, verbose
-quiet
);
887 if (!rv
&& readonly
< 0)
888 rv
= Manage_ro(devlist
->devname
, mdfd
, readonly
);
890 rv
= Manage_runstop(devlist
->devname
, mdfd
, runstop
, 0);
893 if (devs_found
== 1 && ident
.uuid_set
== 0 &&
894 ident
.super_minor
== UnSet
&& ident
.name
[0] == 0 && !scan
) {
895 /* Only a device has been given, so get details from config file */
896 mddev_ident_t array_ident
= conf_get_ident(configfile
, devlist
->devname
);
897 if (array_ident
== NULL
) {
898 fprintf(stderr
, Name
": %s not identified in config file.\n",
902 mdfd
= open_mddev(devlist
->devname
,
903 array_ident
->autof
? array_ident
->autof
: autof
);
907 rv
|= Assemble(ss
, devlist
->devname
, mdfd
, array_ident
, configfile
,
909 readonly
, runstop
, update
, verbose
-quiet
, force
);
914 rv
= Assemble(ss
, devlist
->devname
, mdfd
, &ident
, configfile
,
916 readonly
, runstop
, update
, verbose
-quiet
, force
);
917 else if (devs_found
>0) {
918 if (update
&& devs_found
> 1) {
919 fprintf(stderr
, Name
": can only update a single array at a time\n");
922 for (dv
= devlist
; dv
; dv
=dv
->next
) {
923 mddev_ident_t array_ident
= conf_get_ident(configfile
, dv
->devname
);
924 if (array_ident
== NULL
) {
925 fprintf(stderr
, Name
": %s not identified in config file.\n",
930 mdfd
= open_mddev(dv
->devname
,
931 array_ident
->autof
?array_ident
->autof
: autof
);
936 rv
|= Assemble(ss
, dv
->devname
, mdfd
, array_ident
, configfile
,
938 readonly
, runstop
, update
, verbose
-quiet
, force
);
942 mddev_ident_t array_list
= conf_get_ident(configfile
, NULL
);
944 fprintf(stderr
, Name
": No arrays found in config file\n");
947 for (; array_list
; array_list
= array_list
->next
) {
948 mdu_array_info_t array
;
949 mdfd
= open_mddev(array_list
->devname
,
950 array_list
->autof
? array_list
->autof
: autof
);
955 if (ioctl(mdfd
, GET_ARRAY_INFO
, &array
)>=0)
956 /* already assembled, skip */
959 rv
|= Assemble(ss
, array_list
->devname
, mdfd
,
960 array_list
, configfile
,
962 readonly
, runstop
, NULL
, verbose
-quiet
, force
);
968 if (bitmap_chunk
== UnSet
) bitmap_chunk
= DEFAULT_BITMAP_CHUNK
;
969 if (delay
== 0) delay
= DEFAULT_BITMAP_DELAY
;
970 if (write_behind
&& !bitmap_file
) {
971 fprintf(stderr
, Name
": write-behind mode requires a bitmap.\n");
977 if (strcmp(bitmap_file
, "internal")==0) {
978 fprintf(stderr
, Name
": 'internal' bitmaps not supported with --build\n");
983 rv
= Build(devlist
->devname
, mdfd
, chunk
, level
, layout
,
984 raiddisks
, devlist
->next
, assume_clean
,
985 bitmap_file
, bitmap_chunk
, write_behind
, delay
, verbose
-quiet
);
988 if (delay
== 0) delay
= DEFAULT_BITMAP_DELAY
;
989 if (write_behind
&& !bitmap_file
) {
990 fprintf(stderr
, Name
": write-behind mode requires a bitmap.\n");
995 for(i
=0; !ss
&& superlist
[i
]; i
++)
996 ss
= superlist
[i
]->match_metadata_desc("default");
999 fprintf(stderr
, Name
": internal error - no default metadata style\n");
1003 rv
= Create(ss
, devlist
->devname
, mdfd
, chunk
, level
, layout
, size
<0 ? 0 : size
,
1004 raiddisks
, sparedisks
, ident
.name
,
1005 devs_found
-1, devlist
->next
, runstop
, verbose
-quiet
, force
, assume_clean
,
1006 bitmap_file
, bitmap_chunk
, write_behind
, delay
);
1010 if (devmode
== 'E') {
1011 if (devlist
== NULL
&& !scan
) {
1012 fprintf(stderr
, Name
": No devices to examine\n");
1015 if (devlist
== NULL
)
1016 devlist
= conf_get_devs(configfile
);
1017 if (devlist
== NULL
) {
1018 fprintf(stderr
, Name
": No devices listed in %s\n", configfile
?configfile
:DefaultConfFile
);
1021 rv
= Examine(devlist
, scan
?(verbose
>1?0:verbose
+1):brief
, scan
, SparcAdjust
, ss
);
1023 if (devlist
== NULL
) {
1024 if (devmode
=='D' && scan
) {
1025 /* apply --detail to all devices in /proc/mdstat */
1026 struct mdstat_ent
*ms
= mdstat_read(0);
1027 struct mdstat_ent
*e
;
1028 for (e
=ms
; e
; e
=e
->next
) {
1029 char *name
= get_md_name(e
->devnum
);
1032 fprintf(stderr
, Name
": cannot find device file for %s\n",
1036 rv
|= Detail(name
, verbose
>1?0:verbose
+1, test
);
1039 } else if (devmode
== 'S' && scan
) {
1040 /* apply --stop to all devices in /proc/mdstat */
1041 /* Due to possible stacking of devices, repeat until
1042 * nothing more can be stopped
1044 int progress
=1, err
;
1047 struct mdstat_ent
*ms
= mdstat_read(0);
1048 struct mdstat_ent
*e
;
1050 if (!progress
) last
= 1;
1051 progress
= 0; err
= 0;
1052 for (e
=ms
; e
; e
=e
->next
) {
1053 char *name
= get_md_name(e
->devnum
);
1056 fprintf(stderr
, Name
": cannot find device file for %s\n",
1060 mdfd
= open_mddev(name
, 0);
1062 if (Manage_runstop(name
, mdfd
, -1, !last
))
1071 } while (!last
&& err
);
1074 fprintf(stderr
, Name
": No devices given.\n");
1078 for (dv
=devlist
; dv
; dv
=dv
->next
) {
1079 switch(dv
->disposition
) {
1081 rv
|= Detail(dv
->devname
, brief
?1+verbose
:0, test
); continue;
1082 case 'K': /* Zero superblock */
1083 rv
|= Kill(dv
->devname
, force
); continue;
1085 rv
|= Query(dv
->devname
); continue;
1087 rv
|= ExamineBitmap(dv
->devname
, brief
, ss
); continue;
1089 mdfd
= open_mddev(dv
->devname
, 0);
1091 switch(dv
->disposition
) {
1093 rv
|= Manage_runstop(dv
->devname
, mdfd
, 1, 0); break;
1095 rv
|= Manage_runstop(dv
->devname
, mdfd
, -1, 0); break;
1097 rv
|= Manage_ro(dv
->devname
, mdfd
, 1); break;
1099 rv
|= Manage_ro(dv
->devname
, mdfd
, -1); break;
1108 if (!devlist
&& !scan
) {
1109 fprintf(stderr
, Name
": Cannot monitor: need --scan or at least one device\n");
1113 if (pidfile
&& !daemonise
) {
1114 fprintf(stderr
, Name
": Cannot write a pid file when not in daemon mode\n");
1118 rv
= Monitor(devlist
, mailaddr
, program
,
1119 delay
?delay
:60, daemonise
, scan
, oneshot
, configfile
, test
, pidfile
);
1123 if (devs_found
> 1) {
1126 if (size
>= 0 || raiddisks
) {
1127 fprintf(stderr
, Name
": --size, --raiddisks, and --add are exclusing in --grow mode\n");
1131 for (dv
=devlist
->next
; dv
; dv
=dv
->next
) {
1132 rv
= Grow_Add_device(devlist
->devname
, mdfd
, dv
->devname
);
1136 } else if ((size
>= 0) + (raiddisks
!= 0) + (layout
!= UnSet
) + (bitmap_file
!= NULL
)> 1) {
1137 fprintf(stderr
, Name
": can change at most one of size, raiddisks, bitmap, and layout\n");
1140 } else if (layout
!= UnSet
)
1141 rv
= Manage_reconfig(devlist
->devname
, mdfd
, layout
);
1142 else if (size
>= 0 || raiddisks
)
1143 rv
= Manage_resize(devlist
->devname
, mdfd
, size
, raiddisks
);
1144 else if (bitmap_file
) {
1145 if (delay
== 0) delay
= DEFAULT_BITMAP_DELAY
;
1146 rv
= Grow_addbitmap(devlist
->devname
, mdfd
, bitmap_file
,
1147 bitmap_chunk
, delay
, write_behind
);
1149 fprintf(stderr
, Name
": no changes to --grow\n");