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
;
101 srandom(time(0) ^ getpid());
105 ident
.raid_disks
= UnSet
;
106 ident
.super_minor
= UnSet
;
108 ident
.spare_group
= NULL
;
111 ident
.bitmap_fd
= -1;
114 while ((option_index
= -1) ,
115 (opt
=getopt_long(argc
, argv
,
116 short_options
, long_options
,
117 &option_index
)) != -1) {
119 /* firstly, some mode-independant options */
123 if (option_index
> 0 &&
124 strcmp(long_options
[option_index
].name
, "help-options")==0)
125 help_text
= OptionHelp
;
128 case ASSEMBLE
: help_text
= Help_assemble
; break;
129 case BUILD
: help_text
= Help_build
; break;
130 case CREATE
: help_text
= Help_create
; break;
131 case MANAGE
: help_text
= Help_manage
; break;
132 case MISC
: help_text
= Help_misc
; break;
133 case MONITOR
: help_text
= Help_monitor
; break;
134 case GROW
: help_text
= Help_grow
; break;
136 fputs(help_text
,stderr
);
140 fputs(Version
, stderr
);
150 if (mode
== ASSEMBLE
|| mode
== BUILD
|| mode
== CREATE
|| mode
== GROW
)
151 break; /* b means bitmap */
157 fputs(Usage
, stderr
);
160 /* second, figure out the mode.
161 * Some options force the mode. Others
162 * set the mode if it isn't already
166 case '@': /* just incase they say --manage */
167 newmode
= MANAGE
; break;
172 if (!mode
) newmode
= MANAGE
;
175 case 'A': newmode
= ASSEMBLE
; break;
176 case 'B': newmode
= BUILD
; break;
177 case 'C': newmode
= CREATE
; break;
178 case 'F': newmode
= MONITOR
;break;
179 case 'G': newmode
= GROW
; break;
185 case 'Q': newmode
= MISC
; break;
190 case 'K': if (!mode
) newmode
= MISC
; break;
192 if (mode
&& newmode
== mode
) {
193 /* everybody happy ! */
194 } else if (mode
&& newmode
!= mode
) {
196 fprintf(stderr
, Name
": ");
197 if (option_index
>= 0)
198 fprintf(stderr
, "--%s", long_options
[option_index
].name
);
200 fprintf(stderr
, "-%c", opt
);
201 fprintf(stderr
, " would set mdadm mode to \"%s\", but it is already set to \"%s\".\n",
202 map_num(modes
, newmode
),
203 map_num(modes
, mode
));
205 } else if (!mode
&& newmode
) {
208 /* special case of -c --help */
210 ( strncmp(optarg
, "--h", 3)==0 ||
211 strncmp(optarg
, "-h", 2)==0)) {
212 fputs(Help_config
, stderr
);
216 /* If first option is a device, don't force the mode yet */
218 if (devs_found
== 0) {
219 dv
= malloc(sizeof(*dv
));
221 fprintf(stderr
, Name
": malloc failed\n");
224 dv
->devname
= optarg
;
225 dv
->disposition
= devmode
;
226 dv
->writemostly
= writemostly
;
230 devlistend
= &dv
->next
;
235 /* No mode yet, and this is the second device ... */
236 fprintf(stderr
, Name
": An option must be given to set the mode before a second device is listed\n");
239 if (option_index
>= 0)
240 fprintf(stderr
, Name
": --%s", long_options
[option_index
].name
);
242 fprintf(stderr
, Name
": -%c", opt
);
243 fprintf(stderr
, " does not set the mode, and so cannot be the first option.\n");
247 /* if we just set the mode, then done */
259 /* an undecorated option - must be a device name.
261 if (devs_found
> 0 && mode
== '@' && !devmode
) {
262 fprintf(stderr
, Name
": Must give one of -a/-r/-f for subsequent devices at %s\n", optarg
);
265 if (devs_found
> 0 && mode
== 'G' && !devmode
) {
266 fprintf(stderr
, Name
": Must give one of -a for devices do add: %s\n", optarg
);
269 dv
= malloc(sizeof(*dv
));
271 fprintf(stderr
, Name
": malloc failed\n");
274 dv
->devname
= optarg
;
275 dv
->disposition
= devmode
;
276 dv
->writemostly
= writemostly
;
280 devlistend
= &dv
->next
;
286 /* We've got a mode, and opt is now something else which
287 * could depend on the mode */
288 #define O(a,b) ((a<<8)|b)
289 switch (O(mode
,opt
)) {
291 case O(BUILD
,'c'): /* chunk or rounding */
293 fprintf(stderr
, Name
": chunk/rounding may only be specified once. "
294 "Second value is %s.\n", optarg
);
297 chunk
= strtol(optarg
, &c
, 10);
298 if (!optarg
[0] || *c
|| chunk
<4 || ((chunk
-1)&chunk
)) {
299 fprintf(stderr
, Name
": invalid chunk/rounding value: %s\n",
306 case O(ASSEMBLE
,'e'):
307 case O(MISC
,'e'): /* set metadata (superblock) information */
309 fprintf(stderr
, Name
": metadata information already given\n");
312 for(i
=0; !ss
&& superlist
[i
]; i
++)
313 ss
= superlist
[i
]->match_metadata_desc(optarg
);
316 fprintf(stderr
, Name
": unrecognised metadata identifier: %s\n", optarg
);
319 max_disks
= ss
->max_devs
;
325 /* set write-mostly for following devices */
330 case O(CREATE
,'z'): /* size */
332 fprintf(stderr
, Name
": size may only be specified once. "
333 "Second value is %s.\n", optarg
);
336 if (strcmp(optarg
, "max")==0)
339 size
= strtol(optarg
, &c
, 10);
340 if (!optarg
[0] || *c
|| size
< 4) {
341 fprintf(stderr
, Name
": invalid size: %s\n",
348 case O(GROW
,'l'): /* hack - needed to understand layout */
350 case O(BUILD
,'l'): /* set raid level*/
351 if (level
!= UnSet
) {
352 fprintf(stderr
, Name
": raid level may only be set once. "
353 "Second value is %s.\n", optarg
);
356 level
= map_name(pers
, optarg
);
357 if (level
== UnSet
) {
358 fprintf(stderr
, Name
": invalid raid level: %s\n",
362 if (level
!= 0 && level
!= -1 && level
!= 1 && level
!= -4 && level
!= -5 && mode
== BUILD
) {
363 fprintf(stderr
, Name
": Raid level %s not permitted with --build.\n",
367 if (sparedisks
> 0 && level
< 1 && level
>= -1) {
368 fprintf(stderr
, Name
": raid level %s is incompatible with spare-devices setting.\n",
375 case O(CREATE
,'p'): /* raid5 layout */
376 case O(BUILD
,'p'): /* faulty layout */
377 case O(GROW
, 'p'): /* faulty reconfig */
378 if (layout
!= UnSet
) {
379 fprintf(stderr
,Name
": layout may only be sent once. "
380 "Second value was %s\n", optarg
);
385 fprintf(stderr
, Name
": layout not meaningful for %s arrays.\n",
386 map_num(pers
, level
));
389 fprintf(stderr
, Name
": raid level must be given before layout.\n");
394 layout
= map_name(r5layout
, optarg
);
396 fprintf(stderr
, Name
": layout %s not understood for raid5.\n",
403 /* 'f' or 'n' followed by a number <= raid_disks */
404 if ((optarg
[0] != 'n' && optarg
[0] != 'f') ||
405 (copies
= strtoul(optarg
+1, &cp
, 10)) < 1 ||
408 fprintf(stderr
, Name
": layout for raid10 must be 'nNN' or 'fNN' where NN is a number, not %s\n", optarg
);
411 if (optarg
[0] == 'n')
412 layout
= 256 + copies
;
414 layout
= 1 + (copies
<<8);
421 int ln
= strcspn(optarg
, "0123456789");
422 char *m
= strdup(optarg
);
425 mode
= map_name(faultylayout
, m
);
427 fprintf(stderr
, Name
": layout %s not understood for faulty.\n",
431 layout
= mode
| (atoi(optarg
+ln
)<< ModeShift
);
437 case O(BUILD
,3): /* assume clean */
443 case O(BUILD
,'n'): /* number of raid disks */
445 fprintf(stderr
, Name
": raid-devices set twice: %d and %s\n",
449 raiddisks
= strtol(optarg
, &c
, 10);
450 if (!optarg
[0] || *c
|| raiddisks
<=0) {
451 fprintf(stderr
, Name
": invalid number of raid devices: %s\n",
455 ident
.raid_disks
= raiddisks
;
458 case O(CREATE
,'x'): /* number of spare (eXtra) discs */
460 fprintf(stderr
,Name
": spare-devices set twice: %d and %s\n",
464 if (level
!= UnSet
&& level
<= 0 && level
>= -1) {
465 fprintf(stderr
, Name
": spare-devices setting is incompatible with raid level %d\n",
469 sparedisks
= strtol(optarg
, &c
, 10);
470 if (!optarg
[0] || *c
|| sparedisks
< 0) {
471 fprintf(stderr
, Name
": invalid number of spare-devices: %s\n",
479 case O(ASSEMBLE
,'a'): /* auto-creation of device node */
482 else if (strcasecmp(optarg
,"no")==0)
484 else if (strcasecmp(optarg
,"yes")==0)
486 else if (strcasecmp(optarg
,"md")==0)
489 /* There might be digits, and maybe a hypen, at the end */
490 char *e
= optarg
+ strlen(optarg
);
493 while (e
> optarg
&& isdigit(e
[-1]))
497 if (num
<= 0) num
= 1;
499 if (e
> optarg
&& e
[-1] == '-')
502 if ((len
== 3 && strncasecmp(optarg
,"mdp",3)==0) ||
503 (len
== 1 && strncasecmp(optarg
,"p",1)==0) ||
504 (len
>= 4 && strncasecmp(optarg
,"part",4)==0))
507 fprintf(stderr
, Name
": --auto flag arg of \"%s\" unrecognised: use no,yes,md,mdp,part\n"
508 " optionally followed by a number.\n",
515 case O(BUILD
,'f'): /* force honouring '-n 1' */
516 case O(GROW
,'f'): /* ditto */
517 case O(CREATE
,'f'): /* force honouring of device list */
518 case O(ASSEMBLE
,'f'): /* force assembly */
519 case O(MISC
,'f'): /* force zero */
523 /* now for the Assemble options */
524 case O(ASSEMBLE
,'u'): /* uuid of array */
525 if (ident
.uuid_set
) {
526 fprintf(stderr
, Name
": uuid cannot be set twice. "
527 "Second value %s.\n", optarg
);
530 if (parse_uuid(optarg
, ident
.uuid
))
533 fprintf(stderr
,Name
": Bad uuid: %s\n", optarg
);
539 case O(ASSEMBLE
,'N'):
541 fprintf(stderr
, Name
": name cannot be set twice. "
542 "Second value %s.\n", optarg
);
545 if (strlen(optarg
) > 32) {
546 fprintf(stderr
, Name
": name '%s' is too long, 32 chars max.\n",
550 strcpy(ident
.name
, optarg
);
553 case O(ASSEMBLE
,'m'): /* super-minor for array */
554 if (ident
.super_minor
!= UnSet
) {
555 fprintf(stderr
, Name
": super-minor cannot be set twice. "
556 "Second value: %s.\n", optarg
);
559 if (strcmp(optarg
, "dev")==0)
560 ident
.super_minor
= -2;
562 ident
.super_minor
= strtoul(optarg
, &cp
, 10);
563 if (!optarg
[0] || *cp
) {
564 fprintf(stderr
, Name
": Bad super-minor number: %s.\n", optarg
);
570 case O(ASSEMBLE
,'U'): /* update the superblock */
572 fprintf(stderr
, Name
": Can only update one aspect of superblock, both %s and %s given.\n",
577 if (strcmp(update
, "sparc2.2")==0)
579 if (strcmp(update
, "super-minor") == 0)
581 if (strcmp(update
, "summaries")==0)
583 if (strcmp(update
, "resync")==0)
585 if (strcmp(update
, "byteorder")==0) {
587 fprintf(stderr
, Name
": must not set metadata type with --update=byteorder.\n");
590 for(i
=0; !ss
&& superlist
[i
]; i
++)
591 ss
= superlist
[i
]->match_metadata_desc("0.swap");
593 fprintf(stderr
, Name
": INTERNAL ERROR cannot find 0.swap\n");
599 fprintf(stderr
, Name
": '--update %s' invalid. Only 'sparc2.2', 'super-minor', 'resync' or 'summaries' supported\n",update
);
602 case O(ASSEMBLE
,'c'): /* config file */
606 fprintf(stderr
, Name
": configfile cannot be set twice. "
607 "Second value is %s.\n", optarg
);
611 /* FIXME possibly check that config file exists. Even parse it */
613 case O(ASSEMBLE
,'s'): /* scan */
619 case O(MONITOR
,'m'): /* mail address */
621 fprintf(stderr
, Name
": only specify one mailaddress. %s ignored.\n",
627 case O(MONITOR
,'p'): /* alert program */
629 fprintf(stderr
, Name
": only specify one alter program. %s ignored.\n",
635 case O(MONITOR
,'d'): /* delay in seconds */
637 case O(BUILD
,'d'): /* delay for bitmap updates */
640 fprintf(stderr
, Name
": only specify delay once. %s ignored.\n",
643 delay
= strtol(optarg
, &c
, 10);
644 if (!optarg
[0] || *c
|| delay
<1) {
645 fprintf(stderr
, Name
": invalid delay: %s\n",
651 case O(MONITOR
,'f'): /* daemonise */
654 case O(MONITOR
,'i'): /* pid */
656 fprintf(stderr
, Name
": only specify one pid file. %s ignored.\n",
661 case O(MONITOR
,'1'): /* oneshot */
664 case O(MONITOR
,'t'): /* test */
668 /* now the general management options. Some are applicable
669 * to other modes. None have arguments.
672 case O(MANAGE
,'a'): /* add a drive */
680 case O(MANAGE
,'r'): /* remove a drive */
683 case O(MANAGE
,'f'): /* set faulty */
687 case O(ASSEMBLE
,'R'):
689 case O(CREATE
,'R'): /* Run the array */
691 fprintf(stderr
, Name
": Cannot both Stop and Run an array\n");
698 fprintf(stderr
, Name
": Cannot both Run and Stop an array\n");
706 fprintf(stderr
, Name
": Cannot have both readonly and readwrite\n");
713 fprintf(stderr
, Name
": Cannot have both readwrite and readonly.\n");
728 if (devmode
&& devmode
!= opt
&&
729 (devmode
== 'E' || (opt
== 'E' && devmode
!= 'Q'))) {
730 fprintf(stderr
, Name
": --examine/-E cannot be given with -%c\n",
731 devmode
=='E'?opt
:devmode
);
741 if (devmode
!= 'E') {
742 fprintf(stderr
, Name
": --sparc2.2 only allowed with --examine\n");
748 case O(ASSEMBLE
,'b'): /* here we simply set the bitmap file */
750 fprintf(stderr
, Name
": bitmap file needed with -b in --assemble mode\n");
753 if (strcmp(optarg
, "internal")==0) {
754 fprintf(stderr
, Name
": there is no need to specify --bitmap when assembling arrays with internal bitmaps\n");
757 bitmap_fd
= open(optarg
, O_RDWR
);
758 if (!*optarg
|| bitmap_fd
< 0) {
759 fprintf(stderr
, Name
": cannot open bitmap file %s: %s\n", optarg
, strerror(errno
));
762 ident
.bitmap_fd
= bitmap_fd
; /* for Assemble */
767 case O(CREATE
,'b'): /* here we create the bitmap */
768 bitmap_file
= optarg
;
773 case O(CREATE
,4): /* bitmap chunksize */
774 bitmap_chunk
= strtol(optarg
, &c
, 10);
775 if (!optarg
[0] || *c
|| bitmap_chunk
< 0 ||
776 bitmap_chunk
& (bitmap_chunk
- 1)) {
777 fprintf(stderr
, Name
": invalid bitmap chunksize: %s\n",
781 /* convert K to B, chunk of 0K means 512B */
782 bitmap_chunk
= bitmap_chunk
? bitmap_chunk
* 1024 : 512;
786 case O(CREATE
, 5): /* write-behind mode */
787 write_behind
= DEFAULT_MAX_WRITE_BEHIND
;
789 write_behind
= strtol(optarg
, &c
, 10);
790 if (write_behind
< 0 || *c
||
791 write_behind
> 16383) {
792 fprintf(stderr
, Name
": Invalid value for maximum outstanding write-behind writes: %s.\n\tMust be between 0 and 16383.\n", optarg
);
798 /* We have now processed all the valid options. Anything else is
801 fprintf(stderr
, Name
": option %c not valid in %s mode\n",
802 opt
, map_num(modes
, mode
));
807 if (!mode
&& devs_found
) {
810 if (devlist
->disposition
== 0)
811 devlist
->disposition
= devmode
;
814 fputs(Usage
, stderr
);
817 /* Ok, got the option parsing out of the way
818 * hopefully it's mostly right but there might be some stuff
821 * That is mosty checked in the per-mode stuff but...
823 * For @,B,C and A without -s, the first device listed must be an md device
824 * we check that here and open it.
827 if (mode
==MANAGE
|| mode
== BUILD
|| mode
== CREATE
|| mode
== GROW
||
828 (mode
== ASSEMBLE
&& ! scan
)) {
829 if (devs_found
< 1) {
830 fprintf(stderr
, Name
": an md device must be given in this mode\n");
833 if ((int)ident
.super_minor
== -2 && autof
) {
834 fprintf(stderr
, Name
": --super-minor=dev is incompatible with --auto\n");
837 mdfd
= open_mddev(devlist
->devname
, autof
);
840 if ((int)ident
.super_minor
== -2) {
843 ident
.super_minor
= minor(stb
.st_rdev
);
848 if (raiddisks
> max_disks
) {
849 fprintf(stderr
, Name
": invalid number of raid devices: %d\n",
853 if (raiddisks
== 1 && !force
&& level
!= -5) {
854 fprintf(stderr
, Name
": '1' is an unusual number of drives for an array, so it is probably\n"
855 " a mistake. If you really mean it you will need to specify --force before\n"
856 " setting the number of drives.\n");
861 if ( sparedisks
> max_disks
- raiddisks
) {
862 fprintf(stderr
, Name
": invalid number of spare-devices: %d\n",
871 /* readonly, add/remove, readwrite, runstop */
873 rv
= Manage_ro(devlist
->devname
, mdfd
, readonly
);
874 if (!rv
&& devs_found
>1)
875 rv
= Manage_subdevs(devlist
->devname
, mdfd
,
876 devlist
->next
, verbose
-quiet
);
877 if (!rv
&& readonly
< 0)
878 rv
= Manage_ro(devlist
->devname
, mdfd
, readonly
);
880 rv
= Manage_runstop(devlist
->devname
, mdfd
, runstop
, 0);
883 if (devs_found
== 1 && ident
.uuid_set
== 0 &&
884 ident
.super_minor
== UnSet
&& ident
.name
[0] == 0 && !scan
) {
885 /* Only a device has been given, so get details from config file */
886 mddev_ident_t array_ident
= conf_get_ident(configfile
, devlist
->devname
);
887 if (array_ident
== NULL
) {
888 fprintf(stderr
, Name
": %s not identified in config file.\n",
892 mdfd
= open_mddev(devlist
->devname
,
893 array_ident
->autof
? array_ident
->autof
: autof
);
897 rv
|= Assemble(ss
, devlist
->devname
, mdfd
, array_ident
, configfile
,
899 readonly
, runstop
, update
, verbose
-quiet
, force
);
904 rv
= Assemble(ss
, devlist
->devname
, mdfd
, &ident
, configfile
,
906 readonly
, runstop
, update
, verbose
-quiet
, force
);
907 else if (devs_found
>0) {
908 if (update
&& devs_found
> 1) {
909 fprintf(stderr
, Name
": can only update a single array at a time\n");
912 for (dv
= devlist
; dv
; dv
=dv
->next
) {
913 mddev_ident_t array_ident
= conf_get_ident(configfile
, dv
->devname
);
914 if (array_ident
== NULL
) {
915 fprintf(stderr
, Name
": %s not identified in config file.\n",
920 mdfd
= open_mddev(dv
->devname
,
921 array_ident
->autof
?array_ident
->autof
: autof
);
926 rv
|= Assemble(ss
, dv
->devname
, mdfd
, array_ident
, configfile
,
928 readonly
, runstop
, update
, verbose
-quiet
, force
);
932 mddev_ident_t array_list
= conf_get_ident(configfile
, NULL
);
934 fprintf(stderr
, Name
": No arrays found in config file\n");
937 for (; array_list
; array_list
= array_list
->next
) {
938 mdu_array_info_t array
;
939 mdfd
= open_mddev(array_list
->devname
,
940 array_list
->autof
? array_list
->autof
: autof
);
945 if (ioctl(mdfd
, GET_ARRAY_INFO
, &array
)>=0)
946 /* already assembled, skip */
949 rv
|= Assemble(ss
, array_list
->devname
, mdfd
,
950 array_list
, configfile
,
952 readonly
, runstop
, NULL
, verbose
-quiet
, force
);
958 if (bitmap_chunk
== UnSet
) bitmap_chunk
= DEFAULT_BITMAP_CHUNK
;
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");
967 if (strcmp(bitmap_file
, "internal")==0) {
968 fprintf(stderr
, Name
": 'internal' bitmaps not supported with --build\n");
973 rv
= Build(devlist
->devname
, mdfd
, chunk
, level
, layout
,
974 raiddisks
, devlist
->next
, assume_clean
,
975 bitmap_file
, bitmap_chunk
, write_behind
, delay
, verbose
-quiet
);
978 if (delay
== 0) delay
= DEFAULT_BITMAP_DELAY
;
979 if (write_behind
&& !bitmap_file
) {
980 fprintf(stderr
, Name
": write-behind mode requires a bitmap.\n");
985 for(i
=0; !ss
&& superlist
[i
]; i
++)
986 ss
= superlist
[i
]->match_metadata_desc("default");
989 fprintf(stderr
, Name
": internal error - no default metadata style\n");
993 rv
= Create(ss
, devlist
->devname
, mdfd
, chunk
, level
, layout
, size
<0 ? 0 : size
,
994 raiddisks
, sparedisks
, ident
.name
,
995 devs_found
-1, devlist
->next
, runstop
, verbose
-quiet
, force
,
996 bitmap_file
, bitmap_chunk
, write_behind
, delay
);
1000 if (devmode
== 'E') {
1001 if (devlist
== NULL
&& !scan
) {
1002 fprintf(stderr
, Name
": No devices to examine\n");
1005 if (devlist
== NULL
)
1006 devlist
= conf_get_devs(configfile
);
1007 if (devlist
== NULL
) {
1008 fprintf(stderr
, Name
": No devices listed in %s\n", configfile
?configfile
:DefaultConfFile
);
1011 rv
= Examine(devlist
, scan
?(verbose
>1?0:verbose
+1):brief
, scan
, SparcAdjust
, ss
);
1013 if (devlist
== NULL
) {
1014 if (devmode
=='D' && scan
) {
1015 /* apply --detail to all devices in /proc/mdstat */
1016 struct mdstat_ent
*ms
= mdstat_read(0);
1017 struct mdstat_ent
*e
;
1018 for (e
=ms
; e
; e
=e
->next
) {
1019 char *name
= get_md_name(e
->devnum
);
1022 fprintf(stderr
, Name
": cannot find device file for %s\n",
1026 rv
|= Detail(name
, verbose
>1?0:verbose
+1, test
);
1029 } else if (devmode
== 'S' && scan
) {
1030 /* apply --stop to all devices in /proc/mdstat */
1031 /* Due to possible stacking of devices, repeat until
1032 * nothing more can be stopped
1034 int progress
=1, err
;
1037 struct mdstat_ent
*ms
= mdstat_read(0);
1038 struct mdstat_ent
*e
;
1040 if (!progress
) last
= 1;
1041 progress
= 0; err
= 0;
1042 for (e
=ms
; e
; e
=e
->next
) {
1043 char *name
= get_md_name(e
->devnum
);
1046 fprintf(stderr
, Name
": cannot find device file for %s\n",
1050 mdfd
= open_mddev(name
, 0);
1052 if (Manage_runstop(name
, mdfd
, -1, !last
))
1061 } while (!last
&& err
);
1063 fprintf(stderr
, Name
": No devices given.\n");
1067 for (dv
=devlist
; dv
; dv
=dv
->next
) {
1068 switch(dv
->disposition
) {
1070 rv
|= Detail(dv
->devname
, brief
?1+verbose
:0, test
); continue;
1071 case 'K': /* Zero superblock */
1072 rv
|= Kill(dv
->devname
, force
); continue;
1074 rv
|= Query(dv
->devname
); continue;
1076 rv
|= ExamineBitmap(dv
->devname
, brief
, ss
); continue;
1078 mdfd
= open_mddev(dv
->devname
, 0);
1080 switch(dv
->disposition
) {
1082 rv
|= Manage_runstop(dv
->devname
, mdfd
, 1, 0); break;
1084 rv
|= Manage_runstop(dv
->devname
, mdfd
, -1, 0); break;
1086 rv
|= Manage_ro(dv
->devname
, mdfd
, 1); break;
1088 rv
|= Manage_ro(dv
->devname
, mdfd
, -1); break;
1096 if (!devlist
&& !scan
) {
1097 fprintf(stderr
, Name
": Cannot monitor: need --scan or at least one device\n");
1101 if (pidfile
&& !daemonise
) {
1102 fprintf(stderr
, Name
": Cannot write a pid file when not in daemon mode\n");
1106 rv
= Monitor(devlist
, mailaddr
, program
,
1107 delay
?delay
:60, daemonise
, scan
, oneshot
, configfile
, test
, pidfile
);
1111 if (devs_found
> 1) {
1114 if (size
>= 0 || raiddisks
) {
1115 fprintf(stderr
, Name
": --size, --raiddisks, and --add are exclusing in --grow mode\n");
1119 for (dv
=devlist
->next
; dv
; dv
=dv
->next
) {
1120 rv
= Grow_Add_device(devlist
->devname
, mdfd
, dv
->devname
);
1124 } else if ((size
>= 0) + (raiddisks
!= 0) + (layout
!= UnSet
) + (bitmap_file
!= NULL
)> 1) {
1125 fprintf(stderr
, Name
": can change at most one of size, raiddisks, bitmap, and layout\n");
1128 } else if (layout
!= UnSet
)
1129 rv
= Manage_reconfig(devlist
->devname
, mdfd
, layout
);
1130 else if (size
>= 0 || raiddisks
)
1131 rv
= Manage_resize(devlist
->devname
, mdfd
, size
, raiddisks
);
1132 else if (bitmap_file
) {
1133 if (delay
== 0) delay
= DEFAULT_BITMAP_DELAY
;
1134 rv
= Grow_addbitmap(devlist
->devname
, mdfd
, bitmap_file
,
1135 bitmap_chunk
, delay
, write_behind
);
1137 fprintf(stderr
, Name
": no changes to --grow\n");