2 * mdadm - manage Linux "md" devices aka RAID arrays.
4 * Copyright (C) 2001-2013 Neil Brown <neilb@suse.de>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * Email: <neilb@suse.de>
24 * Additions for bitmap and write-behind RAID options, Copyright (C) 2003-2004,
25 * Paul Clements, SteelEye Technology, Inc.
32 static int scan_assemble(struct supertype
*ss
,
34 struct mddev_ident
*ident
);
35 static int misc_scan(char devmode
, struct context
*c
);
36 static int stop_scan(int verbose
);
37 static int misc_list(struct mddev_dev
*devlist
,
38 struct mddev_ident
*ident
,
40 struct supertype
*ss
, struct context
*c
);
41 const char Name
[] = "mdadm";
43 int main(int argc
, char *argv
[])
51 unsigned long long array_size
= 0;
52 unsigned long long data_offset
= INVALID_SECTORS
;
53 struct mddev_ident ident
;
54 char *configfile
= NULL
;
57 struct mddev_dev
*devlist
= NULL
;
58 struct mddev_dev
**devlistend
= & devlist
;
60 mdu_array_info_t array
;
62 char *symlinks
= NULL
;
63 int grow_continue
= 0;
64 /* autof indicates whether and how to create device node.
65 * bottom 3 bits are style. Rest (when shifted) are number of parts
67 * 1 - don't create (no)
68 * 2 - if is_standard, then create (yes)
69 * 3 - create as 'md' - reject is_standard mdp (md)
70 * 4 - create as 'mdp' - reject is_standard md (mdp)
71 * 5 - default to md if not is_standard (md in config file)
72 * 6 - default to mdp if not is_standard (part, or mdp in config file)
75 .require_homehost
= 1,
81 .bitmap_chunk
= UnSet
,
82 .consistency_policy
= CONSISTENCY_POLICY_UNKNOWN
,
85 char sys_hostname
[256];
86 char *mailaddr
= NULL
;
92 int spare_sharing
= 1;
93 struct supertype
*ss
= NULL
;
94 enum flag_mode writemostly
= FlagDefault
;
95 enum flag_mode failfast
= FlagDefault
;
96 char *shortopt
= short_options
;
99 char *remove_path
= NULL
;
100 char *udev_filename
= NULL
;
101 char *dump_directory
= NULL
;
109 srandom(time(0) ^ getpid());
113 ident
.raid_disks
= UnSet
;
114 ident
.super_minor
= UnSet
;
116 ident
.spare_group
= NULL
;
119 ident
.bitmap_fd
= -1;
120 ident
.bitmap_file
= NULL
;
122 ident
.container
= NULL
;
125 if (get_linux_version() < 2006015) {
126 pr_err("This version of mdadm does not support kernels older than 2.6.15\n");
130 while ((option_index
= -1),
131 (opt
= getopt_long(argc
, argv
, shortopt
, long_options
,
132 &option_index
)) != -1) {
134 /* firstly, some mode-independent options */
144 fputs(Version
, stderr
);
147 case 'v': c
.verbose
++;
150 case 'q': c
.verbose
--;
154 if (mode
== ASSEMBLE
|| mode
== BUILD
||
155 mode
== CREATE
|| mode
== GROW
||
156 mode
== INCREMENTAL
|| mode
== MANAGE
)
157 break; /* b means bitmap */
166 case 'Y': c
.export
++;
170 if (strcasecmp(optarg
, "<ignore>") == 0)
171 c
.require_homehost
= 0;
177 /* Silently ignore old option */
183 if (asprintf(&c
.prefer
, "/%s/", optarg
) <= 0)
189 fputs(Usage
, stderr
);
192 /* second, figure out the mode.
193 * Some options force the mode. Others
194 * set the mode if it isn't already
200 shortopt
= short_bitmap_options
;
212 case ReAdd
: /* re-add */
216 shortopt
= short_bitmap_options
;
220 case 'A': newmode
= ASSEMBLE
;
221 shortopt
= short_bitmap_auto_options
;
223 case 'B': newmode
= BUILD
;
224 shortopt
= short_bitmap_auto_options
;
226 case 'C': newmode
= CREATE
;
227 shortopt
= short_bitmap_auto_options
;
229 case 'F': newmode
= MONITOR
;
231 case 'G': newmode
= GROW
;
232 shortopt
= short_bitmap_options
;
234 case 'I': newmode
= INCREMENTAL
;
235 shortopt
= short_bitmap_auto_options
;
238 newmode
= AUTODETECT
;
273 if (mode
&& newmode
== mode
) {
274 /* everybody happy ! */
275 } else if (mode
&& newmode
!= mode
) {
278 if (option_index
>= 0)
279 fprintf(stderr
, "--%s", long_options
[option_index
].name
);
281 fprintf(stderr
, "-%c", opt
);
282 fprintf(stderr
, " would set mdadm mode to \"%s\", but it is already set to \"%s\".\n",
283 map_num(modes
, newmode
),
284 map_num(modes
, mode
));
286 } else if (!mode
&& newmode
) {
288 if (mode
== MISC
&& devs_found
) {
289 pr_err("No action given for %s in --misc mode\n",
291 cont_err("Action options must come before device names\n");
295 /* special case of -c --help */
296 if ((opt
== 'c' || opt
== ConfigFile
) &&
297 (strncmp(optarg
, "--h", 3) == 0 ||
298 strncmp(optarg
, "-h", 2) == 0)) {
299 fputs(Help_config
, stdout
);
303 /* If first option is a device, don't force the mode yet */
305 if (devs_found
== 0) {
306 dv
= xmalloc(sizeof(*dv
));
307 dv
->devname
= optarg
;
308 dv
->disposition
= devmode
;
309 dv
->writemostly
= writemostly
;
310 dv
->failfast
= failfast
;
314 devlistend
= &dv
->next
;
319 /* No mode yet, and this is the second device ... */
320 pr_err("An option must be given to set the mode before a second device\n"
321 " (%s) is listed\n", optarg
);
324 if (option_index
>= 0)
325 pr_err("--%s", long_options
[option_index
].name
);
328 fprintf(stderr
, " does not set the mode, and so cannot be the first option.\n");
332 /* if we just set the mode, then done */
346 /* an undecorated option - must be a device name.
349 if (devs_found
> 0 && devmode
== DetailPlatform
) {
350 pr_err("controller may only be specified once. %s ignored\n",
355 if (devs_found
> 0 && mode
== MANAGE
&& !devmode
) {
356 pr_err("Must give one of -a/-r/-f for subsequent devices at %s\n", optarg
);
359 if (devs_found
> 0 && mode
== GROW
&& !devmode
) {
360 pr_err("Must give -a/--add for devices to add: %s\n", optarg
);
363 dv
= xmalloc(sizeof(*dv
));
364 dv
->devname
= optarg
;
365 dv
->disposition
= devmode
;
366 dv
->writemostly
= writemostly
;
367 dv
->failfast
= failfast
;
371 devlistend
= &dv
->next
;
377 /* We've got a mode, and opt is now something else which
378 * could depend on the mode */
379 #define O(a,b) ((a<<16)|b)
380 switch (O(mode
,opt
)) {
382 case O(GROW
,ChunkSize
):
384 case O(CREATE
,ChunkSize
):
385 case O(BUILD
,'c'): /* chunk or rounding */
386 case O(BUILD
,ChunkSize
): /* chunk or rounding */
388 pr_err("chunk/rounding may only be specified once. Second value is %s.\n", optarg
);
391 s
.chunk
= parse_size(optarg
);
392 if (s
.chunk
== INVALID_SECTORS
||
393 s
.chunk
< 8 || (s
.chunk
&1)) {
394 pr_err("invalid chunk/rounding value: %s\n",
398 /* Convert sectors to K */
402 case O(INCREMENTAL
, 'e'):
404 case O(ASSEMBLE
,'e'):
405 case O(MISC
,'e'): /* set metadata (superblock) information */
407 pr_err("metadata information already given\n");
410 for(i
= 0; !ss
&& superlist
[i
]; i
++)
411 ss
= superlist
[i
]->match_metadata_desc(optarg
);
414 pr_err("unrecognised metadata identifier: %s\n", optarg
);
420 case O(MANAGE
,WriteMostly
):
422 case O(BUILD
,WriteMostly
):
424 case O(CREATE
,WriteMostly
):
425 /* set write-mostly for following devices */
426 writemostly
= FlagSet
;
430 /* clear write-mostly for following devices */
431 writemostly
= FlagClear
;
434 case O(MANAGE
,FailFast
):
435 case O(CREATE
,FailFast
):
438 case O(MANAGE
,NoFailFast
):
439 failfast
= FlagClear
;
444 case O(BUILD
,'z'): /* size */
446 pr_err("size may only be specified once. Second value is %s.\n", optarg
);
449 if (strcmp(optarg
, "max") == 0)
452 s
.size
= parse_size(optarg
);
453 if (s
.size
== INVALID_SECTORS
|| s
.size
< 8) {
454 pr_err("invalid size: %s\n", optarg
);
457 /* convert sectors to K */
462 case O(GROW
,'Z'): /* array size */
463 if (array_size
> 0) {
464 pr_err("array-size may only be specified once. Second value is %s.\n", optarg
);
467 if (strcmp(optarg
, "max") == 0)
468 array_size
= MAX_SIZE
;
470 array_size
= parse_size(optarg
);
471 if (array_size
== 0 ||
472 array_size
== INVALID_SECTORS
) {
473 pr_err("invalid array size: %s\n",
480 case O(CREATE
,DataOffset
):
481 case O(GROW
,DataOffset
):
482 if (data_offset
!= INVALID_SECTORS
) {
483 pr_err("data-offset may only be specified one. Second value is %s.\n", optarg
);
486 if (mode
== CREATE
&& strcmp(optarg
, "variable") == 0)
487 data_offset
= VARIABLE_OFFSET
;
489 data_offset
= parse_size(optarg
);
490 if (data_offset
== INVALID_SECTORS
) {
491 pr_err("invalid data-offset: %s\n",
499 case O(BUILD
,'l'): /* set raid level*/
500 if (s
.level
!= UnSet
) {
501 pr_err("raid level may only be set once. Second value is %s.\n", optarg
);
504 s
.level
= map_name(pers
, optarg
);
505 if (s
.level
== UnSet
) {
506 pr_err("invalid raid level: %s\n",
510 if (s
.level
!= 0 && s
.level
!= LEVEL_LINEAR
&&
511 s
.level
!= 1 && s
.level
!= LEVEL_MULTIPATH
&&
512 s
.level
!= LEVEL_FAULTY
&& s
.level
!= 10 &&
514 pr_err("Raid level %s not permitted with --build.\n",
518 if (s
.sparedisks
> 0 && s
.level
< 1 && s
.level
>= -1) {
519 pr_err("raid level %s is incompatible with spare-devices setting.\n",
523 ident
.level
= s
.level
;
526 case O(GROW
, 'p'): /* new layout */
527 case O(GROW
, Layout
):
529 pr_err("layout may only be sent once. Second value was %s\n", optarg
);
532 s
.layout_str
= optarg
;
533 /* 'Grow' will parse the value */
536 case O(CREATE
,'p'): /* raid5 layout */
537 case O(CREATE
,Layout
):
538 case O(BUILD
,'p'): /* faulty layout */
539 case O(BUILD
,Layout
):
540 if (s
.layout
!= UnSet
) {
541 pr_err("layout may only be sent once. Second value was %s\n", optarg
);
546 pr_err("layout not meaningful for %s arrays.\n",
547 map_num(pers
, s
.level
));
550 pr_err("raid level must be given before layout.\n");
554 s
.layout
= map_name(r0layout
, optarg
);
555 if (s
.layout
== UnSet
) {
556 pr_err("layout %s not understood for raid0.\n",
562 s
.layout
= map_name(r5layout
, optarg
);
563 if (s
.layout
== UnSet
) {
564 pr_err("layout %s not understood for raid5.\n",
570 s
.layout
= map_name(r6layout
, optarg
);
571 if (s
.layout
== UnSet
) {
572 pr_err("layout %s not understood for raid6.\n",
579 s
.layout
= parse_layout_10(optarg
);
581 pr_err("layout for raid10 must be 'nNN', 'oNN' or 'fNN' where NN is a number, not %s\n", optarg
);
589 s
.layout
= parse_layout_faulty(optarg
);
590 if (s
.layout
== -1) {
591 pr_err("layout %s not understood for faulty.\n",
599 case O(CREATE
,AssumeClean
):
600 case O(BUILD
,AssumeClean
): /* assume clean */
601 case O(GROW
,AssumeClean
):
607 case O(BUILD
,'n'): /* number of raid disks */
609 pr_err("raid-devices set twice: %d and %s\n",
610 s
.raiddisks
, optarg
);
613 s
.raiddisks
= parse_num(optarg
);
614 if (s
.raiddisks
<= 0) {
615 pr_err("invalid number of raid devices: %s\n",
619 ident
.raid_disks
= s
.raiddisks
;
621 case O(ASSEMBLE
, Nodes
):
623 case O(CREATE
, Nodes
):
624 c
.nodes
= parse_num(optarg
);
626 pr_err("clustered array needs two nodes at least: %s\n",
631 case O(CREATE
, ClusterName
):
632 case O(ASSEMBLE
, ClusterName
):
633 c
.homecluster
= optarg
;
634 if (strlen(c
.homecluster
) > 64) {
635 pr_err("Cluster name too big.\n");
639 case O(CREATE
,'x'): /* number of spare (eXtra) disks */
641 pr_err("spare-devices set twice: %d and %s\n",
642 s
.sparedisks
, optarg
);
645 if (s
.level
!= UnSet
&& s
.level
<= 0 && s
.level
>= -1) {
646 pr_err("spare-devices setting is incompatible with raid level %d\n",
650 s
.sparedisks
= parse_num(optarg
);
651 if (s
.sparedisks
< 0) {
652 pr_err("invalid number of spare-devices: %s\n",
662 case O(INCREMENTAL
,'a'):
663 case O(INCREMENTAL
,Auto
):
664 case O(ASSEMBLE
,'a'):
665 case O(ASSEMBLE
,Auto
): /* auto-creation of device node */
666 c
.autof
= parse_auto(optarg
, "--auto flag", 0);
669 case O(CREATE
,Symlinks
):
670 case O(BUILD
,Symlinks
):
671 case O(ASSEMBLE
,Symlinks
): /* auto creation of symlinks in /dev to /dev/md */
675 case O(BUILD
,'f'): /* force honouring '-n 1' */
676 case O(BUILD
,Force
): /* force honouring '-n 1' */
677 case O(GROW
,'f'): /* ditto */
678 case O(GROW
,Force
): /* ditto */
679 case O(CREATE
,'f'): /* force honouring of device list */
680 case O(CREATE
,Force
): /* force honouring of device list */
681 case O(ASSEMBLE
,'f'): /* force assembly */
682 case O(ASSEMBLE
,Force
): /* force assembly */
683 case O(MISC
,'f'): /* force zero */
684 case O(MISC
,Force
): /* force zero */
685 case O(MANAGE
,Force
): /* add device which is too large */
688 /* now for the Assemble options */
689 case O(ASSEMBLE
, FreezeReshape
): /* Freeze reshape during
691 case O(INCREMENTAL
, FreezeReshape
):
692 c
.freeze_reshape
= 1;
694 case O(CREATE
,'u'): /* uuid of array */
695 case O(ASSEMBLE
,'u'): /* uuid of array */
696 if (ident
.uuid_set
) {
697 pr_err("uuid cannot be set twice. Second value %s.\n", optarg
);
700 if (parse_uuid(optarg
, ident
.uuid
))
703 pr_err("Bad uuid: %s\n", optarg
);
709 case O(ASSEMBLE
,'N'):
712 pr_err("name cannot be set twice. Second value %s.\n", optarg
);
715 if (mode
== MISC
&& !c
.subarray
) {
716 pr_err("-N/--name only valid with --update-subarray in misc mode\n");
719 if (strlen(optarg
) > 32) {
720 pr_err("name '%s' is too long, 32 chars max.\n",
724 strcpy(ident
.name
, optarg
);
727 case O(ASSEMBLE
,'m'): /* super-minor for array */
728 case O(ASSEMBLE
,SuperMinor
):
729 if (ident
.super_minor
!= UnSet
) {
730 pr_err("super-minor cannot be set twice. Second value: %s.\n", optarg
);
733 if (strcmp(optarg
, "dev") == 0)
734 ident
.super_minor
= -2;
736 ident
.super_minor
= parse_num(optarg
);
737 if (ident
.super_minor
< 0) {
738 pr_err("Bad super-minor number: %s.\n", optarg
);
744 case O(ASSEMBLE
,'o'):
750 case O(ASSEMBLE
,'U'): /* update the superblock */
753 pr_err("Can only update one aspect of superblock, both %s and %s given.\n",
757 if (mode
== MISC
&& !c
.subarray
) {
758 pr_err("Only subarrays can be updated in misc mode\n");
762 if (strcmp(c
.update
, "sparc2.2") == 0)
764 if (strcmp(c
.update
, "super-minor") == 0)
766 if (strcmp(c
.update
, "summaries") == 0)
768 if (strcmp(c
.update
, "resync") == 0)
770 if (strcmp(c
.update
, "uuid") == 0)
772 if (strcmp(c
.update
, "name") == 0)
774 if (strcmp(c
.update
, "homehost") == 0)
776 if (strcmp(c
.update
, "home-cluster") == 0)
778 if (strcmp(c
.update
, "nodes") == 0)
780 if (strcmp(c
.update
, "devicesize") == 0)
782 if (strcmp(c
.update
, "bitmap") == 0)
784 if (strcmp(c
.update
, "no-bitmap") == 0)
786 if (strcmp(c
.update
, "bbl") == 0)
788 if (strcmp(c
.update
, "no-bbl") == 0)
790 if (strcmp(c
.update
, "force-no-bbl") == 0)
792 if (strcmp(c
.update
, "ppl") == 0)
794 if (strcmp(c
.update
, "no-ppl") == 0)
796 if (strcmp(c
.update
, "metadata") == 0)
798 if (strcmp(c
.update
, "revert-reshape") == 0)
800 if (strcmp(c
.update
, "layout-original") == 0 ||
801 strcmp(c
.update
, "layout-alternate") == 0 ||
802 strcmp(c
.update
, "layout-unspecified") == 0)
804 if (strcmp(c
.update
, "byteorder") == 0) {
806 pr_err("must not set metadata type with --update=byteorder.\n");
809 for(i
= 0; !ss
&& superlist
[i
]; i
++)
810 ss
= superlist
[i
]->match_metadata_desc(
813 pr_err("INTERNAL ERROR cannot find 0.swap\n");
819 if (strcmp(c
.update
,"?") == 0 ||
820 strcmp(c
.update
, "help") == 0) {
822 fprintf(outf
, "%s: ", Name
);
826 "%s: '--update=%s' is invalid. ",
829 fprintf(outf
, "Valid --update options are:\n"
830 " 'sparc2.2', 'super-minor', 'uuid', 'name', 'nodes', 'resync',\n"
831 " 'summaries', 'homehost', 'home-cluster', 'byteorder', 'devicesize',\n"
832 " 'bitmap', 'no-bitmap', 'metadata', 'revert-reshape'\n"
833 " 'bbl', 'no-bbl', 'force-no-bbl', 'ppl', 'no-ppl'\n"
834 " 'layout-original', 'layout-alternate', 'layout-unspecified'\n"
836 exit(outf
== stdout
? 0 : 2);
839 /* update=devicesize is allowed with --re-add */
840 if (devmode
!= 'A') {
841 pr_err("--update in Manage mode only allowed with --re-add.\n");
845 pr_err("Can only update one aspect of superblock, both %s and %s given.\n",
850 if (strcmp(c
.update
, "devicesize") != 0 &&
851 strcmp(c
.update
, "bbl") != 0 &&
852 strcmp(c
.update
, "force-no-bbl") != 0 &&
853 strcmp(c
.update
, "no-bbl") != 0) {
854 pr_err("only 'devicesize', 'bbl', 'no-bbl', and 'force-no-bbl' can be updated with --re-add\n");
859 case O(INCREMENTAL
,NoDegraded
):
860 pr_err("--no-degraded is deprecated in Incremental mode\n");
861 case O(ASSEMBLE
,NoDegraded
): /* --no-degraded */
862 c
.runstop
= -1; /* --stop isn't allowed for --assemble,
863 * so we overload slightly */
866 case O(ASSEMBLE
,'c'):
867 case O(ASSEMBLE
,ConfigFile
):
868 case O(INCREMENTAL
, 'c'):
869 case O(INCREMENTAL
, ConfigFile
):
871 case O(MISC
, ConfigFile
):
873 case O(MONITOR
,ConfigFile
):
874 case O(CREATE
,ConfigFile
):
876 pr_err("configfile cannot be set twice. Second value is %s.\n", optarg
);
880 set_conffile(configfile
);
881 /* FIXME possibly check that config file exists. Even parse it */
883 case O(ASSEMBLE
,'s'): /* scan */
886 case O(INCREMENTAL
,'s'):
890 case O(MONITOR
,'m'): /* mail address */
891 case O(MONITOR
,EMail
):
893 pr_err("only specify one mailaddress. %s ignored.\n",
899 case O(MONITOR
,'p'): /* alert program */
900 case O(MONITOR
,ProgramOpt
): /* alert program */
902 pr_err("only specify one alter program. %s ignored.\n",
908 case O(MONITOR
,'r'): /* rebuild increments */
909 case O(MONITOR
,Increment
):
910 increments
= atoi(optarg
);
911 if (increments
> 99 || increments
< 1) {
912 pr_err("please specify positive integer between 1 and 99 as rebuild increments.\n");
917 case O(MONITOR
,'d'): /* delay in seconds */
919 case O(BUILD
,'d'): /* delay for bitmap updates */
922 pr_err("only specify delay once. %s ignored.\n",
925 c
.delay
= parse_num(optarg
);
927 pr_err("invalid delay: %s\n",
933 case O(MONITOR
,'f'): /* daemonise */
934 case O(MONITOR
,Fork
):
937 case O(MONITOR
,'i'): /* pid */
939 pr_err("only specify one pid file. %s ignored.\n",
944 case O(MONITOR
,'1'): /* oneshot */
948 case O(MONITOR
,'t'): /* test */
951 case O(MONITOR
,'y'): /* log messages to syslog */
952 openlog("mdadm", LOG_PID
, SYSLOG_FACILITY
);
955 case O(MONITOR
, NoSharing
):
959 /* now the general management options. Some are applicable
960 * to other modes. None have arguments.
965 case O(MANAGE
,Add
): /* add a drive */
968 case O(MANAGE
,AddSpare
): /* add drive - never re-add */
971 case O(MANAGE
,AddJournal
): /* add journal */
972 if (s
.journaldisks
&& (s
.level
< 4 || s
.level
> 6)) {
973 pr_err("--add-journal is only supported for RAID level 4/5/6.\n");
978 case O(MANAGE
,ReAdd
):
981 case O(MANAGE
,'r'): /* remove a drive */
982 case O(MANAGE
,Remove
):
985 case O(MANAGE
,'f'): /* set faulty */
987 case O(INCREMENTAL
,'f'):
988 case O(INCREMENTAL
,Remove
):
989 case O(INCREMENTAL
,Fail
): /* r for incremental is taken, use f
990 * even though we will both fail and
991 * remove the device */
994 case O(MANAGE
, ClusterConfirm
):
997 case O(MANAGE
,Replace
):
998 /* Mark these devices for replacement */
1001 case O(MANAGE
,With
):
1002 /* These are the replacements to use */
1003 if (devmode
!= 'R') {
1004 pr_err("--with must follow --replace\n");
1009 case O(INCREMENTAL
,'R'):
1011 case O(ASSEMBLE
,'R'):
1013 case O(CREATE
,'R'): /* Run the array */
1014 if (c
.runstop
< 0) {
1015 pr_err("Cannot both Stop and Run an array\n");
1021 if (c
.runstop
> 0) {
1022 pr_err("Cannot both Run and Stop an array\n");
1034 case O(MISC
,KillOpt
):
1038 case O(MISC
, ExamineBB
):
1042 case O(MISC
, WaitOpt
):
1043 case O(MISC
, Waitclean
):
1044 case O(MISC
, DetailPlatform
):
1045 case O(MISC
, KillSubarray
):
1046 case O(MISC
, UpdateSubarray
):
1048 case O(MISC
, Restore
):
1049 case O(MISC
,Action
):
1050 if (opt
== KillSubarray
|| opt
== UpdateSubarray
) {
1052 pr_err("subarray can only be specified once\n");
1055 c
.subarray
= optarg
;
1057 if (opt
== Action
) {
1059 pr_err("Only one --action can be specified\n");
1062 if (strcmp(optarg
, "idle") == 0 ||
1063 strcmp(optarg
, "frozen") == 0 ||
1064 strcmp(optarg
, "check") == 0 ||
1065 strcmp(optarg
, "repair") == 0)
1068 pr_err("action must be one of idle, frozen, check, repair\n");
1072 if (devmode
&& devmode
!= opt
&&
1074 (opt
== 'E' && devmode
!= 'Q'))) {
1075 pr_err("--examine/-E cannot be given with ");
1076 if (devmode
== 'E') {
1077 if (option_index
>= 0)
1078 fprintf(stderr
, "--%s\n",
1079 long_options
[option_index
].name
);
1081 fprintf(stderr
, "-%c\n", opt
);
1082 } else if (isalpha(devmode
))
1083 fprintf(stderr
, "-%c\n", devmode
);
1085 fprintf(stderr
, "previous option\n");
1089 if (opt
== Dump
|| opt
== Restore
) {
1090 if (dump_directory
!= NULL
) {
1091 pr_err("dump/restore directory specified twice: %s and %s\n",
1092 dump_directory
, optarg
);
1095 dump_directory
= optarg
;
1098 case O(MISC
, UdevRules
):
1099 if (devmode
&& devmode
!= opt
) {
1100 pr_err("--udev-rules must be the only option.\n");
1103 pr_err("only specify one udev rule filename. %s ignored.\n",
1106 udev_filename
= optarg
;
1114 case O(MISC
, Sparc22
):
1115 if (devmode
!= 'E') {
1116 pr_err("--sparc2.2 only allowed with --examine\n");
1122 case O(ASSEMBLE
,'b'): /* here we simply set the bitmap file */
1123 case O(ASSEMBLE
,Bitmap
):
1125 pr_err("bitmap file needed with -b in --assemble mode\n");
1128 if (strcmp(optarg
, "internal") == 0 ||
1129 strcmp(optarg
, "clustered") == 0) {
1130 pr_err("no need to specify --bitmap when assembling"
1131 " arrays with internal or clustered bitmap\n");
1134 bitmap_fd
= open(optarg
, O_RDWR
);
1135 if (!*optarg
|| bitmap_fd
< 0) {
1136 pr_err("cannot open bitmap file %s: %s\n", optarg
, strerror(errno
));
1139 ident
.bitmap_fd
= bitmap_fd
; /* for Assemble */
1142 case O(ASSEMBLE
, BackupFile
):
1143 case O(GROW
, BackupFile
):
1144 /* Specify a file into which grow might place a backup,
1145 * or from which assemble might recover a backup
1147 if (c
.backup_file
) {
1148 pr_err("backup file already specified, rejecting %s\n", optarg
);
1151 c
.backup_file
= optarg
;
1154 case O(GROW
, Continue
):
1155 /* Continue interrupted grow
1159 case O(ASSEMBLE
, InvalidBackup
):
1160 /* Acknowledge that the backupfile is invalid, but ask
1161 * to continue anyway
1163 c
.invalid_backup
= 1;
1167 case O(BUILD
,Bitmap
):
1169 case O(CREATE
,Bitmap
): /* here we create the bitmap */
1171 case O(GROW
,Bitmap
):
1172 if (s
.bitmap_file
) {
1173 pr_err("bitmap cannot be set twice. Second value: %s.\n", optarg
);
1176 if (strcmp(optarg
, "internal") == 0 ||
1177 strcmp(optarg
, "none") == 0 ||
1178 strchr(optarg
, '/') != NULL
) {
1179 s
.bitmap_file
= optarg
;
1182 if (strcmp(optarg
, "clustered") == 0) {
1183 s
.bitmap_file
= optarg
;
1184 /* Set the default number of cluster nodes
1185 * to 4 if not already set by user
1192 pr_err("bitmap file must contain a '/', or be 'internal', or be 'clustered', or 'none'\n"
1193 " not '%s'\n", optarg
);
1196 case O(GROW
,BitmapChunk
):
1197 case O(BUILD
,BitmapChunk
):
1198 case O(CREATE
,BitmapChunk
): /* bitmap chunksize */
1199 s
.bitmap_chunk
= parse_size(optarg
);
1200 if (s
.bitmap_chunk
== 0 ||
1201 s
.bitmap_chunk
== INVALID_SECTORS
||
1202 s
.bitmap_chunk
& (s
.bitmap_chunk
- 1)) {
1203 pr_err("invalid bitmap chunksize: %s\n",
1207 s
.bitmap_chunk
= s
.bitmap_chunk
* 512;
1210 case O(GROW
, WriteBehind
):
1211 case O(BUILD
, WriteBehind
):
1212 case O(CREATE
, WriteBehind
): /* write-behind mode */
1213 s
.write_behind
= DEFAULT_MAX_WRITE_BEHIND
;
1215 s
.write_behind
= parse_num(optarg
);
1216 if (s
.write_behind
< 0 ||
1217 s
.write_behind
> 16383) {
1218 pr_err("Invalid value for maximum outstanding write-behind writes: %s.\n\tMust be between 0 and 16383.\n", optarg
);
1224 case O(INCREMENTAL
, 'r'):
1225 case O(INCREMENTAL
, RebuildMapOpt
):
1228 case O(INCREMENTAL
, IncrementalPath
):
1229 remove_path
= optarg
;
1231 case O(CREATE
, WriteJournal
):
1232 if (s
.journaldisks
) {
1233 pr_err("Please specify only one journal device for the array.\n");
1234 pr_err("Ignoring --write-journal %s...\n", optarg
);
1237 dv
= xmalloc(sizeof(*dv
));
1238 dv
->devname
= optarg
;
1239 dv
->disposition
= 'j'; /* WriteJournal */
1243 devlistend
= &dv
->next
;
1248 case O(CREATE
, 'k'):
1250 s
.consistency_policy
= map_name(consistency_policies
,
1252 if (s
.consistency_policy
< CONSISTENCY_POLICY_RESYNC
) {
1253 pr_err("Invalid consistency policy: %s\n",
1259 /* We have now processed all the valid options. Anything else is
1262 if (option_index
> 0)
1263 pr_err(":option --%s not valid in %s mode\n",
1264 long_options
[option_index
].name
,
1265 map_num(modes
, mode
));
1267 pr_err("option -%c not valid in %s mode\n",
1268 opt
, map_num(modes
, mode
));
1275 if (print_help
== 2)
1276 help_text
= OptionHelp
;
1278 help_text
= mode_help
[mode
];
1279 if (help_text
== NULL
)
1281 fputs(help_text
,stdout
);
1285 if (s
.journaldisks
) {
1286 if (s
.level
< 4 || s
.level
> 6) {
1287 pr_err("--write-journal is only supported for RAID level 4/5/6.\n");
1290 if (s
.consistency_policy
!= CONSISTENCY_POLICY_UNKNOWN
&&
1291 s
.consistency_policy
!= CONSISTENCY_POLICY_JOURNAL
) {
1292 pr_err("--write-journal is not supported with consistency policy: %s\n",
1293 map_num(consistency_policies
, s
.consistency_policy
));
1298 if (mode
== CREATE
&&
1299 s
.consistency_policy
!= CONSISTENCY_POLICY_UNKNOWN
) {
1301 pr_err("--consistency-policy not meaningful with level %s.\n",
1302 map_num(pers
, s
.level
));
1304 } else if (s
.consistency_policy
== CONSISTENCY_POLICY_JOURNAL
&&
1306 pr_err("--write-journal is required for consistency policy: %s\n",
1307 map_num(consistency_policies
, s
.consistency_policy
));
1309 } else if (s
.consistency_policy
== CONSISTENCY_POLICY_PPL
&&
1311 pr_err("PPL consistency policy is only supported for RAID level 5.\n");
1313 } else if (s
.consistency_policy
== CONSISTENCY_POLICY_BITMAP
&&
1315 strcmp(s
.bitmap_file
, "none") == 0)) {
1316 pr_err("--bitmap is required for consistency policy: %s\n",
1317 map_num(consistency_policies
, s
.consistency_policy
));
1319 } else if (s
.bitmap_file
&&
1320 strcmp(s
.bitmap_file
, "none") != 0 &&
1321 s
.consistency_policy
!= CONSISTENCY_POLICY_BITMAP
&&
1322 s
.consistency_policy
!= CONSISTENCY_POLICY_JOURNAL
) {
1323 pr_err("--bitmap is not compatible with consistency policy: %s\n",
1324 map_num(consistency_policies
, s
.consistency_policy
));
1329 if (!mode
&& devs_found
) {
1332 if (devlist
->disposition
== 0)
1333 devlist
->disposition
= devmode
;
1336 fputs(Usage
, stderr
);
1341 struct createinfo
*ci
= conf_get_create_info();
1343 if (strcasecmp(symlinks
, "yes") == 0)
1345 else if (strcasecmp(symlinks
, "no") == 0)
1348 pr_err("option --symlinks must be 'no' or 'yes'\n");
1352 /* Ok, got the option parsing out of the way
1353 * hopefully it's mostly right but there might be some stuff
1356 * That is mostly checked in the per-mode stuff but...
1358 * For @,B,C and A without -s, the first device listed must be
1359 * an md device. We check that here and open it.
1362 if (mode
== MANAGE
|| mode
== BUILD
|| mode
== CREATE
||
1363 mode
== GROW
|| (mode
== ASSEMBLE
&& ! c
.scan
)) {
1364 if (devs_found
< 1) {
1365 pr_err("an md device must be given in this mode\n");
1368 if ((int)ident
.super_minor
== -2 && c
.autof
) {
1369 pr_err("--super-minor=dev is incompatible with --auto\n");
1372 if (mode
== MANAGE
|| mode
== GROW
) {
1373 mdfd
= open_mddev(devlist
->devname
, 1);
1377 /* non-existent device is OK */
1378 mdfd
= open_mddev(devlist
->devname
, 0);
1380 pr_err("device %s exists but is not an md array.\n", devlist
->devname
);
1383 if ((int)ident
.super_minor
== -2) {
1386 pr_err("--super-minor=dev given, and listed device %s doesn't exist.\n",
1391 ident
.super_minor
= minor(stb
.st_rdev
);
1393 if (mdfd
>= 0 && mode
!= MANAGE
&& mode
!= GROW
) {
1394 /* We don't really want this open yet, we just might
1395 * have wanted to check some things
1403 if (s
.raiddisks
== 1 && !c
.force
&& s
.level
!= LEVEL_FAULTY
) {
1404 pr_err("'1' is an unusual number of drives for an array, so it is probably\n"
1405 " a mistake. If you really mean it you will need to specify --force before\n"
1406 " setting the number of drives.\n");
1411 if (c
.homehost
== NULL
&& c
.require_homehost
)
1412 c
.homehost
= conf_get_homehost(&c
.require_homehost
);
1413 if (c
.homehost
== NULL
|| strcasecmp(c
.homehost
, "<system>") == 0) {
1414 if (gethostname(sys_hostname
, sizeof(sys_hostname
)) == 0) {
1415 sys_hostname
[sizeof(sys_hostname
)-1] = 0;
1416 c
.homehost
= sys_hostname
;
1420 (!c
.homehost
[0] || strcasecmp(c
.homehost
, "<none>") == 0)) {
1422 c
.require_homehost
= 0;
1427 set_hooks(); /* set hooks from libs */
1429 if (c
.homecluster
== NULL
&& (c
.nodes
> 0)) {
1430 c
.homecluster
= conf_get_homecluster();
1431 if (c
.homecluster
== NULL
)
1432 rv
= get_cluster_name(&c
.homecluster
);
1434 pr_err("The md can't get cluster name\n");
1439 if (c
.update
&& strcmp(c
.update
, "nodes") == 0 && c
.nodes
== 0) {
1440 pr_err("Please specify nodes number with --nodes\n");
1444 if (c
.backup_file
&& data_offset
!= INVALID_SECTORS
) {
1445 pr_err("--backup-file and --data-offset are incompatible\n");
1449 if ((mode
== MISC
&& devmode
== 'E') ||
1450 (mode
== MONITOR
&& spare_sharing
== 0))
1451 /* Anyone may try this */;
1452 else if (geteuid() != 0) {
1453 pr_err("must be super-user to perform this action\n");
1457 ident
.autof
= c
.autof
;
1459 if (c
.scan
&& c
.verbose
< 2)
1460 /* --scan implied --brief unless -vv */
1463 if (mode
== CREATE
) {
1464 if (s
.bitmap_file
&& strcmp(s
.bitmap_file
, "clustered") == 0) {
1465 locked
= cluster_get_dlmlock();
1469 } else if (mode
== MANAGE
|| mode
== GROW
|| mode
== INCREMENTAL
) {
1470 if (!md_get_array_info(mdfd
, &array
) && (devmode
!= 'c')) {
1471 if (array
.state
& (1 << MD_SB_CLUSTERED
)) {
1472 locked
= cluster_get_dlmlock();
1481 /* readonly, add/remove, readwrite, runstop */
1483 rv
= Manage_ro(devlist
->devname
, mdfd
, c
.readonly
);
1484 if (!rv
&& devs_found
>1)
1485 rv
= Manage_subdevs(devlist
->devname
, mdfd
,
1486 devlist
->next
, c
.verbose
, c
.test
,
1488 if (!rv
&& c
.readonly
< 0)
1489 rv
= Manage_ro(devlist
->devname
, mdfd
, c
.readonly
);
1490 if (!rv
&& c
.runstop
> 0)
1491 rv
= Manage_run(devlist
->devname
, mdfd
, &c
);
1492 if (!rv
&& c
.runstop
< 0)
1493 rv
= Manage_stop(devlist
->devname
, mdfd
, c
.verbose
, 0);
1496 if (!c
.scan
&& c
.runstop
== -1) {
1497 pr_err("--no-degraded not meaningful without a --scan assembly.\n");
1499 } else if (devs_found
== 1 && ident
.uuid_set
== 0 &&
1500 ident
.super_minor
== UnSet
&& ident
.name
[0] == 0 &&
1502 /* Only a device has been given, so get details from config file */
1503 struct mddev_ident
*array_ident
= conf_get_ident(devlist
->devname
);
1504 if (array_ident
== NULL
) {
1505 pr_err("%s not identified in config file.\n",
1511 if (array_ident
->autof
== 0)
1512 array_ident
->autof
= c
.autof
;
1513 rv
|= Assemble(ss
, devlist
->devname
, array_ident
,
1517 rv
= Assemble(ss
, devlist
->devname
, &ident
,
1519 else if (devs_found
> 0) {
1520 if (c
.update
&& devs_found
> 1) {
1521 pr_err("can only update a single array at a time\n");
1524 if (c
.backup_file
&& devs_found
> 1) {
1525 pr_err("can only assemble a single array when providing a backup file.\n");
1528 for (dv
= devlist
; dv
; dv
= dv
->next
) {
1529 struct mddev_ident
*array_ident
= conf_get_ident(dv
->devname
);
1530 if (array_ident
== NULL
) {
1531 pr_err("%s not identified in config file.\n",
1536 if (array_ident
->autof
== 0)
1537 array_ident
->autof
= c
.autof
;
1538 rv
|= Assemble(ss
, dv
->devname
, array_ident
,
1543 pr_err("--update not meaningful with a --scan assembly.\n");
1546 if (c
.backup_file
) {
1547 pr_err("--backup_file not meaningful with a --scan assembly.\n");
1550 rv
= scan_assemble(ss
, &c
, &ident
);
1556 c
.delay
= DEFAULT_BITMAP_DELAY
;
1557 if (s
.write_behind
&& !s
.bitmap_file
) {
1558 pr_err("write-behind mode requires a bitmap.\n");
1562 if (s
.raiddisks
== 0) {
1563 pr_err("no raid-devices specified.\n");
1568 if (s
.bitmap_file
) {
1569 if (strcmp(s
.bitmap_file
, "internal") == 0 ||
1570 strcmp(s
.bitmap_file
, "clustered") == 0) {
1571 pr_err("'internal' and 'clustered' bitmaps not supported with --build\n");
1576 rv
= Build(devlist
->devname
, devlist
->next
, &s
, &c
);
1580 c
.delay
= DEFAULT_BITMAP_DELAY
;
1583 if (!s
.bitmap_file
||
1584 strcmp(s
.bitmap_file
, "clustered") != 0) {
1585 pr_err("--nodes argument only compatible with --bitmap=clustered\n");
1590 if (s
.level
!= 1 && s
.level
!= 10) {
1591 pr_err("--bitmap=clustered is currently supported with raid1/10 only\n");
1595 if (s
.level
== 10 && !(is_near_layout_10(s
.layout
) || s
.layout
== UnSet
)) {
1596 pr_err("only near layout is supported with clustered raid10\n");
1602 if (s
.write_behind
&& !s
.bitmap_file
) {
1603 pr_err("write-behind mode requires a bitmap.\n");
1607 if (s
.raiddisks
== 0) {
1608 pr_err("no raid-devices specified.\n");
1613 rv
= Create(ss
, devlist
->devname
,
1614 ident
.name
, ident
.uuid_set
? ident
.uuid
: NULL
,
1615 devs_found
-1, devlist
->next
,
1616 &s
, &c
, data_offset
);
1619 if (devmode
== 'E') {
1620 if (devlist
== NULL
&& !c
.scan
) {
1621 pr_err("No devices to examine\n");
1624 if (devlist
== NULL
)
1625 devlist
= conf_get_devs();
1626 if (devlist
== NULL
) {
1627 pr_err("No devices listed in %s\n", configfile
?configfile
:DefaultConfFile
);
1630 rv
= Examine(devlist
, &c
, ss
);
1631 } else if (devmode
== DetailPlatform
) {
1632 rv
= Detail_Platform(ss
? ss
->ss
: NULL
, ss
? c
.scan
: 1,
1633 c
.verbose
, c
.export
,
1634 devlist
? devlist
->devname
: NULL
);
1635 } else if (devlist
== NULL
) {
1636 if (devmode
== 'S' && c
.scan
)
1637 rv
= stop_scan(c
.verbose
);
1638 else if ((devmode
== 'D' || devmode
== Waitclean
) &&
1640 rv
= misc_scan(devmode
, &c
);
1641 else if (devmode
== UdevRules
)
1642 rv
= Write_rules(udev_filename
);
1644 pr_err("No devices given.\n");
1648 rv
= misc_list(devlist
, &ident
, dump_directory
, ss
, &c
);
1651 if (!devlist
&& !c
.scan
) {
1652 pr_err("Cannot monitor: need --scan or at least one device\n");
1656 if (pidfile
&& !daemonise
) {
1657 pr_err("Cannot write a pid file when not in daemon mode\n");
1662 if (get_linux_version() > 2006016)
1663 /* mdstat responds to poll */
1668 rv
= Monitor(devlist
, mailaddr
, program
,
1669 &c
, daemonise
, oneshot
,
1670 dosyslog
, pidfile
, increments
,
1675 if (array_size
> 0) {
1676 /* alway impose array size first, independent of
1678 * Do not allow level or raid_disks changes at the
1679 * same time as that can be irreversibly destructive.
1683 if (s
.raiddisks
|| s
.level
!= UnSet
) {
1684 pr_err("cannot change array size in same operation as changing raiddisks or level.\n"
1685 " Change size first, then check that data is still intact.\n");
1689 if (sysfs_init(&sra
, mdfd
, NULL
)) {
1693 if (array_size
== MAX_SIZE
)
1694 err
= sysfs_set_str(&sra
, NULL
, "array_size", "default");
1696 err
= sysfs_set_num(&sra
, NULL
, "array_size", array_size
/ 2);
1699 pr_err("--array-size setting is too large.\n");
1701 pr_err("current kernel does not support setting --array-size\n");
1706 if (devs_found
> 1 && s
.raiddisks
== 0 && s
.level
== UnSet
) {
1708 if (s
.size
> 0 || s
.chunk
||
1709 s
.layout_str
|| s
.bitmap_file
) {
1710 pr_err("--add cannot be used with other geometry changes in --grow mode\n");
1714 for (dv
= devlist
->next
; dv
; dv
= dv
->next
) {
1715 rv
= Grow_Add_device(devlist
->devname
, mdfd
,
1720 } else if (s
.bitmap_file
) {
1721 if (s
.size
> 0 || s
.raiddisks
|| s
.chunk
||
1722 s
.layout_str
|| devs_found
> 1) {
1723 pr_err("--bitmap changes cannot be used with other geometry changes in --grow mode\n");
1728 c
.delay
= DEFAULT_BITMAP_DELAY
;
1729 rv
= Grow_addbitmap(devlist
->devname
, mdfd
, &c
, &s
);
1730 } else if (grow_continue
)
1731 rv
= Grow_continue_command(devlist
->devname
,
1732 mdfd
, c
.backup_file
,
1734 else if (s
.size
> 0 || s
.raiddisks
|| s
.layout_str
||
1735 s
.chunk
!= 0 || s
.level
!= UnSet
||
1736 data_offset
!= INVALID_SECTORS
) {
1737 rv
= Grow_reshape(devlist
->devname
, mdfd
,
1739 data_offset
, &c
, &s
);
1740 } else if (s
.consistency_policy
!= CONSISTENCY_POLICY_UNKNOWN
) {
1741 rv
= Grow_consistency_policy(devlist
->devname
, mdfd
, &c
, &s
);
1742 } else if (array_size
== 0)
1743 pr_err("no changes to --grow\n");
1752 pr_err("In --incremental mode, a device cannot be given with --scan.\n");
1755 if (c
.runstop
<= 0) {
1756 pr_err("--incremental --scan meaningless without --run.\n");
1759 if (devmode
== 'f') {
1760 pr_err("--incremental --scan --fail not supported.\n");
1763 rv
= IncrementalScan(&c
, NULL
);
1766 if (!rebuild_map
&& !c
.scan
) {
1767 pr_err("--incremental requires a device.\n");
1772 if (devmode
== 'f') {
1773 if (devlist
->next
) {
1774 pr_err("'--incremental --fail' can only handle one device.\n");
1778 rv
= IncrementalRemove(devlist
->devname
, remove_path
,
1781 rv
= Incremental(devlist
, &c
, ss
);
1788 cluster_release_dlmlock();
1794 static int scan_assemble(struct supertype
*ss
,
1796 struct mddev_ident
*ident
)
1798 struct mddev_ident
*a
, *array_list
= conf_get_ident(NULL
);
1799 struct mddev_dev
*devlist
= conf_get_devs();
1800 struct map_ent
*map
= NULL
;
1803 int failures
, successes
;
1805 if (conf_verify_devnames(array_list
)) {
1806 pr_err("Duplicate MD device names in conf file were found.\n");
1809 if (devlist
== NULL
) {
1810 pr_err("No devices listed in conf file were found.\n");
1813 for (a
= array_list
; a
; a
= a
->next
) {
1816 a
->autof
= c
->autof
;
1819 pr_err("failed to get exclusive lock on mapfile\n");
1824 for (a
= array_list
; a
; a
= a
->next
) {
1829 strcasecmp(a
->devname
, "<ignore>") == 0)
1832 r
= Assemble(ss
, a
->devname
,
1842 } while (failures
&& successes
);
1843 if (c
->homehost
&& cnt
== 0) {
1844 /* Maybe we can auto-assemble something.
1845 * Repeatedly call Assemble in auto-assemble mode
1850 ident
->autof
= c
->autof
;
1852 struct mddev_dev
*devlist
= conf_get_devs();
1855 rv2
= Assemble(ss
, NULL
,
1863 /* Incase there are stacked devices, we need to go around again */
1865 if (cnt
== 0 && rv
== 0) {
1866 pr_err("No arrays found in config file or automatically\n");
1870 } else if (cnt
== 0 && rv
== 0) {
1871 pr_err("No arrays found in config file\n");
1878 static int misc_scan(char devmode
, struct context
*c
)
1880 /* apply --detail or --wait-clean to
1881 * all devices in /proc/mdstat
1883 struct mdstat_ent
*ms
= mdstat_read(0, 1);
1884 struct mdstat_ent
*e
;
1885 struct map_ent
*map
= NULL
;
1889 for (members
= 0; members
<= 1; members
++) {
1890 for (e
= ms
; e
; e
= e
->next
) {
1894 int member
= e
->metadata_version
&&
1895 strncmp(e
->metadata_version
,
1896 "external:/", 10) == 0;
1897 if (members
!= member
)
1899 me
= map_by_devnm(&map
, e
->devnm
);
1900 if (me
&& me
->path
&& strcmp(me
->path
, "/unknown") != 0)
1902 if (name
== NULL
|| stat(name
, &stb
) != 0)
1903 name
= get_md_name(e
->devnm
);
1906 pr_err("cannot find device file for %s\n",
1911 rv
|= Detail(name
, c
);
1913 rv
|= WaitClean(name
, c
->verbose
);
1923 static int stop_scan(int verbose
)
1925 /* apply --stop to all devices in /proc/mdstat */
1926 /* Due to possible stacking of devices, repeat until
1927 * nothing more can be stopped
1929 int progress
= 1, err
;
1933 struct mdstat_ent
*ms
= mdstat_read(0, 0);
1934 struct mdstat_ent
*e
;
1936 if (!progress
) last
= 1;
1937 progress
= 0; err
= 0;
1938 for (e
= ms
; e
; e
= e
->next
) {
1939 char *name
= get_md_name(e
->devnm
);
1943 pr_err("cannot find device file for %s\n",
1947 mdfd
= open_mddev(name
, 1);
1949 if (Manage_stop(name
, mdfd
, verbose
, !last
))
1959 } while (!last
&& err
);
1965 static int misc_list(struct mddev_dev
*devlist
,
1966 struct mddev_ident
*ident
,
1967 char *dump_directory
,
1968 struct supertype
*ss
, struct context
*c
)
1970 struct mddev_dev
*dv
;
1973 for (dv
= devlist
; dv
; dv
= (rv
& 16) ? NULL
: dv
->next
) {
1976 switch(dv
->disposition
) {
1978 rv
|= Detail(dv
->devname
, c
);
1980 case KillOpt
: /* Zero superblock */
1982 rv
|= Kill(dv
->devname
, ss
, c
->force
, c
->verbose
,0);
1986 rv
|= Kill(dv
->devname
, NULL
, c
->force
, v
, 0);
1993 rv
|= Query(dv
->devname
);
1996 rv
|= ExamineBitmap(dv
->devname
, c
->brief
, ss
);
1999 rv
|= ExamineBadblocks(dv
->devname
, c
->brief
, ss
);
2003 rv
|= Wait(dv
->devname
);
2006 rv
|= WaitClean(dv
->devname
, c
->verbose
);
2009 rv
|= Kill_subarray(dv
->devname
, c
->subarray
, c
->verbose
);
2011 case UpdateSubarray
:
2012 if (c
->update
== NULL
) {
2013 pr_err("-U/--update must be specified with --update-subarray\n");
2017 rv
|= Update_subarray(dv
->devname
, c
->subarray
,
2018 c
->update
, ident
, c
->verbose
);
2021 rv
|= Dump_metadata(dv
->devname
, dump_directory
, c
, ss
);
2024 rv
|= Restore_metadata(dv
->devname
, dump_directory
, c
, ss
,
2025 (dv
== devlist
&& dv
->next
== NULL
));
2028 rv
|= SetAction(dv
->devname
, c
->action
);
2032 if (dv
->devname
[0] != '/')
2033 mdfd
= open_dev(dv
->devname
);
2034 if (dv
->devname
[0] == '/' || mdfd
< 0)
2035 mdfd
= open_mddev(dv
->devname
, 1);
2038 switch(dv
->disposition
) {
2041 rv
|= Manage_run(dv
->devname
, mdfd
, c
);
2044 rv
|= Manage_stop(dv
->devname
, mdfd
, c
->verbose
, 0);
2047 rv
|= Manage_ro(dv
->devname
, mdfd
, 1);
2050 rv
|= Manage_ro(dv
->devname
, mdfd
, -1);
2060 int SetAction(char *dev
, char *action
)
2062 int fd
= open(dev
, O_RDONLY
);
2067 pr_err("Couldn't open %s: %s\n", dev
, strerror(errno
));
2070 retval
= sysfs_init(&mdi
, fd
, NULL
);
2073 pr_err("%s is no an md array\n", dev
);
2077 if (sysfs_set_str(&mdi
, NULL
, "sync_action", action
) < 0) {
2078 pr_err("Count not set action for %s to %s: %s\n",
2079 dev
, action
, strerror(errno
));