f2fs: remove unneeded semicolon
PATCH 1/4 f2fs: remove unneeded semicolon
--- fs/f2fs/checkpoint.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/f2fs/checkpoint.c +1 -1
@@ -1016,7 +1016,7 @@ int f2fs_sync_inode_meta(struct f2fs_sb_info *sbi)update_inode_page (inode);iput (inode); } - }; + }return 0 ; }
Signature · 6 lines
2.13.1.388.g69e6b9b4f4a9 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
PATCH 2/4 f2fs: remove dead code in update_meta_page
After commit a468f0ef516f ("f2fs: use crc and cp version to determine roll-forward recovery"), last caller of update_meta_page passing @src with NULL is gone, so remove related dead code there.
--- fs/f2fs/segment.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
fs/f2fs/segment.c +1 -5
@@ -2028,12 +2028,8 @@ struct page *get_sum_page(struct f2fs_sb_info *sbi, unsigned int segno)void update_meta_page (struct f2fs_sb_info *sbi,void *src,block_t blk_addr) {struct page *page =grab_meta_page (sbi, blk_addr); -void *dst =page_address (page); -if (src) -memcpy (dst, src,PAGE_SIZE ); -else -memset (dst,0 ,PAGE_SIZE ); +memcpy (page_address (page), src,PAGE_SIZE );set_page_dirty (page);f2fs_put_page (page,1 ); }
Signature · 6 lines
2.13.1.388.g69e6b9b4f4a9 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
PATCH 3/4 f2fs: fix summary info corruption
In reply to Chao YuSometimes, after running generic/270 of fstest, fsck reports summary info and actual position of block address in direct node becoming inconsistent.
The root cause is race in between __f2fs_replace_block and change_curseg as below:
Thread A Thread B
- __clone_blkaddrs
- f2fs_replace_block
- __f2fs_replace_block
- segnoA = GET_SEGNO(sbi, blkaddrA);
- type = se->type:=CURSEG_HOT_DATA
- if (!IS_CURSEG(sbi, segnoA))
type = CURSEG_WARM_DATA
- allocate_data_block
- allocate_segment
- get_ssr_segment
- change_curseg(segnoA, CURSEG_HOT_DATA)
- change_curseg(segnoA, CURSEG_WARM_DATA)
- reset_curseg
- __set_sit_entry_type
- change se->type from CURSEG_HOT_DATA to CURSEG_WARM_DATA
So finally, hot curseg locates in segnoA, but type of segnoA becomes CURSEG_WARM_DATA.
Then if we invoke __f2fs_replace_block(blkaddrB, blkaddrA, true, false), as blkaddrA locates in segnoA, so we will move warm type curseg to segnoA, then change its summary cache and writeback it to summary block.
But segnoA is used by hot type curseg too, once it moves or persist, it will cover summary block content with inner old summary cache, result in inconsistent status.
This patch tries to fix this issue by introduce global curseg lock to avoid race in between __f2fs_replace_block and change_curseg.
--- fs/f2fs/f2fs.h | 2 ++ fs/f2fs/segment.c | 28 +++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-)
fs/f2fs/f2fs.h +2 -0
@@ -820,6 +820,8 @@ struct f2fs_sm_info {struct dirty_seglist_info *dirty_info;/* dirty segment information */ struct curseg_info *curseg_array;/* active segment information */ +struct rw_semaphore curseg_lock;/* for preventing curseg change */ +block_t seg0_blkaddr;/* block address of 0'th segment */ block_t main_blkaddr;/* start block address of main area */ block_t ssa_blkaddr;/* start block address of SSA area */
fs/f2fs/segment.c +27 -1
@@ -2549,6 +2549,8 @@ void allocate_data_block(struct f2fs_sb_info *sbi, struct page *page,struct sit_info *sit_i =SIT_I (sbi);struct curseg_info *curseg =CURSEG_I (sbi, type); +down_read (&SM_I (sbi)->curseg_lock); +mutex_lock (&curseg->curseg_mutex);down_write (&sit_i->sentry_lock);
@@ -2606,6 +2608,8 @@ void allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, }mutex_unlock (&curseg->curseg_mutex); + +up_read (&SM_I (sbi)->curseg_lock); }static void update_device_state (struct f2fs_io_info *fio)
@@ -2713,6 +2717,18 @@ int rewrite_data_page(struct f2fs_io_info *fio)return err; } +static inline int __f2fs_get_curseg (struct f2fs_sb_info *sbi, +unsigned int segno) +{ +int i; + +for (i =CURSEG_HOT_DATA ; i <NO_CHECK_TYPE ; i++) { +if (CURSEG_I (sbi, i)->segno == segno) +break ; + } +return i; +} +void __f2fs_replace_block (struct f2fs_sb_info *sbi,struct f2fs_summary *sum,block_t old_blkaddr,block_t new_blkaddr,bool recover_curseg,bool recover_newaddr)
@@ -2728,6 +2744,8 @@ void __f2fs_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, se =get_seg_entry (sbi, segno); type = se->type; +down_write (&SM_I (sbi)->curseg_lock); +if (!recover_curseg) {/* for recovery flow */ if (se->valid_blocks ==0 && !IS_CURSEG (sbi, segno)) {
@@ -2737,8 +2755,13 @@ void __f2fs_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, type =CURSEG_WARM_DATA ; } }else { -if (!IS_CURSEG (sbi, segno)) +if (IS_CURSEG (sbi, segno)) { +/* se->type is volatile as SSR allocation */ + type =__f2fs_get_curseg (sbi, segno); +f2fs_bug_on (sbi, type ==NO_CHECK_TYPE ); + }else { type =CURSEG_WARM_DATA ; + } } curseg =CURSEG_I (sbi, type);
@@ -2778,6 +2801,7 @@ void __f2fs_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,up_write (&sit_i->sentry_lock);mutex_unlock (&curseg->curseg_mutex); +up_write (&SM_I (sbi)->curseg_lock); } void f2fs_replace_block(struct f2fs_sb_info *sbi, struct dnode_of_data *dn,
@@ -3715,6 +3739,8 @@ int build_segment_manager(struct f2fs_sb_info *sbi)INIT_LIST_HEAD (&sm_info->sit_entry_set); +init_rwsem (&sm_info->curseg_lock); +if (!f2fs_readonly (sbi->sb)) { err =create_flush_cmd_control (sbi);if (err)
Signature · 6 lines
2.13.1.388.g69e6b9b4f4a9 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
PATCH 4/4 f2fs: avoid race in between GC and block exchange
In reply to Chao YuDuring block exchange in {insert,collapse,move}_range, page-block mapping is unstable due to mapping moving or recovery, so there should be no concurrent cache read operation rely on such mapping, nor cache write operation to mess up block exchange.
So this patch let background GC be aware of that.
--- fs/f2fs/file.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-)
fs/f2fs/file.c +19 -3
@@ -1186,6 +1186,9 @@ static int f2fs_collapse_range(struct inode *inode, loff_t offset, loff_t len)if (ret) goto out; +/* avoid gc operation during block exchange */ +down_write (&F2FS_I (inode)->dio_rwsem[WRITE ]); +truncate_pagecache (inode, offset); ret =f2fs_do_collapse (inode, pg_start, pg_end);
@@ -1204,6 +1207,7 @@ static int f2fs_collapse_range(struct inode *inode, loff_t offset, loff_t len)f2fs_i_size_write (inode, new_size); out: +up_write (&F2FS_I (inode)->dio_rwsem[WRITE ]);up_write (&F2FS_I (inode)->i_mmap_sem);return ret; }
@@ -1385,6 +1389,9 @@ static int f2fs_insert_range(struct inode *inode, loff_t offset, loff_t len)if (ret) goto out; +/* avoid gc operation during block exchange */ +down_write (&F2FS_I (inode)->dio_rwsem[WRITE ]); +truncate_pagecache (inode, offset); pg_start = offset >>PAGE_SHIFT ;
@@ -1412,6 +1419,8 @@ static int f2fs_insert_range(struct inode *inode, loff_t offset, loff_t len)if (!ret)f2fs_i_size_write (inode, new_size); + +up_write (&F2FS_I (inode)->dio_rwsem[WRITE ]); out:up_write (&F2FS_I (inode)->i_mmap_sem);return ret;
@@ -2274,9 +2283,13 @@ static int f2fs_move_file_range(struct file *file_in, loff_t pos_in, }inode_lock (src); +down_write (&F2FS_I (src)->dio_rwsem[WRITE ]);if (src != dst) { -if (!inode_trylock (dst)) { - ret = -EBUSY ; + ret = -EBUSY ; +if (!inode_trylock (dst)) + goto out; +if (!down_write_trylock (&F2FS_I (dst)->dio_rwsem[WRITE ])) { +inode_unlock (dst); goto out; } }
@@ -2336,9 +2349,12 @@ static int f2fs_move_file_range(struct file *file_in, loff_t pos_in, }f2fs_unlock_op (sbi); out_unlock: -if (src != dst) +if (src != dst) { +up_write (&F2FS_I (dst)->dio_rwsem[WRITE ]);inode_unlock (dst); + } out: +up_write (&F2FS_I (src)->dio_rwsem[WRITE ]);inode_unlock (src);return ret; }
Signature · 6 lines
2.13.1.388.g69e6b9b4f4a9 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot