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
[])
52 int max_disks
= MD_SB_DISKS
;
54 struct mddev_ident_s ident
;
55 char *configfile
= NULL
;
64 char *bitmap_file
= NULL
;
65 int bitmap_chunk
= UnSet
;
67 mddev_dev_t devlist
= NULL
;
68 mddev_dev_t
*devlistend
= & devlist
;
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
;
95 char *shortopt
= short_options
;
103 srandom(time(0) ^ getpid());
107 ident
.raid_disks
= UnSet
;
108 ident
.super_minor
= UnSet
;
110 ident
.spare_group
= NULL
;
113 ident
.bitmap_fd
= -1;
116 while ((option_index
= -1) ,
117 (opt
=getopt_long(argc
, argv
,
118 shortopt
, long_options
,
119 &option_index
)) != -1) {
121 /* firstly, some mode-independant options */
124 if (option_index
> 0 &&
125 strcmp(long_options
[option_index
].name
, "help-options")==0)
132 fputs(Version
, stderr
);
142 if (mode
== ASSEMBLE
|| mode
== BUILD
|| mode
== CREATE
|| mode
== GROW
)
143 break; /* b means bitmap */
146 fprintf(stderr
, Name
": -b cannot have any extra immediately after it, sorry.\n");
153 fputs(Usage
, stderr
);
156 /* second, figure out the mode.
157 * Some options force the mode. Others
158 * set the mode if it isn't already
162 case '@': /* just incase they say --manage */
164 shortopt
= short_bitmap_auto_options
;
172 shortopt
= short_bitmap_auto_options
;
176 case 'A': newmode
= ASSEMBLE
; shortopt
= short_bitmap_auto_options
; break;
177 case 'B': newmode
= BUILD
; shortopt
= short_bitmap_auto_options
; break;
178 case 'C': newmode
= CREATE
; shortopt
= short_bitmap_auto_options
; break;
179 case 'F': newmode
= MONITOR
;break;
180 case 'G': newmode
= GROW
; shortopt
= short_bitmap_auto_options
; break;
186 case 'Q': newmode
= MISC
; break;
191 case 'K': if (!mode
) newmode
= MISC
; break;
193 if (mode
&& newmode
== mode
) {
194 /* everybody happy ! */
195 } else if (mode
&& newmode
!= mode
) {
197 fprintf(stderr
, Name
": ");
198 if (option_index
>= 0)
199 fprintf(stderr
, "--%s", long_options
[option_index
].name
);
201 fprintf(stderr
, "-%c", opt
);
202 fprintf(stderr
, " would set mdadm mode to \"%s\", but it is already set to \"%s\".\n",
203 map_num(modes
, newmode
),
204 map_num(modes
, mode
));
206 } else if (!mode
&& newmode
) {
209 /* special case of -c --help */
211 ( strncmp(optarg
, "--h", 3)==0 ||
212 strncmp(optarg
, "-h", 2)==0)) {
213 fputs(Help_config
, stderr
);
217 /* If first option is a device, don't force the mode yet */
219 if (devs_found
== 0) {
220 dv
= malloc(sizeof(*dv
));
222 fprintf(stderr
, Name
": malloc failed\n");
225 dv
->devname
= optarg
;
226 dv
->disposition
= devmode
;
227 dv
->writemostly
= writemostly
;
231 devlistend
= &dv
->next
;
236 /* No mode yet, and this is the second device ... */
237 fprintf(stderr
, Name
": An option must be given to set the mode before a second device is listed\n");
240 if (option_index
>= 0)
241 fprintf(stderr
, Name
": --%s", long_options
[option_index
].name
);
243 fprintf(stderr
, Name
": -%c", opt
);
244 fprintf(stderr
, " does not set the mode, and so cannot be the first option.\n");
248 /* if we just set the mode, then done */
260 /* an undecorated option - must be a device name.
262 if (devs_found
> 0 && mode
== '@' && !devmode
) {
263 fprintf(stderr
, Name
": Must give one of -a/-r/-f for subsequent devices at %s\n", optarg
);
266 if (devs_found
> 0 && mode
== 'G' && !devmode
) {
267 fprintf(stderr
, Name
": Must give one of -a for devices do add: %s\n", optarg
);
270 dv
= malloc(sizeof(*dv
));
272 fprintf(stderr
, Name
": malloc failed\n");
275 dv
->devname
= optarg
;
276 dv
->disposition
= devmode
;
277 dv
->writemostly
= writemostly
;
281 devlistend
= &dv
->next
;
287 /* We've got a mode, and opt is now something else which
288 * could depend on the mode */
289 #define O(a,b) ((a<<8)|b)
290 switch (O(mode
,opt
)) {
292 case O(BUILD
,'c'): /* chunk or rounding */
294 fprintf(stderr
, Name
": chunk/rounding may only be specified once. "
295 "Second value is %s.\n", optarg
);
298 chunk
= strtol(optarg
, &c
, 10);
299 if (!optarg
[0] || *c
|| chunk
<4 || ((chunk
-1)&chunk
)) {
300 fprintf(stderr
, Name
": invalid chunk/rounding value: %s\n",
307 case O(ASSEMBLE
,'e'):
308 case O(MISC
,'e'): /* set metadata (superblock) information */
310 fprintf(stderr
, Name
": metadata information already given\n");
313 for(i
=0; !ss
&& superlist
[i
]; i
++)
314 ss
= superlist
[i
]->match_metadata_desc(optarg
);
317 fprintf(stderr
, Name
": unrecognised metadata identifier: %s\n", optarg
);
320 max_disks
= ss
->max_devs
;
326 /* set write-mostly for following devices */
331 case O(CREATE
,'z'): /* size */
333 fprintf(stderr
, Name
": size may only be specified once. "
334 "Second value is %s.\n", optarg
);
337 if (strcmp(optarg
, "max")==0)
340 size
= strtoll(optarg
, &c
, 10);
341 if (!optarg
[0] || *c
|| size
< 4) {
342 fprintf(stderr
, Name
": invalid size: %s\n",
349 case O(GROW
,'l'): /* hack - needed to understand layout */
351 case O(BUILD
,'l'): /* set raid level*/
352 if (level
!= UnSet
) {
353 fprintf(stderr
, Name
": raid level may only be set once. "
354 "Second value is %s.\n", optarg
);
357 level
= map_name(pers
, optarg
);
358 if (level
== UnSet
) {
359 fprintf(stderr
, Name
": invalid raid level: %s\n",
363 if (level
!= 0 && level
!= -1 && level
!= 1 && level
!= -4 && level
!= -5 && mode
== BUILD
) {
364 fprintf(stderr
, Name
": Raid level %s not permitted with --build.\n",
368 if (sparedisks
> 0 && level
< 1 && level
>= -1) {
369 fprintf(stderr
, Name
": raid level %s is incompatible with spare-devices setting.\n",
376 case O(CREATE
,'p'): /* raid5 layout */
377 case O(BUILD
,'p'): /* faulty layout */
378 case O(GROW
, 'p'): /* faulty reconfig */
379 if (layout
!= UnSet
) {
380 fprintf(stderr
,Name
": layout may only be sent once. "
381 "Second value was %s\n", optarg
);
386 fprintf(stderr
, Name
": layout not meaningful for %s arrays.\n",
387 map_num(pers
, level
));
390 fprintf(stderr
, Name
": raid level must be given before layout.\n");
395 layout
= map_name(r5layout
, optarg
);
397 fprintf(stderr
, Name
": layout %s not understood for raid5.\n",
404 /* 'f' or 'n' followed by a number <= raid_disks */
405 if ((optarg
[0] != 'n' && optarg
[0] != 'f') ||
406 (copies
= strtoul(optarg
+1, &cp
, 10)) < 1 ||
409 fprintf(stderr
, Name
": layout for raid10 must be 'nNN' or 'fNN' where NN is a number, not %s\n", optarg
);
412 if (optarg
[0] == 'n')
413 layout
= 256 + copies
;
415 layout
= 1 + (copies
<<8);
422 int ln
= strcspn(optarg
, "0123456789");
423 char *m
= strdup(optarg
);
426 mode
= map_name(faultylayout
, m
);
428 fprintf(stderr
, Name
": layout %s not understood for faulty.\n",
432 layout
= mode
| (atoi(optarg
+ln
)<< ModeShift
);
438 case O(BUILD
,3): /* assume clean */
444 case O(BUILD
,'n'): /* number of raid disks */
446 fprintf(stderr
, Name
": raid-devices set twice: %d and %s\n",
450 raiddisks
= strtol(optarg
, &c
, 10);
451 if (!optarg
[0] || *c
|| raiddisks
<=0) {
452 fprintf(stderr
, Name
": invalid number of raid devices: %s\n",
456 ident
.raid_disks
= raiddisks
;
459 case O(CREATE
,'x'): /* number of spare (eXtra) discs */
461 fprintf(stderr
,Name
": spare-devices set twice: %d and %s\n",
465 if (level
!= UnSet
&& level
<= 0 && level
>= -1) {
466 fprintf(stderr
, Name
": spare-devices setting is incompatible with raid level %d\n",
470 sparedisks
= strtol(optarg
, &c
, 10);
471 if (!optarg
[0] || *c
|| sparedisks
< 0) {
472 fprintf(stderr
, Name
": invalid number of spare-devices: %s\n",
480 case O(ASSEMBLE
,'a'): /* auto-creation of device node */
483 else if (strcasecmp(optarg
,"no")==0)
485 else if (strcasecmp(optarg
,"yes")==0)
487 else if (strcasecmp(optarg
,"md")==0)
490 /* There might be digits, and maybe a hypen, at the end */
491 char *e
= optarg
+ strlen(optarg
);
494 while (e
> optarg
&& isdigit(e
[-1]))
498 if (num
<= 0) num
= 1;
500 if (e
> optarg
&& e
[-1] == '-')
503 if ((len
== 3 && strncasecmp(optarg
,"mdp",3)==0) ||
504 (len
== 1 && strncasecmp(optarg
,"p",1)==0) ||
505 (len
>= 4 && strncasecmp(optarg
,"part",4)==0))
508 fprintf(stderr
, Name
": --auto flag arg of \"%s\" unrecognised: use no,yes,md,mdp,part\n"
509 " optionally followed by a number.\n",
516 case O(BUILD
,'f'): /* force honouring '-n 1' */
517 case O(GROW
,'f'): /* ditto */
518 case O(CREATE
,'f'): /* force honouring of device list */
519 case O(ASSEMBLE
,'f'): /* force assembly */
520 case O(MISC
,'f'): /* force zero */
524 /* now for the Assemble options */
525 case O(ASSEMBLE
,'u'): /* uuid of array */
526 if (ident
.uuid_set
) {
527 fprintf(stderr
, Name
": uuid cannot be set twice. "
528 "Second value %s.\n", optarg
);
531 if (parse_uuid(optarg
, ident
.uuid
))
534 fprintf(stderr
,Name
": Bad uuid: %s\n", optarg
);
540 case O(ASSEMBLE
,'N'):
542 fprintf(stderr
, Name
": name cannot be set twice. "
543 "Second value %s.\n", optarg
);
546 if (strlen(optarg
) > 32) {
547 fprintf(stderr
, Name
": name '%s' is too long, 32 chars max.\n",
551 strcpy(ident
.name
, optarg
);
554 case O(ASSEMBLE
,'m'): /* super-minor for array */
555 if (ident
.super_minor
!= UnSet
) {
556 fprintf(stderr
, Name
": super-minor cannot be set twice. "
557 "Second value: %s.\n", optarg
);
560 if (strcmp(optarg
, "dev")==0)
561 ident
.super_minor
= -2;
563 ident
.super_minor
= strtoul(optarg
, &cp
, 10);
564 if (!optarg
[0] || *cp
) {
565 fprintf(stderr
, Name
": Bad super-minor number: %s.\n", optarg
);
571 case O(ASSEMBLE
,'U'): /* update the superblock */
573 fprintf(stderr
, Name
": Can only update one aspect of superblock, both %s and %s given.\n",
578 if (strcmp(update
, "sparc2.2")==0)
580 if (strcmp(update
, "super-minor") == 0)
582 if (strcmp(update
, "summaries")==0)
584 if (strcmp(update
, "resync")==0)
586 if (strcmp(update
, "uuid")==0)
588 if (strcmp(update
, "byteorder")==0) {
590 fprintf(stderr
, Name
": must not set metadata type with --update=byteorder.\n");
593 for(i
=0; !ss
&& superlist
[i
]; i
++)
594 ss
= superlist
[i
]->match_metadata_desc("0.swap");
596 fprintf(stderr
, Name
": INTERNAL ERROR cannot find 0.swap\n");
602 fprintf(stderr
, Name
": '--update %s' invalid. Only 'sparc2.2', 'super-minor', 'uuid', 'resync' or 'summaries' supported\n",update
);
605 case O(ASSEMBLE
,'c'): /* config file */
609 fprintf(stderr
, Name
": configfile cannot be set twice. "
610 "Second value is %s.\n", optarg
);
614 /* FIXME possibly check that config file exists. Even parse it */
616 case O(ASSEMBLE
,'s'): /* scan */
622 case O(MONITOR
,'m'): /* mail address */
624 fprintf(stderr
, Name
": only specify one mailaddress. %s ignored.\n",
630 case O(MONITOR
,'p'): /* alert program */
632 fprintf(stderr
, Name
": only specify one alter program. %s ignored.\n",
638 case O(MONITOR
,'d'): /* delay in seconds */
640 case O(BUILD
,'d'): /* delay for bitmap updates */
643 fprintf(stderr
, Name
": only specify delay once. %s ignored.\n",
646 delay
= strtol(optarg
, &c
, 10);
647 if (!optarg
[0] || *c
|| delay
<1) {
648 fprintf(stderr
, Name
": invalid delay: %s\n",
654 case O(MONITOR
,'f'): /* daemonise */
657 case O(MONITOR
,'i'): /* pid */
659 fprintf(stderr
, Name
": only specify one pid file. %s ignored.\n",
664 case O(MONITOR
,'1'): /* oneshot */
667 case O(MONITOR
,'t'): /* test */
670 case O(MONITOR
,'y'): /* log messages to syslog */
671 openlog("mdadm", 0, SYSLOG_FACILITY
);
675 /* now the general management options. Some are applicable
676 * to other modes. None have arguments.
679 case O(MANAGE
,'a'): /* add a drive */
687 case O(MANAGE
,'r'): /* remove a drive */
690 case O(MANAGE
,'f'): /* set faulty */
694 case O(ASSEMBLE
,'R'):
696 case O(CREATE
,'R'): /* Run the array */
698 fprintf(stderr
, Name
": Cannot both Stop and Run an array\n");
705 fprintf(stderr
, Name
": Cannot both Run and Stop an array\n");
713 fprintf(stderr
, Name
": Cannot have both readonly and readwrite\n");
720 fprintf(stderr
, Name
": Cannot have both readwrite and readonly.\n");
735 if (devmode
&& devmode
!= opt
&&
736 (devmode
== 'E' || (opt
== 'E' && devmode
!= 'Q'))) {
737 fprintf(stderr
, Name
": --examine/-E cannot be given with -%c\n",
738 devmode
=='E'?opt
:devmode
);
748 if (devmode
!= 'E') {
749 fprintf(stderr
, Name
": --sparc2.2 only allowed with --examine\n");
755 case O(ASSEMBLE
,'b'): /* here we simply set the bitmap file */
757 fprintf(stderr
, Name
": bitmap file needed with -b in --assemble mode\n");
760 if (strcmp(optarg
, "internal")==0) {
761 fprintf(stderr
, Name
": there is no need to specify --bitmap when assembling arrays with internal bitmaps\n");
764 bitmap_fd
= open(optarg
, O_RDWR
);
765 if (!*optarg
|| bitmap_fd
< 0) {
766 fprintf(stderr
, Name
": cannot open bitmap file %s: %s\n", optarg
, strerror(errno
));
769 ident
.bitmap_fd
= bitmap_fd
; /* for Assemble */
774 case O(CREATE
,'b'): /* here we create the bitmap */
775 bitmap_file
= optarg
;
780 case O(CREATE
,4): /* bitmap chunksize */
781 bitmap_chunk
= strtol(optarg
, &c
, 10);
782 if (!optarg
[0] || *c
|| bitmap_chunk
< 0 ||
783 bitmap_chunk
& (bitmap_chunk
- 1)) {
784 fprintf(stderr
, Name
": invalid bitmap chunksize: %s\n",
788 /* convert K to B, chunk of 0K means 512B */
789 bitmap_chunk
= bitmap_chunk
? bitmap_chunk
* 1024 : 512;
793 case O(CREATE
, 5): /* write-behind mode */
794 write_behind
= DEFAULT_MAX_WRITE_BEHIND
;
796 write_behind
= strtol(optarg
, &c
, 10);
797 if (write_behind
< 0 || *c
||
798 write_behind
> 16383) {
799 fprintf(stderr
, Name
": Invalid value for maximum outstanding write-behind writes: %s.\n\tMust be between 0 and 16383.\n", optarg
);
805 /* We have now processed all the valid options. Anything else is
808 fprintf(stderr
, Name
": option %c not valid in %s mode\n",
809 opt
, map_num(modes
, mode
));
815 char *help_text
= Help
;
817 help_text
= OptionHelp
;
820 case ASSEMBLE
: help_text
= Help_assemble
; break;
821 case BUILD
: help_text
= Help_build
; break;
822 case CREATE
: help_text
= Help_create
; break;
823 case MANAGE
: help_text
= Help_manage
; break;
824 case MISC
: help_text
= Help_misc
; break;
825 case MONITOR
: help_text
= Help_monitor
; break;
826 case GROW
: help_text
= Help_grow
; break;
828 fputs(help_text
,stderr
);
832 if (!mode
&& devs_found
) {
835 if (devlist
->disposition
== 0)
836 devlist
->disposition
= devmode
;
839 fputs(Usage
, stderr
);
842 /* Ok, got the option parsing out of the way
843 * hopefully it's mostly right but there might be some stuff
846 * That is mosty checked in the per-mode stuff but...
848 * For @,B,C and A without -s, the first device listed must be an md device
849 * we check that here and open it.
852 if (mode
==MANAGE
|| mode
== BUILD
|| mode
== CREATE
|| mode
== GROW
||
853 (mode
== ASSEMBLE
&& ! scan
)) {
854 if (devs_found
< 1) {
855 fprintf(stderr
, Name
": an md device must be given in this mode\n");
858 if ((int)ident
.super_minor
== -2 && autof
) {
859 fprintf(stderr
, Name
": --super-minor=dev is incompatible with --auto\n");
862 mdfd
= open_mddev(devlist
->devname
, autof
);
865 if ((int)ident
.super_minor
== -2) {
868 ident
.super_minor
= minor(stb
.st_rdev
);
873 if (raiddisks
> max_disks
) {
874 fprintf(stderr
, Name
": invalid number of raid devices: %d\n",
878 if (raiddisks
== 1 && !force
&& level
!= -5) {
879 fprintf(stderr
, Name
": '1' is an unusual number of drives for an array, so it is probably\n"
880 " a mistake. If you really mean it you will need to specify --force before\n"
881 " setting the number of drives.\n");
886 if ( sparedisks
> max_disks
- raiddisks
) {
887 fprintf(stderr
, Name
": invalid number of spare-devices: %d\n",
896 /* readonly, add/remove, readwrite, runstop */
898 rv
= Manage_ro(devlist
->devname
, mdfd
, readonly
);
899 if (!rv
&& devs_found
>1)
900 rv
= Manage_subdevs(devlist
->devname
, mdfd
,
901 devlist
->next
, verbose
-quiet
);
902 if (!rv
&& readonly
< 0)
903 rv
= Manage_ro(devlist
->devname
, mdfd
, readonly
);
905 rv
= Manage_runstop(devlist
->devname
, mdfd
, runstop
, 0);
908 if (devs_found
== 1 && ident
.uuid_set
== 0 &&
909 ident
.super_minor
== UnSet
&& ident
.name
[0] == 0 && !scan
) {
910 /* Only a device has been given, so get details from config file */
911 mddev_ident_t array_ident
= conf_get_ident(configfile
, devlist
->devname
);
912 if (array_ident
== NULL
) {
913 fprintf(stderr
, Name
": %s not identified in config file.\n",
917 mdfd
= open_mddev(devlist
->devname
,
918 array_ident
->autof
? array_ident
->autof
: autof
);
922 rv
|= Assemble(ss
, devlist
->devname
, mdfd
, array_ident
, configfile
,
924 readonly
, runstop
, update
, verbose
-quiet
, force
);
929 rv
= Assemble(ss
, devlist
->devname
, mdfd
, &ident
, configfile
,
931 readonly
, runstop
, update
, verbose
-quiet
, force
);
932 else if (devs_found
>0) {
933 if (update
&& devs_found
> 1) {
934 fprintf(stderr
, Name
": can only update a single array at a time\n");
937 for (dv
= devlist
; dv
; dv
=dv
->next
) {
938 mddev_ident_t array_ident
= conf_get_ident(configfile
, dv
->devname
);
939 if (array_ident
== NULL
) {
940 fprintf(stderr
, Name
": %s not identified in config file.\n",
945 mdfd
= open_mddev(dv
->devname
,
946 array_ident
->autof
?array_ident
->autof
: autof
);
951 rv
|= Assemble(ss
, dv
->devname
, mdfd
, array_ident
, configfile
,
953 readonly
, runstop
, update
, verbose
-quiet
, force
);
957 mddev_ident_t array_list
= conf_get_ident(configfile
, NULL
);
959 fprintf(stderr
, Name
": No arrays found in config file\n");
962 for (; array_list
; array_list
= array_list
->next
) {
963 mdu_array_info_t array
;
964 mdfd
= open_mddev(array_list
->devname
,
965 array_list
->autof
? array_list
->autof
: autof
);
970 if (ioctl(mdfd
, GET_ARRAY_INFO
, &array
)>=0)
971 /* already assembled, skip */
974 rv
|= Assemble(ss
, array_list
->devname
, mdfd
,
975 array_list
, configfile
,
977 readonly
, runstop
, NULL
, verbose
-quiet
, force
);
983 if (bitmap_chunk
== UnSet
) bitmap_chunk
= DEFAULT_BITMAP_CHUNK
;
984 if (delay
== 0) delay
= DEFAULT_BITMAP_DELAY
;
985 if (write_behind
&& !bitmap_file
) {
986 fprintf(stderr
, Name
": write-behind mode requires a bitmap.\n");
992 if (strcmp(bitmap_file
, "internal")==0) {
993 fprintf(stderr
, Name
": 'internal' bitmaps not supported with --build\n");
998 rv
= Build(devlist
->devname
, mdfd
, chunk
, level
, layout
,
999 raiddisks
, devlist
->next
, assume_clean
,
1000 bitmap_file
, bitmap_chunk
, write_behind
, delay
, verbose
-quiet
);
1003 if (delay
== 0) delay
= DEFAULT_BITMAP_DELAY
;
1004 if (write_behind
&& !bitmap_file
) {
1005 fprintf(stderr
, Name
": write-behind mode requires a bitmap.\n");
1010 rv
= Create(ss
, devlist
->devname
, mdfd
, chunk
, level
, layout
, size
<0 ? 0 : size
,
1011 raiddisks
, sparedisks
, ident
.name
,
1012 devs_found
-1, devlist
->next
, runstop
, verbose
-quiet
, force
, assume_clean
,
1013 bitmap_file
, bitmap_chunk
, write_behind
, delay
);
1017 if (devmode
== 'E') {
1018 if (devlist
== NULL
&& !scan
) {
1019 fprintf(stderr
, Name
": No devices to examine\n");
1022 if (devlist
== NULL
)
1023 devlist
= conf_get_devs(configfile
);
1024 if (devlist
== NULL
) {
1025 fprintf(stderr
, Name
": No devices listed in %s\n", configfile
?configfile
:DefaultConfFile
);
1028 rv
= Examine(devlist
, scan
?(verbose
>1?0:verbose
+1):brief
, scan
, SparcAdjust
, ss
);
1030 if (devlist
== NULL
) {
1031 if (devmode
=='D' && scan
) {
1032 /* apply --detail to all devices in /proc/mdstat */
1033 struct mdstat_ent
*ms
= mdstat_read(0, 1);
1034 struct mdstat_ent
*e
;
1035 for (e
=ms
; e
; e
=e
->next
) {
1036 char *name
= get_md_name(e
->devnum
);
1039 fprintf(stderr
, Name
": cannot find device file for %s\n",
1043 rv
|= Detail(name
, verbose
>1?0:verbose
+1, test
);
1046 } else if (devmode
== 'S' && scan
) {
1047 /* apply --stop to all devices in /proc/mdstat */
1048 /* Due to possible stacking of devices, repeat until
1049 * nothing more can be stopped
1051 int progress
=1, err
;
1054 struct mdstat_ent
*ms
= mdstat_read(0, 0);
1055 struct mdstat_ent
*e
;
1057 if (!progress
) last
= 1;
1058 progress
= 0; err
= 0;
1059 for (e
=ms
; e
; e
=e
->next
) {
1060 char *name
= get_md_name(e
->devnum
);
1063 fprintf(stderr
, Name
": cannot find device file for %s\n",
1067 mdfd
= open_mddev(name
, 0);
1069 if (Manage_runstop(name
, mdfd
, -1, !last
))
1078 } while (!last
&& err
);
1081 fprintf(stderr
, Name
": No devices given.\n");
1085 for (dv
=devlist
; dv
; dv
=dv
->next
) {
1086 switch(dv
->disposition
) {
1088 rv
|= Detail(dv
->devname
, brief
?1+verbose
:0, test
); continue;
1089 case 'K': /* Zero superblock */
1090 rv
|= Kill(dv
->devname
, force
); continue;
1092 rv
|= Query(dv
->devname
); continue;
1094 rv
|= ExamineBitmap(dv
->devname
, brief
, ss
); continue;
1096 mdfd
= open_mddev(dv
->devname
, 0);
1098 switch(dv
->disposition
) {
1100 rv
|= Manage_runstop(dv
->devname
, mdfd
, 1, 0); break;
1102 rv
|= Manage_runstop(dv
->devname
, mdfd
, -1, 0); break;
1104 rv
|= Manage_ro(dv
->devname
, mdfd
, 1); break;
1106 rv
|= Manage_ro(dv
->devname
, mdfd
, -1); break;
1115 if (!devlist
&& !scan
) {
1116 fprintf(stderr
, Name
": Cannot monitor: need --scan or at least one device\n");
1120 if (pidfile
&& !daemonise
) {
1121 fprintf(stderr
, Name
": Cannot write a pid file when not in daemon mode\n");
1125 rv
= Monitor(devlist
, mailaddr
, program
,
1126 delay
?delay
:60, daemonise
, scan
, oneshot
,
1127 dosyslog
, configfile
, test
, pidfile
);
1131 if (devs_found
> 1) {
1134 if (size
>= 0 || raiddisks
) {
1135 fprintf(stderr
, Name
": --size, --raiddisks, and --add are exclusing in --grow mode\n");
1139 for (dv
=devlist
->next
; dv
; dv
=dv
->next
) {
1140 rv
= Grow_Add_device(devlist
->devname
, mdfd
, dv
->devname
);
1144 } else if ((size
>= 0) + (raiddisks
!= 0) + (layout
!= UnSet
) + (bitmap_file
!= NULL
)> 1) {
1145 fprintf(stderr
, Name
": can change at most one of size, raiddisks, bitmap, and layout\n");
1148 } else if (layout
!= UnSet
)
1149 rv
= Manage_reconfig(devlist
->devname
, mdfd
, layout
);
1150 else if (size
>= 0 || raiddisks
)
1151 rv
= Manage_resize(devlist
->devname
, mdfd
, size
, raiddisks
);
1152 else if (bitmap_file
) {
1153 if (delay
== 0) delay
= DEFAULT_BITMAP_DELAY
;
1154 rv
= Grow_addbitmap(devlist
->devname
, mdfd
, bitmap_file
,
1155 bitmap_chunk
, delay
, write_behind
, force
);
1157 fprintf(stderr
, Name
": no changes to --grow\n");