ext4: Add support FALLOC_FL_COLLAPSE_RANGE for fallocate
Subsystems (3)
PATCH v5 3/10 ext4: Add support FALLOC_FL_COLLAPSE_RANGE for fallocate
From: Namjae Jeon <[email protected]>
This patch implements fallocate's FALLOC_FL_COLLAPSE_RANGE for Ext4.
The semantics of this flag are following:
1) It collapses the range lying between offset and length by removing any data blocks which are present in this range and than updates all the logical offsets of extents beyond "offset + len" to nullify the hole created by removing blocks. In short, it does not leave a hole.
2) It should be used exclusively. No other fallocate flag in combination.
3) Offset and length supplied to fallocate should be fs block size aligned in case of xfs and ext4.
4) Collaspe range does not work beyond i_size.
---
Changelog
v5: Fix review comments from Lukas Czerner.
- Added checks for immutable files and swap files.
- Move inode flag checks under imutex.
- Remove an obsolete checking.
- truncate_pagecache_range can work on page size aligned byte offsets so alignment is not required.
v4:
- move block size aligned check from VFS layer to FS specific layer.
v3:
- fix checkpatch.pl warning
v2:
- Added check to make sure before shifting that the hole is big enough to contian the shift.
- Added code to make merging of extent where possible.
- Change semantics of collapse range and contain it within EOF.
fs/ext4/ext4.h | 3 + fs/ext4/extents.c | 304 +++++++++++++++++++++++++++++++++++++++++++- fs/ext4/move_extent.c | 2 +- include/trace/events/ext4.h | 25 ++++ 4 files changed, 332 insertions(+), 2 deletions(-)
fs/ext4/ext4.h +3 -0
@@ -2755,6 +2755,7 @@ extern int ext4_find_delalloc_cluster(struct inode *inode, ext4_lblk_t lblk);extern int ext4_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo,__u64 start,__u64 len);extern int ext4_ext_precache (struct inode *inode); +extern int ext4_collapse_range (struct inode *inode,loff_t offset,loff_t len);/* move_extent.c */ extern void ext4_double_down_write_data_sem(struct inode *first,
@@ -2764,6 +2765,8 @@ extern void ext4_double_up_write_data_sem(struct inode *orig_inode,extern int ext4_move_extents (struct file *o_filp,struct file *d_filp,__u64 start_orig,__u64 start_donor,__u64 len,__u64 *moved_len); +extern int mext_next_extent (struct inode *inode,struct ext4_ext_path *path, +struct ext4_extent **extent);/* page-io.c */ extern int __init ext4_init_pageio (void );
fs/ext4/extents.c +303 -1
318 lines not on this page · raw message
fs/ext4/move_extent.c +1 -1
@@ -76,7 +76,7 @@ copy_extent_status(struct ext4_extent *src, struct ext4_extent *dest)* ext4_ext_path structure refers to the last extent, or a negative error * value on failure. */ -static int +int mext_next_extent (struct inode *inode,struct ext4_ext_path *path,struct ext4_extent **extent) {
include/trace/events/ext4.h +25 -0
@@ -2410,6 +2410,31 @@ TRACE_EVENT(ext4_es_shrink_exit, __entry->shrunk_nr, __entry->cache_cnt) ); +TRACE_EVENT (ext4_collapse_range, + TP_PROTO(struct inode *inode, loff_t offset, loff_t len), + +TP_ARGS (inode, offset, len), + +TP_STRUCT__entry ( + __field(dev_t, dev) + __field(ino_t, ino) + __field(loff_t, offset) +__field (loff_t, len) + ), + +TP_fast_assign ( + __entry->dev = inode->i_sb->s_dev; + __entry->ino = inode->i_ino; + __entry->offset = offset; + __entry->len = len; + ), + +TP_printk ("dev %d,%d ino %lu offset %lld len %lld" , +MAJOR (__entry->dev),MINOR (__entry->dev), + (unsigned long ) __entry->ino, + __entry->offset, __entry->len) +); +#endif /* _TRACE_EXT4_H */ /* This part must be outside protection */
Signature · 7 lines
1.7.11-rc0 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Hi Namjae,
see below:
Quoted 1 line · Namjae Jeon
This patch implements fallocate's
FALLOC_FL_COLLAPSE_RANGEfor Ext4.
...<snip>...
Quoted 4 lines
fs/ext4/extents.c +4
-0+/* +* Don't start shifting extents until we make sure the hole is big +* enough to accomodate the shift. +*/
fs/ext4/extents.c int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, · line 5032
Quoted 10 lines
fs/ext4/extents.c +10
-0+ path =ext4_ext_find_extent (inode, start -1 ,NULL ,0 ); + depth = path->p_depth; + extent = path[depth].p_ext; + ex_start = extent->ee_block; + ex_end = extent->ee_block +ext4_ext_get_actual_len (extent); +ext4_ext_drop_refs (path); +kfree (path); + +if ((start == ex_start && shift > ex_start) || + (shift > start - ex_end)) {
This line causes a compile error. So the fix would be like that:
- (shift > start - ex_end)) {
+ (shift > start - ex_end))
fs/ext4/extents.c int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, · line 5035
Quoted 3 lines
fs/ext4/extents.c +3
-0+return -EINVAL ; + +/* Its safe to start updating extents */
...<snip>...
Apart from that, the whole patchset seems to work without error, both on xfs and on ext4.
Of course I had to remove Lukas' patches before testing collapse-range. So it would be excellent if two patch series could get somehow merged.
Regards,
Dongsu
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
2014-02-20 6:58 GMT+09:00, Dongsu Park <[email protected]>:
Quoted 2 lines
Hi Namjae,
see below:
Hi Dongsu.
Quoted 20 lines · Namjae Jeon
Quoted 1 line
This patch implements fallocate's
FALLOC_FL_COLLAPSE_RANGEfor Ext4....<snip>...
Quoted 4 lines
fs/ext4/extents.c +4
-0+/* +* Don't start shifting extents until we make sure the hole is big +* enough to accomodate the shift. +*/ fs/ext4/extents.c int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, · line 5032
Quoted 10 lines
fs/ext4/extents.c +10
-0+ path =ext4_ext_find_extent (inode, start -1 ,NULL ,0 ); + depth = path->p_depth; + extent = path[depth].p_ext; + ex_start = extent->ee_block; + ex_end = extent->ee_block +ext4_ext_get_actual_len (extent); +ext4_ext_drop_refs (path); +kfree (path); + +if ((start == ex_start && shift > ex_start) || + (shift > start - ex_end)) {This line causes a compile error. So the fix would be like that:
Oops.. I made a stupid mistake when creating the patch at dawn.. Thanks for your pointing.
Quoted 7 lines
(quoted diff) +1
-1- (shift > start - ex_end)) { + (shift > start - ex_end))fs/ext4/extents.c int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, · line 5035
Quoted 4 lines
fs/ext4/extents.c +3
-0+return -EINVAL ; + +/* Its safe to start updating extents */
Yes, Right.
Quoted 8 lines
...<snip>...
Apart from that, the whole patchset seems to work without error, both on xfs and on ext4.
Of course I had to remove Lukas' patches before testing collapse-range. So it would be excellent if two patch series could get somehow merged.Tested-by Dongsu Park <[email protected]>
Thank you so much for your testing!
Quoted 4 lines
Regards,
Dongsu
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs