Skip to content

Commit

Permalink
md/raid5: reallocate page array after setting new stripe_size
Browse files Browse the repository at this point in the history
When try to resize stripe_size, we also need to free old
shared page array and allocate new.

Signed-off-by: Yufen Yu <yuyufen@huawei.com>
Signed-off-by: Song Liu <songliubraving@fb.com>
  • Loading branch information
Yufen Yu authored and Song Liu committed Sep 24, 2020
1 parent f16acaf commit 3891258
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions drivers/md/raid5.c
Original file line number Diff line number Diff line change
Expand Up @@ -6682,6 +6682,7 @@ raid5_store_stripe_size(struct mddev *mddev, const char *page, size_t len)
struct r5conf *conf;
unsigned long new;
int err;
int size;

if (len >= PAGE_SIZE)
return -EINVAL;
Expand Down Expand Up @@ -6714,10 +6715,29 @@ raid5_store_stripe_size(struct mddev *mddev, const char *page, size_t len)
pr_debug("md/raid: change stripe_size from %lu to %lu\n",
conf->stripe_size, new);

if (mddev->sync_thread ||
test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) ||
mddev->reshape_position != MaxSector ||
mddev->sysfs_active) {
err = -EBUSY;
goto out_unlock;
}

mddev_suspend(mddev);
mutex_lock(&conf->cache_size_mutex);
size = conf->max_nr_stripes;

shrink_stripes(conf);

conf->stripe_size = new;
conf->stripe_shift = ilog2(new) - 9;
conf->stripe_sectors = new >> 9;
if (grow_stripes(conf, size)) {
pr_warn("md/raid:%s: couldn't allocate buffers\n",
mdname(mddev));
err = -ENOMEM;
}
mutex_unlock(&conf->cache_size_mutex);
mddev_resume(mddev);

out_unlock:
Expand Down

0 comments on commit 3891258

Please sign in to comment.