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
;
230 shortopt
= short_monitor_options
;
232 case 'G': newmode
= GROW
;
233 shortopt
= short_bitmap_options
;
235 case 'I': newmode
= INCREMENTAL
;
236 shortopt
= short_bitmap_auto_options
;
239 newmode
= AUTODETECT
;
274 if (mode
&& newmode
== mode
) {
275 /* everybody happy ! */
276 } else if (mode
&& newmode
!= mode
) {
279 if (option_index
>= 0)
280 fprintf(stderr
, "--%s", long_options
[option_index
].name
);
282 fprintf(stderr
, "-%c", opt
);
283 fprintf(stderr
, " would set mdadm mode to \"%s\", but it is already set to \"%s\".\n",
284 map_num_s(modes
, newmode
),
285 map_num_s(modes
, mode
));
287 } else if (!mode
&& newmode
) {
289 if (mode
== MISC
&& devs_found
) {
290 pr_err("No action given for %s in --misc mode\n",
292 cont_err("Action options must come before device names\n");
296 /* special case of -c --help */
297 if ((opt
== 'c' || opt
== ConfigFile
) &&
298 (strncmp(optarg
, "--h", 3) == 0 ||
299 strncmp(optarg
, "-h", 2) == 0)) {
300 fputs(Help_config
, stdout
);
304 /* If first option is a device, don't force the mode yet */
306 if (devs_found
== 0) {
307 dv
= xmalloc(sizeof(*dv
));
308 dv
->devname
= optarg
;
309 dv
->disposition
= devmode
;
310 dv
->writemostly
= writemostly
;
311 dv
->failfast
= failfast
;
315 devlistend
= &dv
->next
;
320 /* No mode yet, and this is the second device ... */
321 pr_err("An option must be given to set the mode before a second device\n"
322 " (%s) is listed\n", optarg
);
325 if (option_index
>= 0)
326 pr_err("--%s", long_options
[option_index
].name
);
329 fprintf(stderr
, " does not set the mode, and so cannot be the first option.\n");
333 /* if we just set the mode, then done */
347 /* an undecorated option - must be a device name.
350 if (devs_found
> 0 && devmode
== DetailPlatform
) {
351 pr_err("controller may only be specified once. %s ignored\n",
356 if (devs_found
> 0 && mode
== MANAGE
&& !devmode
) {
357 pr_err("Must give one of -a/-r/-f for subsequent devices at %s\n", optarg
);
360 if (devs_found
> 0 && mode
== GROW
&& !devmode
) {
361 pr_err("Must give -a/--add for devices to add: %s\n", optarg
);
364 dv
= xmalloc(sizeof(*dv
));
365 dv
->devname
= optarg
;
366 dv
->disposition
= devmode
;
367 dv
->writemostly
= writemostly
;
368 dv
->failfast
= failfast
;
372 devlistend
= &dv
->next
;
378 /* We've got a mode, and opt is now something else which
379 * could depend on the mode */
380 #define O(a,b) ((a<<16)|b)
381 switch (O(mode
,opt
)) {
383 case O(GROW
,ChunkSize
):
385 case O(CREATE
,ChunkSize
):
386 case O(BUILD
,'c'): /* chunk or rounding */
387 case O(BUILD
,ChunkSize
): /* chunk or rounding */
389 pr_err("chunk/rounding may only be specified once. Second value is %s.\n", optarg
);
392 s
.chunk
= parse_size(optarg
);
393 if (s
.chunk
== INVALID_SECTORS
||
394 s
.chunk
< 8 || (s
.chunk
&1)) {
395 pr_err("invalid chunk/rounding value: %s\n",
399 /* Convert sectors to K */
403 case O(INCREMENTAL
, 'e'):
405 case O(ASSEMBLE
,'e'):
406 case O(MISC
,'e'): /* set metadata (superblock) information */
408 pr_err("metadata information already given\n");
411 for(i
= 0; !ss
&& superlist
[i
]; i
++)
412 ss
= superlist
[i
]->match_metadata_desc(optarg
);
415 pr_err("unrecognised metadata identifier: %s\n", optarg
);
421 case O(MANAGE
,WriteMostly
):
423 case O(BUILD
,WriteMostly
):
425 case O(CREATE
,WriteMostly
):
426 /* set write-mostly for following devices */
427 writemostly
= FlagSet
;
431 /* clear write-mostly for following devices */
432 writemostly
= FlagClear
;
435 case O(MANAGE
,FailFast
):
436 case O(CREATE
,FailFast
):
439 case O(MANAGE
,NoFailFast
):
440 failfast
= FlagClear
;
445 case O(BUILD
,'z'): /* size */
447 pr_err("size may only be specified once. Second value is %s.\n", optarg
);
450 if (strcmp(optarg
, "max") == 0)
453 s
.size
= parse_size(optarg
);
454 if (s
.size
== INVALID_SECTORS
|| s
.size
< 8) {
455 pr_err("invalid size: %s\n", optarg
);
458 /* convert sectors to K */
463 case O(GROW
,'Z'): /* array size */
464 if (array_size
> 0) {
465 pr_err("array-size may only be specified once. Second value is %s.\n", optarg
);
468 if (strcmp(optarg
, "max") == 0)
469 array_size
= MAX_SIZE
;
471 array_size
= parse_size(optarg
);
472 if (array_size
== 0 ||
473 array_size
== INVALID_SECTORS
) {
474 pr_err("invalid array size: %s\n",
481 case O(CREATE
,DataOffset
):
482 case O(GROW
,DataOffset
):
483 if (data_offset
!= INVALID_SECTORS
) {
484 pr_err("data-offset may only be specified one. Second value is %s.\n", optarg
);
487 if (mode
== CREATE
&& strcmp(optarg
, "variable") == 0)
488 data_offset
= VARIABLE_OFFSET
;
490 data_offset
= parse_size(optarg
);
491 if (data_offset
== INVALID_SECTORS
) {
492 pr_err("invalid data-offset: %s\n",
500 case O(BUILD
,'l'): /* set raid level*/
501 if (s
.level
!= UnSet
) {
502 pr_err("raid level may only be set once. Second value is %s.\n", optarg
);
505 s
.level
= map_name(pers
, optarg
);
506 if (s
.level
== UnSet
) {
507 pr_err("invalid raid level: %s\n",
511 if (s
.level
!= 0 && s
.level
!= LEVEL_LINEAR
&&
512 s
.level
!= 1 && s
.level
!= LEVEL_MULTIPATH
&&
513 s
.level
!= LEVEL_FAULTY
&& s
.level
!= 10 &&
515 pr_err("Raid level %s not permitted with --build.\n",
519 if (s
.sparedisks
> 0 && s
.level
< 1 && s
.level
>= -1) {
520 pr_err("raid level %s is incompatible with spare-devices setting.\n",
524 ident
.level
= s
.level
;
527 case O(GROW
, 'p'): /* new layout */
528 case O(GROW
, Layout
):
530 pr_err("layout may only be sent once. Second value was %s\n", optarg
);
533 s
.layout_str
= optarg
;
534 /* 'Grow' will parse the value */
537 case O(CREATE
,'p'): /* raid5 layout */
538 case O(CREATE
,Layout
):
539 case O(BUILD
,'p'): /* faulty layout */
540 case O(BUILD
,Layout
):
541 if (s
.layout
!= UnSet
) {
542 pr_err("layout may only be sent once. Second value was %s\n", optarg
);
547 pr_err("layout not meaningful for %s arrays.\n",
548 map_num_s(pers
, s
.level
));
551 pr_err("raid level must be given before layout.\n");
555 s
.layout
= map_name(r0layout
, optarg
);
556 if (s
.layout
== UnSet
) {
557 pr_err("layout %s not understood for raid0.\n",
563 s
.layout
= map_name(r5layout
, optarg
);
564 if (s
.layout
== UnSet
) {
565 pr_err("layout %s not understood for raid5.\n",
571 s
.layout
= map_name(r6layout
, optarg
);
572 if (s
.layout
== UnSet
) {
573 pr_err("layout %s not understood for raid6.\n",
580 s
.layout
= parse_layout_10(optarg
);
582 pr_err("layout for raid10 must be 'nNN', 'oNN' or 'fNN' where NN is a number, not %s\n", optarg
);
590 s
.layout
= parse_layout_faulty(optarg
);
591 if (s
.layout
== -1) {
592 pr_err("layout %s not understood for faulty.\n",
600 case O(CREATE
,AssumeClean
):
601 case O(BUILD
,AssumeClean
): /* assume clean */
602 case O(GROW
,AssumeClean
):
608 case O(BUILD
,'n'): /* number of raid disks */
610 pr_err("raid-devices set twice: %d and %s\n",
611 s
.raiddisks
, optarg
);
614 if (parse_num(&s
.raiddisks
, optarg
) != 0 || 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 if (parse_num(&c
.nodes
, optarg
) != 0 || c
.nodes
< 2) {
625 pr_err("clustered array needs two nodes at least: %s\n",
630 case O(CREATE
, ClusterName
):
631 case O(ASSEMBLE
, ClusterName
):
632 c
.homecluster
= optarg
;
633 if (strlen(c
.homecluster
) > 64) {
634 pr_err("Cluster name too big.\n");
638 case O(CREATE
,'x'): /* number of spare (eXtra) disks */
640 pr_err("spare-devices set twice: %d and %s\n",
641 s
.sparedisks
, optarg
);
644 if (s
.level
!= UnSet
&& s
.level
<= 0 && s
.level
>= -1) {
645 pr_err("spare-devices setting is incompatible with raid level %d\n",
649 if (parse_num(&s
.sparedisks
, optarg
) != 0 || s
.sparedisks
< 0) {
650 pr_err("invalid number of spare-devices: %s\n",
660 case O(INCREMENTAL
,'a'):
661 case O(INCREMENTAL
,Auto
):
662 case O(ASSEMBLE
,'a'):
663 case O(ASSEMBLE
,Auto
): /* auto-creation of device node */
664 c
.autof
= parse_auto(optarg
, "--auto flag", 0);
667 case O(CREATE
,Symlinks
):
668 case O(BUILD
,Symlinks
):
669 case O(ASSEMBLE
,Symlinks
): /* auto creation of symlinks in /dev to /dev/md */
673 case O(BUILD
,'f'): /* force honouring '-n 1' */
674 case O(BUILD
,Force
): /* force honouring '-n 1' */
675 case O(GROW
,'f'): /* ditto */
676 case O(GROW
,Force
): /* ditto */
677 case O(CREATE
,'f'): /* force honouring of device list */
678 case O(CREATE
,Force
): /* force honouring of device list */
679 case O(ASSEMBLE
,'f'): /* force assembly */
680 case O(ASSEMBLE
,Force
): /* force assembly */
681 case O(MISC
,'f'): /* force zero */
682 case O(MISC
,Force
): /* force zero */
683 case O(MANAGE
,Force
): /* add device which is too large */
686 /* now for the Assemble options */
687 case O(ASSEMBLE
, FreezeReshape
): /* Freeze reshape during
689 case O(INCREMENTAL
, FreezeReshape
):
690 c
.freeze_reshape
= 1;
692 case O(CREATE
,'u'): /* uuid of array */
693 case O(ASSEMBLE
,'u'): /* uuid of array */
694 if (ident
.uuid_set
) {
695 pr_err("uuid cannot be set twice. Second value %s.\n", optarg
);
698 if (parse_uuid(optarg
, ident
.uuid
))
701 pr_err("Bad uuid: %s\n", optarg
);
707 case O(ASSEMBLE
,'N'):
710 pr_err("name cannot be set twice. Second value %s.\n", optarg
);
713 if (mode
== MISC
&& !c
.subarray
) {
714 pr_err("-N/--name only valid with --update-subarray in misc mode\n");
717 if (strlen(optarg
) > 32) {
718 pr_err("name '%s' is too long, 32 chars max.\n",
722 strcpy(ident
.name
, optarg
);
725 case O(ASSEMBLE
,'m'): /* super-minor for array */
726 case O(ASSEMBLE
,SuperMinor
):
727 if (ident
.super_minor
!= UnSet
) {
728 pr_err("super-minor cannot be set twice. Second value: %s.\n", optarg
);
731 if (strcmp(optarg
, "dev") == 0)
732 ident
.super_minor
= -2;
733 else if (parse_num(&ident
.super_minor
, optarg
) != 0 || ident
.super_minor
< 0) {
734 pr_err("Bad super-minor number: %s.\n", optarg
);
739 case O(ASSEMBLE
,'o'):
745 case O(ASSEMBLE
,'U'): /* update the superblock */
748 pr_err("Can only update one aspect of superblock, both %s and %s given.\n",
752 if (mode
== MISC
&& !c
.subarray
) {
753 pr_err("Only subarrays can be updated in misc mode\n");
757 if (strcmp(c
.update
, "sparc2.2") == 0)
759 if (strcmp(c
.update
, "super-minor") == 0)
761 if (strcmp(c
.update
, "summaries") == 0)
763 if (strcmp(c
.update
, "resync") == 0)
765 if (strcmp(c
.update
, "uuid") == 0)
767 if (strcmp(c
.update
, "name") == 0)
769 if (strcmp(c
.update
, "homehost") == 0)
771 if (strcmp(c
.update
, "home-cluster") == 0)
773 if (strcmp(c
.update
, "nodes") == 0)
775 if (strcmp(c
.update
, "devicesize") == 0)
777 if (strcmp(c
.update
, "bitmap") == 0)
779 if (strcmp(c
.update
, "no-bitmap") == 0)
781 if (strcmp(c
.update
, "bbl") == 0)
783 if (strcmp(c
.update
, "no-bbl") == 0)
785 if (strcmp(c
.update
, "force-no-bbl") == 0)
787 if (strcmp(c
.update
, "ppl") == 0)
789 if (strcmp(c
.update
, "no-ppl") == 0)
791 if (strcmp(c
.update
, "metadata") == 0)
793 if (strcmp(c
.update
, "revert-reshape") == 0)
795 if (strcmp(c
.update
, "layout-original") == 0 ||
796 strcmp(c
.update
, "layout-alternate") == 0 ||
797 strcmp(c
.update
, "layout-unspecified") == 0)
799 if (strcmp(c
.update
, "byteorder") == 0) {
801 pr_err("must not set metadata type with --update=byteorder.\n");
804 for(i
= 0; !ss
&& superlist
[i
]; i
++)
805 ss
= superlist
[i
]->match_metadata_desc(
808 pr_err("INTERNAL ERROR cannot find 0.swap\n");
814 if (strcmp(c
.update
,"?") == 0 ||
815 strcmp(c
.update
, "help") == 0) {
817 fprintf(outf
, "%s: ", Name
);
821 "%s: '--update=%s' is invalid. ",
824 fprintf(outf
, "Valid --update options are:\n"
825 " 'sparc2.2', 'super-minor', 'uuid', 'name', 'nodes', 'resync',\n"
826 " 'summaries', 'homehost', 'home-cluster', 'byteorder', 'devicesize',\n"
827 " 'bitmap', 'no-bitmap', 'metadata', 'revert-reshape'\n"
828 " 'bbl', 'no-bbl', 'force-no-bbl', 'ppl', 'no-ppl'\n"
829 " 'layout-original', 'layout-alternate', 'layout-unspecified'\n"
831 exit(outf
== stdout
? 0 : 2);
834 /* update=devicesize is allowed with --re-add */
835 if (devmode
!= 'A') {
836 pr_err("--update in Manage mode only allowed with --re-add.\n");
840 pr_err("Can only update one aspect of superblock, both %s and %s given.\n",
845 if (strcmp(c
.update
, "devicesize") != 0 &&
846 strcmp(c
.update
, "bbl") != 0 &&
847 strcmp(c
.update
, "force-no-bbl") != 0 &&
848 strcmp(c
.update
, "no-bbl") != 0) {
849 pr_err("only 'devicesize', 'bbl', 'no-bbl', and 'force-no-bbl' can be updated with --re-add\n");
854 case O(INCREMENTAL
,NoDegraded
):
855 pr_err("--no-degraded is deprecated in Incremental mode\n");
856 case O(ASSEMBLE
,NoDegraded
): /* --no-degraded */
857 c
.runstop
= -1; /* --stop isn't allowed for --assemble,
858 * so we overload slightly */
861 case O(ASSEMBLE
,'c'):
862 case O(ASSEMBLE
,ConfigFile
):
863 case O(INCREMENTAL
, 'c'):
864 case O(INCREMENTAL
, ConfigFile
):
866 case O(MISC
, ConfigFile
):
868 case O(MONITOR
,ConfigFile
):
869 case O(CREATE
,ConfigFile
):
871 pr_err("configfile cannot be set twice. Second value is %s.\n", optarg
);
875 set_conffile(configfile
);
876 /* FIXME possibly check that config file exists. Even parse it */
878 case O(ASSEMBLE
,'s'): /* scan */
881 case O(INCREMENTAL
,'s'):
885 case O(MONITOR
,'m'): /* mail address */
886 case O(MONITOR
,EMail
):
888 pr_err("only specify one mailaddress. %s ignored.\n",
894 case O(MONITOR
,'p'): /* alert program */
895 case O(MONITOR
,ProgramOpt
): /* alert program */
897 pr_err("only specify one alter program. %s ignored.\n",
903 case O(MONITOR
,'r'): /* rebuild increments */
904 case O(MONITOR
,Increment
):
905 if (parse_num(&increments
, optarg
) != 0
906 || increments
> 99 || increments
< 1) {
907 pr_err("please specify positive integer between 1 and 99 as rebuild increments.\n");
912 case O(MONITOR
,'d'): /* delay in seconds */
914 case O(BUILD
,'d'): /* delay for bitmap updates */
917 pr_err("only specify delay once. %s ignored.\n", optarg
);
918 else if (parse_num(&c
.delay
, optarg
) != 0 || c
.delay
< 1) {
919 pr_err("invalid delay: %s\n", optarg
);
923 case O(MONITOR
,'f'): /* daemonise */
924 case O(MONITOR
,Fork
):
927 case O(MONITOR
,'i'): /* pid */
929 pr_err("only specify one pid file. %s ignored.\n",
934 case O(MONITOR
,'1'): /* oneshot */
938 case O(MONITOR
,'t'): /* test */
941 case O(MONITOR
,'y'): /* log messages to syslog */
942 openlog("mdadm", LOG_PID
, SYSLOG_FACILITY
);
945 case O(MONITOR
, NoSharing
):
949 /* now the general management options. Some are applicable
950 * to other modes. None have arguments.
955 case O(MANAGE
,Add
): /* add a drive */
958 case O(MANAGE
,AddSpare
): /* add drive - never re-add */
961 case O(MANAGE
,AddJournal
): /* add journal */
962 if (s
.journaldisks
&& (s
.level
< 4 || s
.level
> 6)) {
963 pr_err("--add-journal is only supported for RAID level 4/5/6.\n");
968 case O(MANAGE
,ReAdd
):
971 case O(MANAGE
,'r'): /* remove a drive */
972 case O(MANAGE
,Remove
):
975 case O(MANAGE
,'f'): /* set faulty */
977 case O(INCREMENTAL
,'f'):
978 case O(INCREMENTAL
,Remove
):
979 case O(INCREMENTAL
,Fail
): /* r for incremental is taken, use f
980 * even though we will both fail and
981 * remove the device */
984 case O(MANAGE
, ClusterConfirm
):
987 case O(MANAGE
,Replace
):
988 /* Mark these devices for replacement */
992 /* These are the replacements to use */
993 if (devmode
!= 'R') {
994 pr_err("--with must follow --replace\n");
999 case O(INCREMENTAL
,'R'):
1001 case O(ASSEMBLE
,'R'):
1003 case O(CREATE
,'R'): /* Run the array */
1004 if (c
.runstop
< 0) {
1005 pr_err("Cannot both Stop and Run an array\n");
1011 if (c
.runstop
> 0) {
1012 pr_err("Cannot both Run and Stop an array\n");
1024 case O(MISC
,KillOpt
):
1028 case O(MISC
, ExamineBB
):
1032 case O(MISC
, WaitOpt
):
1033 case O(MISC
, Waitclean
):
1034 case O(MISC
, DetailPlatform
):
1035 case O(MISC
, KillSubarray
):
1036 case O(MISC
, UpdateSubarray
):
1038 case O(MISC
, Restore
):
1039 case O(MISC
,Action
):
1040 if (opt
== KillSubarray
|| opt
== UpdateSubarray
) {
1042 pr_err("subarray can only be specified once\n");
1045 c
.subarray
= optarg
;
1047 if (opt
== Action
) {
1049 pr_err("Only one --action can be specified\n");
1052 if (strcmp(optarg
, "idle") == 0 ||
1053 strcmp(optarg
, "frozen") == 0 ||
1054 strcmp(optarg
, "check") == 0 ||
1055 strcmp(optarg
, "repair") == 0)
1058 pr_err("action must be one of idle, frozen, check, repair\n");
1062 if (devmode
&& devmode
!= opt
&&
1064 (opt
== 'E' && devmode
!= 'Q'))) {
1065 pr_err("--examine/-E cannot be given with ");
1066 if (devmode
== 'E') {
1067 if (option_index
>= 0)
1068 fprintf(stderr
, "--%s\n",
1069 long_options
[option_index
].name
);
1071 fprintf(stderr
, "-%c\n", opt
);
1072 } else if (isalpha(devmode
))
1073 fprintf(stderr
, "-%c\n", devmode
);
1075 fprintf(stderr
, "previous option\n");
1079 if (opt
== Dump
|| opt
== Restore
) {
1080 if (dump_directory
!= NULL
) {
1081 pr_err("dump/restore directory specified twice: %s and %s\n",
1082 dump_directory
, optarg
);
1085 dump_directory
= optarg
;
1088 case O(MISC
, UdevRules
):
1089 if (devmode
&& devmode
!= opt
) {
1090 pr_err("--udev-rules must be the only option.\n");
1093 pr_err("only specify one udev rule filename. %s ignored.\n",
1096 udev_filename
= optarg
;
1104 case O(MISC
, Sparc22
):
1105 if (devmode
!= 'E') {
1106 pr_err("--sparc2.2 only allowed with --examine\n");
1112 case O(ASSEMBLE
,'b'): /* here we simply set the bitmap file */
1113 case O(ASSEMBLE
,Bitmap
):
1115 pr_err("bitmap file needed with -b in --assemble mode\n");
1118 if (strcmp(optarg
, "internal") == 0 ||
1119 strcmp(optarg
, "clustered") == 0) {
1120 pr_err("no need to specify --bitmap when assembling"
1121 " arrays with internal or clustered bitmap\n");
1124 bitmap_fd
= open(optarg
, O_RDWR
);
1125 if (!*optarg
|| bitmap_fd
< 0) {
1126 pr_err("cannot open bitmap file %s: %s\n", optarg
, strerror(errno
));
1129 ident
.bitmap_fd
= bitmap_fd
; /* for Assemble */
1132 case O(ASSEMBLE
, BackupFile
):
1133 case O(GROW
, BackupFile
):
1134 /* Specify a file into which grow might place a backup,
1135 * or from which assemble might recover a backup
1137 if (c
.backup_file
) {
1138 pr_err("backup file already specified, rejecting %s\n", optarg
);
1141 c
.backup_file
= optarg
;
1144 case O(GROW
, Continue
):
1145 /* Continue interrupted grow
1149 case O(ASSEMBLE
, InvalidBackup
):
1150 /* Acknowledge that the backupfile is invalid, but ask
1151 * to continue anyway
1153 c
.invalid_backup
= 1;
1157 case O(BUILD
,Bitmap
):
1159 case O(CREATE
,Bitmap
): /* here we create the bitmap */
1161 case O(GROW
,Bitmap
):
1162 if (s
.bitmap_file
) {
1163 pr_err("bitmap cannot be set twice. Second value: %s.\n", optarg
);
1166 if (strcmp(optarg
, "internal") == 0 ||
1167 strcmp(optarg
, "none") == 0 ||
1168 strchr(optarg
, '/') != NULL
) {
1169 s
.bitmap_file
= optarg
;
1172 if (strcmp(optarg
, "clustered") == 0) {
1173 s
.bitmap_file
= optarg
;
1174 /* Set the default number of cluster nodes
1175 * to 4 if not already set by user
1182 pr_err("bitmap file must contain a '/', or be 'internal', or be 'clustered', or 'none'\n"
1183 " not '%s'\n", optarg
);
1186 case O(GROW
,BitmapChunk
):
1187 case O(BUILD
,BitmapChunk
):
1188 case O(CREATE
,BitmapChunk
): /* bitmap chunksize */
1189 s
.bitmap_chunk
= parse_size(optarg
);
1190 if (s
.bitmap_chunk
== 0 ||
1191 s
.bitmap_chunk
== INVALID_SECTORS
||
1192 s
.bitmap_chunk
& (s
.bitmap_chunk
- 1)) {
1193 pr_err("invalid bitmap chunksize: %s\n",
1197 s
.bitmap_chunk
= s
.bitmap_chunk
* 512;
1200 case O(GROW
, WriteBehind
):
1201 case O(BUILD
, WriteBehind
):
1202 case O(CREATE
, WriteBehind
):
1203 s
.write_behind
= DEFAULT_MAX_WRITE_BEHIND
;
1204 if (parse_num(&s
.write_behind
, optarg
) != 0 ||
1205 s
.write_behind
< 0 || s
.write_behind
> 16383) {
1206 pr_err("Invalid value for maximum outstanding write-behind writes: %s.\n\tMust be between 0 and 16383.\n",
1211 case O(INCREMENTAL
, 'r'):
1212 case O(INCREMENTAL
, RebuildMapOpt
):
1215 case O(INCREMENTAL
, IncrementalPath
):
1216 remove_path
= optarg
;
1218 case O(CREATE
, WriteJournal
):
1219 if (s
.journaldisks
) {
1220 pr_err("Please specify only one journal device for the array.\n");
1221 pr_err("Ignoring --write-journal %s...\n", optarg
);
1224 dv
= xmalloc(sizeof(*dv
));
1225 dv
->devname
= optarg
;
1226 dv
->disposition
= 'j'; /* WriteJournal */
1230 devlistend
= &dv
->next
;
1235 case O(CREATE
, 'k'):
1237 s
.consistency_policy
= map_name(consistency_policies
,
1239 if (s
.consistency_policy
< CONSISTENCY_POLICY_RESYNC
) {
1240 pr_err("Invalid consistency policy: %s\n",
1246 /* We have now processed all the valid options. Anything else is
1249 if (option_index
> 0)
1250 pr_err(":option --%s not valid in %s mode\n",
1251 long_options
[option_index
].name
,
1252 map_num_s(modes
, mode
));
1254 pr_err("option -%c not valid in %s mode\n",
1255 opt
, map_num_s(modes
, mode
));
1262 if (print_help
== 2)
1263 help_text
= OptionHelp
;
1265 help_text
= mode_help
[mode
];
1266 if (help_text
== NULL
)
1268 fputs(help_text
,stdout
);
1272 if (s
.journaldisks
) {
1273 if (s
.level
< 4 || s
.level
> 6) {
1274 pr_err("--write-journal is only supported for RAID level 4/5/6.\n");
1277 if (s
.consistency_policy
!= CONSISTENCY_POLICY_UNKNOWN
&&
1278 s
.consistency_policy
!= CONSISTENCY_POLICY_JOURNAL
) {
1279 pr_err("--write-journal is not supported with consistency policy: %s\n",
1280 map_num_s(consistency_policies
, s
.consistency_policy
));
1285 if (mode
== CREATE
&&
1286 s
.consistency_policy
!= CONSISTENCY_POLICY_UNKNOWN
) {
1288 pr_err("--consistency-policy not meaningful with level %s.\n",
1289 map_num_s(pers
, s
.level
));
1291 } else if (s
.consistency_policy
== CONSISTENCY_POLICY_JOURNAL
&&
1293 pr_err("--write-journal is required for consistency policy: %s\n",
1294 map_num_s(consistency_policies
, s
.consistency_policy
));
1296 } else if (s
.consistency_policy
== CONSISTENCY_POLICY_PPL
&&
1298 pr_err("PPL consistency policy is only supported for RAID level 5.\n");
1300 } else if (s
.consistency_policy
== CONSISTENCY_POLICY_BITMAP
&&
1302 strcmp(s
.bitmap_file
, "none") == 0)) {
1303 pr_err("--bitmap is required for consistency policy: %s\n",
1304 map_num_s(consistency_policies
, s
.consistency_policy
));
1306 } else if (s
.bitmap_file
&&
1307 strcmp(s
.bitmap_file
, "none") != 0 &&
1308 s
.consistency_policy
!= CONSISTENCY_POLICY_BITMAP
&&
1309 s
.consistency_policy
!= CONSISTENCY_POLICY_JOURNAL
) {
1310 pr_err("--bitmap is not compatible with consistency policy: %s\n",
1311 map_num_s(consistency_policies
, s
.consistency_policy
));
1316 if (!mode
&& devs_found
) {
1319 if (devlist
->disposition
== 0)
1320 devlist
->disposition
= devmode
;
1323 fputs(Usage
, stderr
);
1328 struct createinfo
*ci
= conf_get_create_info();
1330 if (strcasecmp(symlinks
, "yes") == 0)
1332 else if (strcasecmp(symlinks
, "no") == 0)
1335 pr_err("option --symlinks must be 'no' or 'yes'\n");
1339 /* Ok, got the option parsing out of the way
1340 * hopefully it's mostly right but there might be some stuff
1343 * That is mostly checked in the per-mode stuff but...
1345 * For @,B,C and A without -s, the first device listed must be
1346 * an md device. We check that here and open it.
1349 if (mode
== MANAGE
|| mode
== BUILD
|| mode
== CREATE
||
1350 mode
== GROW
|| (mode
== ASSEMBLE
&& ! c
.scan
)) {
1351 if (devs_found
< 1) {
1352 pr_err("an md device must be given in this mode\n");
1355 if ((int)ident
.super_minor
== -2 && c
.autof
) {
1356 pr_err("--super-minor=dev is incompatible with --auto\n");
1359 if (mode
== MANAGE
|| mode
== GROW
) {
1360 mdfd
= open_mddev(devlist
->devname
, 1);
1364 char *bname
= basename(devlist
->devname
);
1366 if (strlen(bname
) > MD_NAME_MAX
) {
1367 pr_err("Name %s is too long.\n", devlist
->devname
);
1370 /* non-existent device is OK */
1371 mdfd
= open_mddev(devlist
->devname
, 0);
1374 pr_err("device %s exists but is not an md array.\n", devlist
->devname
);
1377 if ((int)ident
.super_minor
== -2) {
1380 pr_err("--super-minor=dev given, and listed device %s doesn't exist.\n",
1385 ident
.super_minor
= minor(stb
.st_rdev
);
1387 if (mdfd
>= 0 && mode
!= MANAGE
&& mode
!= GROW
) {
1388 /* We don't really want this open yet, we just might
1389 * have wanted to check some things
1397 if (s
.raiddisks
== 1 && !c
.force
&& s
.level
!= LEVEL_FAULTY
) {
1398 pr_err("'1' is an unusual number of drives for an array, so it is probably\n"
1399 " a mistake. If you really mean it you will need to specify --force before\n"
1400 " setting the number of drives.\n");
1405 if (c
.homehost
== NULL
&& c
.require_homehost
)
1406 c
.homehost
= conf_get_homehost(&c
.require_homehost
);
1407 if (c
.homehost
== NULL
|| strcasecmp(c
.homehost
, "<system>") == 0) {
1408 if (gethostname(sys_hostname
, sizeof(sys_hostname
)) == 0) {
1409 sys_hostname
[sizeof(sys_hostname
)-1] = 0;
1410 c
.homehost
= sys_hostname
;
1414 (!c
.homehost
[0] || strcasecmp(c
.homehost
, "<none>") == 0)) {
1416 c
.require_homehost
= 0;
1421 set_hooks(); /* set hooks from libs */
1423 if (c
.homecluster
== NULL
&& (c
.nodes
> 0)) {
1424 c
.homecluster
= conf_get_homecluster();
1425 if (c
.homecluster
== NULL
)
1426 rv
= get_cluster_name(&c
.homecluster
);
1428 pr_err("The md can't get cluster name\n");
1433 if (c
.update
&& strcmp(c
.update
, "nodes") == 0 && c
.nodes
== 0) {
1434 pr_err("Please specify nodes number with --nodes\n");
1438 if (c
.backup_file
&& data_offset
!= INVALID_SECTORS
) {
1439 pr_err("--backup-file and --data-offset are incompatible\n");
1443 if ((mode
== MISC
&& devmode
== 'E') ||
1444 (mode
== MONITOR
&& spare_sharing
== 0))
1445 /* Anyone may try this */;
1446 else if (geteuid() != 0) {
1447 pr_err("must be super-user to perform this action\n");
1451 ident
.autof
= c
.autof
;
1453 if (c
.scan
&& c
.verbose
< 2)
1454 /* --scan implied --brief unless -vv */
1457 if (mode
== CREATE
) {
1458 if (s
.bitmap_file
&& strcmp(s
.bitmap_file
, "clustered") == 0) {
1459 locked
= cluster_get_dlmlock();
1463 } else if (mode
== MANAGE
|| mode
== GROW
|| mode
== INCREMENTAL
) {
1464 if (!md_get_array_info(mdfd
, &array
) && (devmode
!= 'c')) {
1465 if (array
.state
& (1 << MD_SB_CLUSTERED
)) {
1466 locked
= cluster_get_dlmlock();
1475 /* readonly, add/remove, readwrite, runstop */
1477 rv
= Manage_ro(devlist
->devname
, mdfd
, c
.readonly
);
1478 if (!rv
&& devs_found
>1)
1479 rv
= Manage_subdevs(devlist
->devname
, mdfd
,
1480 devlist
->next
, c
.verbose
, c
.test
,
1482 if (!rv
&& c
.readonly
< 0)
1483 rv
= Manage_ro(devlist
->devname
, mdfd
, c
.readonly
);
1484 if (!rv
&& c
.runstop
> 0)
1485 rv
= Manage_run(devlist
->devname
, mdfd
, &c
);
1486 if (!rv
&& c
.runstop
< 0)
1487 rv
= Manage_stop(devlist
->devname
, mdfd
, c
.verbose
, 0);
1490 if (!c
.scan
&& c
.runstop
== -1) {
1491 pr_err("--no-degraded not meaningful without a --scan assembly.\n");
1493 } else if (devs_found
== 1 && ident
.uuid_set
== 0 &&
1494 ident
.super_minor
== UnSet
&& ident
.name
[0] == 0 &&
1496 /* Only a device has been given, so get details from config file */
1497 struct mddev_ident
*array_ident
= conf_get_ident(devlist
->devname
);
1498 if (array_ident
== NULL
) {
1499 pr_err("%s not identified in config file.\n",
1505 if (array_ident
->autof
== 0)
1506 array_ident
->autof
= c
.autof
;
1507 rv
|= Assemble(ss
, devlist
->devname
, array_ident
,
1511 rv
= Assemble(ss
, devlist
->devname
, &ident
,
1513 else if (devs_found
> 0) {
1514 if (c
.update
&& devs_found
> 1) {
1515 pr_err("can only update a single array at a time\n");
1518 if (c
.backup_file
&& devs_found
> 1) {
1519 pr_err("can only assemble a single array when providing a backup file.\n");
1522 for (dv
= devlist
; dv
; dv
= dv
->next
) {
1523 struct mddev_ident
*array_ident
= conf_get_ident(dv
->devname
);
1524 if (array_ident
== NULL
) {
1525 pr_err("%s not identified in config file.\n",
1530 if (array_ident
->autof
== 0)
1531 array_ident
->autof
= c
.autof
;
1532 rv
|= Assemble(ss
, dv
->devname
, array_ident
,
1537 pr_err("--update not meaningful with a --scan assembly.\n");
1540 if (c
.backup_file
) {
1541 pr_err("--backup_file not meaningful with a --scan assembly.\n");
1544 rv
= scan_assemble(ss
, &c
, &ident
);
1550 c
.delay
= DEFAULT_BITMAP_DELAY
;
1551 if (s
.write_behind
&& !s
.bitmap_file
) {
1552 pr_err("write-behind mode requires a bitmap.\n");
1556 if (s
.raiddisks
== 0) {
1557 pr_err("no raid-devices specified.\n");
1562 if (s
.bitmap_file
) {
1563 if (strcmp(s
.bitmap_file
, "internal") == 0 ||
1564 strcmp(s
.bitmap_file
, "clustered") == 0) {
1565 pr_err("'internal' and 'clustered' bitmaps not supported with --build\n");
1570 rv
= Build(devlist
->devname
, devlist
->next
, &s
, &c
);
1574 c
.delay
= DEFAULT_BITMAP_DELAY
;
1577 if (!s
.bitmap_file
||
1578 strcmp(s
.bitmap_file
, "clustered") != 0) {
1579 pr_err("--nodes argument only compatible with --bitmap=clustered\n");
1584 if (s
.level
!= 1 && s
.level
!= 10) {
1585 pr_err("--bitmap=clustered is currently supported with raid1/10 only\n");
1589 if (s
.level
== 10 && !(is_near_layout_10(s
.layout
) || s
.layout
== UnSet
)) {
1590 pr_err("only near layout is supported with clustered raid10\n");
1596 if (s
.write_behind
&& !s
.bitmap_file
) {
1597 pr_err("write-behind mode requires a bitmap.\n");
1601 if (s
.raiddisks
== 0) {
1602 pr_err("no raid-devices specified.\n");
1607 rv
= Create(ss
, devlist
->devname
,
1608 ident
.name
, ident
.uuid_set
? ident
.uuid
: NULL
,
1609 devs_found
-1, devlist
->next
,
1610 &s
, &c
, data_offset
);
1613 if (devmode
== 'E') {
1614 if (devlist
== NULL
&& !c
.scan
) {
1615 pr_err("No devices to examine\n");
1618 if (devlist
== NULL
)
1619 devlist
= conf_get_devs();
1620 if (devlist
== NULL
) {
1621 pr_err("No devices listed in %s\n", configfile
?configfile
:DefaultConfFile
);
1624 rv
= Examine(devlist
, &c
, ss
);
1625 } else if (devmode
== DetailPlatform
) {
1626 rv
= Detail_Platform(ss
? ss
->ss
: NULL
, ss
? c
.scan
: 1,
1627 c
.verbose
, c
.export
,
1628 devlist
? devlist
->devname
: NULL
);
1629 } else if (devlist
== NULL
) {
1630 if (devmode
== 'S' && c
.scan
)
1631 rv
= stop_scan(c
.verbose
);
1632 else if ((devmode
== 'D' || devmode
== Waitclean
) &&
1634 rv
= misc_scan(devmode
, &c
);
1635 else if (devmode
== UdevRules
)
1636 rv
= Write_rules(udev_filename
);
1638 pr_err("No devices given.\n");
1642 rv
= misc_list(devlist
, &ident
, dump_directory
, ss
, &c
);
1645 if (!devlist
&& !c
.scan
) {
1646 pr_err("Cannot monitor: need --scan or at least one device\n");
1650 if (pidfile
&& !daemonise
) {
1651 pr_err("Cannot write a pid file when not in daemon mode\n");
1656 c
.delay
= conf_get_monitor_delay();
1660 rv
= Monitor(devlist
, mailaddr
, program
,
1661 &c
, daemonise
, oneshot
,
1662 dosyslog
, pidfile
, increments
,
1667 if (array_size
> 0) {
1668 /* alway impose array size first, independent of
1670 * Do not allow level or raid_disks changes at the
1671 * same time as that can be irreversibly destructive.
1675 if (s
.raiddisks
|| s
.level
!= UnSet
) {
1676 pr_err("cannot change array size in same operation as changing raiddisks or level.\n"
1677 " Change size first, then check that data is still intact.\n");
1681 if (sysfs_init(&sra
, mdfd
, NULL
)) {
1685 if (array_size
== MAX_SIZE
)
1686 err
= sysfs_set_str(&sra
, NULL
, "array_size", "default");
1688 err
= sysfs_set_num(&sra
, NULL
, "array_size", array_size
/ 2);
1691 pr_err("--array-size setting is too large.\n");
1693 pr_err("current kernel does not support setting --array-size\n");
1698 if (devs_found
> 1 && s
.raiddisks
== 0 && s
.level
== UnSet
) {
1700 if (s
.size
> 0 || s
.chunk
||
1701 s
.layout_str
|| s
.bitmap_file
) {
1702 pr_err("--add cannot be used with other geometry changes in --grow mode\n");
1706 for (dv
= devlist
->next
; dv
; dv
= dv
->next
) {
1707 rv
= Grow_Add_device(devlist
->devname
, mdfd
,
1712 } else if (s
.bitmap_file
) {
1713 if (s
.size
> 0 || s
.raiddisks
|| s
.chunk
||
1714 s
.layout_str
|| devs_found
> 1) {
1715 pr_err("--bitmap changes cannot be used with other geometry changes in --grow mode\n");
1720 c
.delay
= DEFAULT_BITMAP_DELAY
;
1721 rv
= Grow_addbitmap(devlist
->devname
, mdfd
, &c
, &s
);
1722 } else if (grow_continue
)
1723 rv
= Grow_continue_command(devlist
->devname
,
1724 mdfd
, c
.backup_file
,
1726 else if (s
.size
> 0 || s
.raiddisks
|| s
.layout_str
||
1727 s
.chunk
!= 0 || s
.level
!= UnSet
||
1728 data_offset
!= INVALID_SECTORS
) {
1729 rv
= Grow_reshape(devlist
->devname
, mdfd
,
1731 data_offset
, &c
, &s
);
1732 } else if (s
.consistency_policy
!= CONSISTENCY_POLICY_UNKNOWN
) {
1733 rv
= Grow_consistency_policy(devlist
->devname
, mdfd
, &c
, &s
);
1734 } else if (array_size
== 0)
1735 pr_err("no changes to --grow\n");
1744 pr_err("In --incremental mode, a device cannot be given with --scan.\n");
1747 if (c
.runstop
<= 0) {
1748 pr_err("--incremental --scan meaningless without --run.\n");
1751 if (devmode
== 'f') {
1752 pr_err("--incremental --scan --fail not supported.\n");
1755 rv
= IncrementalScan(&c
, NULL
);
1758 if (!rebuild_map
&& !c
.scan
) {
1759 pr_err("--incremental requires a device.\n");
1764 if (devmode
== 'f') {
1765 if (devlist
->next
) {
1766 pr_err("'--incremental --fail' can only handle one device.\n");
1770 rv
= IncrementalRemove(devlist
->devname
, remove_path
,
1773 rv
= Incremental(devlist
, &c
, ss
);
1780 cluster_release_dlmlock();
1785 static int scan_assemble(struct supertype
*ss
,
1787 struct mddev_ident
*ident
)
1789 struct mddev_ident
*a
, *array_list
= conf_get_ident(NULL
);
1790 struct mddev_dev
*devlist
= conf_get_devs();
1791 struct map_ent
*map
= NULL
;
1794 int failures
, successes
;
1796 if (conf_verify_devnames(array_list
)) {
1797 pr_err("Duplicate MD device names in conf file were found.\n");
1800 if (devlist
== NULL
) {
1801 pr_err("No devices listed in conf file were found.\n");
1804 for (a
= array_list
; a
; a
= a
->next
) {
1807 a
->autof
= c
->autof
;
1810 pr_err("failed to get exclusive lock on mapfile\n");
1815 for (a
= array_list
; a
; a
= a
->next
) {
1820 strcasecmp(a
->devname
, "<ignore>") == 0)
1823 r
= Assemble(ss
, a
->devname
,
1833 } while (failures
&& successes
);
1834 if (c
->homehost
&& cnt
== 0) {
1835 /* Maybe we can auto-assemble something.
1836 * Repeatedly call Assemble in auto-assemble mode
1841 ident
->autof
= c
->autof
;
1843 struct mddev_dev
*devlist
= conf_get_devs();
1846 rv2
= Assemble(ss
, NULL
,
1854 /* Incase there are stacked devices, we need to go around again */
1856 if (cnt
== 0 && rv
== 0) {
1857 pr_err("No arrays found in config file or automatically\n");
1861 } else if (cnt
== 0 && rv
== 0) {
1862 pr_err("No arrays found in config file\n");
1869 static int misc_scan(char devmode
, struct context
*c
)
1871 /* apply --detail or --wait-clean to
1872 * all devices in /proc/mdstat
1874 struct mdstat_ent
*ms
= mdstat_read(0, 1);
1875 struct mdstat_ent
*e
;
1876 struct map_ent
*map
= NULL
;
1880 for (members
= 0; members
<= 1; members
++) {
1881 for (e
= ms
; e
; e
= e
->next
) {
1885 int member
= e
->metadata_version
&&
1886 strncmp(e
->metadata_version
,
1887 "external:/", 10) == 0;
1888 if (members
!= member
)
1890 me
= map_by_devnm(&map
, e
->devnm
);
1891 if (me
&& me
->path
&& strcmp(me
->path
, "/unknown") != 0)
1893 if (name
== NULL
|| stat(name
, &stb
) != 0)
1894 name
= get_md_name(e
->devnm
);
1897 pr_err("cannot find device file for %s\n",
1902 rv
|= Detail(name
, c
);
1904 rv
|= WaitClean(name
, c
->verbose
);
1914 static int stop_scan(int verbose
)
1916 /* apply --stop to all devices in /proc/mdstat */
1917 /* Due to possible stacking of devices, repeat until
1918 * nothing more can be stopped
1920 int progress
= 1, err
;
1924 struct mdstat_ent
*ms
= mdstat_read(0, 0);
1925 struct mdstat_ent
*e
;
1927 if (!progress
) last
= 1;
1928 progress
= 0; err
= 0;
1929 for (e
= ms
; e
; e
= e
->next
) {
1930 char *name
= get_md_name(e
->devnm
);
1934 pr_err("cannot find device file for %s\n",
1938 mdfd
= open_mddev(name
, 1);
1940 if (Manage_stop(name
, mdfd
, verbose
, !last
))
1950 } while (!last
&& err
);
1956 static int misc_list(struct mddev_dev
*devlist
,
1957 struct mddev_ident
*ident
,
1958 char *dump_directory
,
1959 struct supertype
*ss
, struct context
*c
)
1961 struct mddev_dev
*dv
;
1964 for (dv
= devlist
; dv
; dv
= (rv
& 16) ? NULL
: dv
->next
) {
1967 switch(dv
->disposition
) {
1969 rv
|= Detail(dv
->devname
, c
);
1971 case KillOpt
: /* Zero superblock */
1973 rv
|= Kill(dv
->devname
, ss
, c
->force
, c
->verbose
,0);
1977 rv
|= Kill(dv
->devname
, NULL
, c
->force
, v
, 0);
1984 rv
|= Query(dv
->devname
);
1987 rv
|= ExamineBitmap(dv
->devname
, c
->brief
, ss
);
1990 rv
|= ExamineBadblocks(dv
->devname
, c
->brief
, ss
);
1994 rv
|= Wait(dv
->devname
);
1997 rv
|= WaitClean(dv
->devname
, c
->verbose
);
2000 rv
|= Kill_subarray(dv
->devname
, c
->subarray
, c
->verbose
);
2002 case UpdateSubarray
:
2003 if (c
->update
== NULL
) {
2004 pr_err("-U/--update must be specified with --update-subarray\n");
2008 rv
|= Update_subarray(dv
->devname
, c
->subarray
,
2009 c
->update
, ident
, c
->verbose
);
2012 rv
|= Dump_metadata(dv
->devname
, dump_directory
, c
, ss
);
2015 rv
|= Restore_metadata(dv
->devname
, dump_directory
, c
, ss
,
2016 (dv
== devlist
&& dv
->next
== NULL
));
2019 rv
|= SetAction(dv
->devname
, c
->action
);
2023 if (dv
->devname
[0] != '/')
2024 mdfd
= open_dev(dv
->devname
);
2025 if (dv
->devname
[0] == '/' || mdfd
< 0)
2026 mdfd
= open_mddev(dv
->devname
, 1);
2029 switch(dv
->disposition
) {
2032 rv
|= Manage_run(dv
->devname
, mdfd
, c
);
2036 pr_err("--stop not meaningful with both a --scan assembly and a device name.\n");
2040 rv
|= Manage_stop(dv
->devname
, mdfd
, c
->verbose
, 0);
2043 rv
|= Manage_ro(dv
->devname
, mdfd
, 1);
2046 rv
|= Manage_ro(dv
->devname
, mdfd
, -1);
2056 int SetAction(char *dev
, char *action
)
2058 int fd
= open(dev
, O_RDONLY
);
2063 pr_err("Couldn't open %s: %s\n", dev
, strerror(errno
));
2066 retval
= sysfs_init(&mdi
, fd
, NULL
);
2069 pr_err("%s is no an md array\n", dev
);
2073 if (sysfs_set_str(&mdi
, NULL
, "sync_action", action
) < 0) {
2074 pr_err("Count not set action for %s to %s: %s\n",
2075 dev
, action
, strerror(errno
));