Skip to content

Commit 3084885

Browse files
achendertytso
authored andcommitted
ext4: add new function ext4_block_zero_page_range()
This patch modifies the existing ext4_block_truncate_page() function which was used by the truncate code path, and which zeroes out block unaligned data, by adding a new length parameter, and renames it to ext4_block_zero_page_rage(). This function can now be used to zero out the head of a block, the tail of a block, or the middle of a block. The ext4_block_truncate_page() function is now a wrapper to ext4_block_zero_page_range(). [ext4 punch hole patch series 2/5 v7] Signed-off-by: Allison Henderson <[email protected]> Signed-off-by: "Theodore Ts'o" <[email protected]> Reviewed-by: Mingming Cao <[email protected]>
1 parent 55f020d commit 3084885

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

fs/ext4/ext4.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,6 +1825,8 @@ extern int ext4_writepage_trans_blocks(struct inode *);
18251825
extern int ext4_chunk_trans_blocks(struct inode *, int nrblocks);
18261826
extern int ext4_block_truncate_page(handle_t *handle,
18271827
struct address_space *mapping, loff_t from);
1828+
extern int ext4_block_zero_page_range(handle_t *handle,
1829+
struct address_space *mapping, loff_t from, loff_t length);
18281830
extern int ext4_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf);
18291831
extern qsize_t *ext4_get_reserved_space(struct inode *inode);
18301832
extern void ext4_da_update_reserve_space(struct inode *inode,

fs/ext4/inode.c

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3913,10 +3913,31 @@ void ext4_set_aops(struct inode *inode)
39133913
*/
39143914
int ext4_block_truncate_page(handle_t *handle,
39153915
struct address_space *mapping, loff_t from)
3916+
{
3917+
unsigned offset = from & (PAGE_CACHE_SIZE-1);
3918+
unsigned length;
3919+
unsigned blocksize;
3920+
struct inode *inode = mapping->host;
3921+
3922+
blocksize = inode->i_sb->s_blocksize;
3923+
length = blocksize - (offset & (blocksize - 1));
3924+
3925+
return ext4_block_zero_page_range(handle, mapping, from, length);
3926+
}
3927+
3928+
/*
3929+
* ext4_block_zero_page_range() zeros out a mapping of length 'length'
3930+
* starting from file offset 'from'. The range to be zero'd must
3931+
* be contained with in one block. If the specified range exceeds
3932+
* the end of the block it will be shortened to end of the block
3933+
* that cooresponds to 'from'
3934+
*/
3935+
int ext4_block_zero_page_range(handle_t *handle,
3936+
struct address_space *mapping, loff_t from, loff_t length)
39163937
{
39173938
ext4_fsblk_t index = from >> PAGE_CACHE_SHIFT;
39183939
unsigned offset = from & (PAGE_CACHE_SIZE-1);
3919-
unsigned blocksize, length, pos;
3940+
unsigned blocksize, max, pos;
39203941
ext4_lblk_t iblock;
39213942
struct inode *inode = mapping->host;
39223943
struct buffer_head *bh;
@@ -3929,7 +3950,15 @@ int ext4_block_truncate_page(handle_t *handle,
39293950
return -EINVAL;
39303951

39313952
blocksize = inode->i_sb->s_blocksize;
3932-
length = blocksize - (offset & (blocksize - 1));
3953+
max = blocksize - (offset & (blocksize - 1));
3954+
3955+
/*
3956+
* correct length if it does not fall between
3957+
* 'from' and the end of the block
3958+
*/
3959+
if (length > max || length < 0)
3960+
length = max;
3961+
39333962
iblock = index << (PAGE_CACHE_SHIFT - inode->i_sb->s_blocksize_bits);
39343963

39353964
if (!page_has_buffers(page))

0 commit comments

Comments
 (0)