diff options
author | NeilBrown <neilb@suse.de> | 2011-02-24 01:25:47 -0500 |
---|---|---|
committer | NeilBrown <neilb@suse.de> | 2011-02-24 01:25:47 -0500 |
commit | 93b270f76e7ef3b81001576860c2701931cdc78b (patch) | |
tree | abaca0e4d3e86721815498fafd06295dd9cfd002 /fs/block_dev.c | |
parent | da9cf5050a2e3dbc3cf26a8d908482eb4485ed49 (diff) |
Fix over-zealous flush_disk when changing device size.
There are two cases when we call flush_disk.
In one, the device has disappeared (check_disk_change) so any
data will hold becomes irrelevant.
In the oter, the device has changed size (check_disk_size_change)
so data we hold may be irrelevant.
In both cases it makes sense to discard any 'clean' buffers,
so they will be read back from the device if needed.
In the former case it makes sense to discard 'dirty' buffers
as there will never be anywhere safe to write the data. In the
second case it *does*not* make sense to discard dirty buffers
as that will lead to file system corruption when you simply enlarge
the containing devices.
flush_disk calls __invalidate_devices.
__invalidate_device calls both invalidate_inodes and invalidate_bdev.
invalidate_inodes *does* discard I_DIRTY inodes and this does lead
to fs corruption.
invalidate_bev *does*not* discard dirty pages, but I don't really care
about that at present.
So this patch adds a flag to __invalidate_device (calling it
__invalidate_device2) to indicate whether dirty buffers should be
killed, and this is passed to invalidate_inodes which can choose to
skip dirty inodes.
flusk_disk then passes true from check_disk_change and false from
check_disk_size_change.
dm avoids tripping over this problem by calling i_size_write directly
rathher than using check_disk_size_change.
md does use check_disk_size_change and so is affected.
This regression was introduced by commit 608aeef17a which causes
check_disk_size_change to call flush_disk, so it is suitable for any
kernel since 2.6.27.
Cc: stable@kernel.org
Acked-by: Jeff Moyer <jmoyer@redhat.com>
Cc: Andrew Patterson <andrew.patterson@hp.com>
Cc: Jens Axboe <axboe@kernel.dk>
Signed-off-by: NeilBrown <neilb@suse.de>
Diffstat (limited to 'fs/block_dev.c')
-rw-r--r-- | fs/block_dev.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/fs/block_dev.c b/fs/block_dev.c index 333a7bb4cb9c..5e23152d04ad 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c | |||
@@ -927,9 +927,9 @@ EXPORT_SYMBOL_GPL(bd_unlink_disk_holder); | |||
927 | * when a disk has been changed -- either by a media change or online | 927 | * when a disk has been changed -- either by a media change or online |
928 | * resize. | 928 | * resize. |
929 | */ | 929 | */ |
930 | static void flush_disk(struct block_device *bdev) | 930 | static void flush_disk(struct block_device *bdev, bool kill_dirty) |
931 | { | 931 | { |
932 | if (__invalidate_device(bdev)) { | 932 | if (__invalidate_device(bdev, kill_dirty)) { |
933 | char name[BDEVNAME_SIZE] = ""; | 933 | char name[BDEVNAME_SIZE] = ""; |
934 | 934 | ||
935 | if (bdev->bd_disk) | 935 | if (bdev->bd_disk) |
@@ -966,7 +966,7 @@ void check_disk_size_change(struct gendisk *disk, struct block_device *bdev) | |||
966 | "%s: detected capacity change from %lld to %lld\n", | 966 | "%s: detected capacity change from %lld to %lld\n", |
967 | name, bdev_size, disk_size); | 967 | name, bdev_size, disk_size); |
968 | i_size_write(bdev->bd_inode, disk_size); | 968 | i_size_write(bdev->bd_inode, disk_size); |
969 | flush_disk(bdev); | 969 | flush_disk(bdev, false); |
970 | } | 970 | } |
971 | } | 971 | } |
972 | EXPORT_SYMBOL(check_disk_size_change); | 972 | EXPORT_SYMBOL(check_disk_size_change); |
@@ -1019,7 +1019,7 @@ int check_disk_change(struct block_device *bdev) | |||
1019 | if (!(events & DISK_EVENT_MEDIA_CHANGE)) | 1019 | if (!(events & DISK_EVENT_MEDIA_CHANGE)) |
1020 | return 0; | 1020 | return 0; |
1021 | 1021 | ||
1022 | flush_disk(bdev); | 1022 | flush_disk(bdev, true); |
1023 | if (bdops->revalidate_disk) | 1023 | if (bdops->revalidate_disk) |
1024 | bdops->revalidate_disk(bdev->bd_disk); | 1024 | bdops->revalidate_disk(bdev->bd_disk); |
1025 | return 1; | 1025 | return 1; |
@@ -1601,7 +1601,7 @@ fail: | |||
1601 | } | 1601 | } |
1602 | EXPORT_SYMBOL(lookup_bdev); | 1602 | EXPORT_SYMBOL(lookup_bdev); |
1603 | 1603 | ||
1604 | int __invalidate_device(struct block_device *bdev) | 1604 | int __invalidate_device(struct block_device *bdev, bool kill_dirty) |
1605 | { | 1605 | { |
1606 | struct super_block *sb = get_super(bdev); | 1606 | struct super_block *sb = get_super(bdev); |
1607 | int res = 0; | 1607 | int res = 0; |
@@ -1614,7 +1614,7 @@ int __invalidate_device(struct block_device *bdev) | |||
1614 | * hold). | 1614 | * hold). |
1615 | */ | 1615 | */ |
1616 | shrink_dcache_sb(sb); | 1616 | shrink_dcache_sb(sb); |
1617 | res = invalidate_inodes(sb); | 1617 | res = invalidate_inodes(sb, kill_dirty); |
1618 | drop_super(sb); | 1618 | drop_super(sb); |
1619 | } | 1619 | } |
1620 | invalidate_bdev(bdev); | 1620 | invalidate_bdev(bdev); |