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 struct mddev_ident ident
;
53 char *configfile
= NULL
;
56 struct mddev_dev
*devlist
= NULL
;
57 struct mddev_dev
**devlistend
= & devlist
;
59 mdu_array_info_t array
;
61 int grow_continue
= 0;
62 /* autof indicates whether and how to create device node.
63 * bottom 3 bits are style. Rest (when shifted) are number of parts
65 * 1 - don't create (no)
66 * 2 - if is_standard, then create (yes)
67 * 3 - create as 'md' - reject is_standard mdp (md)
68 * 4 - create as 'mdp' - reject is_standard md (mdp)
69 * 5 - default to md if not is_standard (md in config file)
70 * 6 - default to mdp if not is_standard (part, or mdp in config file)
73 .require_homehost
= 1,
79 .bitmap_chunk
= UnSet
,
80 .consistency_policy
= CONSISTENCY_POLICY_UNKNOWN
,
81 .data_offset
= INVALID_SECTORS
,
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
;
108 srandom(time(0) ^ getpid());
110 if (get_linux_version() < 2006015) {
111 pr_err("This version of mdadm does not support kernels older than 2.6.15\n");
117 while ((option_index
= -1),
118 (opt
= getopt_long(argc
, argv
, shortopt
, long_options
,
119 &option_index
)) != -1) {
121 /* firstly, some mode-independent options */
131 fputs(Version
, stderr
);
134 case 'v': c
.verbose
++;
137 case 'q': c
.verbose
--;
141 if (mode
== ASSEMBLE
|| mode
== BUILD
||
142 mode
== CREATE
|| mode
== GROW
||
143 mode
== INCREMENTAL
|| mode
== MANAGE
)
144 break; /* b means bitmap */
153 case 'Y': c
.export
++;
157 if (strcasecmp(optarg
, "<ignore>") == 0)
158 c
.require_homehost
= 0;
164 /* Silently ignore old option */
170 if (asprintf(&c
.prefer
, "/%s/", optarg
) <= 0)
176 fputs(Usage
, stderr
);
179 /* second, figure out the mode.
180 * Some options force the mode. Others
181 * set the mode if it isn't already
187 shortopt
= short_bitmap_options
;
199 case ReAdd
: /* re-add */
203 shortopt
= short_bitmap_options
;
207 case 'A': newmode
= ASSEMBLE
;
208 shortopt
= short_bitmap_auto_options
;
210 case 'B': newmode
= BUILD
;
211 shortopt
= short_bitmap_auto_options
;
213 case 'C': newmode
= CREATE
;
214 shortopt
= short_bitmap_auto_options
;
216 case 'F': newmode
= MONITOR
;
217 shortopt
= short_monitor_options
;
219 case 'G': newmode
= GROW
;
220 shortopt
= short_bitmap_options
;
222 case 'I': newmode
= INCREMENTAL
;
223 shortopt
= short_bitmap_auto_options
;
226 newmode
= AUTODETECT
;
261 if (mode
&& newmode
== mode
) {
262 /* everybody happy ! */
263 } else if (mode
&& newmode
!= mode
) {
266 if (option_index
>= 0)
267 fprintf(stderr
, "--%s", long_options
[option_index
].name
);
269 fprintf(stderr
, "-%c", opt
);
270 fprintf(stderr
, " would set mdadm mode to \"%s\", but it is already set to \"%s\".\n",
271 map_num_s(modes
, newmode
),
272 map_num_s(modes
, mode
));
274 } else if (!mode
&& newmode
) {
276 if (mode
== MISC
&& devs_found
) {
277 pr_err("No action given for %s in --misc mode\n",
279 cont_err("Action options must come before device names\n");
283 /* special case of -c --help */
284 if ((opt
== 'c' || opt
== ConfigFile
) &&
285 (strncmp(optarg
, "--h", 3) == 0 ||
286 strncmp(optarg
, "-h", 2) == 0)) {
287 fputs(Help_config
, stdout
);
291 /* If first option is a device, don't force the mode yet */
293 if (devs_found
== 0) {
294 dv
= xmalloc(sizeof(*dv
));
295 dv
->devname
= optarg
;
296 dv
->disposition
= devmode
;
297 dv
->writemostly
= writemostly
;
298 dv
->failfast
= failfast
;
302 devlistend
= &dv
->next
;
307 /* No mode yet, and this is the second device ... */
308 pr_err("An option must be given to set the mode before a second device\n"
309 " (%s) is listed\n", optarg
);
312 if (option_index
>= 0)
313 pr_err("--%s", long_options
[option_index
].name
);
316 fprintf(stderr
, " does not set the mode, and so cannot be the first option.\n");
320 /* if we just set the mode, then done */
334 /* an undecorated option - must be a device name.
337 if (devs_found
> 0 && devmode
== DetailPlatform
) {
338 pr_err("controller may only be specified once. %s ignored\n",
343 if (devs_found
> 0 && mode
== MANAGE
&& !devmode
) {
344 pr_err("Must give one of -a/-r/-f for subsequent devices at %s\n", optarg
);
347 if (devs_found
> 0 && mode
== GROW
&& !devmode
) {
348 pr_err("Must give -a/--add for devices to add: %s\n", optarg
);
351 dv
= xmalloc(sizeof(*dv
));
352 dv
->devname
= optarg
;
353 dv
->disposition
= devmode
;
354 dv
->writemostly
= writemostly
;
355 dv
->failfast
= failfast
;
359 devlistend
= &dv
->next
;
365 /* We've got a mode, and opt is now something else which
366 * could depend on the mode */
367 #define O(a,b) ((a<<16)|b)
368 switch (O(mode
,opt
)) {
370 case O(GROW
,ChunkSize
):
372 case O(CREATE
,ChunkSize
):
373 case O(BUILD
,'c'): /* chunk or rounding */
374 case O(BUILD
,ChunkSize
): /* chunk or rounding */
376 pr_err("chunk/rounding may only be specified once. Second value is %s.\n", optarg
);
379 s
.chunk
= parse_size(optarg
);
380 if (s
.chunk
== INVALID_SECTORS
||
381 s
.chunk
< 8 || (s
.chunk
&1)) {
382 pr_err("invalid chunk/rounding value: %s\n",
386 /* Convert sectors to K */
390 case O(INCREMENTAL
, 'e'):
392 case O(ASSEMBLE
,'e'):
393 case O(MISC
,'e'): /* set metadata (superblock) information */
395 pr_err("metadata information already given\n");
398 for(i
= 0; !ss
&& superlist
[i
]; i
++)
399 ss
= superlist
[i
]->match_metadata_desc(optarg
);
402 pr_err("unrecognised metadata identifier: %s\n", optarg
);
408 case O(MANAGE
,WriteMostly
):
410 case O(BUILD
,WriteMostly
):
412 case O(CREATE
,WriteMostly
):
413 /* set write-mostly for following devices */
414 writemostly
= FlagSet
;
418 /* clear write-mostly for following devices */
419 writemostly
= FlagClear
;
422 case O(MANAGE
,FailFast
):
423 case O(CREATE
,FailFast
):
426 case O(MANAGE
,NoFailFast
):
427 failfast
= FlagClear
;
432 case O(BUILD
,'z'): /* size */
434 pr_err("size may only be specified once. Second value is %s.\n", optarg
);
437 if (strcmp(optarg
, "max") == 0)
440 s
.size
= parse_size(optarg
);
441 if (s
.size
== INVALID_SECTORS
|| s
.size
< 8) {
442 pr_err("invalid size: %s\n", optarg
);
445 /* convert sectors to K */
450 case O(GROW
,'Z'): /* array size */
451 if (array_size
> 0) {
452 pr_err("array-size may only be specified once. Second value is %s.\n", optarg
);
455 if (strcmp(optarg
, "max") == 0)
456 array_size
= MAX_SIZE
;
458 array_size
= parse_size(optarg
);
459 if (array_size
== 0 ||
460 array_size
== INVALID_SECTORS
) {
461 pr_err("invalid array size: %s\n",
468 case O(CREATE
,DataOffset
):
469 case O(GROW
,DataOffset
):
470 if (s
.data_offset
!= INVALID_SECTORS
) {
471 pr_err("data-offset may only be specified one. Second value is %s.\n", optarg
);
474 if (mode
== CREATE
&& strcmp(optarg
, "variable") == 0)
475 s
.data_offset
= VARIABLE_OFFSET
;
477 s
.data_offset
= parse_size(optarg
);
478 if (s
.data_offset
== INVALID_SECTORS
) {
479 pr_err("invalid data-offset: %s\n",
487 case O(BUILD
,'l'): /* set raid level*/
488 if (s
.level
!= UnSet
) {
489 pr_err("raid level may only be set once. Second value is %s.\n", optarg
);
492 s
.level
= map_name(pers
, optarg
);
493 if (s
.level
== UnSet
) {
494 pr_err("invalid raid level: %s\n",
498 if (s
.level
!= 0 && s
.level
!= LEVEL_LINEAR
&&
499 s
.level
!= 1 && s
.level
!= LEVEL_MULTIPATH
&&
500 s
.level
!= LEVEL_FAULTY
&& s
.level
!= 10 &&
502 pr_err("Raid level %s not permitted with --build.\n",
506 if (s
.sparedisks
> 0 && s
.level
< 1 && s
.level
>= -1) {
507 pr_err("raid level %s is incompatible with spare-devices setting.\n",
511 ident
.level
= s
.level
;
514 case O(GROW
, 'p'): /* new layout */
515 case O(GROW
, Layout
):
517 pr_err("layout may only be sent once. Second value was %s\n", optarg
);
520 s
.layout_str
= optarg
;
521 /* 'Grow' will parse the value */
524 case O(CREATE
,'p'): /* raid5 layout */
525 case O(CREATE
,Layout
):
526 case O(BUILD
,'p'): /* faulty layout */
527 case O(BUILD
,Layout
):
528 if (s
.layout
!= UnSet
) {
529 pr_err("layout may only be sent once. Second value was %s\n", optarg
);
534 pr_err("layout not meaningful for %s arrays.\n",
535 map_num_s(pers
, s
.level
));
538 pr_err("raid level must be given before layout.\n");
542 s
.layout
= map_name(r0layout
, optarg
);
543 if (s
.layout
== UnSet
) {
544 pr_err("layout %s not understood for raid0.\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 if (parse_num(&s
.raiddisks
, optarg
) != 0 || s
.raiddisks
<= 0) {
602 pr_err("invalid number of raid devices: %s\n",
606 ident
.raid_disks
= s
.raiddisks
;
608 case O(ASSEMBLE
, Nodes
):
610 case O(CREATE
, Nodes
):
611 if (parse_num(&c
.nodes
, optarg
) != 0 || c
.nodes
< 2) {
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 if (parse_num(&s
.sparedisks
, optarg
) != 0 || s
.sparedisks
< 0) {
637 pr_err("invalid number of spare-devices: %s\n",
647 case O(INCREMENTAL
,'a'):
648 case O(INCREMENTAL
,Auto
):
649 case O(ASSEMBLE
,'a'):
650 case O(ASSEMBLE
,Auto
): /* auto-creation of device node */
651 c
.autof
= parse_auto(optarg
, "--auto flag", 0);
653 case O(BUILD
,'f'): /* force honouring '-n 1' */
654 case O(BUILD
,Force
): /* force honouring '-n 1' */
655 case O(GROW
,'f'): /* ditto */
656 case O(GROW
,Force
): /* ditto */
657 case O(CREATE
,'f'): /* force honouring of device list */
658 case O(CREATE
,Force
): /* force honouring of device list */
659 case O(ASSEMBLE
,'f'): /* force assembly */
660 case O(ASSEMBLE
,Force
): /* force assembly */
661 case O(MISC
,'f'): /* force zero */
662 case O(MISC
,Force
): /* force zero */
663 case O(MANAGE
,Force
): /* add device which is too large */
666 /* now for the Assemble options */
667 case O(ASSEMBLE
, FreezeReshape
): /* Freeze reshape during
669 case O(INCREMENTAL
, FreezeReshape
):
670 c
.freeze_reshape
= 1;
672 case O(CREATE
,'u'): /* uuid of array */
673 case O(ASSEMBLE
,'u'): /* uuid of array */
674 if (ident
.uuid_set
) {
675 pr_err("uuid cannot be set twice. Second value %s.\n", optarg
);
678 if (parse_uuid(optarg
, ident
.uuid
))
681 pr_err("Bad uuid: %s\n", optarg
);
687 case O(ASSEMBLE
,'N'):
690 pr_err("name cannot be set twice. Second value %s.\n", optarg
);
693 if (mode
== MISC
&& !c
.subarray
) {
694 pr_err("-N/--name only valid with --update-subarray in misc mode\n");
697 if (strlen(optarg
) > 32) {
698 pr_err("name '%s' is too long, 32 chars max.\n",
702 strcpy(ident
.name
, optarg
);
705 case O(ASSEMBLE
,'m'): /* super-minor for array */
706 case O(ASSEMBLE
,SuperMinor
):
707 if (ident
.super_minor
!= UnSet
) {
708 pr_err("super-minor cannot be set twice. Second value: %s.\n", optarg
);
711 if (strcmp(optarg
, "dev") == 0)
712 ident
.super_minor
= -2;
713 else if (parse_num(&ident
.super_minor
, optarg
) != 0 || ident
.super_minor
< 0) {
714 pr_err("Bad super-minor number: %s.\n", optarg
);
719 case O(ASSEMBLE
,'o'):
725 case O(ASSEMBLE
,'U'): /* update the superblock */
727 enum update_opt print_mode
= UOPT_HELP
;
728 const char *error_addon
= "update option";
731 pr_err("Can only update one aspect of superblock, both %s and %s given.\n",
732 map_num(update_options
, c
.update
), optarg
);
735 if (mode
== MISC
&& !c
.subarray
) {
736 pr_err("Only subarrays can be updated in misc mode\n");
740 c
.update
= map_name(update_options
, optarg
);
742 if (devmode
== UpdateSubarray
) {
743 print_mode
= UOPT_SUBARRAY_ONLY
;
744 error_addon
= "update-subarray option";
746 if (c
.update
> UOPT_SUBARRAY_ONLY
&& c
.update
< UOPT_HELP
)
747 c
.update
= UOPT_UNDEFINED
;
752 pr_err("'--update=%s' is invalid %s. ",
753 optarg
, error_addon
);
758 fprint_update_options(outf
, print_mode
);
759 exit(outf
== stdout
? 0 : 2);
762 pr_err("must not set metadata type with --update=byteorder.\n");
771 /* update=devicesize is allowed with --re-add */
772 if (devmode
!= 'A') {
773 pr_err("--update in Manage mode only allowed with --re-add.\n");
777 pr_err("Can only update one aspect of superblock, both %s and %s given.\n",
778 map_num(update_options
, c
.update
), optarg
);
781 c
.update
= map_name(update_options
, optarg
);
782 if (c
.update
!= UOPT_DEVICESIZE
&&
783 c
.update
!= UOPT_BBL
&&
784 c
.update
!= UOPT_NO_BBL
&&
785 c
.update
!= UOPT_FORCE_NO_BBL
) {
786 pr_err("only 'devicesize', 'bbl', 'no-bbl', and 'force-no-bbl' can be updated with --re-add\n");
791 case O(INCREMENTAL
,NoDegraded
):
792 pr_err("--no-degraded is deprecated in Incremental mode\n");
793 case O(ASSEMBLE
,NoDegraded
): /* --no-degraded */
794 c
.runstop
= -1; /* --stop isn't allowed for --assemble,
795 * so we overload slightly */
798 case O(ASSEMBLE
,'c'):
799 case O(ASSEMBLE
,ConfigFile
):
800 case O(INCREMENTAL
, 'c'):
801 case O(INCREMENTAL
, ConfigFile
):
803 case O(MISC
, ConfigFile
):
805 case O(MONITOR
,ConfigFile
):
806 case O(CREATE
,ConfigFile
):
808 pr_err("configfile cannot be set twice. Second value is %s.\n", optarg
);
812 set_conffile(configfile
);
813 /* FIXME possibly check that config file exists. Even parse it */
815 case O(ASSEMBLE
,'s'): /* scan */
818 case O(INCREMENTAL
,'s'):
822 case O(MONITOR
,'m'): /* mail address */
823 case O(MONITOR
,EMail
):
825 pr_err("only specify one mailaddress. %s ignored.\n",
831 case O(MONITOR
,'p'): /* alert program */
832 case O(MONITOR
,ProgramOpt
): /* alert program */
834 pr_err("only specify one alter program. %s ignored.\n",
840 case O(MONITOR
,'r'): /* rebuild increments */
841 case O(MONITOR
,Increment
):
842 if (parse_num(&increments
, optarg
) != 0
843 || increments
> 99 || increments
< 1) {
844 pr_err("please specify positive integer between 1 and 99 as rebuild increments.\n");
849 case O(MONITOR
,'d'): /* delay in seconds */
851 case O(BUILD
,'d'): /* delay for bitmap updates */
854 pr_err("only specify delay once. %s ignored.\n", optarg
);
855 else if (parse_num(&c
.delay
, optarg
) != 0 || c
.delay
< 1) {
856 pr_err("invalid delay: %s\n", optarg
);
860 case O(MONITOR
,'f'): /* daemonise */
861 case O(MONITOR
,Fork
):
864 case O(MONITOR
,'i'): /* pid */
866 pr_err("only specify one pid file. %s ignored.\n",
871 case O(MONITOR
,'1'): /* oneshot */
875 case O(MONITOR
,'t'): /* test */
878 case O(MONITOR
,'y'): /* log messages to syslog */
879 openlog("mdadm", LOG_PID
, SYSLOG_FACILITY
);
882 case O(MONITOR
, NoSharing
):
886 /* now the general management options. Some are applicable
887 * to other modes. None have arguments.
892 case O(MANAGE
,Add
): /* add a drive */
895 case O(MANAGE
,AddSpare
): /* add drive - never re-add */
898 case O(MANAGE
,AddJournal
): /* add journal */
899 if (s
.journaldisks
&& (s
.level
< 4 || s
.level
> 6)) {
900 pr_err("--add-journal is only supported for RAID level 4/5/6.\n");
905 case O(MANAGE
,ReAdd
):
908 case O(MANAGE
,'r'): /* remove a drive */
909 case O(MANAGE
,Remove
):
912 case O(MANAGE
,'f'): /* set faulty */
914 case O(INCREMENTAL
,'f'):
915 case O(INCREMENTAL
,Remove
):
916 case O(INCREMENTAL
,Fail
): /* r for incremental is taken, use f
917 * even though we will both fail and
918 * remove the device */
921 case O(MANAGE
, ClusterConfirm
):
924 case O(MANAGE
,Replace
):
925 /* Mark these devices for replacement */
929 /* These are the replacements to use */
930 if (devmode
!= 'R') {
931 pr_err("--with must follow --replace\n");
936 case O(INCREMENTAL
,'R'):
938 case O(ASSEMBLE
,'R'):
940 case O(CREATE
,'R'): /* Run the array */
942 pr_err("Cannot both Stop and Run an array\n");
949 pr_err("Cannot both Run and Stop an array\n");
961 case O(MISC
,KillOpt
):
965 case O(MISC
, ExamineBB
):
969 case O(MISC
, WaitOpt
):
970 case O(MISC
, Waitclean
):
971 case O(MISC
, DetailPlatform
):
972 case O(MISC
, KillSubarray
):
973 case O(MISC
, UpdateSubarray
):
975 case O(MISC
, Restore
):
976 case O(MISC
,Action
):
977 if (opt
== KillSubarray
|| opt
== UpdateSubarray
) {
979 pr_err("subarray can only be specified once\n");
986 pr_err("Only one --action can be specified\n");
989 if (strcmp(optarg
, "idle") == 0 ||
990 strcmp(optarg
, "frozen") == 0 ||
991 strcmp(optarg
, "check") == 0 ||
992 strcmp(optarg
, "repair") == 0)
995 pr_err("action must be one of idle, frozen, check, repair\n");
999 if (devmode
&& devmode
!= opt
&&
1001 (opt
== 'E' && devmode
!= 'Q'))) {
1002 pr_err("--examine/-E cannot be given with ");
1003 if (devmode
== 'E') {
1004 if (option_index
>= 0)
1005 fprintf(stderr
, "--%s\n",
1006 long_options
[option_index
].name
);
1008 fprintf(stderr
, "-%c\n", opt
);
1009 } else if (isalpha(devmode
))
1010 fprintf(stderr
, "-%c\n", devmode
);
1012 fprintf(stderr
, "previous option\n");
1016 if (opt
== Dump
|| opt
== Restore
) {
1017 if (dump_directory
!= NULL
) {
1018 pr_err("dump/restore directory specified twice: %s and %s\n",
1019 dump_directory
, optarg
);
1022 dump_directory
= optarg
;
1025 case O(MISC
, UdevRules
):
1026 if (devmode
&& devmode
!= opt
) {
1027 pr_err("--udev-rules must be the only option.\n");
1030 pr_err("only specify one udev rule filename. %s ignored.\n",
1033 udev_filename
= optarg
;
1041 case O(MISC
, Sparc22
):
1042 if (devmode
!= 'E') {
1043 pr_err("--sparc2.2 only allowed with --examine\n");
1049 case O(ASSEMBLE
,'b'): /* here we simply set the bitmap file */
1050 case O(ASSEMBLE
,Bitmap
):
1052 pr_err("bitmap file needed with -b in --assemble mode\n");
1055 if (strcmp(optarg
, "internal") == 0 ||
1056 strcmp(optarg
, "clustered") == 0) {
1057 pr_err("no need to specify --bitmap when assembling"
1058 " arrays with internal or clustered bitmap\n");
1061 bitmap_fd
= open(optarg
, O_RDWR
);
1062 if (!*optarg
|| bitmap_fd
< 0) {
1063 pr_err("cannot open bitmap file %s: %s\n", optarg
, strerror(errno
));
1066 ident
.bitmap_fd
= bitmap_fd
; /* for Assemble */
1069 case O(ASSEMBLE
, BackupFile
):
1070 case O(GROW
, BackupFile
):
1071 /* Specify a file into which grow might place a backup,
1072 * or from which assemble might recover a backup
1074 if (c
.backup_file
) {
1075 pr_err("backup file already specified, rejecting %s\n", optarg
);
1078 c
.backup_file
= optarg
;
1081 case O(GROW
, Continue
):
1082 /* Continue interrupted grow
1086 case O(ASSEMBLE
, InvalidBackup
):
1087 /* Acknowledge that the backupfile is invalid, but ask
1088 * to continue anyway
1090 c
.invalid_backup
= 1;
1094 case O(BUILD
,Bitmap
):
1096 case O(CREATE
,Bitmap
): /* here we create the bitmap */
1098 case O(GROW
,Bitmap
):
1099 if (s
.bitmap_file
) {
1100 pr_err("bitmap cannot be set twice. Second value: %s.\n", optarg
);
1103 if (strcmp(optarg
, "internal") == 0 ||
1104 strcmp(optarg
, "none") == 0 ||
1105 strchr(optarg
, '/') != NULL
) {
1106 s
.bitmap_file
= optarg
;
1109 if (strcmp(optarg
, "clustered") == 0) {
1110 s
.bitmap_file
= optarg
;
1111 /* Set the default number of cluster nodes
1112 * to 4 if not already set by user
1119 pr_err("bitmap file must contain a '/', or be 'internal', or be 'clustered', or 'none'\n"
1120 " not '%s'\n", optarg
);
1123 case O(GROW
,BitmapChunk
):
1124 case O(BUILD
,BitmapChunk
):
1125 case O(CREATE
,BitmapChunk
): /* bitmap chunksize */
1126 s
.bitmap_chunk
= parse_size(optarg
);
1127 if (s
.bitmap_chunk
== 0 ||
1128 s
.bitmap_chunk
== INVALID_SECTORS
||
1129 s
.bitmap_chunk
& (s
.bitmap_chunk
- 1)) {
1130 pr_err("invalid bitmap chunksize: %s\n",
1134 s
.bitmap_chunk
= s
.bitmap_chunk
* 512;
1137 case O(GROW
, WriteBehind
):
1138 case O(BUILD
, WriteBehind
):
1139 case O(CREATE
, WriteBehind
):
1140 s
.write_behind
= DEFAULT_MAX_WRITE_BEHIND
;
1142 (parse_num(&s
.write_behind
, optarg
) != 0 ||
1143 s
.write_behind
< 0 || s
.write_behind
> 16383)) {
1144 pr_err("Invalid value for maximum outstanding write-behind writes: %s.\n\tMust be between 0 and 16383.\n",
1149 case O(INCREMENTAL
, 'r'):
1150 case O(INCREMENTAL
, RebuildMapOpt
):
1153 case O(INCREMENTAL
, IncrementalPath
):
1154 remove_path
= optarg
;
1156 case O(CREATE
, WriteJournal
):
1157 if (s
.journaldisks
) {
1158 pr_err("Please specify only one journal device for the array.\n");
1159 pr_err("Ignoring --write-journal %s...\n", optarg
);
1162 dv
= xmalloc(sizeof(*dv
));
1163 dv
->devname
= optarg
;
1164 dv
->disposition
= 'j'; /* WriteJournal */
1168 devlistend
= &dv
->next
;
1173 case O(CREATE
, 'k'):
1175 s
.consistency_policy
= map_name(consistency_policies
,
1177 if (s
.consistency_policy
< CONSISTENCY_POLICY_RESYNC
) {
1178 pr_err("Invalid consistency policy: %s\n",
1184 /* We have now processed all the valid options. Anything else is
1187 if (option_index
> 0)
1188 pr_err(":option --%s not valid in %s mode\n",
1189 long_options
[option_index
].name
,
1190 map_num_s(modes
, mode
));
1192 pr_err("option -%c not valid in %s mode\n",
1193 opt
, map_num_s(modes
, mode
));
1200 if (print_help
== 2)
1201 help_text
= OptionHelp
;
1203 help_text
= mode_help
[mode
];
1204 if (help_text
== NULL
)
1206 fputs(help_text
,stdout
);
1210 if (s
.journaldisks
) {
1211 if (s
.level
< 4 || s
.level
> 6) {
1212 pr_err("--write-journal is only supported for RAID level 4/5/6.\n");
1215 if (s
.consistency_policy
!= CONSISTENCY_POLICY_UNKNOWN
&&
1216 s
.consistency_policy
!= CONSISTENCY_POLICY_JOURNAL
) {
1217 pr_err("--write-journal is not supported with consistency policy: %s\n",
1218 map_num_s(consistency_policies
, s
.consistency_policy
));
1223 if (mode
== CREATE
&&
1224 s
.consistency_policy
!= CONSISTENCY_POLICY_UNKNOWN
) {
1226 pr_err("--consistency-policy not meaningful with level %s.\n",
1227 map_num_s(pers
, s
.level
));
1229 } else if (s
.consistency_policy
== CONSISTENCY_POLICY_JOURNAL
&&
1231 pr_err("--write-journal is required for consistency policy: %s\n",
1232 map_num_s(consistency_policies
, s
.consistency_policy
));
1234 } else if (s
.consistency_policy
== CONSISTENCY_POLICY_PPL
&&
1236 pr_err("PPL consistency policy is only supported for RAID level 5.\n");
1238 } else if (s
.consistency_policy
== CONSISTENCY_POLICY_BITMAP
&&
1240 strcmp(s
.bitmap_file
, "none") == 0)) {
1241 pr_err("--bitmap is required for consistency policy: %s\n",
1242 map_num_s(consistency_policies
, s
.consistency_policy
));
1244 } else if (s
.bitmap_file
&&
1245 strcmp(s
.bitmap_file
, "none") != 0 &&
1246 s
.consistency_policy
!= CONSISTENCY_POLICY_BITMAP
&&
1247 s
.consistency_policy
!= CONSISTENCY_POLICY_JOURNAL
) {
1248 pr_err("--bitmap is not compatible with consistency policy: %s\n",
1249 map_num_s(consistency_policies
, s
.consistency_policy
));
1254 if (!mode
&& devs_found
) {
1257 if (devlist
->disposition
== 0)
1258 devlist
->disposition
= devmode
;
1261 fputs(Usage
, stderr
);
1265 /* Ok, got the option parsing out of the way
1266 * hopefully it's mostly right but there might be some stuff
1269 * That is mostly checked in the per-mode stuff but...
1271 * For @,B,C and A without -s, the first device listed must be
1272 * an md device. We check that here and open it.
1275 if (mode
== MANAGE
|| mode
== BUILD
|| mode
== CREATE
||
1276 mode
== GROW
|| (mode
== ASSEMBLE
&& ! c
.scan
)) {
1280 if (devs_found
< 1) {
1281 pr_err("an md device must be given in this mode\n");
1284 if ((int)ident
.super_minor
== -2 && c
.autof
) {
1285 pr_err("--super-minor=dev is incompatible with --auto\n");
1288 if (mode
== MANAGE
|| mode
== GROW
) {
1289 mdfd
= open_mddev(devlist
->devname
, 1);
1293 ret
= fstat(mdfd
, &stb
);
1295 pr_err("fstat failed on %s.\n", devlist
->devname
);
1299 char *bname
= basename(devlist
->devname
);
1301 if (strlen(bname
) > MD_NAME_MAX
) {
1302 pr_err("Name %s is too long.\n", devlist
->devname
);
1306 ret
= stat(devlist
->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", devlist
->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 (gethostname(sys_hostname
, sizeof(sys_hostname
)) == 0) {
1335 sys_hostname
[sizeof(sys_hostname
)-1] = 0;
1336 c
.homehost
= sys_hostname
;
1340 (!c
.homehost
[0] || strcasecmp(c
.homehost
, "<none>") == 0)) {
1342 c
.require_homehost
= 0;
1347 set_hooks(); /* set hooks from libs */
1349 if (c
.homecluster
== NULL
&& (c
.nodes
> 0)) {
1350 c
.homecluster
= conf_get_homecluster();
1351 if (c
.homecluster
== NULL
)
1352 rv
= get_cluster_name(&c
.homecluster
);
1354 pr_err("The md can't get cluster name\n");
1359 if (c
.update
&& c
.update
== UOPT_NODES
&& c
.nodes
== 0) {
1360 pr_err("Please specify nodes number with --nodes\n");
1364 if (c
.backup_file
&& s
.data_offset
!= INVALID_SECTORS
) {
1365 pr_err("--backup-file and --data-offset are incompatible\n");
1369 if ((mode
== MISC
&& devmode
== 'E') ||
1370 (mode
== MONITOR
&& spare_sharing
== 0))
1371 /* Anyone may try this */;
1372 else if (geteuid() != 0) {
1373 pr_err("must be super-user to perform this action\n");
1377 ident
.autof
= c
.autof
;
1379 if (c
.scan
&& c
.verbose
< 2)
1380 /* --scan implied --brief unless -vv */
1383 if (mode
== CREATE
) {
1384 if (s
.bitmap_file
&& strcmp(s
.bitmap_file
, "clustered") == 0) {
1385 locked
= cluster_get_dlmlock();
1389 } else if (mode
== MANAGE
|| mode
== GROW
|| mode
== INCREMENTAL
) {
1390 if (!md_get_array_info(mdfd
, &array
) && (devmode
!= 'c')) {
1391 if (array
.state
& (1 << MD_SB_CLUSTERED
)) {
1392 locked
= cluster_get_dlmlock();
1401 /* readonly, add/remove, readwrite, runstop */
1403 rv
= Manage_ro(devlist
->devname
, mdfd
, c
.readonly
);
1404 if (!rv
&& devs_found
> 1)
1405 rv
= Manage_subdevs(devlist
->devname
, mdfd
,
1406 devlist
->next
, c
.verbose
,
1407 c
.test
, c
.update
, c
.force
);
1408 if (!rv
&& c
.readonly
< 0)
1409 rv
= Manage_ro(devlist
->devname
, mdfd
, c
.readonly
);
1410 if (!rv
&& c
.runstop
> 0)
1411 rv
= Manage_run(devlist
->devname
, mdfd
, &c
);
1412 if (!rv
&& c
.runstop
< 0)
1413 rv
= Manage_stop(devlist
->devname
, mdfd
, c
.verbose
, 0);
1416 if (!c
.scan
&& c
.runstop
== -1) {
1417 pr_err("--no-degraded not meaningful without a --scan assembly.\n");
1419 } else if (devs_found
== 1 && ident
.uuid_set
== 0 &&
1420 ident
.super_minor
== UnSet
&& ident
.name
[0] == 0 &&
1422 /* Only a device has been given, so get details from config file */
1423 struct mddev_ident
*array_ident
= conf_get_ident(devlist
->devname
);
1424 if (array_ident
== NULL
) {
1425 pr_err("%s not identified in config file.\n",
1431 if (array_ident
->autof
== 0)
1432 array_ident
->autof
= c
.autof
;
1433 rv
|= Assemble(ss
, devlist
->devname
, array_ident
,
1437 rv
= Assemble(ss
, devlist
->devname
, &ident
,
1439 else if (devs_found
> 0) {
1440 if (c
.update
&& devs_found
> 1) {
1441 pr_err("can only update a single array at a time\n");
1444 if (c
.backup_file
&& devs_found
> 1) {
1445 pr_err("can only assemble a single array when providing a backup file.\n");
1448 for (dv
= devlist
; dv
; dv
= dv
->next
) {
1449 struct mddev_ident
*array_ident
= conf_get_ident(dv
->devname
);
1450 if (array_ident
== NULL
) {
1451 pr_err("%s not identified in config file.\n",
1456 if (array_ident
->autof
== 0)
1457 array_ident
->autof
= c
.autof
;
1458 rv
|= Assemble(ss
, dv
->devname
, array_ident
,
1463 pr_err("--update not meaningful with a --scan assembly.\n");
1466 if (c
.backup_file
) {
1467 pr_err("--backup_file not meaningful with a --scan assembly.\n");
1470 rv
= scan_assemble(ss
, &c
, &ident
);
1476 c
.delay
= DEFAULT_BITMAP_DELAY
;
1477 if (s
.write_behind
&& !s
.bitmap_file
) {
1478 pr_err("write-behind mode requires a bitmap.\n");
1482 if (s
.raiddisks
== 0) {
1483 pr_err("no raid-devices specified.\n");
1488 if (s
.bitmap_file
) {
1489 if (strcmp(s
.bitmap_file
, "internal") == 0 ||
1490 strcmp(s
.bitmap_file
, "clustered") == 0) {
1491 pr_err("'internal' and 'clustered' bitmaps not supported with --build\n");
1496 rv
= Build(devlist
->devname
, devlist
->next
, &s
, &c
);
1500 c
.delay
= DEFAULT_BITMAP_DELAY
;
1503 if (!s
.bitmap_file
||
1504 strcmp(s
.bitmap_file
, "clustered") != 0) {
1505 pr_err("--nodes argument only compatible with --bitmap=clustered\n");
1510 if (s
.level
!= 1 && s
.level
!= 10) {
1511 pr_err("--bitmap=clustered is currently supported with raid1/10 only\n");
1515 if (s
.level
== 10 && !(is_near_layout_10(s
.layout
) || s
.layout
== UnSet
)) {
1516 pr_err("only near layout is supported with clustered raid10\n");
1522 if (s
.write_behind
&& !s
.bitmap_file
) {
1523 pr_err("write-behind mode requires a bitmap.\n");
1527 if (s
.raiddisks
== 0) {
1528 pr_err("no raid-devices specified.\n");
1533 rv
= Create(ss
, devlist
->devname
,
1534 ident
.name
, ident
.uuid_set
? ident
.uuid
: NULL
,
1535 devs_found
- 1, devlist
->next
, &s
, &c
);
1538 if (devmode
== 'E') {
1539 if (devlist
== NULL
&& !c
.scan
) {
1540 pr_err("No devices to examine\n");
1543 if (devlist
== NULL
)
1544 devlist
= conf_get_devs();
1545 if (devlist
== NULL
) {
1546 pr_err("No devices listed in %s\n", configfile
?configfile
:DefaultConfFile
);
1549 rv
= Examine(devlist
, &c
, ss
);
1550 } else if (devmode
== DetailPlatform
) {
1551 rv
= Detail_Platform(ss
? ss
->ss
: NULL
, ss
? c
.scan
: 1,
1552 c
.verbose
, c
.export
,
1553 devlist
? devlist
->devname
: NULL
);
1554 } else if (devlist
== NULL
) {
1555 if (devmode
== 'S' && c
.scan
)
1556 rv
= stop_scan(c
.verbose
);
1557 else if ((devmode
== 'D' || devmode
== Waitclean
) &&
1559 rv
= misc_scan(devmode
, &c
);
1560 else if (devmode
== UdevRules
)
1561 rv
= Write_rules(udev_filename
);
1563 pr_err("No devices given.\n");
1567 rv
= misc_list(devlist
, &ident
, dump_directory
, ss
, &c
);
1570 if (!devlist
&& !c
.scan
) {
1571 pr_err("Cannot monitor: need --scan or at least one device\n");
1575 if (pidfile
&& !daemonise
) {
1576 pr_err("Cannot write a pid file when not in daemon mode\n");
1581 c
.delay
= conf_get_monitor_delay();
1585 rv
= Monitor(devlist
, mailaddr
, program
,
1586 &c
, daemonise
, oneshot
,
1587 dosyslog
, pidfile
, increments
,
1592 if (array_size
> 0) {
1593 /* alway impose array size first, independent of
1595 * Do not allow level or raid_disks changes at the
1596 * same time as that can be irreversibly destructive.
1600 if (s
.raiddisks
|| s
.level
!= UnSet
) {
1601 pr_err("cannot change array size in same operation as changing raiddisks or level.\n"
1602 " Change size first, then check that data is still intact.\n");
1606 if (sysfs_init(&sra
, mdfd
, NULL
)) {
1610 if (array_size
== MAX_SIZE
)
1611 err
= sysfs_set_str(&sra
, NULL
, "array_size", "default");
1613 err
= sysfs_set_num(&sra
, NULL
, "array_size", array_size
/ 2);
1616 pr_err("--array-size setting is too large.\n");
1618 pr_err("current kernel does not support setting --array-size\n");
1623 if (devs_found
> 1 && s
.raiddisks
== 0 && s
.level
== UnSet
) {
1625 if (s
.size
> 0 || s
.chunk
||
1626 s
.layout_str
|| s
.bitmap_file
) {
1627 pr_err("--add cannot be used with other geometry changes in --grow mode\n");
1631 for (dv
= devlist
->next
; dv
; dv
= dv
->next
) {
1632 rv
= Grow_Add_device(devlist
->devname
, mdfd
,
1637 } else if (s
.bitmap_file
) {
1638 if (s
.size
> 0 || s
.raiddisks
|| s
.chunk
||
1639 s
.layout_str
|| devs_found
> 1) {
1640 pr_err("--bitmap changes cannot be used with other geometry changes in --grow mode\n");
1645 c
.delay
= DEFAULT_BITMAP_DELAY
;
1646 rv
= Grow_addbitmap(devlist
->devname
, mdfd
, &c
, &s
);
1647 } else if (grow_continue
)
1648 rv
= Grow_continue_command(devlist
->devname
,
1649 mdfd
, c
.backup_file
,
1651 else if (s
.size
> 0 || s
.raiddisks
|| s
.layout_str
||
1652 s
.chunk
!= 0 || s
.level
!= UnSet
||
1653 s
.data_offset
!= INVALID_SECTORS
) {
1654 rv
= Grow_reshape(devlist
->devname
, mdfd
,
1655 devlist
->next
, &c
, &s
);
1656 } else if (s
.consistency_policy
!= CONSISTENCY_POLICY_UNKNOWN
) {
1657 rv
= Grow_consistency_policy(devlist
->devname
, mdfd
, &c
, &s
);
1658 } else if (array_size
== 0)
1659 pr_err("no changes to --grow\n");
1668 pr_err("In --incremental mode, a device cannot be given with --scan.\n");
1671 if (c
.runstop
<= 0) {
1672 pr_err("--incremental --scan meaningless without --run.\n");
1675 if (devmode
== 'f') {
1676 pr_err("--incremental --scan --fail not supported.\n");
1679 rv
= IncrementalScan(&c
, NULL
);
1682 if (!rebuild_map
&& !c
.scan
) {
1683 pr_err("--incremental requires a device.\n");
1688 if (devmode
== 'f') {
1689 if (devlist
->next
) {
1690 pr_err("'--incremental --fail' can only handle one device.\n");
1694 rv
= IncrementalRemove(devlist
->devname
, remove_path
,
1697 rv
= Incremental(devlist
, &c
, ss
);
1704 cluster_release_dlmlock();
1709 static int scan_assemble(struct supertype
*ss
,
1711 struct mddev_ident
*ident
)
1713 struct mddev_ident
*a
, *array_list
= conf_get_ident(NULL
);
1714 struct mddev_dev
*devlist
= conf_get_devs();
1715 struct map_ent
*map
= NULL
;
1718 int failures
, successes
;
1720 if (conf_verify_devnames(array_list
)) {
1721 pr_err("Duplicate MD device names in conf file were found.\n");
1724 if (devlist
== NULL
) {
1725 pr_err("No devices listed in conf file were found.\n");
1728 for (a
= array_list
; a
; a
= a
->next
) {
1731 a
->autof
= c
->autof
;
1734 pr_err("failed to get exclusive lock on mapfile\n");
1739 for (a
= array_list
; a
; a
= a
->next
) {
1744 strcasecmp(a
->devname
, "<ignore>") == 0)
1747 r
= Assemble(ss
, a
->devname
,
1757 } while (failures
&& successes
);
1758 if (c
->homehost
&& cnt
== 0) {
1759 /* Maybe we can auto-assemble something.
1760 * Repeatedly call Assemble in auto-assemble mode
1765 ident
->autof
= c
->autof
;
1767 struct mddev_dev
*devlist
= conf_get_devs();
1770 rv2
= Assemble(ss
, NULL
,
1778 /* Incase there are stacked devices, we need to go around again */
1780 if (cnt
== 0 && rv
== 0) {
1781 pr_err("No arrays found in config file or automatically\n");
1785 } else if (cnt
== 0 && rv
== 0) {
1786 pr_err("No arrays found in config file\n");
1793 static int misc_scan(char devmode
, struct context
*c
)
1795 /* apply --detail or --wait-clean to
1796 * all devices in /proc/mdstat
1798 struct mdstat_ent
*ms
= mdstat_read(0, 1);
1799 struct mdstat_ent
*e
;
1800 struct map_ent
*map
= NULL
;
1804 for (members
= 0; members
<= 1; members
++) {
1805 for (e
= ms
; e
; e
= e
->next
) {
1809 int member
= e
->metadata_version
&&
1810 strncmp(e
->metadata_version
,
1811 "external:/", 10) == 0;
1812 if (members
!= member
)
1814 me
= map_by_devnm(&map
, e
->devnm
);
1815 if (me
&& me
->path
&& strcmp(me
->path
, "/unknown") != 0)
1817 if (name
== NULL
|| stat(name
, &stb
) != 0)
1818 name
= get_md_name(e
->devnm
);
1821 pr_err("cannot find device file for %s\n",
1826 rv
|= Detail(name
, c
);
1828 rv
|= WaitClean(name
, c
->verbose
);
1838 static int stop_scan(int verbose
)
1840 /* apply --stop to all devices in /proc/mdstat */
1841 /* Due to possible stacking of devices, repeat until
1842 * nothing more can be stopped
1844 int progress
= 1, err
;
1848 struct mdstat_ent
*ms
= mdstat_read(0, 0);
1849 struct mdstat_ent
*e
;
1851 if (!progress
) last
= 1;
1852 progress
= 0; err
= 0;
1853 for (e
= ms
; e
; e
= e
->next
) {
1854 char *name
= get_md_name(e
->devnm
);
1858 pr_err("cannot find device file for %s\n",
1862 mdfd
= open_mddev(name
, 1);
1864 if (Manage_stop(name
, mdfd
, verbose
, !last
))
1874 } while (!last
&& err
);
1880 static int misc_list(struct mddev_dev
*devlist
,
1881 struct mddev_ident
*ident
,
1882 char *dump_directory
,
1883 struct supertype
*ss
, struct context
*c
)
1885 struct mddev_dev
*dv
;
1888 for (dv
= devlist
; dv
; dv
= (rv
& 16) ? NULL
: dv
->next
) {
1891 switch(dv
->disposition
) {
1893 rv
|= Detail(dv
->devname
, c
);
1895 case KillOpt
: /* Zero superblock */
1897 rv
|= Kill(dv
->devname
, ss
, c
->force
, c
->verbose
,0);
1901 rv
|= Kill(dv
->devname
, NULL
, c
->force
, v
, 0);
1908 rv
|= Query(dv
->devname
);
1911 rv
|= ExamineBitmap(dv
->devname
, c
->brief
, ss
);
1914 rv
|= ExamineBadblocks(dv
->devname
, c
->brief
, ss
);
1918 rv
|= Wait(dv
->devname
);
1921 rv
|= WaitClean(dv
->devname
, c
->verbose
);
1924 rv
|= Kill_subarray(dv
->devname
, c
->subarray
, c
->verbose
);
1926 case UpdateSubarray
:
1928 pr_err("-U/--update must be specified with --update-subarray\n");
1932 rv
|= Update_subarray(dv
->devname
, c
->subarray
,
1933 c
->update
, ident
, c
->verbose
);
1936 rv
|= Dump_metadata(dv
->devname
, dump_directory
, c
, ss
);
1939 rv
|= Restore_metadata(dv
->devname
, dump_directory
, c
, ss
,
1940 (dv
== devlist
&& dv
->next
== NULL
));
1943 rv
|= SetAction(dv
->devname
, c
->action
);
1947 if (dv
->devname
[0] != '/')
1948 mdfd
= open_dev(dv
->devname
);
1949 if (dv
->devname
[0] == '/' || mdfd
< 0)
1950 mdfd
= open_mddev(dv
->devname
, 1);
1953 switch(dv
->disposition
) {
1956 rv
|= Manage_run(dv
->devname
, mdfd
, c
);
1960 pr_err("--stop not meaningful with both a --scan assembly and a device name.\n");
1964 rv
|= Manage_stop(dv
->devname
, mdfd
, c
->verbose
, 0);
1967 rv
|= Manage_ro(dv
->devname
, mdfd
, 1);
1970 rv
|= Manage_ro(dv
->devname
, mdfd
, -1);
1980 int SetAction(char *dev
, char *action
)
1982 int fd
= open(dev
, O_RDONLY
);
1987 pr_err("Couldn't open %s: %s\n", dev
, strerror(errno
));
1990 retval
= sysfs_init(&mdi
, fd
, NULL
);
1993 pr_err("%s is no an md array\n", dev
);
1997 if (sysfs_set_str(&mdi
, NULL
, "sync_action", action
) < 0) {
1998 pr_err("Count not set action for %s to %s: %s\n",
1999 dev
, action
, strerror(errno
));