Skip to content

Commit 189e868

Browse files
achendertytso
authored andcommitted
ext4: fix fsx truncate failure
While running extended fsx tests to verify the first two patches, a similar bug was also found in the truncate operation. This bug happens because the truncate routine only zeros the unblock aligned portion of the last page. This means that the block aligned portions of the page appearing after i_size are left unzeroed, and the buffer heads still mapped. This bug is corrected by using ext4_discard_partial_page_buffers in the truncate routine to zero the partial page and unmap the buffer headers. Signed-off-by: Allison Henderson <achender@linux.vnet.ibm.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
1 parent decbd91 commit 189e868

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

‎fs/ext4/extents.c‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3653,6 +3653,7 @@ void ext4_ext_truncate(struct inode *inode)
36533653
struct super_block *sb = inode->i_sb;
36543654
ext4_lblk_t last_block;
36553655
handle_t *handle;
3656+
loff_t page_len;
36563657
int err = 0;
36573658

36583659
/*
@@ -3669,8 +3670,16 @@ void ext4_ext_truncate(struct inode *inode)
36693670
if (IS_ERR(handle))
36703671
return;
36713672

3672-
if (inode->i_size & (sb->s_blocksize - 1))
3673-
ext4_block_truncate_page(handle, mapping, inode->i_size);
3673+
if (inode->i_size % PAGE_CACHE_SIZE != 0) {
3674+
page_len = PAGE_CACHE_SIZE -
3675+
(inode->i_size & (PAGE_CACHE_SIZE - 1));
3676+
3677+
err = ext4_discard_partial_page_buffers(handle,
3678+
mapping, inode->i_size, page_len, 0);
3679+
3680+
if (err)
3681+
goto out_stop;
3682+
}
36743683

36753684
if (ext4_orphan_add(handle, inode))
36763685
goto out_stop;

‎fs/ext4/indirect.c‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,7 +1343,9 @@ void ext4_ind_truncate(struct inode *inode)
13431343
__le32 nr = 0;
13441344
int n = 0;
13451345
ext4_lblk_t last_block, max_block;
1346+
loff_t page_len;
13461347
unsigned blocksize = inode->i_sb->s_blocksize;
1348+
int err;
13471349

13481350
handle = start_transaction(inode);
13491351
if (IS_ERR(handle))
@@ -1354,9 +1356,16 @@ void ext4_ind_truncate(struct inode *inode)
13541356
max_block = (EXT4_SB(inode->i_sb)->s_bitmap_maxbytes + blocksize-1)
13551357
>> EXT4_BLOCK_SIZE_BITS(inode->i_sb);
13561358

1357-
if (inode->i_size & (blocksize - 1))
1358-
if (ext4_block_truncate_page(handle, mapping, inode->i_size))
1359+
if (inode->i_size % PAGE_CACHE_SIZE != 0) {
1360+
page_len = PAGE_CACHE_SIZE -
1361+
(inode->i_size & (PAGE_CACHE_SIZE - 1));
1362+
1363+
err = ext4_discard_partial_page_buffers(handle,
1364+
mapping, inode->i_size, page_len, 0);
1365+
1366+
if (err)
13591367
goto out_stop;
1368+
}
13601369

13611370
if (last_block != max_block) {
13621371
n = ext4_block_to_path(inode, last_block, offsets, NULL);

0 commit comments

Comments
 (0)