Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Andre Noll and committed by
Neil Brown
d71f9f88 df5b20cf

+18 -18
+18 -18
drivers/md/md.c
··· 2890 2890 return sprintf(page, "%llu\n", (unsigned long long)mddev->size); 2891 2891 } 2892 2892 2893 - static int update_size(mddev_t *mddev, unsigned long size); 2893 + static int update_size(mddev_t *mddev, sector_t num_sectors); 2894 2894 2895 2895 static ssize_t 2896 2896 size_store(mddev_t *mddev, const char *buf, size_t len) ··· 2907 2907 return -EINVAL; 2908 2908 2909 2909 if (mddev->pers) { 2910 - err = update_size(mddev, size); 2910 + err = update_size(mddev, size * 2); 2911 2911 md_update_sb(mddev, 1); 2912 2912 } else { 2913 2913 if (mddev->size == 0 || ··· 4617 4617 return 0; 4618 4618 } 4619 4619 4620 - static int update_size(mddev_t *mddev, unsigned long size) 4620 + static int update_size(mddev_t *mddev, sector_t num_sectors) 4621 4621 { 4622 4622 mdk_rdev_t * rdev; 4623 4623 int rv; 4624 4624 struct list_head *tmp; 4625 - int fit = (size == 0); 4625 + int fit = (num_sectors == 0); 4626 4626 4627 4627 if (mddev->pers->resize == NULL) 4628 4628 return -EINVAL; 4629 - /* The "size" is the amount of each device that is used. 4630 - * This can only make sense for arrays with redundancy. 4631 - * linear and raid0 always use whatever space is available 4632 - * We can only consider changing the size if no resync 4633 - * or reconstruction is happening, and if the new size 4634 - * is acceptable. It must fit before the sb_offset or, 4635 - * if that is <data_offset, it must fit before the 4636 - * size of each device. 4637 - * If size is zero, we find the largest size that fits. 4629 + /* The "num_sectors" is the number of sectors of each device that 4630 + * is used. This can only make sense for arrays with redundancy. 4631 + * linear and raid0 always use whatever space is available. We can only 4632 + * consider changing this number if no resync or reconstruction is 4633 + * happening, and if the new size is acceptable. It must fit before the 4634 + * sb_offset or, if that is <data_offset, it must fit before the size 4635 + * of each device. If num_sectors is zero, we find the largest size 4636 + * that fits. 4637 + 4638 4638 */ 4639 4639 if (mddev->sync_thread) 4640 4640 return -EBUSY; ··· 4642 4642 sector_t avail; 4643 4643 avail = rdev->size * 2; 4644 4644 4645 - if (fit && (size == 0 || size > avail/2)) 4646 - size = avail/2; 4647 - if (avail < ((sector_t)size << 1)) 4645 + if (fit && (num_sectors == 0 || num_sectors > avail)) 4646 + num_sectors = avail; 4647 + if (avail < num_sectors) 4648 4648 return -ENOSPC; 4649 4649 } 4650 - rv = mddev->pers->resize(mddev, (sector_t)size *2); 4650 + rv = mddev->pers->resize(mddev, num_sectors); 4651 4651 if (!rv) { 4652 4652 struct block_device *bdev; 4653 4653 ··· 4729 4729 return mddev->pers->reconfig(mddev, info->layout, -1); 4730 4730 } 4731 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 4734 if (mddev->raid_disks != info->raid_disks) 4735 4735 rv = update_raid_disks(mddev, info->raid_disks);