aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md/md.c
diff options
context:
space:
mode:
authorAndre Noll <maan@systemlinux.org>2009-03-30 23:33:13 -0400
committerNeilBrown <neilb@suse.de>2009-03-30 23:33:13 -0400
commitdd8ac336c13fd8afdb082ebacb1cddd5cf727889 (patch)
tree0baa8111d7406774525a1053be461135257d73d2 /drivers/md/md.c
parent58c0fed400603a802968b23ddf78f029c5a84e41 (diff)
md: Represent raid device size in sectors.
This patch renames the "size" field of struct mdk_rdev_s to "sectors" and changes this field to store sectors instead of blocks. All users of this field, linear.c, raid0.c and md.c, are fixed up accordingly which gets rid of many multiplications and divisions. Signed-off-by: Andre Noll <maan@systemlinux.org> Signed-off-by: NeilBrown <neilb@suse.de>
Diffstat (limited to 'drivers/md/md.c')
-rw-r--r--drivers/md/md.c96
1 files changed, 48 insertions, 48 deletions
diff --git a/drivers/md/md.c b/drivers/md/md.c
index be4a131e8c01..07ab6790e29d 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -413,7 +413,7 @@ static void free_disk_sb(mdk_rdev_t * rdev)
413 rdev->sb_loaded = 0; 413 rdev->sb_loaded = 0;
414 rdev->sb_page = NULL; 414 rdev->sb_page = NULL;
415 rdev->sb_start = 0; 415 rdev->sb_start = 0;
416 rdev->size = 0; 416 rdev->sectors = 0;
417 } 417 }
418} 418}
419 419
@@ -779,9 +779,9 @@ static int super_90_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version
779 else 779 else
780 ret = 0; 780 ret = 0;
781 } 781 }
782 rdev->size = calc_num_sectors(rdev, sb->chunk_size) / 2; 782 rdev->sectors = calc_num_sectors(rdev, sb->chunk_size);
783 783
784 if (rdev->size < sb->size && sb->level > 1) 784 if (rdev->sectors < sb->size * 2 && sb->level > 1)
785 /* "this cannot possibly happen" ... */ 785 /* "this cannot possibly happen" ... */
786 ret = -EINVAL; 786 ret = -EINVAL;
787 787
@@ -1184,16 +1184,17 @@ static int super_1_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version)
1184 ret = 0; 1184 ret = 0;
1185 } 1185 }
1186 if (minor_version) 1186 if (minor_version)
1187 rdev->size = ((rdev->bdev->bd_inode->i_size>>9) - le64_to_cpu(sb->data_offset)) / 2; 1187 rdev->sectors = (rdev->bdev->bd_inode->i_size >> 9) -
1188 le64_to_cpu(sb->data_offset);
1188 else 1189 else
1189 rdev->size = rdev->sb_start / 2; 1190 rdev->sectors = rdev->sb_start;
1190 if (rdev->size < le64_to_cpu(sb->data_size)/2) 1191 if (rdev->sectors < le64_to_cpu(sb->data_size))
1191 return -EINVAL; 1192 return -EINVAL;
1192 rdev->size = le64_to_cpu(sb->data_size)/2; 1193 rdev->sectors = le64_to_cpu(sb->data_size);
1193 if (le32_to_cpu(sb->chunksize)) 1194 if (le32_to_cpu(sb->chunksize))
1194 rdev->size &= ~((sector_t)le32_to_cpu(sb->chunksize)/2 - 1); 1195 rdev->sectors &= ~((sector_t)le32_to_cpu(sb->chunksize) - 1);
1195 1196
1196 if (le64_to_cpu(sb->size) > rdev->size*2) 1197 if (le64_to_cpu(sb->size) > rdev->sectors)
1197 return -EINVAL; 1198 return -EINVAL;
1198 return ret; 1199 return ret;
1199} 1200}
@@ -1390,7 +1391,7 @@ super_1_rdev_size_change(mdk_rdev_t *rdev, sector_t num_sectors)
1390 sector_t sb_start; 1391 sector_t sb_start;
1391 sb_start = (rdev->bdev->bd_inode->i_size >> 9) - 8*2; 1392 sb_start = (rdev->bdev->bd_inode->i_size >> 9) - 8*2;
1392 sb_start &= ~(sector_t)(4*2 - 1); 1393 sb_start &= ~(sector_t)(4*2 - 1);
1393 max_sectors = rdev->size * 2 + sb_start - rdev->sb_start; 1394 max_sectors = rdev->sectors + sb_start - rdev->sb_start;
1394 if (!num_sectors || num_sectors > max_sectors) 1395 if (!num_sectors || num_sectors > max_sectors)
1395 num_sectors = max_sectors; 1396 num_sectors = max_sectors;
1396 rdev->sb_start = sb_start; 1397 rdev->sb_start = sb_start;
@@ -1490,9 +1491,9 @@ static int bind_rdev_to_array(mdk_rdev_t * rdev, mddev_t * mddev)
1490 if (find_rdev(mddev, rdev->bdev->bd_dev)) 1491 if (find_rdev(mddev, rdev->bdev->bd_dev))
1491 return -EEXIST; 1492 return -EEXIST;
1492 1493
1493 /* make sure rdev->size exceeds mddev->dev_sectors / 2 */ 1494 /* make sure rdev->sectors exceeds mddev->dev_sectors */
1494 if (rdev->size && (mddev->dev_sectors == 0 || 1495 if (rdev->sectors && (mddev->dev_sectors == 0 ||
1495 rdev->size < mddev->dev_sectors / 2)) { 1496 rdev->sectors < mddev->dev_sectors)) {
1496 if (mddev->pers) { 1497 if (mddev->pers) {
1497 /* Cannot change size, so fail 1498 /* Cannot change size, so fail
1498 * If mddev->level <= 0, then we don't care 1499 * If mddev->level <= 0, then we don't care
@@ -1501,7 +1502,7 @@ static int bind_rdev_to_array(mdk_rdev_t * rdev, mddev_t * mddev)
1501 if (mddev->level > 0) 1502 if (mddev->level > 0)
1502 return -ENOSPC; 1503 return -ENOSPC;
1503 } else 1504 } else
1504 mddev->dev_sectors = rdev->size * 2; 1505 mddev->dev_sectors = rdev->sectors;
1505 } 1506 }
1506 1507
1507 /* Verify rdev->desc_nr is unique. 1508 /* Verify rdev->desc_nr is unique.
@@ -1757,8 +1758,8 @@ static void print_sb_1(struct mdp_superblock_1 *sb)
1757static void print_rdev(mdk_rdev_t *rdev, int major_version) 1758static void print_rdev(mdk_rdev_t *rdev, int major_version)
1758{ 1759{
1759 char b[BDEVNAME_SIZE]; 1760 char b[BDEVNAME_SIZE];
1760 printk(KERN_INFO "md: rdev %s, SZ:%08llu F:%d S:%d DN:%u\n", 1761 printk(KERN_INFO "md: rdev %s, Sect:%08llu F:%d S:%d DN:%u\n",
1761 bdevname(rdev->bdev,b), (unsigned long long)rdev->size, 1762 bdevname(rdev->bdev, b), (unsigned long long)rdev->sectors,
1762 test_bit(Faulty, &rdev->flags), test_bit(In_sync, &rdev->flags), 1763 test_bit(Faulty, &rdev->flags), test_bit(In_sync, &rdev->flags),
1763 rdev->desc_nr); 1764 rdev->desc_nr);
1764 if (rdev->sb_loaded) { 1765 if (rdev->sb_loaded) {
@@ -2197,7 +2198,7 @@ offset_store(mdk_rdev_t *rdev, const char *buf, size_t len)
2197 return -EINVAL; 2198 return -EINVAL;
2198 if (rdev->mddev->pers && rdev->raid_disk >= 0) 2199 if (rdev->mddev->pers && rdev->raid_disk >= 0)
2199 return -EBUSY; 2200 return -EBUSY;
2200 if (rdev->size && rdev->mddev->external) 2201 if (rdev->sectors && rdev->mddev->external)
2201 /* Must set offset before size, so overlap checks 2202 /* Must set offset before size, so overlap checks
2202 * can be sane */ 2203 * can be sane */
2203 return -EBUSY; 2204 return -EBUSY;
@@ -2211,7 +2212,7 @@ __ATTR(offset, S_IRUGO|S_IWUSR, offset_show, offset_store);
2211static ssize_t 2212static ssize_t
2212rdev_size_show(mdk_rdev_t *rdev, char *page) 2213rdev_size_show(mdk_rdev_t *rdev, char *page)
2213{ 2214{
2214 return sprintf(page, "%llu\n", (unsigned long long)rdev->size); 2215 return sprintf(page, "%llu\n", (unsigned long long)rdev->sectors / 2);
2215} 2216}
2216 2217
2217static int overlaps(sector_t s1, sector_t l1, sector_t s2, sector_t l2) 2218static int overlaps(sector_t s1, sector_t l1, sector_t s2, sector_t l2)
@@ -2227,31 +2228,31 @@ static int overlaps(sector_t s1, sector_t l1, sector_t s2, sector_t l2)
2227static ssize_t 2228static ssize_t
2228rdev_size_store(mdk_rdev_t *rdev, const char *buf, size_t len) 2229rdev_size_store(mdk_rdev_t *rdev, const char *buf, size_t len)
2229{ 2230{
2230 unsigned long long size;
2231 unsigned long long oldsize = rdev->size;
2232 mddev_t *my_mddev = rdev->mddev; 2231 mddev_t *my_mddev = rdev->mddev;
2232 sector_t oldsectors = rdev->sectors;
2233 unsigned long long sectors;
2233 2234
2234 if (strict_strtoull(buf, 10, &size) < 0) 2235 if (strict_strtoull(buf, 10, &sectors) < 0)
2235 return -EINVAL; 2236 return -EINVAL;
2237 sectors *= 2;
2236 if (my_mddev->pers && rdev->raid_disk >= 0) { 2238 if (my_mddev->pers && rdev->raid_disk >= 0) {
2237 if (my_mddev->persistent) { 2239 if (my_mddev->persistent) {
2238 size = super_types[my_mddev->major_version]. 2240 sectors = super_types[my_mddev->major_version].
2239 rdev_size_change(rdev, size * 2); 2241 rdev_size_change(rdev, sectors);
2240 if (!size) 2242 if (!sectors)
2241 return -EBUSY; 2243 return -EBUSY;
2242 } else if (!size) { 2244 } else if (!sectors)
2243 size = (rdev->bdev->bd_inode->i_size >> 10); 2245 sectors = (rdev->bdev->bd_inode->i_size >> 9) -
2244 size -= rdev->data_offset/2; 2246 rdev->data_offset;
2245 }
2246 } 2247 }
2247 if (size < my_mddev->dev_sectors / 2) 2248 if (sectors < my_mddev->dev_sectors)
2248 return -EINVAL; /* component must fit device */ 2249 return -EINVAL; /* component must fit device */
2249 2250
2250 rdev->size = size; 2251 rdev->sectors = sectors;
2251 if (size > oldsize && my_mddev->external) { 2252 if (sectors > oldsectors && my_mddev->external) {
2252 /* need to check that all other rdevs with the same ->bdev 2253 /* need to check that all other rdevs with the same ->bdev
2253 * do not overlap. We need to unlock the mddev to avoid 2254 * do not overlap. We need to unlock the mddev to avoid
2254 * a deadlock. We have already changed rdev->size, and if 2255 * a deadlock. We have already changed rdev->sectors, and if
2255 * we have to change it back, we will have the lock again. 2256 * we have to change it back, we will have the lock again.
2256 */ 2257 */
2257 mddev_t *mddev; 2258 mddev_t *mddev;
@@ -2267,9 +2268,9 @@ rdev_size_store(mdk_rdev_t *rdev, const char *buf, size_t len)
2267 if (test_bit(AllReserved, &rdev2->flags) || 2268 if (test_bit(AllReserved, &rdev2->flags) ||
2268 (rdev->bdev == rdev2->bdev && 2269 (rdev->bdev == rdev2->bdev &&
2269 rdev != rdev2 && 2270 rdev != rdev2 &&
2270 overlaps(rdev->data_offset, rdev->size * 2, 2271 overlaps(rdev->data_offset, rdev->sectors,
2271 rdev2->data_offset, 2272 rdev2->data_offset,
2272 rdev2->size * 2))) { 2273 rdev2->sectors))) {
2273 overlap = 1; 2274 overlap = 1;
2274 break; 2275 break;
2275 } 2276 }
@@ -2283,11 +2284,11 @@ rdev_size_store(mdk_rdev_t *rdev, const char *buf, size_t len)
2283 if (overlap) { 2284 if (overlap) {
2284 /* Someone else could have slipped in a size 2285 /* Someone else could have slipped in a size
2285 * change here, but doing so is just silly. 2286 * change here, but doing so is just silly.
2286 * We put oldsize back because we *know* it is 2287 * We put oldsectors back because we *know* it is
2287 * safe, and trust userspace not to race with 2288 * safe, and trust userspace not to race with
2288 * itself 2289 * itself
2289 */ 2290 */
2290 rdev->size = oldsize; 2291 rdev->sectors = oldsectors;
2291 return -EBUSY; 2292 return -EBUSY;
2292 } 2293 }
2293 } 2294 }
@@ -3760,13 +3761,13 @@ static int do_md_run(mddev_t * mddev)
3760 list_for_each_entry(rdev, &mddev->disks, same_set) { 3761 list_for_each_entry(rdev, &mddev->disks, same_set) {
3761 if (test_bit(Faulty, &rdev->flags)) 3762 if (test_bit(Faulty, &rdev->flags))
3762 continue; 3763 continue;
3763 if (rdev->size < chunk_size / 1024) { 3764 if (rdev->sectors < chunk_size / 512) {
3764 printk(KERN_WARNING 3765 printk(KERN_WARNING
3765 "md: Dev %s smaller than chunk_size:" 3766 "md: Dev %s smaller than chunk_size:"
3766 " %lluk < %dk\n", 3767 " %llu < %d\n",
3767 bdevname(rdev->bdev,b), 3768 bdevname(rdev->bdev,b),
3768 (unsigned long long)rdev->size, 3769 (unsigned long long)rdev->sectors,
3769 chunk_size / 1024); 3770 chunk_size / 512);
3770 return -EINVAL; 3771 return -EINVAL;
3771 } 3772 }
3772 } 3773 }
@@ -4585,7 +4586,7 @@ static int add_new_disk(mddev_t * mddev, mdu_disk_info_t *info)
4585 rdev->sb_start = rdev->bdev->bd_inode->i_size / 512; 4586 rdev->sb_start = rdev->bdev->bd_inode->i_size / 512;
4586 } else 4587 } else
4587 rdev->sb_start = calc_dev_sboffset(rdev->bdev); 4588 rdev->sb_start = calc_dev_sboffset(rdev->bdev);
4588 rdev->size = calc_num_sectors(rdev, mddev->chunk_size) / 2; 4589 rdev->sectors = calc_num_sectors(rdev, mddev->chunk_size);
4589 4590
4590 err = bind_rdev_to_array(rdev, mddev); 4591 err = bind_rdev_to_array(rdev, mddev);
4591 if (err) { 4592 if (err) {
@@ -4655,7 +4656,7 @@ static int hot_add_disk(mddev_t * mddev, dev_t dev)
4655 else 4656 else
4656 rdev->sb_start = rdev->bdev->bd_inode->i_size / 512; 4657 rdev->sb_start = rdev->bdev->bd_inode->i_size / 512;
4657 4658
4658 rdev->size = calc_num_sectors(rdev, mddev->chunk_size) / 2; 4659 rdev->sectors = calc_num_sectors(rdev, mddev->chunk_size);
4659 4660
4660 if (test_bit(Faulty, &rdev->flags)) { 4661 if (test_bit(Faulty, &rdev->flags)) {
4661 printk(KERN_WARNING 4662 printk(KERN_WARNING
@@ -4856,8 +4857,7 @@ static int update_size(mddev_t *mddev, sector_t num_sectors)
4856 */ 4857 */
4857 return -EBUSY; 4858 return -EBUSY;
4858 list_for_each_entry(rdev, &mddev->disks, same_set) { 4859 list_for_each_entry(rdev, &mddev->disks, same_set) {
4859 sector_t avail; 4860 sector_t avail = rdev->sectors;
4860 avail = rdev->size * 2;
4861 4861
4862 if (fit && (num_sectors == 0 || num_sectors > avail)) 4862 if (fit && (num_sectors == 0 || num_sectors > avail))
4863 num_sectors = avail; 4863 num_sectors = avail;
@@ -5585,7 +5585,7 @@ struct mdstat_info {
5585static int md_seq_show(struct seq_file *seq, void *v) 5585static int md_seq_show(struct seq_file *seq, void *v)
5586{ 5586{
5587 mddev_t *mddev = v; 5587 mddev_t *mddev = v;
5588 sector_t size; 5588 sector_t sectors;
5589 mdk_rdev_t *rdev; 5589 mdk_rdev_t *rdev;
5590 struct mdstat_info *mi = seq->private; 5590 struct mdstat_info *mi = seq->private;
5591 struct bitmap *bitmap; 5591 struct bitmap *bitmap;
@@ -5621,7 +5621,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
5621 seq_printf(seq, " %s", mddev->pers->name); 5621 seq_printf(seq, " %s", mddev->pers->name);
5622 } 5622 }
5623 5623
5624 size = 0; 5624 sectors = 0;
5625 list_for_each_entry(rdev, &mddev->disks, same_set) { 5625 list_for_each_entry(rdev, &mddev->disks, same_set) {
5626 char b[BDEVNAME_SIZE]; 5626 char b[BDEVNAME_SIZE];
5627 seq_printf(seq, " %s[%d]", 5627 seq_printf(seq, " %s[%d]",
@@ -5633,7 +5633,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
5633 continue; 5633 continue;
5634 } else if (rdev->raid_disk < 0) 5634 } else if (rdev->raid_disk < 0)
5635 seq_printf(seq, "(S)"); /* spare */ 5635 seq_printf(seq, "(S)"); /* spare */
5636 size += rdev->size; 5636 sectors += rdev->sectors;
5637 } 5637 }
5638 5638
5639 if (!list_empty(&mddev->disks)) { 5639 if (!list_empty(&mddev->disks)) {
@@ -5643,7 +5643,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
5643 mddev->array_sectors / 2); 5643 mddev->array_sectors / 2);
5644 else 5644 else
5645 seq_printf(seq, "\n %llu blocks", 5645 seq_printf(seq, "\n %llu blocks",
5646 (unsigned long long)size); 5646 (unsigned long long)sectors / 2);
5647 } 5647 }
5648 if (mddev->persistent) { 5648 if (mddev->persistent) {
5649 if (mddev->major_version != 0 || 5649 if (mddev->major_version != 0 ||