Drop the superblock arg from all metadata methods.

It is now in the 'supertype'
This commit is contained in:
Neil Brown 2007-12-14 20:14:33 +11:00
parent 64557c3391
commit 3da92f272d
14 changed files with 330 additions and 325 deletions

View File

@ -115,7 +115,6 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
int must_close = 0; int must_close = 0;
int old_linux = 0; int old_linux = 0;
int vers = 0; /* Keep gcc quite - it really is initialised */ int vers = 0; /* Keep gcc quite - it really is initialised */
void *first_super = NULL, *super = NULL;
struct { struct {
char *devname; char *devname;
unsigned int major, minor; unsigned int major, minor;
@ -215,7 +214,7 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
char *devname = tmpdev->devname; char *devname = tmpdev->devname;
int dfd; int dfd;
struct stat stb; struct stat stb;
struct supertype *tst = st; struct supertype *tst = dup_super(st);
if (tmpdev->used > 1) continue; if (tmpdev->used > 1) continue;
@ -246,55 +245,60 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
fprintf(stderr, Name ": no recogniseable superblock on %s\n", fprintf(stderr, Name ": no recogniseable superblock on %s\n",
devname); devname);
tmpdev->used = 2; tmpdev->used = 2;
} else if (tst->ss->load_super(tst,dfd, &super, NULL)) { } else if (tst->ss->load_super(tst,dfd, NULL)) {
if ((inargv && verbose >= 0) || verbose > 0) if ((inargv && verbose >= 0) || verbose > 0)
fprintf( stderr, Name ": no RAID superblock on %s\n", fprintf( stderr, Name ": no RAID superblock on %s\n",
devname); devname);
} else { } else {
tst->ss->getinfo_super(tst, &info, super); tst->ss->getinfo_super(tst, &info);
} }
if (dfd >= 0) close(dfd); if (dfd >= 0) close(dfd);
if (ident->uuid_set && (!update || strcmp(update, "uuid")!= 0) && if (ident->uuid_set && (!update || strcmp(update, "uuid")!= 0) &&
(!super || same_uuid(info.uuid, ident->uuid, tst->ss->swapuuid)==0)) { (!tst || !tst->sb ||
same_uuid(info.uuid, ident->uuid, tst->ss->swapuuid)==0)) {
if ((inargv && verbose >= 0) || verbose > 0) if ((inargv && verbose >= 0) || verbose > 0)
fprintf(stderr, Name ": %s has wrong uuid.\n", fprintf(stderr, Name ": %s has wrong uuid.\n",
devname); devname);
goto loop; goto loop;
} }
if (ident->name[0] && (!update || strcmp(update, "name")!= 0) && if (ident->name[0] && (!update || strcmp(update, "name")!= 0) &&
(!super || name_matches(info.name, ident->name, homehost)==0)) { (!tst || !tst->sb ||
name_matches(info.name, ident->name, homehost)==0)) {
if ((inargv && verbose >= 0) || verbose > 0) if ((inargv && verbose >= 0) || verbose > 0)
fprintf(stderr, Name ": %s has wrong name.\n", fprintf(stderr, Name ": %s has wrong name.\n",
devname); devname);
goto loop; goto loop;
} }
if (ident->super_minor != UnSet && if (ident->super_minor != UnSet &&
(!super || ident->super_minor != info.array.md_minor)) { (!tst || !tst->sb ||
ident->super_minor != info.array.md_minor)) {
if ((inargv && verbose >= 0) || verbose > 0) if ((inargv && verbose >= 0) || verbose > 0)
fprintf(stderr, Name ": %s has wrong super-minor.\n", fprintf(stderr, Name ": %s has wrong super-minor.\n",
devname); devname);
goto loop; goto loop;
} }
if (ident->level != UnSet && if (ident->level != UnSet &&
(!super|| ident->level != info.array.level)) { (!tst || !tst->sb ||
ident->level != info.array.level)) {
if ((inargv && verbose >= 0) || verbose > 0) if ((inargv && verbose >= 0) || verbose > 0)
fprintf(stderr, Name ": %s has wrong raid level.\n", fprintf(stderr, Name ": %s has wrong raid level.\n",
devname); devname);
goto loop; goto loop;
} }
if (ident->raid_disks != UnSet && if (ident->raid_disks != UnSet &&
(!super || ident->raid_disks!= info.array.raid_disks)) { (!tst || !tst->sb ||
ident->raid_disks!= info.array.raid_disks)) {
if ((inargv && verbose >= 0) || verbose > 0) if ((inargv && verbose >= 0) || verbose > 0)
fprintf(stderr, Name ": %s requires wrong number of drives.\n", fprintf(stderr, Name ": %s requires wrong number of drives.\n",
devname); devname);
goto loop; goto loop;
} }
if (mdfd < 0) { if (mdfd < 0) {
if (tst == NULL || super == NULL) if (tst == NULL || tst->sb == NULL)
continue; continue;
if (update == NULL && if (update == NULL &&
tst->ss->match_home(tst, super, homehost)==0) { tst->ss->match_home(tst, homehost)==0) {
if ((inargv && verbose >= 0) || verbose > 0) if ((inargv && verbose >= 0) || verbose > 0)
fprintf(stderr, Name ": %s is not built for host %s.\n", fprintf(stderr, Name ": %s is not built for host %s.\n",
devname, homehost); devname, homehost);
@ -311,15 +315,17 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
* the other isn't that can disambiguate. * the other isn't that can disambiguate.
*/ */
if (!super) { if (!tst || !tst->sb) {
fprintf(stderr, Name ": %s has no superblock - assembly aborted\n", fprintf(stderr, Name ": %s has no superblock - assembly aborted\n",
devname); devname);
st->ss->free_super(st, first_super); st->ss->free_super(st);
return 1; return 1;
} }
if (st == NULL) if (st == NULL)
st = tst; st = dup_super(tst);
if (st->minor_version == -1)
st->minor_version = tst->minor_version;
if (st->ss != tst->ss || if (st->ss != tst->ss ||
st->minor_version != tst->minor_version || st->minor_version != tst->minor_version ||
st->ss->compare_super(st, tst) != 0) { st->ss->compare_super(st, tst) != 0) {
@ -331,10 +337,8 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
if (mdfd < 0) if (mdfd < 0)
goto loop; goto loop;
if (homehost) { if (homehost) {
int first = st->ss->match_home(st, first_super, int first = st->ss->match_home(st, homehost);
homehost); int last = tst->ss->match_home(tst, homehost);
int last = tst->ss->match_home(tst, super,
homehost);
if (first+last == 1) { if (first+last == 1) {
/* We can do something */ /* We can do something */
if (first) {/* just ignore this one */ if (first) {/* just ignore this one */
@ -357,17 +361,15 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
} }
fprintf(stderr, Name ": superblock on %s doesn't match others - assembly aborted\n", fprintf(stderr, Name ": superblock on %s doesn't match others - assembly aborted\n",
devname); devname);
tst->ss->free_super(tst, super); tst->ss->free_super(tst);
st->ss->free_super(st, first_super); st->ss->free_super(st);
return 1; return 1;
} }
tmpdev->used = 1; tmpdev->used = 1;
loop: loop:
if (super) tst->ss->free_super(tst);
tst->ss->free_super(tst, super);
super = NULL;
} }
if (mdfd < 0) { if (mdfd < 0) {
@ -377,10 +379,10 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
*/ */
mdu_array_info_t inf; mdu_array_info_t inf;
char *c; char *c;
if (!first_super) { if (!st->sb) {
return 2; return 2;
} }
st->ss->getinfo_super(st, &info, first_super); st->ss->getinfo_super(st, &info);
c = strchr(info.name, ':'); c = strchr(info.name, ':');
if (c) c++; else c= info.name; if (c) c++; else c= info.name;
if (isdigit(*c) && ((ident->autof & 7)==4 || (ident->autof&7)==6)) if (isdigit(*c) && ((ident->autof & 7)==4 || (ident->autof&7)==6))
@ -390,9 +392,8 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
asprintf(&mddev, "/dev/md/%s", c); asprintf(&mddev, "/dev/md/%s", c);
mdfd = open_mddev(mddev, ident->autof); mdfd = open_mddev(mddev, ident->autof);
if (mdfd < 0) { if (mdfd < 0) {
st->ss->free_super(st, first_super); st->ss->free_super(st);
free(devices); free(devices);
first_super = NULL;
goto try_again; goto try_again;
} }
vers = md_get_version(mdfd); vers = md_get_version(mdfd);
@ -407,9 +408,8 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
mddev, tmpdev->devname); mddev, tmpdev->devname);
close(mdfd); close(mdfd);
mdfd = -1; mdfd = -1;
st->ss->free_super(st, first_super); st->ss->free_super(st);
free(devices); free(devices);
first_super = NULL;
goto try_again; goto try_again;
} }
must_close = 1; must_close = 1;
@ -426,6 +426,7 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
int dfd; int dfd;
/* prepare useful information in info structures */ /* prepare useful information in info structures */
struct stat stb2; struct stat stb2;
struct supertype *tst;
fstat(mdfd, &stb2); fstat(mdfd, &stb2);
if (strcmp(update, "uuid")==0 && if (strcmp(update, "uuid")==0 &&
@ -444,16 +445,17 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
remove_partitions(dfd); remove_partitions(dfd);
st->ss->load_super(st, dfd, &super, NULL); tst = dup_super(st);
st->ss->getinfo_super(st, &info, super); tst->ss->load_super(tst, dfd, NULL);
tst->ss->getinfo_super(tst, &info);
memcpy(info.uuid, ident->uuid, 16); memcpy(info.uuid, ident->uuid, 16);
strcpy(info.name, ident->name); strcpy(info.name, ident->name);
info.array.md_minor = minor(stb2.st_rdev); info.array.md_minor = minor(stb2.st_rdev);
st->ss->update_super(st, &info, super, update, tst->ss->update_super(tst, &info, update,
devname, verbose, devname, verbose,
ident->uuid_set, homehost); ident->uuid_set, homehost);
if (strcmp(update, "uuid")==0 && if (strcmp(update, "uuid")==0 &&
!ident->uuid_set) { !ident->uuid_set) {
ident->uuid_set = 1; ident->uuid_set = 1;
@ -462,7 +464,7 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
if (dfd < 0) if (dfd < 0)
fprintf(stderr, Name ": Cannot open %s for superblock update\n", fprintf(stderr, Name ": Cannot open %s for superblock update\n",
devname); devname);
else if (st->ss->store_super(st, dfd, super)) else if (tst->ss->store_super(tst, dfd))
fprintf(stderr, Name ": Could not re-write superblock on %s.\n", fprintf(stderr, Name ": Could not re-write superblock on %s.\n",
devname); devname);
if (dfd >= 0) if (dfd >= 0)
@ -470,21 +472,26 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
if (strcmp(update, "uuid")==0 && if (strcmp(update, "uuid")==0 &&
ident->bitmap_fd >= 0 && !bitmap_done) { ident->bitmap_fd >= 0 && !bitmap_done) {
if (bitmap_update_uuid(ident->bitmap_fd, info.uuid, st->ss->swapuuid) != 0) if (bitmap_update_uuid(ident->bitmap_fd,
info.uuid,
tst->ss->swapuuid) != 0)
fprintf(stderr, Name ": Could not update uuid on external bitmap.\n"); fprintf(stderr, Name ": Could not update uuid on external bitmap.\n");
else else
bitmap_done = 1; bitmap_done = 1;
} }
tst->ss->free_super(tst);
} else } else
#endif #endif
{ {
struct supertype *tst = dup_super(st);;
int dfd; int dfd;
dfd = dev_open(devname, O_RDWR|O_EXCL); dfd = dev_open(devname, O_RDWR|O_EXCL);
remove_partitions(dfd); remove_partitions(dfd);
st->ss->load_super(st, dfd, &super, NULL); tst->ss->load_super(tst, dfd, NULL);
st->ss->getinfo_super(st, &info, super); tst->ss->getinfo_super(tst, &info);
tst->ss->free_super(tst);
close(dfd); close(dfd);
} }
@ -563,10 +570,6 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
best[i] = devcnt; best[i] = devcnt;
} }
devcnt++; devcnt++;
if (super)
st->ss->free_super(st, super);
super = NULL;
} }
if (update && strcmp(update, "byteorder")==0) if (update && strcmp(update, "byteorder")==0)
@ -575,12 +578,12 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
if (devcnt == 0) { if (devcnt == 0) {
fprintf(stderr, Name ": no devices found for %s\n", fprintf(stderr, Name ": no devices found for %s\n",
mddev); mddev);
st->ss->free_super(st, first_super); st->ss->free_super(st);
if (must_close) close(mdfd); if (must_close) close(mdfd);
return 1; return 1;
} }
st->ss->getinfo_super(st, &info, first_super); st->ss->getinfo_super(st, &info);
clean = info.array.state & 1; clean = info.array.state & 1;
/* now we have some devices that might be suitable. /* now we have some devices that might be suitable.
@ -623,6 +626,7 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
* and add it. * and add it.
*/ */
int fd; int fd;
struct supertype *tst;
long long current_events; long long current_events;
chosen_drive = -1; chosen_drive = -1;
for (i=0; i<info.array.raid_disks && i < bestcnt; i++) { for (i=0; i<info.array.raid_disks && i < bestcnt; i++) {
@ -650,7 +654,8 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
devices[chosen_drive].events = 0; devices[chosen_drive].events = 0;
continue; continue;
} }
if (st->ss->load_super(st,fd, &super, NULL)) { tst = dup_super(st);
if (tst->ss->load_super(st,fd, NULL)) {
close(fd); close(fd);
fprintf(stderr, Name ": RAID superblock disappeared from %s - not updating.\n", fprintf(stderr, Name ": RAID superblock disappeared from %s - not updating.\n",
devices[chosen_drive].devname); devices[chosen_drive].devname);
@ -658,16 +663,16 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
continue; continue;
} }
info.events = devices[most_recent].events; info.events = devices[most_recent].events;
st->ss->update_super(st, &info, super, "force-one", tst->ss->update_super(tst, &info, "force-one",
devices[chosen_drive].devname, verbose, devices[chosen_drive].devname, verbose,
0, NULL); 0, NULL);
if (st->ss->store_super(st, fd, super)) { if (tst->ss->store_super(tst, fd)) {
close(fd); close(fd);
fprintf(stderr, Name ": Could not re-write superblock on %s\n", fprintf(stderr, Name ": Could not re-write superblock on %s\n",
devices[chosen_drive].devname); devices[chosen_drive].devname);
devices[chosen_drive].events = 0; devices[chosen_drive].events = 0;
st->ss->free_super(st, super); tst->ss->free_super(tst);
continue; continue;
} }
close(fd); close(fd);
@ -675,7 +680,7 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
devices[chosen_drive].uptodate = 1; devices[chosen_drive].uptodate = 1;
avail[chosen_drive] = 1; avail[chosen_drive] = 1;
okcnt++; okcnt++;
st->ss->free_super(st, super); tst->ss->free_super(tst);
/* If there are any other drives of the same vintage, /* If there are any other drives of the same vintage,
* add them in as well. We can't lose and we might gain * add them in as well. We can't lose and we might gain
@ -699,7 +704,7 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
* superblock. * superblock.
*/ */
chosen_drive = -1; chosen_drive = -1;
super = NULL; st->ss->free_super(st);
for (i=0; chosen_drive < 0 && i<bestcnt; i++) { for (i=0; chosen_drive < 0 && i<bestcnt; i++) {
int j = best[i]; int j = best[i];
int fd; int fd;
@ -715,7 +720,7 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
if (must_close) close(mdfd); if (must_close) close(mdfd);
return 1; return 1;
} }
if (st->ss->load_super(st,fd, &super, NULL)) { if (st->ss->load_super(st,fd, NULL)) {
close(fd); close(fd);
fprintf(stderr, Name ": RAID superblock has disappeared from %s\n", fprintf(stderr, Name ": RAID superblock has disappeared from %s\n",
devices[j].devname); devices[j].devname);
@ -724,12 +729,12 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
} }
close(fd); close(fd);
} }
if (super == NULL) { if (st->sb == NULL) {
fprintf(stderr, Name ": No suitable drives found for %s\n", mddev); fprintf(stderr, Name ": No suitable drives found for %s\n", mddev);
if (must_close) close(mdfd); if (must_close) close(mdfd);
return 1; return 1;
} }
st->ss->getinfo_super(st, &info, super); st->ss->getinfo_super(st, &info);
for (i=0; i<bestcnt; i++) { for (i=0; i<bestcnt; i++) {
int j = best[i]; int j = best[i];
unsigned int desired_state; unsigned int desired_state;
@ -748,7 +753,7 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
info.disk.state = desired_state; info.disk.state = desired_state;
if (devices[j].uptodate && if (devices[j].uptodate &&
st->ss->update_super(st, &info, super, "assemble", NULL, st->ss->update_super(st, &info, "assemble", NULL,
verbose, 0, NULL)) { verbose, 0, NULL)) {
if (force) { if (force) {
if (verbose >= 0) if (verbose >= 0)
@ -775,7 +780,7 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
!enough(info.array.level, info.array.raid_disks, !enough(info.array.level, info.array.raid_disks,
info.array.layout, clean, info.array.layout, clean,
avail, okcnt)) { avail, okcnt)) {
change += st->ss->update_super(st, &info, super, "force-array", change += st->ss->update_super(st, &info, "force-array",
devices[chosen_drive].devname, verbose, devices[chosen_drive].devname, verbose,
0, NULL); 0, NULL);
clean = 1; clean = 1;
@ -790,7 +795,7 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
if (must_close) close(mdfd); if (must_close) close(mdfd);
return 1; return 1;
} }
if (st->ss->store_super(st, fd, super)) { if (st->ss->store_super(st, fd)) {
close(fd); close(fd);
fprintf(stderr, Name ": Could not re-write superblock on %s\n", fprintf(stderr, Name ": Could not re-write superblock on %s\n",
devices[chosen_drive].devname); devices[chosen_drive].devname);

View File

@ -65,7 +65,6 @@ int Create(struct supertype *st, char *mddev, int mdfd,
int first_missing = subdevs * 2; int first_missing = subdevs * 2;
int missing_disks = 0; int missing_disks = 0;
int insert_point = subdevs * 2; /* where to insert a missing drive */ int insert_point = subdevs * 2; /* where to insert a missing drive */
void *super;
int pass; int pass;
int vers; int vers;
int rv; int rv;
@ -434,7 +433,7 @@ int Create(struct supertype *st, char *mddev, int mdfd,
name += 2; name += 2;
} }
} }
if (!st->ss->init_super(st, &super, &array, size, name, homehost, uuid)) if (!st->ss->init_super(st, &array, size, name, homehost, uuid))
return 1; return 1;
if (bitmap_file && vers < 9003) { if (bitmap_file && vers < 9003) {
@ -450,7 +449,7 @@ int Create(struct supertype *st, char *mddev, int mdfd,
fprintf(stderr, Name ": internal bitmaps not supported by this kernel.\n"); fprintf(stderr, Name ": internal bitmaps not supported by this kernel.\n");
return 1; return 1;
} }
if (!st->ss->add_internal_bitmap(st, super, &bitmap_chunk, if (!st->ss->add_internal_bitmap(st, &bitmap_chunk,
delay, write_behind, delay, write_behind,
bitmapsize, 1, major_num)) { bitmapsize, 1, major_num)) {
fprintf(stderr, Name ": Given bitmap chunk size not supported.\n"); fprintf(stderr, Name ": Given bitmap chunk size not supported.\n");
@ -478,7 +477,7 @@ int Create(struct supertype *st, char *mddev, int mdfd,
if (bitmap_file) { if (bitmap_file) {
int uuid[4]; int uuid[4];
st->ss->uuid_from_super(st, uuid, super); st->ss->uuid_from_super(st, uuid);
if (CreateBitmap(bitmap_file, force, (char*)uuid, bitmap_chunk, if (CreateBitmap(bitmap_file, force, (char*)uuid, bitmap_chunk,
delay, write_behind, delay, write_behind,
bitmapsize, bitmapsize,
@ -542,18 +541,19 @@ int Create(struct supertype *st, char *mddev, int mdfd,
} }
switch(pass){ switch(pass){
case 1: case 1:
st->ss->add_to_super(st, super, &disk); st->ss->add_to_super(st, &disk);
break; break;
case 2: case 2:
if (disk.state == 1) break; if (disk.state == 1) break;
Kill(dv->devname, 0, 1); /* Just be sure it is clean */ Kill(dv->devname, 0, 1); /* Just be sure it is clean */
Kill(dv->devname, 0, 1); /* and again, there could be two superblocks */ Kill(dv->devname, 0, 1); /* and again, there could be two superblocks */
st->ss->write_init_super(st, super, &disk, dv->devname); st->ss->write_init_super(st, &disk,
dv->devname);
if (ioctl(mdfd, ADD_NEW_DISK, &disk)) { if (ioctl(mdfd, ADD_NEW_DISK, &disk)) {
fprintf(stderr, Name ": ADD_NEW_DISK for %s failed: %s\n", fprintf(stderr, Name ": ADD_NEW_DISK for %s failed: %s\n",
dv->devname, strerror(errno)); dv->devname, strerror(errno));
st->ss->free_super(st, super); st->ss->free_super(st);
return 1; return 1;
} }
@ -562,7 +562,7 @@ int Create(struct supertype *st, char *mddev, int mdfd,
if (dv == moved_disk && dnum != insert_point) break; if (dv == moved_disk && dnum != insert_point) break;
} }
} }
st->ss->free_super(st, super); st->ss->free_super(st);
/* param is not actually used */ /* param is not actually used */
if (runstop == 1 || subdevs >= raiddisks) { if (runstop == 1 || subdevs >= raiddisks) {

View File

@ -56,7 +56,6 @@ int Detail(char *dev, int brief, int export, int test, char *homehost)
int max_disks = MD_SB_DISKS; /* just a default */ int max_disks = MD_SB_DISKS; /* just a default */
struct mdinfo info; struct mdinfo info;
void *super = NULL;
int rv = test ? 4 : 1; int rv = test ? 4 : 1;
int avail_disks = 0; int avail_disks = 0;
char *avail; char *avail;
@ -109,19 +108,18 @@ int Detail(char *dev, int brief, int export, int test, char *homehost)
disk.minor == 0) disk.minor == 0)
continue; continue;
if ((dv=map_dev(disk.major, disk.minor, 1))) { if ((dv=map_dev(disk.major, disk.minor, 1))) {
if (!super && (disk.state & (1<<MD_DISK_ACTIVE))) { if ((!st || !st->sb) &&
(disk.state & (1<<MD_DISK_ACTIVE))) {
/* try to read the superblock from this device /* try to read the superblock from this device
* to get more info * to get more info
*/ */
int fd2 = dev_open(dv, O_RDONLY); int fd2 = dev_open(dv, O_RDONLY);
if (fd2 >=0 && st && if (fd2 >=0 && st &&
st->ss->load_super(st, fd2, &super, NULL) == 0) { st->ss->load_super(st, fd2, NULL) == 0) {
st->ss->getinfo_super(st, &info, super); st->ss->getinfo_super(st, &info);
if (info.array.ctime != array.ctime || if (info.array.ctime != array.ctime ||
info.array.level != array.level) { info.array.level != array.level)
st->ss->free_super(st, super); st->ss->free_super(st);
super = NULL;
}
} }
if (fd2 >= 0) close(fd2); if (fd2 >= 0) close(fd2);
} }
@ -137,8 +135,8 @@ int Detail(char *dev, int brief, int export, int test, char *homehost)
printf("MD_DEVICES=%d\n", array.raid_disks); printf("MD_DEVICES=%d\n", array.raid_disks);
printf("MD_METADATA=%d.%d\n", array.major_version, printf("MD_METADATA=%d.%d\n", array.major_version,
array.minor_version); array.minor_version);
if (super) if (st && st->sb)
st->ss->export_super(st, super); st->ss->export_super(st);
goto out; goto out;
} }
@ -236,13 +234,14 @@ int Detail(char *dev, int brief, int export, int test, char *homehost)
if (e && e->percent >= 0) { if (e && e->percent >= 0) {
printf(" Re%s Status : %d%% complete\n", printf(" Re%s Status : %d%% complete\n",
(super && info.reshape_active)? "shape":"build", (st && st->sb && info.reshape_active)?
"shape":"build",
e->percent); e->percent);
is_rebuilding = 1; is_rebuilding = 1;
} }
free_mdstat(ms); free_mdstat(ms);
if (super && info.reshape_active) { if (st->sb && info.reshape_active) {
#if 0 #if 0
This is pretty boring This is pretty boring
printf(" Reshape pos'n : %llu%s\n", (unsigned long long) info.reshape_progress<<9, printf(" Reshape pos'n : %llu%s\n", (unsigned long long) info.reshape_progress<<9,
@ -277,8 +276,8 @@ This is pretty boring
printf("\n"); printf("\n");
} else if (e && e->percent >= 0) } else if (e && e->percent >= 0)
printf("\n"); printf("\n");
if (super && st) if (st && st->sb)
st->ss->detail_super(st, super, homehost); st->ss->detail_super(st, homehost);
printf(" Number Major Minor RaidDevice State\n"); printf(" Number Major Minor RaidDevice State\n");
} }
@ -376,10 +375,9 @@ This is pretty boring
if (!brief) printf("\n"); if (!brief) printf("\n");
} }
if (spares && brief) printf(" spares=%d", spares); if (spares && brief) printf(" spares=%d", spares);
if (super && brief && st) if (brief && st && st->sb)
st->ss->brief_detail_super(st, super); st->ss->brief_detail_super(st);
if (super) st->ss->free_super(st);
st->ss->free_super(st, super);
if (brief > 1 && devices) printf("\n devices=%s", devices); if (brief > 1 && devices) printf("\n devices=%s", devices);
if (brief) printf("\n"); if (brief) printf("\n");

View File

@ -56,12 +56,10 @@ int Examine(mddev_dev_t devlist, int brief, int scan,
* if devlist==NULL, use conf_get_devs() * if devlist==NULL, use conf_get_devs()
*/ */
int fd; int fd;
void *super = NULL;
int rv = 0; int rv = 0;
int err = 0; int err = 0;
struct array { struct array {
void *super;
struct supertype *st; struct supertype *st;
struct mdinfo info; struct mdinfo info;
void *devs; void *devs;
@ -85,7 +83,9 @@ int Examine(mddev_dev_t devlist, int brief, int scan,
if (!st) if (!st)
st = guess_super(fd); st = guess_super(fd);
if (st) if (st)
err = st->ss->load_super(st, fd, &super, (brief||scan)?NULL:devlist->devname); err = st->ss->load_super(st, fd,
(brief||scan) ? NULL
:devlist->devname);
else { else {
if (!brief) { if (!brief) {
fprintf(stderr, Name ": No md superblock detected on %s.\n", devlist->devname); fprintf(stderr, Name ": No md superblock detected on %s.\n", devlist->devname);
@ -99,7 +99,7 @@ int Examine(mddev_dev_t devlist, int brief, int scan,
continue; continue;
if (SparcAdjust) if (SparcAdjust)
st->ss->update_super(st, NULL, super, "sparc2.2", st->ss->update_super(st, NULL, "sparc2.2",
devlist->devname, 0, 0, NULL); devlist->devname, 0, 0, NULL);
/* Ok, its good enough to try, though the checksum could be wrong */ /* Ok, its good enough to try, though the checksum could be wrong */
if (brief) { if (brief) {
@ -112,16 +112,15 @@ int Examine(mddev_dev_t devlist, int brief, int scan,
} }
if (!ap) { if (!ap) {
ap = malloc(sizeof(*ap)); ap = malloc(sizeof(*ap));
ap->super = super;
ap->devs = dl_head(); ap->devs = dl_head();
ap->next = arrays; ap->next = arrays;
ap->spares = 0; ap->spares = 0;
ap->st = st; ap->st = st;
arrays = ap; arrays = ap;
st->ss->getinfo_super(st, &ap->info, super); st->ss->getinfo_super(st, &ap->info);
} else { } else {
st->ss->getinfo_super(st, &ap->info, super); st->ss->getinfo_super(st, &ap->info);
st->ss->free_super(st, super); st->ss->free_super(st);
} }
if (!(ap->info.disk.state & MD_DISK_SYNC)) if (!(ap->info.disk.state & MD_DISK_SYNC))
ap->spares++; ap->spares++;
@ -129,8 +128,8 @@ int Examine(mddev_dev_t devlist, int brief, int scan,
dl_add(ap->devs, d); dl_add(ap->devs, d);
} else { } else {
printf("%s:\n",devlist->devname); printf("%s:\n",devlist->devname);
st->ss->examine_super(st, super, homehost); st->ss->examine_super(st, homehost);
st->ss->free_super(st, super); st->ss->free_super(st);
} }
} }
if (brief) { if (brief) {
@ -138,7 +137,7 @@ int Examine(mddev_dev_t devlist, int brief, int scan,
for (ap=arrays; ap; ap=ap->next) { for (ap=arrays; ap; ap=ap->next) {
char sep='='; char sep='=';
char *d; char *d;
ap->st->ss->brief_examine_super(ap->st, ap->super); ap->st->ss->brief_examine_super(ap->st);
if (ap->spares) printf(" spares=%d", ap->spares); if (ap->spares) printf(" spares=%d", ap->spares);
if (brief > 1) { if (brief > 1) {
printf(" devices"); printf(" devices");
@ -147,7 +146,7 @@ int Examine(mddev_dev_t devlist, int brief, int scan,
sep=','; sep=',';
} }
} }
ap->st->ss->free_super(ap->st, ap->super); ap->st->ss->free_super(ap->st);
/* FIXME free ap */ /* FIXME free ap */
if (ap->spares || brief > 1) if (ap->spares || brief > 1)
printf("\n"); printf("\n");

61
Grow.c
View File

@ -47,7 +47,6 @@ int Grow_Add_device(char *devname, int fd, char *newdev)
*/ */
struct mdinfo info; struct mdinfo info;
void *super = NULL;
struct stat stb; struct stat stb;
int nfd, fd2; int nfd, fd2;
int d, nd; int d, nd;
@ -103,10 +102,9 @@ int Grow_Add_device(char *devname, int fd, char *newdev)
fprintf(stderr, Name ": cannot open device file %s\n", dv); fprintf(stderr, Name ": cannot open device file %s\n", dv);
return 1; return 1;
} }
if (super) st->ss->free_super(st);
st->ss->free_super(st, super);
super= NULL; if (st->ss->load_super(st, fd2, NULL)) {
if (st->ss->load_super(st, fd2, &super, NULL)) {
fprintf(stderr, Name ": cannot find super block on %s\n", dv); fprintf(stderr, Name ": cannot find super block on %s\n", dv);
close(fd2); close(fd2);
return 1; return 1;
@ -122,10 +120,10 @@ int Grow_Add_device(char *devname, int fd, char *newdev)
info.disk.minor = minor(stb.st_rdev); info.disk.minor = minor(stb.st_rdev);
info.disk.raid_disk = d; info.disk.raid_disk = d;
info.disk.state = (1 << MD_DISK_SYNC) | (1 << MD_DISK_ACTIVE); info.disk.state = (1 << MD_DISK_SYNC) | (1 << MD_DISK_ACTIVE);
st->ss->update_super(st, &info, super, "linear-grow-new", newdev, st->ss->update_super(st, &info, "linear-grow-new", newdev,
0, 0, NULL); 0, 0, NULL);
if (st->ss->store_super(st, nfd, super)) { if (st->ss->store_super(st, nfd)) {
fprintf(stderr, Name ": Cannot store new superblock on %s\n", fprintf(stderr, Name ": Cannot store new superblock on %s\n",
newdev); newdev);
close(nfd); close(nfd);
@ -168,7 +166,7 @@ int Grow_Add_device(char *devname, int fd, char *newdev)
fprintf(stderr, Name ": cannot open device file %s\n", dv); fprintf(stderr, Name ": cannot open device file %s\n", dv);
return 1; return 1;
} }
if (st->ss->load_super(st, fd2, &super, NULL)) { if (st->ss->load_super(st, fd2, NULL)) {
fprintf(stderr, Name ": cannot find super block on %s\n", dv); fprintf(stderr, Name ": cannot find super block on %s\n", dv);
close(fd); close(fd);
return 1; return 1;
@ -178,10 +176,10 @@ int Grow_Add_device(char *devname, int fd, char *newdev)
info.array.active_disks = nd+1; info.array.active_disks = nd+1;
info.array.working_disks = nd+1; info.array.working_disks = nd+1;
st->ss->update_super(st, &info, super, "linear-grow-update", dv, st->ss->update_super(st, &info, "linear-grow-update", dv,
0, 0, NULL); 0, 0, NULL);
if (st->ss->store_super(st, fd2, super)) { if (st->ss->store_super(st, fd2)) {
fprintf(stderr, Name ": Cannot store new superblock on %s\n", dv); fprintf(stderr, Name ": Cannot store new superblock on %s\n", dv);
close(fd2); close(fd2);
return 1; return 1;
@ -303,17 +301,16 @@ int Grow_addbitmap(char *devname, int fd, char *file, int chunk, int delay, int
continue; continue;
dv = map_dev(disk.major, disk.minor, 1); dv = map_dev(disk.major, disk.minor, 1);
if (dv) { if (dv) {
void *super;
int fd2 = dev_open(dv, O_RDWR); int fd2 = dev_open(dv, O_RDWR);
if (fd2 < 0) if (fd2 < 0)
continue; continue;
if (st->ss->load_super(st, fd2, &super, NULL)==0) { if (st->ss->load_super(st, fd2, NULL)==0) {
if (st->ss->add_internal_bitmap( if (st->ss->add_internal_bitmap(
st, super, st,
&chunk, delay, write_behind, &chunk, delay, write_behind,
bitmapsize, 0, major) bitmapsize, 0, major)
) )
st->ss->write_bitmap(st, fd2, super); st->ss->write_bitmap(st, fd2);
else { else {
fprintf(stderr, Name ": failed to create internal bitmap - chunksize problem.\n"); fprintf(stderr, Name ": failed to create internal bitmap - chunksize problem.\n");
close(fd2); close(fd2);
@ -333,7 +330,6 @@ int Grow_addbitmap(char *devname, int fd, char *file, int chunk, int delay, int
int bitmap_fd; int bitmap_fd;
int d; int d;
int max_devs = st->max_devs; int max_devs = st->max_devs;
void *super = NULL;
/* try to load a superblock */ /* try to load a superblock */
for (d=0; d<max_devs; d++) { for (d=0; d<max_devs; d++) {
@ -350,9 +346,9 @@ int Grow_addbitmap(char *devname, int fd, char *file, int chunk, int delay, int
if (!dv) continue; if (!dv) continue;
fd2 = dev_open(dv, O_RDONLY); fd2 = dev_open(dv, O_RDONLY);
if (fd2 >= 0 && if (fd2 >= 0 &&
st->ss->load_super(st, fd2, &super, NULL) == 0) { st->ss->load_super(st, fd2, NULL) == 0) {
close(fd2); close(fd2);
st->ss->uuid_from_super(st, uuid, super); st->ss->uuid_from_super(st, uuid);
break; break;
} }
close(fd2); close(fd2);
@ -438,7 +434,6 @@ int Grow_reshape(char *devname, int fd, int quiet, char *backup_file,
int d, i, spares; int d, i, spares;
int nrdisks; int nrdisks;
int err; int err;
void *super = NULL;
struct sysarray *sra; struct sysarray *sra;
struct sysdev *sd; struct sysdev *sd;
@ -704,7 +699,7 @@ int Grow_reshape(char *devname, int fd, int quiet, char *backup_file,
} }
/* Find a superblock */ /* Find a superblock */
if (st->ss->load_super(st, fdlist[0], &super, NULL)) { if (st->ss->load_super(st, fdlist[0], NULL)) {
fprintf(stderr, Name ": %s: Cannot find a superblock\n", fprintf(stderr, Name ": %s: Cannot find a superblock\n",
devname); devname);
goto abort; goto abort;
@ -712,7 +707,7 @@ int Grow_reshape(char *devname, int fd, int quiet, char *backup_file,
memcpy(bsb.magic, "md_backup_data-1", 16); memcpy(bsb.magic, "md_backup_data-1", 16);
st->ss->uuid_from_super(st, (int*)&bsb.set_uuid, super); st->ss->uuid_from_super(st, (int*)&bsb.set_uuid);
bsb.mtime = __cpu_to_le64(time(0)); bsb.mtime = __cpu_to_le64(time(0));
bsb.arraystart = 0; bsb.arraystart = 0;
bsb.length = __cpu_to_le64(last_block); bsb.length = __cpu_to_le64(last_block);
@ -882,7 +877,6 @@ int Grow_restart(struct supertype *st, struct mdinfo *info, int *fdlist, int cnt
old_disks = info->array.raid_disks - info->delta_disks; old_disks = info->array.raid_disks - info->delta_disks;
for (i=old_disks-(backup_file?1:0); i<cnt; i++) { for (i=old_disks-(backup_file?1:0); i<cnt; i++) {
void *super = NULL;
struct mdinfo dinfo; struct mdinfo dinfo;
struct mdp_backup_super bsb; struct mdp_backup_super bsb;
char buf[4096]; char buf[4096];
@ -903,12 +897,12 @@ int Grow_restart(struct supertype *st, struct mdinfo *info, int *fdlist, int cnt
fd = fdlist[i]; fd = fdlist[i];
if (fd < 0) if (fd < 0)
continue; continue;
if (st->ss->load_super(st, fd, &super, NULL)) if (st->ss->load_super(st, fd, NULL))
continue; continue;
st->ss->getinfo_super(st, &dinfo, super); st->ss->getinfo_super(st, &dinfo);
st->ss->free_super(st, super); st->ss->free_super(st);
super = NULL;
if (lseek64(fd, if (lseek64(fd,
(dinfo.data_offset + dinfo.component_size - 8) <<9, (dinfo.data_offset + dinfo.component_size - 8) <<9,
0) < 0) 0) < 0)
@ -946,12 +940,11 @@ int Grow_restart(struct supertype *st, struct mdinfo *info, int *fdlist, int cnt
for(j=0; j<info->array.raid_disks; j++) { for(j=0; j<info->array.raid_disks; j++) {
if (fdlist[j] < 0) if (fdlist[j] < 0)
continue; continue;
if (st->ss->load_super(st, fdlist[j], &super, NULL)) if (st->ss->load_super(st, fdlist[j], NULL))
/* FIXME should be this be an error */ /* FIXME should be this be an error */
continue; continue;
st->ss->getinfo_super(st, &dinfo, super); st->ss->getinfo_super(st, &dinfo);
st->ss->free_super(st, super); st->ss->free_super(st);
super = NULL;
offsets[j] = dinfo.data_offset; offsets[j] = dinfo.data_offset;
} }
printf(Name ": restoring critical section\n"); printf(Name ": restoring critical section\n");
@ -971,15 +964,15 @@ int Grow_restart(struct supertype *st, struct mdinfo *info, int *fdlist, int cnt
for (j=0; j<info->array.raid_disks; j++) { for (j=0; j<info->array.raid_disks; j++) {
if (fdlist[j] < 0) continue; if (fdlist[j] < 0) continue;
if (st->ss->load_super(st, fdlist[j], &super, NULL)) if (st->ss->load_super(st, fdlist[j], NULL))
continue; continue;
st->ss->getinfo_super(st, &dinfo, super); st->ss->getinfo_super(st, &dinfo);
dinfo.reshape_progress = __le64_to_cpu(bsb.length); dinfo.reshape_progress = __le64_to_cpu(bsb.length);
st->ss->update_super(st, &dinfo, super, st->ss->update_super(st, &dinfo,
"_reshape_progress", "_reshape_progress",
NULL,0, 0, NULL); NULL,0, 0, NULL);
st->ss->store_super(st, fdlist[j], super); st->ss->store_super(st, fdlist[j]);
st->ss->free_super(st, super); st->ss->free_super(st);
} }
/* And we are done! */ /* And we are done! */

View File

@ -74,7 +74,6 @@ int Incremental(char *devname, int verbose, int runstop,
* start the array (auto-readonly). * start the array (auto-readonly).
*/ */
struct stat stb; struct stat stb;
void *super, *super2;
struct mdinfo info, info2; struct mdinfo info, info2;
struct mddev_ident_s *array_list, *match; struct mddev_ident_s *array_list, *match;
char chosen_name[1024]; char chosen_name[1024];
@ -134,14 +133,14 @@ int Incremental(char *devname, int verbose, int runstop,
close(dfd); close(dfd);
return 1; return 1;
} }
if (st->ss->load_super(st, dfd, &super, NULL)) { if (st->ss->load_super(st, dfd, NULL)) {
if (verbose >= 0) if (verbose >= 0)
fprintf(stderr, Name ": no RAID superblock on %s.\n", fprintf(stderr, Name ": no RAID superblock on %s.\n",
devname); devname);
close(dfd); close(dfd);
return 1; return 1;
} }
st->ss->getinfo_super(st, &info, super); st->ss->getinfo_super(st, &info);
close (dfd); close (dfd);
/* 3/ Check if there is a match in mdadm.conf */ /* 3/ Check if there is a match in mdadm.conf */
@ -207,7 +206,7 @@ int Incremental(char *devname, int verbose, int runstop,
/* 3a/ if not, check for homehost match. If no match, reject. */ /* 3a/ if not, check for homehost match. If no match, reject. */
if (!match) { if (!match) {
if (homehost == NULL || if (homehost == NULL ||
st->ss->match_home(st, super, homehost) == 0) { st->ss->match_home(st, homehost) == 0) {
if (verbose >= 0) if (verbose >= 0)
fprintf(stderr, Name fprintf(stderr, Name
": not found in mdadm.conf and not identified by homehost.\n"); ": not found in mdadm.conf and not identified by homehost.\n");
@ -330,6 +329,7 @@ int Incremental(char *devname, int verbose, int runstop,
mdu_disk_info_t disk; mdu_disk_info_t disk;
int err; int err;
struct sysarray *sra; struct sysarray *sra;
struct supertype *st2;
sra = sysfs_read(mdfd, devnum, (GET_VERSION | GET_DEVS | sra = sysfs_read(mdfd, devnum, (GET_VERSION | GET_DEVS |
GET_STATE)); GET_STATE));
if (sra->major_version != st->ss->major || if (sra->major_version != st->ss->major ||
@ -345,7 +345,8 @@ int Incremental(char *devname, int verbose, int runstop,
} }
sprintf(dn, "%d:%d", sra->devs->major, sra->devs->minor); sprintf(dn, "%d:%d", sra->devs->major, sra->devs->minor);
dfd2 = dev_open(dn, O_RDONLY); dfd2 = dev_open(dn, O_RDONLY);
if (st->ss->load_super(st, dfd2,&super2, NULL)) { st2 = dup_super(st);
if (st2->ss->load_super(st2, dfd2, NULL)) {
fprintf(stderr, Name fprintf(stderr, Name
": Strange error loading metadata for %s.\n", ": Strange error loading metadata for %s.\n",
chosen_name); chosen_name);
@ -354,7 +355,8 @@ int Incremental(char *devname, int verbose, int runstop,
return 2; return 2;
} }
close(dfd2); close(dfd2);
st->ss->getinfo_super(st, &info2, super2); st2->ss->getinfo_super(st2, &info2);
st2->ss->free_super(st2);
if (info.array.level != info2.array.level || if (info.array.level != info2.array.level ||
memcmp(info.uuid, info2.uuid, 16) != 0 || memcmp(info.uuid, info2.uuid, 16) != 0 ||
info.array.raid_disks != info2.array.raid_disks) { info.array.raid_disks != info2.array.raid_disks) {
@ -478,7 +480,7 @@ static void find_reject(int mdfd, struct supertype *st, struct sysarray *sra,
int number, __u64 events, int verbose, int number, __u64 events, int verbose,
char *array_name) char *array_name)
{ {
/* Find an device attached to this array with a disk.number of number /* Find a device attached to this array with a disk.number of number
* and events less than the passed events, and remove the device. * and events less than the passed events, and remove the device.
*/ */
struct sysdev *d; struct sysdev *d;
@ -491,18 +493,17 @@ static void find_reject(int mdfd, struct supertype *st, struct sysarray *sra,
for (d = sra->devs; d ; d = d->next) { for (d = sra->devs; d ; d = d->next) {
char dn[10]; char dn[10];
int dfd; int dfd;
void *super;
struct mdinfo info; struct mdinfo info;
sprintf(dn, "%d:%d", d->major, d->minor); sprintf(dn, "%d:%d", d->major, d->minor);
dfd = dev_open(dn, O_RDONLY); dfd = dev_open(dn, O_RDONLY);
if (dfd < 0) if (dfd < 0)
continue; continue;
if (st->ss->load_super(st, dfd, &super, NULL)) { if (st->ss->load_super(st, dfd, NULL)) {
close(dfd); close(dfd);
continue; continue;
} }
st->ss->getinfo_super(st, &info, super); st->ss->getinfo_super(st, &info);
st->ss->free_super(st, super); st->ss->free_super(st);
close(dfd); close(dfd);
if (info.disk.number != number || if (info.disk.number != number ||
@ -526,14 +527,12 @@ static int count_active(struct supertype *st, int mdfd, char **availp,
struct sysdev *d; struct sysdev *d;
int cnt = 0, cnt1 = 0; int cnt = 0, cnt1 = 0;
__u64 max_events = 0; __u64 max_events = 0;
void *best_super = NULL;
struct sysarray *sra = sysfs_read(mdfd, -1, GET_DEVS | GET_STATE); struct sysarray *sra = sysfs_read(mdfd, -1, GET_DEVS | GET_STATE);
char *avail = NULL; char *avail = NULL;
for (d = sra->devs ; d ; d = d->next) { for (d = sra->devs ; d ; d = d->next) {
char dn[30]; char dn[30];
int dfd; int dfd;
void *super;
int ok; int ok;
struct mdinfo info; struct mdinfo info;
@ -541,11 +540,11 @@ static int count_active(struct supertype *st, int mdfd, char **availp,
dfd = dev_open(dn, O_RDONLY); dfd = dev_open(dn, O_RDONLY);
if (dfd < 0) if (dfd < 0)
continue; continue;
ok = st->ss->load_super(st, dfd, &super, NULL); ok = st->ss->load_super(st, dfd, NULL);
close(dfd); close(dfd);
if (ok != 0) if (ok != 0)
continue; continue;
st->ss->getinfo_super(st, &info, super); st->ss->getinfo_super(st, &info);
if (info.disk.state & (1<<MD_DISK_SYNC)) if (info.disk.state & (1<<MD_DISK_SYNC))
{ {
if (avail == NULL) { if (avail == NULL) {
@ -556,7 +555,7 @@ static int count_active(struct supertype *st, int mdfd, char **availp,
cnt++; cnt++;
max_events = info.events; max_events = info.events;
avail[info.disk.raid_disk] = 2; avail[info.disk.raid_disk] = 2;
best_super = super; super = NULL; st->ss->getinfo_super(st, bestinfo);
} else if (info.events == max_events) { } else if (info.events == max_events) {
cnt++; cnt++;
avail[info.disk.raid_disk] = 2; avail[info.disk.raid_disk] = 2;
@ -574,24 +573,15 @@ static int count_active(struct supertype *st, int mdfd, char **availp,
if (avail[i]) if (avail[i])
avail[i]--; avail[i]--;
avail[info.disk.raid_disk] = 2; avail[info.disk.raid_disk] = 2;
st->ss->free_super(st, best_super); st->ss->getinfo_super(st, bestinfo);
best_super = super;
super = NULL;
} else { /* info.events much bigger */ } else { /* info.events much bigger */
cnt = 1; cnt1 = 0; cnt = 1; cnt1 = 0;
memset(avail, 0, info.disk.raid_disk); memset(avail, 0, info.disk.raid_disk);
max_events = info.events; max_events = info.events;
st->ss->free_super(st, best_super); st->ss->getinfo_super(st, bestinfo);
best_super = super;
super = NULL;
} }
} }
if (super) st->ss->free_super(st);
st->ss->free_super(st, super);
}
if (best_super) {
st->ss->getinfo_super(st, bestinfo,best_super);
st->ss->free_super(st, best_super);
} }
return cnt + cnt1; return cnt + cnt1;
} }
@ -613,7 +603,6 @@ void RebuildMap(void)
int ok; int ok;
struct supertype *st; struct supertype *st;
char *path; char *path;
void *super;
struct mdinfo info; struct mdinfo info;
sprintf(dn, "%d:%d", sd->major, sd->minor); sprintf(dn, "%d:%d", sd->major, sd->minor);
@ -624,11 +613,11 @@ void RebuildMap(void)
if ( st == NULL) if ( st == NULL)
ok = -1; ok = -1;
else else
ok = st->ss->load_super(st, dfd, &super, NULL); ok = st->ss->load_super(st, dfd, NULL);
close(dfd); close(dfd);
if (ok != 0) if (ok != 0)
continue; continue;
st->ss->getinfo_super(st, &info, super); st->ss->getinfo_super(st, &info);
if (md->devnum > 0) if (md->devnum > 0)
path = map_dev(MD_MAJOR, md->devnum, 0); path = map_dev(MD_MAJOR, md->devnum, 0);
else else
@ -636,7 +625,7 @@ void RebuildMap(void)
map_add(&map, md->devnum, st->ss->major, map_add(&map, md->devnum, st->ss->major,
st->minor_version, st->minor_version,
info.uuid, path ? : "/unknown"); info.uuid, path ? : "/unknown");
st->ss->free_super(st, super); st->ss->free_super(st);
break; break;
} }
} }

9
Kill.c
View File

@ -41,7 +41,6 @@ int Kill(char *dev, int force, int quiet)
* Definitely not safe. * Definitely not safe.
*/ */
void *super;
int fd, rv = 0; int fd, rv = 0;
struct supertype *st; struct supertype *st;
@ -60,15 +59,15 @@ int Kill(char *dev, int force, int quiet)
close(fd); close(fd);
return 1; return 1;
} }
rv = st->ss->load_super(st, fd, &super, dev); rv = st->ss->load_super(st, fd, dev);
if (force && rv >= 2) if (force && rv >= 2)
rv = 0; /* ignore bad data in superblock */ rv = 0; /* ignore bad data in superblock */
if (rv== 0 || (force && rv >= 2)) { if (rv== 0 || (force && rv >= 2)) {
mdu_array_info_t info; mdu_array_info_t info;
info.major_version = -1; /* zero superblock */ info.major_version = -1; /* zero superblock */
st->ss->free_super(st, super); st->ss->free_super(st);
st->ss->init_super(st, &super, &info, 0, "", NULL, NULL); st->ss->init_super(st, &info, 0, "", NULL, NULL);
if (st->ss->store_super(st, fd, super)) { if (st->ss->store_super(st, fd)) {
if (!quiet) if (!quiet)
fprintf(stderr, Name ": Could not zero superblock on %s\n", fprintf(stderr, Name ": Could not zero superblock on %s\n",
dev); dev);

View File

@ -192,9 +192,7 @@ int Manage_subdevs(char *devname, int fd,
struct stat stb; struct stat stb;
int j, jnext = 0; int j, jnext = 0;
int tfd; int tfd;
struct supertype *st; struct supertype *st, *tst;
void *dsuper = NULL;
void *osuper = NULL; /* original super */
int duuid[4]; int duuid[4];
int ouuid[4]; int ouuid[4];
@ -203,6 +201,15 @@ int Manage_subdevs(char *devname, int fd,
devname); devname);
return 1; return 1;
} }
tst = super_by_version(array.major_version,
array.minor_version);
if (!tst) {
fprintf(stderr, Name ": unsupport array - version %d.%d\n",
array.major_version, array.minor_version);
return 1;
}
for (dv = devlist, j=0 ; dv; dv = next, j = jnext) { for (dv = devlist, j=0 ; dv; dv = next, j = jnext) {
unsigned long long ldsize; unsigned long long ldsize;
char dvname[20]; char dvname[20];
@ -291,13 +298,6 @@ int Manage_subdevs(char *devname, int fd,
return 1; return 1;
case 'a': case 'a':
/* add the device */ /* add the device */
st = super_by_version(array.major_version,
array.minor_version);
if (!st) {
fprintf(stderr, Name ": unsupport array - version %d.%d\n",
array.major_version, array.minor_version);
return 1;
}
/* Make sure it isn't in use (in 2.6 or later) */ /* Make sure it isn't in use (in 2.6 or later) */
tfd = open(dv->devname, O_RDONLY|O_EXCL); tfd = open(dv->devname, O_RDONLY|O_EXCL);
@ -307,9 +307,13 @@ int Manage_subdevs(char *devname, int fd,
return 1; return 1;
} }
remove_partitions(tfd); remove_partitions(tfd);
st = super_by_version(array.major_version,
array.minor_version);
if (array.not_persistent==0) if (array.not_persistent==0)
st->ss->load_super(st, tfd, &osuper, NULL); st->ss->load_super(st, tfd, NULL);
/* will use osuper later */
if (!get_dev_size(tfd, dv->devname, &ldsize)) { if (!get_dev_size(tfd, dv->devname, &ldsize)) {
close(tfd); close(tfd);
return 1; return 1;
@ -334,7 +338,7 @@ int Manage_subdevs(char *devname, int fd,
if (array.not_persistent == 0) { if (array.not_persistent == 0) {
/* Make sure device is large enough */ /* Make sure device is large enough */
if (st->ss->avail_size(st, ldsize/512) < if (tst->ss->avail_size(tst, ldsize/512) <
array.size) { array.size) {
fprintf(stderr, Name ": %s not large enough to join array\n", fprintf(stderr, Name ": %s not large enough to join array\n",
dv->devname); dv->devname);
@ -344,7 +348,7 @@ int Manage_subdevs(char *devname, int fd,
/* need to find a sample superblock to copy, and /* need to find a sample superblock to copy, and
* a spare slot to use * a spare slot to use
*/ */
for (j=0; j<st->max_devs; j++) { for (j = 0; j < tst->max_devs; j++) {
char *dev; char *dev;
int dfd; int dfd;
disc.number = j; disc.number = j;
@ -358,14 +362,15 @@ int Manage_subdevs(char *devname, int fd,
if (!dev) continue; if (!dev) continue;
dfd = dev_open(dev, O_RDONLY); dfd = dev_open(dev, O_RDONLY);
if (dfd < 0) continue; if (dfd < 0) continue;
if (st->ss->load_super(st, dfd, &dsuper, NULL)) { if (tst->ss->load_super(tst, dfd,
NULL)) {
close(dfd); close(dfd);
continue; continue;
} }
close(dfd); close(dfd);
break; break;
} }
if (!dsuper) { if (!tst->sb) {
fprintf(stderr, Name ": cannot find valid superblock in this array - HELP\n"); fprintf(stderr, Name ": cannot find valid superblock in this array - HELP\n");
return 1; return 1;
} }
@ -373,7 +378,7 @@ int Manage_subdevs(char *devname, int fd,
* and was temporarily removed, and is now being re-added. * and was temporarily removed, and is now being re-added.
* If so, we can simply re-add it. * If so, we can simply re-add it.
*/ */
st->ss->uuid_from_super(st, duuid, dsuper); tst->ss->uuid_from_super(tst, duuid);
/* re-add doesn't work for version-1 superblocks /* re-add doesn't work for version-1 superblocks
* before 2.6.18 :-( * before 2.6.18 :-(
@ -381,15 +386,15 @@ int Manage_subdevs(char *devname, int fd,
if (array.major_version == 1 && if (array.major_version == 1 &&
get_linux_version() <= 2006018) get_linux_version() <= 2006018)
; ;
else if (osuper) { else if (st->sb) {
st->ss->uuid_from_super(st, ouuid, osuper); st->ss->uuid_from_super(st, ouuid);
if (memcmp(duuid, ouuid, sizeof(ouuid))==0) { if (memcmp(duuid, ouuid, sizeof(ouuid))==0) {
/* looks close enough for now. Kernel /* looks close enough for now. Kernel
* will worry about whether a bitmap * will worry about whether a bitmap
* based reconstruction is possible. * based reconstruction is possible.
*/ */
struct mdinfo mdi; struct mdinfo mdi;
st->ss->getinfo_super(st, &mdi, osuper); st->ss->getinfo_super(st, &mdi);
disc.major = major(stb.st_rdev); disc.major = major(stb.st_rdev);
disc.minor = minor(stb.st_rdev); disc.minor = minor(stb.st_rdev);
disc.number = mdi.disk.number; disc.number = mdi.disk.number;
@ -420,7 +425,7 @@ int Manage_subdevs(char *devname, int fd,
* we must choose the same free number, which requires * we must choose the same free number, which requires
* starting at 'raid_disks' and counting up * starting at 'raid_disks' and counting up
*/ */
for (j = array.raid_disks; j< st->max_devs; j++) { for (j = array.raid_disks; j< tst->max_devs; j++) {
disc.number = j; disc.number = j;
if (ioctl(fd, GET_DISK_INFO, &disc)) if (ioctl(fd, GET_DISK_INFO, &disc))
break; break;
@ -436,8 +441,9 @@ int Manage_subdevs(char *devname, int fd,
if (array.not_persistent==0) { if (array.not_persistent==0) {
if (dv->writemostly) if (dv->writemostly)
disc.state |= 1 << MD_DISK_WRITEMOSTLY; disc.state |= 1 << MD_DISK_WRITEMOSTLY;
st->ss->add_to_super(st, dsuper, &disc); tst->ss->add_to_super(tst, &disc);
if (st->ss->write_init_super(st, dsuper, &disc, dv->devname)) if (tst->ss->write_init_super(tst, &disc,
dv->devname))
return 1; return 1;
} else if (dv->re_add) { } else if (dv->re_add) {
/* this had better be raid1. /* this had better be raid1.
@ -446,7 +452,7 @@ int Manage_subdevs(char *devname, int fd,
*/ */
char *used = malloc(array.raid_disks); char *used = malloc(array.raid_disks);
memset(used, 0, array.raid_disks); memset(used, 0, array.raid_disks);
for (j=0; j< st->max_devs; j++) { for (j=0; j< tst->max_devs; j++) {
mdu_disk_info_t disc2; mdu_disk_info_t disc2;
disc2.number = j; disc2.number = j;
if (ioctl(fd, GET_DISK_INFO, &disc2)) if (ioctl(fd, GET_DISK_INFO, &disc2))

View File

@ -43,7 +43,6 @@ int Query(char *dev)
int superror, superrno; int superror, superrno;
struct mdinfo info; struct mdinfo info;
mdu_array_info_t array; mdu_array_info_t array;
void *super;
struct supertype *st = NULL; struct supertype *st = NULL;
unsigned long long larray_size; unsigned long long larray_size;
@ -89,14 +88,14 @@ int Query(char *dev)
} }
st = guess_super(fd); st = guess_super(fd);
if (st) { if (st) {
superror = st->ss->load_super(st, fd, &super, dev); superror = st->ss->load_super(st, fd, dev);
superrno = errno; superrno = errno;
} else } else
superror = -1; superror = -1;
close(fd); close(fd);
if (superror == 0) { if (superror == 0) {
/* array might be active... */ /* array might be active... */
st->ss->getinfo_super(st, &info, super); st->ss->getinfo_super(st, &info);
if (st->ss->major == 0) { if (st->ss->major == 0) {
mddev = get_md_name(info.array.md_minor); mddev = get_md_name(info.array.md_minor);
disc.number = info.disk.number; disc.number = info.disk.number;

View File

@ -220,7 +220,7 @@ bitmap_info_t *bitmap_file_read(char *filename, int brief, struct supertype **st
/* just look at device... */ /* just look at device... */
lseek(fd, 0, 0); lseek(fd, 0, 0);
} else { } else {
st->ss->locate_bitmap(st, fd, NULL); st->ss->locate_bitmap(st, fd);
} }
ioctl(fd, BLKFLSBUF, 0); /* make sure we read current data */ ioctl(fd, BLKFLSBUF, 0); /* make sure we read current data */
*stp = st; *stp = st;

40
mdadm.h
View File

@ -341,32 +341,35 @@ extern char *map_dev(int major, int minor, int create);
extern struct superswitch { extern struct superswitch {
void (*examine_super)(struct supertype *st, void *sbv, char *homehost); void (*examine_super)(struct supertype *st, char *homehost);
void (*brief_examine_super)(struct supertype *st, void *sbv); void (*brief_examine_super)(struct supertype *st);
void (*detail_super)(struct supertype *st, void *sbv, char *homehost); void (*detail_super)(struct supertype *st, char *homehost);
void (*export_super)(struct supertype *st, void *sbv); void (*export_super)(struct supertype *st);
void (*brief_detail_super)(struct supertype *st, void *sbv); void (*brief_detail_super)(struct supertype *st);
void (*uuid_from_super)(struct supertype *st, int uuid[4], void *sbv); void (*uuid_from_super)(struct supertype *st, int uuid[4]);
void (*getinfo_super)(struct supertype *st, struct mdinfo *info, void *sbv); void (*getinfo_super)(struct supertype *st, struct mdinfo *info);
int (*match_home)(struct supertype *st, void *sbv, char *homehost); int (*match_home)(struct supertype *st, char *homehost);
int (*update_super)(struct supertype *st, struct mdinfo *info, int (*update_super)(struct supertype *st, struct mdinfo *info,
void *sbv, char *update, char *update,
char *devname, int verbose, char *devname, int verbose,
int uuid_set, char *homehost); int uuid_set, char *homehost);
int (*init_super)(struct supertype *st, void **sbp, mdu_array_info_t *info, unsigned long long size, char *name, char *homehost, int *uuid); int (*init_super)(struct supertype *st, mdu_array_info_t *info,
void (*add_to_super)(struct supertype *st, void *sbv, mdu_disk_info_t *dinfo); unsigned long long size, char *name,
int (*store_super)(struct supertype *st, int fd, void *sbv); char *homehost, int *uuid);
int (*write_init_super)(struct supertype *st, void *sbv, mdu_disk_info_t *dinfo, char *devname); void (*add_to_super)(struct supertype *st, mdu_disk_info_t *dinfo);
int (*store_super)(struct supertype *st, int fd);
int (*write_init_super)(struct supertype *st, mdu_disk_info_t *dinfo,
char *devname);
int (*compare_super)(struct supertype *st, struct supertype *tst); int (*compare_super)(struct supertype *st, struct supertype *tst);
int (*load_super)(struct supertype *st, int fd, void **sbp, char *devname); int (*load_super)(struct supertype *st, int fd, char *devname);
struct supertype * (*match_metadata_desc)(char *arg); struct supertype * (*match_metadata_desc)(char *arg);
__u64 (*avail_size)(struct supertype *st, __u64 size); __u64 (*avail_size)(struct supertype *st, __u64 size);
int (*add_internal_bitmap)(struct supertype *st, void *sbv, int *chunkp, int (*add_internal_bitmap)(struct supertype *st, int *chunkp,
int delay, int write_behind, int delay, int write_behind,
unsigned long long size, int may_change, int major); unsigned long long size, int may_change, int major);
void (*locate_bitmap)(struct supertype *st, int fd, void *sbv); void (*locate_bitmap)(struct supertype *st, int fd);
int (*write_bitmap)(struct supertype *st, int fd, void *sbv); int (*write_bitmap)(struct supertype *st, int fd);
void (*free_super)(struct supertype *st, void *super); void (*free_super)(struct supertype *st);
int major; int major;
int swapuuid; /* true if uuid is bigending rather than hostendian */ int swapuuid; /* true if uuid is bigending rather than hostendian */
} super0, super1, *superlist[]; } super0, super1, *superlist[];
@ -380,6 +383,7 @@ struct supertype {
extern struct supertype *super_by_version(int vers, int minor); extern struct supertype *super_by_version(int vers, int minor);
extern struct supertype *guess_super(int fd); extern struct supertype *guess_super(int fd);
extern struct supertype *dup_super(struct supertype *st);
extern int get_dev_size(int fd, char *dname, unsigned long long *sizep); extern int get_dev_size(int fd, char *dname, unsigned long long *sizep);
extern void get_one_disk(int mdfd, mdu_array_info_t *ainf, extern void get_one_disk(int mdfd, mdu_array_info_t *ainf,
mdu_disk_info_t *disk); mdu_disk_info_t *disk);

View File

@ -85,9 +85,9 @@ void super0_swap_endian(struct mdp_superblock_s *sb)
#ifndef MDASSEMBLE #ifndef MDASSEMBLE
static void examine_super0(struct supertype *st, void *sbv, char *homehost) static void examine_super0(struct supertype *st, char *homehost)
{ {
mdp_super_t *sb = sbv; mdp_super_t *sb = st->sb;
time_t atime; time_t atime;
int d; int d;
char *c; char *c;
@ -231,9 +231,9 @@ static void examine_super0(struct supertype *st, void *sbv, char *homehost)
} }
} }
static void brief_examine_super0(struct supertype *st, void *sbv) static void brief_examine_super0(struct supertype *st)
{ {
mdp_super_t *sb = sbv; mdp_super_t *sb = st->sb;
char *c=map_num(pers, sb->level); char *c=map_num(pers, sb->level);
char devname[20]; char devname[20];
@ -250,9 +250,9 @@ static void brief_examine_super0(struct supertype *st, void *sbv)
printf("\n"); printf("\n");
} }
static void detail_super0(struct supertype *st, void *sbv, char *homehost) static void detail_super0(struct supertype *st, char *homehost)
{ {
mdp_super_t *sb = sbv; mdp_super_t *sb = st->sb;
printf(" UUID : "); printf(" UUID : ");
if (sb->minor_version >= 90) if (sb->minor_version >= 90)
printf("%08x:%08x:%08x:%08x", sb->set_uuid0, sb->set_uuid1, printf("%08x:%08x:%08x:%08x", sb->set_uuid0, sb->set_uuid1,
@ -270,9 +270,9 @@ static void detail_super0(struct supertype *st, void *sbv, char *homehost)
printf("\n Events : %d.%d\n\n", sb->events_hi, sb->events_lo); printf("\n Events : %d.%d\n\n", sb->events_hi, sb->events_lo);
} }
static void brief_detail_super0(struct supertype *st, void *sbv) static void brief_detail_super0(struct supertype *st)
{ {
mdp_super_t *sb = sbv; mdp_super_t *sb = st->sb;
printf(" UUID="); printf(" UUID=");
if (sb->minor_version >= 90) if (sb->minor_version >= 90)
printf("%08x:%08x:%08x:%08x", sb->set_uuid0, sb->set_uuid1, printf("%08x:%08x:%08x:%08x", sb->set_uuid0, sb->set_uuid1,
@ -281,9 +281,9 @@ static void brief_detail_super0(struct supertype *st, void *sbv)
printf("%08x", sb->set_uuid0); printf("%08x", sb->set_uuid0);
} }
static void export_super0(struct supertype *st, void *sbv) static void export_super0(struct supertype *st)
{ {
mdp_super_t *sb = sbv; mdp_super_t *sb = st->sb;
printf("MD_UUID="); printf("MD_UUID=");
if (sb->minor_version >= 90) if (sb->minor_version >= 90)
printf("%08x:%08x:%08x:%08x", sb->set_uuid0, sb->set_uuid1, printf("%08x:%08x:%08x:%08x", sb->set_uuid0, sb->set_uuid1,
@ -294,9 +294,9 @@ static void export_super0(struct supertype *st, void *sbv)
} }
#endif #endif
static int match_home0(struct supertype *st, void *sbv, char *homehost) static int match_home0(struct supertype *st, char *homehost)
{ {
mdp_super_t *sb = sbv; mdp_super_t *sb = st->sb;
char buf[20]; char buf[20];
char *hash = sha1_buffer(homehost, char *hash = sha1_buffer(homehost,
strlen(homehost), strlen(homehost),
@ -305,9 +305,9 @@ static int match_home0(struct supertype *st, void *sbv, char *homehost)
return (memcmp(&sb->set_uuid2, hash, 8)==0); return (memcmp(&sb->set_uuid2, hash, 8)==0);
} }
static void uuid_from_super0(struct supertype *st, int uuid[4], void * sbv) static void uuid_from_super0(struct supertype *st, int uuid[4])
{ {
mdp_super_t *super = sbv; mdp_super_t *super = st->sb;
uuid[0] = super->set_uuid0; uuid[0] = super->set_uuid0;
if (super->minor_version >= 90) { if (super->minor_version >= 90) {
uuid[1] = super->set_uuid1; uuid[1] = super->set_uuid1;
@ -320,9 +320,9 @@ static void uuid_from_super0(struct supertype *st, int uuid[4], void * sbv)
} }
} }
static void getinfo_super0(struct supertype *st, struct mdinfo *info, void *sbv) static void getinfo_super0(struct supertype *st, struct mdinfo *info)
{ {
mdp_super_t *sb = sbv; mdp_super_t *sb = st->sb;
int working = 0; int working = 0;
int i; int i;
@ -348,7 +348,7 @@ static void getinfo_super0(struct supertype *st, struct mdinfo *info, void *sbv)
info->events = md_event(sb); info->events = md_event(sb);
info->data_offset = 0; info->data_offset = 0;
uuid_from_super0(st, info->uuid, sbv); uuid_from_super0(st, info->uuid);
if (sb->minor_version > 90 && (sb->reshape_position+1) != 0) { if (sb->minor_version > 90 && (sb->reshape_position+1) != 0) {
info->reshape_active = 1; info->reshape_active = 1;
@ -373,7 +373,7 @@ static void getinfo_super0(struct supertype *st, struct mdinfo *info, void *sbv)
static int update_super0(struct supertype *st, struct mdinfo *info, static int update_super0(struct supertype *st, struct mdinfo *info,
void *sbv, char *update, char *update,
char *devname, int verbose, char *devname, int verbose,
int uuid_set, char *homehost) int uuid_set, char *homehost)
{ {
@ -381,7 +381,7 @@ static int update_super0(struct supertype *st, struct mdinfo *info,
* For others, the return value is ignored. * For others, the return value is ignored.
*/ */
int rv = 0; int rv = 0;
mdp_super_t *sb = sbv; mdp_super_t *sb = st->sb;
if (strcmp(update, "sparc2.2")==0 ) { if (strcmp(update, "sparc2.2")==0 ) {
/* 2.2 sparc put the events in the wrong place /* 2.2 sparc put the events in the wrong place
* So we copy the tail of the superblock * So we copy the tail of the superblock
@ -508,7 +508,7 @@ static int update_super0(struct supertype *st, struct mdinfo *info,
if (sb->state & (1<<MD_SB_BITMAP_PRESENT)) { if (sb->state & (1<<MD_SB_BITMAP_PRESENT)) {
struct bitmap_super_s *bm; struct bitmap_super_s *bm;
bm = (struct bitmap_super_s*)(sb+1); bm = (struct bitmap_super_s*)(sb+1);
uuid_from_super0(st, (int*)bm->uuid, sbv); uuid_from_super0(st, (int*)bm->uuid);
} }
} }
if (strcmp(update, "_reshape_progress")==0) if (strcmp(update, "_reshape_progress")==0)
@ -527,7 +527,7 @@ static int update_super0(struct supertype *st, struct mdinfo *info,
*/ */
static int init_super0(struct supertype *st, void **sbp, mdu_array_info_t *info, static int init_super0(struct supertype *st, mdu_array_info_t *info,
unsigned long long size, char *ignored_name, char *homehost, unsigned long long size, char *ignored_name, char *homehost,
int *uuid) int *uuid)
{ {
@ -538,7 +538,6 @@ static int init_super0(struct supertype *st, void **sbp, mdu_array_info_t *info,
st->sb = sb; st->sb = sb;
if (info->major_version == -1) { if (info->major_version == -1) {
/* zeroing the superblock */ /* zeroing the superblock */
*sbp = sb;
return 0; return 0;
} }
@ -600,14 +599,13 @@ static int init_super0(struct supertype *st, void **sbp, mdu_array_info_t *info,
sb->layout = info->layout; sb->layout = info->layout;
sb->chunk_size = info->chunk_size; sb->chunk_size = info->chunk_size;
*sbp = sb;
return 1; return 1;
} }
/* Add a device to the superblock being created */ /* Add a device to the superblock being created */
static void add_to_super0(struct supertype *st, void *sbv, mdu_disk_info_t *dinfo) static void add_to_super0(struct supertype *st, mdu_disk_info_t *dinfo)
{ {
mdp_super_t *sb = sbv; mdp_super_t *sb = st->sb;
mdp_disk_t *dk = &sb->disks[dinfo->number]; mdp_disk_t *dk = &sb->disks[dinfo->number];
dk->number = dinfo->number; dk->number = dinfo->number;
@ -617,11 +615,11 @@ static void add_to_super0(struct supertype *st, void *sbv, mdu_disk_info_t *dinf
dk->state = dinfo->state; dk->state = dinfo->state;
} }
static int store_super0(struct supertype *st, int fd, void *sbv) static int store_super0(struct supertype *st, int fd)
{ {
unsigned long long dsize; unsigned long long dsize;
unsigned long long offset; unsigned long long offset;
mdp_super_t *super = sbv; mdp_super_t *super = st->sb;
if (!get_dev_size(fd, NULL, &dsize)) if (!get_dev_size(fd, NULL, &dsize))
return 1; return 1;
@ -650,9 +648,10 @@ static int store_super0(struct supertype *st, int fd, void *sbv)
return 0; return 0;
} }
static int write_init_super0(struct supertype *st, void *sbv, mdu_disk_info_t *dinfo, char *devname) static int write_init_super0(struct supertype *st,
mdu_disk_info_t *dinfo, char *devname)
{ {
mdp_super_t *sb = sbv; mdp_super_t *sb = st->sb;
int fd = open(devname, O_RDWR|O_EXCL); int fd = open(devname, O_RDWR|O_EXCL);
int rv; int rv;
@ -665,10 +664,10 @@ static int write_init_super0(struct supertype *st, void *sbv, mdu_disk_info_t *d
sb->this_disk = sb->disks[dinfo->number]; sb->this_disk = sb->disks[dinfo->number];
sb->sb_csum = calc_sb0_csum(sb); sb->sb_csum = calc_sb0_csum(sb);
rv = store_super0(st, fd, sb); rv = store_super0(st, fd);
if (rv == 0 && (sb->state & (1<<MD_SB_BITMAP_PRESENT))) if (rv == 0 && (sb->state & (1<<MD_SB_BITMAP_PRESENT)))
rv = st->ss->write_bitmap(st, fd, sbv); rv = st->ss->write_bitmap(st, fd);
close(fd); close(fd);
if (rv) if (rv)
@ -698,8 +697,8 @@ static int compare_super0(struct supertype *st, struct supertype *tst)
return 0; return 0;
} }
uuid_from_super0(NULL, uuid1, first); uuid_from_super0(st, uuid1);
uuid_from_super0(NULL, uuid2, second); uuid_from_super0(tst, uuid2);
if (!same_uuid(uuid1, uuid2, 0)) if (!same_uuid(uuid1, uuid2, 0))
return 2; return 2;
if (first->major_version != second->major_version || if (first->major_version != second->major_version ||
@ -716,7 +715,9 @@ static int compare_super0(struct supertype *st, struct supertype *tst)
} }
static int load_super0(struct supertype *st, int fd, void **sbp, char *devname) static void free_super0(struct supertype *st);
static int load_super0(struct supertype *st, int fd, char *devname)
{ {
/* try to read in the superblock /* try to read in the superblock
* Return: * Return:
@ -730,6 +731,8 @@ static int load_super0(struct supertype *st, int fd, void **sbp, char *devname)
int uuid[4]; int uuid[4];
struct bitmap_super_s *bsb; struct bitmap_super_s *bsb;
free_super0(st);
if (!get_dev_size(fd, devname, &dsize)) if (!get_dev_size(fd, devname, &dsize))
return 1; return 1;
@ -783,7 +786,7 @@ static int load_super0(struct supertype *st, int fd, void **sbp, char *devname)
return 2; return 2;
} }
st->sb = super; st->sb = super;
*sbp = super;
if (st->ss == NULL) { if (st->ss == NULL) {
st->ss = &super0; st->ss = &super0;
st->minor_version = 90; st->minor_version = 90;
@ -801,7 +804,7 @@ static int load_super0(struct supertype *st, int fd, void **sbp, char *devname)
!= sizeof(struct bitmap_super_s)) != sizeof(struct bitmap_super_s))
goto no_bitmap; goto no_bitmap;
uuid_from_super0(st, uuid, super); uuid_from_super0(st, uuid);
bsb = (struct bitmap_super_s *)(super+1); bsb = (struct bitmap_super_s *)(super+1);
if (__le32_to_cpu(bsb->magic) != BITMAP_MAGIC || if (__le32_to_cpu(bsb->magic) != BITMAP_MAGIC ||
memcmp(bsb->uuid, uuid, 16) != 0) memcmp(bsb->uuid, uuid, 16) != 0)
@ -844,7 +847,7 @@ static __u64 avail_size0(struct supertype *st, __u64 devsize)
return MD_NEW_SIZE_SECTORS(devsize); return MD_NEW_SIZE_SECTORS(devsize);
} }
static int add_internal_bitmap0(struct supertype *st, void *sbv, int *chunkp, static int add_internal_bitmap0(struct supertype *st, int *chunkp,
int delay, int write_behind, int delay, int write_behind,
unsigned long long size, int may_change, unsigned long long size, int may_change,
int major) int major)
@ -859,7 +862,7 @@ static int add_internal_bitmap0(struct supertype *st, void *sbv, int *chunkp,
unsigned long long max_bits = 60*1024*8; unsigned long long max_bits = 60*1024*8;
unsigned long long min_chunk; unsigned long long min_chunk;
int chunk = *chunkp; int chunk = *chunkp;
mdp_super_t *sb = sbv; mdp_super_t *sb = st->sb;
bitmap_super_t *bms = (bitmap_super_t*)(((char*)sb) + MD_SB_BYTES); bitmap_super_t *bms = (bitmap_super_t*)(((char*)sb) + MD_SB_BYTES);
@ -879,7 +882,7 @@ static int add_internal_bitmap0(struct supertype *st, void *sbv, int *chunkp,
memset(bms, 0, sizeof(*bms)); memset(bms, 0, sizeof(*bms));
bms->magic = __cpu_to_le32(BITMAP_MAGIC); bms->magic = __cpu_to_le32(BITMAP_MAGIC);
bms->version = __cpu_to_le32(major); bms->version = __cpu_to_le32(major);
uuid_from_super0(st, (int*)bms->uuid, sb); uuid_from_super0(st, (int*)bms->uuid);
bms->chunksize = __cpu_to_le32(chunk); bms->chunksize = __cpu_to_le32(chunk);
bms->daemon_sleep = __cpu_to_le32(delay); bms->daemon_sleep = __cpu_to_le32(delay);
bms->sync_size = __cpu_to_le64(size); bms->sync_size = __cpu_to_le64(size);
@ -889,7 +892,7 @@ static int add_internal_bitmap0(struct supertype *st, void *sbv, int *chunkp,
} }
void locate_bitmap0(struct supertype *st, int fd, void *sbv) void locate_bitmap0(struct supertype *st, int fd)
{ {
unsigned long long dsize; unsigned long long dsize;
unsigned long long offset; unsigned long long offset;
@ -909,11 +912,11 @@ void locate_bitmap0(struct supertype *st, int fd, void *sbv)
lseek64(fd, offset, 0); lseek64(fd, offset, 0);
} }
int write_bitmap0(struct supertype *st, int fd, void *sbv) int write_bitmap0(struct supertype *st, int fd)
{ {
unsigned long long dsize; unsigned long long dsize;
unsigned long long offset; unsigned long long offset;
mdp_super_t *sb = sbv; mdp_super_t *sb = st->sb;
int rv = 0; int rv = 0;
@ -957,10 +960,11 @@ int write_bitmap0(struct supertype *st, int fd, void *sbv)
return rv; return rv;
} }
static void free_super0(struct supertype *st, void *super) static void free_super0(struct supertype *st)
{ {
if (super) if (st->sb)
free(super); free(st->sb);
st->sb = NULL;
} }
struct superswitch super0 = { struct superswitch super0 = {

120
super1.c
View File

@ -142,9 +142,9 @@ static unsigned int calc_sb_1_csum(struct mdp_superblock_1 * sb)
} }
#ifndef MDASSEMBLE #ifndef MDASSEMBLE
static void examine_super1(struct supertype *st, void *sbv, char *homehost) static void examine_super1(struct supertype *st, char *homehost)
{ {
struct mdp_superblock_1 *sb = sbv; struct mdp_superblock_1 *sb = st->sb;
time_t atime; time_t atime;
int d; int d;
int faulty; int faulty;
@ -341,9 +341,9 @@ static void examine_super1(struct supertype *st, void *sbv, char *homehost)
} }
static void brief_examine_super1(struct supertype *st, void *sbv) static void brief_examine_super1(struct supertype *st)
{ {
struct mdp_superblock_1 *sb = sbv; struct mdp_superblock_1 *sb = st->sb;
int i; int i;
unsigned long long sb_offset; unsigned long long sb_offset;
char *nm; char *nm;
@ -375,9 +375,9 @@ static void brief_examine_super1(struct supertype *st, void *sbv)
printf("\n"); printf("\n");
} }
static void detail_super1(struct supertype *st, void *sbv, char *homehost) static void detail_super1(struct supertype *st, char *homehost)
{ {
struct mdp_superblock_1 *sb = sbv; struct mdp_superblock_1 *sb = st->sb;
int i; int i;
int l = homehost ? strlen(homehost) : 0; int l = homehost ? strlen(homehost) : 0;
@ -394,9 +394,9 @@ static void detail_super1(struct supertype *st, void *sbv, char *homehost)
printf("\n Events : %llu\n\n", (unsigned long long)__le64_to_cpu(sb->events)); printf("\n Events : %llu\n\n", (unsigned long long)__le64_to_cpu(sb->events));
} }
static void brief_detail_super1(struct supertype *st, void *sbv) static void brief_detail_super1(struct supertype *st)
{ {
struct mdp_superblock_1 *sb = sbv; struct mdp_superblock_1 *sb = st->sb;
int i; int i;
if (sb->set_name[0]) if (sb->set_name[0])
@ -408,9 +408,9 @@ static void brief_detail_super1(struct supertype *st, void *sbv)
} }
} }
static void export_super1(struct supertype *st, void *sbv) static void export_super1(struct supertype *st)
{ {
struct mdp_superblock_1 *sb = sbv; struct mdp_superblock_1 *sb = st->sb;
int i; int i;
int len = 32; int len = 32;
@ -432,9 +432,9 @@ static void export_super1(struct supertype *st, void *sbv)
#endif #endif
static int match_home1(struct supertype *st, void *sbv, char *homehost) static int match_home1(struct supertype *st, char *homehost)
{ {
struct mdp_superblock_1 *sb = sbv; struct mdp_superblock_1 *sb = st->sb;
int l = homehost ? strlen(homehost) : 0; int l = homehost ? strlen(homehost) : 0;
return (l > 0 && l < 32 && return (l > 0 && l < 32 &&
@ -442,18 +442,18 @@ static int match_home1(struct supertype *st, void *sbv, char *homehost)
strncmp(sb->set_name, homehost, l) == 0); strncmp(sb->set_name, homehost, l) == 0);
} }
static void uuid_from_super1(struct supertype *st, int uuid[4], void * sbv) static void uuid_from_super1(struct supertype *st, int uuid[4])
{ {
struct mdp_superblock_1 *super = sbv; struct mdp_superblock_1 *super = st->sb;
char *cuuid = (char*)uuid; char *cuuid = (char*)uuid;
int i; int i;
for (i=0; i<16; i++) for (i=0; i<16; i++)
cuuid[i] = super->set_uuid[i]; cuuid[i] = super->set_uuid[i];
} }
static void getinfo_super1(struct supertype *st, struct mdinfo *info, void *sbv) static void getinfo_super1(struct supertype *st, struct mdinfo *info)
{ {
struct mdp_superblock_1 *sb = sbv; struct mdp_superblock_1 *sb = st->sb;
int working = 0; int working = 0;
int i; int i;
int role; int role;
@ -523,7 +523,7 @@ static void getinfo_super1(struct supertype *st, struct mdinfo *info, void *sbv)
} }
static int update_super1(struct supertype *st, struct mdinfo *info, static int update_super1(struct supertype *st, struct mdinfo *info,
void *sbv, char *update, char *update,
char *devname, int verbose, char *devname, int verbose,
int uuid_set, char *homehost) int uuid_set, char *homehost)
{ {
@ -531,7 +531,7 @@ static int update_super1(struct supertype *st, struct mdinfo *info,
* For others, the return value is ignored. * For others, the return value is ignored.
*/ */
int rv = 0; int rv = 0;
struct mdp_superblock_1 *sb = sbv; struct mdp_superblock_1 *sb = st->sb;
if (strcmp(update, "force-one")==0) { if (strcmp(update, "force-one")==0) {
/* Not enough devices for a working array, /* Not enough devices for a working array,
@ -603,7 +603,7 @@ static int update_super1(struct supertype *st, struct mdinfo *info,
if (__le32_to_cpu(sb->feature_map)&MD_FEATURE_BITMAP_OFFSET) { if (__le32_to_cpu(sb->feature_map)&MD_FEATURE_BITMAP_OFFSET) {
struct bitmap_super_s *bm; struct bitmap_super_s *bm;
bm = (struct bitmap_super_s*)(sbv+1024); bm = (struct bitmap_super_s*)(st->sb+1024);
memcpy(bm->uuid, sb->set_uuid, 16); memcpy(bm->uuid, sb->set_uuid, 16);
} }
} }
@ -636,7 +636,7 @@ static int update_super1(struct supertype *st, struct mdinfo *info,
__le64_to_cpu(sb->data_offset)) { __le64_to_cpu(sb->data_offset)) {
/* set data_size to device size less data_offset */ /* set data_size to device size less data_offset */
struct misc_dev_info *misc = (struct misc_dev_info*) struct misc_dev_info *misc = (struct misc_dev_info*)
(sbv + 1024 + sizeof(struct bitmap_super_s)); (st->sb + 1024 + sizeof(struct bitmap_super_s));
printf("Size was %llu\n", (unsigned long long) printf("Size was %llu\n", (unsigned long long)
__le64_to_cpu(sb->data_size)); __le64_to_cpu(sb->data_size));
sb->data_size = __cpu_to_le64( sb->data_size = __cpu_to_le64(
@ -651,7 +651,7 @@ static int update_super1(struct supertype *st, struct mdinfo *info,
return rv; return rv;
} }
static int init_super1(struct supertype *st, void **sbp, mdu_array_info_t *info, static int init_super1(struct supertype *st, mdu_array_info_t *info,
unsigned long long size, char *name, char *homehost, int *uuid) unsigned long long size, char *name, char *homehost, int *uuid)
{ {
struct mdp_superblock_1 *sb = malloc(1024 + sizeof(bitmap_super_t) + struct mdp_superblock_1 *sb = malloc(1024 + sizeof(bitmap_super_t) +
@ -664,7 +664,6 @@ static int init_super1(struct supertype *st, void **sbp, mdu_array_info_t *info,
st->sb = sb; st->sb = sb;
if (info->major_version == -1) { if (info->major_version == -1) {
/* zeroing superblock */ /* zeroing superblock */
*sbp = sb;
return 0; return 0;
} }
@ -731,14 +730,13 @@ static int init_super1(struct supertype *st, void **sbp, mdu_array_info_t *info,
memset(sb->dev_roles, 0xff, 1024 - sizeof(struct mdp_superblock_1)); memset(sb->dev_roles, 0xff, 1024 - sizeof(struct mdp_superblock_1));
*sbp = sb;
return 1; return 1;
} }
/* Add a device to the superblock being created */ /* Add a device to the superblock being created */
static void add_to_super1(struct supertype *st, void *sbv, mdu_disk_info_t *dk) static void add_to_super1(struct supertype *st, mdu_disk_info_t *dk)
{ {
struct mdp_superblock_1 *sb = sbv; struct mdp_superblock_1 *sb = st->sb;
__u16 *rp = sb->dev_roles + dk->number; __u16 *rp = sb->dev_roles + dk->number;
if ((dk->state & 6) == 6) /* active, sync */ if ((dk->state & 6) == 6) /* active, sync */
*rp = __cpu_to_le16(dk->raid_disk); *rp = __cpu_to_le16(dk->raid_disk);
@ -748,11 +746,11 @@ static void add_to_super1(struct supertype *st, void *sbv, mdu_disk_info_t *dk)
*rp = 0xfffe; *rp = 0xfffe;
} }
static void locate_bitmap1(struct supertype *st, int fd, void *sbv); static void locate_bitmap1(struct supertype *st, int fd);
static int store_super1(struct supertype *st, int fd, void *sbv) static int store_super1(struct supertype *st, int fd)
{ {
struct mdp_superblock_1 *sb = sbv; struct mdp_superblock_1 *sb = st->sb;
unsigned long long sb_offset; unsigned long long sb_offset;
int sbsize; int sbsize;
unsigned long long dsize; unsigned long long dsize;
@ -810,7 +808,7 @@ static int store_super1(struct supertype *st, int fd, void *sbv)
struct bitmap_super_s *bm = (struct bitmap_super_s*) struct bitmap_super_s *bm = (struct bitmap_super_s*)
(((char*)sb)+1024); (((char*)sb)+1024);
if (__le32_to_cpu(bm->magic) == BITMAP_MAGIC) { if (__le32_to_cpu(bm->magic) == BITMAP_MAGIC) {
locate_bitmap1(st, fd, sbv); locate_bitmap1(st, fd);
if (write(fd, bm, sizeof(*bm)) != sizeof(*bm)) if (write(fd, bm, sizeof(*bm)) != sizeof(*bm))
return 5; return 5;
} }
@ -819,7 +817,7 @@ static int store_super1(struct supertype *st, int fd, void *sbv)
return 0; return 0;
} }
static int load_super1(struct supertype *st, int fd, void **sbp, char *devname); static int load_super1(struct supertype *st, int fd, char *devname);
static unsigned long choose_bm_space(unsigned long devsize) static unsigned long choose_bm_space(unsigned long devsize)
{ {
@ -834,11 +832,11 @@ static unsigned long choose_bm_space(unsigned long devsize)
return 4*2; return 4*2;
} }
static int write_init_super1(struct supertype *st, void *sbv, static int write_init_super1(struct supertype *st,
mdu_disk_info_t *dinfo, char *devname) mdu_disk_info_t *dinfo, char *devname)
{ {
struct mdp_superblock_1 *sb = sbv; struct mdp_superblock_1 *sb = st->sb;
void *refsbv = NULL; struct supertype refst;
int fd = open(devname, O_RDWR | O_EXCL); int fd = open(devname, O_RDWR | O_EXCL);
int rfd; int rfd;
int rv; int rv;
@ -868,8 +866,10 @@ static int write_init_super1(struct supertype *st, void *sbv,
if (rfd >= 0) close(rfd); if (rfd >= 0) close(rfd);
sb->events = 0; sb->events = 0;
if (load_super1(st, fd, &refsbv, NULL)==0) { refst =*st;
struct mdp_superblock_1 *refsb = refsbv; refst.sb = NULL;
if (load_super1(&refst, fd, NULL)==0) {
struct mdp_superblock_1 *refsb = refst.sb;
memcpy(sb->device_uuid, refsb->device_uuid, 16); memcpy(sb->device_uuid, refsb->device_uuid, 16);
if (memcmp(sb->set_uuid, refsb->set_uuid, 16)==0) { if (memcmp(sb->set_uuid, refsb->set_uuid, 16)==0) {
@ -938,12 +938,12 @@ static int write_init_super1(struct supertype *st, void *sbv,
sb->sb_csum = calc_sb_1_csum(sb); sb->sb_csum = calc_sb_1_csum(sb);
rv = store_super1(st, fd, sb); rv = store_super1(st, fd);
if (rv) if (rv)
fprintf(stderr, Name ": failed to write superblock to %s\n", devname); fprintf(stderr, Name ": failed to write superblock to %s\n", devname);
if (rv == 0 && (__le32_to_cpu(sb->feature_map) & 1)) if (rv == 0 && (__le32_to_cpu(sb->feature_map) & 1))
rv = st->ss->write_bitmap(st, fd, sbv); rv = st->ss->write_bitmap(st, fd);
close(fd); close(fd);
return rv; return rv;
} }
@ -986,7 +986,9 @@ static int compare_super1(struct supertype *st, struct supertype *tst)
return 0; return 0;
} }
static int load_super1(struct supertype *st, int fd, void **sbp, char *devname) static void free_super1(struct supertype *st);
static int load_super1(struct supertype *st, int fd, char *devname)
{ {
unsigned long long dsize; unsigned long long dsize;
unsigned long long sb_offset; unsigned long long sb_offset;
@ -995,6 +997,7 @@ static int load_super1(struct supertype *st, int fd, void **sbp, char *devname)
struct bitmap_super_s *bsb; struct bitmap_super_s *bsb;
struct misc_dev_info *misc; struct misc_dev_info *misc;
free_super1(st);
if (st->ss == NULL || st->minor_version == -1) { if (st->ss == NULL || st->minor_version == -1) {
int bestvers = -1; int bestvers = -1;
@ -1002,16 +1005,17 @@ static int load_super1(struct supertype *st, int fd, void **sbp, char *devname)
__u64 bestctime = 0; __u64 bestctime = 0;
/* guess... choose latest ctime */ /* guess... choose latest ctime */
tst.ss = &super1; tst.ss = &super1;
tst.sb = NULL;
for (tst.minor_version = 0; tst.minor_version <= 2 ; tst.minor_version++) { for (tst.minor_version = 0; tst.minor_version <= 2 ; tst.minor_version++) {
switch(load_super1(&tst, fd, sbp, devname)) { switch(load_super1(&tst, fd, devname)) {
case 0: super = *sbp; case 0: super = tst.sb;
if (bestvers == -1 || if (bestvers == -1 ||
bestctime < __le64_to_cpu(super->ctime)) { bestctime < __le64_to_cpu(super->ctime)) {
bestvers = tst.minor_version; bestvers = tst.minor_version;
bestctime = __le64_to_cpu(super->ctime); bestctime = __le64_to_cpu(super->ctime);
} }
free(super); free(super);
*sbp = NULL; tst.sb = NULL;
break; break;
case 1: return 1; /*bad device */ case 1: return 1; /*bad device */
case 2: break; /* bad, try next */ case 2: break; /* bad, try next */
@ -1022,7 +1026,7 @@ static int load_super1(struct supertype *st, int fd, void **sbp, char *devname)
tst.minor_version = bestvers; tst.minor_version = bestvers;
tst.ss = &super1; tst.ss = &super1;
tst.max_devs = 384; tst.max_devs = 384;
rv = load_super1(&tst, fd, sbp, devname); rv = load_super1(&tst, fd, devname);
if (rv == 0) if (rv == 0)
*st = tst; *st = tst;
return rv; return rv;
@ -1108,7 +1112,6 @@ static int load_super1(struct supertype *st, int fd, void **sbp, char *devname)
return 2; return 2;
} }
st->sb = super; st->sb = super;
*sbp = super;
bsb = (struct bitmap_super_s *)(((char*)super)+1024); bsb = (struct bitmap_super_s *)(((char*)super)+1024);
@ -1122,12 +1125,12 @@ static int load_super1(struct supertype *st, int fd, void **sbp, char *devname)
* valid. If it doesn't clear the bit. An --assemble --force * valid. If it doesn't clear the bit. An --assemble --force
* should get that written out. * should get that written out.
*/ */
locate_bitmap1(st, fd, super); locate_bitmap1(st, fd);
if (read(fd, ((char*)super)+1024, sizeof(struct bitmap_super_s)) if (read(fd, ((char*)super)+1024, sizeof(struct bitmap_super_s))
!= sizeof(struct bitmap_super_s)) != sizeof(struct bitmap_super_s))
goto no_bitmap; goto no_bitmap;
uuid_from_super1(st, uuid, super); uuid_from_super1(st, uuid);
if (__le32_to_cpu(bsb->magic) != BITMAP_MAGIC || if (__le32_to_cpu(bsb->magic) != BITMAP_MAGIC ||
memcmp(bsb->uuid, uuid, 16) != 0) memcmp(bsb->uuid, uuid, 16) != 0)
goto no_bitmap; goto no_bitmap;
@ -1198,7 +1201,7 @@ static __u64 avail_size1(struct supertype *st, __u64 devsize)
} }
static int static int
add_internal_bitmap1(struct supertype *st, void *sbv, add_internal_bitmap1(struct supertype *st,
int *chunkp, int delay, int write_behind, int *chunkp, int delay, int write_behind,
unsigned long long size, unsigned long long size,
int may_change, int major) int may_change, int major)
@ -1220,7 +1223,7 @@ add_internal_bitmap1(struct supertype *st, void *sbv,
long offset; long offset;
int chunk = *chunkp; int chunk = *chunkp;
int room = 0; int room = 0;
struct mdp_superblock_1 *sb = sbv; struct mdp_superblock_1 *sb = st->sb;
bitmap_super_t *bms = (bitmap_super_t*)(((char*)sb) + 1024); bitmap_super_t *bms = (bitmap_super_t*)(((char*)sb) + 1024);
switch(st->minor_version) { switch(st->minor_version) {
@ -1305,7 +1308,7 @@ add_internal_bitmap1(struct supertype *st, void *sbv,
memset(bms, 0, sizeof(*bms)); memset(bms, 0, sizeof(*bms));
bms->magic = __cpu_to_le32(BITMAP_MAGIC); bms->magic = __cpu_to_le32(BITMAP_MAGIC);
bms->version = __cpu_to_le32(major); bms->version = __cpu_to_le32(major);
uuid_from_super1(st, (int*)bms->uuid, sb); uuid_from_super1(st, (int*)bms->uuid);
bms->chunksize = __cpu_to_le32(chunk); bms->chunksize = __cpu_to_le32(chunk);
bms->daemon_sleep = __cpu_to_le32(delay); bms->daemon_sleep = __cpu_to_le32(delay);
bms->sync_size = __cpu_to_le64(size); bms->sync_size = __cpu_to_le64(size);
@ -1316,18 +1319,18 @@ add_internal_bitmap1(struct supertype *st, void *sbv,
} }
static void locate_bitmap1(struct supertype *st, int fd, void *sbv) static void locate_bitmap1(struct supertype *st, int fd)
{ {
unsigned long long offset; unsigned long long offset;
struct mdp_superblock_1 *sb; struct mdp_superblock_1 *sb;
int mustfree = 0; int mustfree = 0;
if (!sbv) { if (!st->sb) {
if (st->ss->load_super(st, fd, &sbv, NULL)) if (st->ss->load_super(st, fd, NULL))
return; /* no error I hope... */ return; /* no error I hope... */
mustfree = 1; mustfree = 1;
} }
sb = sbv; sb = st->sb;
offset = __le64_to_cpu(sb->super_offset); offset = __le64_to_cpu(sb->super_offset);
offset += (int32_t) __le32_to_cpu(sb->bitmap_offset); offset += (int32_t) __le32_to_cpu(sb->bitmap_offset);
@ -1336,16 +1339,16 @@ static void locate_bitmap1(struct supertype *st, int fd, void *sbv)
lseek64(fd, offset<<9, 0); lseek64(fd, offset<<9, 0);
} }
static int write_bitmap1(struct supertype *st, int fd, void *sbv) static int write_bitmap1(struct supertype *st, int fd)
{ {
struct mdp_superblock_1 *sb = sbv; struct mdp_superblock_1 *sb = st->sb;
bitmap_super_t *bms = (bitmap_super_t*)(((char*)sb)+1024); bitmap_super_t *bms = (bitmap_super_t*)(((char*)sb)+1024);
int rv = 0; int rv = 0;
int towrite, n; int towrite, n;
char buf[4096]; char buf[4096];
locate_bitmap1(st, fd, sbv); locate_bitmap1(st, fd);
if (write(fd, ((char*)sb)+1024, sizeof(bitmap_super_t)) != if (write(fd, ((char*)sb)+1024, sizeof(bitmap_super_t)) !=
sizeof(bitmap_super_t)) sizeof(bitmap_super_t))
@ -1370,10 +1373,11 @@ static int write_bitmap1(struct supertype *st, int fd, void *sbv)
return rv; return rv;
} }
static void free_super1(struct supertype *st, void *super) static void free_super1(struct supertype *st)
{ {
if (super) if (st->sb)
free(super); free(st->sb);
st->sb = NULL;
} }
struct superswitch super1 = { struct superswitch super1 = {

27
util.c
View File

@ -322,19 +322,18 @@ int check_reiser(int fd, char *name)
int check_raid(int fd, char *name) int check_raid(int fd, char *name)
{ {
void *super;
struct mdinfo info; struct mdinfo info;
time_t crtime; time_t crtime;
char *level; char *level;
struct supertype *st = guess_super(fd); struct supertype *st = guess_super(fd);
if (!st) return 0; if (!st) return 0;
st->ss->load_super(st, fd, &super, name); st->ss->load_super(st, fd, name);
/* Looks like a raid array .. */ /* Looks like a raid array .. */
fprintf(stderr, Name ": %s appears to be part of a raid array:\n", fprintf(stderr, Name ": %s appears to be part of a raid array:\n",
name); name);
st->ss->getinfo_super(st, &info, super); st->ss->getinfo_super(st, &info);
st->ss->free_super(st, super); st->ss->free_super(st);
crtime = info.array.ctime; crtime = info.array.ctime;
level = map_num(pers, info.array.level); level = map_num(pers, info.array.level);
if (!level) level = "-unknown-"; if (!level) level = "-unknown-";
@ -738,9 +737,17 @@ struct supertype *super_by_version(int vers, int minor)
st->max_devs = 384; st->max_devs = 384;
} }
st->minor_version = minor; st->minor_version = minor;
st->sb = NULL;
return st; return st;
} }
struct supertype *dup_super(struct supertype *st)
{
if (!st)
return st;
return super_by_version(st->ss->major, st->minor_version);
}
struct supertype *guess_super(int fd) struct supertype *guess_super(int fd)
{ {
/* try each load_super to find the best match, /* try each load_super to find the best match,
@ -750,8 +757,6 @@ struct supertype *guess_super(int fd)
struct supertype *st; struct supertype *st;
unsigned long besttime = 0; unsigned long besttime = 0;
int bestsuper = -1; int bestsuper = -1;
void *sbp = NULL;
int i; int i;
st = malloc(sizeof(*st)); st = malloc(sizeof(*st));
@ -760,24 +765,24 @@ struct supertype *guess_super(int fd)
int rv; int rv;
ss = superlist[i]; ss = superlist[i];
st->ss = NULL; st->ss = NULL;
rv = ss->load_super(st, fd, &sbp, NULL); rv = ss->load_super(st, fd, NULL);
if (rv == 0) { if (rv == 0) {
struct mdinfo info; struct mdinfo info;
st->ss->getinfo_super(st, &info, sbp); st->ss->getinfo_super(st, &info);
if (bestsuper == -1 || if (bestsuper == -1 ||
besttime < info.array.ctime) { besttime < info.array.ctime) {
bestsuper = i; bestsuper = i;
besttime = info.array.ctime; besttime = info.array.ctime;
} }
free(sbp); ss->free_super(st);
} }
} }
if (bestsuper != -1) { if (bestsuper != -1) {
int rv; int rv;
st->ss = NULL; st->ss = NULL;
rv = superlist[bestsuper]->load_super(st, fd, &sbp, NULL); rv = superlist[bestsuper]->load_super(st, fd, NULL);
if (rv == 0) { if (rv == 0) {
free(sbp); ss->free_super(st);
return st; return st;
} }
} }