Ext4 Punch Hole Support: Enable Punch Hole
PATCH 5/5 Ext4 Punch Hole Support: Enable Punch Hole
This patch adds the new "ext4_punch_hole" "ext4_ext_punch_hole" routines.
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 completes all outstanding writes with the associated pages, and then releases them. The unblock aligned data is zeroed, and all blocks in between are identified as mapped or already punched out. Mapped blocks are then punched out using the "ext4_ext_release_blocks" routine
---
:100644 100644 c722e31... fe92010... M fs/ext4/ext4.h
:100644 100644 a46d3d7... 2d0544c... M fs/ext4/extents.c
:100644 100644 78c5bc4... b72b20f... M fs/ext4/inode.c
fs/ext4/ext4.h | 3 + fs/ext4/extents.c | 179 +++++++++++++++++++++++++++++++++++++++++++++++++++- fs/ext4/inode.c | 26 ++++++++ 3 files changed, 204 insertions(+), 4 deletions(-)
fs/ext4/ext4.h +3 -0
@@ -1729,6 +1729,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 *);
@@ -2066,6 +2067,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 +173 -3
191 lines not on this page · raw message
fs/ext4/inode.c +26 -0
@@ -4406,6 +4406,32 @@ 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 ; + } + +ext4_ext_punch_hole (file, offset, length); +return 0 ; +} + +/* * ext4_truncate() * * We block out ext4_get_block() block instantiations across the entire
Signature · 1 line
1.7.1