f2fs: support partial truncation on compressed inode
PATCH 1/1 f2fs: support partial truncation on compressed inode
Supports to truncate compressed/normal cluster partially on compressed inode.
Signed-off-by Chao Yu <[email protected]>
--- fs/f2fs/compress.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++ fs/f2fs/f2fs.h | 2 ++ fs/f2fs/file.c | 19 +++++++++++++----- 3 files changed, 64 insertions(+), 5 deletions(-)
fs/f2fs/compress.c +48 -0
@@ -956,6 +956,54 @@ bool f2fs_compress_write_end(struct inode *inode, void *fsdata,return first_index; } +int f2fs_truncate_partial_cluster (struct inode *inode,u64 from,bool lock) +{ +void *fsdata =NULL ; +struct page *pagep; +int log_cluster_size =F2FS_I (inode)->i_log_cluster_size; +pgoff_t start_idx = from >> (PAGE_SHIFT + log_cluster_size); +int err; + + err =f2fs_is_compressed_cluster (inode, start_idx); +if (err <0 ) +return err; + +/* truncate normal cluster */ +if (!err) +return f2fs_do_truncate_blocks (inode, from, lock); + +/* truncate compressed cluster */ + err =f2fs_prepare_compress_overwrite (inode, &pagep, + start_idx, &fsdata); + +/* should not be a normal cluster */ +f2fs_bug_on (F2FS_I_SB (inode), err ==0 ); + +if (err <=0 ) +return err; + +if (err >0 ) { +struct page **rpages = fsdata; +int cluster_size =F2FS_I (inode)->i_cluster_size; +int i; + +for (i = cluster_size -1 ; i >=0 ; i--) { +loff_t start = rpages[i]->index <<PAGE_SHIFT ; + +if (from <= start) { +zero_user_segment (rpages[i],0 ,PAGE_SIZE ); + }else { +zero_user_segment (rpages[i], from - start, +PAGE_SIZE ); +break ; + } + } + +f2fs_compress_write_end (inode, fsdata, start_idx, true); + } +return 0 ; +} + static int f2fs_write_compressed_pages(struct compress_ctx *cc, int *submitted, struct writeback_control *wbc,
fs/f2fs/f2fs.h +2 -0
@@ -3076,6 +3076,7 @@ static inline void f2fs_clear_page_private(struct page *page)*/ int f2fs_sync_file (struct file *file,loff_t start,loff_t end,int datasync);void f2fs_truncate_data_blocks (struct dnode_of_data *dn); +int f2fs_do_truncate_blocks (struct inode *inode,u64 from,bool lock);int f2fs_truncate_blocks (struct inode *inode,u64 from,bool lock);int f2fs_truncate (struct inode *inode); int f2fs_getattr(const struct path *path, struct kstat *stat,
@@ -3796,6 +3797,7 @@ int f2fs_prepare_compress_overwrite(struct inode *inode, struct page **pagep, pgoff_t index, void **fsdata);bool f2fs_compress_write_end (struct inode *inode,void *fsdata,pgoff_t index,unsigned copied); +int f2fs_truncate_partial_cluster (struct inode *inode,u64 from,bool lock);void f2fs_compress_write_end_io (struct bio *bio,struct page *page);bool f2fs_is_compress_backend_ready (struct inode *inode);void f2fs_decompress_pages (struct bio *bio,struct page *page,bool verity);
fs/f2fs/file.c +14 -5
@@ -646,9 +646,6 @@ static int truncate_partial_data_page(struct inode *inode, u64 from,return 0 ; } -if (f2fs_compressed_file (inode)) -return 0 ; - page =f2fs_get_lock_data_page (inode, index, true);if (IS_ERR (page))return PTR_ERR (page) == -ENOENT ?0 :PTR_ERR (page);
@@ -664,7 +661,7 @@ static int truncate_partial_data_page(struct inode *inode, u64 from,return 0 ; } -static int do_truncate_blocks (struct inode *inode,u64 from,bool lock) +int f2fs_do_truncate_blocks (struct inode *inode,u64 from,bool lock) {struct f2fs_sb_info *sbi =F2FS_I_SB (inode);struct dnode_of_data dn;
@@ -732,7 +729,9 @@ static int do_truncate_blocks(struct inode *inode, u64 from, bool lock)int f2fs_truncate_blocks (struct inode *inode,u64 from,bool lock) {u64 free_from = from; +int err; +#ifdef CONFIG_F2FS_FS_COMPRESSION /* * for compressed file, only support cluster size * aligned truncation.
@@ -747,8 +746,18 @@ int f2fs_truncate_blocks(struct inode *inode, u64 from, bool lock) free_from++; free_from <<= cluster_shift; } +#endif + + err =f2fs_do_truncate_blocks (inode, free_from, lock); +if (err) +return err; + +#ifdef CONFIG_F2FS_FS_COMPRESSION +if (from != free_from) + err =f2fs_truncate_partial_cluster (inode, from, lock); +#endif -return do_truncate_blocks (inode, free_from, lock); +return err; }int f2fs_truncate (struct inode *inode)
Signature · 8 lines
2.18.0.rc1 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel