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
);
519 int uptodate
; /* set once we decide that this device is as
520 * recent as everything else in the array.
522 int included
; /* set if the device is already in the array
523 * due to a previous '-I'
528 static int load_devices(struct devs
*devices
, char *devmap
,
529 struct mddev_ident
*ident
, struct supertype
*st
,
530 struct mddev_dev
*devlist
, struct context
*c
,
531 struct mdinfo
*content
,
532 int mdfd
, char *mddev
,
533 int *most_recentp
, int *bestcntp
, int **bestp
,
536 struct mddev_dev
*tmpdev
;
546 for (tmpdev
= devlist
; tmpdev
; tmpdev
=tmpdev
->next
) {
547 char *devname
= tmpdev
->devname
;
551 if (tmpdev
->used
!= 1)
553 /* looks like a good enough match to update the super block if needed */
557 /* prepare useful information in info structures */
559 struct supertype
*tst
;
563 if (strcmp(c
->update
, "uuid")==0 &&
566 if ((rfd
= open("/dev/urandom", O_RDONLY
)) < 0 ||
567 read(rfd
, ident
->uuid
, 16) != 16) {
568 *(__u32
*)(ident
->uuid
) = random();
569 *(__u32
*)(ident
->uuid
+1) = random();
570 *(__u32
*)(ident
->uuid
+2) = random();
571 *(__u32
*)(ident
->uuid
+3) = random();
573 if (rfd
>= 0) close(rfd
);
575 dfd
= dev_open(devname
,
576 tmpdev
->disposition
== 'I'
577 ? O_RDWR
: (O_RDWR
|O_EXCL
));
580 if (dfd
< 0 || tst
->ss
->load_super(tst
, dfd
, NULL
) != 0) {
581 pr_err("cannot re-read metadata from %s - aborting\n",
590 tst
->ss
->getinfo_super(tst
, content
, devmap
+ devcnt
* content
->array
.raid_disks
);
592 memcpy(content
->uuid
, ident
->uuid
, 16);
593 strcpy(content
->name
, ident
->name
);
594 content
->array
.md_minor
= minor(stb2
.st_rdev
);
596 if (strcmp(c
->update
, "byteorder") == 0)
599 err
= tst
->ss
->update_super(tst
, content
, c
->update
,
604 pr_err("--update=%s not understood"
605 " for %s metadata\n",
606 c
->update
, tst
->ss
->name
);
607 tst
->ss
->free_super(tst
);
615 if (strcmp(c
->update
, "uuid")==0 &&
618 memcpy(ident
->uuid
, content
->uuid
, 16);
620 if (tst
->ss
->store_super(tst
, dfd
))
621 pr_err("Could not re-write superblock on %s.\n",
625 if (strcmp(c
->update
, "uuid")==0 &&
626 ident
->bitmap_fd
>= 0 && !bitmap_done
) {
627 if (bitmap_update_uuid(ident
->bitmap_fd
,
629 tst
->ss
->swapuuid
) != 0)
630 pr_err("Could not update uuid on external bitmap.\n");
634 tst
->ss
->free_super(tst
);
638 struct supertype
*tst
= dup_super(st
);
640 dfd
= dev_open(devname
,
641 tmpdev
->disposition
== 'I'
642 ? O_RDWR
: (O_RDWR
|O_EXCL
));
644 if (dfd
< 0 || tst
->ss
->load_super(tst
, dfd
, NULL
) != 0) {
645 pr_err("cannot re-read metadata from %s - aborting\n",
654 tst
->ss
->getinfo_super(tst
, content
, devmap
+ devcnt
* content
->array
.raid_disks
);
655 tst
->ss
->free_super(tst
);
662 pr_err("%s is identified as a member of %s, slot %d.\n",
663 devname
, mddev
, content
->disk
.raid_disk
);
664 devices
[devcnt
].devname
= devname
;
665 devices
[devcnt
].uptodate
= 0;
666 devices
[devcnt
].included
= (tmpdev
->disposition
== 'I');
667 devices
[devcnt
].i
= *content
;
668 devices
[devcnt
].i
.disk
.major
= major(stb
.st_rdev
);
669 devices
[devcnt
].i
.disk
.minor
= minor(stb
.st_rdev
);
670 if (most_recent
< devcnt
) {
671 if (devices
[devcnt
].i
.events
672 > devices
[most_recent
].i
.events
)
673 most_recent
= devcnt
;
675 if (content
->array
.level
== LEVEL_MULTIPATH
)
676 /* with multipath, the raid_disk from the superblock is meaningless */
679 i
= devices
[devcnt
].i
.disk
.raid_disk
;
681 if (nextspare
< content
->array
.raid_disks
)
682 nextspare
= content
->array
.raid_disks
;
685 if (i
>= content
->array
.raid_disks
&&
691 int newbestcnt
= i
+10;
692 int *newbest
= xmalloc(sizeof(int)*newbestcnt
);
694 for (c
=0; c
< newbestcnt
; c
++)
696 newbest
[c
] = best
[c
];
701 bestcnt
= newbestcnt
;
704 devices
[best
[i
]].i
.events
705 == devices
[devcnt
].i
.events
706 && (devices
[best
[i
]].i
.disk
.minor
707 != devices
[devcnt
].i
.disk
.minor
)
709 && content
->array
.level
!= LEVEL_MULTIPATH
) {
710 /* two different devices with identical superblock.
711 * Could be a mis-detection caused by overlapping
712 * partitions. fail-safe.
714 pr_err("WARNING %s and %s appear"
715 " to have very similar superblocks.\n"
716 " If they are really different, "
717 "please --zero the superblock on one\n"
718 " If they are the same or overlap,"
719 " please remove one from %s.\n",
720 devices
[best
[i
]].devname
, devname
,
721 inargv
? "the list" :
722 "the\n DEVICE list in mdadm.conf"
730 || (devices
[best
[i
]].i
.events
731 < devices
[devcnt
].i
.events
))
736 *most_recentp
= most_recent
;
742 static int force_array(struct mdinfo
*content
,
743 struct devs
*devices
,
744 int *best
, int bestcnt
, char *avail
,
746 struct supertype
*st
,
750 while (!enough(content
->array
.level
, content
->array
.raid_disks
,
751 content
->array
.layout
, 1,
754 (content
->reshape_active
&& content
->delta_disks
> 0 &&
755 !enough(content
->array
.level
, (content
->array
.raid_disks
756 - content
->delta_disks
),
757 content
->new_layout
, 1,
760 /* Choose the newest best drive which is
761 * not up-to-date, update the superblock
765 struct supertype
*tst
;
766 unsigned long long current_events
;
767 int chosen_drive
= -1;
770 for (i
= 0; i
< content
->array
.raid_disks
&& i
< bestcnt
; i
++) {
773 !devices
[j
].uptodate
&&
774 devices
[j
].i
.recovery_start
== MaxSector
&&
777 > devices
[chosen_drive
].i
.events
))
780 if (chosen_drive
< 0)
782 current_events
= devices
[chosen_drive
].i
.events
;
785 pr_err("forcing event count in %s(%d) from %d upto %d\n",
786 devices
[chosen_drive
].devname
,
787 devices
[chosen_drive
].i
.disk
.raid_disk
,
788 (int)(devices
[chosen_drive
].i
.events
),
789 (int)(devices
[most_recent
].i
.events
));
790 fd
= dev_open(devices
[chosen_drive
].devname
,
791 devices
[chosen_drive
].included
? O_RDWR
794 pr_err("Couldn't open %s for write - not updating\n",
795 devices
[chosen_drive
].devname
);
796 devices
[chosen_drive
].i
.events
= 0;
800 if (tst
->ss
->load_super(tst
,fd
, NULL
)) {
802 pr_err("RAID superblock disappeared from %s - not updating.\n",
803 devices
[chosen_drive
].devname
);
804 devices
[chosen_drive
].i
.events
= 0;
807 content
->events
= devices
[most_recent
].i
.events
;
808 tst
->ss
->update_super(tst
, content
, "force-one",
809 devices
[chosen_drive
].devname
, c
->verbose
,
812 if (tst
->ss
->store_super(tst
, fd
)) {
814 pr_err("Could not re-write superblock on %s\n",
815 devices
[chosen_drive
].devname
);
816 devices
[chosen_drive
].i
.events
= 0;
817 tst
->ss
->free_super(tst
);
821 devices
[chosen_drive
].i
.events
= devices
[most_recent
].i
.events
;
822 devices
[chosen_drive
].uptodate
= 1;
823 avail
[chosen_drive
] = 1;
825 tst
->ss
->free_super(tst
);
827 /* If there are any other drives of the same vintage,
828 * add them in as well. We can't lose and we might gain
830 for (i
= 0; i
< content
->array
.raid_disks
&& i
< bestcnt
; i
++) {
833 !devices
[j
].uptodate
&&
834 devices
[j
].i
.recovery_start
== MaxSector
&&
835 devices
[j
].i
.events
== current_events
) {
844 int Assemble(struct supertype
*st
, char *mddev
,
845 struct mddev_ident
*ident
,
846 struct mddev_dev
*devlist
,
850 * The task of Assemble is to find a collection of
851 * devices that should (according to their superblocks)
852 * form an array, and to give this collection to the MD driver.
853 * In Linux-2.4 and later, this involves submitting a
854 * SET_ARRAY_INFO ioctl with no arg - to prepare
855 * the array - and then submit a number of
856 * ADD_NEW_DISK ioctls to add disks into
857 * the array. Finally RUN_ARRAY might
858 * be submitted to start the array.
860 * Much of the work of Assemble is in finding and/or
861 * checking the disks to make sure they look right.
863 * If mddev is not set, then scan must be set and we
864 * read through the config file for dev+uuid mapping
865 * We recurse, setting mddev, for each device that
867 * - has a valid uuid (or any uuid if !uuidset)
869 * If mddev is set, we try to determine state of md.
870 * check version - must be at least 0.90.0
871 * check kernel version. must be at least 2.4.
872 * If not, we can possibly fall back on START_ARRAY
873 * Try to GET_ARRAY_INFO.
874 * If possible, give up
875 * If not, try to STOP_ARRAY just to make sure
877 * If !uuidset and scan, look in conf-file for uuid
878 * If not found, give up
879 * If !devlist and scan and uuidset, get list of devs from conf-file
882 * Check superblock - discard if bad
883 * Check uuid (set if we don't have one) - discard if no match
884 * Check superblock similarity if we have a superblock - discard if different
885 * Record events, devicenum
886 * This should give us a list of devices for the array
887 * We should collect the most recent event number
889 * Count disks with recent enough event count
890 * While force && !enough disks
891 * Choose newest rejected disks, update event count
892 * mark clean and rewrite superblock
895 * foreach device with recent events : ADD_NEW_DISK
896 * if runstop == 1 || "enough" disks and runstop==0 -> RUN_ARRAY
898 * Check the device numbers in superblock are right
899 * update superblock if any changes
905 int auto_assem
= (mddev
== NULL
&& !ident
->uuid_set
&&
906 ident
->super_minor
== UnSet
&& ident
->name
[0] == 0
907 && (ident
->container
== NULL
|| ident
->member
== NULL
));
909 int vers
= vers
; /* Keep gcc quite - it really is initialised */
910 struct devs
*devices
;
912 int *best
= NULL
; /* indexed by raid_disk */
915 unsigned int okcnt
, sparecnt
, rebuilding_cnt
;
916 unsigned int req_cnt
;
922 int start_partial_ok
= (c
->runstop
>= 0) &&
923 (c
->force
|| devlist
==NULL
|| auto_assem
);
925 struct mddev_dev
*tmpdev
;
927 struct mdinfo
*content
= NULL
;
928 struct mdinfo
*pre_exist
= NULL
;
931 char chosen_name
[1024];
932 struct map_ent
*map
= NULL
;
935 if (get_linux_version() < 2004000)
939 * If any subdevs are listed, then any that don't
940 * match ident are discarded. Remainder must all match and
942 * If no subdevs, then we scan all devices in the config file, but
943 * there must be something in the identity
947 ident
->uuid_set
== 0 &&
948 (ident
->super_minor
< 0 || ident
->super_minor
== UnSet
) &&
949 ident
->name
[0] == 0 &&
950 (ident
->container
== NULL
|| ident
->member
== NULL
) &&
951 ident
->devices
== NULL
) {
952 pr_err("No identity information available for %s - cannot assemble.\n",
953 mddev
? mddev
: "further assembly");
958 devlist
= conf_get_devs();
963 /* We come back here when doing auto-assembly and attempting some
964 * set of devices failed. Those are now marked as ->used==2 and
965 * we ignore them and try again
967 if (!st
&& ident
->st
)
970 pr_err("looking for devices for %s\n",
971 mddev
? mddev
: "further assembly");
974 num_devs
= select_devices(devlist
, ident
, &st
, &content
, c
,
979 if (!st
|| !st
->sb
|| !content
)
982 /* We have a full set of devices - we now need to find the
984 * However there is a risk that we are racing with "mdadm -I"
985 * and the array is already partially assembled - we will have
986 * rejected any devices already in this address.
987 * So we take a lock on the map file - to prevent further races -
988 * and look for the uuid in there. If found and the array is
989 * active, we abort. If found and the array is not active
990 * we commit to that md device and add all the contained devices
991 * to our list. We flag them so that we don't try to re-add,
992 * but can remove if they turn out to not be wanted.
995 pr_err("failed to get exclusive lock on mapfile - continue anyway...\n");
996 mp
= map_by_uuid(&map
, content
->uuid
);
999 /* array already exists. */
1000 pre_exist
= sysfs_read(-1, mp
->devnum
, GET_LEVEL
|GET_DEVS
);
1001 if (pre_exist
->array
.level
!= UnSet
) {
1002 pr_err("Found some drive for an array that is already active: %s\n",
1004 pr_err("giving up.\n");
1007 for (dv
= pre_exist
->devs
; dv
; dv
= dv
->next
) {
1008 /* We want to add this device to our list,
1009 * but it could already be there if "mdadm -I"
1010 * started *after* we checked for O_EXCL.
1011 * If we add it to the top of the list
1012 * it will be preferred over later copies.
1014 struct mddev_dev
*newdev
;
1015 char *devname
= map_dev(dv
->disk
.major
,
1020 newdev
= xmalloc(sizeof(*newdev
));
1021 newdev
->devname
= devname
;
1022 newdev
->disposition
= 'I';
1024 newdev
->next
= devlist
;
1028 strcpy(chosen_name
, mp
->path
);
1029 if (c
->verbose
> 0 || mddev
== NULL
||
1030 strcmp(mddev
, chosen_name
) != 0)
1031 pr_err("Merging with already-assembled %s\n",
1033 mdfd
= open_dev_excl(mp
->devnum
);
1035 int trustworthy
= FOREIGN
;
1036 name
= content
->name
;
1037 switch (st
->ss
->match_home(st
, c
->homehost
)
1038 ?: st
->ss
->match_home(st
, "any")) {
1040 trustworthy
= LOCAL
;
1041 name
= strchr(content
->name
, ':');
1045 name
= content
->name
;
1049 /* If the array is listed in mdadm.conf or on
1050 * command line, then we trust the name
1051 * even if the array doesn't look local
1053 trustworthy
= LOCAL
;
1056 content
->array
.level
== LEVEL_CONTAINER
) {
1057 name
= content
->text_version
;
1058 trustworthy
= METADATA
;
1061 if (name
[0] && trustworthy
!= LOCAL
&&
1062 ! c
->require_homehost
&&
1063 conf_name_is_free(name
))
1064 trustworthy
= LOCAL
;
1066 if (trustworthy
== LOCAL
&&
1068 /* Ignore 'host:' prefix of name */
1069 name
= strchr(name
, ':')+1;
1071 mdfd
= create_mddev(mddev
, name
, ident
->autof
, trustworthy
,
1075 st
->ss
->free_super(st
);
1080 mddev
= chosen_name
;
1081 vers
= md_get_version(mdfd
);
1083 pr_err("Assemble requires driver version 0.90.0 or later.\n"
1084 " Upgrade your kernel or try --build\n");
1088 if (pre_exist
== NULL
) {
1089 if (mddev_busy(fd2devnum(mdfd
))) {
1090 pr_err("%s already active, cannot restart it!\n",
1092 for (tmpdev
= devlist
;
1093 tmpdev
&& tmpdev
->used
!= 1;
1094 tmpdev
= tmpdev
->next
)
1096 if (tmpdev
&& auto_assem
)
1097 pr_err("%s needed for %s...\n",
1098 mddev
, tmpdev
->devname
);
1101 st
->ss
->free_super(st
);
1106 /* just incase it was started but has no content */
1107 ioctl(mdfd
, STOP_ARRAY
, NULL
);
1111 if (content
!= &info
) {
1112 /* This is a member of a container. Try starting the array. */
1114 err
= assemble_container_content(st
, mdfd
, content
, c
,
1120 /* Ok, no bad inconsistancy, we can try updating etc */
1121 devices
= xcalloc(num_devs
, sizeof(*devices
));
1122 devmap
= xcalloc(num_devs
, content
->array
.raid_disks
);
1123 devcnt
= load_devices(devices
, devmap
, ident
, st
, devlist
,
1124 c
, content
, mdfd
, mddev
,
1125 &most_recent
, &bestcnt
, &best
, inargv
);
1130 pr_err("no devices found for %s\n",
1133 st
->ss
->free_super(st
);
1140 if (c
->update
&& strcmp(c
->update
, "byteorder")==0)
1141 st
->minor_version
= 90;
1143 st
->ss
->getinfo_super(st
, content
, NULL
);
1144 clean
= content
->array
.state
& 1;
1146 /* now we have some devices that might be suitable.
1149 avail
= xcalloc(content
->array
.raid_disks
, 1);
1153 for (i
=0; i
< bestcnt
; i
++) {
1155 int event_margin
= 1; /* always allow a difference of '1'
1156 * like the kernel does
1158 if (j
< 0) continue;
1159 /* note: we ignore error flags in multipath arrays
1160 * as they don't make sense
1162 if (content
->array
.level
!= LEVEL_MULTIPATH
)
1163 if (!(devices
[j
].i
.disk
.state
& (1<<MD_DISK_ACTIVE
))) {
1164 if (!(devices
[j
].i
.disk
.state
1165 & (1<<MD_DISK_FAULTY
))) {
1166 devices
[j
].uptodate
= 1;
1171 /* If this device thinks that 'most_recent' has failed, then
1172 * we must reject this device.
1174 if (j
!= most_recent
&&
1175 content
->array
.raid_disks
> 0 &&
1176 devices
[most_recent
].i
.disk
.raid_disk
>= 0 &&
1177 devmap
[j
* content
->array
.raid_disks
+ devices
[most_recent
].i
.disk
.raid_disk
] == 0) {
1178 if (c
->verbose
> -1)
1179 pr_err("ignoring %s as it reports %s as failed\n",
1180 devices
[j
].devname
, devices
[most_recent
].devname
);
1184 if (devices
[j
].i
.events
+event_margin
>=
1185 devices
[most_recent
].i
.events
) {
1186 devices
[j
].uptodate
= 1;
1187 if (i
< content
->array
.raid_disks
) {
1188 if (devices
[j
].i
.recovery_start
== MaxSector
||
1189 (content
->reshape_active
&&
1190 ((i
>= content
->array
.raid_disks
- content
->delta_disks
) ||
1191 (i
>= content
->array
.raid_disks
- content
->delta_disks
- 1
1192 && content
->array
.level
== 4)))) {
1203 okcnt
+= force_array(content
, devices
, best
, bestcnt
,
1204 avail
, most_recent
, st
, c
);
1206 /* Now we want to look at the superblock which the kernel will base things on
1207 * and compare the devices that we think are working with the devices that the
1208 * superblock thinks are working.
1209 * If there are differences and --force is given, then update this chosen
1213 st
->ss
->free_super(st
);
1214 for (i
=0; chosen_drive
< 0 && i
<bestcnt
; i
++) {
1220 if (!devices
[j
].uptodate
)
1222 if (devices
[j
].i
.events
< devices
[most_recent
].i
.events
)
1225 if ((fd
=dev_open(devices
[j
].devname
,
1226 devices
[j
].included
? O_RDONLY
1227 : (O_RDONLY
|O_EXCL
)))< 0) {
1228 pr_err("Cannot open %s: %s\n",
1229 devices
[j
].devname
, strerror(errno
));
1234 if (st
->ss
->load_super(st
,fd
, NULL
)) {
1236 pr_err("RAID superblock has disappeared from %s\n",
1237 devices
[j
].devname
);
1244 if (st
->sb
== NULL
) {
1245 pr_err("No suitable drives found for %s\n", mddev
);
1250 st
->ss
->getinfo_super(st
, content
, NULL
);
1252 sysfs_init(content
, mdfd
, 0);
1254 for (i
=0; i
<bestcnt
; i
++) {
1256 unsigned int desired_state
;
1258 if (i
< content
->array
.raid_disks
)
1259 desired_state
= (1<<MD_DISK_ACTIVE
) | (1<<MD_DISK_SYNC
);
1265 if (!devices
[j
].uptodate
)
1268 devices
[j
].i
.disk
.state
= desired_state
;
1269 if (!(devices
[j
].i
.array
.state
& 1))
1272 if (st
->ss
->update_super(st
, &devices
[j
].i
, "assemble", NULL
,
1273 c
->verbose
, 0, NULL
)) {
1275 if (c
->verbose
>= 0)
1276 pr_err("clearing FAULTY flag for device %d in %s for %s\n",
1277 j
, mddev
, devices
[j
].devname
);
1280 if (c
->verbose
>= -1)
1281 pr_err("device %d in %s has wrong state in superblock, but %s seems ok\n",
1282 i
, mddev
, devices
[j
].devname
);
1286 if (!(super
.disks
[i
].i
.disk
.state
& (1 << MD_DISK_FAULTY
))) {
1287 pr_err("devices %d of %s is not marked FAULTY in superblock, but cannot be found\n",
1292 if (c
->force
&& !clean
&&
1293 !enough(content
->array
.level
, content
->array
.raid_disks
,
1294 content
->array
.layout
, clean
,
1296 change
+= st
->ss
->update_super(st
, content
, "force-array",
1297 devices
[chosen_drive
].devname
, c
->verbose
,
1304 fd
= dev_open(devices
[chosen_drive
].devname
,
1305 devices
[chosen_drive
].included
?
1306 O_RDWR
: (O_RDWR
|O_EXCL
));
1308 pr_err("Could not open %s for write - cannot Assemble array.\n",
1309 devices
[chosen_drive
].devname
);
1314 if (st
->ss
->store_super(st
, fd
)) {
1316 pr_err("Could not re-write superblock on %s\n",
1317 devices
[chosen_drive
].devname
);
1322 if (c
->verbose
>= 0)
1323 pr_err("Marking array %s as 'clean'\n",
1328 /* If we are in the middle of a reshape we may need to restore saved data
1329 * that was moved aside due to the reshape overwriting live data
1330 * The code of doing this lives in Grow.c
1333 if (content
->reshape_active
&&
1334 !(content
->reshape_active
& RESHAPE_NO_BACKUP
)) {
1336 int *fdlist
= xmalloc(sizeof(int)* bestcnt
);
1338 pr_err(":%s has an active reshape - checking "
1339 "if critical section needs to be restored\n",
1341 for (i
=0; i
<bestcnt
; i
++) {
1344 fdlist
[i
] = dev_open(devices
[j
].devname
,
1346 ? O_RDWR
: (O_RDWR
|O_EXCL
));
1347 if (fdlist
[i
] < 0) {
1348 pr_err("Could not open %s for write - cannot Assemble array.\n",
1349 devices
[j
].devname
);
1357 if (st
->ss
->external
&& st
->ss
->recover_backup
)
1358 err
= st
->ss
->recover_backup(st
, content
);
1360 err
= Grow_restart(st
, content
, fdlist
, bestcnt
,
1361 c
->backup_file
, c
->verbose
> 0);
1362 if (err
&& c
->invalid_backup
) {
1365 " without restoring backup\n");
1371 if (fdlist
[i
]>=0) close(fdlist
[i
]);
1375 pr_err("Failed to restore critical section for reshape, sorry.\n");
1376 if (c
->backup_file
== NULL
)
1377 cont_err("Possibly you needed to specify the --backup-file\n");
1384 /* count number of in-sync devices according to the superblock.
1385 * We must have this number to start the array without -s or -R
1387 req_cnt
= content
->array
.working_disks
;
1389 /* Almost ready to actually *do* something */
1393 /* First, fill in the map, so that udev can find our name
1394 * as soon as we become active.
1396 map_update(&map
, fd2devnum(mdfd
), content
->text_version
,
1397 content
->uuid
, chosen_name
);
1399 rv
= set_array_info(mdfd
, st
, content
);
1400 if (rv
&& !pre_exist
) {
1401 pr_err("failed to set array info for %s: %s\n",
1402 mddev
, strerror(errno
));
1403 ioctl(mdfd
, STOP_ARRAY
, NULL
);
1409 if (ident
->bitmap_fd
>= 0) {
1410 if (ioctl(mdfd
, SET_BITMAP_FILE
, ident
->bitmap_fd
) != 0) {
1411 pr_err("SET_BITMAP_FILE failed.\n");
1412 ioctl(mdfd
, STOP_ARRAY
, NULL
);
1418 } else if (ident
->bitmap_file
) {
1419 /* From config file */
1420 int bmfd
= open(ident
->bitmap_file
, O_RDWR
);
1422 pr_err("Could not open bitmap file %s\n",
1423 ident
->bitmap_file
);
1424 ioctl(mdfd
, STOP_ARRAY
, NULL
);
1430 if (ioctl(mdfd
, SET_BITMAP_FILE
, bmfd
) != 0) {
1431 pr_err("Failed to set bitmapfile for %s\n", mddev
);
1433 ioctl(mdfd
, STOP_ARRAY
, NULL
);
1442 /* First, add the raid disks, but add the chosen one last */
1443 for (i
=0; i
<= bestcnt
; i
++) {
1447 if (j
== chosen_drive
)
1452 if (j
>= 0 && !devices
[j
].included
) {
1453 int dfd
= dev_open(devices
[j
].devname
,
1456 remove_partitions(dfd
);
1459 rv
= add_disk(mdfd
, st
, content
, &devices
[j
].i
);
1462 pr_err("failed to add "
1467 if (i
< content
->array
.raid_disks
1472 } else if (c
->verbose
> 0)
1473 pr_err("added %s to %s as %d%s\n",
1474 devices
[j
].devname
, mddev
,
1475 devices
[j
].i
.disk
.raid_disk
,
1476 devices
[j
].uptodate
?"":
1477 " (possibly out of date)");
1478 } else if (j
>= 0) {
1480 pr_err("%s is already in %s as %d\n",
1481 devices
[j
].devname
, mddev
,
1482 devices
[j
].i
.disk
.raid_disk
);
1483 } else if (c
->verbose
> 0 && i
< content
->array
.raid_disks
)
1484 pr_err("no uptodate device for slot %d of %s\n",
1488 if (content
->array
.level
== LEVEL_CONTAINER
) {
1489 if (c
->verbose
>= 0) {
1490 pr_err("Container %s has been "
1491 "assembled with %d drive%s",
1492 mddev
, okcnt
+sparecnt
, okcnt
+sparecnt
==1?"":"s");
1493 if (okcnt
< (unsigned)content
->array
.raid_disks
)
1494 fprintf(stderr
, " (out of %d)",
1495 content
->array
.raid_disks
);
1496 fprintf(stderr
, "\n");
1498 st
->ss
->free_super(st
);
1499 sysfs_uevent(content
, "change");
1501 wait_for(chosen_name
, mdfd
);
1507 if (c
->runstop
== 1 ||
1509 ( enough(content
->array
.level
, content
->array
.raid_disks
,
1510 content
->array
.layout
, clean
, avail
) &&
1511 (okcnt
+ rebuilding_cnt
>= req_cnt
|| start_partial_ok
)
1513 /* This array is good-to-go.
1514 * If a reshape is in progress then we might need to
1515 * continue monitoring it. In that case we start
1516 * it read-only and let the grow code make it writable.
1520 if (content
->reshape_active
&&
1521 !(content
->reshape_active
& RESHAPE_NO_BACKUP
) &&
1522 content
->delta_disks
<= 0) {
1523 rv
= sysfs_set_str(content
, NULL
,
1524 "array_state", "readonly");
1526 rv
= Grow_continue(mdfd
, st
, content
,
1529 } else if (c
->readonly
&&
1530 sysfs_attribute_available(
1531 content
, NULL
, "array_state")) {
1532 rv
= sysfs_set_str(content
, NULL
,
1533 "array_state", "readonly");
1536 rv
= ioctl(mdfd
, RUN_ARRAY
, NULL
);
1538 if (c
->verbose
>= 0) {
1539 pr_err("%s has been started with %d drive%s",
1540 mddev
, okcnt
, okcnt
==1?"":"s");
1541 if (okcnt
< (unsigned)content
->array
.raid_disks
)
1542 fprintf(stderr
, " (out of %d)", content
->array
.raid_disks
);
1544 fprintf(stderr
, "%s %d rebuilding", sparecnt
?",":" and", rebuilding_cnt
);
1546 fprintf(stderr
, " and %d spare%s", sparecnt
, sparecnt
==1?"":"s");
1547 fprintf(stderr
, ".\n");
1549 if (content
->reshape_active
&&
1550 content
->array
.level
>= 4 &&
1551 content
->array
.level
<= 6) {
1552 /* might need to increase the size
1553 * of the stripe cache - default is 256
1555 if (256 < 4 * (content
->array
.chunk_size
/4096)) {
1556 struct mdinfo
*sra
= sysfs_read(mdfd
, 0, 0);
1558 sysfs_set_num(sra
, NULL
,
1559 "stripe_cache_size",
1560 (4 * content
->array
.chunk_size
/ 4096) + 1);
1564 if (okcnt
< (unsigned)content
->array
.raid_disks
) {
1565 /* If any devices did not get added
1566 * because the kernel rejected them based
1567 * on event count, try adding them
1568 * again providing the action policy is
1569 * 're-add' or greater. The bitmap
1570 * might allow them to be included, or
1571 * they will become spares.
1573 for (i
= 0; i
< bestcnt
; i
++) {
1575 if (j
>= 0 && !devices
[j
].uptodate
) {
1576 if (!disk_action_allows(&devices
[j
].i
, st
->ss
->name
, act_re_add
))
1578 rv
= add_disk(mdfd
, st
, content
,
1580 if (rv
== 0 && c
->verbose
>= 0)
1581 pr_err("%s has been re-added.\n",
1582 devices
[j
].devname
);
1587 wait_for(mddev
, mdfd
);
1591 /* There is a nasty race with 'mdadm --monitor'.
1592 * If it opens this device before we close it,
1593 * it gets an incomplete open on which IO
1594 * doesn't work and the capacity is
1596 * If we reopen (to check for layered devices)
1597 * before --monitor closes, we loose.
1599 * So: wait upto 1 second for there to be
1600 * a non-zero capacity.
1602 while (usecs
< 1000) {
1603 mdfd
= open(mddev
, O_RDONLY
);
1605 unsigned long long size
;
1606 if (get_dev_size(mdfd
, NULL
, &size
) &&
1618 pr_err("failed to RUN_ARRAY %s: %s\n",
1619 mddev
, strerror(errno
));
1621 if (!enough(content
->array
.level
, content
->array
.raid_disks
,
1622 content
->array
.layout
, 1, avail
))
1623 pr_err("Not enough devices to "
1624 "start the array.\n");
1625 else if (!enough(content
->array
.level
,
1626 content
->array
.raid_disks
,
1627 content
->array
.layout
, clean
,
1629 pr_err("Not enough devices to "
1630 "start the array while not clean "
1631 "- consider --force.\n");
1634 ioctl(mdfd
, STOP_ARRAY
, NULL
);
1640 if (c
->runstop
== -1) {
1641 pr_err("%s assembled from %d drive%s",
1642 mddev
, okcnt
, okcnt
==1?"":"s");
1643 if (okcnt
!= (unsigned)content
->array
.raid_disks
)
1644 fprintf(stderr
, " (out of %d)", content
->array
.raid_disks
);
1645 fprintf(stderr
, ", but not started.\n");
1651 if (c
->verbose
>= -1) {
1652 pr_err("%s assembled from %d drive%s", mddev
, okcnt
, okcnt
==1?"":"s");
1654 fprintf(stderr
, "%s %d rebuilding", sparecnt
?", ":" and ", rebuilding_cnt
);
1656 fprintf(stderr
, " and %d spare%s", sparecnt
, sparecnt
==1?"":"s");
1657 if (!enough(content
->array
.level
, content
->array
.raid_disks
,
1658 content
->array
.layout
, 1, avail
))
1659 fprintf(stderr
, " - not enough to start the array.\n");
1660 else if (!enough(content
->array
.level
,
1661 content
->array
.raid_disks
,
1662 content
->array
.layout
, clean
,
1664 fprintf(stderr
, " - not enough to start the "
1665 "array while not clean - consider "
1668 if (req_cnt
== (unsigned)content
->array
.raid_disks
)
1669 fprintf(stderr
, " - need all %d to start it", req_cnt
);
1671 fprintf(stderr
, " - need %d of %d to start", req_cnt
, content
->array
.raid_disks
);
1672 fprintf(stderr
, " (use --run to insist).\n");
1676 ioctl(mdfd
, STOP_ARRAY
, NULL
);
1682 /* The "chosen_drive" is a good choice, and if necessary, the superblock has
1683 * been updated to point to the current locations of devices.
1684 * so we can just start the array
1687 dev
= makedev(devices
[chosen_drive
].i
.disk
.major
,
1688 devices
[chosen_drive
].i
.disk
.minor
);
1689 if (ioctl(mdfd
, START_ARRAY
, dev
)) {
1690 pr_err("Cannot start array: %s\n",
1702 int assemble_container_content(struct supertype
*st
, int mdfd
,
1703 struct mdinfo
*content
, struct context
*c
,
1706 struct mdinfo
*dev
, *sra
;
1707 int working
= 0, preexist
= 0;
1709 struct map_ent
*map
= NULL
;
1713 sysfs_init(content
, mdfd
, 0);
1715 sra
= sysfs_read(mdfd
, 0, GET_VERSION
);
1716 if (sra
== NULL
|| strcmp(sra
->text_version
, content
->text_version
) != 0) {
1717 if (content
->array
.major_version
== -1 &&
1718 content
->array
.minor_version
== -2 &&
1720 content
->text_version
[0] == '/')
1721 content
->text_version
[0] = '-';
1722 if (sysfs_set_array(content
, md_get_version(mdfd
)) != 0) {
1729 /* There are two types of reshape: container wide or sub-array specific
1730 * Check if metadata requests blocking container wide reshapes
1732 start_reshape
= (content
->reshape_active
&&
1733 !((content
->reshape_active
== CONTAINER_RESHAPE
) &&
1734 (content
->array
.state
& (1<<MD_SB_BLOCK_CONTAINER_RESHAPE
))));
1736 /* Block subarray here if it is under reshape now
1737 * Do not allow for any changes in this array
1739 if (st
->ss
->external
&& content
->recovery_blocked
&& start_reshape
)
1740 block_subarray(content
);
1744 old_raid_disks
= content
->array
.raid_disks
- content
->delta_disks
;
1745 for (dev
= content
->devs
; dev
; dev
= dev
->next
)
1746 if (sysfs_add_disk(content
, dev
, 1) == 0) {
1747 if (dev
->disk
.raid_disk
>= old_raid_disks
&&
1748 content
->reshape_active
)
1752 } else if (errno
== EEXIST
)
1754 if (working
+ expansion
== 0)
1755 return 1;/* Nothing new, don't try to start */
1757 map_update(&map
, fd2devnum(mdfd
),
1758 content
->text_version
,
1759 content
->uuid
, chosen_name
);
1761 if (c
->runstop
> 0 ||
1762 (working
+ preexist
+ expansion
) >=
1763 content
->array
.working_disks
) {
1766 if (start_reshape
) {
1767 int spare
= content
->array
.raid_disks
+ expansion
;
1768 if (restore_backup(st
, content
,
1770 spare
, c
->backup_file
, c
->verbose
) == 1)
1773 err
= sysfs_set_str(content
, NULL
,
1774 "array_state", "readonly");
1778 if (st
->ss
->external
) {
1779 if (!mdmon_running(st
->container_dev
))
1780 start_mdmon(st
->container_dev
);
1781 ping_monitor_by_id(st
->container_dev
);
1782 if (mdmon_running(st
->container_dev
) &&
1783 st
->update_tail
== NULL
)
1784 st
->update_tail
= &st
->updates
;
1787 err
= Grow_continue(mdfd
, st
, content
, c
->backup_file
,
1789 } else switch(content
->array
.level
) {
1791 case LEVEL_MULTIPATH
:
1793 err
= sysfs_set_str(content
, NULL
, "array_state",
1794 c
->readonly
? "readonly" : "active");
1797 err
= sysfs_set_str(content
, NULL
, "array_state",
1799 /* start mdmon if needed. */
1801 if (!mdmon_running(st
->container_dev
))
1802 start_mdmon(st
->container_dev
);
1803 ping_monitor_by_id(st
->container_dev
);
1808 sysfs_set_safemode(content
, content
->safe_mode_delay
);
1810 /* Block subarray here if it is not reshaped now
1811 * It has be blocked a little later to allow mdmon to switch in
1814 if (st
->ss
->external
&& content
->recovery_blocked
&&
1816 block_subarray(content
);
1818 if (c
->verbose
>= 0) {
1820 pr_err("array %s now has %d device%s",
1821 chosen_name
, working
+ preexist
,
1822 working
+ preexist
== 1 ? "":"s");
1824 pr_err("Started %s with %d device%s",
1825 chosen_name
, working
+ preexist
,
1826 working
+ preexist
== 1 ? "":"s");
1828 fprintf(stderr
, " (%d new)", working
);
1830 fprintf(stderr
, " ( + %d for expansion)",
1832 fprintf(stderr
, "\n");
1835 wait_for(chosen_name
, mdfd
);
1837 /* FIXME should have an O_EXCL and wait for read-auto */
1839 if (c
->verbose
>= 0) {
1840 pr_err("%s assembled with %d device%s",
1841 chosen_name
, preexist
+ working
,
1842 preexist
+ working
== 1 ? "":"s");
1844 fprintf(stderr
, " (%d new)", working
);
1845 fprintf(stderr
, " but not started\n");