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_mismatch
= ((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
)) {
176 pr_err("%s is not one of %s\n", devname
, ident
->devices
);
182 dfd
= dev_open(devname
, O_RDONLY
);
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
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
) {
209 pr_err("not a recognisable container: %s\n",
213 } else if (!tst
->ss
->load_container
214 || tst
->ss
->load_container(tst
, dfd
, NULL
)) {
216 pr_err("no correct container type: %s\n",
219 } else if (auto_assem
&&
220 !conf_test_metadata(tst
->ss
->name
, (pol
= devid_policy(stb
.st_rdev
)),
221 tst
->ss
->match_home(tst
, c
->homehost
) == 1)) {
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
) {
232 pr_err("no recogniseable superblock on %s\n",
235 } else if (tst
->ss
->load_super(tst
,dfd
, NULL
)) {
237 pr_err("no RAID superblock on %s\n",
240 } else if (tst
->ss
->compare_super
== NULL
) {
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
= devid_policy(stb
.st_rdev
)),
247 tst
->ss
->match_home(tst
, c
->homehost
) == 1)) {
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
);
286 pr_err("%s is busy - skipping\n", devname
);
291 if (ident
->container
) {
292 if (ident
->container
[0] == '/' &&
293 !same_dev(ident
->container
, devname
)) {
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
)) {
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_mismatch
? devname
: NULL
))
328 /* message already printed */;
329 else if (is_member_busy(content
->text_version
)) {
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 */
366 struct mddev_ident
*match
;
369 tst
->ss
->getinfo_super(tst
, content
, NULL
);
371 if (!ident_matches(ident
, content
, tst
,
372 c
->homehost
, c
->update
,
373 report_mismatch
? devname
: NULL
))
376 match
= conf_match(tst
, content
, devname
,
377 report_mismatch
? c
->verbose
: -1,
379 if (!match
&& rv
== 2)
381 if (match
&& match
->devname
&&
382 strcasecmp(match
->devname
, "<ignore>") == 0) {
384 pr_err("%s is a member of an explicitly ignored array\n",
388 if (match
&& !ident_matches(match
, content
, tst
,
389 c
->homehost
, c
->update
,
390 report_mismatch
? devname
: NULL
))
391 /* Array exists in mdadm.conf but some
392 * details don't match, so reject it
396 /* should be safe to try an exclusive open now, we
397 * have rejected anything that some other mdadm might
400 dfd
= dev_open(devname
, O_RDONLY
| O_EXCL
);
403 pr_err("%s is busy - skipping\n", devname
);
410 if (st
->minor_version
== -1)
411 st
->minor_version
= tst
->minor_version
;
413 if (memcmp(content
->uuid
, uuid_zero
,
414 sizeof(int[4])) == 0) {
415 /* this is a floating spare. It cannot define
416 * an array unless there are no more arrays of
417 * this type to be found. It can be included
418 * in an array of this type though.
424 if (st
->ss
!= tst
->ss
||
425 st
->minor_version
!= tst
->minor_version
||
426 st
->ss
->compare_super(st
, tst
) != 0) {
427 /* Some mismatch. If exactly one array matches this host,
428 * we can resolve on that one.
429 * Or, if we are auto assembling, we just ignore the second
435 int first
= st
->ss
->match_home(st
, c
->homehost
);
436 int last
= tst
->ss
->match_home(tst
, c
->homehost
);
438 (first
== 1 || last
== 1)) {
439 /* We can do something */
440 if (first
) {/* just ignore this one */
442 pr_err("%s misses out due to wrong homehost\n",
445 } else { /* reject all those sofar */
446 struct mddev_dev
*td
;
448 pr_err("%s overrides previous devices due to good homehost\n",
450 for (td
=devlist
; td
!= tmpdev
; td
=td
->next
)
458 pr_err("superblock on %s doesn't match others - assembly aborted\n",
460 tst
->ss
->free_super(tst
);
461 st
->ss
->free_super(st
);
462 dev_policy_free(pol
);
463 domain_free(domains
);
469 /* Collect domain information from members only */
470 if (tmpdev
&& tmpdev
->used
== 1) {
472 pol
= devid_policy(stb
.st_rdev
);
473 domain_merge(&domains
, pol
, tst
?tst
->ss
->name
:NULL
);
475 dev_policy_free(pol
);
478 tst
->ss
->free_super(tst
);
481 /* Check if we found some imsm spares but no members */
484 memcmp(uuid_zero
, ident
->uuid
,sizeof(uuid_zero
)) == 0)) &&
486 for (tmpdev
= devlist
; tmpdev
; tmpdev
= tmpdev
->next
) {
487 if (tmpdev
->used
!= 3)
493 /* we need sb from one of the spares */
494 int dfd
= dev_open(tmpdev
->devname
, O_RDONLY
);
496 st
->ss
->load_super(st
, dfd
, NULL
))
503 /* Now reject spares that don't match domains of identified members */
504 for (tmpdev
= devlist
; tmpdev
; tmpdev
= tmpdev
->next
) {
506 if (tmpdev
->used
!= 3)
508 if (stat(tmpdev
->devname
, &stb
)< 0) {
509 pr_err("fstat failed for %s: %s\n",
510 tmpdev
->devname
, strerror(errno
));
513 struct dev_policy
*pol
= devid_policy(stb
.st_rdev
);
514 int dt
= domain_test(domains
, pol
, NULL
);
515 if (inargv
&& dt
!= 0)
516 /* take this spare as domains match
517 * if there are any */
519 else if (!inargv
&& dt
== 1)
520 /* device wasn't explicitly listed, so need
521 * explicit domain match - which we have */
524 /* if domains don't match mark as unused */
526 dev_policy_free(pol
);
529 domain_free(domains
);
531 if (st
&& st
->sb
&& content
== *contentp
)
532 st
->ss
->getinfo_super(st
, content
, NULL
);
540 int uptodate
; /* set once we decide that this device is as
541 * recent as everything else in the array.
543 int included
; /* set if the device is already in the array
544 * due to a previous '-I'
549 static int load_devices(struct devs
*devices
, char *devmap
,
550 struct mddev_ident
*ident
, struct supertype
*st
,
551 struct mddev_dev
*devlist
, struct context
*c
,
552 struct mdinfo
*content
,
553 int mdfd
, char *mddev
,
554 int *most_recentp
, int *bestcntp
, int **bestp
,
557 struct mddev_dev
*tmpdev
;
567 for (tmpdev
= devlist
; tmpdev
; tmpdev
=tmpdev
->next
) {
568 char *devname
= tmpdev
->devname
;
572 if (tmpdev
->used
!= 1)
574 /* looks like a good enough match to update the super block if needed */
578 /* prepare useful information in info structures */
580 struct supertype
*tst
;
584 if (strcmp(c
->update
, "uuid")==0 &&
587 if ((rfd
= open("/dev/urandom", O_RDONLY
)) < 0 ||
588 read(rfd
, ident
->uuid
, 16) != 16) {
589 *(__u32
*)(ident
->uuid
) = random();
590 *(__u32
*)(ident
->uuid
+1) = random();
591 *(__u32
*)(ident
->uuid
+2) = random();
592 *(__u32
*)(ident
->uuid
+3) = random();
594 if (rfd
>= 0) close(rfd
);
596 dfd
= dev_open(devname
,
597 tmpdev
->disposition
== 'I'
598 ? O_RDWR
: (O_RDWR
|O_EXCL
));
601 if (dfd
< 0 || tst
->ss
->load_super(tst
, dfd
, NULL
) != 0) {
602 pr_err("cannot re-read metadata from %s - aborting\n",
611 tst
->ss
->getinfo_super(tst
, content
, devmap
+ devcnt
* content
->array
.raid_disks
);
613 memcpy(content
->uuid
, ident
->uuid
, 16);
614 strcpy(content
->name
, ident
->name
);
615 content
->array
.md_minor
= minor(stb2
.st_rdev
);
617 if (strcmp(c
->update
, "byteorder") == 0)
620 err
= tst
->ss
->update_super(tst
, content
, c
->update
,
626 pr_err("--update=%s not understood"
627 " for %s metadata\n",
628 c
->update
, tst
->ss
->name
);
629 tst
->ss
->free_super(tst
);
637 if (strcmp(c
->update
, "uuid")==0 &&
640 memcpy(ident
->uuid
, content
->uuid
, 16);
642 if (tst
->ss
->store_super(tst
, dfd
))
643 pr_err("Could not re-write superblock on %s.\n",
647 if (strcmp(c
->update
, "uuid")==0 &&
648 ident
->bitmap_fd
>= 0 && !bitmap_done
) {
649 if (bitmap_update_uuid(ident
->bitmap_fd
,
651 tst
->ss
->swapuuid
) != 0)
652 pr_err("Could not update uuid on external bitmap.\n");
656 tst
->ss
->free_super(tst
);
660 struct supertype
*tst
= dup_super(st
);
662 dfd
= dev_open(devname
,
663 tmpdev
->disposition
== 'I'
664 ? O_RDWR
: (O_RDWR
|O_EXCL
));
666 if (dfd
< 0 || tst
->ss
->load_super(tst
, dfd
, NULL
) != 0) {
667 pr_err("cannot re-read metadata from %s - aborting\n",
676 tst
->ss
->getinfo_super(tst
, content
, devmap
+ devcnt
* content
->array
.raid_disks
);
677 tst
->ss
->free_super(tst
);
684 pr_err("%s is identified as a member of %s, slot %d%s.\n",
685 devname
, mddev
, content
->disk
.raid_disk
,
686 (content
->disk
.state
& (1<<MD_DISK_REPLACEMENT
)) ? " replacement":"");
687 devices
[devcnt
].devname
= devname
;
688 devices
[devcnt
].uptodate
= 0;
689 devices
[devcnt
].included
= (tmpdev
->disposition
== 'I');
690 devices
[devcnt
].i
= *content
;
691 devices
[devcnt
].i
.disk
.major
= major(stb
.st_rdev
);
692 devices
[devcnt
].i
.disk
.minor
= minor(stb
.st_rdev
);
694 if (devices
[devcnt
].i
.events
695 > devices
[most_recent
].i
.events
&&
696 devices
[devcnt
].i
.disk
.state
== 6)
697 most_recent
= devcnt
;
699 if (content
->array
.level
== LEVEL_MULTIPATH
)
700 /* with multipath, the raid_disk from the superblock is meaningless */
703 i
= devices
[devcnt
].i
.disk
.raid_disk
;
705 if (nextspare
< content
->array
.raid_disks
*2)
706 nextspare
= content
->array
.raid_disks
*2;
709 /* i is raid_disk - double it so there is room for
712 if (devices
[devcnt
].i
.disk
.state
& (1<<MD_DISK_REPLACEMENT
))
714 if (i
>= content
->array
.raid_disks
*2 &&
720 int newbestcnt
= i
+10;
721 int *newbest
= xmalloc(sizeof(int)*newbestcnt
);
723 for (c
=0; c
< newbestcnt
; c
++)
725 newbest
[c
] = best
[c
];
730 bestcnt
= newbestcnt
;
733 devices
[best
[i
]].i
.events
734 == devices
[devcnt
].i
.events
735 && (devices
[best
[i
]].i
.disk
.minor
736 != devices
[devcnt
].i
.disk
.minor
)
738 && content
->array
.level
!= LEVEL_MULTIPATH
) {
739 /* two different devices with identical superblock.
740 * Could be a mis-detection caused by overlapping
741 * partitions. fail-safe.
743 pr_err("WARNING %s and %s appear"
744 " to have very similar superblocks.\n"
745 " If they are really different, "
746 "please --zero the superblock on one\n"
747 " If they are the same or overlap,"
748 " please remove one from %s.\n",
749 devices
[best
[i
]].devname
, devname
,
750 inargv
? "the list" :
751 "the\n DEVICE list in mdadm.conf"
759 || (devices
[best
[i
]].i
.events
760 < devices
[devcnt
].i
.events
))
765 *most_recentp
= most_recent
;
771 static int force_array(struct mdinfo
*content
,
772 struct devs
*devices
,
773 int *best
, int bestcnt
, char *avail
,
775 struct supertype
*st
,
779 while (!enough(content
->array
.level
, content
->array
.raid_disks
,
780 content
->array
.layout
, 1,
783 (content
->reshape_active
&& content
->delta_disks
> 0 &&
784 !enough(content
->array
.level
, (content
->array
.raid_disks
785 - content
->delta_disks
),
786 content
->new_layout
, 1,
789 /* Choose the newest best drive which is
790 * not up-to-date, update the superblock
794 struct supertype
*tst
;
795 unsigned long long current_events
;
796 int chosen_drive
= -1;
799 for (i
= 0; i
< content
->array
.raid_disks
&& i
< bestcnt
; i
++) {
802 !devices
[j
].uptodate
&&
803 devices
[j
].i
.recovery_start
== MaxSector
&&
806 > devices
[chosen_drive
].i
.events
))
809 if (chosen_drive
< 0)
811 current_events
= devices
[chosen_drive
].i
.events
;
814 pr_err("forcing event count in %s(%d) from %d upto %d\n",
815 devices
[chosen_drive
].devname
,
816 devices
[chosen_drive
].i
.disk
.raid_disk
,
817 (int)(devices
[chosen_drive
].i
.events
),
818 (int)(devices
[most_recent
].i
.events
));
819 fd
= dev_open(devices
[chosen_drive
].devname
,
820 devices
[chosen_drive
].included
? O_RDWR
823 pr_err("Couldn't open %s for write - not updating\n",
824 devices
[chosen_drive
].devname
);
825 devices
[chosen_drive
].i
.events
= 0;
829 if (tst
->ss
->load_super(tst
,fd
, NULL
)) {
831 pr_err("RAID superblock disappeared from %s - not updating.\n",
832 devices
[chosen_drive
].devname
);
833 devices
[chosen_drive
].i
.events
= 0;
836 content
->events
= devices
[most_recent
].i
.events
;
837 tst
->ss
->update_super(tst
, content
, "force-one",
838 devices
[chosen_drive
].devname
, c
->verbose
,
841 if (tst
->ss
->store_super(tst
, fd
)) {
843 pr_err("Could not re-write superblock on %s\n",
844 devices
[chosen_drive
].devname
);
845 devices
[chosen_drive
].i
.events
= 0;
846 tst
->ss
->free_super(tst
);
850 devices
[chosen_drive
].i
.events
= devices
[most_recent
].i
.events
;
851 devices
[chosen_drive
].uptodate
= 1;
852 avail
[chosen_drive
] = 1;
854 tst
->ss
->free_super(tst
);
856 /* If there are any other drives of the same vintage,
857 * add them in as well. We can't lose and we might gain
859 for (i
= 0; i
< content
->array
.raid_disks
&& i
< bestcnt
; i
++) {
862 !devices
[j
].uptodate
&&
863 devices
[j
].i
.recovery_start
== MaxSector
&&
864 devices
[j
].i
.events
== current_events
) {
873 static int start_array(int mdfd
,
875 struct mdinfo
*content
,
876 struct supertype
*st
,
877 struct mddev_ident
*ident
,
878 int *best
, int bestcnt
,
880 struct devs
*devices
,
882 unsigned int sparecnt
,
883 unsigned int rebuilding_cnt
,
885 int clean
, char *avail
,
886 int start_partial_ok
,
893 unsigned int req_cnt
;
895 rv
= set_array_info(mdfd
, st
, content
);
897 pr_err("failed to set array info for %s: %s\n",
898 mddev
, strerror(errno
));
901 if (ident
->bitmap_fd
>= 0) {
902 if (ioctl(mdfd
, SET_BITMAP_FILE
, ident
->bitmap_fd
) != 0) {
903 pr_err("SET_BITMAP_FILE failed.\n");
906 } else if (ident
->bitmap_file
) {
907 /* From config file */
908 int bmfd
= open(ident
->bitmap_file
, O_RDWR
);
910 pr_err("Could not open bitmap file %s\n",
914 if (ioctl(mdfd
, SET_BITMAP_FILE
, bmfd
) != 0) {
915 pr_err("Failed to set bitmapfile for %s\n", mddev
);
922 /* First, add the raid disks, but add the chosen one last */
923 for (i
=0; i
<= bestcnt
; i
++) {
927 if (j
== chosen_drive
)
932 if (j
>= 0 && !devices
[j
].included
) {
933 int dfd
= dev_open(devices
[j
].devname
,
936 remove_partitions(dfd
);
939 rv
= add_disk(mdfd
, st
, content
, &devices
[j
].i
);
942 pr_err("failed to add "
947 if (i
< content
->array
.raid_disks
* 2
952 } else if (c
->verbose
> 0)
953 pr_err("added %s to %s as %d%s%s\n",
954 devices
[j
].devname
, mddev
,
955 devices
[j
].i
.disk
.raid_disk
,
956 devices
[j
].uptodate
?"":
957 " (possibly out of date)",
958 (devices
[j
].i
.disk
.state
& (1<<MD_DISK_REPLACEMENT
))?" replacement":"");
961 pr_err("%s is already in %s as %d\n",
962 devices
[j
].devname
, mddev
,
963 devices
[j
].i
.disk
.raid_disk
);
964 } else if (c
->verbose
> 0 && i
< content
->array
.raid_disks
*2
966 pr_err("no uptodate device for slot %d of %s\n",
970 if (content
->array
.level
== LEVEL_CONTAINER
) {
971 if (c
->verbose
>= 0) {
972 pr_err("Container %s has been "
973 "assembled with %d drive%s",
974 mddev
, okcnt
+sparecnt
, okcnt
+sparecnt
==1?"":"s");
975 if (okcnt
< (unsigned)content
->array
.raid_disks
)
976 fprintf(stderr
, " (out of %d)",
977 content
->array
.raid_disks
);
978 fprintf(stderr
, "\n");
980 st
->ss
->free_super(st
);
981 sysfs_uevent(content
, "change");
985 /* Get number of in-sync devices according to the superblock.
986 * We must have this number to start the array without -s or -R
988 req_cnt
= content
->array
.working_disks
;
990 if (c
->runstop
== 1 ||
992 ( enough(content
->array
.level
, content
->array
.raid_disks
,
993 content
->array
.layout
, clean
, avail
) &&
994 (okcnt
+ rebuilding_cnt
>= req_cnt
|| start_partial_ok
)
996 /* This array is good-to-go.
997 * If a reshape is in progress then we might need to
998 * continue monitoring it. In that case we start
999 * it read-only and let the grow code make it writable.
1003 if (content
->reshape_active
&&
1004 !(content
->reshape_active
& RESHAPE_NO_BACKUP
) &&
1005 content
->delta_disks
<= 0) {
1006 rv
= sysfs_set_str(content
, NULL
,
1007 "array_state", "readonly");
1009 rv
= Grow_continue(mdfd
, st
, content
,
1012 } else if (c
->readonly
&&
1013 sysfs_attribute_available(
1014 content
, NULL
, "array_state")) {
1015 rv
= sysfs_set_str(content
, NULL
,
1016 "array_state", "readonly");
1019 rv
= ioctl(mdfd
, RUN_ARRAY
, NULL
);
1021 if (c
->verbose
>= 0) {
1022 pr_err("%s has been started with %d drive%s",
1023 mddev
, okcnt
, okcnt
==1?"":"s");
1024 if (okcnt
< (unsigned)content
->array
.raid_disks
)
1025 fprintf(stderr
, " (out of %d)", content
->array
.raid_disks
);
1027 fprintf(stderr
, "%s %d rebuilding", sparecnt
?",":" and", rebuilding_cnt
);
1029 fprintf(stderr
, " and %d spare%s", sparecnt
, sparecnt
==1?"":"s");
1030 fprintf(stderr
, ".\n");
1032 if (content
->reshape_active
&&
1033 content
->array
.level
>= 4 &&
1034 content
->array
.level
<= 6) {
1035 /* might need to increase the size
1036 * of the stripe cache - default is 256
1038 if (256 < 4 * (content
->array
.chunk_size
/4096)) {
1039 struct mdinfo
*sra
= sysfs_read(mdfd
, NULL
, 0);
1041 sysfs_set_num(sra
, NULL
,
1042 "stripe_cache_size",
1043 (4 * content
->array
.chunk_size
/ 4096) + 1);
1047 if (okcnt
< (unsigned)content
->array
.raid_disks
) {
1048 /* If any devices did not get added
1049 * because the kernel rejected them based
1050 * on event count, try adding them
1051 * again providing the action policy is
1052 * 're-add' or greater. The bitmap
1053 * might allow them to be included, or
1054 * they will become spares.
1056 for (i
= 0; i
< bestcnt
; i
++) {
1058 if (j
>= 0 && !devices
[j
].uptodate
) {
1059 if (!disk_action_allows(&devices
[j
].i
, st
->ss
->name
, act_re_add
))
1061 rv
= add_disk(mdfd
, st
, content
,
1063 if (rv
== 0 && c
->verbose
>= 0)
1064 pr_err("%s has been re-added.\n",
1065 devices
[j
].devname
);
1069 printf("l=%d o=%d r=%d w=%d\n",content
->array
.level
,
1070 okcnt
, content
->array
.raid_disks
, was_forced
);
1071 if (content
->array
.level
== 6 &&
1072 okcnt
+ 1 == (unsigned)content
->array
.raid_disks
&&
1074 struct mdinfo
*sra
= sysfs_read(mdfd
, NULL
, 0);
1076 sysfs_set_str(sra
, NULL
,
1077 "sync_action", "repair");
1082 pr_err("failed to RUN_ARRAY %s: %s\n",
1083 mddev
, strerror(errno
));
1085 if (!enough(content
->array
.level
, content
->array
.raid_disks
,
1086 content
->array
.layout
, 1, avail
))
1087 pr_err("Not enough devices to "
1088 "start the array.\n");
1089 else if (!enough(content
->array
.level
,
1090 content
->array
.raid_disks
,
1091 content
->array
.layout
, clean
,
1093 pr_err("Not enough devices to "
1094 "start the array while not clean "
1095 "- consider --force.\n");
1099 if (c
->runstop
== -1) {
1100 pr_err("%s assembled from %d drive%s",
1101 mddev
, okcnt
, okcnt
==1?"":"s");
1102 if (okcnt
!= (unsigned)content
->array
.raid_disks
)
1103 fprintf(stderr
, " (out of %d)", content
->array
.raid_disks
);
1104 fprintf(stderr
, ", but not started.\n");
1107 if (c
->verbose
>= -1) {
1108 pr_err("%s assembled from %d drive%s", mddev
, okcnt
, okcnt
==1?"":"s");
1110 fprintf(stderr
, "%s %d rebuilding", sparecnt
?",":" and", rebuilding_cnt
);
1112 fprintf(stderr
, " and %d spare%s", sparecnt
, sparecnt
==1?"":"s");
1113 if (!enough(content
->array
.level
, content
->array
.raid_disks
,
1114 content
->array
.layout
, 1, avail
))
1115 fprintf(stderr
, " - not enough to start the array.\n");
1116 else if (!enough(content
->array
.level
,
1117 content
->array
.raid_disks
,
1118 content
->array
.layout
, clean
,
1120 fprintf(stderr
, " - not enough to start the "
1121 "array while not clean - consider "
1124 if (req_cnt
== (unsigned)content
->array
.raid_disks
)
1125 fprintf(stderr
, " - need all %d to start it", req_cnt
);
1127 fprintf(stderr
, " - need %d to start", req_cnt
);
1128 fprintf(stderr
, " (use --run to insist).\n");
1134 int Assemble(struct supertype
*st
, char *mddev
,
1135 struct mddev_ident
*ident
,
1136 struct mddev_dev
*devlist
,
1140 * The task of Assemble is to find a collection of
1141 * devices that should (according to their superblocks)
1142 * form an array, and to give this collection to the MD driver.
1143 * In Linux-2.4 and later, this involves submitting a
1144 * SET_ARRAY_INFO ioctl with no arg - to prepare
1145 * the array - and then submit a number of
1146 * ADD_NEW_DISK ioctls to add disks into
1147 * the array. Finally RUN_ARRAY might
1148 * be submitted to start the array.
1150 * Much of the work of Assemble is in finding and/or
1151 * checking the disks to make sure they look right.
1153 * If mddev is not set, then scan must be set and we
1154 * read through the config file for dev+uuid mapping
1155 * We recurse, setting mddev, for each device that
1157 * - has a valid uuid (or any uuid if !uuidset)
1159 * If mddev is set, we try to determine state of md.
1160 * check version - must be at least 0.90.0
1161 * check kernel version. must be at least 2.4.
1162 * If not, we can possibly fall back on START_ARRAY
1163 * Try to GET_ARRAY_INFO.
1164 * If possible, give up
1165 * If not, try to STOP_ARRAY just to make sure
1167 * If !uuidset and scan, look in conf-file for uuid
1168 * If not found, give up
1169 * If !devlist and scan and uuidset, get list of devs from conf-file
1172 * Check superblock - discard if bad
1173 * Check uuid (set if we don't have one) - discard if no match
1174 * Check superblock similarity if we have a superblock - discard if different
1175 * Record events, devicenum
1176 * This should give us a list of devices for the array
1177 * We should collect the most recent event number
1179 * Count disks with recent enough event count
1180 * While force && !enough disks
1181 * Choose newest rejected disks, update event count
1182 * mark clean and rewrite superblock
1185 * foreach device with recent events : ADD_NEW_DISK
1186 * if runstop == 1 || "enough" disks and runstop==0 -> RUN_ARRAY
1188 * Check the device numbers in superblock are right
1189 * update superblock if any changes
1196 int auto_assem
= (mddev
== NULL
&& !ident
->uuid_set
&&
1197 ident
->super_minor
== UnSet
&& ident
->name
[0] == 0
1198 && (ident
->container
== NULL
|| ident
->member
== NULL
));
1199 struct devs
*devices
;
1201 int *best
= NULL
; /* indexed by raid_disk */
1204 unsigned int okcnt
, sparecnt
, rebuilding_cnt
, replcnt
;
1207 int most_recent
= 0;
1211 int start_partial_ok
= (c
->runstop
>= 0) &&
1212 (c
->force
|| devlist
==NULL
|| auto_assem
);
1214 struct mddev_dev
*tmpdev
;
1216 struct mdinfo
*content
= NULL
;
1217 struct mdinfo
*pre_exist
= NULL
;
1220 char chosen_name
[1024];
1221 struct map_ent
*map
= NULL
;
1225 * If any subdevs are listed, then any that don't
1226 * match ident are discarded. Remainder must all match and
1228 * If no subdevs, then we scan all devices in the config file, but
1229 * there must be something in the identity
1233 ident
->uuid_set
== 0 &&
1234 (ident
->super_minor
< 0 || ident
->super_minor
== UnSet
) &&
1235 ident
->name
[0] == 0 &&
1236 (ident
->container
== NULL
|| ident
->member
== NULL
) &&
1237 ident
->devices
== NULL
) {
1238 pr_err("No identity information available for %s - cannot assemble.\n",
1239 mddev
? mddev
: "further assembly");
1243 if (devlist
== NULL
)
1244 devlist
= conf_get_devs();
1249 /* We come back here when doing auto-assembly and attempting some
1250 * set of devices failed. Those are now marked as ->used==2 and
1251 * we ignore them and try again
1253 if (!st
&& ident
->st
)
1256 pr_err("looking for devices for %s\n",
1257 mddev
? mddev
: "further assembly");
1261 st
->ignore_hw_compat
= 1;
1262 num_devs
= select_devices(devlist
, ident
, &st
, &content
, c
,
1263 inargv
, auto_assem
);
1267 if (!st
|| !st
->sb
|| !content
)
1270 /* We have a full set of devices - we now need to find the
1272 * However there is a risk that we are racing with "mdadm -I"
1273 * and the array is already partially assembled - we will have
1274 * rejected any devices already in this address.
1275 * So we take a lock on the map file - to prevent further races -
1276 * and look for the uuid in there. If found and the array is
1277 * active, we abort. If found and the array is not active
1278 * we commit to that md device and add all the contained devices
1279 * to our list. We flag them so that we don't try to re-add,
1280 * but can remove if they turn out to not be wanted.
1283 pr_err("failed to get exclusive lock on mapfile - continue anyway...\n");
1284 mp
= map_by_uuid(&map
, content
->uuid
);
1287 /* array already exists. */
1288 pre_exist
= sysfs_read(-1, mp
->devnm
, GET_LEVEL
|GET_DEVS
);
1289 if (pre_exist
->array
.level
!= UnSet
) {
1290 pr_err("Found some drive for an array that is already active: %s\n",
1292 pr_err("giving up.\n");
1295 for (dv
= pre_exist
->devs
; dv
; dv
= dv
->next
) {
1296 /* We want to add this device to our list,
1297 * but it could already be there if "mdadm -I"
1298 * started *after* we checked for O_EXCL.
1299 * If we add it to the top of the list
1300 * it will be preferred over later copies.
1302 struct mddev_dev
*newdev
;
1303 char *devname
= map_dev(dv
->disk
.major
,
1308 newdev
= xmalloc(sizeof(*newdev
));
1309 newdev
->devname
= devname
;
1310 newdev
->disposition
= 'I';
1312 newdev
->next
= devlist
;
1316 strcpy(chosen_name
, mp
->path
);
1317 if (c
->verbose
> 0 || mddev
== NULL
||
1318 strcmp(mddev
, chosen_name
) != 0)
1319 pr_err("Merging with already-assembled %s\n",
1321 mdfd
= open_dev_excl(mp
->devnm
);
1323 int trustworthy
= FOREIGN
;
1324 name
= content
->name
;
1325 switch (st
->ss
->match_home(st
, c
->homehost
)
1326 ?: st
->ss
->match_home(st
, "any")) {
1328 trustworthy
= LOCAL
;
1329 name
= strchr(content
->name
, ':');
1333 name
= content
->name
;
1337 /* If the array is listed in mdadm.conf or on
1338 * command line, then we trust the name
1339 * even if the array doesn't look local
1341 trustworthy
= LOCAL
;
1344 content
->array
.level
== LEVEL_CONTAINER
) {
1345 name
= content
->text_version
;
1346 trustworthy
= METADATA
;
1349 if (name
[0] && trustworthy
!= LOCAL
&&
1350 ! c
->require_homehost
&&
1351 conf_name_is_free(name
))
1352 trustworthy
= LOCAL
;
1354 if (trustworthy
== LOCAL
&&
1356 /* Ignore 'host:' prefix of name */
1357 name
= strchr(name
, ':')+1;
1359 mdfd
= create_mddev(mddev
, name
, ident
->autof
, trustworthy
,
1363 st
->ss
->free_super(st
);
1368 mddev
= chosen_name
;
1369 if (get_linux_version() < 2004000 ||
1370 md_get_version(mdfd
) < 9000) {
1371 pr_err("Assemble requires Linux 2.4 or later, and\n"
1372 " md driver version 0.90.0 or later.\n"
1373 " Upgrade your kernel or try --build\n");
1377 if (pre_exist
== NULL
) {
1378 if (mddev_busy(fd2devnm(mdfd
))) {
1379 pr_err("%s already active, cannot restart it!\n",
1381 for (tmpdev
= devlist
;
1382 tmpdev
&& tmpdev
->used
!= 1;
1383 tmpdev
= tmpdev
->next
)
1385 if (tmpdev
&& auto_assem
)
1386 pr_err("%s needed for %s...\n",
1387 mddev
, tmpdev
->devname
);
1390 st
->ss
->free_super(st
);
1395 /* just incase it was started but has no content */
1396 ioctl(mdfd
, STOP_ARRAY
, NULL
);
1400 if (content
!= &info
) {
1401 /* This is a member of a container. Try starting the array. */
1403 err
= assemble_container_content(st
, mdfd
, content
, c
,
1409 /* Ok, no bad inconsistancy, we can try updating etc */
1410 devices
= xcalloc(num_devs
, sizeof(*devices
));
1411 devmap
= xcalloc(num_devs
, content
->array
.raid_disks
);
1412 devcnt
= load_devices(devices
, devmap
, ident
, st
, devlist
,
1413 c
, content
, mdfd
, mddev
,
1414 &most_recent
, &bestcnt
, &best
, inargv
);
1419 pr_err("no devices found for %s\n",
1422 st
->ss
->free_super(st
);
1429 if (c
->update
&& strcmp(c
->update
, "byteorder")==0)
1430 st
->minor_version
= 90;
1432 st
->ss
->getinfo_super(st
, content
, NULL
);
1433 clean
= content
->array
.state
& 1;
1435 /* now we have some devices that might be suitable.
1438 avail
= xcalloc(content
->array
.raid_disks
, 1);
1443 for (i
=0; i
< bestcnt
; i
++) {
1445 int event_margin
= 1; /* always allow a difference of '1'
1446 * like the kernel does
1448 if (j
< 0) continue;
1449 /* note: we ignore error flags in multipath arrays
1450 * as they don't make sense
1452 if (content
->array
.level
!= LEVEL_MULTIPATH
)
1453 if (!(devices
[j
].i
.disk
.state
& (1<<MD_DISK_ACTIVE
))) {
1454 if (!(devices
[j
].i
.disk
.state
1455 & (1<<MD_DISK_FAULTY
))) {
1456 devices
[j
].uptodate
= 1;
1461 /* If this device thinks that 'most_recent' has failed, then
1462 * we must reject this device.
1464 if (j
!= most_recent
&&
1465 content
->array
.raid_disks
> 0 &&
1466 devices
[most_recent
].i
.disk
.raid_disk
>= 0 &&
1467 devmap
[j
* content
->array
.raid_disks
+ devices
[most_recent
].i
.disk
.raid_disk
] == 0) {
1468 if (c
->verbose
> -1)
1469 pr_err("ignoring %s as it reports %s as failed\n",
1470 devices
[j
].devname
, devices
[most_recent
].devname
);
1474 /* Require event counter to be same as, or just less than,
1475 * most recent. If it is bigger, it must be a stray spare and
1476 * should be ignored.
1478 if (devices
[j
].i
.events
+event_margin
>=
1479 devices
[most_recent
].i
.events
&&
1480 devices
[j
].i
.events
<=
1481 devices
[most_recent
].i
.events
1483 devices
[j
].uptodate
= 1;
1484 if (i
< content
->array
.raid_disks
* 2) {
1485 if (devices
[j
].i
.recovery_start
== MaxSector
||
1486 (content
->reshape_active
&&
1487 ((i
>= content
->array
.raid_disks
- content
->delta_disks
) ||
1488 (i
>= content
->array
.raid_disks
- content
->delta_disks
- 1
1489 && content
->array
.level
== 4)))) {
1503 int force_ok
= force_array(content
, devices
, best
, bestcnt
,
1504 avail
, most_recent
, st
, c
);
1509 /* Now we want to look at the superblock which the kernel will base things on
1510 * and compare the devices that we think are working with the devices that the
1511 * superblock thinks are working.
1512 * If there are differences and --force is given, then update this chosen
1516 st
->ss
->free_super(st
);
1517 for (i
=0; chosen_drive
< 0 && i
<bestcnt
; i
++) {
1523 if (!devices
[j
].uptodate
)
1525 if (devices
[j
].i
.events
< devices
[most_recent
].i
.events
)
1528 if ((fd
=dev_open(devices
[j
].devname
,
1529 devices
[j
].included
? O_RDONLY
1530 : (O_RDONLY
|O_EXCL
)))< 0) {
1531 pr_err("Cannot open %s: %s\n",
1532 devices
[j
].devname
, strerror(errno
));
1537 if (st
->ss
->load_super(st
,fd
, NULL
)) {
1539 pr_err("RAID superblock has disappeared from %s\n",
1540 devices
[j
].devname
);
1547 if (st
->sb
== NULL
) {
1548 pr_err("No suitable drives found for %s\n", mddev
);
1553 st
->ss
->getinfo_super(st
, content
, NULL
);
1555 sysfs_init(content
, mdfd
, NULL
);
1557 for (i
=0; i
<bestcnt
; i
++) {
1559 unsigned int desired_state
;
1561 if (i
>= content
->array
.raid_disks
* 2)
1564 desired_state
= (1<<MD_DISK_ACTIVE
) | (1<<MD_DISK_REPLACEMENT
);
1566 desired_state
= (1<<MD_DISK_ACTIVE
) | (1<<MD_DISK_SYNC
);
1570 if (!devices
[j
].uptodate
)
1573 devices
[j
].i
.disk
.state
= desired_state
;
1574 if (!(devices
[j
].i
.array
.state
& 1))
1577 if (st
->ss
->update_super(st
, &devices
[j
].i
, "assemble", NULL
,
1578 c
->verbose
, 0, NULL
)) {
1580 if (c
->verbose
>= 0)
1581 pr_err("clearing FAULTY flag for device %d in %s for %s\n",
1582 j
, mddev
, devices
[j
].devname
);
1585 if (c
->verbose
>= -1)
1586 pr_err("device %d in %s has wrong state in superblock, but %s seems ok\n",
1587 i
, mddev
, devices
[j
].devname
);
1591 if (!(super
.disks
[i
].i
.disk
.state
& (1 << MD_DISK_FAULTY
))) {
1592 pr_err("devices %d of %s is not marked FAULTY in superblock, but cannot be found\n",
1597 if (c
->force
&& !clean
&&
1598 !enough(content
->array
.level
, content
->array
.raid_disks
,
1599 content
->array
.layout
, clean
,
1601 change
+= st
->ss
->update_super(st
, content
, "force-array",
1602 devices
[chosen_drive
].devname
, c
->verbose
,
1610 fd
= dev_open(devices
[chosen_drive
].devname
,
1611 devices
[chosen_drive
].included
?
1612 O_RDWR
: (O_RDWR
|O_EXCL
));
1614 pr_err("Could not open %s for write - cannot Assemble array.\n",
1615 devices
[chosen_drive
].devname
);
1620 if (st
->ss
->store_super(st
, fd
)) {
1622 pr_err("Could not re-write superblock on %s\n",
1623 devices
[chosen_drive
].devname
);
1628 if (c
->verbose
>= 0)
1629 pr_err("Marking array %s as 'clean'\n",
1634 /* If we are in the middle of a reshape we may need to restore saved data
1635 * that was moved aside due to the reshape overwriting live data
1636 * The code of doing this lives in Grow.c
1639 if (content
->reshape_active
&&
1640 !(content
->reshape_active
& RESHAPE_NO_BACKUP
)) {
1642 int *fdlist
= xmalloc(sizeof(int)* bestcnt
);
1644 pr_err(":%s has an active reshape - checking "
1645 "if critical section needs to be restored\n",
1647 enable_fds(bestcnt
/2);
1648 for (i
= 0; i
< bestcnt
/2; i
++) {
1651 fdlist
[i
] = dev_open(devices
[j
].devname
,
1653 ? O_RDWR
: (O_RDWR
|O_EXCL
));
1654 if (fdlist
[i
] < 0) {
1655 pr_err("Could not open %s for write - cannot Assemble array.\n",
1656 devices
[j
].devname
);
1664 if (st
->ss
->external
&& st
->ss
->recover_backup
)
1665 err
= st
->ss
->recover_backup(st
, content
);
1667 err
= Grow_restart(st
, content
, fdlist
, bestcnt
/2,
1668 c
->backup_file
, c
->verbose
> 0);
1669 if (err
&& c
->invalid_backup
) {
1672 " without restoring backup\n");
1678 if (fdlist
[i
]>=0) close(fdlist
[i
]);
1682 pr_err("Failed to restore critical section for reshape, sorry.\n");
1683 if (c
->backup_file
== NULL
)
1684 cont_err("Possibly you needed to specify the --backup-file\n");
1692 /* Almost ready to actually *do* something */
1693 /* First, fill in the map, so that udev can find our name
1694 * as soon as we become active.
1696 if (c
->update
&& strcmp(c
->update
, "metadata")==0) {
1697 content
->array
.major_version
= 1;
1698 content
->array
.minor_version
= 0;
1699 strcpy(content
->text_version
, "1.0");
1702 map_update(&map
, fd2devnm(mdfd
), content
->text_version
,
1703 content
->uuid
, chosen_name
);
1705 rv
= start_array(mdfd
, mddev
, content
,
1706 st
, ident
, best
, bestcnt
,
1707 chosen_drive
, devices
, okcnt
, sparecnt
,
1710 clean
, avail
, start_partial_ok
,
1713 if (rv
== 1 && !pre_exist
)
1714 ioctl(mdfd
, STOP_ARRAY
, NULL
);
1718 wait_for(chosen_name
, mdfd
);
1722 /* There is a nasty race with 'mdadm --monitor'.
1723 * If it opens this device before we close it,
1724 * it gets an incomplete open on which IO
1725 * doesn't work and the capacity is
1727 * If we reopen (to check for layered devices)
1728 * before --monitor closes, we loose.
1730 * So: wait upto 1 second for there to be
1731 * a non-zero capacity.
1733 while (usecs
< 1000) {
1734 mdfd
= open(mddev
, O_RDONLY
);
1736 unsigned long long size
;
1737 if (get_dev_size(mdfd
, NULL
, &size
) &&
1749 /* '2' means 'OK, but not started yet' */
1750 return rv
== 2 ? 0 : rv
;
1754 int assemble_container_content(struct supertype
*st
, int mdfd
,
1755 struct mdinfo
*content
, struct context
*c
,
1758 struct mdinfo
*dev
, *sra
;
1759 int working
= 0, preexist
= 0;
1761 struct map_ent
*map
= NULL
;
1765 sysfs_init(content
, mdfd
, NULL
);
1767 sra
= sysfs_read(mdfd
, NULL
, GET_VERSION
);
1768 if (sra
== NULL
|| strcmp(sra
->text_version
, content
->text_version
) != 0) {
1769 if (content
->array
.major_version
== -1 &&
1770 content
->array
.minor_version
== -2 &&
1772 content
->text_version
[0] == '/')
1773 content
->text_version
[0] = '-';
1774 if (sysfs_set_array(content
, md_get_version(mdfd
)) != 0) {
1781 /* There are two types of reshape: container wide or sub-array specific
1782 * Check if metadata requests blocking container wide reshapes
1784 start_reshape
= (content
->reshape_active
&&
1785 !((content
->reshape_active
== CONTAINER_RESHAPE
) &&
1786 (content
->array
.state
& (1<<MD_SB_BLOCK_CONTAINER_RESHAPE
))));
1788 /* Block subarray here if it is under reshape now
1789 * Do not allow for any changes in this array
1791 if (st
->ss
->external
&& content
->recovery_blocked
&& start_reshape
)
1792 block_subarray(content
);
1796 old_raid_disks
= content
->array
.raid_disks
- content
->delta_disks
;
1797 for (dev
= content
->devs
; dev
; dev
= dev
->next
)
1798 if (sysfs_add_disk(content
, dev
, 1) == 0) {
1799 if (dev
->disk
.raid_disk
>= old_raid_disks
&&
1800 content
->reshape_active
)
1804 } else if (errno
== EEXIST
)
1806 if (working
+ expansion
== 0)
1807 return 1;/* Nothing new, don't try to start */
1809 map_update(&map
, fd2devnm(mdfd
),
1810 content
->text_version
,
1811 content
->uuid
, chosen_name
);
1813 if (c
->runstop
> 0 ||
1814 (working
+ preexist
+ expansion
) >=
1815 content
->array
.working_disks
) {
1818 if (start_reshape
) {
1819 int spare
= content
->array
.raid_disks
+ expansion
;
1820 if (restore_backup(st
, content
,
1822 spare
, c
->backup_file
, c
->verbose
) == 1)
1825 err
= sysfs_set_str(content
, NULL
,
1826 "array_state", "readonly");
1830 if (st
->ss
->external
) {
1831 if (!mdmon_running(st
->container_devnm
))
1832 start_mdmon(st
->container_devnm
);
1833 ping_monitor(st
->container_devnm
);
1834 if (mdmon_running(st
->container_devnm
) &&
1835 st
->update_tail
== NULL
)
1836 st
->update_tail
= &st
->updates
;
1839 err
= Grow_continue(mdfd
, st
, content
, c
->backup_file
,
1841 } else switch(content
->array
.level
) {
1843 case LEVEL_MULTIPATH
:
1845 err
= sysfs_set_str(content
, NULL
, "array_state",
1846 c
->readonly
? "readonly" : "active");
1849 err
= sysfs_set_str(content
, NULL
, "array_state",
1851 /* start mdmon if needed. */
1853 if (!mdmon_running(st
->container_devnm
))
1854 start_mdmon(st
->container_devnm
);
1855 ping_monitor(st
->container_devnm
);
1860 sysfs_set_safemode(content
, content
->safe_mode_delay
);
1862 /* Block subarray here if it is not reshaped now
1863 * It has be blocked a little later to allow mdmon to switch in
1866 if (st
->ss
->external
&& content
->recovery_blocked
&&
1868 block_subarray(content
);
1870 if (c
->verbose
>= 0) {
1872 pr_err("array %s now has %d device%s",
1873 chosen_name
, working
+ preexist
,
1874 working
+ preexist
== 1 ? "":"s");
1876 pr_err("Started %s with %d device%s",
1877 chosen_name
, working
+ preexist
,
1878 working
+ preexist
== 1 ? "":"s");
1880 fprintf(stderr
, " (%d new)", working
);
1882 fprintf(stderr
, " ( + %d for expansion)",
1884 fprintf(stderr
, "\n");
1887 wait_for(chosen_name
, mdfd
);
1889 /* FIXME should have an O_EXCL and wait for read-auto */
1891 if (c
->verbose
>= 0) {
1892 pr_err("%s assembled with %d device%s",
1893 chosen_name
, preexist
+ working
,
1894 preexist
+ working
== 1 ? "":"s");
1896 fprintf(stderr
, " (%d new)", working
);
1897 fprintf(stderr
, " but not started\n");