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
= UnSet
,
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 while ((option_index
= -1) ,
124 (opt
=getopt_long(argc
, argv
,
125 shortopt
, long_options
,
126 &option_index
)) != -1) {
128 /* firstly, some mode-independent options */
138 fputs(Version
, stderr
);
141 case 'v': c
.verbose
++;
144 case 'q': c
.verbose
--;
148 if (mode
== ASSEMBLE
|| mode
== BUILD
||
149 mode
== CREATE
|| mode
== GROW
||
150 mode
== INCREMENTAL
|| mode
== MANAGE
)
151 break; /* b means bitmap */
156 case 'Y': c
.export
++;
160 if (strcasecmp(optarg
, "<ignore>") == 0)
161 c
.require_homehost
= 0;
167 /* Silently ignore old option */
173 if (asprintf(&c
.prefer
, "/%s/", optarg
) <= 0)
179 fputs(Usage
, stderr
);
182 /* second, figure out the mode.
183 * Some options force the mode. Others
184 * set the mode if it isn't already
190 shortopt
= short_bitmap_options
;
202 case ReAdd
: /* re-add */
206 shortopt
= short_bitmap_options
;
210 case 'A': newmode
= ASSEMBLE
;
211 shortopt
= short_bitmap_auto_options
;
213 case 'B': newmode
= BUILD
;
214 shortopt
= short_bitmap_auto_options
;
216 case 'C': newmode
= CREATE
;
217 shortopt
= short_bitmap_auto_options
;
219 case 'F': newmode
= MONITOR
;
221 case 'G': newmode
= GROW
;
222 shortopt
= short_bitmap_options
;
224 case 'I': newmode
= INCREMENTAL
;
225 shortopt
= short_bitmap_auto_options
;
228 newmode
= AUTODETECT
;
263 if (mode
&& newmode
== mode
) {
264 /* everybody happy ! */
265 } else if (mode
&& newmode
!= mode
) {
268 if (option_index
>= 0)
269 fprintf(stderr
, "--%s", long_options
[option_index
].name
);
271 fprintf(stderr
, "-%c", opt
);
272 fprintf(stderr
, " would set mdadm mode to \"%s\", but it is already set to \"%s\".\n",
273 map_num(modes
, newmode
),
274 map_num(modes
, mode
));
276 } else if (!mode
&& newmode
) {
278 if (mode
== MISC
&& devs_found
) {
279 pr_err("No action given for %s in --misc mode\n",
281 cont_err("Action options must come before device names\n");
285 /* special case of -c --help */
286 if ((opt
== 'c' || opt
== ConfigFile
) &&
287 (strncmp(optarg
, "--h", 3) == 0 ||
288 strncmp(optarg
, "-h", 2) == 0)) {
289 fputs(Help_config
, stdout
);
293 /* If first option is a device, don't force the mode yet */
295 if (devs_found
== 0) {
296 dv
= xmalloc(sizeof(*dv
));
297 dv
->devname
= optarg
;
298 dv
->disposition
= devmode
;
299 dv
->writemostly
= writemostly
;
300 dv
->failfast
= failfast
;
304 devlistend
= &dv
->next
;
309 /* No mode yet, and this is the second device ... */
310 pr_err("An option must be given to set the mode before a second device\n"
311 " (%s) is listed\n", optarg
);
314 if (option_index
>= 0)
315 pr_err("--%s", long_options
[option_index
].name
);
318 fprintf(stderr
, " does not set the mode, and so cannot be the first option.\n");
322 /* if we just set the mode, then done */
336 /* an undecorated option - must be a device name.
339 if (devs_found
> 0 && devmode
== DetailPlatform
) {
340 pr_err("controller may only be specified once. %s ignored\n",
345 if (devs_found
> 0 && mode
== MANAGE
&& !devmode
) {
346 pr_err("Must give one of -a/-r/-f for subsequent devices at %s\n", optarg
);
349 if (devs_found
> 0 && mode
== GROW
&& !devmode
) {
350 pr_err("Must give -a/--add for devices to add: %s\n", optarg
);
353 dv
= xmalloc(sizeof(*dv
));
354 dv
->devname
= optarg
;
355 dv
->disposition
= devmode
;
356 dv
->writemostly
= writemostly
;
357 dv
->failfast
= failfast
;
361 devlistend
= &dv
->next
;
367 /* We've got a mode, and opt is now something else which
368 * could depend on the mode */
369 #define O(a,b) ((a<<16)|b)
370 switch (O(mode
,opt
)) {
372 case O(GROW
,ChunkSize
):
374 case O(CREATE
,ChunkSize
):
375 case O(BUILD
,'c'): /* chunk or rounding */
376 case O(BUILD
,ChunkSize
): /* chunk or rounding */
378 pr_err("chunk/rounding may only be specified once. Second value is %s.\n", optarg
);
381 s
.chunk
= parse_size(optarg
);
382 if (s
.chunk
== INVALID_SECTORS
||
383 s
.chunk
< 8 || (s
.chunk
&1)) {
384 pr_err("invalid chunk/rounding value: %s\n",
388 /* Convert sectors to K */
392 case O(INCREMENTAL
, 'e'):
394 case O(ASSEMBLE
,'e'):
395 case O(MISC
,'e'): /* set metadata (superblock) information */
397 pr_err("metadata information already given\n");
400 for(i
=0; !ss
&& superlist
[i
]; i
++)
401 ss
= superlist
[i
]->match_metadata_desc(optarg
);
404 pr_err("unrecognised metadata identifier: %s\n", optarg
);
410 case O(MANAGE
,WriteMostly
):
412 case O(BUILD
,WriteMostly
):
414 case O(CREATE
,WriteMostly
):
415 /* set write-mostly for following devices */
416 writemostly
= FlagSet
;
420 /* clear write-mostly for following devices */
421 writemostly
= FlagClear
;
424 case O(MANAGE
,FailFast
):
425 case O(CREATE
,FailFast
):
428 case O(MANAGE
,NoFailFast
):
429 failfast
= FlagClear
;
434 case O(BUILD
,'z'): /* size */
436 pr_err("size may only be specified once. Second value is %s.\n", optarg
);
439 if (strcmp(optarg
, "max") == 0)
442 s
.size
= parse_size(optarg
);
443 if (s
.size
== INVALID_SECTORS
|| s
.size
< 8) {
444 pr_err("invalid size: %s\n", optarg
);
447 /* convert sectors to K */
452 case O(GROW
,'Z'): /* array size */
453 if (array_size
> 0) {
454 pr_err("array-size may only be specified once. Second value is %s.\n", optarg
);
457 if (strcmp(optarg
, "max") == 0)
458 array_size
= MAX_SIZE
;
460 array_size
= parse_size(optarg
);
461 if (array_size
== 0 ||
462 array_size
== INVALID_SECTORS
) {
463 pr_err("invalid array size: %s\n",
470 case O(CREATE
,DataOffset
):
471 case O(GROW
,DataOffset
):
472 if (data_offset
!= INVALID_SECTORS
) {
473 pr_err("data-offset may only be specified one. Second value is %s.\n", optarg
);
476 if (mode
== CREATE
&& strcmp(optarg
, "variable") == 0)
477 data_offset
= VARIABLE_OFFSET
;
479 data_offset
= parse_size(optarg
);
480 if (data_offset
== INVALID_SECTORS
) {
481 pr_err("invalid data-offset: %s\n",
489 case O(BUILD
,'l'): /* set raid level*/
490 if (s
.level
!= UnSet
) {
491 pr_err("raid level may only be set once. Second value is %s.\n", optarg
);
494 s
.level
= map_name(pers
, optarg
);
495 if (s
.level
== UnSet
) {
496 pr_err("invalid raid level: %s\n",
500 if (s
.level
!= 0 && s
.level
!= LEVEL_LINEAR
&&
501 s
.level
!= 1 && s
.level
!= LEVEL_MULTIPATH
&&
502 s
.level
!= LEVEL_FAULTY
&& s
.level
!= 10 &&
504 pr_err("Raid level %s not permitted with --build.\n",
508 if (s
.sparedisks
> 0 && s
.level
< 1 && s
.level
>= -1) {
509 pr_err("raid level %s is incompatible with spare-devices setting.\n",
513 ident
.level
= s
.level
;
516 case O(GROW
, 'p'): /* new layout */
517 case O(GROW
, Layout
):
519 pr_err("layout may only be sent once. Second value was %s\n", optarg
);
522 s
.layout_str
= optarg
;
523 /* 'Grow' will parse the value */
526 case O(CREATE
,'p'): /* raid5 layout */
527 case O(CREATE
,Layout
):
528 case O(BUILD
,'p'): /* faulty layout */
529 case O(BUILD
,Layout
):
530 if (s
.layout
!= UnSet
) {
531 pr_err("layout may only be sent once. Second value was %s\n", optarg
);
536 pr_err("layout not meaningful for %s arrays.\n",
537 map_num(pers
, s
.level
));
540 pr_err("raid level must be given before layout.\n");
544 s
.layout
= map_name(r5layout
, optarg
);
545 if (s
.layout
==UnSet
) {
546 pr_err("layout %s not understood for raid5.\n",
552 s
.layout
= map_name(r6layout
, optarg
);
553 if (s
.layout
==UnSet
) {
554 pr_err("layout %s not understood for raid6.\n",
561 s
.layout
= parse_layout_10(optarg
);
563 pr_err("layout for raid10 must be 'nNN', 'oNN' or 'fNN' where NN is a number, not %s\n", optarg
);
571 s
.layout
= parse_layout_faulty(optarg
);
572 if (s
.layout
== -1) {
573 pr_err("layout %s not understood for faulty.\n",
581 case O(CREATE
,AssumeClean
):
582 case O(BUILD
,AssumeClean
): /* assume clean */
583 case O(GROW
,AssumeClean
):
589 case O(BUILD
,'n'): /* number of raid disks */
591 pr_err("raid-devices set twice: %d and %s\n",
592 s
.raiddisks
, optarg
);
595 s
.raiddisks
= parse_num(optarg
);
596 if (s
.raiddisks
<= 0) {
597 pr_err("invalid number of raid devices: %s\n",
601 ident
.raid_disks
= s
.raiddisks
;
603 case O(ASSEMBLE
, Nodes
):
605 case O(CREATE
, Nodes
):
606 c
.nodes
= parse_num(optarg
);
608 pr_err("clustered array needs two nodes at least: %s\n",
613 case O(CREATE
, ClusterName
):
614 case O(ASSEMBLE
, ClusterName
):
615 c
.homecluster
= optarg
;
616 if (strlen(c
.homecluster
) > 64) {
617 pr_err("Cluster name too big.\n");
621 case O(CREATE
,'x'): /* number of spare (eXtra) disks */
623 pr_err("spare-devices set twice: %d and %s\n",
624 s
.sparedisks
, optarg
);
627 if (s
.level
!= UnSet
&& s
.level
<= 0 && s
.level
>= -1) {
628 pr_err("spare-devices setting is incompatible with raid level %d\n",
632 s
.sparedisks
= parse_num(optarg
);
633 if (s
.sparedisks
< 0) {
634 pr_err("invalid number of spare-devices: %s\n",
644 case O(INCREMENTAL
,'a'):
645 case O(INCREMENTAL
,Auto
):
646 case O(ASSEMBLE
,'a'):
647 case O(ASSEMBLE
,Auto
): /* auto-creation of device node */
648 c
.autof
= parse_auto(optarg
, "--auto flag", 0);
651 case O(CREATE
,Symlinks
):
652 case O(BUILD
,Symlinks
):
653 case O(ASSEMBLE
,Symlinks
): /* auto creation of symlinks in /dev to /dev/md */
657 case O(BUILD
,'f'): /* force honouring '-n 1' */
658 case O(BUILD
,Force
): /* force honouring '-n 1' */
659 case O(GROW
,'f'): /* ditto */
660 case O(GROW
,Force
): /* ditto */
661 case O(CREATE
,'f'): /* force honouring of device list */
662 case O(CREATE
,Force
): /* force honouring of device list */
663 case O(ASSEMBLE
,'f'): /* force assembly */
664 case O(ASSEMBLE
,Force
): /* force assembly */
665 case O(MISC
,'f'): /* force zero */
666 case O(MISC
,Force
): /* force zero */
667 case O(MANAGE
,Force
): /* add device which is too large */
670 /* now for the Assemble options */
671 case O(ASSEMBLE
, FreezeReshape
): /* Freeze reshape during
673 case O(INCREMENTAL
, FreezeReshape
):
674 c
.freeze_reshape
= 1;
676 case O(CREATE
,'u'): /* uuid of array */
677 case O(ASSEMBLE
,'u'): /* uuid of array */
678 if (ident
.uuid_set
) {
679 pr_err("uuid cannot be set twice. Second value %s.\n", optarg
);
682 if (parse_uuid(optarg
, ident
.uuid
))
685 pr_err("Bad uuid: %s\n", optarg
);
691 case O(ASSEMBLE
,'N'):
694 pr_err("name cannot be set twice. Second value %s.\n", optarg
);
697 if (mode
== MISC
&& !c
.subarray
) {
698 pr_err("-N/--name only valid with --update-subarray in misc mode\n");
701 if (strlen(optarg
) > 32) {
702 pr_err("name '%s' is too long, 32 chars max.\n",
706 strcpy(ident
.name
, optarg
);
709 case O(ASSEMBLE
,'m'): /* super-minor for array */
710 case O(ASSEMBLE
,SuperMinor
):
711 if (ident
.super_minor
!= UnSet
) {
712 pr_err("super-minor cannot be set twice. Second value: %s.\n", optarg
);
715 if (strcmp(optarg
, "dev") == 0)
716 ident
.super_minor
= -2;
718 ident
.super_minor
= parse_num(optarg
);
719 if (ident
.super_minor
< 0) {
720 pr_err("Bad super-minor number: %s.\n", optarg
);
726 case O(ASSEMBLE
,'o'):
732 case O(ASSEMBLE
,'U'): /* update the superblock */
735 pr_err("Can only update one aspect of superblock, both %s and %s given.\n",
739 if (mode
== MISC
&& !c
.subarray
) {
740 pr_err("Only subarrays can be updated in misc mode\n");
744 if (strcmp(c
.update
, "sparc2.2") == 0)
746 if (strcmp(c
.update
, "super-minor") == 0)
748 if (strcmp(c
.update
, "summaries") == 0)
750 if (strcmp(c
.update
, "resync") == 0)
752 if (strcmp(c
.update
, "uuid") == 0)
754 if (strcmp(c
.update
, "name") == 0)
756 if (strcmp(c
.update
, "homehost") == 0)
758 if (strcmp(c
.update
, "home-cluster") == 0)
760 if (strcmp(c
.update
, "nodes") == 0)
762 if (strcmp(c
.update
, "devicesize") == 0)
764 if (strcmp(c
.update
, "no-bitmap") == 0)
766 if (strcmp(c
.update
, "bbl") == 0)
768 if (strcmp(c
.update
, "no-bbl") == 0)
770 if (strcmp(c
.update
, "force-no-bbl") == 0)
772 if (strcmp(c
.update
, "metadata") == 0)
774 if (strcmp(c
.update
, "revert-reshape") == 0)
776 if (strcmp(c
.update
, "byteorder")==0) {
778 pr_err("must not set metadata type with --update=byteorder.\n");
781 for(i
=0; !ss
&& superlist
[i
]; i
++)
782 ss
= superlist
[i
]->match_metadata_desc(
785 pr_err("INTERNAL ERROR cannot find 0.swap\n");
791 if (strcmp(c
.update
,"?") == 0 ||
792 strcmp(c
.update
, "help") == 0) {
794 fprintf(outf
, "%s: ", Name
);
798 "%s: '--update=%s' is invalid. ",
801 fprintf(outf
, "Valid --update options are:\n"
802 " 'sparc2.2', 'super-minor', 'uuid', 'name', 'nodes', 'resync',\n"
803 " 'summaries', 'homehost', 'home-cluster', 'byteorder', 'devicesize',\n"
804 " 'no-bitmap', 'metadata', 'revert-reshape'\n"
805 " 'bbl', 'no-bbl', 'force-no-bbl'\n"
807 exit(outf
== stdout
? 0 : 2);
810 /* update=devicesize is allowed with --re-add */
811 if (devmode
!= 'A') {
812 pr_err("--update in Manage mode only allowed with --re-add.\n");
816 pr_err("Can only update one aspect of superblock, both %s and %s given.\n",
821 if (strcmp(c
.update
, "devicesize") != 0 &&
822 strcmp(c
.update
, "bbl") != 0 &&
823 strcmp(c
.update
, "force-no-bbl") != 0 &&
824 strcmp(c
.update
, "no-bbl") != 0) {
825 pr_err("only 'devicesize', 'bbl', 'no-bbl', and 'force-no-bbl' can be updated with --re-add\n");
830 case O(INCREMENTAL
,NoDegraded
):
831 pr_err("--no-degraded is deprecated in Incremental mode\n");
832 case O(ASSEMBLE
,NoDegraded
): /* --no-degraded */
833 c
.runstop
= -1; /* --stop isn't allowed for --assemble,
834 * so we overload slightly */
837 case O(ASSEMBLE
,'c'):
838 case O(ASSEMBLE
,ConfigFile
):
839 case O(INCREMENTAL
, 'c'):
840 case O(INCREMENTAL
, ConfigFile
):
842 case O(MISC
, ConfigFile
):
844 case O(MONITOR
,ConfigFile
):
845 case O(CREATE
,ConfigFile
):
847 pr_err("configfile cannot be set twice. Second value is %s.\n", optarg
);
851 set_conffile(configfile
);
852 /* FIXME possibly check that config file exists. Even parse it */
854 case O(ASSEMBLE
,'s'): /* scan */
857 case O(INCREMENTAL
,'s'):
861 case O(MONITOR
,'m'): /* mail address */
862 case O(MONITOR
,EMail
):
864 pr_err("only specify one mailaddress. %s ignored.\n",
870 case O(MONITOR
,'p'): /* alert program */
871 case O(MONITOR
,ProgramOpt
): /* alert program */
873 pr_err("only specify one alter program. %s ignored.\n",
879 case O(MONITOR
,'r'): /* rebuild increments */
880 case O(MONITOR
,Increment
):
881 increments
= atoi(optarg
);
882 if (increments
> 99 || increments
< 1) {
883 pr_err("please specify positive integer between 1 and 99 as rebuild increments.\n");
888 case O(MONITOR
,'d'): /* delay in seconds */
890 case O(BUILD
,'d'): /* delay for bitmap updates */
893 pr_err("only specify delay once. %s ignored.\n",
896 c
.delay
= parse_num(optarg
);
898 pr_err("invalid delay: %s\n",
904 case O(MONITOR
,'f'): /* daemonise */
905 case O(MONITOR
,Fork
):
908 case O(MONITOR
,'i'): /* pid */
910 pr_err("only specify one pid file. %s ignored.\n",
915 case O(MONITOR
,'1'): /* oneshot */
919 case O(MONITOR
,'t'): /* test */
922 case O(MONITOR
,'y'): /* log messages to syslog */
923 openlog("mdadm", LOG_PID
, SYSLOG_FACILITY
);
926 case O(MONITOR
, NoSharing
):
930 /* now the general management options. Some are applicable
931 * to other modes. None have arguments.
936 case O(MANAGE
,Add
): /* add a drive */
939 case O(MANAGE
,AddSpare
): /* add drive - never re-add */
942 case O(MANAGE
,AddJournal
): /* add journal */
943 if (s
.journaldisks
&& (s
.level
< 4 || s
.level
> 6)) {
944 pr_err("--add-journal is only supported for RAID level 4/5/6.\n");
949 case O(MANAGE
,ReAdd
):
952 case O(MANAGE
,'r'): /* remove a drive */
953 case O(MANAGE
,Remove
):
956 case O(MANAGE
,'f'): /* set faulty */
958 case O(INCREMENTAL
,'f'):
959 case O(INCREMENTAL
,Remove
):
960 case O(INCREMENTAL
,Fail
): /* r for incremental is taken, use f
961 * even though we will both fail and
962 * remove the device */
965 case O(MANAGE
, ClusterConfirm
):
968 case O(MANAGE
,Replace
):
969 /* Mark these devices for replacement */
973 /* These are the replacements to use */
974 if (devmode
!= 'R') {
975 pr_err("--with must follow --replace\n");
980 case O(INCREMENTAL
,'R'):
982 case O(ASSEMBLE
,'R'):
984 case O(CREATE
,'R'): /* Run the array */
986 pr_err("Cannot both Stop and Run an array\n");
993 pr_err("Cannot both Run and Stop an array\n");
1005 case O(MISC
,KillOpt
):
1009 case O(MISC
, ExamineBB
):
1013 case O(MISC
, WaitOpt
):
1014 case O(MISC
, Waitclean
):
1015 case O(MISC
, DetailPlatform
):
1016 case O(MISC
, KillSubarray
):
1017 case O(MISC
, UpdateSubarray
):
1019 case O(MISC
, Restore
):
1020 case O(MISC
,Action
):
1021 if (opt
== KillSubarray
|| opt
== UpdateSubarray
) {
1023 pr_err("subarray can only be specified once\n");
1026 c
.subarray
= optarg
;
1028 if (opt
== Action
) {
1030 pr_err("Only one --action can be specified\n");
1033 if (strcmp(optarg
, "idle") == 0 ||
1034 strcmp(optarg
, "frozen") == 0 ||
1035 strcmp(optarg
, "check") == 0 ||
1036 strcmp(optarg
, "repair") == 0)
1039 pr_err("action must be one of idle, frozen, check, repair\n");
1043 if (devmode
&& devmode
!= opt
&&
1045 (opt
== 'E' && devmode
!= 'Q'))) {
1046 pr_err("--examine/-E cannot be given with ");
1047 if (devmode
== 'E') {
1048 if (option_index
>= 0)
1049 fprintf(stderr
, "--%s\n",
1050 long_options
[option_index
].name
);
1052 fprintf(stderr
, "-%c\n", opt
);
1053 } else if (isalpha(devmode
))
1054 fprintf(stderr
, "-%c\n", devmode
);
1056 fprintf(stderr
, "previous option\n");
1060 if (opt
== Dump
|| opt
== Restore
) {
1061 if (dump_directory
!= NULL
) {
1062 pr_err("dump/restore directory specified twice: %s and %s\n",
1063 dump_directory
, optarg
);
1066 dump_directory
= optarg
;
1069 case O(MISC
, UdevRules
):
1070 if (devmode
&& devmode
!= opt
) {
1071 pr_err("--udev-rules must be the only option.\n");
1074 pr_err("only specify one udev rule filename. %s ignored.\n",
1077 udev_filename
= optarg
;
1085 case O(MISC
, Sparc22
):
1086 if (devmode
!= 'E') {
1087 pr_err("--sparc2.2 only allowed with --examine\n");
1093 case O(ASSEMBLE
,'b'): /* here we simply set the bitmap file */
1094 case O(ASSEMBLE
,Bitmap
):
1096 pr_err("bitmap file needed with -b in --assemble mode\n");
1099 if (strcmp(optarg
, "internal") == 0 ||
1100 strcmp(optarg
, "clustered") == 0) {
1101 pr_err("no need to specify --bitmap when assembling"
1102 " arrays with internal or clustered bitmap\n");
1105 bitmap_fd
= open(optarg
, O_RDWR
);
1106 if (!*optarg
|| bitmap_fd
< 0) {
1107 pr_err("cannot open bitmap file %s: %s\n", optarg
, strerror(errno
));
1110 ident
.bitmap_fd
= bitmap_fd
; /* for Assemble */
1113 case O(ASSEMBLE
, BackupFile
):
1114 case O(GROW
, BackupFile
):
1115 /* Specify a file into which grow might place a backup,
1116 * or from which assemble might recover a backup
1118 if (c
.backup_file
) {
1119 pr_err("backup file already specified, rejecting %s\n", optarg
);
1122 c
.backup_file
= optarg
;
1125 case O(GROW
, Continue
):
1126 /* Continue interrupted grow
1130 case O(ASSEMBLE
, InvalidBackup
):
1131 /* Acknowledge that the backupfile is invalid, but ask
1132 * to continue anyway
1134 c
.invalid_backup
= 1;
1138 case O(BUILD
,Bitmap
):
1140 case O(CREATE
,Bitmap
): /* here we create the bitmap */
1142 case O(GROW
,Bitmap
):
1143 if (s
.bitmap_file
) {
1144 pr_err("bitmap cannot be set twice. Second value: %s.\n", optarg
);
1147 if (strcmp(optarg
, "internal") == 0 ||
1148 strcmp(optarg
, "none") == 0 ||
1149 strchr(optarg
, '/') != NULL
) {
1150 s
.bitmap_file
= optarg
;
1153 if (strcmp(optarg
, "clustered") == 0) {
1154 s
.bitmap_file
= optarg
;
1155 /* Set the default number of cluster nodes
1156 * to 4 if not already set by user
1163 pr_err("bitmap file must contain a '/', or be 'internal', or be 'clustered', or 'none'\n"
1164 " not '%s'\n", optarg
);
1167 case O(GROW
,BitmapChunk
):
1168 case O(BUILD
,BitmapChunk
):
1169 case O(CREATE
,BitmapChunk
): /* bitmap chunksize */
1170 s
.bitmap_chunk
= parse_size(optarg
);
1171 if (s
.bitmap_chunk
== 0 ||
1172 s
.bitmap_chunk
== INVALID_SECTORS
||
1173 s
.bitmap_chunk
& (s
.bitmap_chunk
- 1)) {
1174 pr_err("invalid bitmap chunksize: %s\n",
1178 s
.bitmap_chunk
= s
.bitmap_chunk
* 512;
1181 case O(GROW
, WriteBehind
):
1182 case O(BUILD
, WriteBehind
):
1183 case O(CREATE
, WriteBehind
): /* write-behind mode */
1184 s
.write_behind
= DEFAULT_MAX_WRITE_BEHIND
;
1186 s
.write_behind
= parse_num(optarg
);
1187 if (s
.write_behind
< 0 ||
1188 s
.write_behind
> 16383) {
1189 pr_err("Invalid value for maximum outstanding write-behind writes: %s.\n\tMust be between 0 and 16383.\n", optarg
);
1195 case O(INCREMENTAL
, 'r'):
1196 case O(INCREMENTAL
, RebuildMapOpt
):
1199 case O(INCREMENTAL
, IncrementalPath
):
1200 remove_path
= optarg
;
1202 case O(CREATE
, WriteJournal
):
1203 if (s
.journaldisks
) {
1204 pr_err("Please specify only one journal device for the array.\n");
1205 pr_err("Ignoring --write-journal %s...\n", optarg
);
1208 dv
= xmalloc(sizeof(*dv
));
1209 dv
->devname
= optarg
;
1210 dv
->disposition
= 'j'; /* WriteJournal */
1214 devlistend
= &dv
->next
;
1219 case O(CREATE
, 'k'):
1220 s
.consistency_policy
= map_name(consistency_policies
,
1222 if (s
.consistency_policy
== UnSet
||
1223 s
.consistency_policy
< CONSISTENCY_POLICY_RESYNC
) {
1224 pr_err("Invalid consistency policy: %s\n",
1230 /* We have now processed all the valid options. Anything else is
1233 if (option_index
> 0)
1234 pr_err(":option --%s not valid in %s mode\n",
1235 long_options
[option_index
].name
,
1236 map_num(modes
, mode
));
1238 pr_err("option -%c not valid in %s mode\n",
1239 opt
, map_num(modes
, mode
));
1246 if (print_help
== 2)
1247 help_text
= OptionHelp
;
1249 help_text
= mode_help
[mode
];
1250 if (help_text
== NULL
)
1252 fputs(help_text
,stdout
);
1256 if (s
.journaldisks
) {
1257 if (s
.level
< 4 || s
.level
> 6) {
1258 pr_err("--write-journal is only supported for RAID level 4/5/6.\n");
1261 if (s
.consistency_policy
!= UnSet
&&
1262 s
.consistency_policy
!= CONSISTENCY_POLICY_JOURNAL
) {
1263 pr_err("--write-journal is not supported with consistency policy: %s\n",
1264 map_num(consistency_policies
, s
.consistency_policy
));
1269 if (mode
== CREATE
&& s
.consistency_policy
!= UnSet
) {
1271 pr_err("--consistency-policy not meaningful with level %s.\n",
1272 map_num(pers
, s
.level
));
1274 } else if (s
.consistency_policy
== CONSISTENCY_POLICY_JOURNAL
&&
1276 pr_err("--write-journal is required for consistency policy: %s\n",
1277 map_num(consistency_policies
, s
.consistency_policy
));
1279 } else if (s
.consistency_policy
== CONSISTENCY_POLICY_PPL
&&
1281 pr_err("PPL consistency policy is only supported for RAID level 5.\n");
1283 } else if (s
.consistency_policy
== CONSISTENCY_POLICY_BITMAP
&&
1285 strcmp(s
.bitmap_file
, "none") == 0)) {
1286 pr_err("--bitmap is required for consistency policy: %s\n",
1287 map_num(consistency_policies
, s
.consistency_policy
));
1289 } else if (s
.bitmap_file
&&
1290 strcmp(s
.bitmap_file
, "none") != 0 &&
1291 s
.consistency_policy
!= CONSISTENCY_POLICY_BITMAP
&&
1292 s
.consistency_policy
!= CONSISTENCY_POLICY_JOURNAL
) {
1293 pr_err("--bitmap is not compatible with consistency policy: %s\n",
1294 map_num(consistency_policies
, s
.consistency_policy
));
1299 if (!mode
&& devs_found
) {
1302 if (devlist
->disposition
== 0)
1303 devlist
->disposition
= devmode
;
1306 fputs(Usage
, stderr
);
1311 struct createinfo
*ci
= conf_get_create_info();
1313 if (strcasecmp(symlinks
, "yes") == 0)
1315 else if (strcasecmp(symlinks
, "no") == 0)
1318 pr_err("option --symlinks must be 'no' or 'yes'\n");
1322 /* Ok, got the option parsing out of the way
1323 * hopefully it's mostly right but there might be some stuff
1326 * That is mostly checked in the per-mode stuff but...
1328 * For @,B,C and A without -s, the first device listed must be
1329 * an md device. We check that here and open it.
1332 if (mode
== MANAGE
|| mode
== BUILD
|| mode
== CREATE
||
1333 mode
== GROW
|| (mode
== ASSEMBLE
&& ! c
.scan
)) {
1334 if (devs_found
< 1) {
1335 pr_err("an md device must be given in this mode\n");
1338 if ((int)ident
.super_minor
== -2 && c
.autof
) {
1339 pr_err("--super-minor=dev is incompatible with --auto\n");
1342 if (mode
== MANAGE
|| mode
== GROW
) {
1343 mdfd
= open_mddev(devlist
->devname
, 1);
1347 /* non-existent device is OK */
1348 mdfd
= open_mddev(devlist
->devname
, 0);
1350 pr_err("device %s exists but is not an md array.\n", devlist
->devname
);
1353 if ((int)ident
.super_minor
== -2) {
1356 pr_err("--super-minor=dev given, and listed device %s doesn't exist.\n",
1361 ident
.super_minor
= minor(stb
.st_rdev
);
1363 if (mdfd
>= 0 && mode
!= MANAGE
&& mode
!= GROW
) {
1364 /* We don't really want this open yet, we just might
1365 * have wanted to check some things
1373 if (s
.raiddisks
== 1 && !c
.force
&& s
.level
!= LEVEL_FAULTY
) {
1374 pr_err("'1' is an unusual number of drives for an array, so it is probably\n"
1375 " a mistake. If you really mean it you will need to specify --force before\n"
1376 " setting the number of drives.\n");
1381 if (c
.homehost
== NULL
&& c
.require_homehost
)
1382 c
.homehost
= conf_get_homehost(&c
.require_homehost
);
1383 if (c
.homehost
== NULL
|| strcasecmp(c
.homehost
, "<system>") == 0) {
1384 if (gethostname(sys_hostname
, sizeof(sys_hostname
)) == 0) {
1385 sys_hostname
[sizeof(sys_hostname
)-1] = 0;
1386 c
.homehost
= sys_hostname
;
1390 (!c
.homehost
[0] || strcasecmp(c
.homehost
, "<none>") == 0)) {
1392 c
.require_homehost
= 0;
1397 set_hooks(); /* set hooks from libs */
1399 if (c
.homecluster
== NULL
&& (c
.nodes
> 0)) {
1400 c
.homecluster
= conf_get_homecluster();
1401 if (c
.homecluster
== NULL
)
1402 rv
= get_cluster_name(&c
.homecluster
);
1404 pr_err("The md can't get cluster name\n");
1409 if (c
.backup_file
&& data_offset
!= INVALID_SECTORS
) {
1410 pr_err("--backup-file and --data-offset are incompatible\n");
1414 if ((mode
== MISC
&& devmode
== 'E') ||
1415 (mode
== MONITOR
&& spare_sharing
== 0))
1416 /* Anyone may try this */;
1417 else if (geteuid() != 0) {
1418 pr_err("must be super-user to perform this action\n");
1422 ident
.autof
= c
.autof
;
1424 if (c
.scan
&& c
.verbose
< 2)
1425 /* --scan implied --brief unless -vv */
1430 /* readonly, add/remove, readwrite, runstop */
1432 rv
= Manage_ro(devlist
->devname
, mdfd
, c
.readonly
);
1433 if (!rv
&& devs_found
>1)
1434 rv
= Manage_subdevs(devlist
->devname
, mdfd
,
1435 devlist
->next
, c
.verbose
, c
.test
,
1437 if (!rv
&& c
.readonly
< 0)
1438 rv
= Manage_ro(devlist
->devname
, mdfd
, c
.readonly
);
1439 if (!rv
&& c
.runstop
> 0)
1440 rv
= Manage_run(devlist
->devname
, mdfd
, &c
);
1441 if (!rv
&& c
.runstop
< 0)
1442 rv
= Manage_stop(devlist
->devname
, mdfd
, c
.verbose
, 0);
1445 if (devs_found
== 1 && ident
.uuid_set
== 0 &&
1446 ident
.super_minor
== UnSet
&& ident
.name
[0] == 0 &&
1448 /* Only a device has been given, so get details from config file */
1449 struct mddev_ident
*array_ident
= conf_get_ident(devlist
->devname
);
1450 if (array_ident
== NULL
) {
1451 pr_err("%s not identified in config file.\n",
1457 if (array_ident
->autof
== 0)
1458 array_ident
->autof
= c
.autof
;
1459 rv
|= Assemble(ss
, devlist
->devname
, array_ident
,
1463 rv
= Assemble(ss
, devlist
->devname
, &ident
,
1465 else if (devs_found
> 0) {
1466 if (c
.update
&& devs_found
> 1) {
1467 pr_err("can only update a single array at a time\n");
1470 if (c
.backup_file
&& devs_found
> 1) {
1471 pr_err("can only assemble a single array when providing a backup file.\n");
1474 for (dv
= devlist
; dv
; dv
=dv
->next
) {
1475 struct mddev_ident
*array_ident
= conf_get_ident(dv
->devname
);
1476 if (array_ident
== NULL
) {
1477 pr_err("%s not identified in config file.\n",
1482 if (array_ident
->autof
== 0)
1483 array_ident
->autof
= c
.autof
;
1484 rv
|= Assemble(ss
, dv
->devname
, array_ident
,
1489 pr_err("--update not meaningful with a --scan assembly.\n");
1492 if (c
.backup_file
) {
1493 pr_err("--backup_file not meaningful with a --scan assembly.\n");
1496 rv
= scan_assemble(ss
, &c
, &ident
);
1502 c
.delay
= DEFAULT_BITMAP_DELAY
;
1503 if (s
.write_behind
&& !s
.bitmap_file
) {
1504 pr_err("write-behind mode requires a bitmap.\n");
1508 if (s
.raiddisks
== 0) {
1509 pr_err("no raid-devices specified.\n");
1514 if (s
.bitmap_file
) {
1515 if (strcmp(s
.bitmap_file
, "internal") == 0 ||
1516 strcmp(s
.bitmap_file
, "clustered") == 0) {
1517 pr_err("'internal' and 'clustered' bitmaps not supported with --build\n");
1522 rv
= Build(devlist
->devname
, devlist
->next
, &s
, &c
);
1526 c
.delay
= DEFAULT_BITMAP_DELAY
;
1529 if (!s
.bitmap_file
||
1530 strcmp(s
.bitmap_file
, "clustered") != 0) {
1531 pr_err("--nodes argument only compatible with --bitmap=clustered\n");
1537 pr_err("--bitmap=clustered is currently supported with RAID mirror only\n");
1543 if (s
.write_behind
&& !s
.bitmap_file
) {
1544 pr_err("write-behind mode requires a bitmap.\n");
1548 if (s
.raiddisks
== 0) {
1549 pr_err("no raid-devices specified.\n");
1554 rv
= Create(ss
, devlist
->devname
,
1555 ident
.name
, ident
.uuid_set
? ident
.uuid
: NULL
,
1556 devs_found
-1, devlist
->next
,
1557 &s
, &c
, data_offset
);
1560 if (devmode
== 'E') {
1561 if (devlist
== NULL
&& !c
.scan
) {
1562 pr_err("No devices to examine\n");
1565 if (devlist
== NULL
)
1566 devlist
= conf_get_devs();
1567 if (devlist
== NULL
) {
1568 pr_err("No devices listed in %s\n", configfile
?configfile
:DefaultConfFile
);
1571 rv
= Examine(devlist
, &c
, ss
);
1572 } else if (devmode
== DetailPlatform
) {
1573 rv
= Detail_Platform(ss
? ss
->ss
: NULL
, ss
? c
.scan
: 1,
1574 c
.verbose
, c
.export
,
1575 devlist
? devlist
->devname
: NULL
);
1576 } else if (devlist
== NULL
) {
1577 if (devmode
== 'S' && c
.scan
)
1578 rv
= stop_scan(c
.verbose
);
1579 else if ((devmode
== 'D' || devmode
== Waitclean
) &&
1581 rv
= misc_scan(devmode
, &c
);
1582 else if (devmode
== UdevRules
)
1583 rv
= Write_rules(udev_filename
);
1585 pr_err("No devices given.\n");
1589 rv
= misc_list(devlist
, &ident
, dump_directory
, ss
, &c
);
1592 if (!devlist
&& !c
.scan
) {
1593 pr_err("Cannot monitor: need --scan or at least one device\n");
1597 if (pidfile
&& !daemonise
) {
1598 pr_err("Cannot write a pid file when not in daemon mode\n");
1603 if (get_linux_version() > 2006016)
1604 /* mdstat responds to poll */
1609 rv
= Monitor(devlist
, mailaddr
, program
,
1610 &c
, daemonise
, oneshot
,
1611 dosyslog
, pidfile
, increments
,
1616 if (array_size
> 0) {
1617 /* alway impose array size first, independent of
1619 * Do not allow level or raid_disks changes at the
1620 * same time as that can be irreversibly destructive.
1624 if (s
.raiddisks
|| s
.level
!= UnSet
) {
1625 pr_err("cannot change array size in same operation as changing raiddisks or level.\n"
1626 " Change size first, then check that data is still intact.\n");
1630 sysfs_init(&sra
, mdfd
, NULL
);
1631 if (array_size
== MAX_SIZE
)
1632 err
= sysfs_set_str(&sra
, NULL
, "array_size", "default");
1634 err
= sysfs_set_num(&sra
, NULL
, "array_size", array_size
/ 2);
1637 pr_err("--array-size setting is too large.\n");
1639 pr_err("current kernel does not support setting --array-size\n");
1644 if (devs_found
> 1 && s
.raiddisks
== 0 && s
.level
== UnSet
) {
1646 if (s
.size
> 0 || s
.chunk
||
1647 s
.layout_str
|| s
.bitmap_file
) {
1648 pr_err("--add cannot be used with other geometry changes in --grow mode\n");
1652 for (dv
=devlist
->next
; dv
; dv
=dv
->next
) {
1653 rv
= Grow_Add_device(devlist
->devname
, mdfd
,
1658 } else if (s
.bitmap_file
) {
1659 if (s
.size
> 0 || s
.raiddisks
|| s
.chunk
||
1660 s
.layout_str
|| devs_found
> 1) {
1661 pr_err("--bitmap changes cannot be used with other geometry changes in --grow mode\n");
1666 c
.delay
= DEFAULT_BITMAP_DELAY
;
1667 rv
= Grow_addbitmap(devlist
->devname
, mdfd
, &c
, &s
);
1668 } else if (grow_continue
)
1669 rv
= Grow_continue_command(devlist
->devname
,
1670 mdfd
, c
.backup_file
,
1672 else if (s
.size
> 0 || s
.raiddisks
|| s
.layout_str
||
1673 s
.chunk
!= 0 || s
.level
!= UnSet
||
1674 data_offset
!= INVALID_SECTORS
) {
1675 rv
= Grow_reshape(devlist
->devname
, mdfd
,
1677 data_offset
, &c
, &s
);
1678 } else if (array_size
== 0)
1679 pr_err("no changes to --grow\n");
1688 pr_err("In --incremental mode, a device cannot be given with --scan.\n");
1691 if (c
.runstop
<= 0) {
1692 pr_err("--incremental --scan meaningless without --run.\n");
1695 if (devmode
== 'f') {
1696 pr_err("--incremental --scan --fail not supported.\n");
1699 rv
= IncrementalScan(&c
, NULL
);
1702 if (!rebuild_map
&& !c
.scan
) {
1703 pr_err("--incremental requires a device.\n");
1708 if (devmode
== 'f') {
1709 if (devlist
->next
) {
1710 pr_err("'--incremental --fail' can only handle one device.\n");
1714 rv
= IncrementalRemove(devlist
->devname
, remove_path
,
1717 rv
= Incremental(devlist
, &c
, ss
);
1726 static int scan_assemble(struct supertype
*ss
,
1728 struct mddev_ident
*ident
)
1730 struct mddev_ident
*a
, *array_list
= conf_get_ident(NULL
);
1731 struct mddev_dev
*devlist
= conf_get_devs();
1732 struct map_ent
*map
= NULL
;
1735 int failures
, successes
;
1737 if (conf_verify_devnames(array_list
)) {
1738 pr_err("Duplicate MD device names in conf file were found.\n");
1741 if (devlist
== NULL
) {
1742 pr_err("No devices listed in conf file were found.\n");
1745 for (a
= array_list
; a
; a
= a
->next
) {
1748 a
->autof
= c
->autof
;
1751 pr_err("failed to get exclusive lock on mapfile\n");
1756 for (a
= array_list
; a
; a
= a
->next
) {
1761 strcasecmp(a
->devname
, "<ignore>") == 0)
1764 r
= Assemble(ss
, a
->devname
,
1774 } while (failures
&& successes
);
1775 if (c
->homehost
&& cnt
== 0) {
1776 /* Maybe we can auto-assemble something.
1777 * Repeatedly call Assemble in auto-assemble mode
1782 ident
->autof
= c
->autof
;
1784 struct mddev_dev
*devlist
= conf_get_devs();
1787 rv2
= Assemble(ss
, NULL
,
1795 /* Incase there are stacked devices, we need to go around again */
1797 if (cnt
== 0 && rv
== 0) {
1798 pr_err("No arrays found in config file or automatically\n");
1802 } else if (cnt
== 0 && rv
== 0) {
1803 pr_err("No arrays found in config file\n");
1810 static int misc_scan(char devmode
, struct context
*c
)
1812 /* apply --detail or --wait-clean to
1813 * all devices in /proc/mdstat
1815 struct mdstat_ent
*ms
= mdstat_read(0, 1);
1816 struct mdstat_ent
*e
;
1817 struct map_ent
*map
= NULL
;
1821 for (members
= 0; members
<= 1; members
++) {
1822 for (e
=ms
; e
; e
=e
->next
) {
1826 int member
= e
->metadata_version
&&
1827 strncmp(e
->metadata_version
,
1828 "external:/", 10) == 0;
1829 if (members
!= member
)
1831 me
= map_by_devnm(&map
, e
->devnm
);
1833 && strcmp(me
->path
, "/unknown") != 0)
1835 if (name
== NULL
|| stat(name
, &stb
) != 0)
1836 name
= get_md_name(e
->devnm
);
1839 pr_err("cannot find device file for %s\n",
1844 rv
|= Detail(name
, c
);
1846 rv
|= WaitClean(name
, -1, c
->verbose
);
1854 static int stop_scan(int verbose
)
1856 /* apply --stop to all devices in /proc/mdstat */
1857 /* Due to possible stacking of devices, repeat until
1858 * nothing more can be stopped
1860 int progress
=1, err
;
1864 struct mdstat_ent
*ms
= mdstat_read(0, 0);
1865 struct mdstat_ent
*e
;
1867 if (!progress
) last
= 1;
1868 progress
= 0; err
= 0;
1869 for (e
=ms
; e
; e
=e
->next
) {
1870 char *name
= get_md_name(e
->devnm
);
1874 pr_err("cannot find device file for %s\n",
1878 mdfd
= open_mddev(name
, 1);
1880 if (Manage_stop(name
, mdfd
, verbose
, !last
))
1890 } while (!last
&& err
);
1896 static int misc_list(struct mddev_dev
*devlist
,
1897 struct mddev_ident
*ident
,
1898 char *dump_directory
,
1899 struct supertype
*ss
, struct context
*c
)
1901 struct mddev_dev
*dv
;
1904 for (dv
=devlist
; dv
; dv
=(rv
& 16) ? NULL
: dv
->next
) {
1907 switch(dv
->disposition
) {
1909 rv
|= Detail(dv
->devname
, c
);
1911 case KillOpt
: /* Zero superblock */
1913 rv
|= Kill(dv
->devname
, ss
, c
->force
, c
->verbose
,0);
1917 rv
|= Kill(dv
->devname
, NULL
, c
->force
, v
, 0);
1924 rv
|= Query(dv
->devname
); continue;
1926 rv
|= ExamineBitmap(dv
->devname
, c
->brief
, ss
); continue;
1928 rv
|= ExamineBadblocks(dv
->devname
, c
->brief
, ss
); continue;
1931 rv
|= Wait(dv
->devname
); continue;
1933 rv
|= WaitClean(dv
->devname
, -1, c
->verbose
); continue;
1935 rv
|= Kill_subarray(dv
->devname
, c
->subarray
, c
->verbose
);
1937 case UpdateSubarray
:
1938 if (c
->update
== NULL
) {
1939 pr_err("-U/--update must be specified with --update-subarray\n");
1943 rv
|= Update_subarray(dv
->devname
, c
->subarray
,
1944 c
->update
, ident
, c
->verbose
);
1947 rv
|= Dump_metadata(dv
->devname
, dump_directory
, c
, ss
);
1950 rv
|= Restore_metadata(dv
->devname
, dump_directory
, c
, ss
,
1951 (dv
== devlist
&& dv
->next
== NULL
));
1954 rv
|= SetAction(dv
->devname
, c
->action
);
1957 switch(dv
->devname
[0] == '/') {
1959 mdfd
= open_dev(dv
->devname
);
1960 if (mdfd
>= 0) break;
1962 mdfd
= open_mddev(dv
->devname
, 1);
1965 switch(dv
->disposition
) {
1968 rv
|= Manage_run(dv
->devname
, mdfd
, c
); break;
1970 rv
|= Manage_stop(dv
->devname
, mdfd
, c
->verbose
, 0); break;
1972 rv
|= Manage_ro(dv
->devname
, mdfd
, 1); break;
1974 rv
|= Manage_ro(dv
->devname
, mdfd
, -1); break;
1983 int SetAction(char *dev
, char *action
)
1985 int fd
= open(dev
, O_RDONLY
);
1988 pr_err("Couldn't open %s: %s\n", dev
, strerror(errno
));
1991 sysfs_init(&mdi
, fd
, NULL
);
1993 if (!mdi
.sys_name
[0]) {
1994 pr_err("%s is no an md array\n", dev
);
1998 if (sysfs_set_str(&mdi
, NULL
, "sync_action", action
) < 0) {
1999 pr_err("Count not set action for %s to %s: %s\n",
2000 dev
, action
, strerror(errno
));