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
; /* just a default */
54 struct mddev_ident_s ident
;
55 char *configfile
= NULL
;
64 char *bitmap_file
= NULL
;
65 char *backup_file
= NULL
;
66 int bitmap_chunk
= UnSet
;
68 mddev_dev_t devlist
= NULL
;
69 mddev_dev_t
*devlistend
= & devlist
;
78 int autof
= 0; /* -3 means don't create anything,
79 * -2 means create device based on name:
80 * if it ends mdN, then non-partitioned array N
81 * if it ends dN, then partitions array N
82 * -1 means create non-partitioned, choose N
83 * 1 or more to create partitioned
84 * If -1 or 1 and name is a 'standard' name, then
85 * insist on a match of type and number.
88 char *mailaddr
= NULL
;
94 struct supertype
*ss
= NULL
;
97 char *shortopt
= short_options
;
105 srandom(time(0) ^ getpid());
109 ident
.raid_disks
= UnSet
;
110 ident
.super_minor
= UnSet
;
112 ident
.spare_group
= NULL
;
115 ident
.bitmap_fd
= -1;
116 ident
.bitmap_file
= NULL
;
119 while ((option_index
= -1) ,
120 (opt
=getopt_long(argc
, argv
,
121 shortopt
, long_options
,
122 &option_index
)) != -1) {
124 /* firstly, some mode-independant options */
127 if (option_index
> 0 &&
128 strcmp(long_options
[option_index
].name
, "help-options")==0)
135 fputs(Version
, stderr
);
145 if (mode
== ASSEMBLE
|| mode
== BUILD
|| mode
== CREATE
|| mode
== GROW
)
146 break; /* b means bitmap */
149 fprintf(stderr
, Name
": -b cannot have any extra immediately after it, sorry.\n");
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 */
167 shortopt
= short_bitmap_auto_options
;
175 shortopt
= short_bitmap_auto_options
;
179 case 'A': newmode
= ASSEMBLE
; shortopt
= short_bitmap_auto_options
; break;
180 case 'B': newmode
= BUILD
; shortopt
= short_bitmap_auto_options
; break;
181 case 'C': newmode
= CREATE
; shortopt
= short_bitmap_auto_options
; break;
182 case 'F': newmode
= MONITOR
;break;
183 case 'G': newmode
= GROW
; shortopt
= short_bitmap_auto_options
; break;
189 case 'Q': newmode
= MISC
; break;
194 case 'K': if (!mode
) newmode
= MISC
; break;
196 if (mode
&& newmode
== mode
) {
197 /* everybody happy ! */
198 } else if (mode
&& newmode
!= mode
) {
200 fprintf(stderr
, Name
": ");
201 if (option_index
>= 0)
202 fprintf(stderr
, "--%s", long_options
[option_index
].name
);
204 fprintf(stderr
, "-%c", opt
);
205 fprintf(stderr
, " would set mdadm mode to \"%s\", but it is already set to \"%s\".\n",
206 map_num(modes
, newmode
),
207 map_num(modes
, mode
));
209 } else if (!mode
&& newmode
) {
212 /* special case of -c --help */
214 ( strncmp(optarg
, "--h", 3)==0 ||
215 strncmp(optarg
, "-h", 2)==0)) {
216 fputs(Help_config
, stderr
);
220 /* If first option is a device, don't force the mode yet */
222 if (devs_found
== 0) {
223 dv
= malloc(sizeof(*dv
));
225 fprintf(stderr
, Name
": malloc failed\n");
228 dv
->devname
= optarg
;
229 dv
->disposition
= devmode
;
230 dv
->writemostly
= writemostly
;
234 devlistend
= &dv
->next
;
239 /* No mode yet, and this is the second device ... */
240 fprintf(stderr
, Name
": An option must be given to set the mode before a second device is listed\n");
243 if (option_index
>= 0)
244 fprintf(stderr
, Name
": --%s", long_options
[option_index
].name
);
246 fprintf(stderr
, Name
": -%c", opt
);
247 fprintf(stderr
, " does not set the mode, and so cannot be the first option.\n");
251 /* if we just set the mode, then done */
263 /* an undecorated option - must be a device name.
265 if (devs_found
> 0 && mode
== '@' && !devmode
) {
266 fprintf(stderr
, Name
": Must give one of -a/-r/-f for subsequent devices at %s\n", optarg
);
269 if (devs_found
> 0 && mode
== 'G' && !devmode
) {
270 fprintf(stderr
, Name
": Must give one of -a for devices do add: %s\n", optarg
);
273 dv
= malloc(sizeof(*dv
));
275 fprintf(stderr
, Name
": malloc failed\n");
278 dv
->devname
= optarg
;
279 dv
->disposition
= devmode
;
280 dv
->writemostly
= writemostly
;
284 devlistend
= &dv
->next
;
290 /* We've got a mode, and opt is now something else which
291 * could depend on the mode */
292 #define O(a,b) ((a<<8)|b)
293 switch (O(mode
,opt
)) {
295 case O(BUILD
,'c'): /* chunk or rounding */
297 fprintf(stderr
, Name
": chunk/rounding may only be specified once. "
298 "Second value is %s.\n", optarg
);
301 chunk
= strtol(optarg
, &c
, 10);
302 if (!optarg
[0] || *c
|| chunk
<4 || ((chunk
-1)&chunk
)) {
303 fprintf(stderr
, Name
": invalid chunk/rounding value: %s\n",
310 case O(ASSEMBLE
,'e'):
311 case O(MISC
,'e'): /* set metadata (superblock) information */
313 fprintf(stderr
, Name
": metadata information already given\n");
316 for(i
=0; !ss
&& superlist
[i
]; i
++)
317 ss
= superlist
[i
]->match_metadata_desc(optarg
);
320 fprintf(stderr
, Name
": unrecognised metadata identifier: %s\n", optarg
);
323 max_disks
= ss
->max_devs
;
329 /* set write-mostly for following devices */
334 case O(CREATE
,'z'): /* size */
336 fprintf(stderr
, Name
": size may only be specified once. "
337 "Second value is %s.\n", optarg
);
340 if (strcmp(optarg
, "max")==0)
343 size
= strtoll(optarg
, &c
, 10);
344 if (!optarg
[0] || *c
|| size
< 4) {
345 fprintf(stderr
, Name
": invalid size: %s\n",
352 case O(GROW
,'l'): /* hack - needed to understand layout */
354 case O(BUILD
,'l'): /* set raid level*/
355 if (level
!= UnSet
) {
356 fprintf(stderr
, Name
": raid level may only be set once. "
357 "Second value is %s.\n", optarg
);
360 level
= map_name(pers
, optarg
);
361 if (level
== UnSet
) {
362 fprintf(stderr
, Name
": invalid raid level: %s\n",
366 if (level
!= 0 && level
!= -1 && level
!= 1 && level
!= -4 && level
!= -5 && mode
== BUILD
) {
367 fprintf(stderr
, Name
": Raid level %s not permitted with --build.\n",
371 if (sparedisks
> 0 && level
< 1 && level
>= -1) {
372 fprintf(stderr
, Name
": raid level %s is incompatible with spare-devices setting.\n",
379 case O(CREATE
,'p'): /* raid5 layout */
380 case O(BUILD
,'p'): /* faulty layout */
381 case O(GROW
, 'p'): /* faulty reconfig */
382 if (layout
!= UnSet
) {
383 fprintf(stderr
,Name
": layout may only be sent once. "
384 "Second value was %s\n", optarg
);
389 fprintf(stderr
, Name
": layout not meaningful for %s arrays.\n",
390 map_num(pers
, level
));
393 fprintf(stderr
, Name
": raid level must be given before layout.\n");
398 layout
= map_name(r5layout
, optarg
);
400 fprintf(stderr
, Name
": layout %s not understood for raid5.\n",
407 /* 'f', 'o' or 'n' followed by a number <= raid_disks */
408 if ((optarg
[0] != 'n' && optarg
[0] != 'f' && optarg
[0] != 'o') ||
409 (copies
= strtoul(optarg
+1, &cp
, 10)) < 1 ||
412 fprintf(stderr
, Name
": layout for raid10 must be 'nNN', 'oNN' or 'fNN' where NN is a number, not %s\n", optarg
);
415 if (optarg
[0] == 'n')
416 layout
= 256 + copies
;
417 else if (optarg
[0] == 'o')
418 layout
= 0x10000 + (copies
<<8) + 1;
420 layout
= 1 + (copies
<<8);
427 int ln
= strcspn(optarg
, "0123456789");
428 char *m
= strdup(optarg
);
431 mode
= map_name(faultylayout
, m
);
433 fprintf(stderr
, Name
": layout %s not understood for faulty.\n",
437 layout
= mode
| (atoi(optarg
+ln
)<< ModeShift
);
443 case O(BUILD
,3): /* assume clean */
449 case O(BUILD
,'n'): /* number of raid disks */
451 fprintf(stderr
, Name
": raid-devices set twice: %d and %s\n",
455 raiddisks
= strtol(optarg
, &c
, 10);
456 if (!optarg
[0] || *c
|| raiddisks
<=0) {
457 fprintf(stderr
, Name
": invalid number of raid devices: %s\n",
461 ident
.raid_disks
= raiddisks
;
464 case O(CREATE
,'x'): /* number of spare (eXtra) discs */
466 fprintf(stderr
,Name
": spare-devices set twice: %d and %s\n",
470 if (level
!= UnSet
&& level
<= 0 && level
>= -1) {
471 fprintf(stderr
, Name
": spare-devices setting is incompatible with raid level %d\n",
475 sparedisks
= strtol(optarg
, &c
, 10);
476 if (!optarg
[0] || *c
|| sparedisks
< 0) {
477 fprintf(stderr
, Name
": invalid number of spare-devices: %s\n",
485 case O(ASSEMBLE
,'a'): /* auto-creation of device node */
486 autof
= parse_auto(optarg
, "--auto flag");
489 case O(BUILD
,'f'): /* force honouring '-n 1' */
490 case O(GROW
,'f'): /* ditto */
491 case O(CREATE
,'f'): /* force honouring of device list */
492 case O(ASSEMBLE
,'f'): /* force assembly */
493 case O(MISC
,'f'): /* force zero */
497 /* now for the Assemble options */
498 case O(ASSEMBLE
,'u'): /* uuid of array */
499 if (ident
.uuid_set
) {
500 fprintf(stderr
, Name
": uuid cannot be set twice. "
501 "Second value %s.\n", optarg
);
504 if (parse_uuid(optarg
, ident
.uuid
))
507 fprintf(stderr
,Name
": Bad uuid: %s\n", optarg
);
513 case O(ASSEMBLE
,'N'):
515 fprintf(stderr
, Name
": name cannot be set twice. "
516 "Second value %s.\n", optarg
);
519 if (strlen(optarg
) > 32) {
520 fprintf(stderr
, Name
": name '%s' is too long, 32 chars max.\n",
524 strcpy(ident
.name
, optarg
);
527 case O(ASSEMBLE
,'m'): /* super-minor for array */
528 if (ident
.super_minor
!= UnSet
) {
529 fprintf(stderr
, Name
": super-minor cannot be set twice. "
530 "Second value: %s.\n", optarg
);
533 if (strcmp(optarg
, "dev")==0)
534 ident
.super_minor
= -2;
536 ident
.super_minor
= strtoul(optarg
, &cp
, 10);
537 if (!optarg
[0] || *cp
) {
538 fprintf(stderr
, Name
": Bad super-minor number: %s.\n", optarg
);
544 case O(ASSEMBLE
,'U'): /* update the superblock */
546 fprintf(stderr
, Name
": Can only update one aspect of superblock, both %s and %s given.\n",
551 if (strcmp(update
, "sparc2.2")==0)
553 if (strcmp(update
, "super-minor") == 0)
555 if (strcmp(update
, "summaries")==0)
557 if (strcmp(update
, "resync")==0)
559 if (strcmp(update
, "uuid")==0)
561 if (strcmp(update
, "byteorder")==0) {
563 fprintf(stderr
, Name
": must not set metadata type with --update=byteorder.\n");
566 for(i
=0; !ss
&& superlist
[i
]; i
++)
567 ss
= superlist
[i
]->match_metadata_desc("0.swap");
569 fprintf(stderr
, Name
": INTERNAL ERROR cannot find 0.swap\n");
575 fprintf(stderr
, Name
": '--update %s' invalid. Only 'sparc2.2', 'super-minor', 'uuid', 'resync' or 'summaries' supported\n",update
);
578 case O(ASSEMBLE
,'c'): /* config file */
582 fprintf(stderr
, Name
": configfile cannot be set twice. "
583 "Second value is %s.\n", optarg
);
587 /* FIXME possibly check that config file exists. Even parse it */
589 case O(ASSEMBLE
,'s'): /* scan */
595 case O(MONITOR
,'m'): /* mail address */
597 fprintf(stderr
, Name
": only specify one mailaddress. %s ignored.\n",
603 case O(MONITOR
,'p'): /* alert program */
605 fprintf(stderr
, Name
": only specify one alter program. %s ignored.\n",
611 case O(MONITOR
,'d'): /* delay in seconds */
613 case O(BUILD
,'d'): /* delay for bitmap updates */
616 fprintf(stderr
, Name
": only specify delay once. %s ignored.\n",
619 delay
= strtol(optarg
, &c
, 10);
620 if (!optarg
[0] || *c
|| delay
<1) {
621 fprintf(stderr
, Name
": invalid delay: %s\n",
627 case O(MONITOR
,'f'): /* daemonise */
630 case O(MONITOR
,'i'): /* pid */
632 fprintf(stderr
, Name
": only specify one pid file. %s ignored.\n",
637 case O(MONITOR
,'1'): /* oneshot */
640 case O(MONITOR
,'t'): /* test */
643 case O(MONITOR
,'y'): /* log messages to syslog */
644 openlog("mdadm", 0, SYSLOG_FACILITY
);
648 /* now the general management options. Some are applicable
649 * to other modes. None have arguments.
652 case O(MANAGE
,'a'): /* add a drive */
660 case O(MANAGE
,'r'): /* remove a drive */
663 case O(MANAGE
,'f'): /* set faulty */
667 case O(ASSEMBLE
,'R'):
669 case O(CREATE
,'R'): /* Run the array */
671 fprintf(stderr
, Name
": Cannot both Stop and Run an array\n");
678 fprintf(stderr
, Name
": Cannot both Run and Stop an array\n");
686 fprintf(stderr
, Name
": Cannot have both readonly and readwrite\n");
693 fprintf(stderr
, Name
": Cannot have both readwrite and readonly.\n");
708 if (devmode
&& devmode
!= opt
&&
709 (devmode
== 'E' || (opt
== 'E' && devmode
!= 'Q'))) {
710 fprintf(stderr
, Name
": --examine/-E cannot be given with -%c\n",
711 devmode
=='E'?opt
:devmode
);
721 if (devmode
!= 'E') {
722 fprintf(stderr
, Name
": --sparc2.2 only allowed with --examine\n");
728 case O(ASSEMBLE
,'b'): /* here we simply set the bitmap file */
730 fprintf(stderr
, Name
": bitmap file needed with -b in --assemble mode\n");
733 if (strcmp(optarg
, "internal")==0) {
734 fprintf(stderr
, Name
": there is no need to specify --bitmap when assembling arrays with internal bitmaps\n");
737 bitmap_fd
= open(optarg
, O_RDWR
);
738 if (!*optarg
|| bitmap_fd
< 0) {
739 fprintf(stderr
, Name
": cannot open bitmap file %s: %s\n", optarg
, strerror(errno
));
742 ident
.bitmap_fd
= bitmap_fd
; /* for Assemble */
747 /* Specify a file into which grow might place a backup,
748 * or from which assemble might recover a backup
751 fprintf(stderr
, Name
": backup file already specified, rejecting %s\n", optarg
);
754 backup_file
= optarg
;
759 case O(CREATE
,'b'): /* here we create the bitmap */
760 if (strcmp(optarg
, "internal")== 0 ||
761 strcmp(optarg
, "none")== 0 ||
762 strchr(optarg
, '/') != NULL
) {
763 bitmap_file
= optarg
;
767 fprintf(stderr
, Name
": bitmap file must contain a '/', or be 'internal', or 'none'\n");
772 case O(CREATE
,4): /* bitmap chunksize */
773 bitmap_chunk
= strtol(optarg
, &c
, 10);
774 if (!optarg
[0] || *c
|| bitmap_chunk
< 0 ||
775 bitmap_chunk
& (bitmap_chunk
- 1)) {
776 fprintf(stderr
, Name
": invalid bitmap chunksize: %s\n",
780 /* convert K to B, chunk of 0K means 512B */
781 bitmap_chunk
= bitmap_chunk
? bitmap_chunk
* 1024 : 512;
785 case O(CREATE
, 5): /* write-behind mode */
786 write_behind
= DEFAULT_MAX_WRITE_BEHIND
;
788 write_behind
= strtol(optarg
, &c
, 10);
789 if (write_behind
< 0 || *c
||
790 write_behind
> 16383) {
791 fprintf(stderr
, Name
": Invalid value for maximum outstanding write-behind writes: %s.\n\tMust be between 0 and 16383.\n", optarg
);
797 /* We have now processed all the valid options. Anything else is
800 if (option_index
> 0)
801 fprintf(stderr
, Name
":option --%s not valid in %s mode\n",
802 long_options
[option_index
].name
,
803 map_num(modes
, mode
));
805 fprintf(stderr
, Name
": option -%c not valid in %s mode\n",
806 opt
, map_num(modes
, mode
));
812 char *help_text
= Help
;
814 help_text
= OptionHelp
;
817 case ASSEMBLE
: help_text
= Help_assemble
; break;
818 case BUILD
: help_text
= Help_build
; break;
819 case CREATE
: help_text
= Help_create
; break;
820 case MANAGE
: help_text
= Help_manage
; break;
821 case MISC
: help_text
= Help_misc
; break;
822 case MONITOR
: help_text
= Help_monitor
; break;
823 case GROW
: help_text
= Help_grow
; break;
825 fputs(help_text
,stderr
);
829 if (!mode
&& devs_found
) {
832 if (devlist
->disposition
== 0)
833 devlist
->disposition
= devmode
;
836 fputs(Usage
, stderr
);
839 /* Ok, got the option parsing out of the way
840 * hopefully it's mostly right but there might be some stuff
843 * That is mosty checked in the per-mode stuff but...
845 * For @,B,C and A without -s, the first device listed must be an md device
846 * we check that here and open it.
849 if (mode
==MANAGE
|| mode
== BUILD
|| mode
== CREATE
|| mode
== GROW
||
850 (mode
== ASSEMBLE
&& ! scan
)) {
851 if (devs_found
< 1) {
852 fprintf(stderr
, Name
": an md device must be given in this mode\n");
855 if ((int)ident
.super_minor
== -2 && autof
) {
856 fprintf(stderr
, Name
": --super-minor=dev is incompatible with --auto\n");
859 mdfd
= open_mddev(devlist
->devname
, autof
);
862 if ((int)ident
.super_minor
== -2) {
865 ident
.super_minor
= minor(stb
.st_rdev
);
870 if (raiddisks
> max_disks
) {
871 fprintf(stderr
, Name
": invalid number of raid devices: %d\n",
875 if (raiddisks
== 1 && !force
&& level
!= -5) {
876 fprintf(stderr
, Name
": '1' is an unusual number of drives for an array, so it is probably\n"
877 " a mistake. If you really mean it you will need to specify --force before\n"
878 " setting the number of drives.\n");
883 if ( sparedisks
> max_disks
- raiddisks
) {
884 fprintf(stderr
, Name
": invalid number of spare-devices: %d\n",
893 /* readonly, add/remove, readwrite, runstop */
895 rv
= Manage_ro(devlist
->devname
, mdfd
, readonly
);
896 if (!rv
&& devs_found
>1)
897 rv
= Manage_subdevs(devlist
->devname
, mdfd
,
898 devlist
->next
, verbose
-quiet
);
899 if (!rv
&& readonly
< 0)
900 rv
= Manage_ro(devlist
->devname
, mdfd
, readonly
);
902 rv
= Manage_runstop(devlist
->devname
, mdfd
, runstop
, 0);
905 if (devs_found
== 1 && ident
.uuid_set
== 0 &&
906 ident
.super_minor
== UnSet
&& ident
.name
[0] == 0 && !scan
) {
907 /* Only a device has been given, so get details from config file */
908 mddev_ident_t array_ident
= conf_get_ident(configfile
, devlist
->devname
);
909 if (array_ident
== NULL
) {
910 fprintf(stderr
, Name
": %s not identified in config file.\n",
914 mdfd
= open_mddev(devlist
->devname
,
915 array_ident
->autof
? array_ident
->autof
: autof
);
919 rv
|= Assemble(ss
, devlist
->devname
, mdfd
, array_ident
, configfile
,
921 readonly
, runstop
, update
, verbose
-quiet
, force
);
926 rv
= Assemble(ss
, devlist
->devname
, mdfd
, &ident
, configfile
,
927 devlist
->next
, backup_file
,
928 readonly
, runstop
, update
, verbose
-quiet
, force
);
929 else if (devs_found
>0) {
930 if (update
&& devs_found
> 1) {
931 fprintf(stderr
, Name
": can only update a single array at a time\n");
934 if (backup_file
&& devs_found
> 1) {
935 fprintf(stderr
, Name
": can only assemble a single array when providing a backup file.\n");
938 for (dv
= devlist
; dv
; dv
=dv
->next
) {
939 mddev_ident_t array_ident
= conf_get_ident(configfile
, dv
->devname
);
940 if (array_ident
== NULL
) {
941 fprintf(stderr
, Name
": %s not identified in config file.\n",
946 mdfd
= open_mddev(dv
->devname
,
947 array_ident
->autof
?array_ident
->autof
: autof
);
952 rv
|= Assemble(ss
, dv
->devname
, mdfd
, array_ident
, configfile
,
954 readonly
, runstop
, update
, verbose
-quiet
, force
);
958 mddev_ident_t array_list
= conf_get_ident(configfile
, NULL
);
960 fprintf(stderr
, Name
": No arrays found in config file\n");
964 fprintf(stderr
, Name
": --update not meaningful with a --scan assembly.\n");
968 fprintf(stderr
, Name
": --backup_file not meaningful with a --scan assembly.\n");
971 for (; array_list
; array_list
= array_list
->next
) {
972 mdu_array_info_t array
;
973 mdfd
= open_mddev(array_list
->devname
,
974 array_list
->autof
? array_list
->autof
: autof
);
979 if (ioctl(mdfd
, GET_ARRAY_INFO
, &array
)>=0)
980 /* already assembled, skip */
983 rv
|= Assemble(ss
, array_list
->devname
, mdfd
,
984 array_list
, configfile
,
986 readonly
, runstop
, NULL
, verbose
-quiet
, force
);
992 if (delay
== 0) delay
= DEFAULT_BITMAP_DELAY
;
993 if (write_behind
&& !bitmap_file
) {
994 fprintf(stderr
, Name
": write-behind mode requires a bitmap.\n");
1000 if (strcmp(bitmap_file
, "internal")==0) {
1001 fprintf(stderr
, Name
": 'internal' bitmaps not supported with --build\n");
1006 rv
= Build(devlist
->devname
, mdfd
, chunk
, level
, layout
,
1007 raiddisks
, devlist
->next
, assume_clean
,
1008 bitmap_file
, bitmap_chunk
, write_behind
, delay
, verbose
-quiet
);
1011 if (delay
== 0) delay
= DEFAULT_BITMAP_DELAY
;
1012 if (write_behind
&& !bitmap_file
) {
1013 fprintf(stderr
, Name
": write-behind mode requires a bitmap.\n");
1018 rv
= Create(ss
, devlist
->devname
, mdfd
, chunk
, level
, layout
, size
<0 ? 0 : size
,
1019 raiddisks
, sparedisks
, ident
.name
,
1020 devs_found
-1, devlist
->next
, runstop
, verbose
-quiet
, force
, assume_clean
,
1021 bitmap_file
, bitmap_chunk
, write_behind
, delay
);
1025 if (devmode
== 'E') {
1026 if (devlist
== NULL
&& !scan
) {
1027 fprintf(stderr
, Name
": No devices to examine\n");
1030 if (devlist
== NULL
)
1031 devlist
= conf_get_devs(configfile
);
1032 if (devlist
== NULL
) {
1033 fprintf(stderr
, Name
": No devices listed in %s\n", configfile
?configfile
:DefaultConfFile
);
1036 rv
= Examine(devlist
, scan
?(verbose
>1?0:verbose
+1):brief
, scan
, SparcAdjust
, ss
);
1038 if (devlist
== NULL
) {
1039 if (devmode
=='D' && scan
) {
1040 /* apply --detail to all devices in /proc/mdstat */
1041 struct mdstat_ent
*ms
= mdstat_read(0, 1);
1042 struct mdstat_ent
*e
;
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 rv
|= Detail(name
, verbose
>1?0:verbose
+1, test
);
1054 } else if (devmode
== 'S' && scan
) {
1055 /* apply --stop to all devices in /proc/mdstat */
1056 /* Due to possible stacking of devices, repeat until
1057 * nothing more can be stopped
1059 int progress
=1, err
;
1062 struct mdstat_ent
*ms
= mdstat_read(0, 0);
1063 struct mdstat_ent
*e
;
1065 if (!progress
) last
= 1;
1066 progress
= 0; err
= 0;
1067 for (e
=ms
; e
; e
=e
->next
) {
1068 char *name
= get_md_name(e
->devnum
);
1071 fprintf(stderr
, Name
": cannot find device file for %s\n",
1075 mdfd
= open_mddev(name
, 0);
1077 if (Manage_runstop(name
, mdfd
, -1, !last
))
1086 } while (!last
&& err
);
1089 fprintf(stderr
, Name
": No devices given.\n");
1093 for (dv
=devlist
; dv
; dv
=dv
->next
) {
1094 switch(dv
->disposition
) {
1096 rv
|= Detail(dv
->devname
, brief
?1+verbose
:0, test
); continue;
1097 case 'K': /* Zero superblock */
1098 rv
|= Kill(dv
->devname
, force
, quiet
); continue;
1100 rv
|= Query(dv
->devname
); continue;
1102 rv
|= ExamineBitmap(dv
->devname
, brief
, ss
); continue;
1104 mdfd
= open_mddev(dv
->devname
, 0);
1106 switch(dv
->disposition
) {
1108 rv
|= Manage_runstop(dv
->devname
, mdfd
, 1, 0); break;
1110 rv
|= Manage_runstop(dv
->devname
, mdfd
, -1, 0); break;
1112 rv
|= Manage_ro(dv
->devname
, mdfd
, 1); break;
1114 rv
|= Manage_ro(dv
->devname
, mdfd
, -1); break;
1123 if (!devlist
&& !scan
) {
1124 fprintf(stderr
, Name
": Cannot monitor: need --scan or at least one device\n");
1128 if (pidfile
&& !daemonise
) {
1129 fprintf(stderr
, Name
": Cannot write a pid file when not in daemon mode\n");
1133 rv
= Monitor(devlist
, mailaddr
, program
,
1134 delay
?delay
:60, daemonise
, scan
, oneshot
,
1135 dosyslog
, configfile
, test
, pidfile
);
1139 if (devs_found
> 1) {
1142 if (size
>= 0 || raiddisks
) {
1143 fprintf(stderr
, Name
": --size, --raiddisks, and --add are exclusing in --grow mode\n");
1147 for (dv
=devlist
->next
; dv
; dv
=dv
->next
) {
1148 rv
= Grow_Add_device(devlist
->devname
, mdfd
, dv
->devname
);
1152 } else if ((size
>= 0) + (raiddisks
!= 0) + (layout
!= UnSet
) + (bitmap_file
!= NULL
)> 1) {
1153 fprintf(stderr
, Name
": can change at most one of size, raiddisks, bitmap, and layout\n");
1156 } else if (layout
!= UnSet
)
1157 rv
= Manage_reconfig(devlist
->devname
, mdfd
, layout
);
1158 else if (size
>= 0 || raiddisks
)
1159 rv
= Grow_reshape(devlist
->devname
, mdfd
, quiet
, backup_file
,
1160 size
, level
, layout
, chunk
, raiddisks
);
1161 else if (bitmap_file
) {
1162 if (delay
== 0) delay
= DEFAULT_BITMAP_DELAY
;
1163 rv
= Grow_addbitmap(devlist
->devname
, mdfd
, bitmap_file
,
1164 bitmap_chunk
, delay
, write_behind
, force
);
1166 fprintf(stderr
, Name
": no changes to --grow\n");