int nfd, fd2;
int d, nd;
struct supertype *st = NULL;
-
+
if (ioctl(fd, GET_ARRAY_INFO, &info.array) < 0) {
fprintf(stderr, Name ": cannot get array info for %s\n", devname);
fprintf(stderr, Name ": cannot open device file %s\n", dv);
return 1;
}
- if (super) free(super);
+ if (super)
+ st->ss->free_super(st, super);
super= NULL;
if (st->ss->load_super(st, fd2, &super, NULL)) {
fprintf(stderr, Name ": cannot find super block on %s\n", dv);
/* Ok, looks good. Lets update the superblock and write it out to
* newdev.
*/
-
+
info.disk.number = d;
info.disk.major = major(stb.st_rdev);
info.disk.minor = minor(stb.st_rdev);
info.disk.raid_disk = d;
info.disk.state = (1 << MD_DISK_SYNC) | (1 << MD_DISK_ACTIVE);
- st->ss->update_super(&info, super, "linear-grow-new", newdev,
+ st->ss->update_super(st, &info, super, "linear-grow-new", newdev,
0, 0, NULL);
if (st->ss->store_super(st, nfd, super)) {
info.array.active_disks = nd+1;
info.array.working_disks = nd+1;
- st->ss->update_super(&info, super, "linear-grow-update", dv,
+ st->ss->update_super(st, &info, super, "linear-grow-update", dv,
0, 0, NULL);
-
+
if (st->ss->store_super(st, fd2, super)) {
fprintf(stderr, Name ": Cannot store new superblock on %s\n", dv);
close(fd2);
devname);
return 1;
}
+ if (array.level <= 0) {
+ fprintf(stderr, Name ": Bitmaps not meaningful with level %s\n",
+ map_num(pers, array.level)?:"of this array");
+ return 1;
+ }
bitmapsize = array.size;
bitmapsize <<= 1;
if (get_dev_size(fd, NULL, &array_size) &&
if (fd2 >= 0 &&
st->ss->load_super(st, fd2, &super, NULL) == 0) {
close(fd2);
- st->ss->uuid_from_super(uuid, super);
+ st->ss->uuid_from_super(st, uuid, super);
break;
}
close(fd2);
memcpy(bsb.magic, "md_backup_data-1", 16);
- st->ss->uuid_from_super((int*)&bsb.set_uuid, super);
+ st->ss->uuid_from_super(st, (int*)&bsb.set_uuid, super);
bsb.mtime = __cpu_to_le64(time(0));
bsb.arraystart = 0;
bsb.length = __cpu_to_le64(last_block);
break;
sleep(1);
}
-
+
/* invalidate superblocks */
memset(&bsb, 0, sizeof(bsb));
for (i=odisks; i<d ; i++) {
{
int i, j;
int old_disks;
- int err = 0;
unsigned long long *offsets;
+ unsigned long long nstripe, ostripe, last_block;
+ int ndata, odata;
if (info->delta_disks < 0)
return 1; /* cannot handle a shrink */
if (st->ss->load_super(st, fd, &super, NULL))
continue;
- st->ss->getinfo_super(&dinfo, super);
- free(super); super = NULL;
+ st->ss->getinfo_super(st, &dinfo, super);
+ st->ss->free_super(st, super);
+ super = NULL;
if (lseek64(fd,
(dinfo.data_offset + dinfo.component_size - 8) <<9,
0) < 0)
if (st->ss->load_super(st, fdlist[j], &super, NULL))
/* FIXME should be this be an error */
continue;
- st->ss->getinfo_super(&dinfo, super);
- free(super); super = NULL;
+ st->ss->getinfo_super(st, &dinfo, super);
+ st->ss->free_super(st, super);
+ super = NULL;
offsets[j] = dinfo.data_offset;
}
printf(Name ": restoring critical section\n");
fd, __le64_to_cpu(bsb.devstart)*512,
0, __le64_to_cpu(bsb.length)*512)) {
/* didn't succeed, so giveup */
- return -1;
+ return 1;
}
/* Ok, so the data is restored. Let's update those superblocks. */
if (fdlist[j] < 0) continue;
if (st->ss->load_super(st, fdlist[j], &super, NULL))
continue;
- st->ss->getinfo_super(&dinfo, super);
+ st->ss->getinfo_super(st, &dinfo, super);
dinfo.reshape_progress = __le64_to_cpu(bsb.length);
- st->ss->update_super(&dinfo, super, "_reshape_progress",NULL,0, 0, NULL);
+ st->ss->update_super(st, &dinfo, super,
+ "_reshape_progress",
+ NULL,0, 0, NULL);
st->ss->store_super(st, fdlist[j], super);
- free(super);
+ st->ss->free_super(st, super);
}
/* And we are done! */
return 0;
}
- return err;
+ /* Didn't find any backup data, try to see if any
+ * was needed.
+ */
+ nstripe = ostripe = 0;
+ odata = info->array.raid_disks - info->delta_disks - 1;
+ if (info->array.level == 6) odata--; /* number of data disks */
+ ndata = info->array.raid_disks - 1;
+ if (info->new_level == 6) ndata--;
+ last_block = 0;
+ while (nstripe >= ostripe) {
+ nstripe += info->new_chunk / 512;
+ last_block = nstripe * ndata;
+ ostripe = last_block / odata / (info->array.chunk_size/512) *
+ (info->array.chunk_size/512);
+ }
+
+ if (info->reshape_progress >= last_block)
+ return 0;
+ /* needed to recover critical section! */
+ return 1;
}