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 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
)
139 struct mddev_dev
*tmpdev
;
141 struct supertype
*st
= *stp
;
142 struct mdinfo
*content
= NULL
;
143 int report_missmatch
= ((inargv
&& c
->verbose
>= 0) || c
->verbose
> 0);
144 struct domainlist
*domains
= NULL
;
146 tmpdev
= devlist
; num_devs
= 0;
152 tmpdev
->disposition
= 0;
153 tmpdev
= tmpdev
->next
;
156 /* first walk the list of devices to find a consistent set
157 * that match the criterea, if that is possible.
158 * We flag the ones we like with 'used'.
160 for (tmpdev
= devlist
;
162 tmpdev
= tmpdev
? tmpdev
->next
: NULL
) {
163 char *devname
= tmpdev
->devname
;
166 struct supertype
*tst
;
167 struct dev_policy
*pol
= NULL
;
168 int found_container
= 0;
170 if (tmpdev
->used
> 1)
173 if (ident
->devices
&&
174 !match_oneof(ident
->devices
, devname
)) {
175 if (report_missmatch
)
176 pr_err("%s is not one of %s\n", devname
, ident
->devices
);
182 dfd
= dev_open(devname
, O_RDONLY
);
184 if (report_missmatch
)
185 pr_err("cannot open device %s: %s\n",
186 devname
, strerror(errno
));
188 } else if (fstat(dfd
, &stb
)< 0) {
190 pr_err("fstat failed for %s: %s\n",
191 devname
, strerror(errno
));
193 } else if ((stb
.st_mode
& S_IFMT
) != S_IFBLK
) {
194 pr_err("%s is not a block device.\n",
197 } else if (must_be_container(dfd
)) {
199 /* already found some components, this cannot
202 if (report_missmatch
)
203 pr_err("%s is a container, but we are looking for components\n",
206 #if !defined(MDASSEMBLE) || defined(MDASSEMBLE) && defined(MDASSEMBLE_AUTO)
207 } if (!tst
&& (tst
= super_by_fd(dfd
, NULL
)) == NULL
) {
208 if (report_missmatch
)
209 pr_err("not a recognisable container: %s\n",
213 } else if (!tst
->ss
->load_container
214 || tst
->ss
->load_container(tst
, dfd
, NULL
)) {
215 if (report_missmatch
)
216 pr_err("no correct container type: %s\n",
219 } else if (auto_assem
&&
220 !conf_test_metadata(tst
->ss
->name
, (pol
= devnum_policy(stb
.st_rdev
)),
221 tst
->ss
->match_home(tst
, c
->homehost
) == 1)) {
222 if (report_missmatch
)
223 pr_err("%s has metadata type %s for which "
224 "auto-assembly is disabled\n",
225 devname
, tst
->ss
->name
);
230 if (!tst
&& (tst
= guess_super(dfd
)) == NULL
) {
231 if (report_missmatch
)
232 pr_err("no recogniseable superblock on %s\n",
235 } else if (tst
->ss
->load_super(tst
,dfd
, NULL
)) {
236 if (report_missmatch
)
237 pr_err("no RAID superblock on %s\n",
240 } else if (tst
->ss
->compare_super
== NULL
) {
241 if (report_missmatch
)
242 pr_err("Cannot assemble %s metadata on %s\n",
243 tst
->ss
->name
, devname
);
245 } else if (auto_assem
&& st
== NULL
&&
246 !conf_test_metadata(tst
->ss
->name
, (pol
= devnum_policy(stb
.st_rdev
)),
247 tst
->ss
->match_home(tst
, c
->homehost
) == 1)) {
248 if (report_missmatch
)
249 pr_err("%s has metadata type %s for which "
250 "auto-assembly is disabled\n",
251 devname
, tst
->ss
->name
);
255 if (dfd
>= 0) close(dfd
);
256 if (tmpdev
->used
== 2) {
257 if (auto_assem
|| !inargv
)
258 /* Ignore unrecognised devices during auto-assembly */
260 if (ident
->uuid_set
|| ident
->name
[0] ||
261 ident
->super_minor
!= UnSet
)
262 /* Ignore unrecognised device if looking for
266 pr_err("%s has no superblock - assembly aborted\n",
269 st
->ss
->free_super(st
);
270 dev_policy_free(pol
);
271 domain_free(domains
);
275 if (found_container
) {
276 /* tmpdev is a container. We need to be either
277 * looking for a member, or auto-assembling
279 /* should be safe to try an exclusive open now, we
280 * have rejected anything that some other mdadm might
283 dfd
= dev_open(devname
, O_RDONLY
| O_EXCL
);
285 if (report_missmatch
)
286 pr_err("%s is busy - skipping\n", devname
);
291 if (ident
->container
) {
292 if (ident
->container
[0] == '/' &&
293 !same_dev(ident
->container
, devname
)) {
294 if (report_missmatch
)
295 pr_err("%s is not the container required (%s)\n",
296 devname
, ident
->container
);
299 if (ident
->container
[0] != '/') {
304 tst
->ss
->getinfo_super(tst
, content
, NULL
);
306 if (!parse_uuid(ident
->container
, uuid
) ||
307 !same_uuid(content
->uuid
, uuid
, tst
->ss
->swapuuid
)) {
308 if (report_missmatch
)
309 pr_err("%s has wrong UUID to be required container\n",
315 /* It is worth looking inside this container.
318 pr_err("looking in container %s\n",
321 for (content
= tst
->ss
->container_content(tst
, NULL
);
323 content
= content
->next
) {
325 if (!ident_matches(ident
, content
, tst
,
326 c
->homehost
, c
->update
,
327 report_missmatch
? devname
: NULL
))
328 /* message already printed */;
329 else if (is_member_busy(content
->text_version
)) {
330 if (report_missmatch
)
331 pr_err("member %s in %s is already assembled\n",
332 content
->text_version
,
334 } else if (content
->array
.state
& (1<<MD_SB_BLOCK_VOLUME
)) {
335 /* do not assemble arrays with unsupported configurations */
336 pr_err("Cannot activate member %s in %s.\n",
337 content
->text_version
,
344 goto loop
; /* empty container */
347 st
= tst
; tst
= NULL
;
348 if (!auto_assem
&& inargv
&& tmpdev
->next
!= NULL
) {
349 pr_err("%s is a container, but is not "
350 "only device given: confused and aborting\n",
352 st
->ss
->free_super(st
);
353 dev_policy_free(pol
);
354 domain_free(domains
);
358 pr_err("found match on member %s in %s\n",
359 content
->text_version
, devname
);
361 /* make sure we finished the loop */
367 tst
->ss
->getinfo_super(tst
, content
, NULL
);
369 if (!ident_matches(ident
, content
, tst
,
370 c
->homehost
, c
->update
,
371 report_missmatch
? devname
: NULL
))
374 /* should be safe to try an exclusive open now, we
375 * have rejected anything that some other mdadm might
378 dfd
= dev_open(devname
, O_RDONLY
| O_EXCL
);
380 if (report_missmatch
)
381 pr_err("%s is busy - skipping\n", devname
);
388 if (st
->minor_version
== -1)
389 st
->minor_version
= tst
->minor_version
;
391 if (memcmp(content
->uuid
, uuid_zero
,
392 sizeof(int[4])) == 0) {
393 /* this is a floating spare. It cannot define
394 * an array unless there are no more arrays of
395 * this type to be found. It can be included
396 * in an array of this type though.
402 if (st
->ss
!= tst
->ss
||
403 st
->minor_version
!= tst
->minor_version
||
404 st
->ss
->compare_super(st
, tst
) != 0) {
405 /* Some mismatch. If exactly one array matches this host,
406 * we can resolve on that one.
407 * Or, if we are auto assembling, we just ignore the second
413 int first
= st
->ss
->match_home(st
, c
->homehost
);
414 int last
= tst
->ss
->match_home(tst
, c
->homehost
);
416 (first
== 1 || last
== 1)) {
417 /* We can do something */
418 if (first
) {/* just ignore this one */
419 if (report_missmatch
)
420 pr_err("%s misses out due to wrong homehost\n",
423 } else { /* reject all those sofar */
424 struct mddev_dev
*td
;
425 if (report_missmatch
)
426 pr_err("%s overrides previous devices due to good homehost\n",
428 for (td
=devlist
; td
!= tmpdev
; td
=td
->next
)
436 pr_err("superblock on %s doesn't match others - assembly aborted\n",
438 tst
->ss
->free_super(tst
);
439 st
->ss
->free_super(st
);
440 dev_policy_free(pol
);
441 domain_free(domains
);
447 /* Collect domain information from members only */
448 if (tmpdev
&& tmpdev
->used
== 1) {
450 pol
= devnum_policy(stb
.st_rdev
);
451 domain_merge(&domains
, pol
, tst
?tst
->ss
->name
:NULL
);
453 dev_policy_free(pol
);
456 tst
->ss
->free_super(tst
);
459 /* Check if we found some imsm spares but no members */
462 memcmp(uuid_zero
, ident
->uuid
,sizeof(uuid_zero
)) == 0)) &&
464 for (tmpdev
= devlist
; tmpdev
; tmpdev
= tmpdev
->next
) {
465 if (tmpdev
->used
!= 3)
471 /* we need sb from one of the spares */
472 int dfd
= dev_open(tmpdev
->devname
, O_RDONLY
);
474 st
->ss
->load_super(st
, dfd
, NULL
))
481 /* Now reject spares that don't match domains of identified members */
482 for (tmpdev
= devlist
; tmpdev
; tmpdev
= tmpdev
->next
) {
484 if (tmpdev
->used
!= 3)
486 if (stat(tmpdev
->devname
, &stb
)< 0) {
487 pr_err("fstat failed for %s: %s\n",
488 tmpdev
->devname
, strerror(errno
));
491 struct dev_policy
*pol
= devnum_policy(stb
.st_rdev
);
492 int dt
= domain_test(domains
, pol
, NULL
);
493 if (inargv
&& dt
!= 0)
494 /* take this spare as domains match
495 * if there are any */
497 else if (!inargv
&& dt
== 1)
498 /* device wasn't explicitly listed, so need
499 * explicit domain match - which we have */
502 /* if domains don't match mark as unused */
504 dev_policy_free(pol
);
507 domain_free(domains
);
509 if (st
&& st
->sb
&& content
== *contentp
)
510 st
->ss
->getinfo_super(st
, content
, NULL
);
518 int uptodate
; /* set once we decide that this device is as
519 * recent as everything else in the array.
521 int included
; /* set if the device is already in the array
522 * due to a previous '-I'
527 static int load_devices(struct devs
*devices
, char *devmap
,
528 struct mddev_ident
*ident
, struct supertype
*st
,
529 struct mddev_dev
*devlist
, struct context
*c
,
530 struct mdinfo
*content
,
531 int mdfd
, char *mddev
,
532 int *most_recentp
, int *bestcntp
, int **bestp
,
535 struct mddev_dev
*tmpdev
;
545 for (tmpdev
= devlist
; tmpdev
; tmpdev
=tmpdev
->next
) {
546 char *devname
= tmpdev
->devname
;
550 if (tmpdev
->used
!= 1)
552 /* looks like a good enough match to update the super block if needed */
556 /* prepare useful information in info structures */
558 struct supertype
*tst
;
562 if (strcmp(c
->update
, "uuid")==0 &&
565 if ((rfd
= open("/dev/urandom", O_RDONLY
)) < 0 ||
566 read(rfd
, ident
->uuid
, 16) != 16) {
567 *(__u32
*)(ident
->uuid
) = random();
568 *(__u32
*)(ident
->uuid
+1) = random();
569 *(__u32
*)(ident
->uuid
+2) = random();
570 *(__u32
*)(ident
->uuid
+3) = random();
572 if (rfd
>= 0) close(rfd
);
574 dfd
= dev_open(devname
,
575 tmpdev
->disposition
== 'I'
576 ? O_RDWR
: (O_RDWR
|O_EXCL
));
579 if (dfd
< 0 || tst
->ss
->load_super(tst
, dfd
, NULL
) != 0) {
580 pr_err("cannot re-read metadata from %s - aborting\n",
589 tst
->ss
->getinfo_super(tst
, content
, devmap
+ devcnt
* content
->array
.raid_disks
);
591 memcpy(content
->uuid
, ident
->uuid
, 16);
592 strcpy(content
->name
, ident
->name
);
593 content
->array
.md_minor
= minor(stb2
.st_rdev
);
595 if (strcmp(c
->update
, "byteorder") == 0)
598 err
= tst
->ss
->update_super(tst
, content
, c
->update
,
603 pr_err("--update=%s not understood"
604 " for %s metadata\n",
605 c
->update
, tst
->ss
->name
);
606 tst
->ss
->free_super(tst
);
614 if (strcmp(c
->update
, "uuid")==0 &&
617 memcpy(ident
->uuid
, content
->uuid
, 16);
619 if (tst
->ss
->store_super(tst
, dfd
))
620 pr_err("Could not re-write superblock on %s.\n",
624 if (strcmp(c
->update
, "uuid")==0 &&
625 ident
->bitmap_fd
>= 0 && !bitmap_done
) {
626 if (bitmap_update_uuid(ident
->bitmap_fd
,
628 tst
->ss
->swapuuid
) != 0)
629 pr_err("Could not update uuid on external bitmap.\n");
633 tst
->ss
->free_super(tst
);
637 struct supertype
*tst
= dup_super(st
);
639 dfd
= dev_open(devname
,
640 tmpdev
->disposition
== 'I'
641 ? O_RDWR
: (O_RDWR
|O_EXCL
));
643 if (dfd
< 0 || tst
->ss
->load_super(tst
, dfd
, NULL
) != 0) {
644 pr_err("cannot re-read metadata from %s - aborting\n",
653 tst
->ss
->getinfo_super(tst
, content
, devmap
+ devcnt
* content
->array
.raid_disks
);
654 tst
->ss
->free_super(tst
);
661 pr_err("%s is identified as a member of %s, slot %d%s.\n",
662 devname
, mddev
, content
->disk
.raid_disk
,
663 (content
->disk
.state
& (1<<MD_DISK_REPLACEMENT
)) ? " replacement":"");
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
*2)
682 nextspare
= content
->array
.raid_disks
*2;
685 /* i is raid_disk - double it so there is room for
688 if (devices
[devcnt
].i
.disk
.state
& (1<<MD_DISK_REPLACEMENT
))
690 if (i
>= content
->array
.raid_disks
*2 &&
696 int newbestcnt
= i
+10;
697 int *newbest
= xmalloc(sizeof(int)*newbestcnt
);
699 for (c
=0; c
< newbestcnt
; c
++)
701 newbest
[c
] = best
[c
];
706 bestcnt
= newbestcnt
;
709 devices
[best
[i
]].i
.events
710 == devices
[devcnt
].i
.events
711 && (devices
[best
[i
]].i
.disk
.minor
712 != devices
[devcnt
].i
.disk
.minor
)
714 && content
->array
.level
!= LEVEL_MULTIPATH
) {
715 /* two different devices with identical superblock.
716 * Could be a mis-detection caused by overlapping
717 * partitions. fail-safe.
719 pr_err("WARNING %s and %s appear"
720 " to have very similar superblocks.\n"
721 " If they are really different, "
722 "please --zero the superblock on one\n"
723 " If they are the same or overlap,"
724 " please remove one from %s.\n",
725 devices
[best
[i
]].devname
, devname
,
726 inargv
? "the list" :
727 "the\n DEVICE list in mdadm.conf"
735 || (devices
[best
[i
]].i
.events
736 < devices
[devcnt
].i
.events
))
741 *most_recentp
= most_recent
;
747 static int force_array(struct mdinfo
*content
,
748 struct devs
*devices
,
749 int *best
, int bestcnt
, char *avail
,
751 struct supertype
*st
,
755 while (!enough(content
->array
.level
, content
->array
.raid_disks
,
756 content
->array
.layout
, 1,
759 (content
->reshape_active
&& content
->delta_disks
> 0 &&
760 !enough(content
->array
.level
, (content
->array
.raid_disks
761 - content
->delta_disks
),
762 content
->new_layout
, 1,
765 /* Choose the newest best drive which is
766 * not up-to-date, update the superblock
770 struct supertype
*tst
;
771 unsigned long long current_events
;
772 int chosen_drive
= -1;
775 for (i
= 0; i
< content
->array
.raid_disks
&& i
< bestcnt
; i
++) {
778 !devices
[j
].uptodate
&&
779 devices
[j
].i
.recovery_start
== MaxSector
&&
782 > devices
[chosen_drive
].i
.events
))
785 if (chosen_drive
< 0)
787 current_events
= devices
[chosen_drive
].i
.events
;
790 pr_err("forcing event count in %s(%d) from %d upto %d\n",
791 devices
[chosen_drive
].devname
,
792 devices
[chosen_drive
].i
.disk
.raid_disk
,
793 (int)(devices
[chosen_drive
].i
.events
),
794 (int)(devices
[most_recent
].i
.events
));
795 fd
= dev_open(devices
[chosen_drive
].devname
,
796 devices
[chosen_drive
].included
? O_RDWR
799 pr_err("Couldn't open %s for write - not updating\n",
800 devices
[chosen_drive
].devname
);
801 devices
[chosen_drive
].i
.events
= 0;
805 if (tst
->ss
->load_super(tst
,fd
, NULL
)) {
807 pr_err("RAID superblock disappeared from %s - not updating.\n",
808 devices
[chosen_drive
].devname
);
809 devices
[chosen_drive
].i
.events
= 0;
812 content
->events
= devices
[most_recent
].i
.events
;
813 tst
->ss
->update_super(tst
, content
, "force-one",
814 devices
[chosen_drive
].devname
, c
->verbose
,
817 if (tst
->ss
->store_super(tst
, fd
)) {
819 pr_err("Could not re-write superblock on %s\n",
820 devices
[chosen_drive
].devname
);
821 devices
[chosen_drive
].i
.events
= 0;
822 tst
->ss
->free_super(tst
);
826 devices
[chosen_drive
].i
.events
= devices
[most_recent
].i
.events
;
827 devices
[chosen_drive
].uptodate
= 1;
828 avail
[chosen_drive
] = 1;
830 tst
->ss
->free_super(tst
);
832 /* If there are any other drives of the same vintage,
833 * add them in as well. We can't lose and we might gain
835 for (i
= 0; i
< content
->array
.raid_disks
&& i
< bestcnt
; i
++) {
838 !devices
[j
].uptodate
&&
839 devices
[j
].i
.recovery_start
== MaxSector
&&
840 devices
[j
].i
.events
== current_events
) {
849 static int start_array(int mdfd
,
851 struct mdinfo
*content
,
852 struct supertype
*st
,
853 struct mddev_ident
*ident
,
854 int *best
, int bestcnt
,
856 struct devs
*devices
,
858 unsigned int sparecnt
,
859 unsigned int rebuilding_cnt
,
861 int clean
, char *avail
,
867 unsigned int req_cnt
;
869 rv
= set_array_info(mdfd
, st
, content
);
871 pr_err("failed to set array info for %s: %s\n",
872 mddev
, strerror(errno
));
875 if (ident
->bitmap_fd
>= 0) {
876 if (ioctl(mdfd
, SET_BITMAP_FILE
, ident
->bitmap_fd
) != 0) {
877 pr_err("SET_BITMAP_FILE failed.\n");
880 } else if (ident
->bitmap_file
) {
881 /* From config file */
882 int bmfd
= open(ident
->bitmap_file
, O_RDWR
);
884 pr_err("Could not open bitmap file %s\n",
888 if (ioctl(mdfd
, SET_BITMAP_FILE
, bmfd
) != 0) {
889 pr_err("Failed to set bitmapfile for %s\n", mddev
);
896 /* First, add the raid disks, but add the chosen one last */
897 for (i
=0; i
<= bestcnt
; i
++) {
901 if (j
== chosen_drive
)
906 if (j
>= 0 && !devices
[j
].included
) {
907 int dfd
= dev_open(devices
[j
].devname
,
910 remove_partitions(dfd
);
913 rv
= add_disk(mdfd
, st
, content
, &devices
[j
].i
);
916 pr_err("failed to add "
921 if (i
< content
->array
.raid_disks
* 2
926 } else if (c
->verbose
> 0)
927 pr_err("added %s to %s as %d%s%s\n",
928 devices
[j
].devname
, mddev
,
929 devices
[j
].i
.disk
.raid_disk
,
930 devices
[j
].uptodate
?"":
931 " (possibly out of date)",
932 (devices
[j
].i
.disk
.state
& (1<<MD_DISK_REPLACEMENT
))?" replacement":"");
935 pr_err("%s is already in %s as %d\n",
936 devices
[j
].devname
, mddev
,
937 devices
[j
].i
.disk
.raid_disk
);
938 } else if (c
->verbose
> 0 && i
< content
->array
.raid_disks
*2
940 pr_err("no uptodate device for slot %d of %s\n",
944 if (content
->array
.level
== LEVEL_CONTAINER
) {
945 if (c
->verbose
>= 0) {
946 pr_err("Container %s has been "
947 "assembled with %d drive%s",
948 mddev
, okcnt
+sparecnt
, okcnt
+sparecnt
==1?"":"s");
949 if (okcnt
< (unsigned)content
->array
.raid_disks
)
950 fprintf(stderr
, " (out of %d)",
951 content
->array
.raid_disks
);
952 fprintf(stderr
, "\n");
954 st
->ss
->free_super(st
);
955 sysfs_uevent(content
, "change");
959 /* Get number of in-sync devices according to the superblock.
960 * We must have this number to start the array without -s or -R
962 req_cnt
= content
->array
.working_disks
;
964 if (c
->runstop
== 1 ||
966 ( enough(content
->array
.level
, content
->array
.raid_disks
,
967 content
->array
.layout
, clean
, avail
) &&
968 (okcnt
+ rebuilding_cnt
>= req_cnt
|| start_partial_ok
)
970 /* This array is good-to-go.
971 * If a reshape is in progress then we might need to
972 * continue monitoring it. In that case we start
973 * it read-only and let the grow code make it writable.
977 if (content
->reshape_active
&&
978 !(content
->reshape_active
& RESHAPE_NO_BACKUP
) &&
979 content
->delta_disks
<= 0) {
980 rv
= sysfs_set_str(content
, NULL
,
981 "array_state", "readonly");
983 rv
= Grow_continue(mdfd
, st
, content
,
986 } else if (c
->readonly
&&
987 sysfs_attribute_available(
988 content
, NULL
, "array_state")) {
989 rv
= sysfs_set_str(content
, NULL
,
990 "array_state", "readonly");
993 rv
= ioctl(mdfd
, RUN_ARRAY
, NULL
);
995 if (c
->verbose
>= 0) {
996 pr_err("%s has been started with %d drive%s",
997 mddev
, okcnt
, okcnt
==1?"":"s");
998 if (okcnt
< (unsigned)content
->array
.raid_disks
)
999 fprintf(stderr
, " (out of %d)", content
->array
.raid_disks
);
1001 fprintf(stderr
, "%s %d rebuilding", sparecnt
?",":" and", rebuilding_cnt
);
1003 fprintf(stderr
, " and %d spare%s", sparecnt
, sparecnt
==1?"":"s");
1004 fprintf(stderr
, ".\n");
1006 if (content
->reshape_active
&&
1007 content
->array
.level
>= 4 &&
1008 content
->array
.level
<= 6) {
1009 /* might need to increase the size
1010 * of the stripe cache - default is 256
1012 if (256 < 4 * (content
->array
.chunk_size
/4096)) {
1013 struct mdinfo
*sra
= sysfs_read(mdfd
, 0, 0);
1015 sysfs_set_num(sra
, NULL
,
1016 "stripe_cache_size",
1017 (4 * content
->array
.chunk_size
/ 4096) + 1);
1021 if (okcnt
< (unsigned)content
->array
.raid_disks
) {
1022 /* If any devices did not get added
1023 * because the kernel rejected them based
1024 * on event count, try adding them
1025 * again providing the action policy is
1026 * 're-add' or greater. The bitmap
1027 * might allow them to be included, or
1028 * they will become spares.
1030 for (i
= 0; i
< bestcnt
; i
++) {
1032 if (j
>= 0 && !devices
[j
].uptodate
) {
1033 if (!disk_action_allows(&devices
[j
].i
, st
->ss
->name
, act_re_add
))
1035 rv
= add_disk(mdfd
, st
, content
,
1037 if (rv
== 0 && c
->verbose
>= 0)
1038 pr_err("%s has been re-added.\n",
1039 devices
[j
].devname
);
1045 pr_err("failed to RUN_ARRAY %s: %s\n",
1046 mddev
, strerror(errno
));
1048 if (!enough(content
->array
.level
, content
->array
.raid_disks
,
1049 content
->array
.layout
, 1, avail
))
1050 pr_err("Not enough devices to "
1051 "start the array.\n");
1052 else if (!enough(content
->array
.level
,
1053 content
->array
.raid_disks
,
1054 content
->array
.layout
, clean
,
1056 pr_err("Not enough devices to "
1057 "start the array while not clean "
1058 "- consider --force.\n");
1062 if (c
->runstop
== -1) {
1063 pr_err("%s assembled from %d drive%s",
1064 mddev
, okcnt
, okcnt
==1?"":"s");
1065 if (okcnt
!= (unsigned)content
->array
.raid_disks
)
1066 fprintf(stderr
, " (out of %d)", content
->array
.raid_disks
);
1067 fprintf(stderr
, ", but not started.\n");
1070 if (c
->verbose
>= -1) {
1071 pr_err("%s assembled from %d drive%s", mddev
, okcnt
, okcnt
==1?"":"s");
1073 fprintf(stderr
, "%s %d rebuilding", sparecnt
?",":" and", rebuilding_cnt
);
1075 fprintf(stderr
, " and %d spare%s", sparecnt
, sparecnt
==1?"":"s");
1076 if (!enough(content
->array
.level
, content
->array
.raid_disks
,
1077 content
->array
.layout
, 1, avail
))
1078 fprintf(stderr
, " - not enough to start the array.\n");
1079 else if (!enough(content
->array
.level
,
1080 content
->array
.raid_disks
,
1081 content
->array
.layout
, clean
,
1083 fprintf(stderr
, " - not enough to start the "
1084 "array while not clean - consider "
1087 if (req_cnt
== (unsigned)content
->array
.raid_disks
)
1088 fprintf(stderr
, " - need all %d to start it", req_cnt
);
1090 fprintf(stderr
, " - need %d to start", req_cnt
);
1091 fprintf(stderr
, " (use --run to insist).\n");
1097 int Assemble(struct supertype
*st
, char *mddev
,
1098 struct mddev_ident
*ident
,
1099 struct mddev_dev
*devlist
,
1103 * The task of Assemble is to find a collection of
1104 * devices that should (according to their superblocks)
1105 * form an array, and to give this collection to the MD driver.
1106 * In Linux-2.4 and later, this involves submitting a
1107 * SET_ARRAY_INFO ioctl with no arg - to prepare
1108 * the array - and then submit a number of
1109 * ADD_NEW_DISK ioctls to add disks into
1110 * the array. Finally RUN_ARRAY might
1111 * be submitted to start the array.
1113 * Much of the work of Assemble is in finding and/or
1114 * checking the disks to make sure they look right.
1116 * If mddev is not set, then scan must be set and we
1117 * read through the config file for dev+uuid mapping
1118 * We recurse, setting mddev, for each device that
1120 * - has a valid uuid (or any uuid if !uuidset)
1122 * If mddev is set, we try to determine state of md.
1123 * check version - must be at least 0.90.0
1124 * check kernel version. must be at least 2.4.
1125 * If not, we can possibly fall back on START_ARRAY
1126 * Try to GET_ARRAY_INFO.
1127 * If possible, give up
1128 * If not, try to STOP_ARRAY just to make sure
1130 * If !uuidset and scan, look in conf-file for uuid
1131 * If not found, give up
1132 * If !devlist and scan and uuidset, get list of devs from conf-file
1135 * Check superblock - discard if bad
1136 * Check uuid (set if we don't have one) - discard if no match
1137 * Check superblock similarity if we have a superblock - discard if different
1138 * Record events, devicenum
1139 * This should give us a list of devices for the array
1140 * We should collect the most recent event number
1142 * Count disks with recent enough event count
1143 * While force && !enough disks
1144 * Choose newest rejected disks, update event count
1145 * mark clean and rewrite superblock
1148 * foreach device with recent events : ADD_NEW_DISK
1149 * if runstop == 1 || "enough" disks and runstop==0 -> RUN_ARRAY
1151 * Check the device numbers in superblock are right
1152 * update superblock if any changes
1159 int auto_assem
= (mddev
== NULL
&& !ident
->uuid_set
&&
1160 ident
->super_minor
== UnSet
&& ident
->name
[0] == 0
1161 && (ident
->container
== NULL
|| ident
->member
== NULL
));
1162 struct devs
*devices
;
1164 int *best
= NULL
; /* indexed by raid_disk */
1167 unsigned int okcnt
, sparecnt
, rebuilding_cnt
, replcnt
;
1169 int most_recent
= 0;
1173 int start_partial_ok
= (c
->runstop
>= 0) &&
1174 (c
->force
|| devlist
==NULL
|| auto_assem
);
1176 struct mddev_dev
*tmpdev
;
1178 struct mdinfo
*content
= NULL
;
1179 struct mdinfo
*pre_exist
= NULL
;
1182 char chosen_name
[1024];
1183 struct map_ent
*map
= NULL
;
1187 * If any subdevs are listed, then any that don't
1188 * match ident are discarded. Remainder must all match and
1190 * If no subdevs, then we scan all devices in the config file, but
1191 * there must be something in the identity
1195 ident
->uuid_set
== 0 &&
1196 (ident
->super_minor
< 0 || ident
->super_minor
== UnSet
) &&
1197 ident
->name
[0] == 0 &&
1198 (ident
->container
== NULL
|| ident
->member
== NULL
) &&
1199 ident
->devices
== NULL
) {
1200 pr_err("No identity information available for %s - cannot assemble.\n",
1201 mddev
? mddev
: "further assembly");
1205 if (devlist
== NULL
)
1206 devlist
= conf_get_devs();
1211 /* We come back here when doing auto-assembly and attempting some
1212 * set of devices failed. Those are now marked as ->used==2 and
1213 * we ignore them and try again
1215 if (!st
&& ident
->st
)
1218 pr_err("looking for devices for %s\n",
1219 mddev
? mddev
: "further assembly");
1223 st
->ignore_hw_compat
= 1;
1224 num_devs
= select_devices(devlist
, ident
, &st
, &content
, c
,
1225 inargv
, auto_assem
);
1229 if (!st
|| !st
->sb
|| !content
)
1232 /* We have a full set of devices - we now need to find the
1234 * However there is a risk that we are racing with "mdadm -I"
1235 * and the array is already partially assembled - we will have
1236 * rejected any devices already in this address.
1237 * So we take a lock on the map file - to prevent further races -
1238 * and look for the uuid in there. If found and the array is
1239 * active, we abort. If found and the array is not active
1240 * we commit to that md device and add all the contained devices
1241 * to our list. We flag them so that we don't try to re-add,
1242 * but can remove if they turn out to not be wanted.
1245 pr_err("failed to get exclusive lock on mapfile - continue anyway...\n");
1246 mp
= map_by_uuid(&map
, content
->uuid
);
1249 /* array already exists. */
1250 pre_exist
= sysfs_read(-1, mp
->devnum
, GET_LEVEL
|GET_DEVS
);
1251 if (pre_exist
->array
.level
!= UnSet
) {
1252 pr_err("Found some drive for an array that is already active: %s\n",
1254 pr_err("giving up.\n");
1257 for (dv
= pre_exist
->devs
; dv
; dv
= dv
->next
) {
1258 /* We want to add this device to our list,
1259 * but it could already be there if "mdadm -I"
1260 * started *after* we checked for O_EXCL.
1261 * If we add it to the top of the list
1262 * it will be preferred over later copies.
1264 struct mddev_dev
*newdev
;
1265 char *devname
= map_dev(dv
->disk
.major
,
1270 newdev
= xmalloc(sizeof(*newdev
));
1271 newdev
->devname
= devname
;
1272 newdev
->disposition
= 'I';
1274 newdev
->next
= devlist
;
1278 strcpy(chosen_name
, mp
->path
);
1279 if (c
->verbose
> 0 || mddev
== NULL
||
1280 strcmp(mddev
, chosen_name
) != 0)
1281 pr_err("Merging with already-assembled %s\n",
1283 mdfd
= open_dev_excl(mp
->devnum
);
1285 int trustworthy
= FOREIGN
;
1286 name
= content
->name
;
1287 switch (st
->ss
->match_home(st
, c
->homehost
)
1288 ?: st
->ss
->match_home(st
, "any")) {
1290 trustworthy
= LOCAL
;
1291 name
= strchr(content
->name
, ':');
1295 name
= content
->name
;
1299 /* If the array is listed in mdadm.conf or on
1300 * command line, then we trust the name
1301 * even if the array doesn't look local
1303 trustworthy
= LOCAL
;
1306 content
->array
.level
== LEVEL_CONTAINER
) {
1307 name
= content
->text_version
;
1308 trustworthy
= METADATA
;
1311 if (name
[0] && trustworthy
!= LOCAL
&&
1312 ! c
->require_homehost
&&
1313 conf_name_is_free(name
))
1314 trustworthy
= LOCAL
;
1316 if (trustworthy
== LOCAL
&&
1318 /* Ignore 'host:' prefix of name */
1319 name
= strchr(name
, ':')+1;
1321 mdfd
= create_mddev(mddev
, name
, ident
->autof
, trustworthy
,
1325 st
->ss
->free_super(st
);
1330 mddev
= chosen_name
;
1331 if (get_linux_version() < 2004000 ||
1332 md_get_version(mdfd
) < 9000) {
1333 pr_err("Assemble requires Linux 2.4 or later, and\n"
1334 " md driver version 0.90.0 or later.\n"
1335 " Upgrade your kernel or try --build\n");
1339 if (pre_exist
== NULL
) {
1340 if (mddev_busy(fd2devnum(mdfd
))) {
1341 pr_err("%s already active, cannot restart it!\n",
1343 for (tmpdev
= devlist
;
1344 tmpdev
&& tmpdev
->used
!= 1;
1345 tmpdev
= tmpdev
->next
)
1347 if (tmpdev
&& auto_assem
)
1348 pr_err("%s needed for %s...\n",
1349 mddev
, tmpdev
->devname
);
1352 st
->ss
->free_super(st
);
1357 /* just incase it was started but has no content */
1358 ioctl(mdfd
, STOP_ARRAY
, NULL
);
1362 if (content
!= &info
) {
1363 /* This is a member of a container. Try starting the array. */
1365 err
= assemble_container_content(st
, mdfd
, content
, c
,
1371 /* Ok, no bad inconsistancy, we can try updating etc */
1372 devices
= xcalloc(num_devs
, sizeof(*devices
));
1373 devmap
= xcalloc(num_devs
, content
->array
.raid_disks
);
1374 devcnt
= load_devices(devices
, devmap
, ident
, st
, devlist
,
1375 c
, content
, mdfd
, mddev
,
1376 &most_recent
, &bestcnt
, &best
, inargv
);
1381 pr_err("no devices found for %s\n",
1384 st
->ss
->free_super(st
);
1391 if (c
->update
&& strcmp(c
->update
, "byteorder")==0)
1392 st
->minor_version
= 90;
1394 st
->ss
->getinfo_super(st
, content
, NULL
);
1395 clean
= content
->array
.state
& 1;
1397 /* now we have some devices that might be suitable.
1400 avail
= xcalloc(content
->array
.raid_disks
, 1);
1405 for (i
=0; i
< bestcnt
; i
++) {
1407 int event_margin
= 1; /* always allow a difference of '1'
1408 * like the kernel does
1410 if (j
< 0) continue;
1411 /* note: we ignore error flags in multipath arrays
1412 * as they don't make sense
1414 if (content
->array
.level
!= LEVEL_MULTIPATH
)
1415 if (!(devices
[j
].i
.disk
.state
& (1<<MD_DISK_ACTIVE
))) {
1416 if (!(devices
[j
].i
.disk
.state
1417 & (1<<MD_DISK_FAULTY
))) {
1418 devices
[j
].uptodate
= 1;
1423 /* If this device thinks that 'most_recent' has failed, then
1424 * we must reject this device.
1426 if (j
!= most_recent
&&
1427 content
->array
.raid_disks
> 0 &&
1428 devices
[most_recent
].i
.disk
.raid_disk
>= 0 &&
1429 devmap
[j
* content
->array
.raid_disks
+ devices
[most_recent
].i
.disk
.raid_disk
] == 0) {
1430 if (c
->verbose
> -1)
1431 pr_err("ignoring %s as it reports %s as failed\n",
1432 devices
[j
].devname
, devices
[most_recent
].devname
);
1436 if (devices
[j
].i
.events
+event_margin
>=
1437 devices
[most_recent
].i
.events
) {
1438 devices
[j
].uptodate
= 1;
1439 if (i
< content
->array
.raid_disks
* 2) {
1440 if (devices
[j
].i
.recovery_start
== MaxSector
||
1441 (content
->reshape_active
&&
1442 ((i
>= content
->array
.raid_disks
- content
->delta_disks
) ||
1443 (i
>= content
->array
.raid_disks
- content
->delta_disks
- 1
1444 && content
->array
.level
== 4)))) {
1458 okcnt
+= force_array(content
, devices
, best
, bestcnt
,
1459 avail
, most_recent
, st
, c
);
1461 /* Now we want to look at the superblock which the kernel will base things on
1462 * and compare the devices that we think are working with the devices that the
1463 * superblock thinks are working.
1464 * If there are differences and --force is given, then update this chosen
1468 st
->ss
->free_super(st
);
1469 for (i
=0; chosen_drive
< 0 && i
<bestcnt
; i
++) {
1475 if (!devices
[j
].uptodate
)
1477 if (devices
[j
].i
.events
< devices
[most_recent
].i
.events
)
1480 if ((fd
=dev_open(devices
[j
].devname
,
1481 devices
[j
].included
? O_RDONLY
1482 : (O_RDONLY
|O_EXCL
)))< 0) {
1483 pr_err("Cannot open %s: %s\n",
1484 devices
[j
].devname
, strerror(errno
));
1489 if (st
->ss
->load_super(st
,fd
, NULL
)) {
1491 pr_err("RAID superblock has disappeared from %s\n",
1492 devices
[j
].devname
);
1499 if (st
->sb
== NULL
) {
1500 pr_err("No suitable drives found for %s\n", mddev
);
1505 st
->ss
->getinfo_super(st
, content
, NULL
);
1507 sysfs_init(content
, mdfd
, 0);
1509 for (i
=0; i
<bestcnt
; i
++) {
1511 unsigned int desired_state
;
1513 if (i
>= content
->array
.raid_disks
* 2)
1516 desired_state
= (1<<MD_DISK_ACTIVE
) | (1<<MD_DISK_REPLACEMENT
);
1518 desired_state
= (1<<MD_DISK_ACTIVE
) | (1<<MD_DISK_SYNC
);
1522 if (!devices
[j
].uptodate
)
1525 devices
[j
].i
.disk
.state
= desired_state
;
1526 if (!(devices
[j
].i
.array
.state
& 1))
1529 if (st
->ss
->update_super(st
, &devices
[j
].i
, "assemble", NULL
,
1530 c
->verbose
, 0, NULL
)) {
1532 if (c
->verbose
>= 0)
1533 pr_err("clearing FAULTY flag for device %d in %s for %s\n",
1534 j
, mddev
, devices
[j
].devname
);
1537 if (c
->verbose
>= -1)
1538 pr_err("device %d in %s has wrong state in superblock, but %s seems ok\n",
1539 i
, mddev
, devices
[j
].devname
);
1543 if (!(super
.disks
[i
].i
.disk
.state
& (1 << MD_DISK_FAULTY
))) {
1544 pr_err("devices %d of %s is not marked FAULTY in superblock, but cannot be found\n",
1549 if (c
->force
&& !clean
&&
1550 !enough(content
->array
.level
, content
->array
.raid_disks
,
1551 content
->array
.layout
, clean
,
1553 change
+= st
->ss
->update_super(st
, content
, "force-array",
1554 devices
[chosen_drive
].devname
, c
->verbose
,
1561 fd
= dev_open(devices
[chosen_drive
].devname
,
1562 devices
[chosen_drive
].included
?
1563 O_RDWR
: (O_RDWR
|O_EXCL
));
1565 pr_err("Could not open %s for write - cannot Assemble array.\n",
1566 devices
[chosen_drive
].devname
);
1571 if (st
->ss
->store_super(st
, fd
)) {
1573 pr_err("Could not re-write superblock on %s\n",
1574 devices
[chosen_drive
].devname
);
1579 if (c
->verbose
>= 0)
1580 pr_err("Marking array %s as 'clean'\n",
1585 /* If we are in the middle of a reshape we may need to restore saved data
1586 * that was moved aside due to the reshape overwriting live data
1587 * The code of doing this lives in Grow.c
1590 if (content
->reshape_active
&&
1591 !(content
->reshape_active
& RESHAPE_NO_BACKUP
)) {
1593 int *fdlist
= xmalloc(sizeof(int)* bestcnt
);
1595 pr_err(":%s has an active reshape - checking "
1596 "if critical section needs to be restored\n",
1598 for (i
= 0; i
< bestcnt
/2; i
++) {
1601 fdlist
[i
] = dev_open(devices
[j
].devname
,
1603 ? O_RDWR
: (O_RDWR
|O_EXCL
));
1604 if (fdlist
[i
] < 0) {
1605 pr_err("Could not open %s for write - cannot Assemble array.\n",
1606 devices
[j
].devname
);
1614 if (st
->ss
->external
&& st
->ss
->recover_backup
)
1615 err
= st
->ss
->recover_backup(st
, content
);
1617 err
= Grow_restart(st
, content
, fdlist
, bestcnt
/2,
1618 c
->backup_file
, c
->verbose
> 0);
1619 if (err
&& c
->invalid_backup
) {
1622 " without restoring backup\n");
1628 if (fdlist
[i
]>=0) close(fdlist
[i
]);
1632 pr_err("Failed to restore critical section for reshape, sorry.\n");
1633 if (c
->backup_file
== NULL
)
1634 cont_err("Possibly you needed to specify the --backup-file\n");
1642 /* Almost ready to actually *do* something */
1643 /* First, fill in the map, so that udev can find our name
1644 * as soon as we become active.
1646 map_update(&map
, fd2devnum(mdfd
), content
->text_version
,
1647 content
->uuid
, chosen_name
);
1649 rv
= start_array(mdfd
, mddev
, content
,
1650 st
, ident
, best
, bestcnt
,
1651 chosen_drive
, devices
, okcnt
, sparecnt
,
1654 clean
, avail
, start_partial_ok
);
1655 if (rv
== 1 && !pre_exist
)
1656 ioctl(mdfd
, STOP_ARRAY
, NULL
);
1660 wait_for(chosen_name
, mdfd
);
1664 /* There is a nasty race with 'mdadm --monitor'.
1665 * If it opens this device before we close it,
1666 * it gets an incomplete open on which IO
1667 * doesn't work and the capacity is
1669 * If we reopen (to check for layered devices)
1670 * before --monitor closes, we loose.
1672 * So: wait upto 1 second for there to be
1673 * a non-zero capacity.
1675 while (usecs
< 1000) {
1676 mdfd
= open(mddev
, O_RDONLY
);
1678 unsigned long long size
;
1679 if (get_dev_size(mdfd
, NULL
, &size
) &&
1691 /* '2' means 'OK, but not started yet' */
1692 return rv
== 2 ? 0 : rv
;
1696 int assemble_container_content(struct supertype
*st
, int mdfd
,
1697 struct mdinfo
*content
, struct context
*c
,
1700 struct mdinfo
*dev
, *sra
;
1701 int working
= 0, preexist
= 0;
1703 struct map_ent
*map
= NULL
;
1707 sysfs_init(content
, mdfd
, 0);
1709 sra
= sysfs_read(mdfd
, 0, GET_VERSION
);
1710 if (sra
== NULL
|| strcmp(sra
->text_version
, content
->text_version
) != 0) {
1711 if (content
->array
.major_version
== -1 &&
1712 content
->array
.minor_version
== -2 &&
1714 content
->text_version
[0] == '/')
1715 content
->text_version
[0] = '-';
1716 if (sysfs_set_array(content
, md_get_version(mdfd
)) != 0) {
1723 /* There are two types of reshape: container wide or sub-array specific
1724 * Check if metadata requests blocking container wide reshapes
1726 start_reshape
= (content
->reshape_active
&&
1727 !((content
->reshape_active
== CONTAINER_RESHAPE
) &&
1728 (content
->array
.state
& (1<<MD_SB_BLOCK_CONTAINER_RESHAPE
))));
1730 /* Block subarray here if it is under reshape now
1731 * Do not allow for any changes in this array
1733 if (st
->ss
->external
&& content
->recovery_blocked
&& start_reshape
)
1734 block_subarray(content
);
1738 old_raid_disks
= content
->array
.raid_disks
- content
->delta_disks
;
1739 for (dev
= content
->devs
; dev
; dev
= dev
->next
)
1740 if (sysfs_add_disk(content
, dev
, 1) == 0) {
1741 if (dev
->disk
.raid_disk
>= old_raid_disks
&&
1742 content
->reshape_active
)
1746 } else if (errno
== EEXIST
)
1748 if (working
+ expansion
== 0)
1749 return 1;/* Nothing new, don't try to start */
1751 map_update(&map
, fd2devnum(mdfd
),
1752 content
->text_version
,
1753 content
->uuid
, chosen_name
);
1755 if (c
->runstop
> 0 ||
1756 (working
+ preexist
+ expansion
) >=
1757 content
->array
.working_disks
) {
1760 if (start_reshape
) {
1761 int spare
= content
->array
.raid_disks
+ expansion
;
1762 if (restore_backup(st
, content
,
1764 spare
, c
->backup_file
, c
->verbose
) == 1)
1767 err
= sysfs_set_str(content
, NULL
,
1768 "array_state", "readonly");
1772 if (st
->ss
->external
) {
1773 if (!mdmon_running(st
->container_dev
))
1774 start_mdmon(st
->container_dev
);
1775 ping_monitor_by_id(st
->container_dev
);
1776 if (mdmon_running(st
->container_dev
) &&
1777 st
->update_tail
== NULL
)
1778 st
->update_tail
= &st
->updates
;
1781 err
= Grow_continue(mdfd
, st
, content
, c
->backup_file
,
1783 } else switch(content
->array
.level
) {
1785 case LEVEL_MULTIPATH
:
1787 err
= sysfs_set_str(content
, NULL
, "array_state",
1788 c
->readonly
? "readonly" : "active");
1791 err
= sysfs_set_str(content
, NULL
, "array_state",
1793 /* start mdmon if needed. */
1795 if (!mdmon_running(st
->container_dev
))
1796 start_mdmon(st
->container_dev
);
1797 ping_monitor_by_id(st
->container_dev
);
1802 sysfs_set_safemode(content
, content
->safe_mode_delay
);
1804 /* Block subarray here if it is not reshaped now
1805 * It has be blocked a little later to allow mdmon to switch in
1808 if (st
->ss
->external
&& content
->recovery_blocked
&&
1810 block_subarray(content
);
1812 if (c
->verbose
>= 0) {
1814 pr_err("array %s now has %d device%s",
1815 chosen_name
, working
+ preexist
,
1816 working
+ preexist
== 1 ? "":"s");
1818 pr_err("Started %s with %d device%s",
1819 chosen_name
, working
+ preexist
,
1820 working
+ preexist
== 1 ? "":"s");
1822 fprintf(stderr
, " (%d new)", working
);
1824 fprintf(stderr
, " ( + %d for expansion)",
1826 fprintf(stderr
, "\n");
1829 wait_for(chosen_name
, mdfd
);
1831 /* FIXME should have an O_EXCL and wait for read-auto */
1833 if (c
->verbose
>= 0) {
1834 pr_err("%s assembled with %d device%s",
1835 chosen_name
, preexist
+ working
,
1836 preexist
+ working
== 1 ? "":"s");
1838 fprintf(stderr
, " (%d new)", working
);
1839 fprintf(stderr
, " but not started\n");