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.
35 * set_bitmap_value() - set bitmap value.
40 * Validate and set bitmap. Context is needed for setting nodes for clustered bitmap.
42 static mdadm_status_t
set_bitmap_value(struct shape
*s
, struct context
*c
, char *val
)
44 if (s
->btype
!= BitmapUnknown
) {
45 pr_err("--bitmap cannot be set twice. Second value: \"%s\".\n", val
);
46 return MDADM_STATUS_ERROR
;
49 if (strcmp(optarg
, STR_COMMON_NONE
) == 0) {
50 s
->btype
= BitmapNone
;
51 return MDADM_STATUS_SUCCESS
;
54 if (strcmp(val
, "internal") == 0) {
55 s
->btype
= BitmapInternal
;
56 return MDADM_STATUS_SUCCESS
;
59 if (strcmp(val
, "clustered") == 0) {
60 s
->btype
= BitmapCluster
;
61 /* Set the default number of cluster nodes
62 * to 4 if not already set by user
66 return MDADM_STATUS_SUCCESS
;
69 if (strchr(val
, '/')) {
70 pr_err("Custom write-intent bitmap file option is not supported.\n");
71 return MDADM_STATUS_ERROR
;
74 pr_err("--bitmap value must be 'internal', 'clustered' or 'none'\n");
75 pr_err("Current value is \"%s\"\n", val
);
76 return MDADM_STATUS_ERROR
;
79 static int scan_assemble(struct supertype
*ss
,
81 struct mddev_ident
*ident
);
82 static int misc_scan(char devmode
, struct context
*c
);
83 static int stop_scan(int verbose
);
84 static int misc_list(struct mddev_dev
*devlist
,
85 struct mddev_ident
*ident
,
87 struct supertype
*ss
, struct context
*c
);
88 const char Name
[] = "mdadm";
90 int main(int argc
, char *argv
[])
98 unsigned long long array_size
= 0;
99 struct mddev_ident ident
;
100 char *configfile
= NULL
;
102 struct mddev_dev
*devlist
= NULL
;
103 struct mddev_dev
**devlistend
= & devlist
;
104 struct mddev_dev
*dv
;
105 mdu_array_info_t array
;
107 int grow_continue
= 0;
109 .require_homehost
= 1,
115 .bitmap_chunk
= UnSet
,
116 .consistency_policy
= CONSISTENCY_POLICY_UNKNOWN
,
117 .data_offset
= INVALID_SECTORS
,
118 .btype
= BitmapUnknown
,
121 char sys_hostname
[256];
122 char *mailaddr
= NULL
;
123 char *program
= NULL
;
126 char *pidfile
= NULL
;
128 int spare_sharing
= 1;
129 struct supertype
*ss
= NULL
;
130 enum flag_mode writemostly
= FlagDefault
;
131 enum flag_mode failfast
= FlagDefault
;
132 char *shortopt
= short_opts
;
135 char *remove_path
= NULL
;
136 char *udev_filename
= NULL
;
137 char *dump_directory
= NULL
;
145 srandom(time(0) ^ getpid());
147 if (get_linux_version() < 2006032) {
148 pr_err("This version of mdadm does not support kernels older than 2.6.32\n");
154 while ((option_index
= -1),
155 (opt
= getopt_long(argc
, argv
, shortopt
, long_options
,
156 &option_index
)) != -1) {
158 /* firstly, some mode-independent options */
168 fputs(Version
, stderr
);
171 case 'v': c
.verbose
++;
174 case 'q': c
.verbose
--;
178 if (mode
== ASSEMBLE
|| mode
== BUILD
||
179 mode
== CREATE
|| mode
== GROW
||
180 mode
== INCREMENTAL
|| mode
== MANAGE
)
181 break; /* b means bitmap */
190 case 'Y': c
.export
++;
194 if (is_devname_ignore(optarg
) == true)
195 c
.require_homehost
= 0;
201 /* Silently ignore old option */
207 if (asprintf(&c
.prefer
, "/%s/", optarg
) <= 0)
213 fputs(Usage
, stderr
);
216 /* second, figure out the mode.
217 * Some options force the mode. Others
218 * set the mode if it isn't already
224 shortopt
= short_bitmap_opts
;
236 case ReAdd
: /* re-add */
240 shortopt
= short_bitmap_opts
;
246 shortopt
= short_bitmap_auto_opts
;
250 shortopt
= short_bitmap_auto_opts
;
254 shortopt
= short_bitmap_auto_opts
;
258 shortopt
= short_monitor_opts
;
262 shortopt
= short_bitmap_opts
;
265 newmode
= INCREMENTAL
;
266 shortopt
= short_bitmap_auto_opts
;
269 newmode
= AUTODETECT
;
304 if (mode
&& newmode
== mode
) {
305 /* everybody happy ! */
306 } else if (mode
&& newmode
!= mode
) {
309 if (option_index
>= 0)
310 fprintf(stderr
, "--%s", long_options
[option_index
].name
);
312 fprintf(stderr
, "-%c", opt
);
313 fprintf(stderr
, " would set mdadm mode to \"%s\", but it is already set to \"%s\".\n",
314 map_num_s(modes
, newmode
),
315 map_num_s(modes
, mode
));
317 } else if (!mode
&& newmode
) {
319 if (mode
== MISC
&& devs_found
) {
320 pr_err("No action given for %s in --misc mode\n",
322 cont_err("Action options must come before device names\n");
326 /* special case of -c --help */
327 if ((opt
== 'c' || opt
== ConfigFile
) &&
328 (strncmp(optarg
, "--h", 3) == 0 ||
329 strncmp(optarg
, "-h", 2) == 0)) {
330 fputs(Help_config
, stdout
);
334 /* If first option is a device, don't force the mode yet */
336 if (devs_found
== 0) {
337 dv
= xmalloc(sizeof(*dv
));
338 dv
->devname
= optarg
;
339 dv
->disposition
= devmode
;
340 dv
->writemostly
= writemostly
;
341 dv
->failfast
= failfast
;
345 devlistend
= &dv
->next
;
350 /* No mode yet, and this is the second device ... */
351 pr_err("An option must be given to set the mode before a second device\n"
352 " (%s) is listed\n", optarg
);
355 if (option_index
>= 0)
356 pr_err("--%s", long_options
[option_index
].name
);
359 fprintf(stderr
, " does not set the mode, and so cannot be the first option.\n");
363 /* if we just set the mode, then done */
377 /* an undecorated option - must be a device name.
380 if (devs_found
> 0 && devmode
== DetailPlatform
) {
381 pr_err("controller may only be specified once. %s ignored\n",
386 if (devs_found
> 0 && mode
== MANAGE
&& !devmode
) {
387 pr_err("Must give one of -a/-r/-f for subsequent devices at %s\n", optarg
);
390 if (devs_found
> 0 && mode
== GROW
&& !devmode
) {
391 pr_err("Must give -a/--add for devices to add: %s\n", optarg
);
394 dv
= xmalloc(sizeof(*dv
));
395 dv
->devname
= optarg
;
396 dv
->disposition
= devmode
;
397 dv
->writemostly
= writemostly
;
398 dv
->failfast
= failfast
;
402 devlistend
= &dv
->next
;
408 /* We've got a mode, and opt is now something else which
409 * could depend on the mode */
410 #define O(a,b) ((a<<16)|b)
411 switch (O(mode
,opt
)) {
413 case O(GROW
,ChunkSize
):
415 case O(CREATE
,ChunkSize
):
416 case O(BUILD
,'c'): /* chunk or rounding */
417 case O(BUILD
,ChunkSize
): /* chunk or rounding */
419 pr_err("chunk/rounding may only be specified once. Second value is %s.\n", optarg
);
422 s
.chunk
= parse_size(optarg
);
423 if (s
.chunk
== INVALID_SECTORS
||
424 s
.chunk
< 8 || (s
.chunk
&1)) {
425 pr_err("invalid chunk/rounding value: %s\n",
429 /* Convert sectors to K */
433 case O(INCREMENTAL
, 'e'):
435 case O(ASSEMBLE
,'e'):
436 case O(MISC
,'e'): /* set metadata (superblock) information */
438 pr_err("metadata information already given\n");
441 for(i
= 0; !ss
&& superlist
[i
]; i
++)
442 ss
= superlist
[i
]->match_metadata_desc(optarg
);
445 pr_err("unrecognised metadata identifier: %s\n", optarg
);
451 case O(MANAGE
,WriteMostly
):
453 case O(BUILD
,WriteMostly
):
455 case O(CREATE
,WriteMostly
):
456 /* set write-mostly for following devices */
457 writemostly
= FlagSet
;
461 /* clear write-mostly for following devices */
462 writemostly
= FlagClear
;
465 case O(MANAGE
,FailFast
):
466 case O(CREATE
,FailFast
):
469 case O(MANAGE
,NoFailFast
):
470 failfast
= FlagClear
;
475 case O(BUILD
,'z'): /* size */
477 pr_err("size may only be specified once. Second value is %s.\n", optarg
);
480 if (strcmp(optarg
, "max") == 0)
483 s
.size
= parse_size(optarg
);
484 if (s
.size
== INVALID_SECTORS
|| s
.size
< 8) {
485 pr_err("invalid size: %s\n", optarg
);
488 /* convert sectors to K */
493 case O(GROW
,'Z'): /* array size */
494 if (array_size
> 0) {
495 pr_err("array-size may only be specified once. Second value is %s.\n", optarg
);
498 if (strcmp(optarg
, "max") == 0)
499 array_size
= MAX_SIZE
;
501 array_size
= parse_size(optarg
);
502 if (array_size
== 0 ||
503 array_size
== INVALID_SECTORS
) {
504 pr_err("invalid array size: %s\n",
511 case O(CREATE
,DataOffset
):
512 case O(GROW
,DataOffset
):
513 if (s
.data_offset
!= INVALID_SECTORS
) {
514 pr_err("data-offset may only be specified one. Second value is %s.\n", optarg
);
517 if (mode
== CREATE
&& strcmp(optarg
, "variable") == 0)
518 s
.data_offset
= VARIABLE_OFFSET
;
520 s
.data_offset
= parse_size(optarg
);
521 if (s
.data_offset
== INVALID_SECTORS
) {
522 pr_err("invalid data-offset: %s\n",
530 case O(BUILD
,'l'): /* set raid level*/
531 if (s
.level
!= UnSet
) {
532 pr_err("raid level may only be set once. Second value is %s.\n", optarg
);
535 s
.level
= map_name(pers
, optarg
);
536 if (s
.level
== UnSet
) {
537 pr_err("invalid raid level: %s\n",
541 if (s
.level
!= 0 && s
.level
!= LEVEL_LINEAR
&&
542 s
.level
!= 1 && s
.level
!= LEVEL_MULTIPATH
&&
543 s
.level
!= LEVEL_FAULTY
&& s
.level
!= 10 &&
545 pr_err("Raid level %s not permitted with --build.\n",
549 if (s
.sparedisks
> 0 && s
.level
< 1 && s
.level
>= -1) {
550 pr_err("raid level %s is incompatible with spare-devices setting.\n",
554 ident
.level
= s
.level
;
557 case O(GROW
, 'p'): /* new layout */
558 case O(GROW
, Layout
):
560 pr_err("layout may only be sent once. Second value was %s\n", optarg
);
563 s
.layout_str
= optarg
;
564 /* 'Grow' will parse the value */
567 case O(CREATE
,'p'): /* raid5 layout */
568 case O(CREATE
,Layout
):
569 case O(BUILD
,'p'): /* faulty layout */
570 case O(BUILD
,Layout
):
571 if (s
.layout
!= UnSet
) {
572 pr_err("layout may only be sent once. Second value was %s\n", optarg
);
577 pr_err("layout not meaningful for %s arrays.\n",
578 map_num_s(pers
, s
.level
));
581 pr_err("raid level must be given before layout.\n");
585 s
.layout
= map_name(r0layout
, optarg
);
586 if (s
.layout
== UnSet
) {
587 pr_err("layout %s not understood for raid0.\n",
593 s
.layout
= map_name(r5layout
, optarg
);
594 if (s
.layout
== UnSet
) {
595 pr_err("layout %s not understood for raid5.\n",
601 s
.layout
= map_name(r6layout
, optarg
);
602 if (s
.layout
== UnSet
) {
603 pr_err("layout %s not understood for raid6.\n",
610 s
.layout
= parse_layout_10(optarg
);
612 pr_err("layout for raid10 must be 'nNN', 'oNN' or 'fNN' where NN is a number, not %s\n", optarg
);
620 s
.layout
= parse_layout_faulty(optarg
);
621 if (s
.layout
== -1) {
622 pr_err("layout %s not understood for faulty.\n",
630 case O(CREATE
,AssumeClean
):
631 case O(BUILD
,AssumeClean
): /* assume clean */
632 case O(GROW
,AssumeClean
):
636 case O(CREATE
, WriteZeroes
):
642 case O(BUILD
,'n'): /* number of raid disks */
644 pr_err("raid-devices set twice: %d and %s\n",
645 s
.raiddisks
, optarg
);
648 if (parse_num(&s
.raiddisks
, optarg
) != 0 || s
.raiddisks
<= 0) {
649 pr_err("invalid number of raid devices: %s\n",
653 ident
.raid_disks
= s
.raiddisks
;
655 case O(ASSEMBLE
, Nodes
):
657 case O(CREATE
, Nodes
):
658 if (parse_num(&c
.nodes
, optarg
) != 0 || c
.nodes
< 2) {
659 pr_err("clustered array needs two nodes at least: %s\n",
664 case O(CREATE
, ClusterName
):
665 case O(ASSEMBLE
, ClusterName
):
666 c
.homecluster
= optarg
;
667 if (strlen(c
.homecluster
) > 64) {
668 pr_err("Cluster name too big.\n");
672 case O(CREATE
,'x'): /* number of spare (eXtra) disks */
674 pr_err("spare-devices set twice: %d and %s\n",
675 s
.sparedisks
, optarg
);
678 if (s
.level
!= UnSet
&& s
.level
<= 0 && s
.level
>= -1) {
679 pr_err("spare-devices setting is incompatible with raid level %d\n",
683 if (parse_num(&s
.sparedisks
, optarg
) != 0 || s
.sparedisks
< 0) {
684 pr_err("invalid number of spare-devices: %s\n",
694 case O(INCREMENTAL
,'a'):
695 case O(INCREMENTAL
,Auto
):
696 case O(ASSEMBLE
,'a'):
697 case O(ASSEMBLE
, Auto
): /* auto-creation of device node - deprecated */
698 pr_info("--auto is deprecated and will be removed in future releases.\n");
700 case O(BUILD
,'f'): /* force honouring '-n 1' */
701 case O(BUILD
,Force
): /* force honouring '-n 1' */
702 case O(GROW
,'f'): /* ditto */
703 case O(GROW
,Force
): /* ditto */
704 case O(CREATE
,'f'): /* force honouring of device list */
705 case O(CREATE
,Force
): /* force honouring of device list */
706 case O(ASSEMBLE
,'f'): /* force assembly */
707 case O(ASSEMBLE
,Force
): /* force assembly */
708 case O(MISC
,'f'): /* force zero */
709 case O(MISC
,Force
): /* force zero */
710 case O(MANAGE
,Force
): /* add device which is too large */
713 case O(CREATE
,'u'): /* uuid of array */
714 case O(ASSEMBLE
,'u'): /* uuid of array */
715 if (ident
.uuid_set
) {
716 pr_err("uuid cannot be set twice. Second value %s.\n", optarg
);
719 if (parse_uuid(optarg
, ident
.uuid
))
722 pr_err("Bad uuid: %s\n", optarg
);
728 case O(ASSEMBLE
,'N'):
730 if (mode
== MISC
&& !c
.subarray
) {
731 pr_err("-N/--name only valid with --update-subarray in misc mode\n");
735 if (ident_set_name(&ident
, optarg
) != MDADM_STATUS_SUCCESS
)
740 case O(ASSEMBLE
,'m'): /* super-minor for array */
741 case O(ASSEMBLE
,SuperMinor
):
742 if (ident
.super_minor
!= UnSet
) {
743 pr_err("super-minor cannot be set twice. Second value: %s.\n", optarg
);
746 if (strcmp(optarg
, "dev") == 0)
747 ident
.super_minor
= -2;
748 else if (parse_num(&ident
.super_minor
, optarg
) != 0 || ident
.super_minor
< 0) {
749 pr_err("Bad super-minor number: %s.\n", optarg
);
754 case O(ASSEMBLE
,'o'):
760 case O(ASSEMBLE
,'U'): /* update the superblock */
762 enum update_opt print_mode
= UOPT_HELP
;
763 const char *error_addon
= "update option";
766 pr_err("Can only update one aspect of superblock, both %s and %s given.\n",
767 map_num(update_options
, c
.update
), optarg
);
770 if (mode
== MISC
&& !c
.subarray
) {
771 pr_err("Only subarrays can be updated in misc mode\n");
775 c
.update
= map_name(update_options
, optarg
);
777 if (devmode
== UpdateSubarray
) {
778 print_mode
= UOPT_SUBARRAY_ONLY
;
779 error_addon
= "update-subarray option";
781 if (c
.update
> UOPT_SUBARRAY_ONLY
&& c
.update
< UOPT_HELP
)
782 c
.update
= UOPT_UNDEFINED
;
787 pr_err("'--update=%s' is invalid %s. ",
788 optarg
, error_addon
);
793 fprint_update_options(outf
, print_mode
);
794 exit(outf
== stdout
? 0 : 2);
797 pr_err("must not set metadata type with --update=byteorder.\n");
806 /* update=devicesize is allowed with --re-add */
807 if (devmode
!= 'A') {
808 pr_err("--update in Manage mode only allowed with --re-add.\n");
812 pr_err("Can only update one aspect of superblock, both %s and %s given.\n",
813 map_num(update_options
, c
.update
), optarg
);
816 c
.update
= map_name(update_options
, optarg
);
817 if (c
.update
!= UOPT_DEVICESIZE
&&
818 c
.update
!= UOPT_BBL
&&
819 c
.update
!= UOPT_NO_BBL
&&
820 c
.update
!= UOPT_FORCE_NO_BBL
) {
821 pr_err("only 'devicesize', 'bbl', 'no-bbl', and 'force-no-bbl' can be updated with --re-add\n");
826 case O(INCREMENTAL
,NoDegraded
):
827 pr_err("--no-degraded is deprecated in Incremental mode\n");
828 case O(ASSEMBLE
,NoDegraded
): /* --no-degraded */
829 c
.runstop
= -1; /* --stop isn't allowed for --assemble,
830 * so we overload slightly */
833 case O(ASSEMBLE
,'c'):
834 case O(ASSEMBLE
,ConfigFile
):
835 case O(INCREMENTAL
, 'c'):
836 case O(INCREMENTAL
, ConfigFile
):
838 case O(MISC
, ConfigFile
):
840 case O(MONITOR
,ConfigFile
):
841 case O(CREATE
,ConfigFile
):
843 pr_err("configfile cannot be set twice. Second value is %s.\n", optarg
);
847 set_conffile(configfile
);
848 /* FIXME possibly check that config file exists. Even parse it */
850 case O(ASSEMBLE
,'s'): /* scan */
853 case O(INCREMENTAL
,'s'):
857 case O(MONITOR
,'m'): /* mail address */
858 case O(MONITOR
,EMail
):
860 pr_err("only specify one mailaddress. %s ignored.\n",
866 case O(MONITOR
,'p'): /* alert program */
867 case O(MONITOR
,ProgramOpt
): /* alert program */
869 pr_err("only specify one alter program. %s ignored.\n",
875 case O(MONITOR
,'r'): /* rebuild increments */
876 case O(MONITOR
,Increment
):
877 if (parse_num(&increments
, optarg
) != 0
878 || increments
> 99 || increments
< 1) {
879 pr_err("please specify positive integer between 1 and 99 as rebuild increments.\n");
884 case O(MONITOR
,'d'): /* delay in seconds */
886 case O(BUILD
,'d'): /* delay for bitmap updates */
889 pr_err("only specify delay once. %s ignored.\n", optarg
);
890 else if (parse_num(&c
.delay
, optarg
) != 0 || c
.delay
< 1) {
891 pr_err("invalid delay: %s\n", optarg
);
895 case O(MONITOR
,'f'): /* daemonise */
896 case O(MONITOR
,Fork
):
899 case O(MONITOR
,'i'): /* pid */
901 pr_err("only specify one pid file. %s ignored.\n",
906 case O(MONITOR
,'1'): /* oneshot */
910 case O(MONITOR
,'t'): /* test */
913 case O(MONITOR
,'y'): /* log messages to syslog */
914 openlog("mdadm", LOG_PID
, SYSLOG_FACILITY
);
917 case O(MONITOR
, NoSharing
):
921 /* now the general management options. Some are applicable
922 * to other modes. None have arguments.
927 case O(MANAGE
,Add
): /* add a drive */
930 case O(MANAGE
,AddSpare
): /* add drive - never re-add */
933 case O(MANAGE
,AddJournal
): /* add journal */
934 if (s
.journaldisks
&& (s
.level
< 4 || s
.level
> 6)) {
935 pr_err("--add-journal is only supported for RAID level 4/5/6.\n");
940 case O(MANAGE
,ReAdd
):
943 case O(MANAGE
,'r'): /* remove a drive */
944 case O(MANAGE
,Remove
):
947 case O(MANAGE
,'f'): /* set faulty */
949 case O(INCREMENTAL
,'f'):
950 case O(INCREMENTAL
,Remove
):
951 case O(INCREMENTAL
,Fail
): /* r for incremental is taken, use f
952 * even though we will both fail and
953 * remove the device */
956 case O(MANAGE
, ClusterConfirm
):
959 case O(MANAGE
,Replace
):
960 /* Mark these devices for replacement */
964 /* These are the replacements to use */
965 if (devmode
!= 'R') {
966 pr_err("--with must follow --replace\n");
971 case O(INCREMENTAL
,'R'):
973 case O(ASSEMBLE
,'R'):
975 case O(CREATE
,'R'): /* Run the array */
977 pr_err("Cannot both Stop and Run an array\n");
984 pr_err("Cannot both Run and Stop an array\n");
996 case O(MISC
,KillOpt
):
1000 case O(MISC
, ExamineBB
):
1004 case O(MISC
, WaitOpt
):
1005 case O(MISC
, Waitclean
):
1006 case O(MISC
, DetailPlatform
):
1007 case O(MISC
, KillSubarray
):
1008 case O(MISC
, UpdateSubarray
):
1010 case O(MISC
, Restore
):
1011 case O(MISC
,Action
):
1012 if (opt
== KillSubarray
|| opt
== UpdateSubarray
) {
1014 pr_err("subarray can only be specified once\n");
1017 c
.subarray
= optarg
;
1019 if (opt
== Action
) {
1021 pr_err("Only one --action can be specified\n");
1024 if (strcmp(optarg
, "idle") == 0 ||
1025 strcmp(optarg
, "frozen") == 0 ||
1026 strcmp(optarg
, "check") == 0 ||
1027 strcmp(optarg
, "repair") == 0)
1030 pr_err("action must be one of idle, frozen, check, repair\n");
1034 if (devmode
&& devmode
!= opt
&&
1036 (opt
== 'E' && devmode
!= 'Q'))) {
1037 pr_err("--examine/-E cannot be given with ");
1038 if (devmode
== 'E') {
1039 if (option_index
>= 0)
1040 fprintf(stderr
, "--%s\n",
1041 long_options
[option_index
].name
);
1043 fprintf(stderr
, "-%c\n", opt
);
1044 } else if (isalpha(devmode
))
1045 fprintf(stderr
, "-%c\n", devmode
);
1047 fprintf(stderr
, "previous option\n");
1051 if (opt
== Dump
|| opt
== Restore
) {
1052 if (dump_directory
!= NULL
) {
1053 pr_err("dump/restore directory specified twice: %s and %s\n",
1054 dump_directory
, optarg
);
1057 dump_directory
= optarg
;
1060 case O(MISC
, UdevRules
):
1061 if (devmode
&& devmode
!= opt
) {
1062 pr_err("--udev-rules must be the only option.\n");
1065 pr_err("only specify one udev rule filename. %s ignored.\n",
1068 udev_filename
= optarg
;
1076 case O(MISC
, Sparc22
):
1077 if (devmode
!= 'E') {
1078 pr_err("--sparc2.2 only allowed with --examine\n");
1084 case O(ASSEMBLE
,'b'): /* here we simply set the bitmap file */
1085 case O(ASSEMBLE
,Bitmap
):
1086 if (optarg
&& (strcmp(optarg
, "internal") == 0 ||
1087 strcmp(optarg
, "clustered")) == 0) {
1088 pr_err("no need to specify --bitmap when assembling"
1089 " arrays with internal or clustered bitmap\n");
1093 pr_err("bitmap file is not supported %s\n", optarg
);
1095 case O(ASSEMBLE
, BackupFile
):
1096 case O(GROW
, BackupFile
):
1097 /* Specify a file into which grow might place a backup,
1098 * or from which assemble might recover a backup
1100 if (c
.backup_file
) {
1101 pr_err("backup file already specified, rejecting %s\n", optarg
);
1104 c
.backup_file
= optarg
;
1107 case O(GROW
, Continue
):
1108 /* Continue interrupted grow
1112 case O(ASSEMBLE
, InvalidBackup
):
1113 /* Acknowledge that the backupfile is invalid, but ask
1114 * to continue anyway
1116 c
.invalid_backup
= 1;
1120 case O(BUILD
,Bitmap
):
1122 case O(CREATE
,Bitmap
): /* here we create the bitmap */
1124 case O(GROW
,Bitmap
):
1125 if (set_bitmap_value(&s
, &c
, optarg
))
1128 case O(GROW
,BitmapChunk
):
1129 case O(BUILD
,BitmapChunk
):
1130 case O(CREATE
,BitmapChunk
): /* bitmap chunksize */
1131 s
.bitmap_chunk
= parse_size(optarg
);
1132 if (s
.bitmap_chunk
== 0 ||
1133 s
.bitmap_chunk
== INVALID_SECTORS
||
1134 s
.bitmap_chunk
& (s
.bitmap_chunk
- 1)) {
1135 pr_err("invalid bitmap chunksize: %s\n",
1139 s
.bitmap_chunk
= s
.bitmap_chunk
* 512;
1142 case O(GROW
, WriteBehind
):
1143 case O(BUILD
, WriteBehind
):
1144 case O(CREATE
, WriteBehind
):
1145 s
.write_behind
= DEFAULT_MAX_WRITE_BEHIND
;
1147 (parse_num(&s
.write_behind
, optarg
) != 0 ||
1148 s
.write_behind
< 0 || s
.write_behind
> 16383)) {
1149 pr_err("Invalid value for maximum outstanding write-behind writes: %s.\n\tMust be between 0 and 16383.\n",
1154 case O(INCREMENTAL
, 'r'):
1155 case O(INCREMENTAL
, RebuildMapOpt
):
1158 case O(INCREMENTAL
, IncrementalPath
):
1159 remove_path
= optarg
;
1161 case O(CREATE
, WriteJournal
):
1162 if (s
.journaldisks
) {
1163 pr_err("Please specify only one journal device for the array.\n");
1164 pr_err("Ignoring --write-journal %s...\n", optarg
);
1167 dv
= xmalloc(sizeof(*dv
));
1168 dv
->devname
= optarg
;
1169 dv
->disposition
= 'j'; /* WriteJournal */
1173 devlistend
= &dv
->next
;
1178 case O(CREATE
, 'k'):
1180 s
.consistency_policy
= map_name(consistency_policies
,
1182 if (s
.consistency_policy
< CONSISTENCY_POLICY_RESYNC
) {
1183 pr_err("Invalid consistency policy: %s\n",
1189 /* We have now processed all the valid options. Anything else is
1192 if (option_index
> 0)
1193 pr_err(":option --%s not valid in %s mode\n",
1194 long_options
[option_index
].name
,
1195 map_num_s(modes
, mode
));
1197 pr_err("option -%c not valid in %s mode\n",
1198 opt
, map_num_s(modes
, mode
));
1205 if (print_help
== 2)
1206 help_text
= OptionHelp
;
1208 help_text
= mode_help
[mode
];
1209 if (help_text
== NULL
)
1211 fputs(help_text
,stdout
);
1215 if (s
.journaldisks
) {
1216 if (s
.level
< 4 || s
.level
> 6) {
1217 pr_err("--write-journal is only supported for RAID level 4/5/6.\n");
1220 if (s
.consistency_policy
!= CONSISTENCY_POLICY_UNKNOWN
&&
1221 s
.consistency_policy
!= CONSISTENCY_POLICY_JOURNAL
) {
1222 pr_err("--write-journal is not supported with consistency policy: %s\n",
1223 map_num_s(consistency_policies
, s
.consistency_policy
));
1228 if (mode
== CREATE
&&
1229 s
.consistency_policy
!= CONSISTENCY_POLICY_UNKNOWN
) {
1231 pr_err("--consistency-policy not meaningful with level %s.\n",
1232 map_num_s(pers
, s
.level
));
1234 } else if (s
.consistency_policy
== CONSISTENCY_POLICY_JOURNAL
&&
1236 pr_err("--write-journal is required for consistency policy: %s\n",
1237 map_num_s(consistency_policies
, s
.consistency_policy
));
1239 } else if (s
.consistency_policy
== CONSISTENCY_POLICY_PPL
&&
1241 pr_err("PPL consistency policy is only supported for RAID level 5.\n");
1243 } else if (s
.consistency_policy
== CONSISTENCY_POLICY_BITMAP
&&
1244 s
.btype
== BitmapNone
) {
1245 pr_err("--bitmap is required for consistency policy: %s\n",
1246 map_num_s(consistency_policies
, s
.consistency_policy
));
1248 } else if ((s
.btype
== BitmapInternal
|| s
.btype
== BitmapCluster
) &&
1249 s
.consistency_policy
!= CONSISTENCY_POLICY_BITMAP
&&
1250 s
.consistency_policy
!= CONSISTENCY_POLICY_JOURNAL
) {
1251 pr_err("--bitmap is not compatible with consistency policy: %s\n",
1252 map_num_s(consistency_policies
, s
.consistency_policy
));
1257 if (s
.write_zeroes
&& !s
.assume_clean
) {
1258 pr_info("Disk zeroing requested, setting --assume-clean to skip resync\n");
1262 if (!mode
&& devs_found
) {
1265 if (devlist
->disposition
== 0)
1266 devlist
->disposition
= devmode
;
1269 fputs(Usage
, stderr
);
1273 /* Ok, got the option parsing out of the way
1274 * hopefully it's mostly right but there might be some stuff
1277 * That is mostly checked in the per-mode stuff but...
1279 * For @,B,C and A without -s, the first device listed must be
1280 * an md device. We check that here and open it.
1283 if (mode
== MANAGE
|| mode
== BUILD
|| mode
== CREATE
||
1284 mode
== GROW
|| (mode
== ASSEMBLE
&& ! c
.scan
)) {
1288 if (devs_found
< 1) {
1289 pr_err("an md device must be given in this mode\n");
1292 if (ident_set_devname(&ident
, devlist
->devname
) != MDADM_STATUS_SUCCESS
)
1295 if (mode
== MANAGE
|| mode
== GROW
) {
1296 mdfd
= open_mddev(ident
.devname
, 1);
1300 ret
= fstat(mdfd
, &stb
);
1302 pr_err("fstat failed on %s.\n", ident
.devname
);
1306 ret
= stat(ident
.devname
, &stb
);
1307 if (ident
.super_minor
== -2 && ret
!= 0) {
1308 pr_err("--super-minor=dev given, and listed device %s doesn't exist.\n",
1313 if (!ret
&& !stat_is_md_dev(&stb
)) {
1314 pr_err("device %s exists but is not an md array.\n", ident
.devname
);
1318 if (ident
.super_minor
== -2)
1319 ident
.super_minor
= minor(stb
.st_rdev
);
1323 if (s
.raiddisks
== 1 && !c
.force
&& s
.level
!= LEVEL_FAULTY
) {
1324 pr_err("'1' is an unusual number of drives for an array, so it is probably\n"
1325 " a mistake. If you really mean it you will need to specify --force before\n"
1326 " setting the number of drives.\n");
1331 if (c
.homehost
== NULL
&& c
.require_homehost
)
1332 c
.homehost
= conf_get_homehost(&c
.require_homehost
);
1333 if (c
.homehost
== NULL
|| strcasecmp(c
.homehost
, "<system>") == 0) {
1334 if (s_gethostname(sys_hostname
, sizeof(sys_hostname
)) == 0) {
1335 c
.homehost
= sys_hostname
;
1339 (!c
.homehost
[0] || strcasecmp(c
.homehost
, "<none>") == 0)) {
1341 c
.require_homehost
= 0;
1346 set_hooks(); /* set hooks from libs */
1348 if (c
.homecluster
== NULL
&& (c
.nodes
> 0)) {
1349 c
.homecluster
= conf_get_homecluster();
1350 if (c
.homecluster
== NULL
)
1351 rv
= get_cluster_name(&c
.homecluster
);
1353 pr_err("The md can't get cluster name\n");
1358 if (c
.update
&& c
.update
== UOPT_NODES
&& c
.nodes
== 0) {
1359 pr_err("Please specify nodes number with --nodes\n");
1363 if (c
.backup_file
&& s
.data_offset
!= INVALID_SECTORS
) {
1364 pr_err("--backup-file and --data-offset are incompatible\n");
1368 if ((mode
== MISC
&& devmode
== 'E') ||
1369 (mode
== MONITOR
&& spare_sharing
== 0))
1370 /* Anyone may try this */;
1371 else if (geteuid() != 0) {
1372 pr_err("must be super-user to perform this action\n");
1376 if (c
.scan
&& c
.verbose
< 2)
1377 /* --scan implied --brief unless -vv */
1380 if (mode
== CREATE
) {
1381 if (s
.btype
== BitmapCluster
) {
1382 locked
= cluster_get_dlmlock();
1386 } else if (mode
== MANAGE
|| mode
== GROW
|| mode
== INCREMENTAL
) {
1387 if (!md_get_array_info(mdfd
, &array
) && (devmode
!= 'c')) {
1388 if (array
.state
& (1 << MD_SB_CLUSTERED
)) {
1389 locked
= cluster_get_dlmlock();
1398 /* readonly, add/remove, readwrite, runstop */
1400 rv
= Manage_ro(ident
.devname
, mdfd
, c
.readonly
);
1401 if (!rv
&& devs_found
> 1)
1402 rv
= Manage_subdevs(ident
.devname
, mdfd
,
1403 devlist
->next
, c
.verbose
,
1404 c
.test
, c
.update
, c
.force
);
1405 if (!rv
&& c
.readonly
< 0)
1406 rv
= Manage_ro(ident
.devname
, mdfd
, c
.readonly
);
1407 if (!rv
&& c
.runstop
> 0)
1408 rv
= Manage_run(ident
.devname
, mdfd
, &c
);
1409 if (!rv
&& c
.runstop
< 0)
1410 rv
= Manage_stop(ident
.devname
, mdfd
, c
.verbose
, 0);
1413 if (!c
.scan
&& c
.runstop
== -1) {
1414 pr_err("--no-degraded not meaningful without a --scan assembly.\n");
1416 } else if (devs_found
== 1 && ident
.uuid_set
== 0 &&
1417 ident
.super_minor
== UnSet
&& ident
.name
[0] == 0 &&
1419 /* Only a device has been given, so get details from config file */
1420 struct mddev_ident
*array_ident
= conf_get_ident(ident
.devname
);
1421 if (array_ident
== NULL
) {
1422 pr_err("%s not identified in config file.\n", ident
.devname
);
1427 rv
|= Assemble(ss
, ident
.devname
, array_ident
, NULL
, &c
);
1430 rv
= Assemble(ss
, ident
.devname
, &ident
, devlist
->next
, &c
);
1431 else if (devs_found
> 0) {
1432 if (c
.update
&& devs_found
> 1) {
1433 pr_err("can only update a single array at a time\n");
1436 if (c
.backup_file
&& devs_found
> 1) {
1437 pr_err("can only assemble a single array when providing a backup file.\n");
1440 for (dv
= devlist
; dv
; dv
= dv
->next
) {
1441 struct mddev_ident
*array_ident
= conf_get_ident(dv
->devname
);
1442 if (array_ident
== NULL
) {
1443 pr_err("%s not identified in config file.\n",
1448 rv
|= Assemble(ss
, dv
->devname
, array_ident
, NULL
, &c
);
1452 pr_err("--update not meaningful with a --scan assembly.\n");
1455 if (c
.backup_file
) {
1456 pr_err("--backup_file not meaningful with a --scan assembly.\n");
1459 rv
= scan_assemble(ss
, &c
, &ident
);
1465 c
.delay
= DEFAULT_BITMAP_DELAY
;
1467 if (s
.btype
== BitmapUnknown
)
1468 s
.btype
= BitmapNone
;
1470 if (s
.btype
!= BitmapNone
) {
1471 pr_err("--build argument only compatible with --bitmap=none\n");
1476 if (s
.write_behind
) {
1477 pr_err("write-behind mode requires a bitmap.\n");
1481 if (s
.raiddisks
== 0) {
1482 pr_err("no raid-devices specified.\n");
1487 rv
= Build(&ident
, devlist
->next
, &s
, &c
);
1491 c
.delay
= DEFAULT_BITMAP_DELAY
;
1494 if (s
.btype
!= BitmapCluster
) {
1495 pr_err("--nodes argument only compatible with --bitmap=clustered\n");
1500 if (s
.level
!= 1 && s
.level
!= 10) {
1501 pr_err("--bitmap=clustered is currently supported with raid1/10 only\n");
1505 if (s
.level
== 10 && !(is_near_layout_10(s
.layout
) || s
.layout
== UnSet
)) {
1506 pr_err("only near layout is supported with clustered raid10\n");
1512 if (s
.write_behind
&& s
.btype
== BitmapNone
) {
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
.btype
== BitmapUnknown
) {
1524 if (c
.runstop
!= 1 && s
.level
>= 1 &&
1525 ask("To optimize recovery speed, it is recommended to enable write-intent bitmap, do you want to enable it now?"))
1526 s
.btype
= BitmapInternal
;
1528 s
.btype
= BitmapNone
;
1531 rv
= Create(ss
, &ident
, devs_found
- 1, devlist
->next
, &s
, &c
);
1534 if (devmode
== 'E') {
1535 if (devlist
== NULL
&& !c
.scan
) {
1536 pr_err("No devices to examine\n");
1539 if (devlist
== NULL
)
1540 devlist
= conf_get_devs();
1541 if (devlist
== NULL
) {
1542 pr_err("No devices listed in %s\n", configfile
?configfile
:DefaultConfFile
);
1545 rv
= Examine(devlist
, &c
, ss
);
1546 } else if (devmode
== DetailPlatform
) {
1547 rv
= Detail_Platform(ss
? ss
->ss
: NULL
, ss
? c
.scan
: 1,
1548 c
.verbose
, c
.export
,
1549 devlist
? devlist
->devname
: NULL
);
1550 } else if (devlist
== NULL
) {
1551 if (devmode
== 'S' && c
.scan
)
1552 rv
= stop_scan(c
.verbose
);
1553 else if ((devmode
== 'D' || devmode
== Waitclean
) &&
1555 rv
= misc_scan(devmode
, &c
);
1556 else if (devmode
== UdevRules
)
1557 rv
= Write_rules(udev_filename
);
1559 pr_err("No devices given.\n");
1563 rv
= misc_list(devlist
, &ident
, dump_directory
, ss
, &c
);
1566 if (!devlist
&& !c
.scan
) {
1567 pr_err("Cannot monitor: need --scan or at least one device\n");
1571 if (pidfile
&& !daemonise
) {
1572 pr_err("Cannot write a pid file when not in daemon mode\n");
1577 c
.delay
= conf_get_monitor_delay();
1581 rv
= Monitor(devlist
, mailaddr
, program
,
1582 &c
, daemonise
, oneshot
,
1583 dosyslog
, pidfile
, increments
,
1588 if (array_size
> 0) {
1589 /* alway impose array size first, independent of
1591 * Do not allow level or raid_disks changes at the
1592 * same time as that can be irreversibly destructive.
1596 if (s
.raiddisks
|| s
.level
!= UnSet
) {
1597 pr_err("cannot change array size in same operation as changing raiddisks or level.\n"
1598 " Change size first, then check that data is still intact.\n");
1602 if (sysfs_init(&sra
, mdfd
, NULL
)) {
1606 if (array_size
== MAX_SIZE
)
1607 err
= sysfs_set_str(&sra
, NULL
, "array_size", "default");
1609 err
= sysfs_set_num(&sra
, NULL
, "array_size", array_size
/ 2);
1612 pr_err("--array-size setting is too large.\n");
1614 pr_err("current kernel does not support setting --array-size\n");
1619 if (devs_found
> 1 && s
.raiddisks
== 0 && s
.level
== UnSet
) {
1621 if (s
.size
> 0 || s
.chunk
||
1622 s
.layout_str
|| s
.btype
!= BitmapUnknown
) {
1623 pr_err("--add cannot be used with other geometry changes in --grow mode\n");
1627 for (dv
= devlist
->next
; dv
; dv
= dv
->next
) {
1628 rv
= Grow_Add_device(ident
.devname
, mdfd
, dv
->devname
);
1632 } else if (s
.btype
!= BitmapUnknown
) {
1633 if (s
.size
> 0 || s
.raiddisks
|| s
.chunk
||
1634 s
.layout_str
|| devs_found
> 1) {
1635 pr_err("--bitmap changes cannot be used with other geometry changes in --grow mode\n");
1640 c
.delay
= DEFAULT_BITMAP_DELAY
;
1641 rv
= Grow_addbitmap(ident
.devname
, mdfd
, &c
, &s
);
1642 } else if (grow_continue
)
1643 rv
= Grow_continue_command(ident
.devname
, mdfd
, &c
);
1644 else if (s
.size
> 0 || s
.raiddisks
|| s
.layout_str
||
1645 s
.chunk
!= 0 || s
.level
!= UnSet
||
1646 s
.data_offset
!= INVALID_SECTORS
) {
1647 rv
= Grow_reshape(ident
.devname
, mdfd
, devlist
->next
, &c
, &s
);
1648 } else if (s
.consistency_policy
!= CONSISTENCY_POLICY_UNKNOWN
) {
1649 rv
= Grow_consistency_policy(ident
.devname
, mdfd
, &c
, &s
);
1650 } else if (array_size
== 0)
1651 pr_err("no changes to --grow\n");
1660 pr_err("In --incremental mode, a device cannot be given with --scan.\n");
1663 if (c
.runstop
<= 0) {
1664 pr_err("--incremental --scan meaningless without --run.\n");
1667 if (devmode
== 'f') {
1668 pr_err("--incremental --scan --fail not supported.\n");
1671 rv
= IncrementalScan(&c
, NULL
);
1674 if (!rebuild_map
&& !c
.scan
) {
1675 pr_err("--incremental requires a device.\n");
1680 if (devmode
== 'f') {
1681 if (devlist
->next
) {
1682 pr_err("'--incremental --fail' can only handle one device.\n");
1686 rv
= Incremental_remove(devlist
->devname
, remove_path
, c
.verbose
);
1688 rv
= Incremental(devlist
, &c
, ss
);
1695 ss
->ss
->free_super(ss
);
1699 cluster_release_dlmlock();
1704 static int scan_assemble(struct supertype
*ss
,
1706 struct mddev_ident
*ident
)
1708 struct mddev_ident
*a
, *array_list
= conf_get_ident(NULL
);
1709 struct mddev_dev
*devlist
= conf_get_devs();
1710 struct map_ent
*map
= NULL
;
1713 int failures
, successes
;
1715 if (conf_verify_devnames(array_list
)) {
1716 pr_err("Duplicate MD device names in conf file were found.\n");
1719 if (devlist
== NULL
) {
1720 pr_err("No devices listed in conf file were found.\n");
1724 for (a
= array_list
; a
; a
= a
->next
)
1728 pr_err("failed to get exclusive lock on mapfile\n");
1733 for (a
= array_list
; a
; a
= a
->next
) {
1737 if (a
->devname
&& is_devname_ignore(a
->devname
) == true)
1740 r
= Assemble(ss
, a
->devname
,
1750 } while (failures
&& successes
);
1751 if (c
->homehost
&& cnt
== 0) {
1752 /* Maybe we can auto-assemble something.
1753 * Repeatedly call Assemble in auto-assemble mode
1760 struct mddev_dev
*devlist
= conf_get_devs();
1763 rv2
= Assemble(ss
, NULL
,
1771 /* Incase there are stacked devices, we need to go around again */
1773 if (cnt
== 0 && rv
== 0) {
1774 pr_err("No arrays found in config file or automatically\n");
1778 } else if (cnt
== 0 && rv
== 0) {
1779 pr_err("No arrays found in config file\n");
1786 static int misc_scan(char devmode
, struct context
*c
)
1788 /* apply --detail or --wait-clean to
1789 * all devices in /proc/mdstat
1791 struct mdstat_ent
*ms
= mdstat_read(0, 1);
1792 struct mdstat_ent
*e
;
1793 struct map_ent
*map
= NULL
;
1797 for (members
= 0; members
<= 1; members
++) {
1798 for (e
= ms
; e
; e
= e
->next
) {
1802 int member
= e
->metadata_version
&&
1803 strncmp(e
->metadata_version
,
1804 "external:/", 10) == 0;
1805 if (members
!= member
)
1807 me
= map_by_devnm(&map
, e
->devnm
);
1808 if (me
&& me
->path
&& strcmp(me
->path
, "/unknown") != 0)
1810 if (name
== NULL
|| stat(name
, &stb
) != 0)
1811 name
= get_md_name(e
->devnm
);
1814 pr_err("cannot find device file for %s\n",
1819 rv
|= Detail(name
, c
);
1821 rv
|= WaitClean(name
, c
->verbose
);
1831 static int stop_scan(int verbose
)
1833 /* apply --stop to all devices in /proc/mdstat */
1834 /* Due to possible stacking of devices, repeat until
1835 * nothing more can be stopped
1837 int progress
= 1, err
;
1841 struct mdstat_ent
*ms
= mdstat_read(0, 0);
1842 struct mdstat_ent
*e
;
1844 if (!progress
) last
= 1;
1845 progress
= 0; err
= 0;
1846 for (e
= ms
; e
; e
= e
->next
) {
1847 char *name
= get_md_name(e
->devnm
);
1851 pr_err("cannot find device file for %s\n",
1855 mdfd
= open_mddev(name
, 1);
1857 if (Manage_stop(name
, mdfd
, verbose
, !last
))
1867 } while (!last
&& err
);
1873 static int misc_list(struct mddev_dev
*devlist
,
1874 struct mddev_ident
*ident
,
1875 char *dump_directory
,
1876 struct supertype
*ss
, struct context
*c
)
1878 struct mddev_dev
*dv
;
1881 for (dv
= devlist
; dv
; dv
= (rv
& 16) ? NULL
: dv
->next
) {
1884 switch(dv
->disposition
) {
1886 rv
|= Detail(dv
->devname
, c
);
1888 case KillOpt
: /* Zero superblock */
1890 rv
|= Kill(dv
->devname
, ss
, c
->force
, c
->verbose
,0);
1894 rv
|= Kill(dv
->devname
, NULL
, c
->force
, v
, 0);
1901 rv
|= Query(dv
->devname
);
1904 rv
|= ExamineBitmap(dv
->devname
, c
->brief
, ss
);
1907 rv
|= ExamineBadblocks(dv
->devname
, c
->brief
, ss
);
1911 rv
|= Wait(dv
->devname
);
1914 rv
|= WaitClean(dv
->devname
, c
->verbose
);
1917 rv
|= Kill_subarray(dv
->devname
, c
->subarray
, c
->verbose
);
1919 case UpdateSubarray
:
1921 pr_err("-U/--update must be specified with --update-subarray\n");
1925 rv
|= Update_subarray(dv
->devname
, c
->subarray
,
1926 c
->update
, ident
, c
->verbose
);
1929 rv
|= Dump_metadata(dv
->devname
, dump_directory
, c
, ss
);
1932 rv
|= Restore_metadata(dv
->devname
, dump_directory
, c
, ss
,
1933 (dv
== devlist
&& dv
->next
== NULL
));
1936 rv
|= SetAction(dv
->devname
, c
->action
);
1940 if (dv
->devname
[0] != '/')
1941 mdfd
= open_dev(dv
->devname
);
1942 if (dv
->devname
[0] == '/' || mdfd
< 0)
1943 mdfd
= open_mddev(dv
->devname
, 1);
1946 switch(dv
->disposition
) {
1949 rv
|= Manage_run(dv
->devname
, mdfd
, c
);
1953 pr_err("--stop not meaningful with both a --scan assembly and a device name.\n");
1957 rv
|= Manage_stop(dv
->devname
, mdfd
, c
->verbose
, 0);
1960 rv
|= Manage_ro(dv
->devname
, mdfd
, 1);
1963 rv
|= Manage_ro(dv
->devname
, mdfd
, -1);
1973 int SetAction(char *dev
, char *action
)
1975 int fd
= open(dev
, O_RDONLY
);
1980 pr_err("Couldn't open %s: %s\n", dev
, strerror(errno
));
1983 retval
= sysfs_init(&mdi
, fd
, NULL
);
1986 pr_err("%s is no an md array\n", dev
);
1990 if (sysfs_set_str(&mdi
, NULL
, "sync_action", action
) < 0) {
1991 pr_err("Count not set action for %s to %s: %s\n",
1992 dev
, action
, strerror(errno
));