Commit d71f9f88 authored by Andre Noll's avatar Andre Noll Committed by Neil Brown

md: Make update_size() take the number of sectors.

Changing the internal representations of sizes of raid devices
from 1K blocks to sector counts (512B units) is desirable because
it allows to get rid of many divisions/multiplications and unnecessary
casts that are present in the current code.

This patch is a first step in this direction. It replaces the old
1K-based "size" argument of update_size() by "num_sectors" and
fixes up its two callers.
Signed-off-by: default avatarAndre Noll <maan@systemlinux.org>
Signed-off-by: default avatarNeil Brown <neilb@suse.de>
parent df5b20cf
...@@ -2890,7 +2890,7 @@ size_show(mddev_t *mddev, char *page) ...@@ -2890,7 +2890,7 @@ size_show(mddev_t *mddev, char *page)
return sprintf(page, "%llu\n", (unsigned long long)mddev->size); return sprintf(page, "%llu\n", (unsigned long long)mddev->size);
} }
static int update_size(mddev_t *mddev, unsigned long size); static int update_size(mddev_t *mddev, sector_t num_sectors);
static ssize_t static ssize_t
size_store(mddev_t *mddev, const char *buf, size_t len) size_store(mddev_t *mddev, const char *buf, size_t len)
...@@ -2907,7 +2907,7 @@ size_store(mddev_t *mddev, const char *buf, size_t len) ...@@ -2907,7 +2907,7 @@ size_store(mddev_t *mddev, const char *buf, size_t len)
return -EINVAL; return -EINVAL;
if (mddev->pers) { if (mddev->pers) {
err = update_size(mddev, size); err = update_size(mddev, size * 2);
md_update_sb(mddev, 1); md_update_sb(mddev, 1);
} else { } else {
if (mddev->size == 0 || if (mddev->size == 0 ||
...@@ -4617,24 +4617,24 @@ static int set_array_info(mddev_t * mddev, mdu_array_info_t *info) ...@@ -4617,24 +4617,24 @@ static int set_array_info(mddev_t * mddev, mdu_array_info_t *info)
return 0; return 0;
} }
static int update_size(mddev_t *mddev, unsigned long size) static int update_size(mddev_t *mddev, sector_t num_sectors)
{ {
mdk_rdev_t * rdev; mdk_rdev_t * rdev;
int rv; int rv;
struct list_head *tmp; struct list_head *tmp;
int fit = (size == 0); int fit = (num_sectors == 0);
if (mddev->pers->resize == NULL) if (mddev->pers->resize == NULL)
return -EINVAL; return -EINVAL;
/* The "size" is the amount of each device that is used. /* The "num_sectors" is the number of sectors of each device that
* This can only make sense for arrays with redundancy. * is used. This can only make sense for arrays with redundancy.
* linear and raid0 always use whatever space is available * linear and raid0 always use whatever space is available. We can only
* We can only consider changing the size if no resync * consider changing this number if no resync or reconstruction is
* or reconstruction is happening, and if the new size * happening, and if the new size is acceptable. It must fit before the
* is acceptable. It must fit before the sb_offset or, * sb_offset or, if that is <data_offset, it must fit before the size
* if that is <data_offset, it must fit before the * of each device. If num_sectors is zero, we find the largest size
* size of each device. * that fits.
* If size is zero, we find the largest size that fits.
*/ */
if (mddev->sync_thread) if (mddev->sync_thread)
return -EBUSY; return -EBUSY;
...@@ -4642,12 +4642,12 @@ static int update_size(mddev_t *mddev, unsigned long size) ...@@ -4642,12 +4642,12 @@ static int update_size(mddev_t *mddev, unsigned long size)
sector_t avail; sector_t avail;
avail = rdev->size * 2; avail = rdev->size * 2;
if (fit && (size == 0 || size > avail/2)) if (fit && (num_sectors == 0 || num_sectors > avail))
size = avail/2; num_sectors = avail;
if (avail < ((sector_t)size << 1)) if (avail < num_sectors)
return -ENOSPC; return -ENOSPC;
} }
rv = mddev->pers->resize(mddev, (sector_t)size *2); rv = mddev->pers->resize(mddev, num_sectors);
if (!rv) { if (!rv) {
struct block_device *bdev; struct block_device *bdev;
...@@ -4729,7 +4729,7 @@ static int update_array_info(mddev_t *mddev, mdu_array_info_t *info) ...@@ -4729,7 +4729,7 @@ static int update_array_info(mddev_t *mddev, mdu_array_info_t *info)
return mddev->pers->reconfig(mddev, info->layout, -1); return mddev->pers->reconfig(mddev, info->layout, -1);
} }
if (info->size >= 0 && mddev->size != info->size) if (info->size >= 0 && mddev->size != info->size)
rv = update_size(mddev, info->size); rv = update_size(mddev, (sector_t)info->size * 2);
if (mddev->raid_disks != info->raid_disks) if (mddev->raid_disks != info->raid_disks)
rv = update_raid_disks(mddev, info->raid_disks); rv = update_raid_disks(mddev, info->raid_disks);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment