From: NeilBrown <neilb@suse.de>
To: Andrew Morton <akpm@osdl.org>
Cc: linux-raid@vger.kernel.org
Subject: [PATCH md 015 of 20] Keep better track of dev/array size when assembling md arrays.
Date: Mon, 12 Dec 2005 14:15:29 +1100 [thread overview]
Message-ID: <1051212031529.5152@suse.de> (raw)
In-Reply-To: 20051212135705.4561.patches@notabene
Move the checks - that dev size is never less than array size - into
bind_rdev_to_array to make sure it always happens properly (there is
one place where currently it doesn't).
Also reject any superblock which claims an array size smaller than the
device in question can hold.
Signed-off-by: Neil Brown <neilb@suse.de>
### Diffstat output
./drivers/md/md.c | 41 +++++++++++++++++++++++------------------
1 file changed, 23 insertions(+), 18 deletions(-)
diff ./drivers/md/md.c~current~ ./drivers/md/md.c
--- ./drivers/md/md.c~current~ 2005-12-12 11:35:53.000000000 +1100
+++ ./drivers/md/md.c 2005-12-12 11:36:25.000000000 +1100
@@ -695,6 +695,10 @@ static int super_90_load(mdk_rdev_t *rde
}
rdev->size = calc_dev_size(rdev, sb->chunk_size);
+ if (rdev->size < sb->size && sb->level > 1)
+ /* "this cannot possibly happen" ... */
+ ret = -EINVAL;
+
abort:
return ret;
}
@@ -1039,6 +1043,9 @@ static int super_1_load(mdk_rdev_t *rdev
rdev->size = le64_to_cpu(sb->data_size)/2;
if (le32_to_cpu(sb->chunksize))
rdev->size &= ~((sector_t)le32_to_cpu(sb->chunksize)/2 - 1);
+
+ if (le32_to_cpu(sb->size) > rdev->size*2)
+ return -EINVAL;
return 0;
}
@@ -1224,6 +1231,14 @@ static int bind_rdev_to_array(mdk_rdev_t
MD_BUG();
return -EINVAL;
}
+ /* make sure rdev->size exceeds mddev->size */
+ if (rdev->size && (mddev->size == 0 || rdev->size < mddev->size)) {
+ if (mddev->pers)
+ /* Cannot change size, so fail */
+ return -ENOSPC;
+ else
+ mddev->size = rdev->size;
+ }
same_pdev = match_dev_unit(mddev, rdev);
if (same_pdev)
printk(KERN_WARNING
@@ -2898,12 +2913,6 @@ static int add_new_disk(mddev_t * mddev,
if (info->state & (1<<MD_DISK_WRITEMOSTLY))
set_bit(WriteMostly, &rdev->flags);
- err = bind_rdev_to_array(rdev, mddev);
- if (err) {
- export_rdev(rdev);
- return err;
- }
-
if (!mddev->persistent) {
printk(KERN_INFO "md: nonpersistent superblock ...\n");
rdev->sb_offset = rdev->bdev->bd_inode->i_size >> BLOCK_SIZE_BITS;
@@ -2911,8 +2920,11 @@ static int add_new_disk(mddev_t * mddev,
rdev->sb_offset = calc_dev_sboffset(rdev->bdev);
rdev->size = calc_dev_size(rdev, mddev->chunk_size);
- if (!mddev->size || (mddev->size > rdev->size))
- mddev->size = rdev->size;
+ err = bind_rdev_to_array(rdev, mddev);
+ if (err) {
+ export_rdev(rdev);
+ return err;
+ }
}
return 0;
@@ -2984,15 +2996,6 @@ static int hot_add_disk(mddev_t * mddev,
size = calc_dev_size(rdev, mddev->chunk_size);
rdev->size = size;
- if (size < mddev->size) {
- printk(KERN_WARNING
- "%s: disk size %llu blocks < array size %llu\n",
- mdname(mddev), (unsigned long long)size,
- (unsigned long long)mddev->size);
- err = -ENOSPC;
- goto abort_export;
- }
-
if (test_bit(Faulty, &rdev->flags)) {
printk(KERN_WARNING
"md: can not hot-add faulty %s disk to %s!\n",
@@ -3002,7 +3005,9 @@ static int hot_add_disk(mddev_t * mddev,
}
clear_bit(In_sync, &rdev->flags);
rdev->desc_nr = -1;
- bind_rdev_to_array(rdev, mddev);
+ err = bind_rdev_to_array(rdev, mddev);
+ if (err)
+ goto abort_export;
/*
* The rest should better be atomic, we can have disk failures
next prev parent reply other threads:[~2005-12-12 3:15 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-12-12 3:10 [PATCH md 000 of 20] Introduction NeilBrown
2005-12-12 3:10 ` [PATCH md 001 of 20] Fix a use-after-free bug in raid1 NeilBrown
2005-12-12 3:10 ` [PATCH md 002 of 20] Use correct size of raid5 stripe cache when measuring how full it is NeilBrown
2005-12-12 3:10 ` [PATCH md 003 of 20] Define and use safe_put_page for md NeilBrown
2005-12-12 3:13 ` [PATCH md 004 of 20] Helper function to match commands written to sysfs files NeilBrown
2005-12-12 3:14 ` [PATCH md 005 of 20] Fix typo in comment NeilBrown
2005-12-12 3:14 ` [PATCH md 006 of 20] Make a couple of names in md.c static NeilBrown
2005-12-12 3:14 ` [PATCH md 007 of 20] Make sure bitmap updates are visible through filesystem NeilBrown
2005-12-12 3:14 ` [PATCH md 008 of 20] Fix rdev->pending counts in raid1 NeilBrown
2005-12-12 3:14 ` [PATCH md 009 of 20] Allow chunk_size to be settable through sysfs NeilBrown
2005-12-12 3:15 ` [PATCH md 010 of 20] Allow md array component size to be accessed and set via sysfs NeilBrown
2005-12-12 3:15 ` [PATCH md 011 of 20] Expose md metadata format in sysfs NeilBrown
2005-12-12 3:15 ` [PATCH md 012 of 20] Allow array level to be set textually via sysfs NeilBrown
2005-12-12 3:15 ` [PATCH md 013 of 20] Count corrected read errors per drive NeilBrown
2005-12-12 10:07 ` Andrew Morton
2005-12-12 3:15 ` [PATCH md 014 of 20] Allow md/raid_disks to be settable NeilBrown
2005-12-12 3:15 ` NeilBrown [this message]
2005-12-12 3:15 ` [PATCH md 016 of 20] Expose device slot information via sysfs NeilBrown
2005-12-12 3:15 ` [PATCH md 017 of 20] Export rdev->data_offset " NeilBrown
2005-12-12 3:15 ` [PATCH md 018 of 20] Allow available size of component devices to be set " NeilBrown
2005-12-12 3:15 ` [PATCH md 019 of 20] Support adding new devices to md arrays " NeilBrown
2005-12-12 3:15 ` [PATCH md 020 of 20] Allow sync-speed to be controlled per-device NeilBrown
2005-12-12 11:30 ` Jeff Breidenbach
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1051212031529.5152@suse.de \
--to=neilb@suse.de \
--cc=akpm@osdl.org \
--cc=linux-raid@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).