ocfs2: fix data corruption after conversion from inline format
Commit6dbf7bb555
("fs: Don't invalidate page buffers in block_write_full_page()") uncovered a latent bug in ocfs2 conversion from inline inode format to a normal inode format. The code in ocfs2_convert_inline_data_to_extents() attempts to zero out the whole cluster allocated for file data by grabbing, zeroing, and dirtying all pages covering this cluster. However these pages are beyond i_size, thus writeback code generally ignores these dirty pages and no blocks were ever actually zeroed on the disk. This oversight was fixed by commit693c241a5f
("ocfs2: No need to zero pages past i_size.") for standard ocfs2 write path, inline conversion path was apparently forgotten; the commit log also has a reasoning why the zeroing actually is not needed. After commit6dbf7bb555
, things became worse as writeback code stopped invalidating buffers on pages beyond i_size and thus these pages end up with clean PageDirty bit but with buffers attached to these pages being still dirty. So when a file is converted from inline format, then writeback triggers, and then the file is grown so that these pages become valid, the invalid dirtiness state is preserved, mark_buffer_dirty() does nothing on these pages (buffers are already dirty) but page is never written back because it is clean. So data written to these pages is lost once pages are reclaimed. Simple reproducer for the problem is: xfs_io -f -c "pwrite 0 2000" -c "pwrite 2000 2000" -c "fsync" \ -c "pwrite 4000 2000" ocfs2_file After unmounting and mounting the fs again, you can observe that end of 'ocfs2_file' has lost its contents. Fix the problem by not doing the pointless zeroing during conversion from inline format similarly as in the standard write path. [akpm@linux-foundation.org: fix whitespace, per Joseph] Link: https://lkml.kernel.org/r/20210930095405.21433-1-jack@suse.cz Fixes:6dbf7bb555
("fs: Don't invalidate page buffers in block_write_full_page()") Signed-off-by: Jan Kara <jack@suse.cz> Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com> Tested-by: Joseph Qi <joseph.qi@linux.alibaba.com> Acked-by: Gang He <ghe@suse.com> Cc: Mark Fasheh <mark@fasheh.com> Cc: Joel Becker <jlbec@evilplan.org> Cc: Junxiao Bi <junxiao.bi@oracle.com> Cc: Changwei Ge <gechangwei@live.cn> Cc: Jun Piao <piaojun@huawei.com> Cc: "Markov, Andrey" <Markov.Andrey@Dell.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
a6a0251c6f
commit
5314454ea3
|
@ -7045,7 +7045,7 @@ void ocfs2_set_inode_data_inline(struct inode *inode, struct ocfs2_dinode *di)
|
||||||
int ocfs2_convert_inline_data_to_extents(struct inode *inode,
|
int ocfs2_convert_inline_data_to_extents(struct inode *inode,
|
||||||
struct buffer_head *di_bh)
|
struct buffer_head *di_bh)
|
||||||
{
|
{
|
||||||
int ret, i, has_data, num_pages = 0;
|
int ret, has_data, num_pages = 0;
|
||||||
int need_free = 0;
|
int need_free = 0;
|
||||||
u32 bit_off, num;
|
u32 bit_off, num;
|
||||||
handle_t *handle;
|
handle_t *handle;
|
||||||
|
@ -7054,26 +7054,17 @@ int ocfs2_convert_inline_data_to_extents(struct inode *inode,
|
||||||
struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
|
struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
|
||||||
struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data;
|
struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data;
|
||||||
struct ocfs2_alloc_context *data_ac = NULL;
|
struct ocfs2_alloc_context *data_ac = NULL;
|
||||||
struct page **pages = NULL;
|
struct page *page = NULL;
|
||||||
loff_t end = osb->s_clustersize;
|
|
||||||
struct ocfs2_extent_tree et;
|
struct ocfs2_extent_tree et;
|
||||||
int did_quota = 0;
|
int did_quota = 0;
|
||||||
|
|
||||||
has_data = i_size_read(inode) ? 1 : 0;
|
has_data = i_size_read(inode) ? 1 : 0;
|
||||||
|
|
||||||
if (has_data) {
|
if (has_data) {
|
||||||
pages = kcalloc(ocfs2_pages_per_cluster(osb->sb),
|
|
||||||
sizeof(struct page *), GFP_NOFS);
|
|
||||||
if (pages == NULL) {
|
|
||||||
ret = -ENOMEM;
|
|
||||||
mlog_errno(ret);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = ocfs2_reserve_clusters(osb, 1, &data_ac);
|
ret = ocfs2_reserve_clusters(osb, 1, &data_ac);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
mlog_errno(ret);
|
mlog_errno(ret);
|
||||||
goto free_pages;
|
goto out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7093,7 +7084,8 @@ int ocfs2_convert_inline_data_to_extents(struct inode *inode,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (has_data) {
|
if (has_data) {
|
||||||
unsigned int page_end;
|
unsigned int page_end = min_t(unsigned, PAGE_SIZE,
|
||||||
|
osb->s_clustersize);
|
||||||
u64 phys;
|
u64 phys;
|
||||||
|
|
||||||
ret = dquot_alloc_space_nodirty(inode,
|
ret = dquot_alloc_space_nodirty(inode,
|
||||||
|
@ -7117,15 +7109,8 @@ int ocfs2_convert_inline_data_to_extents(struct inode *inode,
|
||||||
*/
|
*/
|
||||||
block = phys = ocfs2_clusters_to_blocks(inode->i_sb, bit_off);
|
block = phys = ocfs2_clusters_to_blocks(inode->i_sb, bit_off);
|
||||||
|
|
||||||
/*
|
ret = ocfs2_grab_eof_pages(inode, 0, page_end, &page,
|
||||||
* Non sparse file systems zero on extend, so no need
|
&num_pages);
|
||||||
* to do that now.
|
|
||||||
*/
|
|
||||||
if (!ocfs2_sparse_alloc(osb) &&
|
|
||||||
PAGE_SIZE < osb->s_clustersize)
|
|
||||||
end = PAGE_SIZE;
|
|
||||||
|
|
||||||
ret = ocfs2_grab_eof_pages(inode, 0, end, pages, &num_pages);
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
mlog_errno(ret);
|
mlog_errno(ret);
|
||||||
need_free = 1;
|
need_free = 1;
|
||||||
|
@ -7136,20 +7121,15 @@ int ocfs2_convert_inline_data_to_extents(struct inode *inode,
|
||||||
* This should populate the 1st page for us and mark
|
* This should populate the 1st page for us and mark
|
||||||
* it up to date.
|
* it up to date.
|
||||||
*/
|
*/
|
||||||
ret = ocfs2_read_inline_data(inode, pages[0], di_bh);
|
ret = ocfs2_read_inline_data(inode, page, di_bh);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
mlog_errno(ret);
|
mlog_errno(ret);
|
||||||
need_free = 1;
|
need_free = 1;
|
||||||
goto out_unlock;
|
goto out_unlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
page_end = PAGE_SIZE;
|
ocfs2_map_and_dirty_page(inode, handle, 0, page_end, page, 0,
|
||||||
if (PAGE_SIZE > osb->s_clustersize)
|
&phys);
|
||||||
page_end = osb->s_clustersize;
|
|
||||||
|
|
||||||
for (i = 0; i < num_pages; i++)
|
|
||||||
ocfs2_map_and_dirty_page(inode, handle, 0, page_end,
|
|
||||||
pages[i], i > 0, &phys);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
spin_lock(&oi->ip_lock);
|
spin_lock(&oi->ip_lock);
|
||||||
|
@ -7180,8 +7160,8 @@ int ocfs2_convert_inline_data_to_extents(struct inode *inode,
|
||||||
}
|
}
|
||||||
|
|
||||||
out_unlock:
|
out_unlock:
|
||||||
if (pages)
|
if (page)
|
||||||
ocfs2_unlock_and_free_pages(pages, num_pages);
|
ocfs2_unlock_and_free_pages(&page, num_pages);
|
||||||
|
|
||||||
out_commit:
|
out_commit:
|
||||||
if (ret < 0 && did_quota)
|
if (ret < 0 && did_quota)
|
||||||
|
@ -7205,8 +7185,6 @@ int ocfs2_convert_inline_data_to_extents(struct inode *inode,
|
||||||
out:
|
out:
|
||||||
if (data_ac)
|
if (data_ac)
|
||||||
ocfs2_free_alloc_context(data_ac);
|
ocfs2_free_alloc_context(data_ac);
|
||||||
free_pages:
|
|
||||||
kfree(pages);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue