Commit dd8ac336 authored by Andre Noll's avatar Andre Noll Committed by NeilBrown

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: default avatarAndre Noll <maan@systemlinux.org>
Signed-off-by: default avatarNeilBrown <neilb@suse.de>
parent 58c0fed4
...@@ -139,8 +139,8 @@ static linear_conf_t *linear_conf(mddev_t *mddev, int raid_disks) ...@@ -139,8 +139,8 @@ static linear_conf_t *linear_conf(mddev_t *mddev, int raid_disks)
mddev->queue->max_sectors > (PAGE_SIZE>>9)) mddev->queue->max_sectors > (PAGE_SIZE>>9))
blk_queue_max_sectors(mddev->queue, PAGE_SIZE>>9); blk_queue_max_sectors(mddev->queue, PAGE_SIZE>>9);
disk->num_sectors = rdev->size * 2; disk->num_sectors = rdev->sectors;
conf->array_sectors += rdev->size * 2; conf->array_sectors += rdev->sectors;
cnt++; cnt++;
} }
......
...@@ -413,7 +413,7 @@ static void free_disk_sb(mdk_rdev_t * rdev) ...@@ -413,7 +413,7 @@ static void free_disk_sb(mdk_rdev_t * rdev)
rdev->sb_loaded = 0; rdev->sb_loaded = 0;
rdev->sb_page = NULL; rdev->sb_page = NULL;
rdev->sb_start = 0; rdev->sb_start = 0;
rdev->size = 0; rdev->sectors = 0;
} }
} }
...@@ -779,9 +779,9 @@ static int super_90_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version ...@@ -779,9 +779,9 @@ static int super_90_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version
else else
ret = 0; ret = 0;
} }
rdev->size = calc_num_sectors(rdev, sb->chunk_size) / 2; rdev->sectors = calc_num_sectors(rdev, sb->chunk_size);
if (rdev->size < sb->size && sb->level > 1) if (rdev->sectors < sb->size * 2 && sb->level > 1)
/* "this cannot possibly happen" ... */ /* "this cannot possibly happen" ... */
ret = -EINVAL; ret = -EINVAL;
...@@ -1184,16 +1184,17 @@ static int super_1_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version) ...@@ -1184,16 +1184,17 @@ static int super_1_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version)
ret = 0; ret = 0;
} }
if (minor_version) if (minor_version)
rdev->size = ((rdev->bdev->bd_inode->i_size>>9) - le64_to_cpu(sb->data_offset)) / 2; rdev->sectors = (rdev->bdev->bd_inode->i_size >> 9) -
le64_to_cpu(sb->data_offset);
else else
rdev->size = rdev->sb_start / 2; rdev->sectors = rdev->sb_start;
if (rdev->size < le64_to_cpu(sb->data_size)/2) if (rdev->sectors < le64_to_cpu(sb->data_size))
return -EINVAL; return -EINVAL;
rdev->size = le64_to_cpu(sb->data_size)/2; rdev->sectors = le64_to_cpu(sb->data_size);
if (le32_to_cpu(sb->chunksize)) if (le32_to_cpu(sb->chunksize))
rdev->size &= ~((sector_t)le32_to_cpu(sb->chunksize)/2 - 1); rdev->sectors &= ~((sector_t)le32_to_cpu(sb->chunksize) - 1);
if (le64_to_cpu(sb->size) > rdev->size*2) if (le64_to_cpu(sb->size) > rdev->sectors)
return -EINVAL; return -EINVAL;
return ret; return ret;
} }
...@@ -1390,7 +1391,7 @@ super_1_rdev_size_change(mdk_rdev_t *rdev, sector_t num_sectors) ...@@ -1390,7 +1391,7 @@ super_1_rdev_size_change(mdk_rdev_t *rdev, sector_t num_sectors)
sector_t sb_start; sector_t sb_start;
sb_start = (rdev->bdev->bd_inode->i_size >> 9) - 8*2; sb_start = (rdev->bdev->bd_inode->i_size >> 9) - 8*2;
sb_start &= ~(sector_t)(4*2 - 1); sb_start &= ~(sector_t)(4*2 - 1);
max_sectors = rdev->size * 2 + sb_start - rdev->sb_start; max_sectors = rdev->sectors + sb_start - rdev->sb_start;
if (!num_sectors || num_sectors > max_sectors) if (!num_sectors || num_sectors > max_sectors)
num_sectors = max_sectors; num_sectors = max_sectors;
rdev->sb_start = sb_start; rdev->sb_start = sb_start;
...@@ -1490,9 +1491,9 @@ static int bind_rdev_to_array(mdk_rdev_t * rdev, mddev_t * mddev) ...@@ -1490,9 +1491,9 @@ static int bind_rdev_to_array(mdk_rdev_t * rdev, mddev_t * mddev)
if (find_rdev(mddev, rdev->bdev->bd_dev)) if (find_rdev(mddev, rdev->bdev->bd_dev))
return -EEXIST; return -EEXIST;
/* make sure rdev->size exceeds mddev->dev_sectors / 2 */ /* make sure rdev->sectors exceeds mddev->dev_sectors */
if (rdev->size && (mddev->dev_sectors == 0 || if (rdev->sectors && (mddev->dev_sectors == 0 ||
rdev->size < mddev->dev_sectors / 2)) { rdev->sectors < mddev->dev_sectors)) {
if (mddev->pers) { if (mddev->pers) {
/* Cannot change size, so fail /* Cannot change size, so fail
* If mddev->level <= 0, then we don't care * 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,7 +1502,7 @@ static int bind_rdev_to_array(mdk_rdev_t * rdev, mddev_t * mddev)
if (mddev->level > 0) if (mddev->level > 0)
return -ENOSPC; return -ENOSPC;
} else } else
mddev->dev_sectors = rdev->size * 2; mddev->dev_sectors = rdev->sectors;
} }
/* Verify rdev->desc_nr is unique. /* Verify rdev->desc_nr is unique.
...@@ -1757,8 +1758,8 @@ static void print_sb_1(struct mdp_superblock_1 *sb) ...@@ -1757,8 +1758,8 @@ static void print_sb_1(struct mdp_superblock_1 *sb)
static void print_rdev(mdk_rdev_t *rdev, int major_version) static void print_rdev(mdk_rdev_t *rdev, int major_version)
{ {
char b[BDEVNAME_SIZE]; char b[BDEVNAME_SIZE];
printk(KERN_INFO "md: rdev %s, SZ:%08llu F:%d S:%d DN:%u\n", printk(KERN_INFO "md: rdev %s, Sect:%08llu F:%d S:%d DN:%u\n",
bdevname(rdev->bdev,b), (unsigned long long)rdev->size, bdevname(rdev->bdev, b), (unsigned long long)rdev->sectors,
test_bit(Faulty, &rdev->flags), test_bit(In_sync, &rdev->flags), test_bit(Faulty, &rdev->flags), test_bit(In_sync, &rdev->flags),
rdev->desc_nr); rdev->desc_nr);
if (rdev->sb_loaded) { if (rdev->sb_loaded) {
...@@ -2197,7 +2198,7 @@ offset_store(mdk_rdev_t *rdev, const char *buf, size_t len) ...@@ -2197,7 +2198,7 @@ offset_store(mdk_rdev_t *rdev, const char *buf, size_t len)
return -EINVAL; return -EINVAL;
if (rdev->mddev->pers && rdev->raid_disk >= 0) if (rdev->mddev->pers && rdev->raid_disk >= 0)
return -EBUSY; return -EBUSY;
if (rdev->size && rdev->mddev->external) if (rdev->sectors && rdev->mddev->external)
/* Must set offset before size, so overlap checks /* Must set offset before size, so overlap checks
* can be sane */ * can be sane */
return -EBUSY; return -EBUSY;
...@@ -2211,7 +2212,7 @@ __ATTR(offset, S_IRUGO|S_IWUSR, offset_show, offset_store); ...@@ -2211,7 +2212,7 @@ __ATTR(offset, S_IRUGO|S_IWUSR, offset_show, offset_store);
static ssize_t static ssize_t
rdev_size_show(mdk_rdev_t *rdev, char *page) rdev_size_show(mdk_rdev_t *rdev, char *page)
{ {
return sprintf(page, "%llu\n", (unsigned long long)rdev->size); return sprintf(page, "%llu\n", (unsigned long long)rdev->sectors / 2);
} }
static int overlaps(sector_t s1, sector_t l1, sector_t s2, sector_t l2) static 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) ...@@ -2227,31 +2228,31 @@ static int overlaps(sector_t s1, sector_t l1, sector_t s2, sector_t l2)
static ssize_t static ssize_t
rdev_size_store(mdk_rdev_t *rdev, const char *buf, size_t len) rdev_size_store(mdk_rdev_t *rdev, const char *buf, size_t len)
{ {
unsigned long long size;
unsigned long long oldsize = rdev->size;
mddev_t *my_mddev = rdev->mddev; mddev_t *my_mddev = rdev->mddev;
sector_t oldsectors = rdev->sectors;
unsigned long long sectors;
if (strict_strtoull(buf, 10, &size) < 0) if (strict_strtoull(buf, 10, &sectors) < 0)
return -EINVAL; return -EINVAL;
sectors *= 2;
if (my_mddev->pers && rdev->raid_disk >= 0) { if (my_mddev->pers && rdev->raid_disk >= 0) {
if (my_mddev->persistent) { if (my_mddev->persistent) {
size = super_types[my_mddev->major_version]. sectors = super_types[my_mddev->major_version].
rdev_size_change(rdev, size * 2); rdev_size_change(rdev, sectors);
if (!size) if (!sectors)
return -EBUSY; return -EBUSY;
} else if (!size) { } else if (!sectors)
size = (rdev->bdev->bd_inode->i_size >> 10); sectors = (rdev->bdev->bd_inode->i_size >> 9) -
size -= rdev->data_offset/2; rdev->data_offset;
}
} }
if (size < my_mddev->dev_sectors / 2) if (sectors < my_mddev->dev_sectors)
return -EINVAL; /* component must fit device */ return -EINVAL; /* component must fit device */
rdev->size = size; rdev->sectors = sectors;
if (size > oldsize && my_mddev->external) { if (sectors > oldsectors && my_mddev->external) {
/* need to check that all other rdevs with the same ->bdev /* need to check that all other rdevs with the same ->bdev
* do not overlap. We need to unlock the mddev to avoid * do not overlap. We need to unlock the mddev to avoid
* a deadlock. We have already changed rdev->size, and if * a deadlock. We have already changed rdev->sectors, and if
* we have to change it back, we will have the lock again. * we have to change it back, we will have the lock again.
*/ */
mddev_t *mddev; mddev_t *mddev;
...@@ -2267,9 +2268,9 @@ rdev_size_store(mdk_rdev_t *rdev, const char *buf, size_t len) ...@@ -2267,9 +2268,9 @@ rdev_size_store(mdk_rdev_t *rdev, const char *buf, size_t len)
if (test_bit(AllReserved, &rdev2->flags) || if (test_bit(AllReserved, &rdev2->flags) ||
(rdev->bdev == rdev2->bdev && (rdev->bdev == rdev2->bdev &&
rdev != rdev2 && rdev != rdev2 &&
overlaps(rdev->data_offset, rdev->size * 2, overlaps(rdev->data_offset, rdev->sectors,
rdev2->data_offset, rdev2->data_offset,
rdev2->size * 2))) { rdev2->sectors))) {
overlap = 1; overlap = 1;
break; break;
} }
...@@ -2283,11 +2284,11 @@ rdev_size_store(mdk_rdev_t *rdev, const char *buf, size_t len) ...@@ -2283,11 +2284,11 @@ rdev_size_store(mdk_rdev_t *rdev, const char *buf, size_t len)
if (overlap) { if (overlap) {
/* Someone else could have slipped in a size /* Someone else could have slipped in a size
* change here, but doing so is just silly. * change here, but doing so is just silly.
* We put oldsize back because we *know* it is * We put oldsectors back because we *know* it is
* safe, and trust userspace not to race with * safe, and trust userspace not to race with
* itself * itself
*/ */
rdev->size = oldsize; rdev->sectors = oldsectors;
return -EBUSY; return -EBUSY;
} }
} }
...@@ -3760,13 +3761,13 @@ static int do_md_run(mddev_t * mddev) ...@@ -3760,13 +3761,13 @@ static int do_md_run(mddev_t * mddev)
list_for_each_entry(rdev, &mddev->disks, same_set) { list_for_each_entry(rdev, &mddev->disks, same_set) {
if (test_bit(Faulty, &rdev->flags)) if (test_bit(Faulty, &rdev->flags))
continue; continue;
if (rdev->size < chunk_size / 1024) { if (rdev->sectors < chunk_size / 512) {
printk(KERN_WARNING printk(KERN_WARNING
"md: Dev %s smaller than chunk_size:" "md: Dev %s smaller than chunk_size:"
" %lluk < %dk\n", " %llu < %d\n",
bdevname(rdev->bdev,b), bdevname(rdev->bdev,b),
(unsigned long long)rdev->size, (unsigned long long)rdev->sectors,
chunk_size / 1024); chunk_size / 512);
return -EINVAL; return -EINVAL;
} }
} }
...@@ -4585,7 +4586,7 @@ static int add_new_disk(mddev_t * mddev, mdu_disk_info_t *info) ...@@ -4585,7 +4586,7 @@ static int add_new_disk(mddev_t * mddev, mdu_disk_info_t *info)
rdev->sb_start = rdev->bdev->bd_inode->i_size / 512; rdev->sb_start = rdev->bdev->bd_inode->i_size / 512;
} else } else
rdev->sb_start = calc_dev_sboffset(rdev->bdev); rdev->sb_start = calc_dev_sboffset(rdev->bdev);
rdev->size = calc_num_sectors(rdev, mddev->chunk_size) / 2; rdev->sectors = calc_num_sectors(rdev, mddev->chunk_size);
err = bind_rdev_to_array(rdev, mddev); err = bind_rdev_to_array(rdev, mddev);
if (err) { if (err) {
...@@ -4655,7 +4656,7 @@ static int hot_add_disk(mddev_t * mddev, dev_t dev) ...@@ -4655,7 +4656,7 @@ static int hot_add_disk(mddev_t * mddev, dev_t dev)
else else
rdev->sb_start = rdev->bdev->bd_inode->i_size / 512; rdev->sb_start = rdev->bdev->bd_inode->i_size / 512;
rdev->size = calc_num_sectors(rdev, mddev->chunk_size) / 2; rdev->sectors = calc_num_sectors(rdev, mddev->chunk_size);
if (test_bit(Faulty, &rdev->flags)) { if (test_bit(Faulty, &rdev->flags)) {
printk(KERN_WARNING printk(KERN_WARNING
...@@ -4856,8 +4857,7 @@ static int update_size(mddev_t *mddev, sector_t num_sectors) ...@@ -4856,8 +4857,7 @@ static int update_size(mddev_t *mddev, sector_t num_sectors)
*/ */
return -EBUSY; return -EBUSY;
list_for_each_entry(rdev, &mddev->disks, same_set) { list_for_each_entry(rdev, &mddev->disks, same_set) {
sector_t avail; sector_t avail = rdev->sectors;
avail = rdev->size * 2;
if (fit && (num_sectors == 0 || num_sectors > avail)) if (fit && (num_sectors == 0 || num_sectors > avail))
num_sectors = avail; num_sectors = avail;
...@@ -5585,7 +5585,7 @@ struct mdstat_info { ...@@ -5585,7 +5585,7 @@ struct mdstat_info {
static int md_seq_show(struct seq_file *seq, void *v) static int md_seq_show(struct seq_file *seq, void *v)
{ {
mddev_t *mddev = v; mddev_t *mddev = v;
sector_t size; sector_t sectors;
mdk_rdev_t *rdev; mdk_rdev_t *rdev;
struct mdstat_info *mi = seq->private; struct mdstat_info *mi = seq->private;
struct bitmap *bitmap; struct bitmap *bitmap;
...@@ -5621,7 +5621,7 @@ static int md_seq_show(struct seq_file *seq, void *v) ...@@ -5621,7 +5621,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
seq_printf(seq, " %s", mddev->pers->name); seq_printf(seq, " %s", mddev->pers->name);
} }
size = 0; sectors = 0;
list_for_each_entry(rdev, &mddev->disks, same_set) { list_for_each_entry(rdev, &mddev->disks, same_set) {
char b[BDEVNAME_SIZE]; char b[BDEVNAME_SIZE];
seq_printf(seq, " %s[%d]", seq_printf(seq, " %s[%d]",
...@@ -5633,7 +5633,7 @@ static int md_seq_show(struct seq_file *seq, void *v) ...@@ -5633,7 +5633,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
continue; continue;
} else if (rdev->raid_disk < 0) } else if (rdev->raid_disk < 0)
seq_printf(seq, "(S)"); /* spare */ seq_printf(seq, "(S)"); /* spare */
size += rdev->size; sectors += rdev->sectors;
} }
if (!list_empty(&mddev->disks)) { if (!list_empty(&mddev->disks)) {
...@@ -5643,7 +5643,7 @@ static int md_seq_show(struct seq_file *seq, void *v) ...@@ -5643,7 +5643,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
mddev->array_sectors / 2); mddev->array_sectors / 2);
else else
seq_printf(seq, "\n %llu blocks", seq_printf(seq, "\n %llu blocks",
(unsigned long long)size); (unsigned long long)sectors / 2);
} }
if (mddev->persistent) { if (mddev->persistent) {
if (mddev->major_version != 0 || if (mddev->major_version != 0 ||
......
...@@ -36,7 +36,7 @@ struct mdk_rdev_s ...@@ -36,7 +36,7 @@ struct mdk_rdev_s
{ {
struct list_head same_set; /* RAID devices within the same set */ struct list_head same_set; /* RAID devices within the same set */
sector_t size; /* Device size (in blocks) */ sector_t sectors; /* Device size (in 512bytes sectors) */
mddev_t *mddev; /* RAID array if running */ mddev_t *mddev; /* RAID array if running */
int last_events; /* IO event timestamp */ int last_events; /* IO event timestamp */
......
...@@ -76,16 +76,15 @@ static int create_strip_zones (mddev_t *mddev) ...@@ -76,16 +76,15 @@ static int create_strip_zones (mddev_t *mddev)
list_for_each_entry(rdev2, &mddev->disks, same_set) { list_for_each_entry(rdev2, &mddev->disks, same_set) {
printk(KERN_INFO "raid0: comparing %s(%llu)", printk(KERN_INFO "raid0: comparing %s(%llu)",
bdevname(rdev1->bdev,b), bdevname(rdev1->bdev,b),
(unsigned long long)rdev1->size); (unsigned long long)rdev1->sectors);
printk(KERN_INFO " with %s(%llu)\n", printk(KERN_INFO " with %s(%llu)\n",
bdevname(rdev2->bdev,b), bdevname(rdev2->bdev,b),
(unsigned long long)rdev2->size); (unsigned long long)rdev2->sectors);
if (rdev2 == rdev1) { if (rdev2 == rdev1) {
printk(KERN_INFO "raid0: END\n"); printk(KERN_INFO "raid0: END\n");
break; break;
} }
if (rdev2->size == rdev1->size) if (rdev2->sectors == rdev1->sectors) {
{
/* /*
* Not unique, don't count it as a new * Not unique, don't count it as a new
* group * group
...@@ -148,7 +147,7 @@ static int create_strip_zones (mddev_t *mddev) ...@@ -148,7 +147,7 @@ static int create_strip_zones (mddev_t *mddev)
mddev->queue->max_sectors > (PAGE_SIZE>>9)) mddev->queue->max_sectors > (PAGE_SIZE>>9))
blk_queue_max_sectors(mddev->queue, PAGE_SIZE>>9); blk_queue_max_sectors(mddev->queue, PAGE_SIZE>>9);
if (!smallest || (rdev1->size <smallest->size)) if (!smallest || (rdev1->sectors < smallest->sectors))
smallest = rdev1; smallest = rdev1;
cnt++; cnt++;
} }
...@@ -158,10 +157,10 @@ static int create_strip_zones (mddev_t *mddev) ...@@ -158,10 +157,10 @@ static int create_strip_zones (mddev_t *mddev)
goto abort; goto abort;
} }
zone->nb_dev = cnt; zone->nb_dev = cnt;
zone->sectors = smallest->size * cnt * 2; zone->sectors = smallest->sectors * cnt;
zone->zone_start = 0; zone->zone_start = 0;
current_start = smallest->size * 2; current_start = smallest->sectors;
curr_zone_start = zone->sectors; curr_zone_start = zone->sectors;
/* now do the other zones */ /* now do the other zones */
...@@ -180,29 +179,29 @@ static int create_strip_zones (mddev_t *mddev) ...@@ -180,29 +179,29 @@ static int create_strip_zones (mddev_t *mddev)
rdev = conf->strip_zone[0].dev[j]; rdev = conf->strip_zone[0].dev[j];
printk(KERN_INFO "raid0: checking %s ...", printk(KERN_INFO "raid0: checking %s ...",
bdevname(rdev->bdev, b)); bdevname(rdev->bdev, b));
if (rdev->size > current_start / 2) { if (rdev->sectors <= current_start) {
printk(KERN_INFO " contained as device %d\n",
c);
zone->dev[c] = rdev;
c++;
if (!smallest || (rdev->size <smallest->size)) {
smallest = rdev;
printk(KERN_INFO " (%llu) is smallest!.\n",
(unsigned long long)rdev->size);
}
} else
printk(KERN_INFO " nope.\n"); printk(KERN_INFO " nope.\n");
continue;
}
printk(KERN_INFO " contained as device %d\n", c);
zone->dev[c] = rdev;
c++;
if (!smallest || rdev->sectors < smallest->sectors) {
smallest = rdev;
printk(KERN_INFO " (%llu) is smallest!.\n",
(unsigned long long)rdev->sectors);
}
} }
zone->nb_dev = c; zone->nb_dev = c;
zone->sectors = (smallest->size * 2 - current_start) * c; zone->sectors = (smallest->sectors - current_start) * c;
printk(KERN_INFO "raid0: zone->nb_dev: %d, sectors: %llu\n", printk(KERN_INFO "raid0: zone->nb_dev: %d, sectors: %llu\n",
zone->nb_dev, (unsigned long long)zone->sectors); zone->nb_dev, (unsigned long long)zone->sectors);
zone->zone_start = curr_zone_start; zone->zone_start = curr_zone_start;
curr_zone_start += zone->sectors; curr_zone_start += zone->sectors;
current_start = smallest->size * 2; current_start = smallest->sectors;
printk(KERN_INFO "raid0: current zone start: %llu\n", printk(KERN_INFO "raid0: current zone start: %llu\n",
(unsigned long long)current_start); (unsigned long long)current_start);
} }
...@@ -296,7 +295,7 @@ static int raid0_run (mddev_t *mddev) ...@@ -296,7 +295,7 @@ static int raid0_run (mddev_t *mddev)
/* calculate array device size */ /* calculate array device size */
mddev->array_sectors = 0; mddev->array_sectors = 0;
list_for_each_entry(rdev, &mddev->disks, same_set) list_for_each_entry(rdev, &mddev->disks, same_set)
mddev->array_sectors += rdev->size * 2; mddev->array_sectors += rdev->sectors;
printk(KERN_INFO "raid0 : md_size is %llu sectors.\n", printk(KERN_INFO "raid0 : md_size is %llu sectors.\n",
(unsigned long long)mddev->array_sectors); (unsigned long long)mddev->array_sectors);
......
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