else {
struct mdinfo *sra = sysfs_read(-1, st->devnum, GET_VERSION);
int err;
+ char buf[20];
if (!sra)
return -1;
+ /* Need to clear any 'read-auto' status */
+ if (sysfs_get_str(sra, NULL, "array_state", buf, 20) > 0 &&
+ strncmp(buf, "read-auto", 9) == 0)
+ sysfs_set_str(sra, NULL, "array_state", "clean");
+
err = sysfs_freeze_array(sra);
sysfs_free(sra);
return err;
info->new_chunk = info->array.chunk_size;
switch (info->array.level) {
+ default:
+ return "Cannot understand this RAID level";
case 1:
/* RAID1 can convert to RAID1 with different disks, or
* raid5 with 2 disks, or
if (re->after.data_disks < re->before.data_disks &&
get_linux_version() < 2006030)
- return "reshape to fewer devices is not supported before 2.6.32 - sorry.";
+ return "reshape to fewer devices is not supported before 2.6.30 - sorry.";
re->backup_blocks = compute_backup_blocks(
info->new_chunk, info->array.chunk_size,
long long size,
int level, char *layout_str, int chunksize, int raid_disks,
struct mddev_dev *devlist,
- int force)
+ int assume_clean, int force)
{
/* Make some changes in the shape of an array.
* The kernel must support the change.
/* ========= set size =============== */
if (size >= 0 && (size == 0 || size != array.size)) {
- long long orig_size = array.size;
+ long long orig_size = get_component_size(fd)/2;
+ struct mdinfo *mdi;
+
+ if (orig_size == 0)
+ orig_size = array.size;
if (reshape_super(st, size, UnSet, UnSet, 0, 0, UnSet, NULL,
devname, !quiet)) {
goto release;
}
sync_metadata(st);
+
+ /* Update the size of each member device in case
+ * they have been resized. This will never reduce
+ * below the current used-size. The "size" attribute
+ * understand '0' to mean 'max'.
+ */
+ for (mdi = sra->devs; mdi; mdi = mdi->next)
+ sysfs_set_num(sra, mdi, "size", size);
+
array.size = size;
if (array.size != size) {
/* got truncated to 32bit, write to
rv = 1;
goto release;
}
+ if (assume_clean) {
+ /* This will fail on kernels newer than 3.0 unless
+ * a backport has been arranged.
+ */
+ if (sra == NULL ||
+ sysfs_set_str(sra, NULL, "resync_start", "none") < 0)
+ fprintf(stderr, Name ": --assume-clean not support with --grow on this kernel\n");
+ }
ioctl(fd, GET_ARRAY_INFO, &array);
size = get_component_size(fd)/2;
if (size == 0)
size = array.size;
- if (!quiet)
- fprintf(stderr, Name ": component size of %s has been set to %lluK\n",
- devname, size);
+ if (!quiet) {
+ if (size == orig_size)
+ fprintf(stderr, Name ": component size of %s "
+ "unchanged at %lluK\n",
+ devname, size);
+ else
+ fprintf(stderr, Name ": component size of %s "
+ "has been set to %lluK\n",
+ devname, size);
+ }
changed = 1;
} else if (array.level != LEVEL_CONTAINER) {
size = get_component_size(fd)/2;
size = array.size;
}
+ /* See if there is anything else to do */
+ if ((level == UnSet || level == array.level) &&
+ (layout_str == NULL) &&
+ (chunksize == 0 || chunksize == array.chunk_size) &&
+ (raid_disks == 0 || raid_disks == array.raid_disks)) {
+ /* Nothing more to do */
+ if (!changed && !quiet)
+ fprintf(stderr, Name ": %s: no change requested\n",
+ devname);
+ goto release;
+ }
+
/* ========= check for Raid10/Raid1 -> Raid0 conversion ===============
* current implementation assumes that following conditions must be met:
* - RAID10:
}
}
- if (array.level == LEVEL_CONTAINER) {
+ if (array.level == LEVEL_FAULTY) {
+ if (level != UnSet && level != array.level) {
+ fprintf(stderr, Name ": cannot change level of Faulty device\n");
+ rv =1 ;
+ }
+ if (chunksize) {
+ fprintf(stderr, Name ": cannot set chunksize of Faulty device\n");
+ rv =1 ;
+ }
+ if (raid_disks && raid_disks != 1) {
+ fprintf(stderr, Name ": cannot set raid_disks of Faulty device\n");
+ rv =1 ;
+ }
+ if (layout_str) {
+ if (ioctl(fd, GET_ARRAY_INFO, &array) != 0) {
+ dprintf("Cannot get array information.\n");
+ goto release;
+ }
+ array.layout = info.new_layout;
+ if (ioctl(fd, SET_ARRAY_INFO, &array) != 0) {
+ fprintf(stderr, Name ": failed to set new layout\n");
+ rv = 1;
+ } else if (!quiet)
+ printf("layout for %s set to %d\n",
+ devname, array.layout);
+ }
+ } else if (array.level == LEVEL_CONTAINER) {
/* This change is to be applied to every array in the
* container. This is only needed when the metadata imposes
* restraints of the various arrays in the container.
if (info->reshape_active) {
int new_level = info->new_level;
info->new_level = UnSet;
+ info->array.raid_disks -= info->delta_disks;
msg = analyse_change(info, &reshape);
info->new_level = new_level;
+ info->array.raid_disks += info->delta_disks;
if (!restart)
/* Make sure the array isn't read-only */
ioctl(fd, RESTART_ARRAY_RW, 0);
if (restart &&
(reshape.level != info->array.level ||
reshape.before.layout != info->array.layout ||
- reshape.before.data_disks + reshape.parity != info->array.raid_disks)) {
+ reshape.before.data_disks + reshape.parity
+ != info->array.raid_disks - info->delta_disks)) {
fprintf(stderr, Name ": reshape info is not in native format -"
" cannot continue.\n");
goto release;
if (!mdmon_running(st->container_dev))
start_mdmon(st->container_dev);
ping_monitor(container);
+ if (mdmon_running(st->container_dev) &&
+ st->update_tail == NULL)
+ st->update_tail = &st->updates;
}
}
/* ->reshape_super might have chosen some spares from the
if (info2) {
sysfs_init(info2, fd, st->devnum);
+ /* When increasing number of devices, we need to set
+ * new raid_disks before adding these, or they might
+ * be rejected.
+ */
+ if (reshape.backup_blocks &&
+ reshape.after.data_disks > reshape.before.data_disks)
+ subarray_set_num(container, info2, "raid_disks",
+ reshape.after.data_disks +
+ reshape.parity);
for (d = info2->devs; d; d = d->next) {
if (d->disk.state == 0 &&
d->disk.raid_disk >= 0) {
*/
if (devlist)
Manage_subdevs(devname, fd, devlist, !quiet,
- 0,NULL);
+ 0,NULL, 0);
if (reshape.backup_blocks == 0) {
/* No restriping needed, but we might need to impose
if (d < 0) {
goto release;
}
- if (backup_file == NULL) {
- if (reshape.after.data_disks <= reshape.before.data_disks) {
- fprintf(stderr,
- Name ": %s: Cannot grow - need backup-file\n",
- devname);
- goto release;
- } else if (sra->array.spare_disks == 0) {
- fprintf(stderr, Name ": %s: Cannot grow - need a spare or "
- "backup-file to backup critical section\n",
- devname);
- goto release;
- }
- } else {
- if (!reshape_open_backup_file(backup_file, fd, devname,
- (signed)blocks,
- fdlist+d, offsets+d, restart)) {
- goto release;
+ if ((st->ss->manage_reshape == NULL) ||
+ (st->ss->recover_backup == NULL)) {
+ if (backup_file == NULL) {
+ if (reshape.after.data_disks <=
+ reshape.before.data_disks) {
+ fprintf(stderr, Name ": %s: Cannot grow - "
+ "need backup-file\n", devname);
+ goto release;
+ } else if (sra->array.spare_disks == 0) {
+ fprintf(stderr, Name ": %s: Cannot grow - "
+ "need a spare or backup-file to backup "
+ "critical section\n", devname);
+ goto release;
+ }
+ } else {
+ if (!reshape_open_backup_file(backup_file, fd, devname,
+ (signed)blocks,
+ fdlist+d, offsets+d,
+ restart)) {
+ goto release;
+ }
+ d++;
}
- d++;
}
/* lastly, check that the internal stripe cache is
": %s: could not set level "
"to %s\n", devname, c);
}
+ if (info->new_level == 0)
+ st->update_tail = NULL;
}
out:
if (forked)
if (fd < 0)
goto check_progress;
- if (sysfs_fd_get_ll(fd, &completed) < 0) {
- close(fd);
+ if (sysfs_fd_get_ll(fd, &completed) < 0)
goto check_progress;
- }
+
while (completed < max_progress && completed < wait_point) {
/* Check that sync_action is still 'reshape' to avoid
* waiting forever on a dead array
FD_ZERO(&rfds);
FD_SET(fd, &rfds);
select(fd+1, NULL, NULL, &rfds, NULL);
- if (sysfs_fd_get_ll(fd, &completed) < 0) {
- close(fd);
+ if (sysfs_fd_get_ll(fd, &completed) < 0)
goto check_progress;
- }
}
/* Some kernels reset 'sync_completed' to zero,
* we need to have real point we are in md
/* if we couldn't read a number from sync_completed, then
* either the reshape did complete, or it aborted.
* We can tell which by checking for 'none' in reshape_position.
+ * If it did abort, then it might immediately restart if it
+ * it was just a device failure that leaves us degraded but
+ * functioning.
*/
strcpy(buf, "hi");
if (sysfs_get_str(info, NULL, "reshape_position", buf, sizeof(buf)) < 0
- || strncmp(buf, "none", 4) != 0)
- return -2; /* abort */
- else {
+ || strncmp(buf, "none", 4) != 0) {
+ /* The abort might only be temporary. Wait up to 10
+ * seconds for fd to contain a valid number again.
+ */
+ struct timeval tv;
+ int rv = -2;
+ tv.tv_sec = 10;
+ tv.tv_usec = 0;
+ while (fd >= 0 && rv < 0 && tv.tv_sec > 0) {
+ fd_set rfds;
+ FD_ZERO(&rfds);
+ FD_SET(fd, &rfds);
+ if (select(fd+1, NULL, NULL, &rfds, &tv) != 1)
+ break;
+ switch (sysfs_fd_get_ll(fd, &completed)) {
+ case 0:
+ /* all good again */
+ rv = 1;
+ break;
+ case -2: /* read error - abort */
+ tv.tv_sec = 0;
+ break;
+ }
+ }
+ if (fd >= 0)
+ close(fd);
+ return rv; /* abort */
+ } else {
/* Maybe racing with array shutdown - check state */
+ if (fd >= 0)
+ close(fd);
if (sysfs_get_str(info, NULL, "array_state", buf, sizeof(buf)) < 0
|| strncmp(buf, "inactive", 8) == 0
|| strncmp(buf, "clear",5) == 0)
int chunk = sra->array.chunk_size;
struct mdinfo *sd;
unsigned long stripes;
+ int uuid[4];
/* set up the backup-super-block. This requires the
* uuid from the array.
continue;
ok = st->ss->load_super(st, devfd, NULL);
close(devfd);
- if (ok >= 0)
+ if (ok == 0)
break;
}
if (!sd) {
memset(&bsb, 0, 512);
memcpy(bsb.magic, "md_backup_data-1", 16);
- st->ss->uuid_from_super(st, (int*)&bsb.set_uuid);
+ st->ss->uuid_from_super(st, uuid);
+ memcpy(bsb.set_uuid, uuid, 16);
bsb.mtime = __cpu_to_le64(time(0));
bsb.devstart2 = blocks;
unsigned long long nstripe, ostripe;
int ndata, odata;
- if (info->new_level != info->array.level)
- return 1; /* Cannot handle level changes (they are instantaneous) */
-
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;
info->new_layout,
fd, __le64_to_cpu(bsb.devstart)*512,
__le64_to_cpu(bsb.arraystart)*512,
- __le64_to_cpu(bsb.length)*512)) {
+ __le64_to_cpu(bsb.length)*512, NULL)) {
/* didn't succeed, so giveup */
if (verbose)
fprintf(stderr, Name ": Error restoring backup from %s\n",
fd, __le64_to_cpu(bsb.devstart)*512 +
__le64_to_cpu(bsb.devstart2)*512,
__le64_to_cpu(bsb.arraystart2)*512,
- __le64_to_cpu(bsb.length2)*512)) {
+ __le64_to_cpu(bsb.length2)*512, NULL)) {
/* didn't succeed, so giveup */
if (verbose)
fprintf(stderr, Name ": Error restoring second backup from %s\n",
if (!mdmon_running(st->container_dev))
start_mdmon(st->container_dev);
- ping_monitor(devnum2devname(st->container_dev));
+ ping_monitor_by_id(st->container_dev);
if (info->reshape_active == 2) {