Ext4 Punch Hole Support: Enable Punch Hole
PATCH v4 6/6 Ext4 Punch Hole Support: Enable Punch Hole
This patch adds new routines: "ext4_punch_hole" "ext4_ext_punch_hole"
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.
---
:100644 100644 6b64a79... 007f254... M fs/ext4/ext4.h
:100644 100644 d97bc87... b05d79c... M fs/ext4/extents.c
:100644 100644 09fc53b... 9df5056... M fs/ext4/inode.c
fs/ext4/ext4.h | 3 + fs/ext4/extents.c | 175 +++++++++++++++++++++++++++++++++++++++++++++++++++- fs/ext4/inode.c | 25 ++++++++ 3 files changed, 199 insertions(+), 4 deletions(-)
fs/ext4/ext4.h +3 -0
@@ -1744,6 +1744,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 *);
@@ -2081,6 +2082,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 +171 -4
190 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