2 * mdadm - manage Linux "md" devices aka RAID arrays.
4 * Copyright (C) 2001-2013 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@suse.de>
24 * Additions for bitmap and write-behind RAID options, Copyright (C) 2003-2004,
25 * Paul Clements, SteelEye Technology, Inc.
32 static int scan_assemble(struct supertype
*ss
,
34 struct mddev_ident
*ident
);
35 static int misc_scan(char devmode
, struct context
*c
);
36 static int stop_scan(int verbose
);
37 static int misc_list(struct mddev_dev
*devlist
,
38 struct mddev_ident
*ident
,
40 struct supertype
*ss
, struct context
*c
);
41 const char Name
[] = "mdadm";
43 int main(int argc
, char *argv
[])
51 unsigned long long array_size
= 0;
52 unsigned long long data_offset
= INVALID_SECTORS
;
53 struct mddev_ident ident
;
54 char *configfile
= NULL
;
57 struct mddev_dev
*devlist
= NULL
;
58 struct mddev_dev
**devlistend
= & devlist
;
60 mdu_array_info_t array
;
62 char *symlinks
= NULL
;
63 int grow_continue
= 0;
64 /* autof indicates whether and how to create device node.
65 * bottom 3 bits are style. Rest (when shifted) are number of parts
67 * 1 - don't create (no)
68 * 2 - if is_standard, then create (yes)
69 * 3 - create as 'md' - reject is_standard mdp (md)
70 * 4 - create as 'mdp' - reject is_standard md (mdp)
71 * 5 - default to md if not is_standard (md in config file)
72 * 6 - default to mdp if not is_standard (part, or mdp in config file)
75 .require_homehost
= 1,
81 .bitmap_chunk
= UnSet
,
82 .consistency_policy
= CONSISTENCY_POLICY_UNKNOWN
,
85 char sys_hostname
[256];
86 char *mailaddr
= NULL
;
92 int spare_sharing
= 1;
93 struct supertype
*ss
= NULL
;
94 enum flag_mode writemostly
= FlagDefault
;
95 enum flag_mode failfast
= FlagDefault
;
96 char *shortopt
= short_options
;
99 char *remove_path
= NULL
;
100 char *udev_filename
= NULL
;
101 char *dump_directory
= NULL
;
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
;
122 ident
.container
= NULL
;
125 if (get_linux_version() < 2006015) {
126 pr_err("This version of mdadm does not support kernels older than 2.6.15\n");
130 while ((option_index
= -1),
131 (opt
= getopt_long(argc
, argv
, shortopt
, long_options
,
132 &option_index
)) != -1) {
134 /* firstly, some mode-independent options */
144 fputs(Version
, stderr
);
147 case 'v': c
.verbose
++;
150 case 'q': c
.verbose
--;
154 if (mode
== ASSEMBLE
|| mode
== BUILD
||
155 mode
== CREATE
|| mode
== GROW
||
156 mode
== INCREMENTAL
|| mode
== MANAGE
)
157 break; /* b means bitmap */
162 case 'Y': c
.export
++;
166 if (strcasecmp(optarg
, "<ignore>") == 0)
167 c
.require_homehost
= 0;
173 /* Silently ignore old option */
179 if (asprintf(&c
.prefer
, "/%s/", optarg
) <= 0)
185 fputs(Usage
, stderr
);
188 /* second, figure out the mode.
189 * Some options force the mode. Others
190 * set the mode if it isn't already
196 shortopt
= short_bitmap_options
;
208 case ReAdd
: /* re-add */
212 shortopt
= short_bitmap_options
;
216 case 'A': newmode
= ASSEMBLE
;
217 shortopt
= short_bitmap_auto_options
;
219 case 'B': newmode
= BUILD
;
220 shortopt
= short_bitmap_auto_options
;
222 case 'C': newmode
= CREATE
;
223 shortopt
= short_bitmap_auto_options
;
225 case 'F': newmode
= MONITOR
;
227 case 'G': newmode
= GROW
;
228 shortopt
= short_bitmap_options
;
230 case 'I': newmode
= INCREMENTAL
;
231 shortopt
= short_bitmap_auto_options
;
234 newmode
= AUTODETECT
;
269 if (mode
&& newmode
== mode
) {
270 /* everybody happy ! */
271 } else if (mode
&& newmode
!= mode
) {
274 if (option_index
>= 0)
275 fprintf(stderr
, "--%s", long_options
[option_index
].name
);
277 fprintf(stderr
, "-%c", opt
);
278 fprintf(stderr
, " would set mdadm mode to \"%s\", but it is already set to \"%s\".\n",
279 map_num(modes
, newmode
),
280 map_num(modes
, mode
));
282 } else if (!mode
&& newmode
) {
284 if (mode
== MISC
&& devs_found
) {
285 pr_err("No action given for %s in --misc mode\n",
287 cont_err("Action options must come before device names\n");
291 /* special case of -c --help */
292 if ((opt
== 'c' || opt
== ConfigFile
) &&
293 (strncmp(optarg
, "--h", 3) == 0 ||
294 strncmp(optarg
, "-h", 2) == 0)) {
295 fputs(Help_config
, stdout
);
299 /* If first option is a device, don't force the mode yet */
301 if (devs_found
== 0) {
302 dv
= xmalloc(sizeof(*dv
));
303 dv
->devname
= optarg
;
304 dv
->disposition
= devmode
;
305 dv
->writemostly
= writemostly
;
306 dv
->failfast
= failfast
;
310 devlistend
= &dv
->next
;
315 /* No mode yet, and this is the second device ... */
316 pr_err("An option must be given to set the mode before a second device\n"
317 " (%s) is listed\n", optarg
);
320 if (option_index
>= 0)
321 pr_err("--%s", long_options
[option_index
].name
);
324 fprintf(stderr
, " does not set the mode, and so cannot be the first option.\n");
328 /* if we just set the mode, then done */
342 /* an undecorated option - must be a device name.
345 if (devs_found
> 0 && devmode
== DetailPlatform
) {
346 pr_err("controller may only be specified once. %s ignored\n",
351 if (devs_found
> 0 && mode
== MANAGE
&& !devmode
) {
352 pr_err("Must give one of -a/-r/-f for subsequent devices at %s\n", optarg
);
355 if (devs_found
> 0 && mode
== GROW
&& !devmode
) {
356 pr_err("Must give -a/--add for devices to add: %s\n", optarg
);
359 dv
= xmalloc(sizeof(*dv
));
360 dv
->devname
= optarg
;
361 dv
->disposition
= devmode
;
362 dv
->writemostly
= writemostly
;
363 dv
->failfast
= failfast
;
367 devlistend
= &dv
->next
;
373 /* We've got a mode, and opt is now something else which
374 * could depend on the mode */
375 #define O(a,b) ((a<<16)|b)
376 switch (O(mode
,opt
)) {
378 case O(GROW
,ChunkSize
):
380 case O(CREATE
,ChunkSize
):
381 case O(BUILD
,'c'): /* chunk or rounding */
382 case O(BUILD
,ChunkSize
): /* chunk or rounding */
384 pr_err("chunk/rounding may only be specified once. Second value is %s.\n", optarg
);
387 s
.chunk
= parse_size(optarg
);
388 if (s
.chunk
== INVALID_SECTORS
||
389 s
.chunk
< 8 || (s
.chunk
&1)) {
390 pr_err("invalid chunk/rounding value: %s\n",
394 /* Convert sectors to K */
398 case O(INCREMENTAL
, 'e'):
400 case O(ASSEMBLE
,'e'):
401 case O(MISC
,'e'): /* set metadata (superblock) information */
403 pr_err("metadata information already given\n");
406 for(i
= 0; !ss
&& superlist
[i
]; i
++)
407 ss
= superlist
[i
]->match_metadata_desc(optarg
);
410 pr_err("unrecognised metadata identifier: %s\n", optarg
);
416 case O(MANAGE
,WriteMostly
):
418 case O(BUILD
,WriteMostly
):
420 case O(CREATE
,WriteMostly
):
421 /* set write-mostly for following devices */
422 writemostly
= FlagSet
;
426 /* clear write-mostly for following devices */
427 writemostly
= FlagClear
;
430 case O(MANAGE
,FailFast
):
431 case O(CREATE
,FailFast
):
434 case O(MANAGE
,NoFailFast
):
435 failfast
= FlagClear
;
440 case O(BUILD
,'z'): /* size */
442 pr_err("size may only be specified once. Second value is %s.\n", optarg
);
445 if (strcmp(optarg
, "max") == 0)
448 s
.size
= parse_size(optarg
);
449 if (s
.size
== INVALID_SECTORS
|| s
.size
< 8) {
450 pr_err("invalid size: %s\n", optarg
);
453 /* convert sectors to K */
458 case O(GROW
,'Z'): /* array size */
459 if (array_size
> 0) {
460 pr_err("array-size may only be specified once. Second value is %s.\n", optarg
);
463 if (strcmp(optarg
, "max") == 0)
464 array_size
= MAX_SIZE
;
466 array_size
= parse_size(optarg
);
467 if (array_size
== 0 ||
468 array_size
== INVALID_SECTORS
) {
469 pr_err("invalid array size: %s\n",
476 case O(CREATE
,DataOffset
):
477 case O(GROW
,DataOffset
):
478 if (data_offset
!= INVALID_SECTORS
) {
479 pr_err("data-offset may only be specified one. Second value is %s.\n", optarg
);
482 if (mode
== CREATE
&& strcmp(optarg
, "variable") == 0)
483 data_offset
= VARIABLE_OFFSET
;
485 data_offset
= parse_size(optarg
);
486 if (data_offset
== INVALID_SECTORS
) {
487 pr_err("invalid data-offset: %s\n",
495 case O(BUILD
,'l'): /* set raid level*/
496 if (s
.level
!= UnSet
) {
497 pr_err("raid level may only be set once. Second value is %s.\n", optarg
);
500 s
.level
= map_name(pers
, optarg
);
501 if (s
.level
== UnSet
) {
502 pr_err("invalid raid level: %s\n",
506 if (s
.level
!= 0 && s
.level
!= LEVEL_LINEAR
&&
507 s
.level
!= 1 && s
.level
!= LEVEL_MULTIPATH
&&
508 s
.level
!= LEVEL_FAULTY
&& s
.level
!= 10 &&
510 pr_err("Raid level %s not permitted with --build.\n",
514 if (s
.sparedisks
> 0 && s
.level
< 1 && s
.level
>= -1) {
515 pr_err("raid level %s is incompatible with spare-devices setting.\n",
519 ident
.level
= s
.level
;
522 case O(GROW
, 'p'): /* new layout */
523 case O(GROW
, Layout
):
525 pr_err("layout may only be sent once. Second value was %s\n", optarg
);
528 s
.layout_str
= optarg
;
529 /* 'Grow' will parse the value */
532 case O(CREATE
,'p'): /* raid5 layout */
533 case O(CREATE
,Layout
):
534 case O(BUILD
,'p'): /* faulty layout */
535 case O(BUILD
,Layout
):
536 if (s
.layout
!= UnSet
) {
537 pr_err("layout may only be sent once. Second value was %s\n", optarg
);
542 pr_err("layout not meaningful for %s arrays.\n",
543 map_num(pers
, s
.level
));
546 pr_err("raid level must be given before layout.\n");
550 s
.layout
= map_name(r5layout
, optarg
);
551 if (s
.layout
== UnSet
) {
552 pr_err("layout %s not understood for raid5.\n",
558 s
.layout
= map_name(r6layout
, optarg
);
559 if (s
.layout
== UnSet
) {
560 pr_err("layout %s not understood for raid6.\n",
567 s
.layout
= parse_layout_10(optarg
);
569 pr_err("layout for raid10 must be 'nNN', 'oNN' or 'fNN' where NN is a number, not %s\n", optarg
);
577 s
.layout
= parse_layout_faulty(optarg
);
578 if (s
.layout
== -1) {
579 pr_err("layout %s not understood for faulty.\n",
587 case O(CREATE
,AssumeClean
):
588 case O(BUILD
,AssumeClean
): /* assume clean */
589 case O(GROW
,AssumeClean
):
595 case O(BUILD
,'n'): /* number of raid disks */
597 pr_err("raid-devices set twice: %d and %s\n",
598 s
.raiddisks
, optarg
);
601 s
.raiddisks
= parse_num(optarg
);
602 if (s
.raiddisks
<= 0) {
603 pr_err("invalid number of raid devices: %s\n",
607 ident
.raid_disks
= s
.raiddisks
;
609 case O(ASSEMBLE
, Nodes
):
611 case O(CREATE
, Nodes
):
612 c
.nodes
= parse_num(optarg
);
614 pr_err("clustered array needs two nodes at least: %s\n",
619 case O(CREATE
, ClusterName
):
620 case O(ASSEMBLE
, ClusterName
):
621 c
.homecluster
= optarg
;
622 if (strlen(c
.homecluster
) > 64) {
623 pr_err("Cluster name too big.\n");
627 case O(CREATE
,'x'): /* number of spare (eXtra) disks */
629 pr_err("spare-devices set twice: %d and %s\n",
630 s
.sparedisks
, optarg
);
633 if (s
.level
!= UnSet
&& s
.level
<= 0 && s
.level
>= -1) {
634 pr_err("spare-devices setting is incompatible with raid level %d\n",
638 s
.sparedisks
= parse_num(optarg
);
639 if (s
.sparedisks
< 0) {
640 pr_err("invalid number of spare-devices: %s\n",
650 case O(INCREMENTAL
,'a'):
651 case O(INCREMENTAL
,Auto
):
652 case O(ASSEMBLE
,'a'):
653 case O(ASSEMBLE
,Auto
): /* auto-creation of device node */
654 c
.autof
= parse_auto(optarg
, "--auto flag", 0);
657 case O(CREATE
,Symlinks
):
658 case O(BUILD
,Symlinks
):
659 case O(ASSEMBLE
,Symlinks
): /* auto creation of symlinks in /dev to /dev/md */
663 case O(BUILD
,'f'): /* force honouring '-n 1' */
664 case O(BUILD
,Force
): /* force honouring '-n 1' */
665 case O(GROW
,'f'): /* ditto */
666 case O(GROW
,Force
): /* ditto */
667 case O(CREATE
,'f'): /* force honouring of device list */
668 case O(CREATE
,Force
): /* force honouring of device list */
669 case O(ASSEMBLE
,'f'): /* force assembly */
670 case O(ASSEMBLE
,Force
): /* force assembly */
671 case O(MISC
,'f'): /* force zero */
672 case O(MISC
,Force
): /* force zero */
673 case O(MANAGE
,Force
): /* add device which is too large */
676 /* now for the Assemble options */
677 case O(ASSEMBLE
, FreezeReshape
): /* Freeze reshape during
679 case O(INCREMENTAL
, FreezeReshape
):
680 c
.freeze_reshape
= 1;
682 case O(CREATE
,'u'): /* uuid of array */
683 case O(ASSEMBLE
,'u'): /* uuid of array */
684 if (ident
.uuid_set
) {
685 pr_err("uuid cannot be set twice. Second value %s.\n", optarg
);
688 if (parse_uuid(optarg
, ident
.uuid
))
691 pr_err("Bad uuid: %s\n", optarg
);
697 case O(ASSEMBLE
,'N'):
700 pr_err("name cannot be set twice. Second value %s.\n", optarg
);
703 if (mode
== MISC
&& !c
.subarray
) {
704 pr_err("-N/--name only valid with --update-subarray in misc mode\n");
707 if (strlen(optarg
) > 32) {
708 pr_err("name '%s' is too long, 32 chars max.\n",
712 strcpy(ident
.name
, optarg
);
715 case O(ASSEMBLE
,'m'): /* super-minor for array */
716 case O(ASSEMBLE
,SuperMinor
):
717 if (ident
.super_minor
!= UnSet
) {
718 pr_err("super-minor cannot be set twice. Second value: %s.\n", optarg
);
721 if (strcmp(optarg
, "dev") == 0)
722 ident
.super_minor
= -2;
724 ident
.super_minor
= parse_num(optarg
);
725 if (ident
.super_minor
< 0) {
726 pr_err("Bad super-minor number: %s.\n", optarg
);
732 case O(ASSEMBLE
,'o'):
738 case O(ASSEMBLE
,'U'): /* update the superblock */
741 pr_err("Can only update one aspect of superblock, both %s and %s given.\n",
745 if (mode
== MISC
&& !c
.subarray
) {
746 pr_err("Only subarrays can be updated in misc mode\n");
750 if (strcmp(c
.update
, "sparc2.2") == 0)
752 if (strcmp(c
.update
, "super-minor") == 0)
754 if (strcmp(c
.update
, "summaries") == 0)
756 if (strcmp(c
.update
, "resync") == 0)
758 if (strcmp(c
.update
, "uuid") == 0)
760 if (strcmp(c
.update
, "name") == 0)
762 if (strcmp(c
.update
, "homehost") == 0)
764 if (strcmp(c
.update
, "home-cluster") == 0)
766 if (strcmp(c
.update
, "nodes") == 0)
768 if (strcmp(c
.update
, "devicesize") == 0)
770 if (strcmp(c
.update
, "no-bitmap") == 0)
772 if (strcmp(c
.update
, "bbl") == 0)
774 if (strcmp(c
.update
, "no-bbl") == 0)
776 if (strcmp(c
.update
, "force-no-bbl") == 0)
778 if (strcmp(c
.update
, "ppl") == 0)
780 if (strcmp(c
.update
, "no-ppl") == 0)
782 if (strcmp(c
.update
, "metadata") == 0)
784 if (strcmp(c
.update
, "revert-reshape") == 0)
786 if (strcmp(c
.update
, "byteorder") == 0) {
788 pr_err("must not set metadata type with --update=byteorder.\n");
791 for(i
= 0; !ss
&& superlist
[i
]; i
++)
792 ss
= superlist
[i
]->match_metadata_desc(
795 pr_err("INTERNAL ERROR cannot find 0.swap\n");
801 if (strcmp(c
.update
,"?") == 0 ||
802 strcmp(c
.update
, "help") == 0) {
804 fprintf(outf
, "%s: ", Name
);
808 "%s: '--update=%s' is invalid. ",
811 fprintf(outf
, "Valid --update options are:\n"
812 " 'sparc2.2', 'super-minor', 'uuid', 'name', 'nodes', 'resync',\n"
813 " 'summaries', 'homehost', 'home-cluster', 'byteorder', 'devicesize',\n"
814 " 'no-bitmap', 'metadata', 'revert-reshape'\n"
815 " 'bbl', 'no-bbl', 'force-no-bbl', 'ppl', 'no-ppl'\n"
817 exit(outf
== stdout
? 0 : 2);
820 /* update=devicesize is allowed with --re-add */
821 if (devmode
!= 'A') {
822 pr_err("--update in Manage mode only allowed with --re-add.\n");
826 pr_err("Can only update one aspect of superblock, both %s and %s given.\n",
831 if (strcmp(c
.update
, "devicesize") != 0 &&
832 strcmp(c
.update
, "bbl") != 0 &&
833 strcmp(c
.update
, "force-no-bbl") != 0 &&
834 strcmp(c
.update
, "no-bbl") != 0) {
835 pr_err("only 'devicesize', 'bbl', 'no-bbl', and 'force-no-bbl' can be updated with --re-add\n");
840 case O(INCREMENTAL
,NoDegraded
):
841 pr_err("--no-degraded is deprecated in Incremental mode\n");
842 case O(ASSEMBLE
,NoDegraded
): /* --no-degraded */
843 c
.runstop
= -1; /* --stop isn't allowed for --assemble,
844 * so we overload slightly */
847 case O(ASSEMBLE
,'c'):
848 case O(ASSEMBLE
,ConfigFile
):
849 case O(INCREMENTAL
, 'c'):
850 case O(INCREMENTAL
, ConfigFile
):
852 case O(MISC
, ConfigFile
):
854 case O(MONITOR
,ConfigFile
):
855 case O(CREATE
,ConfigFile
):
857 pr_err("configfile cannot be set twice. Second value is %s.\n", optarg
);
861 set_conffile(configfile
);
862 /* FIXME possibly check that config file exists. Even parse it */
864 case O(ASSEMBLE
,'s'): /* scan */
867 case O(INCREMENTAL
,'s'):
871 case O(MONITOR
,'m'): /* mail address */
872 case O(MONITOR
,EMail
):
874 pr_err("only specify one mailaddress. %s ignored.\n",
880 case O(MONITOR
,'p'): /* alert program */
881 case O(MONITOR
,ProgramOpt
): /* alert program */
883 pr_err("only specify one alter program. %s ignored.\n",
889 case O(MONITOR
,'r'): /* rebuild increments */
890 case O(MONITOR
,Increment
):
891 increments
= atoi(optarg
);
892 if (increments
> 99 || increments
< 1) {
893 pr_err("please specify positive integer between 1 and 99 as rebuild increments.\n");
898 case O(MONITOR
,'d'): /* delay in seconds */
900 case O(BUILD
,'d'): /* delay for bitmap updates */
903 pr_err("only specify delay once. %s ignored.\n",
906 c
.delay
= parse_num(optarg
);
908 pr_err("invalid delay: %s\n",
914 case O(MONITOR
,'f'): /* daemonise */
915 case O(MONITOR
,Fork
):
918 case O(MONITOR
,'i'): /* pid */
920 pr_err("only specify one pid file. %s ignored.\n",
925 case O(MONITOR
,'1'): /* oneshot */
929 case O(MONITOR
,'t'): /* test */
932 case O(MONITOR
,'y'): /* log messages to syslog */
933 openlog("mdadm", LOG_PID
, SYSLOG_FACILITY
);
936 case O(MONITOR
, NoSharing
):
940 /* now the general management options. Some are applicable
941 * to other modes. None have arguments.
946 case O(MANAGE
,Add
): /* add a drive */
949 case O(MANAGE
,AddSpare
): /* add drive - never re-add */
952 case O(MANAGE
,AddJournal
): /* add journal */
953 if (s
.journaldisks
&& (s
.level
< 4 || s
.level
> 6)) {
954 pr_err("--add-journal is only supported for RAID level 4/5/6.\n");
959 case O(MANAGE
,ReAdd
):
962 case O(MANAGE
,'r'): /* remove a drive */
963 case O(MANAGE
,Remove
):
966 case O(MANAGE
,'f'): /* set faulty */
968 case O(INCREMENTAL
,'f'):
969 case O(INCREMENTAL
,Remove
):
970 case O(INCREMENTAL
,Fail
): /* r for incremental is taken, use f
971 * even though we will both fail and
972 * remove the device */
975 case O(MANAGE
, ClusterConfirm
):
978 case O(MANAGE
,Replace
):
979 /* Mark these devices for replacement */
983 /* These are the replacements to use */
984 if (devmode
!= 'R') {
985 pr_err("--with must follow --replace\n");
990 case O(INCREMENTAL
,'R'):
992 case O(ASSEMBLE
,'R'):
994 case O(CREATE
,'R'): /* Run the array */
996 pr_err("Cannot both Stop and Run an array\n");
1002 if (c
.runstop
> 0) {
1003 pr_err("Cannot both Run and Stop an array\n");
1015 case O(MISC
,KillOpt
):
1019 case O(MISC
, ExamineBB
):
1023 case O(MISC
, WaitOpt
):
1024 case O(MISC
, Waitclean
):
1025 case O(MISC
, DetailPlatform
):
1026 case O(MISC
, KillSubarray
):
1027 case O(MISC
, UpdateSubarray
):
1029 case O(MISC
, Restore
):
1030 case O(MISC
,Action
):
1031 if (opt
== KillSubarray
|| opt
== UpdateSubarray
) {
1033 pr_err("subarray can only be specified once\n");
1036 c
.subarray
= optarg
;
1038 if (opt
== Action
) {
1040 pr_err("Only one --action can be specified\n");
1043 if (strcmp(optarg
, "idle") == 0 ||
1044 strcmp(optarg
, "frozen") == 0 ||
1045 strcmp(optarg
, "check") == 0 ||
1046 strcmp(optarg
, "repair") == 0)
1049 pr_err("action must be one of idle, frozen, check, repair\n");
1053 if (devmode
&& devmode
!= opt
&&
1055 (opt
== 'E' && devmode
!= 'Q'))) {
1056 pr_err("--examine/-E cannot be given with ");
1057 if (devmode
== 'E') {
1058 if (option_index
>= 0)
1059 fprintf(stderr
, "--%s\n",
1060 long_options
[option_index
].name
);
1062 fprintf(stderr
, "-%c\n", opt
);
1063 } else if (isalpha(devmode
))
1064 fprintf(stderr
, "-%c\n", devmode
);
1066 fprintf(stderr
, "previous option\n");
1070 if (opt
== Dump
|| opt
== Restore
) {
1071 if (dump_directory
!= NULL
) {
1072 pr_err("dump/restore directory specified twice: %s and %s\n",
1073 dump_directory
, optarg
);
1076 dump_directory
= optarg
;
1079 case O(MISC
, UdevRules
):
1080 if (devmode
&& devmode
!= opt
) {
1081 pr_err("--udev-rules must be the only option.\n");
1084 pr_err("only specify one udev rule filename. %s ignored.\n",
1087 udev_filename
= optarg
;
1095 case O(MISC
, Sparc22
):
1096 if (devmode
!= 'E') {
1097 pr_err("--sparc2.2 only allowed with --examine\n");
1103 case O(ASSEMBLE
,'b'): /* here we simply set the bitmap file */
1104 case O(ASSEMBLE
,Bitmap
):
1106 pr_err("bitmap file needed with -b in --assemble mode\n");
1109 if (strcmp(optarg
, "internal") == 0 ||
1110 strcmp(optarg
, "clustered") == 0) {
1111 pr_err("no need to specify --bitmap when assembling"
1112 " arrays with internal or clustered bitmap\n");
1115 bitmap_fd
= open(optarg
, O_RDWR
);
1116 if (!*optarg
|| bitmap_fd
< 0) {
1117 pr_err("cannot open bitmap file %s: %s\n", optarg
, strerror(errno
));
1120 ident
.bitmap_fd
= bitmap_fd
; /* for Assemble */
1123 case O(ASSEMBLE
, BackupFile
):
1124 case O(GROW
, BackupFile
):
1125 /* Specify a file into which grow might place a backup,
1126 * or from which assemble might recover a backup
1128 if (c
.backup_file
) {
1129 pr_err("backup file already specified, rejecting %s\n", optarg
);
1132 c
.backup_file
= optarg
;
1135 case O(GROW
, Continue
):
1136 /* Continue interrupted grow
1140 case O(ASSEMBLE
, InvalidBackup
):
1141 /* Acknowledge that the backupfile is invalid, but ask
1142 * to continue anyway
1144 c
.invalid_backup
= 1;
1148 case O(BUILD
,Bitmap
):
1150 case O(CREATE
,Bitmap
): /* here we create the bitmap */
1152 case O(GROW
,Bitmap
):
1153 if (s
.bitmap_file
) {
1154 pr_err("bitmap cannot be set twice. Second value: %s.\n", optarg
);
1157 if (strcmp(optarg
, "internal") == 0 ||
1158 strcmp(optarg
, "none") == 0 ||
1159 strchr(optarg
, '/') != NULL
) {
1160 s
.bitmap_file
= optarg
;
1163 if (strcmp(optarg
, "clustered") == 0) {
1164 s
.bitmap_file
= optarg
;
1165 /* Set the default number of cluster nodes
1166 * to 4 if not already set by user
1173 pr_err("bitmap file must contain a '/', or be 'internal', or be 'clustered', or 'none'\n"
1174 " not '%s'\n", optarg
);
1177 case O(GROW
,BitmapChunk
):
1178 case O(BUILD
,BitmapChunk
):
1179 case O(CREATE
,BitmapChunk
): /* bitmap chunksize */
1180 s
.bitmap_chunk
= parse_size(optarg
);
1181 if (s
.bitmap_chunk
== 0 ||
1182 s
.bitmap_chunk
== INVALID_SECTORS
||
1183 s
.bitmap_chunk
& (s
.bitmap_chunk
- 1)) {
1184 pr_err("invalid bitmap chunksize: %s\n",
1188 s
.bitmap_chunk
= s
.bitmap_chunk
* 512;
1191 case O(GROW
, WriteBehind
):
1192 case O(BUILD
, WriteBehind
):
1193 case O(CREATE
, WriteBehind
): /* write-behind mode */
1194 s
.write_behind
= DEFAULT_MAX_WRITE_BEHIND
;
1196 s
.write_behind
= parse_num(optarg
);
1197 if (s
.write_behind
< 0 ||
1198 s
.write_behind
> 16383) {
1199 pr_err("Invalid value for maximum outstanding write-behind writes: %s.\n\tMust be between 0 and 16383.\n", optarg
);
1205 case O(INCREMENTAL
, 'r'):
1206 case O(INCREMENTAL
, RebuildMapOpt
):
1209 case O(INCREMENTAL
, IncrementalPath
):
1210 remove_path
= optarg
;
1212 case O(CREATE
, WriteJournal
):
1213 if (s
.journaldisks
) {
1214 pr_err("Please specify only one journal device for the array.\n");
1215 pr_err("Ignoring --write-journal %s...\n", optarg
);
1218 dv
= xmalloc(sizeof(*dv
));
1219 dv
->devname
= optarg
;
1220 dv
->disposition
= 'j'; /* WriteJournal */
1224 devlistend
= &dv
->next
;
1229 case O(CREATE
, 'k'):
1231 s
.consistency_policy
= map_name(consistency_policies
,
1233 if (s
.consistency_policy
< CONSISTENCY_POLICY_RESYNC
) {
1234 pr_err("Invalid consistency policy: %s\n",
1240 /* We have now processed all the valid options. Anything else is
1243 if (option_index
> 0)
1244 pr_err(":option --%s not valid in %s mode\n",
1245 long_options
[option_index
].name
,
1246 map_num(modes
, mode
));
1248 pr_err("option -%c not valid in %s mode\n",
1249 opt
, map_num(modes
, mode
));
1256 if (print_help
== 2)
1257 help_text
= OptionHelp
;
1259 help_text
= mode_help
[mode
];
1260 if (help_text
== NULL
)
1262 fputs(help_text
,stdout
);
1266 if (s
.journaldisks
) {
1267 if (s
.level
< 4 || s
.level
> 6) {
1268 pr_err("--write-journal is only supported for RAID level 4/5/6.\n");
1271 if (s
.consistency_policy
!= CONSISTENCY_POLICY_UNKNOWN
&&
1272 s
.consistency_policy
!= CONSISTENCY_POLICY_JOURNAL
) {
1273 pr_err("--write-journal is not supported with consistency policy: %s\n",
1274 map_num(consistency_policies
, s
.consistency_policy
));
1279 if (mode
== CREATE
&&
1280 s
.consistency_policy
!= CONSISTENCY_POLICY_UNKNOWN
) {
1282 pr_err("--consistency-policy not meaningful with level %s.\n",
1283 map_num(pers
, s
.level
));
1285 } else if (s
.consistency_policy
== CONSISTENCY_POLICY_JOURNAL
&&
1287 pr_err("--write-journal is required for consistency policy: %s\n",
1288 map_num(consistency_policies
, s
.consistency_policy
));
1290 } else if (s
.consistency_policy
== CONSISTENCY_POLICY_PPL
&&
1292 pr_err("PPL consistency policy is only supported for RAID level 5.\n");
1294 } else if (s
.consistency_policy
== CONSISTENCY_POLICY_BITMAP
&&
1296 strcmp(s
.bitmap_file
, "none") == 0)) {
1297 pr_err("--bitmap is required for consistency policy: %s\n",
1298 map_num(consistency_policies
, s
.consistency_policy
));
1300 } else if (s
.bitmap_file
&&
1301 strcmp(s
.bitmap_file
, "none") != 0 &&
1302 s
.consistency_policy
!= CONSISTENCY_POLICY_BITMAP
&&
1303 s
.consistency_policy
!= CONSISTENCY_POLICY_JOURNAL
) {
1304 pr_err("--bitmap is not compatible with consistency policy: %s\n",
1305 map_num(consistency_policies
, s
.consistency_policy
));
1310 if (!mode
&& devs_found
) {
1313 if (devlist
->disposition
== 0)
1314 devlist
->disposition
= devmode
;
1317 fputs(Usage
, stderr
);
1322 struct createinfo
*ci
= conf_get_create_info();
1324 if (strcasecmp(symlinks
, "yes") == 0)
1326 else if (strcasecmp(symlinks
, "no") == 0)
1329 pr_err("option --symlinks must be 'no' or 'yes'\n");
1333 /* Ok, got the option parsing out of the way
1334 * hopefully it's mostly right but there might be some stuff
1337 * That is mostly checked in the per-mode stuff but...
1339 * For @,B,C and A without -s, the first device listed must be
1340 * an md device. We check that here and open it.
1343 if (mode
== MANAGE
|| mode
== BUILD
|| mode
== CREATE
||
1344 mode
== GROW
|| (mode
== ASSEMBLE
&& ! c
.scan
)) {
1345 if (devs_found
< 1) {
1346 pr_err("an md device must be given in this mode\n");
1349 if ((int)ident
.super_minor
== -2 && c
.autof
) {
1350 pr_err("--super-minor=dev is incompatible with --auto\n");
1353 if (mode
== MANAGE
|| mode
== GROW
) {
1354 mdfd
= open_mddev(devlist
->devname
, 1);
1358 /* non-existent device is OK */
1359 mdfd
= open_mddev(devlist
->devname
, 0);
1361 pr_err("device %s exists but is not an md array.\n", devlist
->devname
);
1364 if ((int)ident
.super_minor
== -2) {
1367 pr_err("--super-minor=dev given, and listed device %s doesn't exist.\n",
1372 ident
.super_minor
= minor(stb
.st_rdev
);
1374 if (mdfd
>= 0 && mode
!= MANAGE
&& mode
!= GROW
) {
1375 /* We don't really want this open yet, we just might
1376 * have wanted to check some things
1384 if (s
.raiddisks
== 1 && !c
.force
&& s
.level
!= LEVEL_FAULTY
) {
1385 pr_err("'1' is an unusual number of drives for an array, so it is probably\n"
1386 " a mistake. If you really mean it you will need to specify --force before\n"
1387 " setting the number of drives.\n");
1392 if (c
.homehost
== NULL
&& c
.require_homehost
)
1393 c
.homehost
= conf_get_homehost(&c
.require_homehost
);
1394 if (c
.homehost
== NULL
|| strcasecmp(c
.homehost
, "<system>") == 0) {
1395 if (gethostname(sys_hostname
, sizeof(sys_hostname
)) == 0) {
1396 sys_hostname
[sizeof(sys_hostname
)-1] = 0;
1397 c
.homehost
= sys_hostname
;
1401 (!c
.homehost
[0] || strcasecmp(c
.homehost
, "<none>") == 0)) {
1403 c
.require_homehost
= 0;
1408 set_hooks(); /* set hooks from libs */
1410 if (c
.homecluster
== NULL
&& (c
.nodes
> 0)) {
1411 c
.homecluster
= conf_get_homecluster();
1412 if (c
.homecluster
== NULL
)
1413 rv
= get_cluster_name(&c
.homecluster
);
1415 pr_err("The md can't get cluster name\n");
1420 if (c
.backup_file
&& data_offset
!= INVALID_SECTORS
) {
1421 pr_err("--backup-file and --data-offset are incompatible\n");
1425 if ((mode
== MISC
&& devmode
== 'E') ||
1426 (mode
== MONITOR
&& spare_sharing
== 0))
1427 /* Anyone may try this */;
1428 else if (geteuid() != 0) {
1429 pr_err("must be super-user to perform this action\n");
1433 ident
.autof
= c
.autof
;
1435 if (c
.scan
&& c
.verbose
< 2)
1436 /* --scan implied --brief unless -vv */
1439 if (mode
== CREATE
) {
1440 if (s
.bitmap_file
&& strcmp(s
.bitmap_file
, "clustered") == 0) {
1441 locked
= cluster_get_dlmlock();
1445 } else if (mode
== MANAGE
|| mode
== GROW
|| mode
== INCREMENTAL
) {
1446 if (!md_get_array_info(mdfd
, &array
) && (devmode
!= 'c')) {
1447 if (array
.state
& (1 << MD_SB_CLUSTERED
)) {
1448 locked
= cluster_get_dlmlock();
1457 /* readonly, add/remove, readwrite, runstop */
1459 rv
= Manage_ro(devlist
->devname
, mdfd
, c
.readonly
);
1460 if (!rv
&& devs_found
>1)
1461 rv
= Manage_subdevs(devlist
->devname
, mdfd
,
1462 devlist
->next
, c
.verbose
, c
.test
,
1464 if (!rv
&& c
.readonly
< 0)
1465 rv
= Manage_ro(devlist
->devname
, mdfd
, c
.readonly
);
1466 if (!rv
&& c
.runstop
> 0)
1467 rv
= Manage_run(devlist
->devname
, mdfd
, &c
);
1468 if (!rv
&& c
.runstop
< 0)
1469 rv
= Manage_stop(devlist
->devname
, mdfd
, c
.verbose
, 0);
1472 if (devs_found
== 1 && ident
.uuid_set
== 0 &&
1473 ident
.super_minor
== UnSet
&& ident
.name
[0] == 0 &&
1475 /* Only a device has been given, so get details from config file */
1476 struct mddev_ident
*array_ident
= conf_get_ident(devlist
->devname
);
1477 if (array_ident
== NULL
) {
1478 pr_err("%s not identified in config file.\n",
1484 if (array_ident
->autof
== 0)
1485 array_ident
->autof
= c
.autof
;
1486 rv
|= Assemble(ss
, devlist
->devname
, array_ident
,
1490 rv
= Assemble(ss
, devlist
->devname
, &ident
,
1492 else if (devs_found
> 0) {
1493 if (c
.update
&& devs_found
> 1) {
1494 pr_err("can only update a single array at a time\n");
1497 if (c
.backup_file
&& devs_found
> 1) {
1498 pr_err("can only assemble a single array when providing a backup file.\n");
1501 for (dv
= devlist
; dv
; dv
= dv
->next
) {
1502 struct mddev_ident
*array_ident
= conf_get_ident(dv
->devname
);
1503 if (array_ident
== NULL
) {
1504 pr_err("%s not identified in config file.\n",
1509 if (array_ident
->autof
== 0)
1510 array_ident
->autof
= c
.autof
;
1511 rv
|= Assemble(ss
, dv
->devname
, array_ident
,
1516 pr_err("--update not meaningful with a --scan assembly.\n");
1519 if (c
.backup_file
) {
1520 pr_err("--backup_file not meaningful with a --scan assembly.\n");
1523 rv
= scan_assemble(ss
, &c
, &ident
);
1529 c
.delay
= DEFAULT_BITMAP_DELAY
;
1530 if (s
.write_behind
&& !s
.bitmap_file
) {
1531 pr_err("write-behind mode requires a bitmap.\n");
1535 if (s
.raiddisks
== 0) {
1536 pr_err("no raid-devices specified.\n");
1541 if (s
.bitmap_file
) {
1542 if (strcmp(s
.bitmap_file
, "internal") == 0 ||
1543 strcmp(s
.bitmap_file
, "clustered") == 0) {
1544 pr_err("'internal' and 'clustered' bitmaps not supported with --build\n");
1549 rv
= Build(devlist
->devname
, devlist
->next
, &s
, &c
);
1553 c
.delay
= DEFAULT_BITMAP_DELAY
;
1556 if (!s
.bitmap_file
||
1557 strcmp(s
.bitmap_file
, "clustered") != 0) {
1558 pr_err("--nodes argument only compatible with --bitmap=clustered\n");
1563 if (s
.level
!= 1 && s
.level
!= 10) {
1564 pr_err("--bitmap=clustered is currently supported with raid1/10 only\n");
1568 if (s
.level
== 10 && !(is_near_layout_10(s
.layout
) || s
.layout
== UnSet
)) {
1569 pr_err("only near layout is supported with clustered raid10\n");
1575 if (s
.write_behind
&& !s
.bitmap_file
) {
1576 pr_err("write-behind mode requires a bitmap.\n");
1580 if (s
.raiddisks
== 0) {
1581 pr_err("no raid-devices specified.\n");
1586 rv
= Create(ss
, devlist
->devname
,
1587 ident
.name
, ident
.uuid_set
? ident
.uuid
: NULL
,
1588 devs_found
-1, devlist
->next
,
1589 &s
, &c
, data_offset
);
1592 if (devmode
== 'E') {
1593 if (devlist
== NULL
&& !c
.scan
) {
1594 pr_err("No devices to examine\n");
1597 if (devlist
== NULL
)
1598 devlist
= conf_get_devs();
1599 if (devlist
== NULL
) {
1600 pr_err("No devices listed in %s\n", configfile
?configfile
:DefaultConfFile
);
1603 rv
= Examine(devlist
, &c
, ss
);
1604 } else if (devmode
== DetailPlatform
) {
1605 rv
= Detail_Platform(ss
? ss
->ss
: NULL
, ss
? c
.scan
: 1,
1606 c
.verbose
, c
.export
,
1607 devlist
? devlist
->devname
: NULL
);
1608 } else if (devlist
== NULL
) {
1609 if (devmode
== 'S' && c
.scan
)
1610 rv
= stop_scan(c
.verbose
);
1611 else if ((devmode
== 'D' || devmode
== Waitclean
) &&
1613 rv
= misc_scan(devmode
, &c
);
1614 else if (devmode
== UdevRules
)
1615 rv
= Write_rules(udev_filename
);
1617 pr_err("No devices given.\n");
1621 rv
= misc_list(devlist
, &ident
, dump_directory
, ss
, &c
);
1624 if (!devlist
&& !c
.scan
) {
1625 pr_err("Cannot monitor: need --scan or at least one device\n");
1629 if (pidfile
&& !daemonise
) {
1630 pr_err("Cannot write a pid file when not in daemon mode\n");
1635 if (get_linux_version() > 2006016)
1636 /* mdstat responds to poll */
1641 rv
= Monitor(devlist
, mailaddr
, program
,
1642 &c
, daemonise
, oneshot
,
1643 dosyslog
, pidfile
, increments
,
1648 if (array_size
> 0) {
1649 /* alway impose array size first, independent of
1651 * Do not allow level or raid_disks changes at the
1652 * same time as that can be irreversibly destructive.
1656 if (s
.raiddisks
|| s
.level
!= UnSet
) {
1657 pr_err("cannot change array size in same operation as changing raiddisks or level.\n"
1658 " Change size first, then check that data is still intact.\n");
1662 if (sysfs_init(&sra
, mdfd
, NULL
)) {
1666 if (array_size
== MAX_SIZE
)
1667 err
= sysfs_set_str(&sra
, NULL
, "array_size", "default");
1669 err
= sysfs_set_num(&sra
, NULL
, "array_size", array_size
/ 2);
1672 pr_err("--array-size setting is too large.\n");
1674 pr_err("current kernel does not support setting --array-size\n");
1679 if (devs_found
> 1 && s
.raiddisks
== 0 && s
.level
== UnSet
) {
1681 if (s
.size
> 0 || s
.chunk
||
1682 s
.layout_str
|| s
.bitmap_file
) {
1683 pr_err("--add cannot be used with other geometry changes in --grow mode\n");
1687 for (dv
= devlist
->next
; dv
; dv
= dv
->next
) {
1688 rv
= Grow_Add_device(devlist
->devname
, mdfd
,
1693 } else if (s
.bitmap_file
) {
1694 if (s
.size
> 0 || s
.raiddisks
|| s
.chunk
||
1695 s
.layout_str
|| devs_found
> 1) {
1696 pr_err("--bitmap changes cannot be used with other geometry changes in --grow mode\n");
1701 c
.delay
= DEFAULT_BITMAP_DELAY
;
1702 rv
= Grow_addbitmap(devlist
->devname
, mdfd
, &c
, &s
);
1703 } else if (grow_continue
)
1704 rv
= Grow_continue_command(devlist
->devname
,
1705 mdfd
, c
.backup_file
,
1707 else if (s
.size
> 0 || s
.raiddisks
|| s
.layout_str
||
1708 s
.chunk
!= 0 || s
.level
!= UnSet
||
1709 data_offset
!= INVALID_SECTORS
) {
1710 rv
= Grow_reshape(devlist
->devname
, mdfd
,
1712 data_offset
, &c
, &s
);
1713 } else if (s
.consistency_policy
!= CONSISTENCY_POLICY_UNKNOWN
) {
1714 rv
= Grow_consistency_policy(devlist
->devname
, mdfd
, &c
, &s
);
1715 } else if (array_size
== 0)
1716 pr_err("no changes to --grow\n");
1725 pr_err("In --incremental mode, a device cannot be given with --scan.\n");
1728 if (c
.runstop
<= 0) {
1729 pr_err("--incremental --scan meaningless without --run.\n");
1732 if (devmode
== 'f') {
1733 pr_err("--incremental --scan --fail not supported.\n");
1736 rv
= IncrementalScan(&c
, NULL
);
1739 if (!rebuild_map
&& !c
.scan
) {
1740 pr_err("--incremental requires a device.\n");
1745 if (devmode
== 'f') {
1746 if (devlist
->next
) {
1747 pr_err("'--incremental --fail' can only handle one device.\n");
1751 rv
= IncrementalRemove(devlist
->devname
, remove_path
,
1754 rv
= Incremental(devlist
, &c
, ss
);
1761 cluster_release_dlmlock();
1767 static int scan_assemble(struct supertype
*ss
,
1769 struct mddev_ident
*ident
)
1771 struct mddev_ident
*a
, *array_list
= conf_get_ident(NULL
);
1772 struct mddev_dev
*devlist
= conf_get_devs();
1773 struct map_ent
*map
= NULL
;
1776 int failures
, successes
;
1778 if (conf_verify_devnames(array_list
)) {
1779 pr_err("Duplicate MD device names in conf file were found.\n");
1782 if (devlist
== NULL
) {
1783 pr_err("No devices listed in conf file were found.\n");
1786 for (a
= array_list
; a
; a
= a
->next
) {
1789 a
->autof
= c
->autof
;
1792 pr_err("failed to get exclusive lock on mapfile\n");
1797 for (a
= array_list
; a
; a
= a
->next
) {
1802 strcasecmp(a
->devname
, "<ignore>") == 0)
1805 r
= Assemble(ss
, a
->devname
,
1815 } while (failures
&& successes
);
1816 if (c
->homehost
&& cnt
== 0) {
1817 /* Maybe we can auto-assemble something.
1818 * Repeatedly call Assemble in auto-assemble mode
1823 ident
->autof
= c
->autof
;
1825 struct mddev_dev
*devlist
= conf_get_devs();
1828 rv2
= Assemble(ss
, NULL
,
1836 /* Incase there are stacked devices, we need to go around again */
1838 if (cnt
== 0 && rv
== 0) {
1839 pr_err("No arrays found in config file or automatically\n");
1843 } else if (cnt
== 0 && rv
== 0) {
1844 pr_err("No arrays found in config file\n");
1851 static int misc_scan(char devmode
, struct context
*c
)
1853 /* apply --detail or --wait-clean to
1854 * all devices in /proc/mdstat
1856 struct mdstat_ent
*ms
= mdstat_read(0, 1);
1857 struct mdstat_ent
*e
;
1858 struct map_ent
*map
= NULL
;
1862 for (members
= 0; members
<= 1; members
++) {
1863 for (e
= ms
; e
; e
= e
->next
) {
1867 int member
= e
->metadata_version
&&
1868 strncmp(e
->metadata_version
,
1869 "external:/", 10) == 0;
1870 if (members
!= member
)
1872 me
= map_by_devnm(&map
, e
->devnm
);
1873 if (me
&& me
->path
&& strcmp(me
->path
, "/unknown") != 0)
1875 if (name
== NULL
|| stat(name
, &stb
) != 0)
1876 name
= get_md_name(e
->devnm
);
1879 pr_err("cannot find device file for %s\n",
1884 rv
|= Detail(name
, c
);
1886 rv
|= WaitClean(name
, c
->verbose
);
1896 static int stop_scan(int verbose
)
1898 /* apply --stop to all devices in /proc/mdstat */
1899 /* Due to possible stacking of devices, repeat until
1900 * nothing more can be stopped
1902 int progress
= 1, err
;
1906 struct mdstat_ent
*ms
= mdstat_read(0, 0);
1907 struct mdstat_ent
*e
;
1909 if (!progress
) last
= 1;
1910 progress
= 0; err
= 0;
1911 for (e
= ms
; e
; e
= e
->next
) {
1912 char *name
= get_md_name(e
->devnm
);
1916 pr_err("cannot find device file for %s\n",
1920 mdfd
= open_mddev(name
, 1);
1922 if (Manage_stop(name
, mdfd
, verbose
, !last
))
1932 } while (!last
&& err
);
1938 static int misc_list(struct mddev_dev
*devlist
,
1939 struct mddev_ident
*ident
,
1940 char *dump_directory
,
1941 struct supertype
*ss
, struct context
*c
)
1943 struct mddev_dev
*dv
;
1946 for (dv
= devlist
; dv
; dv
= (rv
& 16) ? NULL
: dv
->next
) {
1949 switch(dv
->disposition
) {
1951 rv
|= Detail(dv
->devname
, c
);
1953 case KillOpt
: /* Zero superblock */
1955 rv
|= Kill(dv
->devname
, ss
, c
->force
, c
->verbose
,0);
1959 rv
|= Kill(dv
->devname
, NULL
, c
->force
, v
, 0);
1966 rv
|= Query(dv
->devname
);
1969 rv
|= ExamineBitmap(dv
->devname
, c
->brief
, ss
);
1972 rv
|= ExamineBadblocks(dv
->devname
, c
->brief
, ss
);
1976 rv
|= Wait(dv
->devname
);
1979 rv
|= WaitClean(dv
->devname
, c
->verbose
);
1982 rv
|= Kill_subarray(dv
->devname
, c
->subarray
, c
->verbose
);
1984 case UpdateSubarray
:
1985 if (c
->update
== NULL
) {
1986 pr_err("-U/--update must be specified with --update-subarray\n");
1990 rv
|= Update_subarray(dv
->devname
, c
->subarray
,
1991 c
->update
, ident
, c
->verbose
);
1994 rv
|= Dump_metadata(dv
->devname
, dump_directory
, c
, ss
);
1997 rv
|= Restore_metadata(dv
->devname
, dump_directory
, c
, ss
,
1998 (dv
== devlist
&& dv
->next
== NULL
));
2001 rv
|= SetAction(dv
->devname
, c
->action
);
2005 if (dv
->devname
[0] != '/')
2006 mdfd
= open_dev(dv
->devname
);
2007 if (dv
->devname
[0] == '/' || mdfd
< 0)
2008 mdfd
= open_mddev(dv
->devname
, 1);
2011 switch(dv
->disposition
) {
2014 rv
|= Manage_run(dv
->devname
, mdfd
, c
);
2017 rv
|= Manage_stop(dv
->devname
, mdfd
, c
->verbose
, 0);
2020 rv
|= Manage_ro(dv
->devname
, mdfd
, 1);
2023 rv
|= Manage_ro(dv
->devname
, mdfd
, -1);
2033 int SetAction(char *dev
, char *action
)
2035 int fd
= open(dev
, O_RDONLY
);
2040 pr_err("Couldn't open %s: %s\n", dev
, strerror(errno
));
2043 retval
= sysfs_init(&mdi
, fd
, NULL
);
2046 pr_err("%s is no an md array\n", dev
);
2050 if (sysfs_set_str(&mdi
, NULL
, "sync_action", action
) < 0) {
2051 pr_err("Count not set action for %s to %s: %s\n",
2052 dev
, action
, strerror(errno
));