ext4: fix xfstests 75, 112, 127 punch hole failure
PATCH v2 1/1 ext4: fix xfstests 75, 112, 127 punch hole failure
Hi All,
This is an earlier version of this patch that was reviewed internally, before it came to the ext4 list as v3. V2 pretty much expands ext4_block_zero_page_range, where as v3 makes a separate but simple function. Some of the feed back for v3 mentioned having one complex function, so I am resending v2 so we can decide which version people like better before we go and do a v4.
This patch corrects a punch hole bug found by xfstests when the block size is set to 1k. Test 127 runs longer before it fails, but that appears to be a separate bug.
This bug happens because the punch hole code only zeros out non block aligned blocks, and then releases the pages for data that is page aligned. This means that if the blocks are smaller than a page, then the blocks contained in the non page aligned regions (but still block aligned) are left unzeroed and mapped.
This patch expands the ext4_block_zero_page_range routine to zero multiple blocks in a page instead of just one. A new flag EXT4_BLOCK_ZERO_DISCARD_BUFFER has also been added that discards buffers for blocks that would have been completely zeroed.
---
v1 -> v2 Added EXT4_BLOCK_ZERO_DISCARD_BUFFER flag
:100644 100644 040b3fa... fbde9e17d. M fs/ext4/ext4.h
:100644 100644 4d73e11... 4b5f82e... M fs/ext4/extents.c
:100644 100644 8fdc298... 2d3268f... M fs/ext4/inode.c
fs/ext4/ext4.h | 8 +++- fs/ext4/extents.c | 27 ++++++---- fs/ext4/inode.c | 145 +++++++++++++++++++++++++++++++++++----------------- 3 files changed, 119 insertions(+), 61 deletions(-)
fs/ext4/ext4.h +7 -1
@@ -492,6 +492,11 @@ struct ext4_new_group_data { };/* +* Flags used by ext4_block_zero_page_range +*/ +#define EXT4_BLOCK_ZERO_DISCARD_BUFFER 0x0001 + +/* * Flags used by ext4_map_blocks() */ /* Allocate any needed blocks and/or convert an unitialized
@@ -1835,7 +1840,8 @@ extern int ext4_chunk_trans_blocks(struct inode *, int nrblocks);extern int ext4_block_truncate_page (handle_t *handle,struct address_space *mapping,loff_t from);extern int ext4_block_zero_page_range (handle_t *handle, -struct address_space *mapping,loff_t from,loff_t length); +struct address_space *mapping,loff_t from,loff_t length, +int flags);extern int ext4_page_mkwrite (struct vm_area_struct *vma,struct vm_fault *vmf);extern qsize_t *ext4_get_reserved_space (struct inode *inode); extern void ext4_da_update_reserve_space(struct inode *inode,
fs/ext4/extents.c +15 -12
@@ -4157,7 +4157,7 @@ int ext4_ext_punch_hole(struct file *file, loff_t offset, loff_t length)struct address_space *mapping = inode->i_mapping;struct ext4_map_blocks map;handle_t *handle; -loff_t first_block_offset, last_block_offset, block_len; +loff_t first_block_offset, last_block_offset, page_len;loff_t first_page, last_page, first_page_offset, last_page_offset;int ret, credits, blocks_released, err =0 ;
@@ -4207,23 +4207,26 @@ int ext4_ext_punch_hole(struct file *file, loff_t offset, loff_t length)/* * Now we need to zero out the un block aligned data. -* If the file is smaller than a block, just +* If the file is smaller than a page, just * zero out the middle */ -if (first_block > last_block) -ext4_block_zero_page_range (handle, mapping, offset, length); +if (first_page > last_page) +ext4_block_zero_page_range (handle, mapping, offset, length, +EXT4_BLOCK_ZERO_DISCARD_BUFFER );else { -/* zero out the head of the hole before the first block */ - block_len = first_block_offset - offset; -if (block_len >0 ) +/* zero out the head of the hole before the first page */ + page_len = first_page_offset - offset; +if (page_len >0 )ext4_block_zero_page_range (handle, mapping, - offset, block_len); + offset, page_len, +EXT4_BLOCK_ZERO_DISCARD_BUFFER ); -/* zero out the tail of the hole after the last block */ - block_len = offset + length - last_block_offset; -if (block_len >0 ) { +/* zero out the tail of the hole after the last page */ + page_len = offset + length - last_page_offset; +if (page_len >0 ) {ext4_block_zero_page_range (handle, mapping, - last_block_offset, block_len); + last_page_offset, page_len, +EXT4_BLOCK_ZERO_DISCARD_BUFFER ); } }
fs/ext4/inode.c +97 -47
181 lines not on this page · raw message