X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=Assemble.c;h=ea3a6484d9ad78ac8977a0efa02e686c9662324b;hb=1502a43a08d0648a6b03d89b7cf189f15bea8647;hp=7da090506a224d0f6efdf4288ee8537c2ac10cb1;hpb=5d504f42782ced8af5438ebc455b084275c86eec;p=thirdparty%2Fmdadm.git diff --git a/Assemble.c b/Assemble.c index 7da09050..ea3a6484 100644 --- a/Assemble.c +++ b/Assemble.c @@ -146,11 +146,11 @@ int Assemble(struct supertype *st, char *mddev, struct mdinfo i; } *devices; int *best = NULL; /* indexed by raid_disk */ - unsigned int bestcnt = 0; + int bestcnt = 0; int devcnt = 0; - unsigned int okcnt, sparecnt; + unsigned int okcnt, sparecnt, rebuilding_cnt; unsigned int req_cnt; - unsigned int i; + int i; int most_recent = 0; int chosen_drive; int change = 0; @@ -182,7 +182,7 @@ int Assemble(struct supertype *st, char *mddev, if (!devlist && ident->uuid_set == 0 && - ident->super_minor < 0 && + (ident->super_minor < 0 || ident->super_minor == UnSet) && ident->name[0] == 0 && (ident->container == NULL || ident->member == NULL) && ident->devices == NULL) { @@ -260,17 +260,19 @@ int Assemble(struct supertype *st, char *mddev, 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)); @@ -315,6 +317,9 @@ int Assemble(struct supertype *st, char *mddev, } /* It is worth looking inside this container. */ + if (verbose > 0) + fprintf(stderr, Name ": looking in container %s\n", + devname); next_member: if (tmpdev->content) content = tmpdev->content; @@ -405,6 +410,9 @@ int Assemble(struct supertype *st, char *mddev, fprintf(stderr, Name ": member %s in %s is already assembled\n", content->text_version, devname); + skip: + if (tmpdev->content) + goto next_member; tst->ss->free_super(tst); tst = NULL; content = NULL; @@ -412,14 +420,32 @@ int Assemble(struct supertype *st, char *mddev, goto loop; return 1; } + if (ident->member && ident->member[0]) { + char *s = strchr(content->text_version+1, '/'); + if (s == NULL) { + fprintf(stderr, Name ": badly formatted version: %s\n", + content->text_version); + goto skip; + } + if (strcmp(ident->member, s+1) != 0) { + if (report_missmatch) + fprintf(stderr, + Name ": skipping wrong member %s\n", + content->text_version); + goto skip; + } + } 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); st->ss->free_super(st); return 1; } + if (verbose > 0) + fprintf(stderr, Name ": found match on member %s in %s\n", + content->text_version, devname); break; } if (st == NULL) @@ -592,10 +618,15 @@ int Assemble(struct supertype *st, char *mddev, } dfd = dev_open(devname, O_RDWR|O_EXCL); - 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); @@ -636,9 +667,14 @@ int Assemble(struct supertype *st, char *mddev, int dfd; dfd = dev_open(devname, O_RDWR|O_EXCL); - 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); @@ -659,7 +695,7 @@ int Assemble(struct supertype *st, char *mddev, > 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 @@ -675,9 +711,9 @@ int Assemble(struct supertype *st, char *mddev, } if (i < 10000) { if (i >= bestcnt) { - unsigned int newbestcnt = i+10; + int newbestcnt = i+10; int *newbest = malloc(sizeof(int)*newbestcnt); - unsigned int c; + int c; for (c=0; c < newbestcnt; c++) if (c < bestcnt) newbest[c] = best[c]; @@ -743,7 +779,8 @@ int Assemble(struct supertype *st, char *mddev, memset(avail, 0, content->array.raid_disks); okcnt = 0; sparecnt=0; - for (i=0; i< bestcnt ;i++) { + rebuilding_cnt=0; + for (i=0; i< bestcnt; i++) { int j = best[i]; int event_margin = 1; /* always allow a difference of '1' * like the kernel does @@ -752,8 +789,8 @@ int Assemble(struct supertype *st, char *mddev, /* 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<array.level != LEVEL_MULTIPATH) + if (!(devices[j].i.disk.state & (1<array.raid_disks) { - okcnt++; - avail[i]=1; + if (devices[j].i.recovery_start == MaxSector) { + okcnt++; + avail[i]=1; + } else + rebuilding_cnt++; } else sparecnt++; } @@ -778,12 +818,13 @@ int Assemble(struct supertype *st, char *mddev, */ int fd; struct supertype *tst; - long long current_events; + unsigned long long current_events; chosen_drive = -1; - for (i=0; iarray.raid_disks && i < bestcnt; i++) { + for (i = 0; i < content->array.raid_disks && i < bestcnt; i++) { 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)) @@ -837,7 +878,7 @@ int Assemble(struct supertype *st, char *mddev, /* If there are any other drives of the same vintage, * add them in as well. We can't lose and we might gain */ - for (i=0; iarray.raid_disks && i < bestcnt ; i++) { + for (i = 0; i < content->array.raid_disks && i < bestcnt ; i++) { int j = best[i]; if (j >= 0 && !devices[j].uptodate && @@ -966,6 +1007,10 @@ int Assemble(struct supertype *st, char *mddev, if (content->reshape_active) { int err = 0; int *fdlist = malloc(sizeof(int)* bestcnt); + if (verbose > 0) + fprintf(stderr, Name ":%s has an active reshape - checking " + "if critical section needs to be restored\n", + chosen_name); for (i=0; i= 0) { @@ -980,13 +1025,15 @@ int Assemble(struct supertype *st, char *mddev, fdlist[i] = -1; } if (!err) - err = Grow_restart(st, content, fdlist, bestcnt, backup_file); + err = Grow_restart(st, content, fdlist, bestcnt, backup_file, verbose > 0); while (i>0) { i--; if (fdlist[i]>=0) close(fdlist[i]); } if (err) { fprintf(stderr, Name ": Failed to restore critical section for reshape, sorry.\n"); + if (backup_file == NULL) + fprintf(stderr," Possibly you needed to specify the --backup-file\n"); close(mdfd); return err; } @@ -1011,12 +1058,14 @@ int Assemble(struct supertype *st, char *mddev, 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; } @@ -1026,12 +1075,14 @@ int Assemble(struct supertype *st, char *mddev, 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; } @@ -1049,6 +1100,12 @@ int Assemble(struct supertype *st, char *mddev, j = chosen_drive; if (j >= 0 /* && devices[j].uptodate */) { + int dfd = dev_open(devices[j].devname, + O_RDWR|O_EXCL); + if (dfd >= 0) { + remove_partitions(dfd); + close(dfd); + } rv = add_disk(mdfd, st, content, &devices[j].i); if (rv) { @@ -1078,7 +1135,7 @@ int Assemble(struct supertype *st, char *mddev, fprintf(stderr, Name ": Container %s has been " "assembled with %d drive%s", mddev, okcnt+sparecnt, okcnt+sparecnt==1?"":"s"); - if (okcnt < content->array.raid_disks) + if (okcnt < (unsigned)content->array.raid_disks) fprintf(stderr, " (out of %d)", content->array.raid_disks); fprintf(stderr, "\n"); @@ -1093,14 +1150,29 @@ int Assemble(struct supertype *st, char *mddev, (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) ))) { - if (ioctl(mdfd, RUN_ARRAY, NULL)==0) { + /* This array is good-to-go. + * If a reshape is in progress then we might need to + * continue monitoring it. In that case we start + * it read-only and let the grow code make it writable. + */ + int rv; +#ifndef MDASSEMBLE + if (content->reshape_active && + content->delta_disks <= 0) + rv = Grow_continue(mdfd, st, content, backup_file); + else +#endif + rv = ioctl(mdfd, RUN_ARRAY, NULL); + if (rv == 0) { if (verbose >= 0) { fprintf(stderr, Name ": %s has been started with %d drive%s", mddev, okcnt, okcnt==1?"":"s"); - if (okcnt < content->array.raid_disks) + if (okcnt < (unsigned)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"); @@ -1172,7 +1244,7 @@ int Assemble(struct supertype *st, char *mddev, if (runstop == -1) { fprintf(stderr, Name ": %s assembled from %d drive%s", mddev, okcnt, okcnt==1?"":"s"); - if (okcnt != content->array.raid_disks) + if (okcnt != (unsigned)content->array.raid_disks) fprintf(stderr, " (out of %d)", content->array.raid_disks); fprintf(stderr, ", but not started.\n"); close(mdfd); @@ -1180,6 +1252,8 @@ int Assemble(struct supertype *st, char *mddev, } 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, @@ -1193,7 +1267,7 @@ int Assemble(struct supertype *st, char *mddev, "array while not clean - consider " "--force.\n"); else { - if (req_cnt == content->array.raid_disks) + if (req_cnt == (unsigned)content->array.raid_disks) fprintf(stderr, " - need all %d to start it", req_cnt); else fprintf(stderr, " - need %d of %d to start", req_cnt, content->array.raid_disks);