int *best = NULL; /* indexed by raid_disk */
unsigned int bestcnt = 0;
int devcnt = 0;
- unsigned int okcnt, sparecnt;
+ unsigned int okcnt, sparecnt, rebuilding_cnt;
unsigned int req_cnt;
unsigned int i;
int most_recent = 0;
fprintf(stderr, Name ": no recogniseable superblock on %s\n",
devname);
tmpdev->used = 2;
+ } else if (tst->ss->load_super(tst,dfd, NULL)) {
+ if (report_missmatch)
+ fprintf( stderr, Name ": no RAID superblock on %s\n",
+ devname);
} else if (auto_assem && st == NULL &&
- !conf_test_metadata(tst->ss->name)) {
+ !conf_test_metadata(tst->ss->name,
+ tst->ss->match_home(tst, homehost) == 1)) {
if (report_missmatch)
fprintf(stderr, Name ": %s has metadata type %s for which "
"auto-assembly is disabled\n",
devname, tst->ss->name);
+ tst->ss->free_super(tst);
tmpdev->used = 2;
- } else if (tst->ss->load_super(tst,dfd, NULL)) {
- if (report_missmatch)
- fprintf( stderr, Name ": no RAID superblock on %s\n",
- devname);
} else {
content = &info;
memset(content, 0, sizeof(*content));
}
}
st = tst; tst = NULL;
- if (!auto_assem && tmpdev->next != NULL) {
+ if (!auto_assem && inargv && tmpdev->next != NULL) {
fprintf(stderr, Name ": %s is a container, but is not "
"only device given: confused and aborting\n",
devname);
remove_partitions(dfd);
tst = dup_super(st);
- tst->ss->load_super(tst, dfd, NULL);
+ if (dfd < 0 || tst->ss->load_super(tst, dfd, NULL) != 0) {
+ fprintf(stderr, Name ": cannot re-read metadata from %s - aborting\n",
+ devname);
+ if (dfd >= 0)
+ close(dfd);
+ close(mdfd);
+ return 1;
+ }
tst->ss->getinfo_super(tst, content);
memcpy(content->uuid, ident->uuid, 16);
remove_partitions(dfd);
- tst->ss->load_super(tst, dfd, NULL);
+ if (dfd < 0 || tst->ss->load_super(tst, dfd, NULL) != 0) {
+ fprintf(stderr, Name ": cannot re-read metadata from %s - aborting\n",
+ devname);
+ if (dfd >= 0)
+ close(dfd);
+ close(mdfd);
+ return 1;
+ }
tst->ss->getinfo_super(tst, content);
tst->ss->free_super(tst);
close(dfd);
> devices[most_recent].i.events)
most_recent = devcnt;
}
- if (content->array.level == -4)
+ if (content->array.level == LEVEL_MULTIPATH)
/* with multipath, the raid_disk from the superblock is meaningless */
i = devcnt;
else
memset(avail, 0, content->array.raid_disks);
okcnt = 0;
sparecnt=0;
+ rebuilding_cnt=0;
for (i=0; i< bestcnt ;i++) {
int j = best[i];
int event_margin = 1; /* always allow a difference of '1'
/* note: we ignore error flags in multipath arrays
* as they don't make sense
*/
- if (content->array.level != -4)
- if (!(devices[j].i.disk.state & (1<<MD_DISK_SYNC))) {
+ if (content->array.level != LEVEL_MULTIPATH)
+ if (!(devices[j].i.disk.state & (1<<MD_DISK_ACTIVE))) {
if (!(devices[j].i.disk.state
& (1<<MD_DISK_FAULTY)))
sparecnt++;
devices[most_recent].i.events) {
devices[j].uptodate = 1;
if (i < content->array.raid_disks) {
- okcnt++;
- avail[i]=1;
+ if (devices[j].i.recovery_start == MaxSector) {
+ okcnt++;
+ avail[i]=1;
+ } else
+ rebuilding_cnt++;
} else
sparecnt++;
}
int j = best[i];
if (j>=0 &&
!devices[j].uptodate &&
+ devices[j].i.recovery_start == MaxSector &&
(chosen_drive < 0 ||
devices[j].i.events
> devices[chosen_drive].i.events))
if (content->reshape_active) {
int err = 0;
int *fdlist = malloc(sizeof(int)* bestcnt);
- if (verbose)
+ if (verbose > 0)
fprintf(stderr, Name ":%s has an active reshape - checking "
"if critical section needs to be restored\n",
chosen_name);
fdlist[i] = -1;
}
if (!err)
- err = Grow_restart(st, content, fdlist, bestcnt, backup_file, verbose);
+ err = Grow_restart(st, content, fdlist, bestcnt, backup_file, verbose > 0);
while (i>0) {
i--;
if (fdlist[i]>=0) close(fdlist[i]);
if (rv) {
fprintf(stderr, Name ": failed to set array info for %s: %s\n",
mddev, strerror(errno));
+ ioctl(mdfd, STOP_ARRAY, NULL);
close(mdfd);
return 1;
}
if (ident->bitmap_fd >= 0) {
if (ioctl(mdfd, SET_BITMAP_FILE, ident->bitmap_fd) != 0) {
fprintf(stderr, Name ": SET_BITMAP_FILE failed.\n");
+ ioctl(mdfd, STOP_ARRAY, NULL);
close(mdfd);
return 1;
}
if (bmfd < 0) {
fprintf(stderr, Name ": Could not open bitmap file %s\n",
ident->bitmap_file);
+ ioctl(mdfd, STOP_ARRAY, NULL);
close(mdfd);
return 1;
}
if (ioctl(mdfd, SET_BITMAP_FILE, bmfd) != 0) {
fprintf(stderr, Name ": Failed to set bitmapfile for %s\n", mddev);
close(bmfd);
+ ioctl(mdfd, STOP_ARRAY, NULL);
close(mdfd);
return 1;
}
(runstop <= 0 &&
( enough(content->array.level, content->array.raid_disks,
content->array.layout, clean, avail, okcnt) &&
- (okcnt >= req_cnt || start_partial_ok)
+ (okcnt + rebuilding_cnt >= req_cnt || start_partial_ok)
))) {
/* This array is good-to-go.
* If a reshape is in progress then we might need to
mddev, okcnt, okcnt==1?"":"s");
if (okcnt < content->array.raid_disks)
fprintf(stderr, " (out of %d)", content->array.raid_disks);
+ if (rebuilding_cnt)
+ fprintf(stderr, "%s %d rebuilding", sparecnt?",":" and", rebuilding_cnt);
if (sparecnt)
fprintf(stderr, " and %d spare%s", sparecnt, sparecnt==1?"":"s");
fprintf(stderr, ".\n");
}
if (verbose >= -1) {
fprintf(stderr, Name ": %s assembled from %d drive%s", mddev, okcnt, okcnt==1?"":"s");
+ if (rebuilding_cnt)
+ fprintf(stderr, "%s %d rebuilding", sparecnt?", ":" and ", rebuilding_cnt);
if (sparecnt)
fprintf(stderr, " and %d spare%s", sparecnt, sparecnt==1?"":"s");
if (!enough(content->array.level, content->array.raid_disks,