Commit 0002b271 authored by NeilBrown's avatar NeilBrown Committed by Linus Torvalds

[PATCH] md: limit size of sb read/written to appropriate amount

version-1 superblocks are not (normally) 4K long, and can be of variable size.
 Writing the full 4K can cause corruption (but only in non-default
configurations).

With this patch the super-block-flavour can choose a size to read, and set a
size to write based on what it finds.
Signed-off-by: default avatarNeil Brown <neilb@cse.unsw.edu.au>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 773f7834
...@@ -393,7 +393,7 @@ int sync_page_io(struct block_device *bdev, sector_t sector, int size, ...@@ -393,7 +393,7 @@ int sync_page_io(struct block_device *bdev, sector_t sector, int size,
return ret; return ret;
} }
static int read_disk_sb(mdk_rdev_t * rdev) static int read_disk_sb(mdk_rdev_t * rdev, int size)
{ {
char b[BDEVNAME_SIZE]; char b[BDEVNAME_SIZE];
if (!rdev->sb_page) { if (!rdev->sb_page) {
...@@ -404,7 +404,7 @@ static int read_disk_sb(mdk_rdev_t * rdev) ...@@ -404,7 +404,7 @@ static int read_disk_sb(mdk_rdev_t * rdev)
return 0; return 0;
if (!sync_page_io(rdev->bdev, rdev->sb_offset<<1, MD_SB_BYTES, rdev->sb_page, READ)) if (!sync_page_io(rdev->bdev, rdev->sb_offset<<1, size, rdev->sb_page, READ))
goto fail; goto fail;
rdev->sb_loaded = 1; rdev->sb_loaded = 1;
return 0; return 0;
...@@ -531,7 +531,7 @@ static int super_90_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version ...@@ -531,7 +531,7 @@ static int super_90_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version
sb_offset = calc_dev_sboffset(rdev->bdev); sb_offset = calc_dev_sboffset(rdev->bdev);
rdev->sb_offset = sb_offset; rdev->sb_offset = sb_offset;
ret = read_disk_sb(rdev); ret = read_disk_sb(rdev, MD_SB_BYTES);
if (ret) return ret; if (ret) return ret;
ret = -EINVAL; ret = -EINVAL;
...@@ -564,6 +564,7 @@ static int super_90_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version ...@@ -564,6 +564,7 @@ static int super_90_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version
rdev->preferred_minor = sb->md_minor; rdev->preferred_minor = sb->md_minor;
rdev->data_offset = 0; rdev->data_offset = 0;
rdev->sb_size = MD_SB_BYTES;
if (sb->level == LEVEL_MULTIPATH) if (sb->level == LEVEL_MULTIPATH)
rdev->desc_nr = -1; rdev->desc_nr = -1;
...@@ -837,6 +838,7 @@ static int super_1_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version) ...@@ -837,6 +838,7 @@ static int super_1_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version)
int ret; int ret;
sector_t sb_offset; sector_t sb_offset;
char b[BDEVNAME_SIZE], b2[BDEVNAME_SIZE]; char b[BDEVNAME_SIZE], b2[BDEVNAME_SIZE];
int bmask;
/* /*
* Calculate the position of the superblock. * Calculate the position of the superblock.
...@@ -865,7 +867,10 @@ static int super_1_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version) ...@@ -865,7 +867,10 @@ static int super_1_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version)
} }
rdev->sb_offset = sb_offset; rdev->sb_offset = sb_offset;
ret = read_disk_sb(rdev); /* superblock is rarely larger than 1K, but it can be larger,
* and it is safe to read 4k, so we do that
*/
ret = read_disk_sb(rdev, 4096);
if (ret) return ret; if (ret) return ret;
...@@ -891,6 +896,11 @@ static int super_1_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version) ...@@ -891,6 +896,11 @@ static int super_1_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version)
rdev->preferred_minor = 0xffff; rdev->preferred_minor = 0xffff;
rdev->data_offset = le64_to_cpu(sb->data_offset); rdev->data_offset = le64_to_cpu(sb->data_offset);
rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
bmask = block_size(rdev->bdev)-1;
if (rdev->sb_size & bmask)
rdev-> sb_size = (rdev->sb_size | bmask)+1;
if (refdev == 0) if (refdev == 0)
return 1; return 1;
else { else {
...@@ -1375,7 +1385,7 @@ repeat: ...@@ -1375,7 +1385,7 @@ repeat:
dprintk("%s ", bdevname(rdev->bdev,b)); dprintk("%s ", bdevname(rdev->bdev,b));
if (!rdev->faulty) { if (!rdev->faulty) {
md_super_write(mddev,rdev, md_super_write(mddev,rdev,
rdev->sb_offset<<1, MD_SB_BYTES, rdev->sb_offset<<1, rdev->sb_size,
rdev->sb_page); rdev->sb_page);
dprintk(KERN_INFO "(write) %s's sb offset: %llu\n", dprintk(KERN_INFO "(write) %s's sb offset: %llu\n",
bdevname(rdev->bdev,b), bdevname(rdev->bdev,b),
......
...@@ -102,6 +102,7 @@ struct mdk_rdev_s ...@@ -102,6 +102,7 @@ struct mdk_rdev_s
int sb_loaded; int sb_loaded;
sector_t data_offset; /* start of data in array */ sector_t data_offset; /* start of data in array */
sector_t sb_offset; sector_t sb_offset;
int sb_size; /* bytes in the superblock */
int preferred_minor; /* autorun support */ int preferred_minor; /* autorun support */
/* A device can be in one of three states based on two flags: /* A device can be in one of three states based on two flags:
......
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