Ext4 Punch Hole Support: Enable Punch Hole
PATCH v6 5/5 Ext4 Punch Hole Support: Enable Punch Hole
This patch adds new routines: "ext4_punch_hole" "ext4_ext_punch_hole" and "ext4_ext_check_cache"
fallocate has been modified to call ext4_punch_hole when the punch hole flag is passed. At the moment, we only support punching holes in extents, so this routine is pretty much a wrapper for the ext4_ext_punch_hole routine.
The ext4_ext_punch_hole routine first completes all outstanding writes with the associated pages, and then releases them. The unblock aligned data is zeroed, and all blocks in between are punched out.
v5->v6:
The ext4_ext_check_cache routine is very similar to ext4_ext_in_cache but it accepts a ext4_ext_cache parameter instead of a ext4_extent parameter. This routine is used by ext4_ext_punch_hole to check and see if a block in a hole that has been cached. The ext4_ext_cache parameter is necessary because the members ext4_extent structure are not large enough to hold a 32 bit value. The existing ext4_ext_in_cache routine has become a wrapper to this new function.
---
:100644 100644 45136d8... 04c3dc2... M fs/ext4/ext4.h
:100644 100644 7f0fcc1... 4a7b9e0... M fs/ext4/extents.c
:100644 100644 dc45631... d4305aa... M fs/ext4/inode.c
fs/ext4/ext4.h | 3 + fs/ext4/extents.c | 240 ++++++++++++++++++++++++++++++++++++++++++++++++++--- fs/ext4/inode.c | 25 ++++++ 3 files changed, 257 insertions(+), 11 deletions(-)
fs/ext4/ext4.h +3 -0
@@ -1734,6 +1734,7 @@ extern int ext4_change_inode_journal_flag(struct inode *, int);extern int ext4_get_inode_loc (struct inode *,struct ext4_iloc *);extern int ext4_can_truncate (struct inode *inode);extern void ext4_truncate (struct inode *); +extern int ext4_punch_hole (struct file *file,loff_t offset,loff_t length);extern int ext4_truncate_restart_trans (handle_t *,struct inode *,int nblocks);extern void ext4_set_inode_flags (struct inode *);extern void ext4_get_inode_flags (struct ext4_inode_info *);
@@ -2071,6 +2072,8 @@ extern int ext4_ext_index_trans_blocks(struct inode *inode, int nrblocks,extern int ext4_ext_map_blocks (handle_t *handle,struct inode *inode,struct ext4_map_blocks *map,int flags);extern void ext4_ext_truncate (struct inode *); +extern int ext4_ext_punch_hole (struct file *file,loff_t offset, +loff_t length);extern void ext4_ext_init (struct super_block *);extern void ext4_ext_release (struct super_block *); extern long ext4_fallocate(struct file *file, int mode, loff_t offset,
fs/ext4/extents.c +229 -11
275 lines not on this page · raw message
fs/ext4/inode.c +25 -0
@@ -4420,6 +4420,31 @@ int ext4_can_truncate(struct inode *inode) }/* +* ext4_punch_hole: punches a hole in a file by releaseing the blocks +* associated with the given offset and length +* +* @inode: File inode +* @offset: The offset where the hole will begin +* @len: The length of the hole +* +* Returns: 0 on sucess or negative on failure +*/ + +int ext4_punch_hole (struct file *file,loff_t offset,loff_t length) +{ +struct inode *inode = file->f_path.dentry->d_inode; +if (!S_ISREG (inode->i_mode)) +return -ENOTSUPP ; + +if (!ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS )) { +/* TODO: Add support for non extent hole punching */ +return -ENOTSUPP ; + } + +return ext4_ext_punch_hole (file, offset, length); +} + +/* * ext4_truncate() * * We block out ext4_get_block() block instantiations across the entire
Signature · 1 line
1.7.1