2 * mdadm - manage Linux "md" devices aka RAID arrays.
4 * Copyright (C) 2001-2006 Neil Brown <neilb@suse.de>
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 /* autof indicates whether and how to create device node.
79 * bottom 3 bits are style. Rest (when shifted) are number of parts
81 * 1 - don't create (no)
82 * 2 - if is_standard, then create (yes)
83 * 3 - create as 'md' - reject is_standard mdp (md)
84 * 4 - create as 'mdp' - reject is_standard md (mdp)
85 * 5 - default to md if not is_standard (md in config file)
86 * 6 - default to mdp if not is_standard (part, or mdp in config file)
90 char *homehost
= NULL
;
91 char sys_hostname
[256];
92 char *mailaddr
= NULL
;
98 struct supertype
*ss
= NULL
;
101 char *shortopt
= short_options
;
109 srandom(time(0) ^ getpid());
113 ident
.raid_disks
= UnSet
;
114 ident
.super_minor
= UnSet
;
116 ident
.spare_group
= NULL
;
119 ident
.bitmap_fd
= -1;
120 ident
.bitmap_file
= NULL
;
123 while ((option_index
= -1) ,
124 (opt
=getopt_long(argc
, argv
,
125 shortopt
, long_options
,
126 &option_index
)) != -1) {
128 /* firstly, some mode-independant options */
131 if (option_index
> 0 &&
132 strcmp(long_options
[option_index
].name
, "help-options")==0)
139 fputs(Version
, stderr
);
149 if (mode
== ASSEMBLE
|| mode
== BUILD
|| mode
== CREATE
|| mode
== GROW
)
150 break; /* b means bitmap */
153 fprintf(stderr
, Name
": -b cannot have any extra immediately after it, sorry.\n");
164 fputs(Usage
, stderr
);
167 /* second, figure out the mode.
168 * Some options force the mode. Others
169 * set the mode if it isn't already
173 case '@': /* just incase they say --manage */
175 shortopt
= short_bitmap_auto_options
;
183 shortopt
= short_bitmap_auto_options
;
187 case 'A': newmode
= ASSEMBLE
; shortopt
= short_bitmap_auto_options
; break;
188 case 'B': newmode
= BUILD
; shortopt
= short_bitmap_auto_options
; break;
189 case 'C': newmode
= CREATE
; shortopt
= short_bitmap_auto_options
; break;
190 case 'F': newmode
= MONITOR
;break;
191 case 'G': newmode
= GROW
; shortopt
= short_bitmap_auto_options
; break;
197 case 'Q': newmode
= MISC
; break;
202 case 'K': if (!mode
) newmode
= MISC
; break;
204 if (mode
&& newmode
== mode
) {
205 /* everybody happy ! */
206 } else if (mode
&& newmode
!= mode
) {
208 fprintf(stderr
, Name
": ");
209 if (option_index
>= 0)
210 fprintf(stderr
, "--%s", long_options
[option_index
].name
);
212 fprintf(stderr
, "-%c", opt
);
213 fprintf(stderr
, " would set mdadm mode to \"%s\", but it is already set to \"%s\".\n",
214 map_num(modes
, newmode
),
215 map_num(modes
, mode
));
217 } else if (!mode
&& newmode
) {
220 /* special case of -c --help */
222 ( strncmp(optarg
, "--h", 3)==0 ||
223 strncmp(optarg
, "-h", 2)==0)) {
224 fputs(Help_config
, stderr
);
228 /* If first option is a device, don't force the mode yet */
230 if (devs_found
== 0) {
231 dv
= malloc(sizeof(*dv
));
233 fprintf(stderr
, Name
": malloc failed\n");
236 dv
->devname
= optarg
;
237 dv
->disposition
= devmode
;
238 dv
->writemostly
= writemostly
;
242 devlistend
= &dv
->next
;
247 /* No mode yet, and this is the second device ... */
248 fprintf(stderr
, Name
": An option must be given to set the mode before a second device is listed\n");
251 if (option_index
>= 0)
252 fprintf(stderr
, Name
": --%s", long_options
[option_index
].name
);
254 fprintf(stderr
, Name
": -%c", opt
);
255 fprintf(stderr
, " does not set the mode, and so cannot be the first option.\n");
259 /* if we just set the mode, then done */
271 /* an undecorated option - must be a device name.
273 if (devs_found
> 0 && mode
== '@' && !devmode
) {
274 fprintf(stderr
, Name
": Must give one of -a/-r/-f for subsequent devices at %s\n", optarg
);
277 if (devs_found
> 0 && mode
== 'G' && !devmode
) {
278 fprintf(stderr
, Name
": Must give one of -a for devices do add: %s\n", optarg
);
281 dv
= malloc(sizeof(*dv
));
283 fprintf(stderr
, Name
": malloc failed\n");
286 dv
->devname
= optarg
;
287 dv
->disposition
= devmode
;
288 dv
->writemostly
= writemostly
;
292 devlistend
= &dv
->next
;
298 /* We've got a mode, and opt is now something else which
299 * could depend on the mode */
300 #define O(a,b) ((a<<8)|b)
301 switch (O(mode
,opt
)) {
303 case O(BUILD
,'c'): /* chunk or rounding */
305 fprintf(stderr
, Name
": chunk/rounding may only be specified once. "
306 "Second value is %s.\n", optarg
);
309 chunk
= strtol(optarg
, &c
, 10);
310 if (!optarg
[0] || *c
|| chunk
<4 || ((chunk
-1)&chunk
)) {
311 fprintf(stderr
, Name
": invalid chunk/rounding value: %s\n",
318 case O(ASSEMBLE
,'e'):
319 case O(MISC
,'e'): /* set metadata (superblock) information */
321 fprintf(stderr
, Name
": metadata information already given\n");
324 for(i
=0; !ss
&& superlist
[i
]; i
++)
325 ss
= superlist
[i
]->match_metadata_desc(optarg
);
328 fprintf(stderr
, Name
": unrecognised metadata identifier: %s\n", optarg
);
331 max_disks
= ss
->max_devs
;
337 /* set write-mostly for following devices */
342 case O(CREATE
,'z'): /* size */
344 fprintf(stderr
, Name
": size may only be specified once. "
345 "Second value is %s.\n", optarg
);
348 if (strcmp(optarg
, "max")==0)
351 size
= strtoll(optarg
, &c
, 10);
352 if (!optarg
[0] || *c
|| size
< 4) {
353 fprintf(stderr
, Name
": invalid size: %s\n",
360 case O(GROW
,'l'): /* hack - needed to understand layout */
362 case O(BUILD
,'l'): /* set raid level*/
363 if (level
!= UnSet
) {
364 fprintf(stderr
, Name
": raid level may only be set once. "
365 "Second value is %s.\n", optarg
);
368 level
= map_name(pers
, optarg
);
369 if (level
== UnSet
) {
370 fprintf(stderr
, Name
": invalid raid level: %s\n",
374 if (level
!= 0 && level
!= -1 && level
!= 1 && level
!= -4 && level
!= -5 && mode
== BUILD
) {
375 fprintf(stderr
, Name
": Raid level %s not permitted with --build.\n",
379 if (sparedisks
> 0 && level
< 1 && level
>= -1) {
380 fprintf(stderr
, Name
": raid level %s is incompatible with spare-devices setting.\n",
387 case O(CREATE
,'p'): /* raid5 layout */
388 case O(BUILD
,'p'): /* faulty layout */
389 case O(GROW
, 'p'): /* faulty reconfig */
390 if (layout
!= UnSet
) {
391 fprintf(stderr
,Name
": layout may only be sent once. "
392 "Second value was %s\n", optarg
);
397 fprintf(stderr
, Name
": layout not meaningful for %s arrays.\n",
398 map_num(pers
, level
));
401 fprintf(stderr
, Name
": raid level must be given before layout.\n");
406 layout
= map_name(r5layout
, optarg
);
408 fprintf(stderr
, Name
": layout %s not understood for raid5.\n",
415 /* 'f', 'o' or 'n' followed by a number <= raid_disks */
416 if ((optarg
[0] != 'n' && optarg
[0] != 'f' && optarg
[0] != 'o') ||
417 (copies
= strtoul(optarg
+1, &cp
, 10)) < 1 ||
420 fprintf(stderr
, Name
": layout for raid10 must be 'nNN', 'oNN' or 'fNN' where NN is a number, not %s\n", optarg
);
423 if (optarg
[0] == 'n')
424 layout
= 256 + copies
;
425 else if (optarg
[0] == 'o')
426 layout
= 0x10000 + (copies
<<8) + 1;
428 layout
= 1 + (copies
<<8);
435 int ln
= strcspn(optarg
, "0123456789");
436 char *m
= strdup(optarg
);
439 mode
= map_name(faultylayout
, m
);
441 fprintf(stderr
, Name
": layout %s not understood for faulty.\n",
445 layout
= mode
| (atoi(optarg
+ln
)<< ModeShift
);
450 case O(CREATE
,AssumeClean
):
451 case O(BUILD
,AssumeClean
): /* assume clean */
457 case O(BUILD
,'n'): /* number of raid disks */
459 fprintf(stderr
, Name
": raid-devices set twice: %d and %s\n",
463 raiddisks
= strtol(optarg
, &c
, 10);
464 if (!optarg
[0] || *c
|| raiddisks
<=0) {
465 fprintf(stderr
, Name
": invalid number of raid devices: %s\n",
469 ident
.raid_disks
= raiddisks
;
472 case O(CREATE
,'x'): /* number of spare (eXtra) discs */
474 fprintf(stderr
,Name
": spare-devices set twice: %d and %s\n",
478 if (level
!= UnSet
&& level
<= 0 && level
>= -1) {
479 fprintf(stderr
, Name
": spare-devices setting is incompatible with raid level %d\n",
483 sparedisks
= strtol(optarg
, &c
, 10);
484 if (!optarg
[0] || *c
|| sparedisks
< 0) {
485 fprintf(stderr
, Name
": invalid number of spare-devices: %s\n",
493 case O(ASSEMBLE
,'a'): /* auto-creation of device node */
494 autof
= parse_auto(optarg
, "--auto flag", 0);
497 case O(BUILD
,'f'): /* force honouring '-n 1' */
498 case O(GROW
,'f'): /* ditto */
499 case O(CREATE
,'f'): /* force honouring of device list */
500 case O(ASSEMBLE
,'f'): /* force assembly */
501 case O(MISC
,'f'): /* force zero */
505 /* now for the Assemble options */
506 case O(ASSEMBLE
,'u'): /* uuid of array */
507 if (ident
.uuid_set
) {
508 fprintf(stderr
, Name
": uuid cannot be set twice. "
509 "Second value %s.\n", optarg
);
512 if (parse_uuid(optarg
, ident
.uuid
))
515 fprintf(stderr
,Name
": Bad uuid: %s\n", optarg
);
521 case O(ASSEMBLE
,'N'):
523 fprintf(stderr
, Name
": name cannot be set twice. "
524 "Second value %s.\n", optarg
);
527 if (strlen(optarg
) > 32) {
528 fprintf(stderr
, Name
": name '%s' is too long, 32 chars max.\n",
532 strcpy(ident
.name
, optarg
);
535 case O(ASSEMBLE
,'m'): /* super-minor for array */
536 if (ident
.super_minor
!= UnSet
) {
537 fprintf(stderr
, Name
": super-minor cannot be set twice. "
538 "Second value: %s.\n", optarg
);
541 if (strcmp(optarg
, "dev")==0)
542 ident
.super_minor
= -2;
544 ident
.super_minor
= strtoul(optarg
, &cp
, 10);
545 if (!optarg
[0] || *cp
) {
546 fprintf(stderr
, Name
": Bad super-minor number: %s.\n", optarg
);
552 case O(ASSEMBLE
,'U'): /* update the superblock */
554 fprintf(stderr
, Name
": Can only update one aspect of superblock, both %s and %s given.\n",
559 if (strcmp(update
, "sparc2.2")==0)
561 if (strcmp(update
, "super-minor") == 0)
563 if (strcmp(update
, "summaries")==0)
565 if (strcmp(update
, "resync")==0)
567 if (strcmp(update
, "uuid")==0)
569 if (strcmp(update
, "name")==0)
571 if (strcmp(update
, "byteorder")==0) {
573 fprintf(stderr
, Name
": must not set metadata type with --update=byteorder.\n");
576 for(i
=0; !ss
&& superlist
[i
]; i
++)
577 ss
= superlist
[i
]->match_metadata_desc("0.swap");
579 fprintf(stderr
, Name
": INTERNAL ERROR cannot find 0.swap\n");
585 fprintf(stderr
, Name
": '--update %s' invalid. Only 'sparc2.2', 'super-minor', 'uuid', 'resync' or 'summaries' supported\n",update
);
588 case O(ASSEMBLE
,NoDegraded
): /* --no-degraded */
589 runstop
= -1; /* --stop isn't allowed for --assemble, so we overload slightly */
592 case O(ASSEMBLE
,'c'): /* config file */
596 fprintf(stderr
, Name
": configfile cannot be set twice. "
597 "Second value is %s.\n", optarg
);
601 /* FIXME possibly check that config file exists. Even parse it */
603 case O(ASSEMBLE
,'s'): /* scan */
609 case O(MONITOR
,'m'): /* mail address */
611 fprintf(stderr
, Name
": only specify one mailaddress. %s ignored.\n",
617 case O(MONITOR
,'p'): /* alert program */
619 fprintf(stderr
, Name
": only specify one alter program. %s ignored.\n",
625 case O(MONITOR
,'d'): /* delay in seconds */
627 case O(BUILD
,'d'): /* delay for bitmap updates */
630 fprintf(stderr
, Name
": only specify delay once. %s ignored.\n",
633 delay
= strtol(optarg
, &c
, 10);
634 if (!optarg
[0] || *c
|| delay
<1) {
635 fprintf(stderr
, Name
": invalid delay: %s\n",
641 case O(MONITOR
,'f'): /* daemonise */
644 case O(MONITOR
,'i'): /* pid */
646 fprintf(stderr
, Name
": only specify one pid file. %s ignored.\n",
651 case O(MONITOR
,'1'): /* oneshot */
654 case O(MONITOR
,'t'): /* test */
657 case O(MONITOR
,'y'): /* log messages to syslog */
658 openlog("mdadm", 0, SYSLOG_FACILITY
);
662 /* now the general management options. Some are applicable
663 * to other modes. None have arguments.
666 case O(MANAGE
,'a'): /* add a drive */
670 case O(MANAGE
,ReAdd
):
674 case O(MANAGE
,'r'): /* remove a drive */
677 case O(MANAGE
,'f'): /* set faulty */
681 case O(ASSEMBLE
,'R'):
683 case O(CREATE
,'R'): /* Run the array */
685 fprintf(stderr
, Name
": Cannot both Stop and Run an array\n");
692 fprintf(stderr
, Name
": Cannot both Run and Stop an array\n");
700 fprintf(stderr
, Name
": Cannot have both readonly and readwrite\n");
707 fprintf(stderr
, Name
": Cannot have both readwrite and readonly.\n");
722 if (devmode
&& devmode
!= opt
&&
723 (devmode
== 'E' || (opt
== 'E' && devmode
!= 'Q'))) {
724 fprintf(stderr
, Name
": --examine/-E cannot be given with -%c\n",
725 devmode
=='E'?opt
:devmode
);
734 case O(MISC
, Sparc22
):
735 if (devmode
!= 'E') {
736 fprintf(stderr
, Name
": --sparc2.2 only allowed with --examine\n");
742 case O(ASSEMBLE
,'b'): /* here we simply set the bitmap file */
744 fprintf(stderr
, Name
": bitmap file needed with -b in --assemble mode\n");
747 if (strcmp(optarg
, "internal")==0) {
748 fprintf(stderr
, Name
": there is no need to specify --bitmap when assembling arrays with internal bitmaps\n");
751 bitmap_fd
= open(optarg
, O_RDWR
);
752 if (!*optarg
|| bitmap_fd
< 0) {
753 fprintf(stderr
, Name
": cannot open bitmap file %s: %s\n", optarg
, strerror(errno
));
756 ident
.bitmap_fd
= bitmap_fd
; /* for Assemble */
759 case O(ASSEMBLE
, BackupFile
):
760 case O(GROW
, BackupFile
):
761 /* Specify a file into which grow might place a backup,
762 * or from which assemble might recover a backup
765 fprintf(stderr
, Name
": backup file already specified, rejecting %s\n", optarg
);
768 backup_file
= optarg
;
773 case O(CREATE
,'b'): /* here we create the bitmap */
774 if (strcmp(optarg
, "internal")== 0 ||
775 strcmp(optarg
, "none")== 0 ||
776 strchr(optarg
, '/') != NULL
) {
777 bitmap_file
= optarg
;
781 fprintf(stderr
, Name
": bitmap file must contain a '/', or be 'internal', or 'none'\n");
784 case O(GROW
,BitmapChunk
):
785 case O(BUILD
,BitmapChunk
):
786 case O(CREATE
,BitmapChunk
): /* bitmap chunksize */
787 bitmap_chunk
= strtol(optarg
, &c
, 10);
788 if (!optarg
[0] || *c
|| bitmap_chunk
< 0 ||
789 bitmap_chunk
& (bitmap_chunk
- 1)) {
790 fprintf(stderr
, Name
": invalid bitmap chunksize: %s\n",
794 /* convert K to B, chunk of 0K means 512B */
795 bitmap_chunk
= bitmap_chunk
? bitmap_chunk
* 1024 : 512;
798 case O(BUILD
, WriteBehind
):
799 case O(CREATE
, WriteBehind
): /* write-behind mode */
800 write_behind
= DEFAULT_MAX_WRITE_BEHIND
;
802 write_behind
= strtol(optarg
, &c
, 10);
803 if (write_behind
< 0 || *c
||
804 write_behind
> 16383) {
805 fprintf(stderr
, Name
": Invalid value for maximum outstanding write-behind writes: %s.\n\tMust be between 0 and 16383.\n", optarg
);
811 /* We have now processed all the valid options. Anything else is
814 if (option_index
> 0)
815 fprintf(stderr
, Name
":option --%s not valid in %s mode\n",
816 long_options
[option_index
].name
,
817 map_num(modes
, mode
));
819 fprintf(stderr
, Name
": option -%c not valid in %s mode\n",
820 opt
, map_num(modes
, mode
));
826 char *help_text
= Help
;
828 help_text
= OptionHelp
;
831 case ASSEMBLE
: help_text
= Help_assemble
; break;
832 case BUILD
: help_text
= Help_build
; break;
833 case CREATE
: help_text
= Help_create
; break;
834 case MANAGE
: help_text
= Help_manage
; break;
835 case MISC
: help_text
= Help_misc
; break;
836 case MONITOR
: help_text
= Help_monitor
; break;
837 case GROW
: help_text
= Help_grow
; break;
839 fputs(help_text
,stderr
);
843 if (!mode
&& devs_found
) {
846 if (devlist
->disposition
== 0)
847 devlist
->disposition
= devmode
;
850 fputs(Usage
, stderr
);
853 /* Ok, got the option parsing out of the way
854 * hopefully it's mostly right but there might be some stuff
857 * That is mosty checked in the per-mode stuff but...
859 * For @,B,C and A without -s, the first device listed must be an md device
860 * we check that here and open it.
863 if (mode
==MANAGE
|| mode
== BUILD
|| mode
== CREATE
|| mode
== GROW
||
864 (mode
== ASSEMBLE
&& ! scan
)) {
865 if (devs_found
< 1) {
866 fprintf(stderr
, Name
": an md device must be given in this mode\n");
869 if ((int)ident
.super_minor
== -2 && autof
) {
870 fprintf(stderr
, Name
": --super-minor=dev is incompatible with --auto\n");
873 mdfd
= open_mddev(devlist
->devname
, autof
);
876 if ((int)ident
.super_minor
== -2) {
879 ident
.super_minor
= minor(stb
.st_rdev
);
884 if (raiddisks
> max_disks
) {
885 fprintf(stderr
, Name
": invalid number of raid devices: %d\n",
889 if (raiddisks
== 1 && !force
&& level
!= -5) {
890 fprintf(stderr
, Name
": '1' is an unusual number of drives for an array, so it is probably\n"
891 " a mistake. If you really mean it you will need to specify --force before\n"
892 " setting the number of drives.\n");
897 if ( sparedisks
> max_disks
- raiddisks
) {
898 fprintf(stderr
, Name
": invalid number of spare-devices: %d\n",
904 if (homehost
== NULL
)
905 homehost
= conf_get_homehost(configfile
);
906 if (homehost
&& strcmp(homehost
, "<system>")==0) {
907 if (gethostname(sys_hostname
, sizeof(sys_hostname
)) == 0) {
908 sys_hostname
[sizeof(sys_hostname
)-1] = 0;
909 homehost
= sys_hostname
;
916 /* readonly, add/remove, readwrite, runstop */
918 rv
= Manage_ro(devlist
->devname
, mdfd
, readonly
);
919 if (!rv
&& devs_found
>1)
920 rv
= Manage_subdevs(devlist
->devname
, mdfd
,
921 devlist
->next
, verbose
-quiet
);
922 if (!rv
&& readonly
< 0)
923 rv
= Manage_ro(devlist
->devname
, mdfd
, readonly
);
925 rv
= Manage_runstop(devlist
->devname
, mdfd
, runstop
, 0);
928 if (devs_found
== 1 && ident
.uuid_set
== 0 &&
929 ident
.super_minor
== UnSet
&& ident
.name
[0] == 0 && !scan
) {
930 /* Only a device has been given, so get details from config file */
931 mddev_ident_t array_ident
= conf_get_ident(configfile
, devlist
->devname
);
932 if (array_ident
== NULL
) {
933 fprintf(stderr
, Name
": %s not identified in config file.\n",
937 mdfd
= open_mddev(devlist
->devname
,
938 array_ident
->autof
? array_ident
->autof
: autof
);
942 rv
|= Assemble(ss
, devlist
->devname
, mdfd
, array_ident
, configfile
,
944 readonly
, runstop
, update
, homehost
, verbose
-quiet
, force
);
949 rv
= Assemble(ss
, devlist
->devname
, mdfd
, &ident
, configfile
,
950 devlist
->next
, backup_file
,
951 readonly
, runstop
, update
, homehost
, verbose
-quiet
, force
);
952 else if (devs_found
>0) {
953 if (update
&& devs_found
> 1) {
954 fprintf(stderr
, Name
": can only update a single array at a time\n");
957 if (backup_file
&& devs_found
> 1) {
958 fprintf(stderr
, Name
": can only assemble a single array when providing a backup file.\n");
961 for (dv
= devlist
; dv
; dv
=dv
->next
) {
962 mddev_ident_t array_ident
= conf_get_ident(configfile
, dv
->devname
);
963 if (array_ident
== NULL
) {
964 fprintf(stderr
, Name
": %s not identified in config file.\n",
969 mdfd
= open_mddev(dv
->devname
,
970 array_ident
->autof
?array_ident
->autof
: autof
);
975 rv
|= Assemble(ss
, dv
->devname
, mdfd
, array_ident
, configfile
,
977 readonly
, runstop
, update
, homehost
, verbose
-quiet
, force
);
981 mddev_ident_t array_list
= conf_get_ident(configfile
, NULL
);
983 fprintf(stderr
, Name
": No arrays found in config file\n");
987 fprintf(stderr
, Name
": --update not meaningful with a --scan assembly.\n");
991 fprintf(stderr
, Name
": --backup_file not meaningful with a --scan assembly.\n");
994 for (; array_list
; array_list
= array_list
->next
) {
995 mdu_array_info_t array
;
996 mdfd
= open_mddev(array_list
->devname
,
997 array_list
->autof
? array_list
->autof
: autof
);
1002 if (ioctl(mdfd
, GET_ARRAY_INFO
, &array
)>=0)
1003 /* already assembled, skip */
1006 rv
|= Assemble(ss
, array_list
->devname
, mdfd
,
1007 array_list
, configfile
,
1009 readonly
, runstop
, NULL
, homehost
, verbose
-quiet
, force
);
1015 if (delay
== 0) delay
= DEFAULT_BITMAP_DELAY
;
1016 if (write_behind
&& !bitmap_file
) {
1017 fprintf(stderr
, Name
": write-behind mode requires a bitmap.\n");
1023 if (strcmp(bitmap_file
, "internal")==0) {
1024 fprintf(stderr
, Name
": 'internal' bitmaps not supported with --build\n");
1029 rv
= Build(devlist
->devname
, mdfd
, chunk
, level
, layout
,
1030 raiddisks
, devlist
->next
, assume_clean
,
1031 bitmap_file
, bitmap_chunk
, write_behind
, delay
, verbose
-quiet
);
1034 if (delay
== 0) delay
= DEFAULT_BITMAP_DELAY
;
1035 if (write_behind
&& !bitmap_file
) {
1036 fprintf(stderr
, Name
": write-behind mode requires a bitmap.\n");
1041 rv
= Create(ss
, devlist
->devname
, mdfd
, chunk
, level
, layout
, size
<0 ? 0 : size
,
1042 raiddisks
, sparedisks
, ident
.name
, homehost
,
1043 devs_found
-1, devlist
->next
, runstop
, verbose
-quiet
, force
, assume_clean
,
1044 bitmap_file
, bitmap_chunk
, write_behind
, delay
);
1048 if (devmode
== 'E') {
1049 if (devlist
== NULL
&& !scan
) {
1050 fprintf(stderr
, Name
": No devices to examine\n");
1053 if (devlist
== NULL
)
1054 devlist
= conf_get_devs(configfile
);
1055 if (devlist
== NULL
) {
1056 fprintf(stderr
, Name
": No devices listed in %s\n", configfile
?configfile
:DefaultConfFile
);
1059 rv
= Examine(devlist
, scan
?(verbose
>1?0:verbose
+1):brief
, scan
, SparcAdjust
, ss
, homehost
);
1061 if (devlist
== NULL
) {
1062 if (devmode
=='D' && scan
) {
1063 /* apply --detail to all devices in /proc/mdstat */
1064 struct mdstat_ent
*ms
= mdstat_read(0, 1);
1065 struct mdstat_ent
*e
;
1066 for (e
=ms
; e
; e
=e
->next
) {
1067 char *name
= get_md_name(e
->devnum
);
1070 fprintf(stderr
, Name
": cannot find device file for %s\n",
1074 rv
|= Detail(name
, verbose
>1?0:verbose
+1, test
, homehost
);
1077 } else if (devmode
== 'S' && scan
) {
1078 /* apply --stop to all devices in /proc/mdstat */
1079 /* Due to possible stacking of devices, repeat until
1080 * nothing more can be stopped
1082 int progress
=1, err
;
1085 struct mdstat_ent
*ms
= mdstat_read(0, 0);
1086 struct mdstat_ent
*e
;
1088 if (!progress
) last
= 1;
1089 progress
= 0; err
= 0;
1090 for (e
=ms
; e
; e
=e
->next
) {
1091 char *name
= get_md_name(e
->devnum
);
1094 fprintf(stderr
, Name
": cannot find device file for %s\n",
1098 mdfd
= open_mddev(name
, 0);
1100 if (Manage_runstop(name
, mdfd
, -1, !last
))
1109 } while (!last
&& err
);
1112 fprintf(stderr
, Name
": No devices given.\n");
1116 for (dv
=devlist
; dv
; dv
=dv
->next
) {
1117 switch(dv
->disposition
) {
1119 rv
|= Detail(dv
->devname
, brief
?1+verbose
:0, test
, homehost
); continue;
1120 case 'K': /* Zero superblock */
1121 rv
|= Kill(dv
->devname
, force
, quiet
); continue;
1123 rv
|= Query(dv
->devname
); continue;
1125 rv
|= ExamineBitmap(dv
->devname
, brief
, ss
); continue;
1127 mdfd
= open_mddev(dv
->devname
, 0);
1129 switch(dv
->disposition
) {
1131 rv
|= Manage_runstop(dv
->devname
, mdfd
, 1, 0); break;
1133 rv
|= Manage_runstop(dv
->devname
, mdfd
, -1, 0); break;
1135 rv
|= Manage_ro(dv
->devname
, mdfd
, 1); break;
1137 rv
|= Manage_ro(dv
->devname
, mdfd
, -1); break;
1146 if (!devlist
&& !scan
) {
1147 fprintf(stderr
, Name
": Cannot monitor: need --scan or at least one device\n");
1151 if (pidfile
&& !daemonise
) {
1152 fprintf(stderr
, Name
": Cannot write a pid file when not in daemon mode\n");
1156 rv
= Monitor(devlist
, mailaddr
, program
,
1157 delay
?delay
:60, daemonise
, scan
, oneshot
,
1158 dosyslog
, configfile
, test
, pidfile
);
1162 if (devs_found
> 1) {
1165 if (size
>= 0 || raiddisks
) {
1166 fprintf(stderr
, Name
": --size, --raiddisks, and --add are exclusing in --grow mode\n");
1170 for (dv
=devlist
->next
; dv
; dv
=dv
->next
) {
1171 rv
= Grow_Add_device(devlist
->devname
, mdfd
, dv
->devname
);
1175 } else if ((size
>= 0) + (raiddisks
!= 0) + (layout
!= UnSet
) + (bitmap_file
!= NULL
)> 1) {
1176 fprintf(stderr
, Name
": can change at most one of size, raiddisks, bitmap, and layout\n");
1179 } else if (layout
!= UnSet
)
1180 rv
= Manage_reconfig(devlist
->devname
, mdfd
, layout
);
1181 else if (size
>= 0 || raiddisks
)
1182 rv
= Grow_reshape(devlist
->devname
, mdfd
, quiet
, backup_file
,
1183 size
, level
, layout
, chunk
, raiddisks
);
1184 else if (bitmap_file
) {
1185 if (delay
== 0) delay
= DEFAULT_BITMAP_DELAY
;
1186 rv
= Grow_addbitmap(devlist
->devname
, mdfd
, bitmap_file
,
1187 bitmap_chunk
, delay
, write_behind
, force
);
1189 fprintf(stderr
, Name
": no changes to --grow\n");