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
;
61 char *symlinks
= NULL
;
62 int grow_continue
= 0;
63 /* autof indicates whether and how to create device node.
64 * bottom 3 bits are style. Rest (when shifted) are number of parts
66 * 1 - don't create (no)
67 * 2 - if is_standard, then create (yes)
68 * 3 - create as 'md' - reject is_standard mdp (md)
69 * 4 - create as 'mdp' - reject is_standard md (mdp)
70 * 5 - default to md if not is_standard (md in config file)
71 * 6 - default to mdp if not is_standard (part, or mdp in config file)
74 .require_homehost
= 1,
80 .bitmap_chunk
= UnSet
,
81 .consistency_policy
= CONSISTENCY_POLICY_UNKNOWN
,
84 char sys_hostname
[256];
85 char *mailaddr
= NULL
;
91 int spare_sharing
= 1;
92 struct supertype
*ss
= NULL
;
93 enum flag_mode writemostly
= FlagDefault
;
94 enum flag_mode failfast
= FlagDefault
;
95 char *shortopt
= short_options
;
98 char *remove_path
= NULL
;
99 char *udev_filename
= NULL
;
100 char *dump_directory
= NULL
;
107 srandom(time(0) ^ getpid());
111 ident
.raid_disks
= UnSet
;
112 ident
.super_minor
= UnSet
;
114 ident
.spare_group
= NULL
;
117 ident
.bitmap_fd
= -1;
118 ident
.bitmap_file
= NULL
;
120 ident
.container
= NULL
;
123 if (get_linux_version() < 2006015) {
124 pr_err("This version of mdadm does not support kernels older than 2.6.15\n");
128 while ((option_index
= -1),
129 (opt
= getopt_long(argc
, argv
, shortopt
, long_options
,
130 &option_index
)) != -1) {
132 /* firstly, some mode-independent options */
142 fputs(Version
, stderr
);
145 case 'v': c
.verbose
++;
148 case 'q': c
.verbose
--;
152 if (mode
== ASSEMBLE
|| mode
== BUILD
||
153 mode
== CREATE
|| mode
== GROW
||
154 mode
== INCREMENTAL
|| mode
== MANAGE
)
155 break; /* b means bitmap */
160 case 'Y': c
.export
++;
164 if (strcasecmp(optarg
, "<ignore>") == 0)
165 c
.require_homehost
= 0;
171 /* Silently ignore old option */
177 if (asprintf(&c
.prefer
, "/%s/", optarg
) <= 0)
183 fputs(Usage
, stderr
);
186 /* second, figure out the mode.
187 * Some options force the mode. Others
188 * set the mode if it isn't already
194 shortopt
= short_bitmap_options
;
206 case ReAdd
: /* re-add */
210 shortopt
= short_bitmap_options
;
214 case 'A': newmode
= ASSEMBLE
;
215 shortopt
= short_bitmap_auto_options
;
217 case 'B': newmode
= BUILD
;
218 shortopt
= short_bitmap_auto_options
;
220 case 'C': newmode
= CREATE
;
221 shortopt
= short_bitmap_auto_options
;
223 case 'F': newmode
= MONITOR
;
225 case 'G': newmode
= GROW
;
226 shortopt
= short_bitmap_options
;
228 case 'I': newmode
= INCREMENTAL
;
229 shortopt
= short_bitmap_auto_options
;
232 newmode
= AUTODETECT
;
267 if (mode
&& newmode
== mode
) {
268 /* everybody happy ! */
269 } else if (mode
&& newmode
!= mode
) {
272 if (option_index
>= 0)
273 fprintf(stderr
, "--%s", long_options
[option_index
].name
);
275 fprintf(stderr
, "-%c", opt
);
276 fprintf(stderr
, " would set mdadm mode to \"%s\", but it is already set to \"%s\".\n",
277 map_num(modes
, newmode
),
278 map_num(modes
, mode
));
280 } else if (!mode
&& newmode
) {
282 if (mode
== MISC
&& devs_found
) {
283 pr_err("No action given for %s in --misc mode\n",
285 cont_err("Action options must come before device names\n");
289 /* special case of -c --help */
290 if ((opt
== 'c' || opt
== ConfigFile
) &&
291 (strncmp(optarg
, "--h", 3) == 0 ||
292 strncmp(optarg
, "-h", 2) == 0)) {
293 fputs(Help_config
, stdout
);
297 /* If first option is a device, don't force the mode yet */
299 if (devs_found
== 0) {
300 dv
= xmalloc(sizeof(*dv
));
301 dv
->devname
= optarg
;
302 dv
->disposition
= devmode
;
303 dv
->writemostly
= writemostly
;
304 dv
->failfast
= failfast
;
308 devlistend
= &dv
->next
;
313 /* No mode yet, and this is the second device ... */
314 pr_err("An option must be given to set the mode before a second device\n"
315 " (%s) is listed\n", optarg
);
318 if (option_index
>= 0)
319 pr_err("--%s", long_options
[option_index
].name
);
322 fprintf(stderr
, " does not set the mode, and so cannot be the first option.\n");
326 /* if we just set the mode, then done */
340 /* an undecorated option - must be a device name.
343 if (devs_found
> 0 && devmode
== DetailPlatform
) {
344 pr_err("controller may only be specified once. %s ignored\n",
349 if (devs_found
> 0 && mode
== MANAGE
&& !devmode
) {
350 pr_err("Must give one of -a/-r/-f for subsequent devices at %s\n", optarg
);
353 if (devs_found
> 0 && mode
== GROW
&& !devmode
) {
354 pr_err("Must give -a/--add for devices to add: %s\n", optarg
);
357 dv
= xmalloc(sizeof(*dv
));
358 dv
->devname
= optarg
;
359 dv
->disposition
= devmode
;
360 dv
->writemostly
= writemostly
;
361 dv
->failfast
= failfast
;
365 devlistend
= &dv
->next
;
371 /* We've got a mode, and opt is now something else which
372 * could depend on the mode */
373 #define O(a,b) ((a<<16)|b)
374 switch (O(mode
,opt
)) {
376 case O(GROW
,ChunkSize
):
378 case O(CREATE
,ChunkSize
):
379 case O(BUILD
,'c'): /* chunk or rounding */
380 case O(BUILD
,ChunkSize
): /* chunk or rounding */
382 pr_err("chunk/rounding may only be specified once. Second value is %s.\n", optarg
);
385 s
.chunk
= parse_size(optarg
);
386 if (s
.chunk
== INVALID_SECTORS
||
387 s
.chunk
< 8 || (s
.chunk
&1)) {
388 pr_err("invalid chunk/rounding value: %s\n",
392 /* Convert sectors to K */
396 case O(INCREMENTAL
, 'e'):
398 case O(ASSEMBLE
,'e'):
399 case O(MISC
,'e'): /* set metadata (superblock) information */
401 pr_err("metadata information already given\n");
404 for(i
= 0; !ss
&& superlist
[i
]; i
++)
405 ss
= superlist
[i
]->match_metadata_desc(optarg
);
408 pr_err("unrecognised metadata identifier: %s\n", optarg
);
414 case O(MANAGE
,WriteMostly
):
416 case O(BUILD
,WriteMostly
):
418 case O(CREATE
,WriteMostly
):
419 /* set write-mostly for following devices */
420 writemostly
= FlagSet
;
424 /* clear write-mostly for following devices */
425 writemostly
= FlagClear
;
428 case O(MANAGE
,FailFast
):
429 case O(CREATE
,FailFast
):
432 case O(MANAGE
,NoFailFast
):
433 failfast
= FlagClear
;
438 case O(BUILD
,'z'): /* size */
440 pr_err("size may only be specified once. Second value is %s.\n", optarg
);
443 if (strcmp(optarg
, "max") == 0)
446 s
.size
= parse_size(optarg
);
447 if (s
.size
== INVALID_SECTORS
|| s
.size
< 8) {
448 pr_err("invalid size: %s\n", optarg
);
451 /* convert sectors to K */
456 case O(GROW
,'Z'): /* array size */
457 if (array_size
> 0) {
458 pr_err("array-size may only be specified once. Second value is %s.\n", optarg
);
461 if (strcmp(optarg
, "max") == 0)
462 array_size
= MAX_SIZE
;
464 array_size
= parse_size(optarg
);
465 if (array_size
== 0 ||
466 array_size
== INVALID_SECTORS
) {
467 pr_err("invalid array size: %s\n",
474 case O(CREATE
,DataOffset
):
475 case O(GROW
,DataOffset
):
476 if (data_offset
!= INVALID_SECTORS
) {
477 pr_err("data-offset may only be specified one. Second value is %s.\n", optarg
);
480 if (mode
== CREATE
&& strcmp(optarg
, "variable") == 0)
481 data_offset
= VARIABLE_OFFSET
;
483 data_offset
= parse_size(optarg
);
484 if (data_offset
== INVALID_SECTORS
) {
485 pr_err("invalid data-offset: %s\n",
493 case O(BUILD
,'l'): /* set raid level*/
494 if (s
.level
!= UnSet
) {
495 pr_err("raid level may only be set once. Second value is %s.\n", optarg
);
498 s
.level
= map_name(pers
, optarg
);
499 if (s
.level
== UnSet
) {
500 pr_err("invalid raid level: %s\n",
504 if (s
.level
!= 0 && s
.level
!= LEVEL_LINEAR
&&
505 s
.level
!= 1 && s
.level
!= LEVEL_MULTIPATH
&&
506 s
.level
!= LEVEL_FAULTY
&& s
.level
!= 10 &&
508 pr_err("Raid level %s not permitted with --build.\n",
512 if (s
.sparedisks
> 0 && s
.level
< 1 && s
.level
>= -1) {
513 pr_err("raid level %s is incompatible with spare-devices setting.\n",
517 ident
.level
= s
.level
;
520 case O(GROW
, 'p'): /* new layout */
521 case O(GROW
, Layout
):
523 pr_err("layout may only be sent once. Second value was %s\n", optarg
);
526 s
.layout_str
= optarg
;
527 /* 'Grow' will parse the value */
530 case O(CREATE
,'p'): /* raid5 layout */
531 case O(CREATE
,Layout
):
532 case O(BUILD
,'p'): /* faulty layout */
533 case O(BUILD
,Layout
):
534 if (s
.layout
!= UnSet
) {
535 pr_err("layout may only be sent once. Second value was %s\n", optarg
);
540 pr_err("layout not meaningful for %s arrays.\n",
541 map_num(pers
, s
.level
));
544 pr_err("raid level must be given before layout.\n");
548 s
.layout
= map_name(r5layout
, optarg
);
549 if (s
.layout
== UnSet
) {
550 pr_err("layout %s not understood for raid5.\n",
556 s
.layout
= map_name(r6layout
, optarg
);
557 if (s
.layout
== UnSet
) {
558 pr_err("layout %s not understood for raid6.\n",
565 s
.layout
= parse_layout_10(optarg
);
567 pr_err("layout for raid10 must be 'nNN', 'oNN' or 'fNN' where NN is a number, not %s\n", optarg
);
575 s
.layout
= parse_layout_faulty(optarg
);
576 if (s
.layout
== -1) {
577 pr_err("layout %s not understood for faulty.\n",
585 case O(CREATE
,AssumeClean
):
586 case O(BUILD
,AssumeClean
): /* assume clean */
587 case O(GROW
,AssumeClean
):
593 case O(BUILD
,'n'): /* number of raid disks */
595 pr_err("raid-devices set twice: %d and %s\n",
596 s
.raiddisks
, optarg
);
599 s
.raiddisks
= parse_num(optarg
);
600 if (s
.raiddisks
<= 0) {
601 pr_err("invalid number of raid devices: %s\n",
605 ident
.raid_disks
= s
.raiddisks
;
607 case O(ASSEMBLE
, Nodes
):
609 case O(CREATE
, Nodes
):
610 c
.nodes
= parse_num(optarg
);
612 pr_err("clustered array needs two nodes at least: %s\n",
617 case O(CREATE
, ClusterName
):
618 case O(ASSEMBLE
, ClusterName
):
619 c
.homecluster
= optarg
;
620 if (strlen(c
.homecluster
) > 64) {
621 pr_err("Cluster name too big.\n");
625 case O(CREATE
,'x'): /* number of spare (eXtra) disks */
627 pr_err("spare-devices set twice: %d and %s\n",
628 s
.sparedisks
, optarg
);
631 if (s
.level
!= UnSet
&& s
.level
<= 0 && s
.level
>= -1) {
632 pr_err("spare-devices setting is incompatible with raid level %d\n",
636 s
.sparedisks
= parse_num(optarg
);
637 if (s
.sparedisks
< 0) {
638 pr_err("invalid number of spare-devices: %s\n",
648 case O(INCREMENTAL
,'a'):
649 case O(INCREMENTAL
,Auto
):
650 case O(ASSEMBLE
,'a'):
651 case O(ASSEMBLE
,Auto
): /* auto-creation of device node */
652 c
.autof
= parse_auto(optarg
, "--auto flag", 0);
655 case O(CREATE
,Symlinks
):
656 case O(BUILD
,Symlinks
):
657 case O(ASSEMBLE
,Symlinks
): /* auto creation of symlinks in /dev to /dev/md */
661 case O(BUILD
,'f'): /* force honouring '-n 1' */
662 case O(BUILD
,Force
): /* force honouring '-n 1' */
663 case O(GROW
,'f'): /* ditto */
664 case O(GROW
,Force
): /* ditto */
665 case O(CREATE
,'f'): /* force honouring of device list */
666 case O(CREATE
,Force
): /* force honouring of device list */
667 case O(ASSEMBLE
,'f'): /* force assembly */
668 case O(ASSEMBLE
,Force
): /* force assembly */
669 case O(MISC
,'f'): /* force zero */
670 case O(MISC
,Force
): /* force zero */
671 case O(MANAGE
,Force
): /* add device which is too large */
674 /* now for the Assemble options */
675 case O(ASSEMBLE
, FreezeReshape
): /* Freeze reshape during
677 case O(INCREMENTAL
, FreezeReshape
):
678 c
.freeze_reshape
= 1;
680 case O(CREATE
,'u'): /* uuid of array */
681 case O(ASSEMBLE
,'u'): /* uuid of array */
682 if (ident
.uuid_set
) {
683 pr_err("uuid cannot be set twice. Second value %s.\n", optarg
);
686 if (parse_uuid(optarg
, ident
.uuid
))
689 pr_err("Bad uuid: %s\n", optarg
);
695 case O(ASSEMBLE
,'N'):
698 pr_err("name cannot be set twice. Second value %s.\n", optarg
);
701 if (mode
== MISC
&& !c
.subarray
) {
702 pr_err("-N/--name only valid with --update-subarray in misc mode\n");
705 if (strlen(optarg
) > 32) {
706 pr_err("name '%s' is too long, 32 chars max.\n",
710 strcpy(ident
.name
, optarg
);
713 case O(ASSEMBLE
,'m'): /* super-minor for array */
714 case O(ASSEMBLE
,SuperMinor
):
715 if (ident
.super_minor
!= UnSet
) {
716 pr_err("super-minor cannot be set twice. Second value: %s.\n", optarg
);
719 if (strcmp(optarg
, "dev") == 0)
720 ident
.super_minor
= -2;
722 ident
.super_minor
= parse_num(optarg
);
723 if (ident
.super_minor
< 0) {
724 pr_err("Bad super-minor number: %s.\n", optarg
);
730 case O(ASSEMBLE
,'o'):
736 case O(ASSEMBLE
,'U'): /* update the superblock */
739 pr_err("Can only update one aspect of superblock, both %s and %s given.\n",
743 if (mode
== MISC
&& !c
.subarray
) {
744 pr_err("Only subarrays can be updated in misc mode\n");
748 if (strcmp(c
.update
, "sparc2.2") == 0)
750 if (strcmp(c
.update
, "super-minor") == 0)
752 if (strcmp(c
.update
, "summaries") == 0)
754 if (strcmp(c
.update
, "resync") == 0)
756 if (strcmp(c
.update
, "uuid") == 0)
758 if (strcmp(c
.update
, "name") == 0)
760 if (strcmp(c
.update
, "homehost") == 0)
762 if (strcmp(c
.update
, "home-cluster") == 0)
764 if (strcmp(c
.update
, "nodes") == 0)
766 if (strcmp(c
.update
, "devicesize") == 0)
768 if (strcmp(c
.update
, "no-bitmap") == 0)
770 if (strcmp(c
.update
, "bbl") == 0)
772 if (strcmp(c
.update
, "no-bbl") == 0)
774 if (strcmp(c
.update
, "force-no-bbl") == 0)
776 if (strcmp(c
.update
, "ppl") == 0)
778 if (strcmp(c
.update
, "no-ppl") == 0)
780 if (strcmp(c
.update
, "metadata") == 0)
782 if (strcmp(c
.update
, "revert-reshape") == 0)
784 if (strcmp(c
.update
, "byteorder") == 0) {
786 pr_err("must not set metadata type with --update=byteorder.\n");
789 for(i
= 0; !ss
&& superlist
[i
]; i
++)
790 ss
= superlist
[i
]->match_metadata_desc(
793 pr_err("INTERNAL ERROR cannot find 0.swap\n");
799 if (strcmp(c
.update
,"?") == 0 ||
800 strcmp(c
.update
, "help") == 0) {
802 fprintf(outf
, "%s: ", Name
);
806 "%s: '--update=%s' is invalid. ",
809 fprintf(outf
, "Valid --update options are:\n"
810 " 'sparc2.2', 'super-minor', 'uuid', 'name', 'nodes', 'resync',\n"
811 " 'summaries', 'homehost', 'home-cluster', 'byteorder', 'devicesize',\n"
812 " 'no-bitmap', 'metadata', 'revert-reshape'\n"
813 " 'bbl', 'no-bbl', 'force-no-bbl', 'ppl', 'no-ppl'\n"
815 exit(outf
== stdout
? 0 : 2);
818 /* update=devicesize is allowed with --re-add */
819 if (devmode
!= 'A') {
820 pr_err("--update in Manage mode only allowed with --re-add.\n");
824 pr_err("Can only update one aspect of superblock, both %s and %s given.\n",
829 if (strcmp(c
.update
, "devicesize") != 0 &&
830 strcmp(c
.update
, "bbl") != 0 &&
831 strcmp(c
.update
, "force-no-bbl") != 0 &&
832 strcmp(c
.update
, "no-bbl") != 0) {
833 pr_err("only 'devicesize', 'bbl', 'no-bbl', and 'force-no-bbl' can be updated with --re-add\n");
838 case O(INCREMENTAL
,NoDegraded
):
839 pr_err("--no-degraded is deprecated in Incremental mode\n");
840 case O(ASSEMBLE
,NoDegraded
): /* --no-degraded */
841 c
.runstop
= -1; /* --stop isn't allowed for --assemble,
842 * so we overload slightly */
845 case O(ASSEMBLE
,'c'):
846 case O(ASSEMBLE
,ConfigFile
):
847 case O(INCREMENTAL
, 'c'):
848 case O(INCREMENTAL
, ConfigFile
):
850 case O(MISC
, ConfigFile
):
852 case O(MONITOR
,ConfigFile
):
853 case O(CREATE
,ConfigFile
):
855 pr_err("configfile cannot be set twice. Second value is %s.\n", optarg
);
859 set_conffile(configfile
);
860 /* FIXME possibly check that config file exists. Even parse it */
862 case O(ASSEMBLE
,'s'): /* scan */
865 case O(INCREMENTAL
,'s'):
869 case O(MONITOR
,'m'): /* mail address */
870 case O(MONITOR
,EMail
):
872 pr_err("only specify one mailaddress. %s ignored.\n",
878 case O(MONITOR
,'p'): /* alert program */
879 case O(MONITOR
,ProgramOpt
): /* alert program */
881 pr_err("only specify one alter program. %s ignored.\n",
887 case O(MONITOR
,'r'): /* rebuild increments */
888 case O(MONITOR
,Increment
):
889 increments
= atoi(optarg
);
890 if (increments
> 99 || increments
< 1) {
891 pr_err("please specify positive integer between 1 and 99 as rebuild increments.\n");
896 case O(MONITOR
,'d'): /* delay in seconds */
898 case O(BUILD
,'d'): /* delay for bitmap updates */
901 pr_err("only specify delay once. %s ignored.\n",
904 c
.delay
= parse_num(optarg
);
906 pr_err("invalid delay: %s\n",
912 case O(MONITOR
,'f'): /* daemonise */
913 case O(MONITOR
,Fork
):
916 case O(MONITOR
,'i'): /* pid */
918 pr_err("only specify one pid file. %s ignored.\n",
923 case O(MONITOR
,'1'): /* oneshot */
927 case O(MONITOR
,'t'): /* test */
930 case O(MONITOR
,'y'): /* log messages to syslog */
931 openlog("mdadm", LOG_PID
, SYSLOG_FACILITY
);
934 case O(MONITOR
, NoSharing
):
938 /* now the general management options. Some are applicable
939 * to other modes. None have arguments.
944 case O(MANAGE
,Add
): /* add a drive */
947 case O(MANAGE
,AddSpare
): /* add drive - never re-add */
950 case O(MANAGE
,AddJournal
): /* add journal */
951 if (s
.journaldisks
&& (s
.level
< 4 || s
.level
> 6)) {
952 pr_err("--add-journal is only supported for RAID level 4/5/6.\n");
957 case O(MANAGE
,ReAdd
):
960 case O(MANAGE
,'r'): /* remove a drive */
961 case O(MANAGE
,Remove
):
964 case O(MANAGE
,'f'): /* set faulty */
966 case O(INCREMENTAL
,'f'):
967 case O(INCREMENTAL
,Remove
):
968 case O(INCREMENTAL
,Fail
): /* r for incremental is taken, use f
969 * even though we will both fail and
970 * remove the device */
973 case O(MANAGE
, ClusterConfirm
):
976 case O(MANAGE
,Replace
):
977 /* Mark these devices for replacement */
981 /* These are the replacements to use */
982 if (devmode
!= 'R') {
983 pr_err("--with must follow --replace\n");
988 case O(INCREMENTAL
,'R'):
990 case O(ASSEMBLE
,'R'):
992 case O(CREATE
,'R'): /* Run the array */
994 pr_err("Cannot both Stop and Run an array\n");
1000 if (c
.runstop
> 0) {
1001 pr_err("Cannot both Run and Stop an array\n");
1013 case O(MISC
,KillOpt
):
1017 case O(MISC
, ExamineBB
):
1021 case O(MISC
, WaitOpt
):
1022 case O(MISC
, Waitclean
):
1023 case O(MISC
, DetailPlatform
):
1024 case O(MISC
, KillSubarray
):
1025 case O(MISC
, UpdateSubarray
):
1027 case O(MISC
, Restore
):
1028 case O(MISC
,Action
):
1029 if (opt
== KillSubarray
|| opt
== UpdateSubarray
) {
1031 pr_err("subarray can only be specified once\n");
1034 c
.subarray
= optarg
;
1036 if (opt
== Action
) {
1038 pr_err("Only one --action can be specified\n");
1041 if (strcmp(optarg
, "idle") == 0 ||
1042 strcmp(optarg
, "frozen") == 0 ||
1043 strcmp(optarg
, "check") == 0 ||
1044 strcmp(optarg
, "repair") == 0)
1047 pr_err("action must be one of idle, frozen, check, repair\n");
1051 if (devmode
&& devmode
!= opt
&&
1053 (opt
== 'E' && devmode
!= 'Q'))) {
1054 pr_err("--examine/-E cannot be given with ");
1055 if (devmode
== 'E') {
1056 if (option_index
>= 0)
1057 fprintf(stderr
, "--%s\n",
1058 long_options
[option_index
].name
);
1060 fprintf(stderr
, "-%c\n", opt
);
1061 } else if (isalpha(devmode
))
1062 fprintf(stderr
, "-%c\n", devmode
);
1064 fprintf(stderr
, "previous option\n");
1068 if (opt
== Dump
|| opt
== Restore
) {
1069 if (dump_directory
!= NULL
) {
1070 pr_err("dump/restore directory specified twice: %s and %s\n",
1071 dump_directory
, optarg
);
1074 dump_directory
= optarg
;
1077 case O(MISC
, UdevRules
):
1078 if (devmode
&& devmode
!= opt
) {
1079 pr_err("--udev-rules must be the only option.\n");
1082 pr_err("only specify one udev rule filename. %s ignored.\n",
1085 udev_filename
= optarg
;
1093 case O(MISC
, Sparc22
):
1094 if (devmode
!= 'E') {
1095 pr_err("--sparc2.2 only allowed with --examine\n");
1101 case O(ASSEMBLE
,'b'): /* here we simply set the bitmap file */
1102 case O(ASSEMBLE
,Bitmap
):
1104 pr_err("bitmap file needed with -b in --assemble mode\n");
1107 if (strcmp(optarg
, "internal") == 0 ||
1108 strcmp(optarg
, "clustered") == 0) {
1109 pr_err("no need to specify --bitmap when assembling"
1110 " arrays with internal or clustered bitmap\n");
1113 bitmap_fd
= open(optarg
, O_RDWR
);
1114 if (!*optarg
|| bitmap_fd
< 0) {
1115 pr_err("cannot open bitmap file %s: %s\n", optarg
, strerror(errno
));
1118 ident
.bitmap_fd
= bitmap_fd
; /* for Assemble */
1121 case O(ASSEMBLE
, BackupFile
):
1122 case O(GROW
, BackupFile
):
1123 /* Specify a file into which grow might place a backup,
1124 * or from which assemble might recover a backup
1126 if (c
.backup_file
) {
1127 pr_err("backup file already specified, rejecting %s\n", optarg
);
1130 c
.backup_file
= optarg
;
1133 case O(GROW
, Continue
):
1134 /* Continue interrupted grow
1138 case O(ASSEMBLE
, InvalidBackup
):
1139 /* Acknowledge that the backupfile is invalid, but ask
1140 * to continue anyway
1142 c
.invalid_backup
= 1;
1146 case O(BUILD
,Bitmap
):
1148 case O(CREATE
,Bitmap
): /* here we create the bitmap */
1150 case O(GROW
,Bitmap
):
1151 if (s
.bitmap_file
) {
1152 pr_err("bitmap cannot be set twice. Second value: %s.\n", optarg
);
1155 if (strcmp(optarg
, "internal") == 0 ||
1156 strcmp(optarg
, "none") == 0 ||
1157 strchr(optarg
, '/') != NULL
) {
1158 s
.bitmap_file
= optarg
;
1161 if (strcmp(optarg
, "clustered") == 0) {
1162 s
.bitmap_file
= optarg
;
1163 /* Set the default number of cluster nodes
1164 * to 4 if not already set by user
1171 pr_err("bitmap file must contain a '/', or be 'internal', or be 'clustered', or 'none'\n"
1172 " not '%s'\n", optarg
);
1175 case O(GROW
,BitmapChunk
):
1176 case O(BUILD
,BitmapChunk
):
1177 case O(CREATE
,BitmapChunk
): /* bitmap chunksize */
1178 s
.bitmap_chunk
= parse_size(optarg
);
1179 if (s
.bitmap_chunk
== 0 ||
1180 s
.bitmap_chunk
== INVALID_SECTORS
||
1181 s
.bitmap_chunk
& (s
.bitmap_chunk
- 1)) {
1182 pr_err("invalid bitmap chunksize: %s\n",
1186 s
.bitmap_chunk
= s
.bitmap_chunk
* 512;
1189 case O(GROW
, WriteBehind
):
1190 case O(BUILD
, WriteBehind
):
1191 case O(CREATE
, WriteBehind
): /* write-behind mode */
1192 s
.write_behind
= DEFAULT_MAX_WRITE_BEHIND
;
1194 s
.write_behind
= parse_num(optarg
);
1195 if (s
.write_behind
< 0 ||
1196 s
.write_behind
> 16383) {
1197 pr_err("Invalid value for maximum outstanding write-behind writes: %s.\n\tMust be between 0 and 16383.\n", optarg
);
1203 case O(INCREMENTAL
, 'r'):
1204 case O(INCREMENTAL
, RebuildMapOpt
):
1207 case O(INCREMENTAL
, IncrementalPath
):
1208 remove_path
= optarg
;
1210 case O(CREATE
, WriteJournal
):
1211 if (s
.journaldisks
) {
1212 pr_err("Please specify only one journal device for the array.\n");
1213 pr_err("Ignoring --write-journal %s...\n", optarg
);
1216 dv
= xmalloc(sizeof(*dv
));
1217 dv
->devname
= optarg
;
1218 dv
->disposition
= 'j'; /* WriteJournal */
1222 devlistend
= &dv
->next
;
1227 case O(CREATE
, 'k'):
1229 s
.consistency_policy
= map_name(consistency_policies
,
1231 if (s
.consistency_policy
< CONSISTENCY_POLICY_RESYNC
) {
1232 pr_err("Invalid consistency policy: %s\n",
1238 /* We have now processed all the valid options. Anything else is
1241 if (option_index
> 0)
1242 pr_err(":option --%s not valid in %s mode\n",
1243 long_options
[option_index
].name
,
1244 map_num(modes
, mode
));
1246 pr_err("option -%c not valid in %s mode\n",
1247 opt
, map_num(modes
, mode
));
1254 if (print_help
== 2)
1255 help_text
= OptionHelp
;
1257 help_text
= mode_help
[mode
];
1258 if (help_text
== NULL
)
1260 fputs(help_text
,stdout
);
1264 if (s
.journaldisks
) {
1265 if (s
.level
< 4 || s
.level
> 6) {
1266 pr_err("--write-journal is only supported for RAID level 4/5/6.\n");
1269 if (s
.consistency_policy
!= CONSISTENCY_POLICY_UNKNOWN
&&
1270 s
.consistency_policy
!= CONSISTENCY_POLICY_JOURNAL
) {
1271 pr_err("--write-journal is not supported with consistency policy: %s\n",
1272 map_num(consistency_policies
, s
.consistency_policy
));
1277 if (mode
== CREATE
&&
1278 s
.consistency_policy
!= CONSISTENCY_POLICY_UNKNOWN
) {
1280 pr_err("--consistency-policy not meaningful with level %s.\n",
1281 map_num(pers
, s
.level
));
1283 } else if (s
.consistency_policy
== CONSISTENCY_POLICY_JOURNAL
&&
1285 pr_err("--write-journal is required for consistency policy: %s\n",
1286 map_num(consistency_policies
, s
.consistency_policy
));
1288 } else if (s
.consistency_policy
== CONSISTENCY_POLICY_PPL
&&
1290 pr_err("PPL consistency policy is only supported for RAID level 5.\n");
1292 } else if (s
.consistency_policy
== CONSISTENCY_POLICY_BITMAP
&&
1294 strcmp(s
.bitmap_file
, "none") == 0)) {
1295 pr_err("--bitmap is required for consistency policy: %s\n",
1296 map_num(consistency_policies
, s
.consistency_policy
));
1298 } else if (s
.bitmap_file
&&
1299 strcmp(s
.bitmap_file
, "none") != 0 &&
1300 s
.consistency_policy
!= CONSISTENCY_POLICY_BITMAP
&&
1301 s
.consistency_policy
!= CONSISTENCY_POLICY_JOURNAL
) {
1302 pr_err("--bitmap is not compatible with consistency policy: %s\n",
1303 map_num(consistency_policies
, s
.consistency_policy
));
1308 if (!mode
&& devs_found
) {
1311 if (devlist
->disposition
== 0)
1312 devlist
->disposition
= devmode
;
1315 fputs(Usage
, stderr
);
1320 struct createinfo
*ci
= conf_get_create_info();
1322 if (strcasecmp(symlinks
, "yes") == 0)
1324 else if (strcasecmp(symlinks
, "no") == 0)
1327 pr_err("option --symlinks must be 'no' or 'yes'\n");
1331 /* Ok, got the option parsing out of the way
1332 * hopefully it's mostly right but there might be some stuff
1335 * That is mostly checked in the per-mode stuff but...
1337 * For @,B,C and A without -s, the first device listed must be
1338 * an md device. We check that here and open it.
1341 if (mode
== MANAGE
|| mode
== BUILD
|| mode
== CREATE
||
1342 mode
== GROW
|| (mode
== ASSEMBLE
&& ! c
.scan
)) {
1343 if (devs_found
< 1) {
1344 pr_err("an md device must be given in this mode\n");
1347 if ((int)ident
.super_minor
== -2 && c
.autof
) {
1348 pr_err("--super-minor=dev is incompatible with --auto\n");
1351 if (mode
== MANAGE
|| mode
== GROW
) {
1352 mdfd
= open_mddev(devlist
->devname
, 1);
1356 /* non-existent device is OK */
1357 mdfd
= open_mddev(devlist
->devname
, 0);
1359 pr_err("device %s exists but is not an md array.\n", devlist
->devname
);
1362 if ((int)ident
.super_minor
== -2) {
1365 pr_err("--super-minor=dev given, and listed device %s doesn't exist.\n",
1370 ident
.super_minor
= minor(stb
.st_rdev
);
1372 if (mdfd
>= 0 && mode
!= MANAGE
&& mode
!= GROW
) {
1373 /* We don't really want this open yet, we just might
1374 * have wanted to check some things
1382 if (s
.raiddisks
== 1 && !c
.force
&& s
.level
!= LEVEL_FAULTY
) {
1383 pr_err("'1' is an unusual number of drives for an array, so it is probably\n"
1384 " a mistake. If you really mean it you will need to specify --force before\n"
1385 " setting the number of drives.\n");
1390 if (c
.homehost
== NULL
&& c
.require_homehost
)
1391 c
.homehost
= conf_get_homehost(&c
.require_homehost
);
1392 if (c
.homehost
== NULL
|| strcasecmp(c
.homehost
, "<system>") == 0) {
1393 if (gethostname(sys_hostname
, sizeof(sys_hostname
)) == 0) {
1394 sys_hostname
[sizeof(sys_hostname
)-1] = 0;
1395 c
.homehost
= sys_hostname
;
1399 (!c
.homehost
[0] || strcasecmp(c
.homehost
, "<none>") == 0)) {
1401 c
.require_homehost
= 0;
1406 set_hooks(); /* set hooks from libs */
1408 if (c
.homecluster
== NULL
&& (c
.nodes
> 0)) {
1409 c
.homecluster
= conf_get_homecluster();
1410 if (c
.homecluster
== NULL
)
1411 rv
= get_cluster_name(&c
.homecluster
);
1413 pr_err("The md can't get cluster name\n");
1418 if (c
.backup_file
&& data_offset
!= INVALID_SECTORS
) {
1419 pr_err("--backup-file and --data-offset are incompatible\n");
1423 if ((mode
== MISC
&& devmode
== 'E') ||
1424 (mode
== MONITOR
&& spare_sharing
== 0))
1425 /* Anyone may try this */;
1426 else if (geteuid() != 0) {
1427 pr_err("must be super-user to perform this action\n");
1431 ident
.autof
= c
.autof
;
1433 if (c
.scan
&& c
.verbose
< 2)
1434 /* --scan implied --brief unless -vv */
1439 /* readonly, add/remove, readwrite, runstop */
1441 rv
= Manage_ro(devlist
->devname
, mdfd
, c
.readonly
);
1442 if (!rv
&& devs_found
>1)
1443 rv
= Manage_subdevs(devlist
->devname
, mdfd
,
1444 devlist
->next
, c
.verbose
, c
.test
,
1446 if (!rv
&& c
.readonly
< 0)
1447 rv
= Manage_ro(devlist
->devname
, mdfd
, c
.readonly
);
1448 if (!rv
&& c
.runstop
> 0)
1449 rv
= Manage_run(devlist
->devname
, mdfd
, &c
);
1450 if (!rv
&& c
.runstop
< 0)
1451 rv
= Manage_stop(devlist
->devname
, mdfd
, c
.verbose
, 0);
1454 if (devs_found
== 1 && ident
.uuid_set
== 0 &&
1455 ident
.super_minor
== UnSet
&& ident
.name
[0] == 0 &&
1457 /* Only a device has been given, so get details from config file */
1458 struct mddev_ident
*array_ident
= conf_get_ident(devlist
->devname
);
1459 if (array_ident
== NULL
) {
1460 pr_err("%s not identified in config file.\n",
1466 if (array_ident
->autof
== 0)
1467 array_ident
->autof
= c
.autof
;
1468 rv
|= Assemble(ss
, devlist
->devname
, array_ident
,
1472 rv
= Assemble(ss
, devlist
->devname
, &ident
,
1474 else if (devs_found
> 0) {
1475 if (c
.update
&& devs_found
> 1) {
1476 pr_err("can only update a single array at a time\n");
1479 if (c
.backup_file
&& devs_found
> 1) {
1480 pr_err("can only assemble a single array when providing a backup file.\n");
1483 for (dv
= devlist
; dv
; dv
= dv
->next
) {
1484 struct mddev_ident
*array_ident
= conf_get_ident(dv
->devname
);
1485 if (array_ident
== NULL
) {
1486 pr_err("%s not identified in config file.\n",
1491 if (array_ident
->autof
== 0)
1492 array_ident
->autof
= c
.autof
;
1493 rv
|= Assemble(ss
, dv
->devname
, array_ident
,
1498 pr_err("--update not meaningful with a --scan assembly.\n");
1501 if (c
.backup_file
) {
1502 pr_err("--backup_file not meaningful with a --scan assembly.\n");
1505 rv
= scan_assemble(ss
, &c
, &ident
);
1511 c
.delay
= DEFAULT_BITMAP_DELAY
;
1512 if (s
.write_behind
&& !s
.bitmap_file
) {
1513 pr_err("write-behind mode requires a bitmap.\n");
1517 if (s
.raiddisks
== 0) {
1518 pr_err("no raid-devices specified.\n");
1523 if (s
.bitmap_file
) {
1524 if (strcmp(s
.bitmap_file
, "internal") == 0 ||
1525 strcmp(s
.bitmap_file
, "clustered") == 0) {
1526 pr_err("'internal' and 'clustered' bitmaps not supported with --build\n");
1531 rv
= Build(devlist
->devname
, devlist
->next
, &s
, &c
);
1535 c
.delay
= DEFAULT_BITMAP_DELAY
;
1538 if (!s
.bitmap_file
||
1539 strcmp(s
.bitmap_file
, "clustered") != 0) {
1540 pr_err("--nodes argument only compatible with --bitmap=clustered\n");
1546 pr_err("--bitmap=clustered is currently supported with RAID mirror only\n");
1552 if (s
.write_behind
&& !s
.bitmap_file
) {
1553 pr_err("write-behind mode requires a bitmap.\n");
1557 if (s
.raiddisks
== 0) {
1558 pr_err("no raid-devices specified.\n");
1563 rv
= Create(ss
, devlist
->devname
,
1564 ident
.name
, ident
.uuid_set
? ident
.uuid
: NULL
,
1565 devs_found
-1, devlist
->next
,
1566 &s
, &c
, data_offset
);
1569 if (devmode
== 'E') {
1570 if (devlist
== NULL
&& !c
.scan
) {
1571 pr_err("No devices to examine\n");
1574 if (devlist
== NULL
)
1575 devlist
= conf_get_devs();
1576 if (devlist
== NULL
) {
1577 pr_err("No devices listed in %s\n", configfile
?configfile
:DefaultConfFile
);
1580 rv
= Examine(devlist
, &c
, ss
);
1581 } else if (devmode
== DetailPlatform
) {
1582 rv
= Detail_Platform(ss
? ss
->ss
: NULL
, ss
? c
.scan
: 1,
1583 c
.verbose
, c
.export
,
1584 devlist
? devlist
->devname
: NULL
);
1585 } else if (devlist
== NULL
) {
1586 if (devmode
== 'S' && c
.scan
)
1587 rv
= stop_scan(c
.verbose
);
1588 else if ((devmode
== 'D' || devmode
== Waitclean
) &&
1590 rv
= misc_scan(devmode
, &c
);
1591 else if (devmode
== UdevRules
)
1592 rv
= Write_rules(udev_filename
);
1594 pr_err("No devices given.\n");
1598 rv
= misc_list(devlist
, &ident
, dump_directory
, ss
, &c
);
1601 if (!devlist
&& !c
.scan
) {
1602 pr_err("Cannot monitor: need --scan or at least one device\n");
1606 if (pidfile
&& !daemonise
) {
1607 pr_err("Cannot write a pid file when not in daemon mode\n");
1612 if (get_linux_version() > 2006016)
1613 /* mdstat responds to poll */
1618 rv
= Monitor(devlist
, mailaddr
, program
,
1619 &c
, daemonise
, oneshot
,
1620 dosyslog
, pidfile
, increments
,
1625 if (array_size
> 0) {
1626 /* alway impose array size first, independent of
1628 * Do not allow level or raid_disks changes at the
1629 * same time as that can be irreversibly destructive.
1633 if (s
.raiddisks
|| s
.level
!= UnSet
) {
1634 pr_err("cannot change array size in same operation as changing raiddisks or level.\n"
1635 " Change size first, then check that data is still intact.\n");
1639 if (sysfs_init(&sra
, mdfd
, NULL
)) {
1643 if (array_size
== MAX_SIZE
)
1644 err
= sysfs_set_str(&sra
, NULL
, "array_size", "default");
1646 err
= sysfs_set_num(&sra
, NULL
, "array_size", array_size
/ 2);
1649 pr_err("--array-size setting is too large.\n");
1651 pr_err("current kernel does not support setting --array-size\n");
1656 if (devs_found
> 1 && s
.raiddisks
== 0 && s
.level
== UnSet
) {
1658 if (s
.size
> 0 || s
.chunk
||
1659 s
.layout_str
|| s
.bitmap_file
) {
1660 pr_err("--add cannot be used with other geometry changes in --grow mode\n");
1664 for (dv
= devlist
->next
; dv
; dv
= dv
->next
) {
1665 rv
= Grow_Add_device(devlist
->devname
, mdfd
,
1670 } else if (s
.bitmap_file
) {
1671 if (s
.size
> 0 || s
.raiddisks
|| s
.chunk
||
1672 s
.layout_str
|| devs_found
> 1) {
1673 pr_err("--bitmap changes cannot be used with other geometry changes in --grow mode\n");
1678 c
.delay
= DEFAULT_BITMAP_DELAY
;
1679 rv
= Grow_addbitmap(devlist
->devname
, mdfd
, &c
, &s
);
1680 } else if (grow_continue
)
1681 rv
= Grow_continue_command(devlist
->devname
,
1682 mdfd
, c
.backup_file
,
1684 else if (s
.size
> 0 || s
.raiddisks
|| s
.layout_str
||
1685 s
.chunk
!= 0 || s
.level
!= UnSet
||
1686 data_offset
!= INVALID_SECTORS
) {
1687 rv
= Grow_reshape(devlist
->devname
, mdfd
,
1689 data_offset
, &c
, &s
);
1690 } else if (s
.consistency_policy
!= CONSISTENCY_POLICY_UNKNOWN
) {
1691 rv
= Grow_consistency_policy(devlist
->devname
, mdfd
, &c
, &s
);
1692 } else if (array_size
== 0)
1693 pr_err("no changes to --grow\n");
1702 pr_err("In --incremental mode, a device cannot be given with --scan.\n");
1705 if (c
.runstop
<= 0) {
1706 pr_err("--incremental --scan meaningless without --run.\n");
1709 if (devmode
== 'f') {
1710 pr_err("--incremental --scan --fail not supported.\n");
1713 rv
= IncrementalScan(&c
, NULL
);
1716 if (!rebuild_map
&& !c
.scan
) {
1717 pr_err("--incremental requires a device.\n");
1722 if (devmode
== 'f') {
1723 if (devlist
->next
) {
1724 pr_err("'--incremental --fail' can only handle one device.\n");
1728 rv
= IncrementalRemove(devlist
->devname
, remove_path
,
1731 rv
= Incremental(devlist
, &c
, ss
);
1740 static int scan_assemble(struct supertype
*ss
,
1742 struct mddev_ident
*ident
)
1744 struct mddev_ident
*a
, *array_list
= conf_get_ident(NULL
);
1745 struct mddev_dev
*devlist
= conf_get_devs();
1746 struct map_ent
*map
= NULL
;
1749 int failures
, successes
;
1751 if (conf_verify_devnames(array_list
)) {
1752 pr_err("Duplicate MD device names in conf file were found.\n");
1755 if (devlist
== NULL
) {
1756 pr_err("No devices listed in conf file were found.\n");
1759 for (a
= array_list
; a
; a
= a
->next
) {
1762 a
->autof
= c
->autof
;
1765 pr_err("failed to get exclusive lock on mapfile\n");
1770 for (a
= array_list
; a
; a
= a
->next
) {
1775 strcasecmp(a
->devname
, "<ignore>") == 0)
1778 r
= Assemble(ss
, a
->devname
,
1788 } while (failures
&& successes
);
1789 if (c
->homehost
&& cnt
== 0) {
1790 /* Maybe we can auto-assemble something.
1791 * Repeatedly call Assemble in auto-assemble mode
1796 ident
->autof
= c
->autof
;
1798 struct mddev_dev
*devlist
= conf_get_devs();
1801 rv2
= Assemble(ss
, NULL
,
1809 /* Incase there are stacked devices, we need to go around again */
1811 if (cnt
== 0 && rv
== 0) {
1812 pr_err("No arrays found in config file or automatically\n");
1816 } else if (cnt
== 0 && rv
== 0) {
1817 pr_err("No arrays found in config file\n");
1824 static int misc_scan(char devmode
, struct context
*c
)
1826 /* apply --detail or --wait-clean to
1827 * all devices in /proc/mdstat
1829 struct mdstat_ent
*ms
= mdstat_read(0, 1);
1830 struct mdstat_ent
*e
;
1831 struct map_ent
*map
= NULL
;
1835 for (members
= 0; members
<= 1; members
++) {
1836 for (e
= ms
; e
; e
= e
->next
) {
1840 int member
= e
->metadata_version
&&
1841 strncmp(e
->metadata_version
,
1842 "external:/", 10) == 0;
1843 if (members
!= member
)
1845 me
= map_by_devnm(&map
, e
->devnm
);
1847 && strcmp(me
->path
, "/unknown") != 0)
1849 if (name
== NULL
|| stat(name
, &stb
) != 0)
1850 name
= get_md_name(e
->devnm
);
1853 pr_err("cannot find device file for %s\n",
1858 rv
|= Detail(name
, c
);
1860 rv
|= WaitClean(name
, -1, c
->verbose
);
1868 static int stop_scan(int verbose
)
1870 /* apply --stop to all devices in /proc/mdstat */
1871 /* Due to possible stacking of devices, repeat until
1872 * nothing more can be stopped
1874 int progress
= 1, err
;
1878 struct mdstat_ent
*ms
= mdstat_read(0, 0);
1879 struct mdstat_ent
*e
;
1881 if (!progress
) last
= 1;
1882 progress
= 0; err
= 0;
1883 for (e
= ms
; e
; e
= e
->next
) {
1884 char *name
= get_md_name(e
->devnm
);
1888 pr_err("cannot find device file for %s\n",
1892 mdfd
= open_mddev(name
, 1);
1894 if (Manage_stop(name
, mdfd
, verbose
, !last
))
1904 } while (!last
&& err
);
1910 static int misc_list(struct mddev_dev
*devlist
,
1911 struct mddev_ident
*ident
,
1912 char *dump_directory
,
1913 struct supertype
*ss
, struct context
*c
)
1915 struct mddev_dev
*dv
;
1918 for (dv
= devlist
; dv
; dv
= (rv
& 16) ? NULL
: dv
->next
) {
1921 switch(dv
->disposition
) {
1923 rv
|= Detail(dv
->devname
, c
);
1925 case KillOpt
: /* Zero superblock */
1927 rv
|= Kill(dv
->devname
, ss
, c
->force
, c
->verbose
,0);
1931 rv
|= Kill(dv
->devname
, NULL
, c
->force
, v
, 0);
1938 rv
|= Query(dv
->devname
);
1941 rv
|= ExamineBitmap(dv
->devname
, c
->brief
, ss
);
1944 rv
|= ExamineBadblocks(dv
->devname
, c
->brief
, ss
);
1948 rv
|= Wait(dv
->devname
);
1951 rv
|= WaitClean(dv
->devname
, -1, c
->verbose
);
1954 rv
|= Kill_subarray(dv
->devname
, c
->subarray
, c
->verbose
);
1956 case UpdateSubarray
:
1957 if (c
->update
== NULL
) {
1958 pr_err("-U/--update must be specified with --update-subarray\n");
1962 rv
|= Update_subarray(dv
->devname
, c
->subarray
,
1963 c
->update
, ident
, c
->verbose
);
1966 rv
|= Dump_metadata(dv
->devname
, dump_directory
, c
, ss
);
1969 rv
|= Restore_metadata(dv
->devname
, dump_directory
, c
, ss
,
1970 (dv
== devlist
&& dv
->next
== NULL
));
1973 rv
|= SetAction(dv
->devname
, c
->action
);
1977 if (dv
->devname
[0] != '/')
1978 mdfd
= open_dev(dv
->devname
);
1979 if (dv
->devname
[0] == '/' || mdfd
< 0)
1980 mdfd
= open_mddev(dv
->devname
, 1);
1983 switch(dv
->disposition
) {
1986 rv
|= Manage_run(dv
->devname
, mdfd
, c
);
1989 rv
|= Manage_stop(dv
->devname
, mdfd
, c
->verbose
, 0);
1992 rv
|= Manage_ro(dv
->devname
, mdfd
, 1);
1995 rv
|= Manage_ro(dv
->devname
, mdfd
, -1);
2005 int SetAction(char *dev
, char *action
)
2007 int fd
= open(dev
, O_RDONLY
);
2012 pr_err("Couldn't open %s: %s\n", dev
, strerror(errno
));
2015 retval
= sysfs_init(&mdi
, fd
, NULL
);
2018 pr_err("%s is no an md array\n", dev
);
2022 if (sysfs_set_str(&mdi
, NULL
, "sync_action", action
) < 0) {
2023 pr_err("Count not set action for %s to %s: %s\n",
2024 dev
, action
, strerror(errno
));