2 * mdadm - manage Linux "md" devices aka RAID arrays.
4 * Copyright (C) 2001-2009 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>
28 static int name_matches(char *found
, char *required
, char *homehost
)
30 /* See if the name found matches the required name, possibly
31 * prefixed with 'homehost'
35 strncpy(fnd
, found
, 32);
37 if (strcmp(found
, required
)==0)
40 int l
= strlen(homehost
);
41 if (l
< 32 && fnd
[l
] == ':' &&
42 strcmp(fnd
+l
+1, required
)==0)
48 static int is_member_busy(char *metadata_version
)
50 /* check if the given member array is active */
51 struct mdstat_ent
*mdstat
= mdstat_read(1, 0);
52 struct mdstat_ent
*ent
;
55 for (ent
= mdstat
; ent
; ent
= ent
->next
) {
56 if (ent
->metadata_version
== NULL
)
58 if (strncmp(ent
->metadata_version
, "external:", 9) != 0)
60 if (!is_subarray(&ent
->metadata_version
[9]))
62 /* Skip first char - it can be '/' or '-' */
63 if (strcmp(&ent
->metadata_version
[10], metadata_version
+1) == 0) {
73 static int ident_matches(struct mddev_ident
*ident
,
74 struct mdinfo
*content
,
75 struct supertype
*tst
,
77 char *update
, char *devname
)
80 if (ident
->uuid_set
&& (!update
|| strcmp(update
, "uuid")!= 0) &&
81 same_uuid(content
->uuid
, ident
->uuid
, tst
->ss
->swapuuid
)==0 &&
82 memcmp(content
->uuid
, uuid_zero
, sizeof(int[4])) != 0) {
84 pr_err("%s has wrong uuid.\n", devname
);
87 if (ident
->name
[0] && (!update
|| strcmp(update
, "name")!= 0) &&
88 name_matches(content
->name
, ident
->name
, homehost
)==0) {
90 pr_err("%s has wrong name.\n", devname
);
93 if (ident
->super_minor
!= UnSet
&&
94 ident
->super_minor
!= content
->array
.md_minor
) {
96 pr_err("%s has wrong super-minor.\n",
100 if (ident
->level
!= UnSet
&&
101 ident
->level
!= content
->array
.level
) {
103 pr_err("%s has wrong raid level.\n",
107 if (ident
->raid_disks
!= UnSet
&&
108 ident
->raid_disks
!= content
->array
.raid_disks
) {
110 pr_err("%s requires wrong number of drives.\n",
114 if (ident
->member
&& ident
->member
[0]) {
115 /* content->text_version must match */
116 char *s
= strchr(content
->text_version
+1, '/');
119 pr_err("%s is not a container and one is required.\n",
122 } else if (strcmp(ident
->member
, s
+1) != 0) {
124 pr_err("skipping wrong member %s is %s\n",
125 content
->text_version
, devname
);
132 static int select_devices(struct mddev_dev
*devlist
,
133 struct mddev_ident
*ident
,
134 struct supertype
**stp
,
135 struct mdinfo
**contentp
,
137 int inargv
, int auto_assem
)
140 struct mddev_dev
*tmpdev
;
142 struct supertype
*st
= *stp
;
143 struct mdinfo
*content
= NULL
;
144 int report_missmatch
= ((inargv
&& c
->verbose
>= 0) || c
->verbose
> 0);
145 struct domainlist
*domains
= NULL
;
147 tmpdev
= devlist
; num_devs
= 0;
153 tmpdev
->disposition
= 0;
154 tmpdev
= tmpdev
->next
;
157 /* first walk the list of devices to find a consistent set
158 * that match the criterea, if that is possible.
159 * We flag the ones we like with 'used'.
161 for (tmpdev
= devlist
;
163 tmpdev
= tmpdev
? tmpdev
->next
: NULL
) {
164 char *devname
= tmpdev
->devname
;
167 struct supertype
*tst
;
168 struct dev_policy
*pol
= NULL
;
169 int found_container
= 0;
171 if (tmpdev
->used
> 1)
174 if (ident
->devices
&&
175 !match_oneof(ident
->devices
, devname
)) {
176 if (report_missmatch
)
177 pr_err("%s is not one of %s\n", devname
, ident
->devices
);
183 dfd
= dev_open(devname
, O_RDONLY
);
185 if (report_missmatch
)
186 pr_err("cannot open device %s: %s\n",
187 devname
, strerror(errno
));
189 } else if (fstat(dfd
, &stb
)< 0) {
191 pr_err("fstat failed for %s: %s\n",
192 devname
, strerror(errno
));
194 } else if ((stb
.st_mode
& S_IFMT
) != S_IFBLK
) {
195 pr_err("%s is not a block device.\n",
198 } else if (must_be_container(dfd
)) {
200 /* already found some components, this cannot
203 if (report_missmatch
)
204 pr_err("%s is a container, but we are looking for components\n",
207 #if !defined(MDASSEMBLE) || defined(MDASSEMBLE) && defined(MDASSEMBLE_AUTO)
208 } if (!tst
&& (tst
= super_by_fd(dfd
, NULL
)) == NULL
) {
209 if (report_missmatch
)
210 pr_err("not a recognisable container: %s\n",
214 } else if (!tst
->ss
->load_container
215 || tst
->ss
->load_container(tst
, dfd
, NULL
)) {
216 if (report_missmatch
)
217 pr_err("no correct container type: %s\n",
220 } else if (auto_assem
&&
221 !conf_test_metadata(tst
->ss
->name
, (pol
= devnum_policy(stb
.st_rdev
)),
222 tst
->ss
->match_home(tst
, c
->homehost
) == 1)) {
223 if (report_missmatch
)
224 pr_err("%s has metadata type %s for which "
225 "auto-assembly is disabled\n",
226 devname
, tst
->ss
->name
);
231 if (!tst
&& (tst
= guess_super(dfd
)) == NULL
) {
232 if (report_missmatch
)
233 pr_err("no recogniseable superblock on %s\n",
236 } else if (tst
->ss
->load_super(tst
,dfd
, NULL
)) {
237 if (report_missmatch
)
238 pr_err("no RAID superblock on %s\n",
241 } else if (tst
->ss
->compare_super
== NULL
) {
242 if (report_missmatch
)
243 pr_err("Cannot assemble %s metadata on %s\n",
244 tst
->ss
->name
, devname
);
246 } else if (auto_assem
&& st
== NULL
&&
247 !conf_test_metadata(tst
->ss
->name
, (pol
= devnum_policy(stb
.st_rdev
)),
248 tst
->ss
->match_home(tst
, c
->homehost
) == 1)) {
249 if (report_missmatch
)
250 pr_err("%s has metadata type %s for which "
251 "auto-assembly is disabled\n",
252 devname
, tst
->ss
->name
);
256 if (dfd
>= 0) close(dfd
);
257 if (tmpdev
->used
== 2) {
258 if (auto_assem
|| !inargv
)
259 /* Ignore unrecognised devices during auto-assembly */
261 if (ident
->uuid_set
|| ident
->name
[0] ||
262 ident
->super_minor
!= UnSet
)
263 /* Ignore unrecognised device if looking for
267 pr_err("%s has no superblock - assembly aborted\n",
270 st
->ss
->free_super(st
);
271 dev_policy_free(pol
);
272 domain_free(domains
);
276 if (found_container
) {
277 /* tmpdev is a container. We need to be either
278 * looking for a member, or auto-assembling
280 /* should be safe to try an exclusive open now, we
281 * have rejected anything that some other mdadm might
284 dfd
= dev_open(devname
, O_RDONLY
| O_EXCL
);
286 if (report_missmatch
)
287 pr_err("%s is busy - skipping\n", devname
);
292 if (ident
->container
) {
293 if (ident
->container
[0] == '/' &&
294 !same_dev(ident
->container
, devname
)) {
295 if (report_missmatch
)
296 pr_err("%s is not the container required (%s)\n",
297 devname
, ident
->container
);
300 if (ident
->container
[0] != '/') {
305 tst
->ss
->getinfo_super(tst
, content
, NULL
);
307 if (!parse_uuid(ident
->container
, uuid
) ||
308 !same_uuid(content
->uuid
, uuid
, tst
->ss
->swapuuid
)) {
309 if (report_missmatch
)
310 pr_err("%s has wrong UUID to be required container\n",
316 /* It is worth looking inside this container.
319 pr_err("looking in container %s\n",
322 for (content
= tst
->ss
->container_content(tst
, NULL
);
324 content
= content
->next
) {
326 if (!ident_matches(ident
, content
, tst
,
327 c
->homehost
, c
->update
,
328 report_missmatch
? devname
: NULL
))
329 /* message already printed */;
330 else if (is_member_busy(content
->text_version
)) {
331 if (report_missmatch
)
332 pr_err("member %s in %s is already assembled\n",
333 content
->text_version
,
335 } else if (content
->array
.state
& (1<<MD_SB_BLOCK_VOLUME
)) {
336 /* do not assemble arrays with unsupported configurations */
337 pr_err("Cannot activate member %s in %s.\n",
338 content
->text_version
,
345 goto loop
; /* empty container */
348 st
= tst
; tst
= NULL
;
349 if (!auto_assem
&& inargv
&& tmpdev
->next
!= NULL
) {
350 pr_err("%s is a container, but is not "
351 "only device given: confused and aborting\n",
353 st
->ss
->free_super(st
);
354 dev_policy_free(pol
);
355 domain_free(domains
);
359 pr_err("found match on member %s in %s\n",
360 content
->text_version
, devname
);
362 /* make sure we finished the loop */
368 tst
->ss
->getinfo_super(tst
, content
, NULL
);
370 if (!ident_matches(ident
, content
, tst
,
371 c
->homehost
, c
->update
,
372 report_missmatch
? devname
: NULL
))
375 /* should be safe to try an exclusive open now, we
376 * have rejected anything that some other mdadm might
379 dfd
= dev_open(devname
, O_RDONLY
| O_EXCL
);
381 if (report_missmatch
)
382 pr_err("%s is busy - skipping\n", devname
);
389 if (st
->minor_version
== -1)
390 st
->minor_version
= tst
->minor_version
;
392 if (memcmp(content
->uuid
, uuid_zero
,
393 sizeof(int[4])) == 0) {
394 /* this is a floating spare. It cannot define
395 * an array unless there are no more arrays of
396 * this type to be found. It can be included
397 * in an array of this type though.
403 if (st
->ss
!= tst
->ss
||
404 st
->minor_version
!= tst
->minor_version
||
405 st
->ss
->compare_super(st
, tst
) != 0) {
406 /* Some mismatch. If exactly one array matches this host,
407 * we can resolve on that one.
408 * Or, if we are auto assembling, we just ignore the second
414 int first
= st
->ss
->match_home(st
, c
->homehost
);
415 int last
= tst
->ss
->match_home(tst
, c
->homehost
);
417 (first
== 1 || last
== 1)) {
418 /* We can do something */
419 if (first
) {/* just ignore this one */
420 if (report_missmatch
)
421 pr_err("%s misses out due to wrong homehost\n",
424 } else { /* reject all those sofar */
425 struct mddev_dev
*td
;
426 if (report_missmatch
)
427 pr_err("%s overrides previous devices due to good homehost\n",
429 for (td
=devlist
; td
!= tmpdev
; td
=td
->next
)
437 pr_err("superblock on %s doesn't match others - assembly aborted\n",
439 tst
->ss
->free_super(tst
);
440 st
->ss
->free_super(st
);
441 dev_policy_free(pol
);
442 domain_free(domains
);
448 /* Collect domain information from members only */
449 if (tmpdev
&& tmpdev
->used
== 1) {
451 pol
= devnum_policy(stb
.st_rdev
);
452 domain_merge(&domains
, pol
, tst
?tst
->ss
->name
:NULL
);
454 dev_policy_free(pol
);
457 tst
->ss
->free_super(tst
);
460 /* Check if we found some imsm spares but no members */
463 memcmp(uuid_zero
, ident
->uuid
,sizeof(uuid_zero
)) == 0)) &&
465 for (tmpdev
= devlist
; tmpdev
; tmpdev
= tmpdev
->next
) {
466 if (tmpdev
->used
!= 3)
472 /* we need sb from one of the spares */
473 int dfd
= dev_open(tmpdev
->devname
, O_RDONLY
);
475 st
->ss
->load_super(st
, dfd
, NULL
))
482 /* Now reject spares that don't match domains of identified members */
483 for (tmpdev
= devlist
; tmpdev
; tmpdev
= tmpdev
->next
) {
485 if (tmpdev
->used
!= 3)
487 if (stat(tmpdev
->devname
, &stb
)< 0) {
488 pr_err("fstat failed for %s: %s\n",
489 tmpdev
->devname
, strerror(errno
));
492 struct dev_policy
*pol
= devnum_policy(stb
.st_rdev
);
493 int dt
= domain_test(domains
, pol
, NULL
);
494 if (inargv
&& dt
!= 0)
495 /* take this spare as domains match
496 * if there are any */
498 else if (!inargv
&& dt
== 1)
499 /* device wasn't explicitly listed, so need
500 * explicit domain match - which we have */
503 /* if domains don't match mark as unused */
505 dev_policy_free(pol
);
508 domain_free(domains
);
510 if (st
&& st
->sb
&& content
== *contentp
)
511 st
->ss
->getinfo_super(st
, content
, NULL
);
517 int Assemble(struct supertype
*st
, char *mddev
,
518 struct mddev_ident
*ident
,
519 struct mddev_dev
*devlist
,
523 * The task of Assemble is to find a collection of
524 * devices that should (according to their superblocks)
525 * form an array, and to give this collection to the MD driver.
526 * In Linux-2.4 and later, this involves submitting a
527 * SET_ARRAY_INFO ioctl with no arg - to prepare
528 * the array - and then submit a number of
529 * ADD_NEW_DISK ioctls to add disks into
530 * the array. Finally RUN_ARRAY might
531 * be submitted to start the array.
533 * Much of the work of Assemble is in finding and/or
534 * checking the disks to make sure they look right.
536 * If mddev is not set, then scan must be set and we
537 * read through the config file for dev+uuid mapping
538 * We recurse, setting mddev, for each device that
540 * - has a valid uuid (or any uuid if !uuidset)
542 * If mddev is set, we try to determine state of md.
543 * check version - must be at least 0.90.0
544 * check kernel version. must be at least 2.4.
545 * If not, we can possibly fall back on START_ARRAY
546 * Try to GET_ARRAY_INFO.
547 * If possible, give up
548 * If not, try to STOP_ARRAY just to make sure
550 * If !uuidset and scan, look in conf-file for uuid
551 * If not found, give up
552 * If !devlist and scan and uuidset, get list of devs from conf-file
555 * Check superblock - discard if bad
556 * Check uuid (set if we don't have one) - discard if no match
557 * Check superblock similarity if we have a superblock - discard if different
558 * Record events, devicenum
559 * This should give us a list of devices for the array
560 * We should collect the most recent event number
562 * Count disks with recent enough event count
563 * While force && !enough disks
564 * Choose newest rejected disks, update event count
565 * mark clean and rewrite superblock
568 * foreach device with recent events : ADD_NEW_DISK
569 * if runstop == 1 || "enough" disks and runstop==0 -> RUN_ARRAY
571 * Check the device numbers in superblock are right
572 * update superblock if any changes
578 int auto_assem
= (mddev
== NULL
&& !ident
->uuid_set
&&
579 ident
->super_minor
== UnSet
&& ident
->name
[0] == 0
580 && (ident
->container
== NULL
|| ident
->member
== NULL
));
582 int vers
= vers
; /* Keep gcc quite - it really is initialised */
585 int uptodate
; /* set once we decide that this device is as
586 * recent as everything else in the array.
588 int included
; /* set if the device is already in the array
589 * due to a previous '-I'
594 int *best
= NULL
; /* indexed by raid_disk */
597 unsigned int okcnt
, sparecnt
, rebuilding_cnt
;
598 unsigned int req_cnt
;
607 int start_partial_ok
= (c
->runstop
>= 0) &&
608 (c
->force
|| devlist
==NULL
|| auto_assem
);
610 struct mddev_dev
*tmpdev
;
612 struct mdinfo
*content
= NULL
;
613 struct mdinfo
*pre_exist
= NULL
;
617 char chosen_name
[1024];
618 struct map_ent
*map
= NULL
;
621 if (get_linux_version() < 2004000)
625 * If any subdevs are listed, then any that don't
626 * match ident are discarded. Remainder must all match and
628 * If no subdevs, then we scan all devices in the config file, but
629 * there must be something in the identity
633 ident
->uuid_set
== 0 &&
634 (ident
->super_minor
< 0 || ident
->super_minor
== UnSet
) &&
635 ident
->name
[0] == 0 &&
636 (ident
->container
== NULL
|| ident
->member
== NULL
) &&
637 ident
->devices
== NULL
) {
638 pr_err("No identity information available for %s - cannot assemble.\n",
639 mddev
? mddev
: "further assembly");
644 devlist
= conf_get_devs();
649 /* We come back here when doing auto-assembly and attempting some
650 * set of devices failed. Those are now marked as ->used==2 and
651 * we ignore them and try again
653 if (!st
&& ident
->st
)
656 pr_err("looking for devices for %s\n",
657 mddev
? mddev
: "further assembly");
660 num_devs
= select_devices(devlist
, ident
, &st
, &content
, c
,
665 if (!st
|| !st
->sb
|| !content
)
668 /* We have a full set of devices - we now need to find the
670 * However there is a risk that we are racing with "mdadm -I"
671 * and the array is already partially assembled - we will have
672 * rejected any devices already in this address.
673 * So we take a lock on the map file - to prevent further races -
674 * and look for the uuid in there. If found and the array is
675 * active, we abort. If found and the array is not active
676 * we commit to that md device and add all the contained devices
677 * to our list. We flag them so that we don't try to re-add,
678 * but can remove if they turn out to not be wanted.
681 pr_err("failed to get exclusive lock on mapfile - continue anyway...\n");
682 mp
= map_by_uuid(&map
, content
->uuid
);
685 /* array already exists. */
686 pre_exist
= sysfs_read(-1, mp
->devnum
, GET_LEVEL
|GET_DEVS
);
687 if (pre_exist
->array
.level
!= UnSet
) {
688 pr_err("Found some drive for an array that is already active: %s\n",
690 pr_err("giving up.\n");
693 for (dv
= pre_exist
->devs
; dv
; dv
= dv
->next
) {
694 /* We want to add this device to our list,
695 * but it could already be there if "mdadm -I"
696 * started *after* we checked for O_EXCL.
697 * If we add it to the top of the list
698 * it will be preferred over later copies.
700 struct mddev_dev
*newdev
;
701 char *devname
= map_dev(dv
->disk
.major
,
706 newdev
= xmalloc(sizeof(*newdev
));
707 newdev
->devname
= devname
;
708 newdev
->disposition
= 'I';
710 newdev
->next
= devlist
;
714 strcpy(chosen_name
, mp
->path
);
715 if (c
->verbose
> 0 || mddev
== NULL
||
716 strcmp(mddev
, chosen_name
) != 0)
717 pr_err("Merging with already-assembled %s\n",
719 mdfd
= open_dev_excl(mp
->devnum
);
721 int trustworthy
= FOREIGN
;
722 name
= content
->name
;
723 switch (st
->ss
->match_home(st
, c
->homehost
)
724 ?: st
->ss
->match_home(st
, "any")) {
727 name
= strchr(content
->name
, ':');
731 name
= content
->name
;
735 /* If the array is listed in mdadm.conf or on
736 * command line, then we trust the name
737 * even if the array doesn't look local
742 content
->array
.level
== LEVEL_CONTAINER
) {
743 name
= content
->text_version
;
744 trustworthy
= METADATA
;
747 if (name
[0] && trustworthy
!= LOCAL
&&
748 ! c
->require_homehost
&&
749 conf_name_is_free(name
))
752 if (trustworthy
== LOCAL
&&
754 /* Ignore 'host:' prefix of name */
755 name
= strchr(name
, ':')+1;
757 mdfd
= create_mddev(mddev
, name
, ident
->autof
, trustworthy
,
761 st
->ss
->free_super(st
);
767 vers
= md_get_version(mdfd
);
769 pr_err("Assemble requires driver version 0.90.0 or later.\n"
770 " Upgrade your kernel or try --build\n");
774 if (pre_exist
== NULL
) {
775 if (mddev_busy(fd2devnum(mdfd
))) {
776 pr_err("%s already active, cannot restart it!\n",
778 for (tmpdev
= devlist
;
779 tmpdev
&& tmpdev
->used
!= 1;
780 tmpdev
= tmpdev
->next
)
782 if (tmpdev
&& auto_assem
)
783 pr_err("%s needed for %s...\n",
784 mddev
, tmpdev
->devname
);
787 st
->ss
->free_super(st
);
792 /* just incase it was started but has no content */
793 ioctl(mdfd
, STOP_ARRAY
, NULL
);
797 if (content
!= &info
) {
798 /* This is a member of a container. Try starting the array. */
800 err
= assemble_container_content(st
, mdfd
, content
, c
,
807 /* Ok, no bad inconsistancy, we can try updating etc */
808 devices
= xcalloc(num_devs
, sizeof(*devices
));
809 devmap
= xcalloc(num_devs
, content
->array
.raid_disks
);
810 for (tmpdev
= devlist
; tmpdev
; tmpdev
=tmpdev
->next
) if (tmpdev
->used
== 1) {
811 char *devname
= tmpdev
->devname
;
813 /* looks like a good enough match to update the super block if needed */
817 /* prepare useful information in info structures */
819 struct supertype
*tst
;
823 if (strcmp(c
->update
, "uuid")==0 &&
826 if ((rfd
= open("/dev/urandom", O_RDONLY
)) < 0 ||
827 read(rfd
, ident
->uuid
, 16) != 16) {
828 *(__u32
*)(ident
->uuid
) = random();
829 *(__u32
*)(ident
->uuid
+1) = random();
830 *(__u32
*)(ident
->uuid
+2) = random();
831 *(__u32
*)(ident
->uuid
+3) = random();
833 if (rfd
>= 0) close(rfd
);
835 dfd
= dev_open(devname
,
836 tmpdev
->disposition
== 'I'
837 ? O_RDWR
: (O_RDWR
|O_EXCL
));
840 if (dfd
< 0 || tst
->ss
->load_super(tst
, dfd
, NULL
) != 0) {
841 pr_err("cannot re-read metadata from %s - aborting\n",
850 tst
->ss
->getinfo_super(tst
, content
, devmap
+ devcnt
* content
->array
.raid_disks
);
852 memcpy(content
->uuid
, ident
->uuid
, 16);
853 strcpy(content
->name
, ident
->name
);
854 content
->array
.md_minor
= minor(stb2
.st_rdev
);
856 if (strcmp(c
->update
, "byteorder") == 0)
859 err
= tst
->ss
->update_super(tst
, content
, c
->update
,
864 pr_err("--update=%s not understood"
865 " for %s metadata\n",
866 c
->update
, tst
->ss
->name
);
867 tst
->ss
->free_super(tst
);
875 if (strcmp(c
->update
, "uuid")==0 &&
878 memcpy(ident
->uuid
, content
->uuid
, 16);
880 if (tst
->ss
->store_super(tst
, dfd
))
881 pr_err("Could not re-write superblock on %s.\n",
885 if (strcmp(c
->update
, "uuid")==0 &&
886 ident
->bitmap_fd
>= 0 && !bitmap_done
) {
887 if (bitmap_update_uuid(ident
->bitmap_fd
,
889 tst
->ss
->swapuuid
) != 0)
890 pr_err("Could not update uuid on external bitmap.\n");
894 tst
->ss
->free_super(tst
);
898 struct supertype
*tst
= dup_super(st
);
900 dfd
= dev_open(devname
,
901 tmpdev
->disposition
== 'I'
902 ? O_RDWR
: (O_RDWR
|O_EXCL
));
904 if (dfd
< 0 || tst
->ss
->load_super(tst
, dfd
, NULL
) != 0) {
905 pr_err("cannot re-read metadata from %s - aborting\n",
914 tst
->ss
->getinfo_super(tst
, content
, devmap
+ devcnt
* content
->array
.raid_disks
);
915 tst
->ss
->free_super(tst
);
922 pr_err("%s is identified as a member of %s, slot %d.\n",
923 devname
, mddev
, content
->disk
.raid_disk
);
924 devices
[devcnt
].devname
= devname
;
925 devices
[devcnt
].uptodate
= 0;
926 devices
[devcnt
].included
= (tmpdev
->disposition
== 'I');
927 devices
[devcnt
].i
= *content
;
928 devices
[devcnt
].i
.disk
.major
= major(stb
.st_rdev
);
929 devices
[devcnt
].i
.disk
.minor
= minor(stb
.st_rdev
);
930 if (most_recent
< devcnt
) {
931 if (devices
[devcnt
].i
.events
932 > devices
[most_recent
].i
.events
)
933 most_recent
= devcnt
;
935 if (content
->array
.level
== LEVEL_MULTIPATH
)
936 /* with multipath, the raid_disk from the superblock is meaningless */
939 i
= devices
[devcnt
].i
.disk
.raid_disk
;
941 if (nextspare
< content
->array
.raid_disks
)
942 nextspare
= content
->array
.raid_disks
;
945 if (i
>= content
->array
.raid_disks
&&
951 int newbestcnt
= i
+10;
952 int *newbest
= xmalloc(sizeof(int)*newbestcnt
);
954 for (c
=0; c
< newbestcnt
; c
++)
956 newbest
[c
] = best
[c
];
961 bestcnt
= newbestcnt
;
964 devices
[best
[i
]].i
.events
965 == devices
[devcnt
].i
.events
966 && (devices
[best
[i
]].i
.disk
.minor
967 != devices
[devcnt
].i
.disk
.minor
)
969 && content
->array
.level
!= LEVEL_MULTIPATH
) {
970 /* two different devices with identical superblock.
971 * Could be a mis-detection caused by overlapping
972 * partitions. fail-safe.
974 pr_err("WARNING %s and %s appear"
975 " to have very similar superblocks.\n"
976 " If they are really different, "
977 "please --zero the superblock on one\n"
978 " If they are the same or overlap,"
979 " please remove one from %s.\n",
980 devices
[best
[i
]].devname
, devname
,
981 inargv
? "the list" :
982 "the\n DEVICE list in mdadm.conf"
990 || (devices
[best
[i
]].i
.events
991 < devices
[devcnt
].i
.events
))
998 pr_err("no devices found for %s\n",
1001 st
->ss
->free_super(st
);
1008 if (c
->update
&& strcmp(c
->update
, "byteorder")==0)
1009 st
->minor_version
= 90;
1011 st
->ss
->getinfo_super(st
, content
, NULL
);
1012 clean
= content
->array
.state
& 1;
1014 /* now we have some devices that might be suitable.
1017 avail
= xcalloc(content
->array
.raid_disks
, 1);
1021 for (i
=0; i
< bestcnt
; i
++) {
1023 int event_margin
= 1; /* always allow a difference of '1'
1024 * like the kernel does
1026 if (j
< 0) continue;
1027 /* note: we ignore error flags in multipath arrays
1028 * as they don't make sense
1030 if (content
->array
.level
!= LEVEL_MULTIPATH
)
1031 if (!(devices
[j
].i
.disk
.state
& (1<<MD_DISK_ACTIVE
))) {
1032 if (!(devices
[j
].i
.disk
.state
1033 & (1<<MD_DISK_FAULTY
))) {
1034 devices
[j
].uptodate
= 1;
1039 /* If this device thinks that 'most_recent' has failed, then
1040 * we must reject this device.
1042 if (j
!= most_recent
&&
1043 content
->array
.raid_disks
> 0 &&
1044 devices
[most_recent
].i
.disk
.raid_disk
>= 0 &&
1045 devmap
[j
* content
->array
.raid_disks
+ devices
[most_recent
].i
.disk
.raid_disk
] == 0) {
1046 if (c
->verbose
> -1)
1047 pr_err("ignoring %s as it reports %s as failed\n",
1048 devices
[j
].devname
, devices
[most_recent
].devname
);
1052 if (devices
[j
].i
.events
+event_margin
>=
1053 devices
[most_recent
].i
.events
) {
1054 devices
[j
].uptodate
= 1;
1055 if (i
< content
->array
.raid_disks
) {
1056 if (devices
[j
].i
.recovery_start
== MaxSector
||
1057 (content
->reshape_active
&&
1058 ((i
>= content
->array
.raid_disks
- content
->delta_disks
) ||
1059 (i
>= content
->array
.raid_disks
- content
->delta_disks
- 1
1060 && content
->array
.level
== 4)))) {
1071 (!enough(content
->array
.level
, content
->array
.raid_disks
,
1072 content
->array
.layout
, 1,
1075 (content
->reshape_active
&& content
->delta_disks
> 0 &&
1076 !enough(content
->array
.level
, (content
->array
.raid_disks
1077 - content
->delta_disks
),
1078 content
->new_layout
, 1,
1081 /* Choose the newest best drive which is
1082 * not up-to-date, update the superblock
1086 struct supertype
*tst
;
1087 unsigned long long current_events
;
1089 for (i
= 0; i
< content
->array
.raid_disks
&& i
< bestcnt
; i
++) {
1092 !devices
[j
].uptodate
&&
1093 devices
[j
].i
.recovery_start
== MaxSector
&&
1094 (chosen_drive
< 0 ||
1096 > devices
[chosen_drive
].i
.events
))
1099 if (chosen_drive
< 0)
1101 current_events
= devices
[chosen_drive
].i
.events
;
1103 if (c
->verbose
>= 0)
1104 pr_err("forcing event count in %s(%d) from %d upto %d\n",
1105 devices
[chosen_drive
].devname
,
1106 devices
[chosen_drive
].i
.disk
.raid_disk
,
1107 (int)(devices
[chosen_drive
].i
.events
),
1108 (int)(devices
[most_recent
].i
.events
));
1109 fd
= dev_open(devices
[chosen_drive
].devname
,
1110 devices
[chosen_drive
].included
? O_RDWR
1113 pr_err("Couldn't open %s for write - not updating\n",
1114 devices
[chosen_drive
].devname
);
1115 devices
[chosen_drive
].i
.events
= 0;
1118 tst
= dup_super(st
);
1119 if (tst
->ss
->load_super(tst
,fd
, NULL
)) {
1121 pr_err("RAID superblock disappeared from %s - not updating.\n",
1122 devices
[chosen_drive
].devname
);
1123 devices
[chosen_drive
].i
.events
= 0;
1126 content
->events
= devices
[most_recent
].i
.events
;
1127 tst
->ss
->update_super(tst
, content
, "force-one",
1128 devices
[chosen_drive
].devname
, c
->verbose
,
1131 if (tst
->ss
->store_super(tst
, fd
)) {
1133 pr_err("Could not re-write superblock on %s\n",
1134 devices
[chosen_drive
].devname
);
1135 devices
[chosen_drive
].i
.events
= 0;
1136 tst
->ss
->free_super(tst
);
1140 devices
[chosen_drive
].i
.events
= devices
[most_recent
].i
.events
;
1141 devices
[chosen_drive
].uptodate
= 1;
1142 avail
[chosen_drive
] = 1;
1144 tst
->ss
->free_super(tst
);
1146 /* If there are any other drives of the same vintage,
1147 * add them in as well. We can't lose and we might gain
1149 for (i
= 0; i
< content
->array
.raid_disks
&& i
< bestcnt
; i
++) {
1152 !devices
[j
].uptodate
&&
1153 devices
[j
].i
.recovery_start
== MaxSector
&&
1154 devices
[j
].i
.events
== current_events
) {
1161 /* Now we want to look at the superblock which the kernel will base things on
1162 * and compare the devices that we think are working with the devices that the
1163 * superblock thinks are working.
1164 * If there are differences and --force is given, then update this chosen
1168 st
->ss
->free_super(st
);
1169 for (i
=0; chosen_drive
< 0 && i
<bestcnt
; i
++) {
1175 if (!devices
[j
].uptodate
)
1177 if (devices
[j
].i
.events
< devices
[most_recent
].i
.events
)
1180 if ((fd
=dev_open(devices
[j
].devname
,
1181 devices
[j
].included
? O_RDONLY
1182 : (O_RDONLY
|O_EXCL
)))< 0) {
1183 pr_err("Cannot open %s: %s\n",
1184 devices
[j
].devname
, strerror(errno
));
1189 if (st
->ss
->load_super(st
,fd
, NULL
)) {
1191 pr_err("RAID superblock has disappeared from %s\n",
1192 devices
[j
].devname
);
1199 if (st
->sb
== NULL
) {
1200 pr_err("No suitable drives found for %s\n", mddev
);
1205 st
->ss
->getinfo_super(st
, content
, NULL
);
1207 sysfs_init(content
, mdfd
, 0);
1209 for (i
=0; i
<bestcnt
; i
++) {
1211 unsigned int desired_state
;
1213 if (i
< content
->array
.raid_disks
)
1214 desired_state
= (1<<MD_DISK_ACTIVE
) | (1<<MD_DISK_SYNC
);
1220 if (!devices
[j
].uptodate
)
1223 devices
[j
].i
.disk
.state
= desired_state
;
1224 if (!(devices
[j
].i
.array
.state
& 1))
1227 if (st
->ss
->update_super(st
, &devices
[j
].i
, "assemble", NULL
,
1228 c
->verbose
, 0, NULL
)) {
1230 if (c
->verbose
>= 0)
1231 pr_err("clearing FAULTY flag for device %d in %s for %s\n",
1232 j
, mddev
, devices
[j
].devname
);
1235 if (c
->verbose
>= -1)
1236 pr_err("device %d in %s has wrong state in superblock, but %s seems ok\n",
1237 i
, mddev
, devices
[j
].devname
);
1241 if (!(super
.disks
[i
].i
.disk
.state
& (1 << MD_DISK_FAULTY
))) {
1242 pr_err("devices %d of %s is not marked FAULTY in superblock, but cannot be found\n",
1247 if (c
->force
&& !clean
&&
1248 !enough(content
->array
.level
, content
->array
.raid_disks
,
1249 content
->array
.layout
, clean
,
1251 change
+= st
->ss
->update_super(st
, content
, "force-array",
1252 devices
[chosen_drive
].devname
, c
->verbose
,
1259 fd
= dev_open(devices
[chosen_drive
].devname
,
1260 devices
[chosen_drive
].included
?
1261 O_RDWR
: (O_RDWR
|O_EXCL
));
1263 pr_err("Could not open %s for write - cannot Assemble array.\n",
1264 devices
[chosen_drive
].devname
);
1269 if (st
->ss
->store_super(st
, fd
)) {
1271 pr_err("Could not re-write superblock on %s\n",
1272 devices
[chosen_drive
].devname
);
1277 if (c
->verbose
>= 0)
1278 pr_err("Marking array %s as 'clean'\n",
1283 /* If we are in the middle of a reshape we may need to restore saved data
1284 * that was moved aside due to the reshape overwriting live data
1285 * The code of doing this lives in Grow.c
1288 if (content
->reshape_active
&&
1289 !(content
->reshape_active
& RESHAPE_NO_BACKUP
)) {
1291 int *fdlist
= xmalloc(sizeof(int)* bestcnt
);
1293 pr_err(":%s has an active reshape - checking "
1294 "if critical section needs to be restored\n",
1296 for (i
=0; i
<bestcnt
; i
++) {
1299 fdlist
[i
] = dev_open(devices
[j
].devname
,
1301 ? O_RDWR
: (O_RDWR
|O_EXCL
));
1302 if (fdlist
[i
] < 0) {
1303 pr_err("Could not open %s for write - cannot Assemble array.\n",
1304 devices
[j
].devname
);
1312 if (st
->ss
->external
&& st
->ss
->recover_backup
)
1313 err
= st
->ss
->recover_backup(st
, content
);
1315 err
= Grow_restart(st
, content
, fdlist
, bestcnt
,
1316 c
->backup_file
, c
->verbose
> 0);
1317 if (err
&& c
->invalid_backup
) {
1320 " without restoring backup\n");
1326 if (fdlist
[i
]>=0) close(fdlist
[i
]);
1330 pr_err("Failed to restore critical section for reshape, sorry.\n");
1331 if (c
->backup_file
== NULL
)
1332 cont_err("Possibly you needed to specify the --backup-file\n");
1339 /* count number of in-sync devices according to the superblock.
1340 * We must have this number to start the array without -s or -R
1342 req_cnt
= content
->array
.working_disks
;
1344 /* Almost ready to actually *do* something */
1348 /* First, fill in the map, so that udev can find our name
1349 * as soon as we become active.
1351 map_update(&map
, fd2devnum(mdfd
), content
->text_version
,
1352 content
->uuid
, chosen_name
);
1354 rv
= set_array_info(mdfd
, st
, content
);
1355 if (rv
&& !pre_exist
) {
1356 pr_err("failed to set array info for %s: %s\n",
1357 mddev
, strerror(errno
));
1358 ioctl(mdfd
, STOP_ARRAY
, NULL
);
1364 if (ident
->bitmap_fd
>= 0) {
1365 if (ioctl(mdfd
, SET_BITMAP_FILE
, ident
->bitmap_fd
) != 0) {
1366 pr_err("SET_BITMAP_FILE failed.\n");
1367 ioctl(mdfd
, STOP_ARRAY
, NULL
);
1373 } else if (ident
->bitmap_file
) {
1374 /* From config file */
1375 int bmfd
= open(ident
->bitmap_file
, O_RDWR
);
1377 pr_err("Could not open bitmap file %s\n",
1378 ident
->bitmap_file
);
1379 ioctl(mdfd
, STOP_ARRAY
, NULL
);
1385 if (ioctl(mdfd
, SET_BITMAP_FILE
, bmfd
) != 0) {
1386 pr_err("Failed to set bitmapfile for %s\n", mddev
);
1388 ioctl(mdfd
, STOP_ARRAY
, NULL
);
1397 /* First, add the raid disks, but add the chosen one last */
1398 for (i
=0; i
<= bestcnt
; i
++) {
1402 if (j
== chosen_drive
)
1407 if (j
>= 0 && !devices
[j
].included
) {
1408 int dfd
= dev_open(devices
[j
].devname
,
1411 remove_partitions(dfd
);
1414 rv
= add_disk(mdfd
, st
, content
, &devices
[j
].i
);
1417 pr_err("failed to add "
1422 if (i
< content
->array
.raid_disks
1427 } else if (c
->verbose
> 0)
1428 pr_err("added %s to %s as %d%s\n",
1429 devices
[j
].devname
, mddev
,
1430 devices
[j
].i
.disk
.raid_disk
,
1431 devices
[j
].uptodate
?"":
1432 " (possibly out of date)");
1433 } else if (j
>= 0) {
1435 pr_err("%s is already in %s as %d\n",
1436 devices
[j
].devname
, mddev
,
1437 devices
[j
].i
.disk
.raid_disk
);
1438 } else if (c
->verbose
> 0 && i
< content
->array
.raid_disks
)
1439 pr_err("no uptodate device for slot %d of %s\n",
1443 if (content
->array
.level
== LEVEL_CONTAINER
) {
1444 if (c
->verbose
>= 0) {
1445 pr_err("Container %s has been "
1446 "assembled with %d drive%s",
1447 mddev
, okcnt
+sparecnt
, okcnt
+sparecnt
==1?"":"s");
1448 if (okcnt
< (unsigned)content
->array
.raid_disks
)
1449 fprintf(stderr
, " (out of %d)",
1450 content
->array
.raid_disks
);
1451 fprintf(stderr
, "\n");
1453 st
->ss
->free_super(st
);
1454 sysfs_uevent(content
, "change");
1456 wait_for(chosen_name
, mdfd
);
1462 if (c
->runstop
== 1 ||
1464 ( enough(content
->array
.level
, content
->array
.raid_disks
,
1465 content
->array
.layout
, clean
, avail
) &&
1466 (okcnt
+ rebuilding_cnt
>= req_cnt
|| start_partial_ok
)
1468 /* This array is good-to-go.
1469 * If a reshape is in progress then we might need to
1470 * continue monitoring it. In that case we start
1471 * it read-only and let the grow code make it writable.
1475 if (content
->reshape_active
&&
1476 !(content
->reshape_active
& RESHAPE_NO_BACKUP
) &&
1477 content
->delta_disks
<= 0) {
1478 rv
= sysfs_set_str(content
, NULL
,
1479 "array_state", "readonly");
1481 rv
= Grow_continue(mdfd
, st
, content
,
1484 } else if (c
->readonly
&&
1485 sysfs_attribute_available(
1486 content
, NULL
, "array_state")) {
1487 rv
= sysfs_set_str(content
, NULL
,
1488 "array_state", "readonly");
1491 rv
= ioctl(mdfd
, RUN_ARRAY
, NULL
);
1493 if (c
->verbose
>= 0) {
1494 pr_err("%s has been started with %d drive%s",
1495 mddev
, okcnt
, okcnt
==1?"":"s");
1496 if (okcnt
< (unsigned)content
->array
.raid_disks
)
1497 fprintf(stderr
, " (out of %d)", content
->array
.raid_disks
);
1499 fprintf(stderr
, "%s %d rebuilding", sparecnt
?",":" and", rebuilding_cnt
);
1501 fprintf(stderr
, " and %d spare%s", sparecnt
, sparecnt
==1?"":"s");
1502 fprintf(stderr
, ".\n");
1504 if (content
->reshape_active
&&
1505 content
->array
.level
>= 4 &&
1506 content
->array
.level
<= 6) {
1507 /* might need to increase the size
1508 * of the stripe cache - default is 256
1510 if (256 < 4 * (content
->array
.chunk_size
/4096)) {
1511 struct mdinfo
*sra
= sysfs_read(mdfd
, 0, 0);
1513 sysfs_set_num(sra
, NULL
,
1514 "stripe_cache_size",
1515 (4 * content
->array
.chunk_size
/ 4096) + 1);
1519 if (okcnt
< (unsigned)content
->array
.raid_disks
) {
1520 /* If any devices did not get added
1521 * because the kernel rejected them based
1522 * on event count, try adding them
1523 * again providing the action policy is
1524 * 're-add' or greater. The bitmap
1525 * might allow them to be included, or
1526 * they will become spares.
1528 for (i
= 0; i
< bestcnt
; i
++) {
1530 if (j
>= 0 && !devices
[j
].uptodate
) {
1531 if (!disk_action_allows(&devices
[j
].i
, st
->ss
->name
, act_re_add
))
1533 rv
= add_disk(mdfd
, st
, content
,
1535 if (rv
== 0 && c
->verbose
>= 0)
1536 pr_err("%s has been re-added.\n",
1537 devices
[j
].devname
);
1542 wait_for(mddev
, mdfd
);
1546 /* There is a nasty race with 'mdadm --monitor'.
1547 * If it opens this device before we close it,
1548 * it gets an incomplete open on which IO
1549 * doesn't work and the capacity is
1551 * If we reopen (to check for layered devices)
1552 * before --monitor closes, we loose.
1554 * So: wait upto 1 second for there to be
1555 * a non-zero capacity.
1557 while (usecs
< 1000) {
1558 mdfd
= open(mddev
, O_RDONLY
);
1560 unsigned long long size
;
1561 if (get_dev_size(mdfd
, NULL
, &size
) &&
1573 pr_err("failed to RUN_ARRAY %s: %s\n",
1574 mddev
, strerror(errno
));
1576 if (!enough(content
->array
.level
, content
->array
.raid_disks
,
1577 content
->array
.layout
, 1, avail
))
1578 pr_err("Not enough devices to "
1579 "start the array.\n");
1580 else if (!enough(content
->array
.level
,
1581 content
->array
.raid_disks
,
1582 content
->array
.layout
, clean
,
1584 pr_err("Not enough devices to "
1585 "start the array while not clean "
1586 "- consider --force.\n");
1589 ioctl(mdfd
, STOP_ARRAY
, NULL
);
1595 if (c
->runstop
== -1) {
1596 pr_err("%s assembled from %d drive%s",
1597 mddev
, okcnt
, okcnt
==1?"":"s");
1598 if (okcnt
!= (unsigned)content
->array
.raid_disks
)
1599 fprintf(stderr
, " (out of %d)", content
->array
.raid_disks
);
1600 fprintf(stderr
, ", but not started.\n");
1606 if (c
->verbose
>= -1) {
1607 pr_err("%s assembled from %d drive%s", mddev
, okcnt
, okcnt
==1?"":"s");
1609 fprintf(stderr
, "%s %d rebuilding", sparecnt
?", ":" and ", rebuilding_cnt
);
1611 fprintf(stderr
, " and %d spare%s", sparecnt
, sparecnt
==1?"":"s");
1612 if (!enough(content
->array
.level
, content
->array
.raid_disks
,
1613 content
->array
.layout
, 1, avail
))
1614 fprintf(stderr
, " - not enough to start the array.\n");
1615 else if (!enough(content
->array
.level
,
1616 content
->array
.raid_disks
,
1617 content
->array
.layout
, clean
,
1619 fprintf(stderr
, " - not enough to start the "
1620 "array while not clean - consider "
1623 if (req_cnt
== (unsigned)content
->array
.raid_disks
)
1624 fprintf(stderr
, " - need all %d to start it", req_cnt
);
1626 fprintf(stderr
, " - need %d of %d to start", req_cnt
, content
->array
.raid_disks
);
1627 fprintf(stderr
, " (use --run to insist).\n");
1631 ioctl(mdfd
, STOP_ARRAY
, NULL
);
1637 /* The "chosen_drive" is a good choice, and if necessary, the superblock has
1638 * been updated to point to the current locations of devices.
1639 * so we can just start the array
1642 dev
= makedev(devices
[chosen_drive
].i
.disk
.major
,
1643 devices
[chosen_drive
].i
.disk
.minor
);
1644 if (ioctl(mdfd
, START_ARRAY
, dev
)) {
1645 pr_err("Cannot start array: %s\n",
1657 int assemble_container_content(struct supertype
*st
, int mdfd
,
1658 struct mdinfo
*content
, struct context
*c
,
1661 struct mdinfo
*dev
, *sra
;
1662 int working
= 0, preexist
= 0;
1664 struct map_ent
*map
= NULL
;
1668 sysfs_init(content
, mdfd
, 0);
1670 sra
= sysfs_read(mdfd
, 0, GET_VERSION
);
1671 if (sra
== NULL
|| strcmp(sra
->text_version
, content
->text_version
) != 0) {
1672 if (content
->array
.major_version
== -1 &&
1673 content
->array
.minor_version
== -2 &&
1675 content
->text_version
[0] == '/')
1676 content
->text_version
[0] = '-';
1677 if (sysfs_set_array(content
, md_get_version(mdfd
)) != 0) {
1684 /* There are two types of reshape: container wide or sub-array specific
1685 * Check if metadata requests blocking container wide reshapes
1687 start_reshape
= (content
->reshape_active
&&
1688 !((content
->reshape_active
== CONTAINER_RESHAPE
) &&
1689 (content
->array
.state
& (1<<MD_SB_BLOCK_CONTAINER_RESHAPE
))));
1691 /* Block subarray here if it is under reshape now
1692 * Do not allow for any changes in this array
1694 if (st
->ss
->external
&& content
->recovery_blocked
&& start_reshape
)
1695 block_subarray(content
);
1699 old_raid_disks
= content
->array
.raid_disks
- content
->delta_disks
;
1700 for (dev
= content
->devs
; dev
; dev
= dev
->next
)
1701 if (sysfs_add_disk(content
, dev
, 1) == 0) {
1702 if (dev
->disk
.raid_disk
>= old_raid_disks
&&
1703 content
->reshape_active
)
1707 } else if (errno
== EEXIST
)
1709 if (working
+ expansion
== 0)
1710 return 1;/* Nothing new, don't try to start */
1712 map_update(&map
, fd2devnum(mdfd
),
1713 content
->text_version
,
1714 content
->uuid
, chosen_name
);
1716 if (c
->runstop
> 0 ||
1717 (working
+ preexist
+ expansion
) >=
1718 content
->array
.working_disks
) {
1721 if (start_reshape
) {
1722 int spare
= content
->array
.raid_disks
+ expansion
;
1723 if (restore_backup(st
, content
,
1725 spare
, c
->backup_file
, c
->verbose
) == 1)
1728 err
= sysfs_set_str(content
, NULL
,
1729 "array_state", "readonly");
1733 if (st
->ss
->external
) {
1734 if (!mdmon_running(st
->container_dev
))
1735 start_mdmon(st
->container_dev
);
1736 ping_monitor_by_id(st
->container_dev
);
1737 if (mdmon_running(st
->container_dev
) &&
1738 st
->update_tail
== NULL
)
1739 st
->update_tail
= &st
->updates
;
1742 err
= Grow_continue(mdfd
, st
, content
, c
->backup_file
,
1744 } else switch(content
->array
.level
) {
1746 case LEVEL_MULTIPATH
:
1748 err
= sysfs_set_str(content
, NULL
, "array_state",
1749 c
->readonly
? "readonly" : "active");
1752 err
= sysfs_set_str(content
, NULL
, "array_state",
1754 /* start mdmon if needed. */
1756 if (!mdmon_running(st
->container_dev
))
1757 start_mdmon(st
->container_dev
);
1758 ping_monitor_by_id(st
->container_dev
);
1763 sysfs_set_safemode(content
, content
->safe_mode_delay
);
1765 /* Block subarray here if it is not reshaped now
1766 * It has be blocked a little later to allow mdmon to switch in
1769 if (st
->ss
->external
&& content
->recovery_blocked
&&
1771 block_subarray(content
);
1773 if (c
->verbose
>= 0) {
1775 pr_err("array %s now has %d device%s",
1776 chosen_name
, working
+ preexist
,
1777 working
+ preexist
== 1 ? "":"s");
1779 pr_err("Started %s with %d device%s",
1780 chosen_name
, working
+ preexist
,
1781 working
+ preexist
== 1 ? "":"s");
1783 fprintf(stderr
, " (%d new)", working
);
1785 fprintf(stderr
, " ( + %d for expansion)",
1787 fprintf(stderr
, "\n");
1790 wait_for(chosen_name
, mdfd
);
1792 /* FIXME should have an O_EXCL and wait for read-auto */
1794 if (c
->verbose
>= 0) {
1795 pr_err("%s assembled with %d device%s",
1796 chosen_name
, preexist
+ working
,
1797 preexist
+ working
== 1 ? "":"s");
1799 fprintf(stderr
, " (%d new)", working
);
1800 fprintf(stderr
, " but not started\n");