f2fs: ioctl for removing a range from F2FS
Subsystems (2)
PATCH v2 1/1 f2fs: ioctl for removing a range from F2FS
From: Qiuyang Sun <[email protected]>
This ioctl shrinks a given length (aligned to sections) from end of the main area. Any cursegs and valid blocks will be moved out before invalidating the range.
This feature can be used for adjusting partition sizes online.
Changlog v1 ==> v2:
Sahitya Tummala:
- Add this ioctl for f2fs_compat_ioctl() as well.
- Fix debugfs status to reflect the online resize changes.
- Fix potential race between online resize path and allocate new data block path or gc path.
Others:
- Rename some identifiers.
- Add some error handling branches.
- Clear sbi->next_victim_seg[BG_GC/FG_GC] in shrinking range.
--- fs/f2fs/debug.c | 7 ++++ fs/f2fs/f2fs.h | 9 +++++ fs/f2fs/file.c | 29 +++++++++++++++ fs/f2fs/gc.c | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++++- fs/f2fs/segment.c | 49 ++++++++++++++++++------ fs/f2fs/segment.h | 1 + fs/f2fs/super.c | 1 + 7 files changed, 192 insertions(+), 13 deletions(-)
fs/f2fs/debug.c +7 -0
@@ -27,8 +27,15 @@static void update_general_status (struct f2fs_sb_info *sbi) {struct f2fs_stat_info *si =F2FS_STAT (sbi); +struct f2fs_super_block *raw_super =F2FS_RAW_SUPER (sbi);int i; +/* these will be changed if online resize is done */ + si->main_area_segs =le32_to_cpu (raw_super->segment_count_main); + si->main_area_sections =le32_to_cpu (raw_super->section_count); + si->main_area_zones = si->main_area_sections / +le32_to_cpu (raw_super->secs_per_zone); +/* validation check of the segment numbers */ si->hit_largest =atomic64_read (&sbi->read_hit_largest); si->hit_cached =atomic64_read (&sbi->read_hit_cached);
fs/f2fs/f2fs.h +9 -0
@@ -423,6 +423,8 @@ static inline bool __has_cursum_space(struct f2fs_journal *journal,#define F2FS_IOC_SET_PIN_FILE _IOW(F2FS_IOCTL_MAGIC, 13, __u32)#define F2FS_IOC_GET_PIN_FILE _IOR(F2FS_IOCTL_MAGIC, 14, __u32)#define F2FS_IOC_PRECACHE_EXTENTS _IO(F2FS_IOCTL_MAGIC, 15) +#define F2FS_IOC_SHRINK_RESIZE _IOW(F2FS_IOCTL_MAGIC, 16, \ + struct f2fs_resize_param)#define F2FS_IOC_SET_ENCRYPTION_POLICY FS_IOC_SET_ENCRYPTION_POLICY#define F2FS_IOC_GET_ENCRYPTION_POLICY FS_IOC_GET_ENCRYPTION_POLICY
@@ -474,6 +476,10 @@ struct f2fs_flush_device {u32 segments;/* # of segments to flush */ }; +struct f2fs_resize_param { +u64 len;/* bytes to shrink */ +}; +/* for inline stuff */ #define DEF_INLINE_RESERVED_SIZE 1static inline int get_extra_isize (struct inode *inode);
@@ -1309,6 +1315,7 @@ struct f2fs_sb_info {unsigned int segs_per_sec;/* segments per section */ unsigned int secs_per_zone;/* sections per zone */ unsigned int total_sections;/* total section count */ +unsigned int current_total_sections;/* for shrink resize */ unsigned int total_node_count;/* total node block count */ unsigned int total_valid_node_count;/* valid node block count */ loff_t max_file_blocks;/* max block index of file */
@@ -3175,6 +3182,7 @@ void f2fs_clear_prefree_segments(struct f2fs_sb_info *sbi,int f2fs_disable_cp_again (struct f2fs_sb_info *sbi,block_t unusable);void f2fs_release_discard_addrs (struct f2fs_sb_info *sbi);int f2fs_npages_for_summary_flush (struct f2fs_sb_info *sbi,bool for_ra); +void allocate_segment_for_resize (struct f2fs_sb_info *sbi,int type);void f2fs_allocate_new_segments (struct f2fs_sb_info *sbi);int f2fs_trim_fs (struct f2fs_sb_info *sbi,struct fstrim_range *range); bool f2fs_exist_trim_candidates(struct f2fs_sb_info *sbi,
@@ -3318,6 +3326,7 @@ int f2fs_migrate_page(struct address_space *mapping, struct page *newpage,int f2fs_gc (struct f2fs_sb_info *sbi,bool sync,bool background,unsigned int segno);void f2fs_build_gc_manager (struct f2fs_sb_info *sbi); +int f2fs_shrink_resize (struct f2fs_sb_info *sbi,size_t resize_len);/* * recovery.c
fs/f2fs/file.c +29 -0
@@ -3013,6 +3013,32 @@ static int f2fs_ioc_precache_extents(struct file *filp, unsigned long arg)return f2fs_precache_extents (file_inode (filp)); } +static int f2fs_ioc_shrink_resize (struct file *filp,unsigned long arg) +{ +struct f2fs_sb_info *sbi =F2FS_I_SB (file_inode (filp)); +struct f2fs_resize_param param; +int ret; + +if (!capable (CAP_SYS_ADMIN )) +return -EPERM ; + +if (f2fs_readonly (sbi->sb)) +return -EROFS ; + +if (copy_from_user (¶m, (struct f2fs_resize_param __user *)arg, +sizeof (param))) +return -EFAULT ; + + ret =mnt_want_write_file (filp); +if (ret) +return ret; + + ret =f2fs_shrink_resize (sbi, param.len); +mnt_drop_write_file (filp); + +return ret; +} +long f2fs_ioctl (struct file *filp,unsigned int cmd,unsigned long arg) {if (unlikely (f2fs_cp_error (F2FS_I_SB (file_inode (filp)))))
@@ -3069,6 +3095,8 @@ long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)return f2fs_ioc_set_pin_file (filp, arg);case F2FS_IOC_PRECACHE_EXTENTS :return f2fs_ioc_precache_extents (filp, arg); +case F2FS_IOC_SHRINK_RESIZE : +return f2fs_ioc_shrink_resize (filp, arg);default :return -ENOTTY ; }
@@ -3182,6 +3210,7 @@ long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)case F2FS_IOC_GET_PIN_FILE :case F2FS_IOC_SET_PIN_FILE :case F2FS_IOC_PRECACHE_EXTENTS : +case F2FS_IOC_SHRINK_RESIZE :break ;default :return -ENOIOCTLCMD ;
fs/f2fs/gc.c +107 -2
127 lines not on this page · raw message
fs/f2fs/segment.c +38 -11
89 lines not on this page · raw message
fs/f2fs/segment.h +1 -0
@@ -59,6 +59,7 @@#define MAIN_SEGS (sbi) (SM_I(sbi)->main_segments)#define MAIN_SECS (sbi) ((sbi)->total_sections) +#define CUR_MAIN_SECS (sbi) ((sbi)->current_total_sections)#define TOTAL_SEGS (sbi) \ (SM_I(sbi) ? SM_I(sbi)->segment_count : \
fs/f2fs/super.c +1 -0
@@ -2843,6 +2843,7 @@ static void init_sb_info(struct f2fs_sb_info *sbi) sbi->segs_per_sec =le32_to_cpu (raw_super->segs_per_sec); sbi->secs_per_zone =le32_to_cpu (raw_super->secs_per_zone); sbi->total_sections =le32_to_cpu (raw_super->section_count); + sbi->current_total_sections = sbi->total_sections; sbi->total_node_count = (le32_to_cpu (raw_super->segment_count_nat) /2 ) * sbi->blocks_per_seg *NAT_ENTRY_PER_BLOCK ;
Signature · 1 line
1.8.3.1
fs/f2fs/f2fs.h static inline bool __has_cursum_space(struct f2fs_journal *journal, · line 427
Quoted 7 lines · sunqiuyang
+++
b/fs/f2fs/f2fs.hfs/f2fs/f2fs.h +2
-0@@ -423,6 +423,8 @@ static inline bool __has_cursum_space(struct f2fs_journal *journal,#define F2FS_IOC_SET_PIN_FILE _IOW(F2FS_IOCTL_MAGIC, 13, __u32)#define F2FS_IOC_GET_PIN_FILE _IOR(F2FS_IOCTL_MAGIC, 14, __u32)#define F2FS_IOC_PRECACHE_EXTENTS _IO(F2FS_IOCTL_MAGIC, 15) +#define F2FS_IOC_SHRINK_RESIZE _IOW(F2FS_IOCTL_MAGIC, 16, \ + struct f2fs_resize_param)
Why not match ext4?
fs/ext4/ext4.h:#define EXT4_IOC_RESIZE_FS _IOW('f', 16, __u64)
Quoted 11 lines · Matthew Wilcox
fs/f2fs/f2fs.h static inline bool __has_cursum_space(struct f2fs_journal *journal, · line 427
Quoted 7 lines · sunqiuyang
+++
b/fs/f2fs/f2fs.hfs/f2fs/f2fs.h +2
-0@@ -423,6 +423,8 @@ static inline bool __has_cursum_space(struct f2fs_journal *journal,#define F2FS_IOC_SET_PIN_FILE _IOW(F2FS_IOCTL_MAGIC, 13, __u32)#define F2FS_IOC_GET_PIN_FILE _IOR(F2FS_IOCTL_MAGIC, 14, __u32)#define F2FS_IOC_PRECACHE_EXTENTS _IO(F2FS_IOCTL_MAGIC, 15) +#define F2FS_IOC_SHRINK_RESIZE _IOW(F2FS_IOCTL_MAGIC, 16, \ + struct f2fs_resize_param)Why not match ext4?
Quoted 1 line
fs/ext4/ext4.h:#define
EXT4_IOC_RESIZE_FS_IOW('f', 16, __u64)
Agreed, Qiuyang, could you consider to implement this interface as ext4's, in addition, changing parameter from shrunk bytes to new block count of fs?
F2FS_IOC_RESIZE_FS _IOW('f', 16, __u64)
if (copy_from_user(&block_count, (__u64 __user *)arg, sizeof(__u64)))
Thanks,
Quoted 3 lines
.