aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md/md.c
diff options
context:
space:
mode:
authorAndre Noll <maan@systemlinux.org>2008-07-11 08:02:22 -0400
committerNeil Brown <neilb@suse.de>2008-07-11 08:02:22 -0400
commitd71f9f88d74166dcdef743a057f9222d64d2d509 (patch)
treeaf2c0a93855347bce2fc24ecffa27be035bc8ef0 /drivers/md/md.c
parentdf5b20cf68f9c90204c5fd36b7b090635cee3cdf (diff)
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: Andre Noll <maan@systemlinux.org> Signed-off-by: Neil Brown <neilb@suse.de>
Diffstat (limited to 'drivers/md/md.c')
-rw-r--r--drivers/md/md.c36
1 files changed, 18 insertions, 18 deletions
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 4c4c79da72b9..158c38f54a40 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -2890,7 +2890,7 @@ size_show(mddev_t *mddev, char *page)
2890 return sprintf(page, "%llu\n", (unsigned long long)mddev->size); 2890 return sprintf(page, "%llu\n", (unsigned long long)mddev->size);
2891} 2891}
2892 2892
2893static int update_size(mddev_t *mddev, unsigned long size); 2893static int update_size(mddev_t *mddev, sector_t num_sectors);
2894 2894
2895static ssize_t 2895static ssize_t
2896size_store(mddev_t *mddev, const char *buf, size_t len) 2896size_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 return -EINVAL; 2907 return -EINVAL;
2908 2908
2909 if (mddev->pers) { 2909 if (mddev->pers) {
2910 err = update_size(mddev, size); 2910 err = update_size(mddev, size * 2);
2911 md_update_sb(mddev, 1); 2911 md_update_sb(mddev, 1);
2912 } else { 2912 } else {
2913 if (mddev->size == 0 || 2913 if (mddev->size == 0 ||
@@ -4617,24 +4617,24 @@ static int set_array_info(mddev_t * mddev, mdu_array_info_t *info)
4617 return 0; 4617 return 0;
4618} 4618}
4619 4619
4620static int update_size(mddev_t *mddev, unsigned long size) 4620static int update_size(mddev_t *mddev, sector_t num_sectors)
4621{ 4621{
4622 mdk_rdev_t * rdev; 4622 mdk_rdev_t * rdev;
4623 int rv; 4623 int rv;
4624 struct list_head *tmp; 4624 struct list_head *tmp;
4625 int fit = (size == 0); 4625 int fit = (num_sectors == 0);
4626 4626
4627 if (mddev->pers->resize == NULL) 4627 if (mddev->pers->resize == NULL)
4628 return -EINVAL; 4628 return -EINVAL;
4629 /* The "size" is the amount of each device that is used. 4629 /* The "num_sectors" is the number of sectors of each device that
4630 * This can only make sense for arrays with redundancy. 4630 * is used. This can only make sense for arrays with redundancy.
4631 * linear and raid0 always use whatever space is available 4631 * linear and raid0 always use whatever space is available. We can only
4632 * We can only consider changing the size if no resync 4632 * consider changing this number if no resync or reconstruction is
4633 * or reconstruction is happening, and if the new size 4633 * happening, and if the new size is acceptable. It must fit before the
4634 * is acceptable. It must fit before the sb_offset or, 4634 * sb_offset or, if that is <data_offset, it must fit before the size
4635 * if that is <data_offset, it must fit before the 4635 * of each device. If num_sectors is zero, we find the largest size
4636 * size of each device. 4636 * that fits.
4637 * If size is zero, we find the largest size that fits. 4637
4638 */ 4638 */
4639 if (mddev->sync_thread) 4639 if (mddev->sync_thread)
4640 return -EBUSY; 4640 return -EBUSY;
@@ -4642,12 +4642,12 @@ static int update_size(mddev_t *mddev, unsigned long size)
4642 sector_t avail; 4642 sector_t avail;
4643 avail = rdev->size * 2; 4643 avail = rdev->size * 2;
4644 4644
4645 if (fit && (size == 0 || size > avail/2)) 4645 if (fit && (num_sectors == 0 || num_sectors > avail))
4646 size = avail/2; 4646 num_sectors = avail;
4647 if (avail < ((sector_t)size << 1)) 4647 if (avail < num_sectors)
4648 return -ENOSPC; 4648 return -ENOSPC;
4649 } 4649 }
4650 rv = mddev->pers->resize(mddev, (sector_t)size *2); 4650 rv = mddev->pers->resize(mddev, num_sectors);
4651 if (!rv) { 4651 if (!rv) {
4652 struct block_device *bdev; 4652 struct block_device *bdev;
4653 4653
@@ -4729,7 +4729,7 @@ static int update_array_info(mddev_t *mddev, mdu_array_info_t *info)
4729 return mddev->pers->reconfig(mddev, info->layout, -1); 4729 return mddev->pers->reconfig(mddev, info->layout, -1);
4730 } 4730 }
4731 if (info->size >= 0 && mddev->size != info->size) 4731 if (info->size >= 0 && mddev->size != info->size)
4732 rv = update_size(mddev, info->size); 4732 rv = update_size(mddev, (sector_t)info->size * 2);
4733 4733
4734 if (mddev->raid_disks != info->raid_disks) 4734 if (mddev->raid_disks != info->raid_disks)
4735 rv = update_raid_disks(mddev, info->raid_disks); 4735 rv = update_raid_disks(mddev, info->raid_disks);