2 * mdadm - manage Linux "md" devices aka RAID arrays.
4 * Copyright (C) 2001-2012 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 content
->array
.raid_disks
!= 0 && /* metadata doesn't know how many to expect */
109 ident
->raid_disks
!= content
->array
.raid_disks
) {
111 pr_err("%s requires wrong number of drives.\n",
115 if (ident
->member
&& ident
->member
[0]) {
116 /* content->text_version must match */
117 char *s
= strchr(content
->text_version
+1, '/');
120 pr_err("%s is not a container and one is required.\n",
123 } else if (strcmp(ident
->member
, s
+1) != 0) {
125 pr_err("skipping wrong member %s is %s\n",
126 content
->text_version
, devname
);
133 static int select_devices(struct mddev_dev
*devlist
,
134 struct mddev_ident
*ident
,
135 struct supertype
**stp
,
136 struct mdinfo
**contentp
,
138 int inargv
, int auto_assem
)
140 struct mddev_dev
*tmpdev
;
142 struct supertype
*st
= *stp
;
143 struct mdinfo
*content
= NULL
;
144 int report_mismatch
= ((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
)) {
177 pr_err("%s is not one of %s\n", devname
, ident
->devices
);
183 dfd
= dev_open(devname
, O_RDONLY
);
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
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
) {
210 pr_err("not a recognisable container: %s\n",
214 } else if (!tst
->ss
->load_container
215 || tst
->ss
->load_container(tst
, dfd
, NULL
)) {
217 pr_err("no correct container type: %s\n",
220 } else if (auto_assem
&&
221 !conf_test_metadata(tst
->ss
->name
, (pol
= devid_policy(stb
.st_rdev
)),
222 tst
->ss
->match_home(tst
, c
->homehost
) == 1)) {
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
) {
233 pr_err("no recogniseable superblock on %s\n",
236 } else if (tst
->ss
->load_super(tst
,dfd
, NULL
)) {
238 pr_err("no RAID superblock on %s\n",
241 } else if (tst
->ss
->compare_super
== NULL
) {
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
= devid_policy(stb
.st_rdev
)),
248 tst
->ss
->match_home(tst
, c
->homehost
) == 1)) {
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
);
287 pr_err("%s is busy - skipping\n", devname
);
292 if (ident
->container
) {
293 if (ident
->container
[0] == '/' &&
294 !same_dev(ident
->container
, devname
)) {
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
)) {
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_mismatch
? devname
: NULL
))
329 /* message already printed */;
330 else if (is_member_busy(content
->text_version
)) {
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 */
367 struct mddev_ident
*match
;
370 tst
->ss
->getinfo_super(tst
, content
, NULL
);
372 if (!ident_matches(ident
, content
, tst
,
373 c
->homehost
, c
->update
,
374 report_mismatch
? devname
: NULL
))
377 match
= conf_match(tst
, content
, devname
,
378 report_mismatch
? c
->verbose
: -1,
380 if (!match
&& rv
== 2)
382 if (match
&& match
->devname
&&
383 strcasecmp(match
->devname
, "<ignore>") == 0) {
385 pr_err("%s is a member of an explicitly ignored array\n",
389 if (match
&& !ident_matches(match
, content
, tst
,
390 c
->homehost
, c
->update
,
391 report_mismatch
? devname
: NULL
))
392 /* Array exists in mdadm.conf but some
393 * details don't match, so reject it
397 /* should be safe to try an exclusive open now, we
398 * have rejected anything that some other mdadm might
401 dfd
= dev_open(devname
, O_RDONLY
| O_EXCL
);
404 pr_err("%s is busy - skipping\n", devname
);
411 if (st
->minor_version
== -1)
412 st
->minor_version
= tst
->minor_version
;
414 if (memcmp(content
->uuid
, uuid_zero
,
415 sizeof(int[4])) == 0) {
416 /* this is a floating spare. It cannot define
417 * an array unless there are no more arrays of
418 * this type to be found. It can be included
419 * in an array of this type though.
425 if (st
->ss
!= tst
->ss
||
426 st
->minor_version
!= tst
->minor_version
||
427 st
->ss
->compare_super(st
, tst
) != 0) {
428 /* Some mismatch. If exactly one array matches this host,
429 * we can resolve on that one.
430 * Or, if we are auto assembling, we just ignore the second
436 int first
= st
->ss
->match_home(st
, c
->homehost
);
437 int last
= tst
->ss
->match_home(tst
, c
->homehost
);
439 (first
== 1 || last
== 1)) {
440 /* We can do something */
441 if (first
) {/* just ignore this one */
443 pr_err("%s misses out due to wrong homehost\n",
446 } else { /* reject all those sofar */
447 struct mddev_dev
*td
;
449 pr_err("%s overrides previous devices due to good homehost\n",
451 for (td
=devlist
; td
!= tmpdev
; td
=td
->next
)
459 pr_err("superblock on %s doesn't match others - assembly aborted\n",
461 tst
->ss
->free_super(tst
);
462 st
->ss
->free_super(st
);
463 dev_policy_free(pol
);
464 domain_free(domains
);
470 /* Collect domain information from members only */
471 if (tmpdev
&& tmpdev
->used
== 1) {
473 pol
= devid_policy(stb
.st_rdev
);
474 domain_merge(&domains
, pol
, tst
?tst
->ss
->name
:NULL
);
476 dev_policy_free(pol
);
479 tst
->ss
->free_super(tst
);
482 /* Check if we found some imsm spares but no members */
485 memcmp(uuid_zero
, ident
->uuid
,sizeof(uuid_zero
)) == 0)) &&
487 for (tmpdev
= devlist
; tmpdev
; tmpdev
= tmpdev
->next
) {
488 if (tmpdev
->used
!= 3)
494 /* we need sb from one of the spares */
495 int dfd
= dev_open(tmpdev
->devname
, O_RDONLY
);
497 st
->ss
->load_super(st
, dfd
, NULL
))
504 /* Now reject spares that don't match domains of identified members */
505 for (tmpdev
= devlist
; tmpdev
; tmpdev
= tmpdev
->next
) {
507 if (tmpdev
->used
!= 3)
509 if (stat(tmpdev
->devname
, &stb
)< 0) {
510 pr_err("fstat failed for %s: %s\n",
511 tmpdev
->devname
, strerror(errno
));
514 struct dev_policy
*pol
= devid_policy(stb
.st_rdev
);
515 int dt
= domain_test(domains
, pol
, NULL
);
516 if (inargv
&& dt
!= 0)
517 /* take this spare as domains match
518 * if there are any */
520 else if (!inargv
&& dt
== 1)
521 /* device wasn't explicitly listed, so need
522 * explicit domain match - which we have */
525 /* if domains don't match mark as unused */
527 dev_policy_free(pol
);
530 domain_free(domains
);
532 if (st
&& st
->sb
&& content
== *contentp
)
533 st
->ss
->getinfo_super(st
, content
, NULL
);
541 int uptodate
; /* set once we decide that this device is as
542 * recent as everything else in the array.
544 int included
; /* set if the device is already in the array
545 * due to a previous '-I'
550 static int load_devices(struct devs
*devices
, char *devmap
,
551 struct mddev_ident
*ident
, struct supertype
*st
,
552 struct mddev_dev
*devlist
, struct context
*c
,
553 struct mdinfo
*content
,
554 int mdfd
, char *mddev
,
555 int *most_recentp
, int *bestcntp
, int **bestp
,
558 struct mddev_dev
*tmpdev
;
568 for (tmpdev
= devlist
; tmpdev
; tmpdev
=tmpdev
->next
) {
569 char *devname
= tmpdev
->devname
;
573 if (tmpdev
->used
!= 1)
575 /* looks like a good enough match to update the super block if needed */
579 /* prepare useful information in info structures */
581 struct supertype
*tst
;
585 if (strcmp(c
->update
, "uuid")==0 &&
588 if ((rfd
= open("/dev/urandom", O_RDONLY
)) < 0 ||
589 read(rfd
, ident
->uuid
, 16) != 16) {
590 *(__u32
*)(ident
->uuid
) = random();
591 *(__u32
*)(ident
->uuid
+1) = random();
592 *(__u32
*)(ident
->uuid
+2) = random();
593 *(__u32
*)(ident
->uuid
+3) = random();
595 if (rfd
>= 0) close(rfd
);
597 dfd
= dev_open(devname
,
598 tmpdev
->disposition
== 'I'
599 ? O_RDWR
: (O_RDWR
|O_EXCL
));
602 if (dfd
< 0 || tst
->ss
->load_super(tst
, dfd
, NULL
) != 0) {
603 pr_err("cannot re-read metadata from %s - aborting\n",
612 tst
->ss
->getinfo_super(tst
, content
, devmap
+ devcnt
* content
->array
.raid_disks
);
614 memcpy(content
->uuid
, ident
->uuid
, 16);
615 strcpy(content
->name
, ident
->name
);
616 content
->array
.md_minor
= minor(stb2
.st_rdev
);
618 if (strcmp(c
->update
, "byteorder") == 0)
621 err
= tst
->ss
->update_super(tst
, content
, c
->update
,
627 pr_err("--update=%s not understood"
628 " for %s metadata\n",
629 c
->update
, tst
->ss
->name
);
630 tst
->ss
->free_super(tst
);
638 if (strcmp(c
->update
, "uuid")==0 &&
641 memcpy(ident
->uuid
, content
->uuid
, 16);
643 if (tst
->ss
->store_super(tst
, dfd
))
644 pr_err("Could not re-write superblock on %s.\n",
648 if (strcmp(c
->update
, "uuid")==0 &&
649 ident
->bitmap_fd
>= 0 && !bitmap_done
) {
650 if (bitmap_update_uuid(ident
->bitmap_fd
,
652 tst
->ss
->swapuuid
) != 0)
653 pr_err("Could not update uuid on external bitmap.\n");
657 tst
->ss
->free_super(tst
);
661 struct supertype
*tst
= dup_super(st
);
663 dfd
= dev_open(devname
,
664 tmpdev
->disposition
== 'I'
665 ? O_RDWR
: (O_RDWR
|O_EXCL
));
667 if (dfd
< 0 || tst
->ss
->load_super(tst
, dfd
, NULL
) != 0) {
668 pr_err("cannot re-read metadata from %s - aborting\n",
677 tst
->ss
->getinfo_super(tst
, content
, devmap
+ devcnt
* content
->array
.raid_disks
);
678 tst
->ss
->free_super(tst
);
685 pr_err("%s is identified as a member of %s, slot %d%s.\n",
686 devname
, mddev
, content
->disk
.raid_disk
,
687 (content
->disk
.state
& (1<<MD_DISK_REPLACEMENT
)) ? " replacement":"");
688 devices
[devcnt
].devname
= devname
;
689 devices
[devcnt
].uptodate
= 0;
690 devices
[devcnt
].included
= (tmpdev
->disposition
== 'I');
691 devices
[devcnt
].i
= *content
;
692 devices
[devcnt
].i
.disk
.major
= major(stb
.st_rdev
);
693 devices
[devcnt
].i
.disk
.minor
= minor(stb
.st_rdev
);
695 if (devices
[devcnt
].i
.events
696 > devices
[most_recent
].i
.events
&&
697 devices
[devcnt
].i
.disk
.state
== 6)
698 most_recent
= devcnt
;
700 if (content
->array
.level
== LEVEL_MULTIPATH
)
701 /* with multipath, the raid_disk from the superblock is meaningless */
704 i
= devices
[devcnt
].i
.disk
.raid_disk
;
706 if (nextspare
< content
->array
.raid_disks
*2)
707 nextspare
= content
->array
.raid_disks
*2;
710 /* i is raid_disk - double it so there is room for
713 if (devices
[devcnt
].i
.disk
.state
& (1<<MD_DISK_REPLACEMENT
))
715 if (i
>= content
->array
.raid_disks
*2 &&
721 int newbestcnt
= i
+10;
722 int *newbest
= xmalloc(sizeof(int)*newbestcnt
);
724 for (c
=0; c
< newbestcnt
; c
++)
726 newbest
[c
] = best
[c
];
731 bestcnt
= newbestcnt
;
734 devices
[best
[i
]].i
.events
735 == devices
[devcnt
].i
.events
736 && (devices
[best
[i
]].i
.disk
.minor
737 != devices
[devcnt
].i
.disk
.minor
)
739 && content
->array
.level
!= LEVEL_MULTIPATH
) {
740 /* two different devices with identical superblock.
741 * Could be a mis-detection caused by overlapping
742 * partitions. fail-safe.
744 pr_err("WARNING %s and %s appear"
745 " to have very similar superblocks.\n"
746 " If they are really different, "
747 "please --zero the superblock on one\n"
748 " If they are the same or overlap,"
749 " please remove one from %s.\n",
750 devices
[best
[i
]].devname
, devname
,
751 inargv
? "the list" :
752 "the\n DEVICE list in mdadm.conf"
760 || (devices
[best
[i
]].i
.events
761 < devices
[devcnt
].i
.events
))
766 *most_recentp
= most_recent
;
772 static int force_array(struct mdinfo
*content
,
773 struct devs
*devices
,
774 int *best
, int bestcnt
, char *avail
,
776 struct supertype
*st
,
780 while (!enough(content
->array
.level
, content
->array
.raid_disks
,
781 content
->array
.layout
, 1,
784 (content
->reshape_active
&& content
->delta_disks
> 0 &&
785 !enough(content
->array
.level
, (content
->array
.raid_disks
786 - content
->delta_disks
),
787 content
->new_layout
, 1,
790 /* Choose the newest best drive which is
791 * not up-to-date, update the superblock
795 struct supertype
*tst
;
796 unsigned long long current_events
;
797 int chosen_drive
= -1;
800 for (i
= 0; i
< content
->array
.raid_disks
&& i
< bestcnt
; i
++) {
803 !devices
[j
].uptodate
&&
804 devices
[j
].i
.recovery_start
== MaxSector
&&
807 > devices
[chosen_drive
].i
.events
))
810 if (chosen_drive
< 0)
812 current_events
= devices
[chosen_drive
].i
.events
;
815 pr_err("forcing event count in %s(%d) from %d upto %d\n",
816 devices
[chosen_drive
].devname
,
817 devices
[chosen_drive
].i
.disk
.raid_disk
,
818 (int)(devices
[chosen_drive
].i
.events
),
819 (int)(devices
[most_recent
].i
.events
));
820 fd
= dev_open(devices
[chosen_drive
].devname
,
821 devices
[chosen_drive
].included
? O_RDWR
824 pr_err("Couldn't open %s for write - not updating\n",
825 devices
[chosen_drive
].devname
);
826 devices
[chosen_drive
].i
.events
= 0;
830 if (tst
->ss
->load_super(tst
,fd
, NULL
)) {
832 pr_err("RAID superblock disappeared from %s - not updating.\n",
833 devices
[chosen_drive
].devname
);
834 devices
[chosen_drive
].i
.events
= 0;
837 content
->events
= devices
[most_recent
].i
.events
;
838 tst
->ss
->update_super(tst
, content
, "force-one",
839 devices
[chosen_drive
].devname
, c
->verbose
,
842 if (tst
->ss
->store_super(tst
, fd
)) {
844 pr_err("Could not re-write superblock on %s\n",
845 devices
[chosen_drive
].devname
);
846 devices
[chosen_drive
].i
.events
= 0;
847 tst
->ss
->free_super(tst
);
851 devices
[chosen_drive
].i
.events
= devices
[most_recent
].i
.events
;
852 devices
[chosen_drive
].uptodate
= 1;
853 avail
[chosen_drive
] = 1;
855 tst
->ss
->free_super(tst
);
857 /* If there are any other drives of the same vintage,
858 * add them in as well. We can't lose and we might gain
860 for (i
= 0; i
< content
->array
.raid_disks
&& i
< bestcnt
; i
++) {
863 !devices
[j
].uptodate
&&
864 devices
[j
].i
.recovery_start
== MaxSector
&&
865 devices
[j
].i
.events
== current_events
) {
874 static int start_array(int mdfd
,
876 struct mdinfo
*content
,
877 struct supertype
*st
,
878 struct mddev_ident
*ident
,
879 int *best
, int bestcnt
,
881 struct devs
*devices
,
883 unsigned int sparecnt
,
884 unsigned int rebuilding_cnt
,
886 int clean
, char *avail
,
887 int start_partial_ok
,
894 unsigned int req_cnt
;
896 rv
= set_array_info(mdfd
, st
, content
);
898 pr_err("failed to set array info for %s: %s\n",
899 mddev
, strerror(errno
));
902 if (ident
->bitmap_fd
>= 0) {
903 if (ioctl(mdfd
, SET_BITMAP_FILE
, ident
->bitmap_fd
) != 0) {
904 pr_err("SET_BITMAP_FILE failed.\n");
907 } else if (ident
->bitmap_file
) {
908 /* From config file */
909 int bmfd
= open(ident
->bitmap_file
, O_RDWR
);
911 pr_err("Could not open bitmap file %s\n",
915 if (ioctl(mdfd
, SET_BITMAP_FILE
, bmfd
) != 0) {
916 pr_err("Failed to set bitmapfile for %s\n", mddev
);
923 /* First, add the raid disks, but add the chosen one last */
924 for (i
=0; i
<= bestcnt
; i
++) {
928 if (j
== chosen_drive
)
933 if (j
>= 0 && !devices
[j
].included
) {
934 int dfd
= dev_open(devices
[j
].devname
,
937 remove_partitions(dfd
);
940 rv
= add_disk(mdfd
, st
, content
, &devices
[j
].i
);
943 pr_err("failed to add "
948 if (i
< content
->array
.raid_disks
* 2
953 } else if (c
->verbose
> 0)
954 pr_err("added %s to %s as %d%s%s\n",
955 devices
[j
].devname
, mddev
,
956 devices
[j
].i
.disk
.raid_disk
,
957 devices
[j
].uptodate
?"":
958 " (possibly out of date)",
959 (devices
[j
].i
.disk
.state
& (1<<MD_DISK_REPLACEMENT
))?" replacement":"");
962 pr_err("%s is already in %s as %d\n",
963 devices
[j
].devname
, mddev
,
964 devices
[j
].i
.disk
.raid_disk
);
965 } else if (c
->verbose
> 0 && i
< content
->array
.raid_disks
*2
967 pr_err("no uptodate device for slot %d of %s\n",
971 if (content
->array
.level
== LEVEL_CONTAINER
) {
972 if (c
->verbose
>= 0) {
973 pr_err("Container %s has been "
974 "assembled with %d drive%s",
975 mddev
, okcnt
+sparecnt
, okcnt
+sparecnt
==1?"":"s");
976 if (okcnt
< (unsigned)content
->array
.raid_disks
)
977 fprintf(stderr
, " (out of %d)",
978 content
->array
.raid_disks
);
979 fprintf(stderr
, "\n");
981 st
->ss
->free_super(st
);
982 sysfs_uevent(content
, "change");
986 /* Get number of in-sync devices according to the superblock.
987 * We must have this number to start the array without -s or -R
989 req_cnt
= content
->array
.working_disks
;
991 if (c
->runstop
== 1 ||
993 ( enough(content
->array
.level
, content
->array
.raid_disks
,
994 content
->array
.layout
, clean
, avail
) &&
995 (okcnt
+ rebuilding_cnt
>= req_cnt
|| start_partial_ok
)
997 /* This array is good-to-go.
998 * If a reshape is in progress then we might need to
999 * continue monitoring it. In that case we start
1000 * it read-only and let the grow code make it writable.
1004 if (content
->reshape_active
&&
1005 !(content
->reshape_active
& RESHAPE_NO_BACKUP
) &&
1006 content
->delta_disks
<= 0) {
1007 rv
= sysfs_set_str(content
, NULL
,
1008 "array_state", "readonly");
1010 rv
= Grow_continue(mdfd
, st
, content
,
1013 } else if (c
->readonly
&&
1014 sysfs_attribute_available(
1015 content
, NULL
, "array_state")) {
1016 rv
= sysfs_set_str(content
, NULL
,
1017 "array_state", "readonly");
1020 rv
= ioctl(mdfd
, RUN_ARRAY
, NULL
);
1022 if (c
->verbose
>= 0) {
1023 pr_err("%s has been started with %d drive%s",
1024 mddev
, okcnt
, okcnt
==1?"":"s");
1025 if (okcnt
< (unsigned)content
->array
.raid_disks
)
1026 fprintf(stderr
, " (out of %d)", content
->array
.raid_disks
);
1028 fprintf(stderr
, "%s %d rebuilding", sparecnt
?",":" and", rebuilding_cnt
);
1030 fprintf(stderr
, " and %d spare%s", sparecnt
, sparecnt
==1?"":"s");
1031 fprintf(stderr
, ".\n");
1033 if (content
->reshape_active
&&
1034 content
->array
.level
>= 4 &&
1035 content
->array
.level
<= 6) {
1036 /* might need to increase the size
1037 * of the stripe cache - default is 256
1039 if (256 < 4 * (content
->array
.chunk_size
/4096)) {
1040 struct mdinfo
*sra
= sysfs_read(mdfd
, NULL
, 0);
1042 sysfs_set_num(sra
, NULL
,
1043 "stripe_cache_size",
1044 (4 * content
->array
.chunk_size
/ 4096) + 1);
1048 if (okcnt
< (unsigned)content
->array
.raid_disks
) {
1049 /* If any devices did not get added
1050 * because the kernel rejected them based
1051 * on event count, try adding them
1052 * again providing the action policy is
1053 * 're-add' or greater. The bitmap
1054 * might allow them to be included, or
1055 * they will become spares.
1057 for (i
= 0; i
< bestcnt
; i
++) {
1059 if (j
>= 0 && !devices
[j
].uptodate
) {
1060 if (!disk_action_allows(&devices
[j
].i
, st
->ss
->name
, act_re_add
))
1062 rv
= add_disk(mdfd
, st
, content
,
1064 if (rv
== 0 && c
->verbose
>= 0)
1065 pr_err("%s has been re-added.\n",
1066 devices
[j
].devname
);
1070 if (content
->array
.level
== 6 &&
1071 okcnt
+ 1 == (unsigned)content
->array
.raid_disks
&&
1073 struct mdinfo
*sra
= sysfs_read(mdfd
, NULL
, 0);
1075 sysfs_set_str(sra
, NULL
,
1076 "sync_action", "repair");
1081 pr_err("failed to RUN_ARRAY %s: %s\n",
1082 mddev
, strerror(errno
));
1084 if (!enough(content
->array
.level
, content
->array
.raid_disks
,
1085 content
->array
.layout
, 1, avail
))
1086 pr_err("Not enough devices to "
1087 "start the array.\n");
1088 else if (!enough(content
->array
.level
,
1089 content
->array
.raid_disks
,
1090 content
->array
.layout
, clean
,
1092 pr_err("Not enough devices to "
1093 "start the array while not clean "
1094 "- consider --force.\n");
1098 if (c
->runstop
== -1) {
1099 pr_err("%s assembled from %d drive%s",
1100 mddev
, okcnt
, okcnt
==1?"":"s");
1101 if (okcnt
!= (unsigned)content
->array
.raid_disks
)
1102 fprintf(stderr
, " (out of %d)", content
->array
.raid_disks
);
1103 fprintf(stderr
, ", but not started.\n");
1106 if (c
->verbose
>= -1) {
1107 pr_err("%s assembled from %d drive%s", mddev
, okcnt
, okcnt
==1?"":"s");
1109 fprintf(stderr
, "%s %d rebuilding", sparecnt
?",":" and", rebuilding_cnt
);
1111 fprintf(stderr
, " and %d spare%s", sparecnt
, sparecnt
==1?"":"s");
1112 if (!enough(content
->array
.level
, content
->array
.raid_disks
,
1113 content
->array
.layout
, 1, avail
))
1114 fprintf(stderr
, " - not enough to start the array.\n");
1115 else if (!enough(content
->array
.level
,
1116 content
->array
.raid_disks
,
1117 content
->array
.layout
, clean
,
1119 fprintf(stderr
, " - not enough to start the "
1120 "array while not clean - consider "
1123 if (req_cnt
== (unsigned)content
->array
.raid_disks
)
1124 fprintf(stderr
, " - need all %d to start it", req_cnt
);
1126 fprintf(stderr
, " - need %d to start", req_cnt
);
1127 fprintf(stderr
, " (use --run to insist).\n");
1133 int Assemble(struct supertype
*st
, char *mddev
,
1134 struct mddev_ident
*ident
,
1135 struct mddev_dev
*devlist
,
1139 * The task of Assemble is to find a collection of
1140 * devices that should (according to their superblocks)
1141 * form an array, and to give this collection to the MD driver.
1142 * In Linux-2.4 and later, this involves submitting a
1143 * SET_ARRAY_INFO ioctl with no arg - to prepare
1144 * the array - and then submit a number of
1145 * ADD_NEW_DISK ioctls to add disks into
1146 * the array. Finally RUN_ARRAY might
1147 * be submitted to start the array.
1149 * Much of the work of Assemble is in finding and/or
1150 * checking the disks to make sure they look right.
1152 * If mddev is not set, then scan must be set and we
1153 * read through the config file for dev+uuid mapping
1154 * We recurse, setting mddev, for each device that
1156 * - has a valid uuid (or any uuid if !uuidset)
1158 * If mddev is set, we try to determine state of md.
1159 * check version - must be at least 0.90.0
1160 * check kernel version. must be at least 2.4.
1161 * If not, we can possibly fall back on START_ARRAY
1162 * Try to GET_ARRAY_INFO.
1163 * If possible, give up
1164 * If not, try to STOP_ARRAY just to make sure
1166 * If !uuidset and scan, look in conf-file for uuid
1167 * If not found, give up
1168 * If !devlist and scan and uuidset, get list of devs from conf-file
1171 * Check superblock - discard if bad
1172 * Check uuid (set if we don't have one) - discard if no match
1173 * Check superblock similarity if we have a superblock - discard if different
1174 * Record events, devicenum
1175 * This should give us a list of devices for the array
1176 * We should collect the most recent event number
1178 * Count disks with recent enough event count
1179 * While force && !enough disks
1180 * Choose newest rejected disks, update event count
1181 * mark clean and rewrite superblock
1184 * foreach device with recent events : ADD_NEW_DISK
1185 * if runstop == 1 || "enough" disks and runstop==0 -> RUN_ARRAY
1187 * Check the device numbers in superblock are right
1188 * update superblock if any changes
1195 int auto_assem
= (mddev
== NULL
&& !ident
->uuid_set
&&
1196 ident
->super_minor
== UnSet
&& ident
->name
[0] == 0
1197 && (ident
->container
== NULL
|| ident
->member
== NULL
));
1198 struct devs
*devices
;
1200 int *best
= NULL
; /* indexed by raid_disk */
1203 unsigned int okcnt
, sparecnt
, rebuilding_cnt
, replcnt
;
1206 int most_recent
= 0;
1210 int start_partial_ok
= (c
->runstop
>= 0) &&
1211 (c
->force
|| devlist
==NULL
|| auto_assem
);
1213 struct mddev_dev
*tmpdev
;
1215 struct mdinfo
*content
= NULL
;
1216 struct mdinfo
*pre_exist
= NULL
;
1219 char chosen_name
[1024];
1220 struct map_ent
*map
= NULL
;
1224 * If any subdevs are listed, then any that don't
1225 * match ident are discarded. Remainder must all match and
1227 * If no subdevs, then we scan all devices in the config file, but
1228 * there must be something in the identity
1232 ident
->uuid_set
== 0 &&
1233 (ident
->super_minor
< 0 || ident
->super_minor
== UnSet
) &&
1234 ident
->name
[0] == 0 &&
1235 (ident
->container
== NULL
|| ident
->member
== NULL
) &&
1236 ident
->devices
== NULL
) {
1237 pr_err("No identity information available for %s - cannot assemble.\n",
1238 mddev
? mddev
: "further assembly");
1242 if (devlist
== NULL
)
1243 devlist
= conf_get_devs();
1248 /* We come back here when doing auto-assembly and attempting some
1249 * set of devices failed. Those are now marked as ->used==2 and
1250 * we ignore them and try again
1252 if (!st
&& ident
->st
)
1255 pr_err("looking for devices for %s\n",
1256 mddev
? mddev
: "further assembly");
1260 st
->ignore_hw_compat
= 1;
1261 num_devs
= select_devices(devlist
, ident
, &st
, &content
, c
,
1262 inargv
, auto_assem
);
1266 if (!st
|| !st
->sb
|| !content
)
1269 /* We have a full set of devices - we now need to find the
1271 * However there is a risk that we are racing with "mdadm -I"
1272 * and the array is already partially assembled - we will have
1273 * rejected any devices already in this address.
1274 * So we take a lock on the map file - to prevent further races -
1275 * and look for the uuid in there. If found and the array is
1276 * active, we abort. If found and the array is not active
1277 * we commit to that md device and add all the contained devices
1278 * to our list. We flag them so that we don't try to re-add,
1279 * but can remove if they turn out to not be wanted.
1282 pr_err("failed to get exclusive lock on mapfile - continue anyway...\n");
1283 mp
= map_by_uuid(&map
, content
->uuid
);
1286 /* array already exists. */
1287 pre_exist
= sysfs_read(-1, mp
->devnm
, GET_LEVEL
|GET_DEVS
);
1288 if (pre_exist
->array
.level
!= UnSet
) {
1289 pr_err("Found some drive for an array that is already active: %s\n",
1291 pr_err("giving up.\n");
1294 for (dv
= pre_exist
->devs
; dv
; dv
= dv
->next
) {
1295 /* We want to add this device to our list,
1296 * but it could already be there if "mdadm -I"
1297 * started *after* we checked for O_EXCL.
1298 * If we add it to the top of the list
1299 * it will be preferred over later copies.
1301 struct mddev_dev
*newdev
;
1302 char *devname
= map_dev(dv
->disk
.major
,
1307 newdev
= xmalloc(sizeof(*newdev
));
1308 newdev
->devname
= devname
;
1309 newdev
->disposition
= 'I';
1311 newdev
->next
= devlist
;
1315 strcpy(chosen_name
, mp
->path
);
1316 if (c
->verbose
> 0 || mddev
== NULL
||
1317 strcmp(mddev
, chosen_name
) != 0)
1318 pr_err("Merging with already-assembled %s\n",
1320 mdfd
= open_dev_excl(mp
->devnm
);
1322 int trustworthy
= FOREIGN
;
1323 name
= content
->name
;
1324 switch (st
->ss
->match_home(st
, c
->homehost
)
1325 ?: st
->ss
->match_home(st
, "any")) {
1327 trustworthy
= LOCAL
;
1328 name
= strchr(content
->name
, ':');
1332 name
= content
->name
;
1336 /* If the array is listed in mdadm.conf or on
1337 * command line, then we trust the name
1338 * even if the array doesn't look local
1340 trustworthy
= LOCAL
;
1343 content
->array
.level
== LEVEL_CONTAINER
) {
1344 name
= content
->text_version
;
1345 trustworthy
= METADATA
;
1348 if (name
[0] && trustworthy
!= LOCAL
&&
1349 ! c
->require_homehost
&&
1350 conf_name_is_free(name
))
1351 trustworthy
= LOCAL
;
1353 if (trustworthy
== LOCAL
&&
1355 /* Ignore 'host:' prefix of name */
1356 name
= strchr(name
, ':')+1;
1358 mdfd
= create_mddev(mddev
, name
, ident
->autof
, trustworthy
,
1362 st
->ss
->free_super(st
);
1367 mddev
= chosen_name
;
1368 if (get_linux_version() < 2004000 ||
1369 md_get_version(mdfd
) < 9000) {
1370 pr_err("Assemble requires Linux 2.4 or later, and\n"
1371 " md driver version 0.90.0 or later.\n"
1372 " Upgrade your kernel or try --build\n");
1376 if (pre_exist
== NULL
) {
1377 if (mddev_busy(fd2devnm(mdfd
))) {
1378 pr_err("%s already active, cannot restart it!\n",
1380 for (tmpdev
= devlist
;
1381 tmpdev
&& tmpdev
->used
!= 1;
1382 tmpdev
= tmpdev
->next
)
1384 if (tmpdev
&& auto_assem
)
1385 pr_err("%s needed for %s...\n",
1386 mddev
, tmpdev
->devname
);
1389 st
->ss
->free_super(st
);
1394 /* just incase it was started but has no content */
1395 ioctl(mdfd
, STOP_ARRAY
, NULL
);
1399 if (content
!= &info
) {
1400 /* This is a member of a container. Try starting the array. */
1402 err
= assemble_container_content(st
, mdfd
, content
, c
,
1408 /* Ok, no bad inconsistancy, we can try updating etc */
1409 devices
= xcalloc(num_devs
, sizeof(*devices
));
1410 devmap
= xcalloc(num_devs
, content
->array
.raid_disks
);
1411 devcnt
= load_devices(devices
, devmap
, ident
, st
, devlist
,
1412 c
, content
, mdfd
, mddev
,
1413 &most_recent
, &bestcnt
, &best
, inargv
);
1418 pr_err("no devices found for %s\n",
1421 st
->ss
->free_super(st
);
1428 if (c
->update
&& strcmp(c
->update
, "byteorder")==0)
1429 st
->minor_version
= 90;
1431 st
->ss
->getinfo_super(st
, content
, NULL
);
1432 clean
= content
->array
.state
& 1;
1434 /* now we have some devices that might be suitable.
1437 avail
= xcalloc(content
->array
.raid_disks
, 1);
1442 for (i
=0; i
< bestcnt
; i
++) {
1444 int event_margin
= 1; /* always allow a difference of '1'
1445 * like the kernel does
1447 if (j
< 0) continue;
1448 /* note: we ignore error flags in multipath arrays
1449 * as they don't make sense
1451 if (content
->array
.level
!= LEVEL_MULTIPATH
)
1452 if (!(devices
[j
].i
.disk
.state
& (1<<MD_DISK_ACTIVE
))) {
1453 if (!(devices
[j
].i
.disk
.state
1454 & (1<<MD_DISK_FAULTY
))) {
1455 devices
[j
].uptodate
= 1;
1460 /* If this device thinks that 'most_recent' has failed, then
1461 * we must reject this device.
1463 if (j
!= most_recent
&&
1464 content
->array
.raid_disks
> 0 &&
1465 devices
[most_recent
].i
.disk
.raid_disk
>= 0 &&
1466 devmap
[j
* content
->array
.raid_disks
+ devices
[most_recent
].i
.disk
.raid_disk
] == 0) {
1467 if (c
->verbose
> -1)
1468 pr_err("ignoring %s as it reports %s as failed\n",
1469 devices
[j
].devname
, devices
[most_recent
].devname
);
1473 /* Require event counter to be same as, or just less than,
1474 * most recent. If it is bigger, it must be a stray spare and
1475 * should be ignored.
1477 if (devices
[j
].i
.events
+event_margin
>=
1478 devices
[most_recent
].i
.events
&&
1479 devices
[j
].i
.events
<=
1480 devices
[most_recent
].i
.events
1482 devices
[j
].uptodate
= 1;
1483 if (i
< content
->array
.raid_disks
* 2) {
1484 if (devices
[j
].i
.recovery_start
== MaxSector
||
1485 (content
->reshape_active
&&
1486 ((i
>= content
->array
.raid_disks
- content
->delta_disks
) ||
1487 (i
>= content
->array
.raid_disks
- content
->delta_disks
- 1
1488 && content
->array
.level
== 4)))) {
1502 int force_ok
= force_array(content
, devices
, best
, bestcnt
,
1503 avail
, most_recent
, st
, c
);
1508 /* Now we want to look at the superblock which the kernel will base things on
1509 * and compare the devices that we think are working with the devices that the
1510 * superblock thinks are working.
1511 * If there are differences and --force is given, then update this chosen
1515 st
->ss
->free_super(st
);
1516 for (i
=0; chosen_drive
< 0 && i
<bestcnt
; i
++) {
1522 if (!devices
[j
].uptodate
)
1524 if (devices
[j
].i
.events
< devices
[most_recent
].i
.events
)
1527 if ((fd
=dev_open(devices
[j
].devname
,
1528 devices
[j
].included
? O_RDONLY
1529 : (O_RDONLY
|O_EXCL
)))< 0) {
1530 pr_err("Cannot open %s: %s\n",
1531 devices
[j
].devname
, strerror(errno
));
1536 if (st
->ss
->load_super(st
,fd
, NULL
)) {
1538 pr_err("RAID superblock has disappeared from %s\n",
1539 devices
[j
].devname
);
1546 if (st
->sb
== NULL
) {
1547 pr_err("No suitable drives found for %s\n", mddev
);
1552 st
->ss
->getinfo_super(st
, content
, NULL
);
1554 sysfs_init(content
, mdfd
, NULL
);
1556 for (i
=0; i
<bestcnt
; i
++) {
1558 unsigned int desired_state
;
1560 if (i
>= content
->array
.raid_disks
* 2)
1563 desired_state
= (1<<MD_DISK_ACTIVE
) | (1<<MD_DISK_REPLACEMENT
);
1565 desired_state
= (1<<MD_DISK_ACTIVE
) | (1<<MD_DISK_SYNC
);
1569 if (!devices
[j
].uptodate
)
1572 devices
[j
].i
.disk
.state
= desired_state
;
1573 if (!(devices
[j
].i
.array
.state
& 1))
1576 if (st
->ss
->update_super(st
, &devices
[j
].i
, "assemble", NULL
,
1577 c
->verbose
, 0, NULL
)) {
1579 if (c
->verbose
>= 0)
1580 pr_err("clearing FAULTY flag for device %d in %s for %s\n",
1581 j
, mddev
, devices
[j
].devname
);
1584 if (c
->verbose
>= -1)
1585 pr_err("device %d in %s has wrong state in superblock, but %s seems ok\n",
1586 i
, mddev
, devices
[j
].devname
);
1590 if (!(super
.disks
[i
].i
.disk
.state
& (1 << MD_DISK_FAULTY
))) {
1591 pr_err("devices %d of %s is not marked FAULTY in superblock, but cannot be found\n",
1596 if (c
->force
&& !clean
&&
1597 !enough(content
->array
.level
, content
->array
.raid_disks
,
1598 content
->array
.layout
, clean
,
1600 change
+= st
->ss
->update_super(st
, content
, "force-array",
1601 devices
[chosen_drive
].devname
, c
->verbose
,
1609 fd
= dev_open(devices
[chosen_drive
].devname
,
1610 devices
[chosen_drive
].included
?
1611 O_RDWR
: (O_RDWR
|O_EXCL
));
1613 pr_err("Could not open %s for write - cannot Assemble array.\n",
1614 devices
[chosen_drive
].devname
);
1619 if (st
->ss
->store_super(st
, fd
)) {
1621 pr_err("Could not re-write superblock on %s\n",
1622 devices
[chosen_drive
].devname
);
1627 if (c
->verbose
>= 0)
1628 pr_err("Marking array %s as 'clean'\n",
1633 /* If we are in the middle of a reshape we may need to restore saved data
1634 * that was moved aside due to the reshape overwriting live data
1635 * The code of doing this lives in Grow.c
1638 if (content
->reshape_active
&&
1639 !(content
->reshape_active
& RESHAPE_NO_BACKUP
)) {
1641 int *fdlist
= xmalloc(sizeof(int)* bestcnt
);
1643 pr_err(":%s has an active reshape - checking "
1644 "if critical section needs to be restored\n",
1646 enable_fds(bestcnt
/2);
1647 for (i
= 0; i
< bestcnt
/2; i
++) {
1650 fdlist
[i
] = dev_open(devices
[j
].devname
,
1652 ? O_RDWR
: (O_RDWR
|O_EXCL
));
1653 if (fdlist
[i
] < 0) {
1654 pr_err("Could not open %s for write - cannot Assemble array.\n",
1655 devices
[j
].devname
);
1663 if (st
->ss
->external
&& st
->ss
->recover_backup
)
1664 err
= st
->ss
->recover_backup(st
, content
);
1666 err
= Grow_restart(st
, content
, fdlist
, bestcnt
/2,
1667 c
->backup_file
, c
->verbose
> 0);
1668 if (err
&& c
->invalid_backup
) {
1671 " without restoring backup\n");
1677 if (fdlist
[i
]>=0) close(fdlist
[i
]);
1681 pr_err("Failed to restore critical section for reshape, sorry.\n");
1682 if (c
->backup_file
== NULL
)
1683 cont_err("Possibly you needed to specify the --backup-file\n");
1691 /* Almost ready to actually *do* something */
1692 /* First, fill in the map, so that udev can find our name
1693 * as soon as we become active.
1695 if (c
->update
&& strcmp(c
->update
, "metadata")==0) {
1696 content
->array
.major_version
= 1;
1697 content
->array
.minor_version
= 0;
1698 strcpy(content
->text_version
, "1.0");
1701 map_update(&map
, fd2devnm(mdfd
), content
->text_version
,
1702 content
->uuid
, chosen_name
);
1704 rv
= start_array(mdfd
, mddev
, content
,
1705 st
, ident
, best
, bestcnt
,
1706 chosen_drive
, devices
, okcnt
, sparecnt
,
1709 clean
, avail
, start_partial_ok
,
1712 if (rv
== 1 && !pre_exist
)
1713 ioctl(mdfd
, STOP_ARRAY
, NULL
);
1717 wait_for(chosen_name
, mdfd
);
1721 /* There is a nasty race with 'mdadm --monitor'.
1722 * If it opens this device before we close it,
1723 * it gets an incomplete open on which IO
1724 * doesn't work and the capacity is
1726 * If we reopen (to check for layered devices)
1727 * before --monitor closes, we loose.
1729 * So: wait upto 1 second for there to be
1730 * a non-zero capacity.
1732 while (usecs
< 1000) {
1733 mdfd
= open(mddev
, O_RDONLY
);
1735 unsigned long long size
;
1736 if (get_dev_size(mdfd
, NULL
, &size
) &&
1748 /* '2' means 'OK, but not started yet' */
1749 return rv
== 2 ? 0 : rv
;
1753 int assemble_container_content(struct supertype
*st
, int mdfd
,
1754 struct mdinfo
*content
, struct context
*c
,
1757 struct mdinfo
*dev
, *sra
;
1758 int working
= 0, preexist
= 0;
1760 struct map_ent
*map
= NULL
;
1764 sysfs_init(content
, mdfd
, NULL
);
1766 sra
= sysfs_read(mdfd
, NULL
, GET_VERSION
);
1767 if (sra
== NULL
|| strcmp(sra
->text_version
, content
->text_version
) != 0) {
1768 if (content
->array
.major_version
== -1 &&
1769 content
->array
.minor_version
== -2 &&
1771 content
->text_version
[0] == '/')
1772 content
->text_version
[0] = '-';
1773 if (sysfs_set_array(content
, md_get_version(mdfd
)) != 0) {
1780 /* There are two types of reshape: container wide or sub-array specific
1781 * Check if metadata requests blocking container wide reshapes
1783 start_reshape
= (content
->reshape_active
&&
1784 !((content
->reshape_active
== CONTAINER_RESHAPE
) &&
1785 (content
->array
.state
& (1<<MD_SB_BLOCK_CONTAINER_RESHAPE
))));
1787 /* Block subarray here if it is under reshape now
1788 * Do not allow for any changes in this array
1790 if (st
->ss
->external
&& content
->recovery_blocked
&& start_reshape
)
1791 block_subarray(content
);
1795 old_raid_disks
= content
->array
.raid_disks
- content
->delta_disks
;
1796 for (dev
= content
->devs
; dev
; dev
= dev
->next
)
1797 if (sysfs_add_disk(content
, dev
, 1) == 0) {
1798 if (dev
->disk
.raid_disk
>= old_raid_disks
&&
1799 content
->reshape_active
)
1803 } else if (errno
== EEXIST
)
1805 if (working
+ expansion
== 0)
1806 return 1;/* Nothing new, don't try to start */
1808 map_update(&map
, fd2devnm(mdfd
),
1809 content
->text_version
,
1810 content
->uuid
, chosen_name
);
1812 if (c
->runstop
> 0 ||
1813 (working
+ preexist
+ expansion
) >=
1814 content
->array
.working_disks
) {
1817 if (start_reshape
) {
1818 int spare
= content
->array
.raid_disks
+ expansion
;
1819 if (restore_backup(st
, content
,
1821 spare
, c
->backup_file
, c
->verbose
) == 1)
1824 err
= sysfs_set_str(content
, NULL
,
1825 "array_state", "readonly");
1829 if (st
->ss
->external
) {
1830 if (!mdmon_running(st
->container_devnm
))
1831 start_mdmon(st
->container_devnm
);
1832 ping_monitor(st
->container_devnm
);
1833 if (mdmon_running(st
->container_devnm
) &&
1834 st
->update_tail
== NULL
)
1835 st
->update_tail
= &st
->updates
;
1838 err
= Grow_continue(mdfd
, st
, content
, c
->backup_file
,
1840 } else switch(content
->array
.level
) {
1842 case LEVEL_MULTIPATH
:
1844 err
= sysfs_set_str(content
, NULL
, "array_state",
1845 c
->readonly
? "readonly" : "active");
1848 err
= sysfs_set_str(content
, NULL
, "array_state",
1850 /* start mdmon if needed. */
1852 if (!mdmon_running(st
->container_devnm
))
1853 start_mdmon(st
->container_devnm
);
1854 ping_monitor(st
->container_devnm
);
1859 sysfs_set_safemode(content
, content
->safe_mode_delay
);
1861 /* Block subarray here if it is not reshaped now
1862 * It has be blocked a little later to allow mdmon to switch in
1865 if (st
->ss
->external
&& content
->recovery_blocked
&&
1867 block_subarray(content
);
1869 if (c
->verbose
>= 0) {
1871 pr_err("array %s now has %d device%s",
1872 chosen_name
, working
+ preexist
,
1873 working
+ preexist
== 1 ? "":"s");
1875 pr_err("Started %s with %d device%s",
1876 chosen_name
, working
+ preexist
,
1877 working
+ preexist
== 1 ? "":"s");
1879 fprintf(stderr
, " (%d new)", working
);
1881 fprintf(stderr
, " ( + %d for expansion)",
1883 fprintf(stderr
, "\n");
1886 wait_for(chosen_name
, mdfd
);
1888 /* FIXME should have an O_EXCL and wait for read-auto */
1890 if (c
->verbose
>= 0) {
1891 pr_err("%s assembled with %d device%s",
1892 chosen_name
, preexist
+ working
,
1893 preexist
+ working
== 1 ? "":"s");
1895 fprintf(stderr
, " (%d new)", working
);
1896 fprintf(stderr
, " but not started\n");