On Fri, Sep 04, 2020 at 10:58:51AM +0200, Jan Kara wrote:
If block_write_full_page() is called for a page that is beyond current inode size, it will truncate page buffers for the page and return 0. This logic has been added in 2.5.62 in commit 81eb69062588 ("fix ext3 BUG due to race with truncate") in history.git tree to fix a problem with ext3 in data=ordered mode. This particular problem doesn't exist anymore because ext3 is long gone and ext4 handles ordered data differently. Also normally buffers are invalidated by truncate code and there's no need to specially handle this in ->writepage() code.
This invalidation of page buffers in block_write_full_page() is causing issues to filesystems (e.g. ext4 or ocfs2) when block device is shrunk under filesystem's hands and metadata buffers get discarded while being tracked by the journalling layer. Although it is obviously "not supported" it can cause kernel crashes like:
Btw, while looking over the block device revalidation code I think all the magic we do on shrinking block devices actually is a bad idea - potentially very harmful, but without much real benefit. And it only is run on file systems directly created on the whole device, meaning it isn't even used at all with the typical setups that use partitions.
Anyway, this patch looks good:
Reviewed-by: Christoph Hellwig hch@lst.de