f2fs: quota: fix quota flush failure during filesystem freeze
PATCH 1/1 f2fs: quota: fix quota flush failure during filesystem freeze
Quota flush retries can be exhausted during filesystem freeze.
freeze_super() and the quota checkpoint may race as below.
freeze_super() f2fs_ckpt
- down_write(&sb->s_umount)
- sb->s_writers.frozen = SB_FREEZE_PAGEFAULT
- sync_filesystem()
- f2fs_sync_fs()
- f2fs_issue_checkpoint()
- queue CP_SYNC -----------------> - block_operations()
- down_read_trylock(s_umount) : fails; freeze holds write lock
- quota flush retries exhausted
- set CP_QUOTA_NEED_FSCK_FLAG
During the PAGEFAULT sync pass, freeze_super() holds s_umount for write, but umount_lock_holder is not set until f2fs_freeze(). Thus quota writeback tries to acquire s_umount again and can exhaust retries.
With checkpoint merge enabled, f2fs_issue_checkpoint() may dispatch CP_SYNC to f2fs_ckpt. That thread also cannot acquire the freeze lock.
Split the F2FS-internal sync implementation from the super-operation callback. For the VFS PAGEFAULT freeze sync, record current as holder around the internal sync. This lets quota writeback use the existing lock and makes CP_SYNC run directly in the freeze caller.
Convert F2FS-internal callers to the internal helper so they cannot be mistaken for the freeze owner while the filesystem is frozen.
--- fs/f2fs/f2fs.h | 2 +- fs/f2fs/file.c | 8 ++++---- fs/f2fs/namei.c | 16 ++++++++-------- fs/f2fs/segment.c | 4 ++-- fs/f2fs/super.c | 25 ++++++++++++++++++++++--- 5 files changed, 37 insertions(+), 18 deletions(-)
fs/f2fs/f2fs.h +1 -1
@@ -3977,7 +3977,7 @@ void f2fs_quota_off_umount(struct super_block *sb);void f2fs_save_errors (struct f2fs_sb_info *sbi,unsigned char flag);void f2fs_handle_error (struct f2fs_sb_info *sbi,unsigned char error);int f2fs_commit_super (struct f2fs_sb_info *sbi,bool recover); -int f2fs_sync_fs (struct super_block *sb,int sync); +int __f2fs_sync_fs (struct super_block *sb,int sync);int f2fs_sanity_check_ckpt (struct f2fs_sb_info *sbi);/*
fs/f2fs/file.c +4 -4
@@ -408,7 +408,7 @@ static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end,if (cp_reason) {/* all the dirty node pages should be flushed for POR */ - ret =f2fs_sync_fs (inode->i_sb,1 ); + ret =__f2fs_sync_fs (inode->i_sb,1 );/* * We've secured consistency through sync_fs. Following pino
@@ -2548,7 +2548,7 @@ int f2fs_do_shutdown(struct f2fs_sb_info *sbi, unsigned int flag,break ;case F2FS_GOING_DOWN_METASYNC :/* do checkpoint only */ - ret =f2fs_sync_fs (sb,1 ); + ret =__f2fs_sync_fs (sb,1 );if (ret) {if (ret == -EIO ) ret =0 ;
@@ -2568,7 +2568,7 @@ int f2fs_do_shutdown(struct f2fs_sb_info *sbi, unsigned int flag,set_sbi_flag (sbi,SBI_CP_DISABLED_QUICK );set_sbi_flag (sbi,SBI_IS_DIRTY );/* do checkpoint only */ - ret =f2fs_sync_fs (sb,1 ); + ret =__f2fs_sync_fs (sb,1 );if (ret == -EIO ) ret =0 ; goto out;
@@ -2988,7 +2988,7 @@ static int f2fs_ioc_write_checkpoint(struct file *filp)if (ret)return ret; - ret =f2fs_sync_fs (sbi->sb,1 ); + ret =__f2fs_sync_fs (sbi->sb,1 );mnt_drop_write_file (filp);return ret;
fs/f2fs/namei.c +8 -8
@@ -403,7 +403,7 @@ static int f2fs_create(struct mnt_idmap *idmap, struct inode *dir,d_instantiate_new (dentry, inode);if (IS_DIRSYNC (dir)) { - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (err)return err; }
@@ -459,7 +459,7 @@ static int f2fs_link(struct dentry *old_dentry, struct inode *dir,d_instantiate (dentry, inode);if (IS_DIRSYNC (dir)) { - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (err)return err; }
@@ -641,7 +641,7 @@ static int f2fs_unlink(struct inode *dir, struct dentry *dentry)d_invalidate (dentry);if (IS_DIRSYNC (dir)) - err =f2fs_sync_fs (F2FS_I_SB (dir)->sb,1 ); + err =__f2fs_sync_fs (F2FS_I_SB (dir)->sb,1 ); out:trace_f2fs_unlink_exit (d_inode (dentry), err);return err;
@@ -729,7 +729,7 @@ static int f2fs_symlink(struct mnt_idmap *idmap, struct inode *dir, ret =filemap_write_and_wait_range (inode->i_mapping,0 , disk_link.len -1 );if (!ret &&IS_DIRSYNC (dir)) - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );f2fs_balance_fs (sbi, true); out:
@@ -787,7 +787,7 @@ static struct dentry *f2fs_mkdir(struct mnt_idmap *idmap, struct inode *dir,d_instantiate_new (dentry, inode);if (IS_DIRSYNC (dir)) { - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (err)return ERR_PTR (err); }
@@ -845,7 +845,7 @@ static int f2fs_mknod(struct mnt_idmap *idmap, struct inode *dir,d_instantiate_new (dentry, inode);if (IS_DIRSYNC (dir)) { - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (err)return err; }
@@ -1148,7 +1148,7 @@ static int f2fs_rename(struct mnt_idmap *idmap, struct inode *old_dir,f2fs_unlock_op (sbi, &lc);if (IS_DIRSYNC (old_dir) ||IS_DIRSYNC (new_dir)) { - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (err)return err; }
@@ -1318,7 +1318,7 @@ static int f2fs_cross_rename(struct inode *old_dir, struct dentry *old_dentry,f2fs_unlock_op (sbi, &lc);if (IS_DIRSYNC (old_dir) ||IS_DIRSYNC (new_dir)) { - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (err)return err; }
fs/f2fs/segment.c +2 -2
@@ -550,7 +550,7 @@ void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi, bool from_bg)mutex_unlock (&sbi->flush_lock); }stat_inc_cp_call_count (sbi,BACKGROUND ); -f2fs_sync_fs (sbi->sb,1 ); +__f2fs_sync_fs (sbi->sb,1 ); } static int __submit_flush_wait(struct f2fs_sb_info *sbi,
@@ -3478,7 +3478,7 @@ int f2fs_allocate_pinning_section(struct f2fs_sb_info *sbi) true, ZONED_PIN_SEC_REQUIRED_COUNT, true);if (err)return err; - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (!err) { gc_required = false; goto retry;
fs/f2fs/super.c +22 -3
@@ -2131,7 +2131,7 @@ static void f2fs_put_super(struct super_block *sb) } } -int f2fs_sync_fs (struct super_block *sb,int sync) +int __f2fs_sync_fs (struct super_block *sb,int sync) {struct f2fs_sb_info *sbi =F2FS_SB (sb);int err =0 ;
@@ -2154,6 +2154,25 @@ int f2fs_sync_fs(struct super_block *sb, int sync)return err; } +static int f2fs_sync_fs (struct super_block *sb,int sync) +{ +struct f2fs_sb_info *sbi =F2FS_SB (sb); +bool freeze_sync = sync && + sb->s_writers.frozen ==SB_FREEZE_PAGEFAULT ; +int err; + +/* freeze_super() holds s_umount for write during this sync pass. */ +if (freeze_sync) + sbi->umount_lock_holder = current; + + err =__f2fs_sync_fs (sb, sync); + +if (freeze_sync) + sbi->umount_lock_holder =NULL ; + +return err; +} +static int f2fs_freeze (struct super_block *sb) {struct f2fs_sb_info *sbi =F2FS_SB (sb);
@@ -2807,7 +2826,7 @@ static int f2fs_enable_checkpoint(struct f2fs_sb_info *sbi)set_sbi_flag (sbi,SBI_IS_DIRTY );f2fs_up_write_trace (&sbi->gc_lock, &lc); - ret =f2fs_sync_fs (sbi->sb,1 ); + ret =__f2fs_sync_fs (sbi->sb,1 );if (ret)f2fs_err (sbi,"%s sync_fs failed, ret: %d" , __func__, ret);
@@ -2993,7 +3012,7 @@ static int __f2fs_remount(struct fs_context *fc, struct super_block *sb)set_sbi_flag (sbi,SBI_IS_DIRTY );set_sbi_flag (sbi,SBI_IS_CLOSE ); - err =f2fs_sync_fs (sb,1 ); + err =__f2fs_sync_fs (sb,1 );if (err) goto restore_gc;clear_sbi_flag (sbi,SBI_IS_CLOSE );
Signature · 8 lines
2.43.0 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 206 lines · Jianan Huang
Quota flush retries can be exhausted during filesystem freeze.
freeze_super()and the quota checkpoint may race as below.
freeze_super()f2fs_ckpt
-down_write(&sb->s_umount)
-sb->s_writers.frozen=SB_FREEZE_PAGEFAULT
-sync_filesystem()
-f2fs_sync_fs()
-f2fs_issue_checkpoint()
- queueCP_SYNC-----------------> -block_operations()
-down_read_trylock(s_umount): fails; freeze holds write lock
- quota flush retries exhausted
- setCP_QUOTA_NEED_FSCK_FLAGDuring the PAGEFAULT sync pass,
freeze_super()holdss_umountfor write, butumount_lock_holderis not set untilf2fs_freeze(). Thus quota writeback tries to acquires_umountagain and can exhaust retries.With checkpoint merge enabled,
f2fs_issue_checkpoint()may dispatchCP_SYNCtof2fs_ckpt. That thread also cannot acquire the freeze lock.Split the F2FS-internal sync implementation from the super-operation callback. For the VFS PAGEFAULT freeze sync, record current as holder around the internal sync. This lets quota writeback use the existing lock and makes
CP_SYNCrun directly in the freeze caller.Convert F2FS-internal callers to the internal helper so they cannot be mistaken for the freeze owner while the filesystem is frozen.
Fixes eb85c2410d6f ("f2fs: quota: fix to avoid warning in dquot_writeback_dquots()")Signed-off-by Jianan Huang <[email protected]>--- fs/f2fs/f2fs.h | 2 +- fs/f2fs/file.c | 8 ++++---- fs/f2fs/namei.c | 16 ++++++++-------- fs/f2fs/segment.c | 4 ++-- fs/f2fs/super.c | 25 ++++++++++++++++++++++--- 5 files changed, 37 insertions(+), 18 deletions(-)fs/f2fs/f2fs.h +1
-1@@ -3977,7 +3977,7 @@ void f2fs_quota_off_umount(struct super_block *sb);void f2fs_save_errors (struct f2fs_sb_info *sbi,unsigned char flag);void f2fs_handle_error (struct f2fs_sb_info *sbi,unsigned char error);int f2fs_commit_super (struct f2fs_sb_info *sbi,bool recover); -int f2fs_sync_fs (struct super_block *sb,int sync); +int __f2fs_sync_fs (struct super_block *sb,int sync);int f2fs_sanity_check_ckpt (struct f2fs_sb_info *sbi);/* fs/f2fs/file.c +4
-4@@ -408,7 +408,7 @@ static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end,if (cp_reason) {/* all the dirty node pages should be flushed for POR */ - ret =f2fs_sync_fs (inode->i_sb,1 ); + ret =__f2fs_sync_fs (inode->i_sb,1 );/* * We've secured consistency through sync_fs. Following pino @@ -2548,7 +2548,7 @@ int f2fs_do_shutdown(struct f2fs_sb_info *sbi, unsigned int flag,break ;case F2FS_GOING_DOWN_METASYNC :/* do checkpoint only */ - ret =f2fs_sync_fs (sb,1 ); + ret =__f2fs_sync_fs (sb,1 );if (ret) {if (ret == -EIO ) ret =0 ;@@ -2568,7 +2568,7 @@ int f2fs_do_shutdown(struct f2fs_sb_info *sbi, unsigned int flag,set_sbi_flag (sbi,SBI_CP_DISABLED_QUICK );set_sbi_flag (sbi,SBI_IS_DIRTY );/* do checkpoint only */ - ret =f2fs_sync_fs (sb,1 ); + ret =__f2fs_sync_fs (sb,1 );if (ret == -EIO ) ret =0 ; goto out;@@ -2988,7 +2988,7 @@ static int f2fs_ioc_write_checkpoint(struct file *filp)if (ret)return ret; - ret =f2fs_sync_fs (sbi->sb,1 ); + ret =__f2fs_sync_fs (sbi->sb,1 );mnt_drop_write_file (filp);return ret;fs/f2fs/namei.c +8
-8@@ -403,7 +403,7 @@ static int f2fs_create(struct mnt_idmap *idmap, struct inode *dir,d_instantiate_new (dentry, inode);if (IS_DIRSYNC (dir)) { - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (err)return err; }@@ -459,7 +459,7 @@ static int f2fs_link(struct dentry *old_dentry, struct inode *dir,d_instantiate (dentry, inode);if (IS_DIRSYNC (dir)) { - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (err)return err; }@@ -641,7 +641,7 @@ static int f2fs_unlink(struct inode *dir, struct dentry *dentry)d_invalidate (dentry);if (IS_DIRSYNC (dir)) - err =f2fs_sync_fs (F2FS_I_SB (dir)->sb,1 ); + err =__f2fs_sync_fs (F2FS_I_SB (dir)->sb,1 ); out:trace_f2fs_unlink_exit (d_inode (dentry), err);return err;@@ -729,7 +729,7 @@ static int f2fs_symlink(struct mnt_idmap *idmap, struct inode *dir, ret =filemap_write_and_wait_range (inode->i_mapping,0 , disk_link.len -1 );if (!ret &&IS_DIRSYNC (dir)) - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );f2fs_balance_fs (sbi, true); out:@@ -787,7 +787,7 @@ static struct dentry *f2fs_mkdir(struct mnt_idmap *idmap, struct inode *dir,d_instantiate_new (dentry, inode);if (IS_DIRSYNC (dir)) { - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (err)return ERR_PTR (err); }@@ -845,7 +845,7 @@ static int f2fs_mknod(struct mnt_idmap *idmap, struct inode *dir,d_instantiate_new (dentry, inode);if (IS_DIRSYNC (dir)) { - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (err)return err; }@@ -1148,7 +1148,7 @@ static int f2fs_rename(struct mnt_idmap *idmap, struct inode *old_dir,f2fs_unlock_op (sbi, &lc);if (IS_DIRSYNC (old_dir) ||IS_DIRSYNC (new_dir)) { - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (err)return err; }@@ -1318,7 +1318,7 @@ static int f2fs_cross_rename(struct inode *old_dir, struct dentry *old_dentry,f2fs_unlock_op (sbi, &lc);if (IS_DIRSYNC (old_dir) ||IS_DIRSYNC (new_dir)) { - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (err)return err; }fs/f2fs/segment.c +2
-2@@ -550,7 +550,7 @@ void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi, bool from_bg)mutex_unlock (&sbi->flush_lock); }stat_inc_cp_call_count (sbi,BACKGROUND ); -f2fs_sync_fs (sbi->sb,1 ); +__f2fs_sync_fs (sbi->sb,1 ); } static int __submit_flush_wait(struct f2fs_sb_info *sbi,@@ -3478,7 +3478,7 @@ int f2fs_allocate_pinning_section(struct f2fs_sb_info *sbi) true, ZONED_PIN_SEC_REQUIRED_COUNT, true);if (err)return err; - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (!err) { gc_required = false; goto retry;fs/f2fs/super.c +1
-1@@ -2131,7 +2131,7 @@ static void f2fs_put_super(struct super_block *sb) } } -int f2fs_sync_fs (struct super_block *sb,int sync) +int __f2fs_sync_fs (struct super_block *sb,int sync) {struct f2fs_sb_info *sbi =F2FS_SB (sb);int err =0 ;
fs/f2fs/super.c int f2fs_sync_fs(struct super_block *sb, int sync) · line 2161
Quoted 8 lines
fs/f2fs/super.c +5
-0@@ -2154,6 +2154,25 @@ int f2fs_sync_fs(struct super_block *sb, int sync)return err; } +static int f2fs_sync_fs (struct super_block *sb,int sync) +{ +struct f2fs_sb_info *sbi =F2FS_SB (sb); +bool freeze_sync = sync && + sb->s_writers.frozen ==SB_FREEZE_PAGEFAULT ;
How about this to make sure freeze_sync will only be true in freeze_super()?
bool freeze_sync = sync && rwsem_is_locked(&sb->s_umount) &&
sb->s_writers.frozen == SB_FREEZE_PAGEFAULT;
And it's not needed to rename f2fs_sync_fs() to __f2fs_sync_fs()?
Thanks,
Quoted 27 lines
fs/f2fs/super.c +15
-1+int err; + +/* freeze_super() holds s_umount for write during this sync pass. */ +if (freeze_sync) + sbi->umount_lock_holder = current; + + err =__f2fs_sync_fs (sb, sync); + +if (freeze_sync) + sbi->umount_lock_holder =NULL ; + +return err; +} +static int f2fs_freeze (struct super_block *sb) {struct f2fs_sb_info *sbi =F2FS_SB (sb);@@ -2807,7 +2826,7 @@ static int f2fs_enable_checkpoint(struct f2fs_sb_info *sbi)set_sbi_flag (sbi,SBI_IS_DIRTY );f2fs_up_write_trace (&sbi->gc_lock, &lc); - ret =f2fs_sync_fs (sbi->sb,1 ); + ret =__f2fs_sync_fs (sbi->sb,1 );if (ret)f2fs_err (sbi,"%s sync_fs failed, ret: %d" , __func__, ret);
fs/f2fs/super.c static int __f2fs_remount(struct fs_context *fc, struct super_block *sb) · line 3018
Quoted 8 lines
fs/f2fs/super.c +1
-1@@ -2993,7 +3012,7 @@ static int __f2fs_remount(struct fs_context *fc, struct super_block *sb)set_sbi_flag (sbi,SBI_IS_DIRTY );set_sbi_flag (sbi,SBI_IS_CLOSE ); - err =f2fs_sync_fs (sb,1 ); + err =__f2fs_sync_fs (sb,1 );if (err) goto restore_gc;clear_sbi_flag (sbi,SBI_IS_CLOSE );
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 219 lines · Chao Yu <[email protected]> 于2026年9月9日周三 19:43写道:
Quoted 206 lines · Jianan Huang
Quota flush retries can be exhausted during filesystem freeze.
freeze_super()and the quota checkpoint may race as below.
freeze_super()f2fs_ckpt
-down_write(&sb->s_umount)
-sb->s_writers.frozen=SB_FREEZE_PAGEFAULT
-sync_filesystem()
-f2fs_sync_fs()
-f2fs_issue_checkpoint()
- queueCP_SYNC-----------------> -block_operations()
-down_read_trylock(s_umount): fails; freeze holds write lock
- quota flush retries exhausted
- setCP_QUOTA_NEED_FSCK_FLAGDuring the PAGEFAULT sync pass,
freeze_super()holdss_umountfor write, butumount_lock_holderis not set untilf2fs_freeze(). Thus quota writeback tries to acquires_umountagain and can exhaust retries.With checkpoint merge enabled,
f2fs_issue_checkpoint()may dispatchCP_SYNCtof2fs_ckpt. That thread also cannot acquire the freeze lock.Split the F2FS-internal sync implementation from the super-operation callback. For the VFS PAGEFAULT freeze sync, record current as holder around the internal sync. This lets quota writeback use the existing lock and makes
CP_SYNCrun directly in the freeze caller.Convert F2FS-internal callers to the internal helper so they cannot be mistaken for the freeze owner while the filesystem is frozen.
Fixes eb85c2410d6f ("f2fs: quota: fix to avoid warning in dquot_writeback_dquots()")Signed-off-by Jianan Huang <[email protected]>--- fs/f2fs/f2fs.h | 2 +- fs/f2fs/file.c | 8 ++++---- fs/f2fs/namei.c | 16 ++++++++-------- fs/f2fs/segment.c | 4 ++-- fs/f2fs/super.c | 25 ++++++++++++++++++++++--- 5 files changed, 37 insertions(+), 18 deletions(-)fs/f2fs/f2fs.h +1
-1@@ -3977,7 +3977,7 @@ void f2fs_quota_off_umount(struct super_block *sb);void f2fs_save_errors (struct f2fs_sb_info *sbi,unsigned char flag);void f2fs_handle_error (struct f2fs_sb_info *sbi,unsigned char error);int f2fs_commit_super (struct f2fs_sb_info *sbi,bool recover); -int f2fs_sync_fs (struct super_block *sb,int sync); +int __f2fs_sync_fs (struct super_block *sb,int sync);int f2fs_sanity_check_ckpt (struct f2fs_sb_info *sbi);/* fs/f2fs/file.c +4
-4@@ -408,7 +408,7 @@ static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end,if (cp_reason) {/* all the dirty node pages should be flushed for POR */ - ret =f2fs_sync_fs (inode->i_sb,1 ); + ret =__f2fs_sync_fs (inode->i_sb,1 );/* * We've secured consistency through sync_fs. Following pino @@ -2548,7 +2548,7 @@ int f2fs_do_shutdown(struct f2fs_sb_info *sbi, unsigned int flag,break ;case F2FS_GOING_DOWN_METASYNC :/* do checkpoint only */ - ret =f2fs_sync_fs (sb,1 ); + ret =__f2fs_sync_fs (sb,1 );if (ret) {if (ret == -EIO ) ret =0 ;@@ -2568,7 +2568,7 @@ int f2fs_do_shutdown(struct f2fs_sb_info *sbi, unsigned int flag,set_sbi_flag (sbi,SBI_CP_DISABLED_QUICK );set_sbi_flag (sbi,SBI_IS_DIRTY );/* do checkpoint only */ - ret =f2fs_sync_fs (sb,1 ); + ret =__f2fs_sync_fs (sb,1 );if (ret == -EIO ) ret =0 ; goto out;@@ -2988,7 +2988,7 @@ static int f2fs_ioc_write_checkpoint(struct file *filp)if (ret)return ret; - ret =f2fs_sync_fs (sbi->sb,1 ); + ret =__f2fs_sync_fs (sbi->sb,1 );mnt_drop_write_file (filp);return ret;fs/f2fs/namei.c +8
-8@@ -403,7 +403,7 @@ static int f2fs_create(struct mnt_idmap *idmap, struct inode *dir,d_instantiate_new (dentry, inode);if (IS_DIRSYNC (dir)) { - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (err)return err; }@@ -459,7 +459,7 @@ static int f2fs_link(struct dentry *old_dentry, struct inode *dir,d_instantiate (dentry, inode);if (IS_DIRSYNC (dir)) { - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (err)return err; }@@ -641,7 +641,7 @@ static int f2fs_unlink(struct inode *dir, struct dentry *dentry)d_invalidate (dentry);if (IS_DIRSYNC (dir)) - err =f2fs_sync_fs (F2FS_I_SB (dir)->sb,1 ); + err =__f2fs_sync_fs (F2FS_I_SB (dir)->sb,1 ); out:trace_f2fs_unlink_exit (d_inode (dentry), err);return err;@@ -729,7 +729,7 @@ static int f2fs_symlink(struct mnt_idmap *idmap, struct inode *dir, ret =filemap_write_and_wait_range (inode->i_mapping,0 , disk_link.len -1 );if (!ret &&IS_DIRSYNC (dir)) - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );f2fs_balance_fs (sbi, true); out:@@ -787,7 +787,7 @@ static struct dentry *f2fs_mkdir(struct mnt_idmap *idmap, struct inode *dir,d_instantiate_new (dentry, inode);if (IS_DIRSYNC (dir)) { - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (err)return ERR_PTR (err); }@@ -845,7 +845,7 @@ static int f2fs_mknod(struct mnt_idmap *idmap, struct inode *dir,d_instantiate_new (dentry, inode);if (IS_DIRSYNC (dir)) { - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (err)return err; }@@ -1148,7 +1148,7 @@ static int f2fs_rename(struct mnt_idmap *idmap, struct inode *old_dir,f2fs_unlock_op (sbi, &lc);if (IS_DIRSYNC (old_dir) ||IS_DIRSYNC (new_dir)) { - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (err)return err; }@@ -1318,7 +1318,7 @@ static int f2fs_cross_rename(struct inode *old_dir, struct dentry *old_dentry,f2fs_unlock_op (sbi, &lc);if (IS_DIRSYNC (old_dir) ||IS_DIRSYNC (new_dir)) { - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (err)return err; }fs/f2fs/segment.c +2
-2@@ -550,7 +550,7 @@ void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi, bool from_bg)mutex_unlock (&sbi->flush_lock); }stat_inc_cp_call_count (sbi,BACKGROUND ); -f2fs_sync_fs (sbi->sb,1 ); +__f2fs_sync_fs (sbi->sb,1 ); } static int __submit_flush_wait(struct f2fs_sb_info *sbi,@@ -3478,7 +3478,7 @@ int f2fs_allocate_pinning_section(struct f2fs_sb_info *sbi) true, ZONED_PIN_SEC_REQUIRED_COUNT, true);if (err)return err; - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (!err) { gc_required = false; goto retry;fs/f2fs/super.c +1
-1@@ -2131,7 +2131,7 @@ static void f2fs_put_super(struct super_block *sb) } } -int f2fs_sync_fs (struct super_block *sb,int sync) +int __f2fs_sync_fs (struct super_block *sb,int sync) {struct f2fs_sb_info *sbi =F2FS_SB (sb);int err =0 ;fs/f2fs/super.c int f2fs_sync_fs(struct super_block *sb, int sync) · line 2161
Quoted 8 lines
fs/f2fs/super.c +5
-0@@ -2154,6 +2154,25 @@ int f2fs_sync_fs(struct super_block *sb, int sync)return err; } +static int f2fs_sync_fs (struct super_block *sb,int sync) +{ +struct f2fs_sb_info *sbi =F2FS_SB (sb); +bool freeze_sync = sync && + sb->s_writers.frozen ==SB_FREEZE_PAGEFAULT ;How about this to make sure
freeze_syncwill only be true infreeze_super()?
Quoted 5 lines
bool
freeze_sync= sync &&rwsem_is_locked(&sb->s_umount)&&sb->s_writers.frozen == SB_FREEZE_PAGEFAULT;And it's not needed to rename
f2fs_sync_fs()to__f2fs_sync_fs()?
Sorry for the late reply. rwsem_is_locked() doesn't tell us whether current owns the lock, so I'm concerned about the following race:
Freezer A Directory fsync B
holds s_umount write lock
stage = SB_FREEZE_PAGEFAULT
holder = current_A
locks gc_lock
holder = current_B waits for gc_lock
holder != current_As_umount read trylock fails
retry limit -> QUOTA_SKIP_FLUSH
sets QUOTA_NEED_FLUSH
commits CP with quota_need_fsck
clears IS_DIRTY
unlocks gc_lock
holder = NULL
stage = SB_FREEZE_FS
locks gc_lock
!IS_DIRTY && CP_SYNC
-> returns before quota flush
unlocks gc_lock
holder = NULLcompletes f2fs_freeze()
unlocks s_umount
FIFREEZE returns
Could we use a separate f2fs_sync_fs_super() wrapper for the VFS callback and keep freeze holder management there, leaving f2fs_sync_fs() for internal callers?
Thanks,
Quoted 30 lines
Thanks,
Quoted 28 lines
fs/f2fs/super.c +15
-1+int err; + +/* freeze_super() holds s_umount for write during this sync pass. */ +if (freeze_sync) + sbi->umount_lock_holder = current; + + err =__f2fs_sync_fs (sb, sync); + +if (freeze_sync) + sbi->umount_lock_holder =NULL ; + +return err; +} +static int f2fs_freeze (struct super_block *sb) {struct f2fs_sb_info *sbi =F2FS_SB (sb);@@ -2807,7 +2826,7 @@ static int f2fs_enable_checkpoint(struct f2fs_sb_info *sbi)set_sbi_flag (sbi,SBI_IS_DIRTY );f2fs_up_write_trace (&sbi->gc_lock, &lc); - ret =f2fs_sync_fs (sbi->sb,1 ); + ret =__f2fs_sync_fs (sbi->sb,1 );if (ret)f2fs_err (sbi,"%s sync_fs failed, ret: %d" , __func__, ret);@@ -2993,7 +3012,7 @@ static int __f2fs_remount(struct fs_context *fc, struct super_block *sb)
Quoted 8 lines
fs/f2fs/super.c static int __f2fs_remount(struct fs_context *fc, struct super_block *sb) · line 3018
Quoted 7 lines
fs/f2fs/super.c +1
-1set_sbi_flag (sbi,SBI_IS_DIRTY );set_sbi_flag (sbi,SBI_IS_CLOSE ); - err =f2fs_sync_fs (sb,1 ); + err =__f2fs_sync_fs (sb,1 );if (err) goto restore_gc;clear_sbi_flag (sbi,SBI_IS_CLOSE );
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 229 lines · Jianan Huang
Quoted 219 lines · Chao Yu <[email protected]> 于2026年9月9日周三 19:43写道:
Quoted 206 lines · Jianan Huang
Quota flush retries can be exhausted during filesystem freeze.
freeze_super()and the quota checkpoint may race as below.
freeze_super()f2fs_ckpt
-down_write(&sb->s_umount)
-sb->s_writers.frozen=SB_FREEZE_PAGEFAULT
-sync_filesystem()
-f2fs_sync_fs()
-f2fs_issue_checkpoint()
- queueCP_SYNC-----------------> -block_operations()
-down_read_trylock(s_umount): fails; freeze holds write lock
- quota flush retries exhausted
- setCP_QUOTA_NEED_FSCK_FLAGDuring the PAGEFAULT sync pass,
freeze_super()holdss_umountfor write, butumount_lock_holderis not set untilf2fs_freeze(). Thus quota writeback tries to acquires_umountagain and can exhaust retries.With checkpoint merge enabled,
f2fs_issue_checkpoint()may dispatchCP_SYNCtof2fs_ckpt. That thread also cannot acquire the freeze lock.Split the F2FS-internal sync implementation from the super-operation callback. For the VFS PAGEFAULT freeze sync, record current as holder around the internal sync. This lets quota writeback use the existing lock and makes
CP_SYNCrun directly in the freeze caller.Convert F2FS-internal callers to the internal helper so they cannot be mistaken for the freeze owner while the filesystem is frozen.
Fixes eb85c2410d6f ("f2fs: quota: fix to avoid warning in dquot_writeback_dquots()")Signed-off-by Jianan Huang <[email protected]>--- fs/f2fs/f2fs.h | 2 +- fs/f2fs/file.c | 8 ++++---- fs/f2fs/namei.c | 16 ++++++++-------- fs/f2fs/segment.c | 4 ++-- fs/f2fs/super.c | 25 ++++++++++++++++++++++--- 5 files changed, 37 insertions(+), 18 deletions(-)fs/f2fs/f2fs.h +1
-1@@ -3977,7 +3977,7 @@ void f2fs_quota_off_umount(struct super_block *sb);void f2fs_save_errors (struct f2fs_sb_info *sbi,unsigned char flag);void f2fs_handle_error (struct f2fs_sb_info *sbi,unsigned char error);int f2fs_commit_super (struct f2fs_sb_info *sbi,bool recover); -int f2fs_sync_fs (struct super_block *sb,int sync); +int __f2fs_sync_fs (struct super_block *sb,int sync);int f2fs_sanity_check_ckpt (struct f2fs_sb_info *sbi);/* fs/f2fs/file.c +4
-4@@ -408,7 +408,7 @@ static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end,if (cp_reason) {/* all the dirty node pages should be flushed for POR */ - ret =f2fs_sync_fs (inode->i_sb,1 ); + ret =__f2fs_sync_fs (inode->i_sb,1 );/* * We've secured consistency through sync_fs. Following pino @@ -2548,7 +2548,7 @@ int f2fs_do_shutdown(struct f2fs_sb_info *sbi, unsigned int flag,break ;case F2FS_GOING_DOWN_METASYNC :/* do checkpoint only */ - ret =f2fs_sync_fs (sb,1 ); + ret =__f2fs_sync_fs (sb,1 );if (ret) {if (ret == -EIO ) ret =0 ;@@ -2568,7 +2568,7 @@ int f2fs_do_shutdown(struct f2fs_sb_info *sbi, unsigned int flag,set_sbi_flag (sbi,SBI_CP_DISABLED_QUICK );set_sbi_flag (sbi,SBI_IS_DIRTY );/* do checkpoint only */ - ret =f2fs_sync_fs (sb,1 ); + ret =__f2fs_sync_fs (sb,1 );if (ret == -EIO ) ret =0 ; goto out;@@ -2988,7 +2988,7 @@ static int f2fs_ioc_write_checkpoint(struct file *filp)if (ret)return ret; - ret =f2fs_sync_fs (sbi->sb,1 ); + ret =__f2fs_sync_fs (sbi->sb,1 );mnt_drop_write_file (filp);return ret;fs/f2fs/namei.c +8
-8@@ -403,7 +403,7 @@ static int f2fs_create(struct mnt_idmap *idmap, struct inode *dir,d_instantiate_new (dentry, inode);if (IS_DIRSYNC (dir)) { - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (err)return err; }@@ -459,7 +459,7 @@ static int f2fs_link(struct dentry *old_dentry, struct inode *dir,d_instantiate (dentry, inode);if (IS_DIRSYNC (dir)) { - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (err)return err; }@@ -641,7 +641,7 @@ static int f2fs_unlink(struct inode *dir, struct dentry *dentry)d_invalidate (dentry);if (IS_DIRSYNC (dir)) - err =f2fs_sync_fs (F2FS_I_SB (dir)->sb,1 ); + err =__f2fs_sync_fs (F2FS_I_SB (dir)->sb,1 ); out:trace_f2fs_unlink_exit (d_inode (dentry), err);return err;@@ -729,7 +729,7 @@ static int f2fs_symlink(struct mnt_idmap *idmap, struct inode *dir, ret =filemap_write_and_wait_range (inode->i_mapping,0 , disk_link.len -1 );if (!ret &&IS_DIRSYNC (dir)) - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );f2fs_balance_fs (sbi, true); out:@@ -787,7 +787,7 @@ static struct dentry *f2fs_mkdir(struct mnt_idmap *idmap, struct inode *dir,d_instantiate_new (dentry, inode);if (IS_DIRSYNC (dir)) { - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (err)return ERR_PTR (err); }@@ -845,7 +845,7 @@ static int f2fs_mknod(struct mnt_idmap *idmap, struct inode *dir,d_instantiate_new (dentry, inode);if (IS_DIRSYNC (dir)) { - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (err)return err; }@@ -1148,7 +1148,7 @@ static int f2fs_rename(struct mnt_idmap *idmap, struct inode *old_dir,f2fs_unlock_op (sbi, &lc);if (IS_DIRSYNC (old_dir) ||IS_DIRSYNC (new_dir)) { - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (err)return err; }@@ -1318,7 +1318,7 @@ static int f2fs_cross_rename(struct inode *old_dir, struct dentry *old_dentry,f2fs_unlock_op (sbi, &lc);if (IS_DIRSYNC (old_dir) ||IS_DIRSYNC (new_dir)) { - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (err)return err; }fs/f2fs/segment.c +2
-2@@ -550,7 +550,7 @@ void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi, bool from_bg)mutex_unlock (&sbi->flush_lock); }stat_inc_cp_call_count (sbi,BACKGROUND ); -f2fs_sync_fs (sbi->sb,1 ); +__f2fs_sync_fs (sbi->sb,1 ); } static int __submit_flush_wait(struct f2fs_sb_info *sbi,@@ -3478,7 +3478,7 @@ int f2fs_allocate_pinning_section(struct f2fs_sb_info *sbi) true, ZONED_PIN_SEC_REQUIRED_COUNT, true);if (err)return err; - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (!err) { gc_required = false; goto retry;fs/f2fs/super.c +1
-1@@ -2131,7 +2131,7 @@ static void f2fs_put_super(struct super_block *sb) } } -int f2fs_sync_fs (struct super_block *sb,int sync) +int __f2fs_sync_fs (struct super_block *sb,int sync) {struct f2fs_sb_info *sbi =F2FS_SB (sb);int err =0 ;fs/f2fs/super.c int f2fs_sync_fs(struct super_block *sb, int sync) · line 2161
Quoted 8 lines
fs/f2fs/super.c +5
-0@@ -2154,6 +2154,25 @@ int f2fs_sync_fs(struct super_block *sb, int sync)return err; } +static int f2fs_sync_fs (struct super_block *sb,int sync) +{ +struct f2fs_sb_info *sbi =F2FS_SB (sb); +bool freeze_sync = sync && + sb->s_writers.frozen ==SB_FREEZE_PAGEFAULT ;How about this to make sure
freeze_syncwill only be true infreeze_super()?Quoted 5 lines
bool
freeze_sync= sync &&rwsem_is_locked(&sb->s_umount)&&sb->s_writers.frozen == SB_FREEZE_PAGEFAULT;And it's not needed to rename
f2fs_sync_fs()to__f2fs_sync_fs()?Sorry for the late reply.
rwsem_is_locked()doesn't tell us whether current owns the lock, so I'm concerned about the following race:
Quoted 7 lines
Freezer A Directory fsync B
holdss_umountwrite lock
stage =SB_FREEZE_PAGEFAULT
holder =current_A
locksgc_lock
holder =current_Bwaits forgc_lock
Oh, right, fsync won't call sb_start_*().
One more question, if we set holder under gc_lock, will it resolve this race case?
Thanks,
Quoted 18 lines
holder !=
current_As_umountread trylock fails
retry limit ->QUOTA_SKIP_FLUSH
setsQUOTA_NEED_FLUSH
commits CP withquota_need_fsck
clearsIS_DIRTY
unlocksgc_lock
holder = NULL
stage =SB_FREEZE_FSlocks gc_lock !IS_DIRTY && CP_SYNC -> returns before quota flush unlocks gc_lock holder = NULLcompletes
f2fs_freeze()
unlockss_umount
FIFREEZE returns
Quoted 44 lines
Could we use a separate
f2fs_sync_fs_super()wrapper for the VFS callback and keep freeze holder management there, leavingf2fs_sync_fs()for internal callers?Thanks,
Quoted 38 lines
Thanks,
Quoted 35 lines
fs/f2fs/super.c +16
-2+int err; + +/* freeze_super() holds s_umount for write during this sync pass. */ +if (freeze_sync) + sbi->umount_lock_holder = current; + + err =__f2fs_sync_fs (sb, sync); + +if (freeze_sync) + sbi->umount_lock_holder =NULL ; + +return err; +} +static int f2fs_freeze (struct super_block *sb) {struct f2fs_sb_info *sbi =F2FS_SB (sb);@@ -2807,7 +2826,7 @@ static int f2fs_enable_checkpoint(struct f2fs_sb_info *sbi)set_sbi_flag (sbi,SBI_IS_DIRTY );f2fs_up_write_trace (&sbi->gc_lock, &lc); - ret =f2fs_sync_fs (sbi->sb,1 ); + ret =__f2fs_sync_fs (sbi->sb,1 );if (ret)f2fs_err (sbi,"%s sync_fs failed, ret: %d" , __func__, ret);@@ -2993,7 +3012,7 @@ static int __f2fs_remount(struct fs_context *fc, struct super_block *sb)set_sbi_flag (sbi,SBI_IS_DIRTY );set_sbi_flag (sbi,SBI_IS_CLOSE ); - err =f2fs_sync_fs (sb,1 ); + err =__f2fs_sync_fs (sb,1 );if (err) goto restore_gc;clear_sbi_flag (sbi,SBI_IS_CLOSE );
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 239 lines · Chao Yu <[email protected]> 于2026年9月16日周三 09:59写道:
Quoted 229 lines · Jianan Huang
Quoted 219 lines · Chao Yu <[email protected]> 于2026年9月9日周三 19:43写道:
Quoted 206 lines · Jianan Huang
Quota flush retries can be exhausted during filesystem freeze.
freeze_super()and the quota checkpoint may race as below.
freeze_super()f2fs_ckpt
-down_write(&sb->s_umount)
-sb->s_writers.frozen=SB_FREEZE_PAGEFAULT
-sync_filesystem()
-f2fs_sync_fs()
-f2fs_issue_checkpoint()
- queueCP_SYNC-----------------> -block_operations()
-down_read_trylock(s_umount): fails; freeze holds write lock
- quota flush retries exhausted
- setCP_QUOTA_NEED_FSCK_FLAGDuring the PAGEFAULT sync pass,
freeze_super()holdss_umountfor write, butumount_lock_holderis not set untilf2fs_freeze(). Thus quota writeback tries to acquires_umountagain and can exhaust retries.With checkpoint merge enabled,
f2fs_issue_checkpoint()may dispatchCP_SYNCtof2fs_ckpt. That thread also cannot acquire the freeze lock.Split the F2FS-internal sync implementation from the super-operation callback. For the VFS PAGEFAULT freeze sync, record current as holder around the internal sync. This lets quota writeback use the existing lock and makes
CP_SYNCrun directly in the freeze caller.Convert F2FS-internal callers to the internal helper so they cannot be mistaken for the freeze owner while the filesystem is frozen.
Fixes eb85c2410d6f ("f2fs: quota: fix to avoid warning in dquot_writeback_dquots()")Signed-off-by Jianan Huang <[email protected]>--- fs/f2fs/f2fs.h | 2 +- fs/f2fs/file.c | 8 ++++---- fs/f2fs/namei.c | 16 ++++++++-------- fs/f2fs/segment.c | 4 ++-- fs/f2fs/super.c | 25 ++++++++++++++++++++++--- 5 files changed, 37 insertions(+), 18 deletions(-)fs/f2fs/f2fs.h +1
-1@@ -3977,7 +3977,7 @@ void f2fs_quota_off_umount(struct super_block *sb);void f2fs_save_errors (struct f2fs_sb_info *sbi,unsigned char flag);void f2fs_handle_error (struct f2fs_sb_info *sbi,unsigned char error);int f2fs_commit_super (struct f2fs_sb_info *sbi,bool recover); -int f2fs_sync_fs (struct super_block *sb,int sync); +int __f2fs_sync_fs (struct super_block *sb,int sync);int f2fs_sanity_check_ckpt (struct f2fs_sb_info *sbi);/* fs/f2fs/file.c +4
-4@@ -408,7 +408,7 @@ static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end,if (cp_reason) {/* all the dirty node pages should be flushed for POR */ - ret =f2fs_sync_fs (inode->i_sb,1 ); + ret =__f2fs_sync_fs (inode->i_sb,1 );/* * We've secured consistency through sync_fs. Following pino @@ -2548,7 +2548,7 @@ int f2fs_do_shutdown(struct f2fs_sb_info *sbi, unsigned int flag,break ;case F2FS_GOING_DOWN_METASYNC :/* do checkpoint only */ - ret =f2fs_sync_fs (sb,1 ); + ret =__f2fs_sync_fs (sb,1 );if (ret) {if (ret == -EIO ) ret =0 ;@@ -2568,7 +2568,7 @@ int f2fs_do_shutdown(struct f2fs_sb_info *sbi, unsigned int flag,set_sbi_flag (sbi,SBI_CP_DISABLED_QUICK );set_sbi_flag (sbi,SBI_IS_DIRTY );/* do checkpoint only */ - ret =f2fs_sync_fs (sb,1 ); + ret =__f2fs_sync_fs (sb,1 );if (ret == -EIO ) ret =0 ; goto out;@@ -2988,7 +2988,7 @@ static int f2fs_ioc_write_checkpoint(struct file *filp)if (ret)return ret; - ret =f2fs_sync_fs (sbi->sb,1 ); + ret =__f2fs_sync_fs (sbi->sb,1 );mnt_drop_write_file (filp);return ret;fs/f2fs/namei.c +8
-8@@ -403,7 +403,7 @@ static int f2fs_create(struct mnt_idmap *idmap, struct inode *dir,d_instantiate_new (dentry, inode);if (IS_DIRSYNC (dir)) { - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (err)return err; }@@ -459,7 +459,7 @@ static int f2fs_link(struct dentry *old_dentry, struct inode *dir,d_instantiate (dentry, inode);if (IS_DIRSYNC (dir)) { - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (err)return err; }@@ -641,7 +641,7 @@ static int f2fs_unlink(struct inode *dir, struct dentry *dentry)d_invalidate (dentry);if (IS_DIRSYNC (dir)) - err =f2fs_sync_fs (F2FS_I_SB (dir)->sb,1 ); + err =__f2fs_sync_fs (F2FS_I_SB (dir)->sb,1 ); out:trace_f2fs_unlink_exit (d_inode (dentry), err);return err;@@ -729,7 +729,7 @@ static int f2fs_symlink(struct mnt_idmap *idmap, struct inode *dir, ret =filemap_write_and_wait_range (inode->i_mapping,0 , disk_link.len -1 );if (!ret &&IS_DIRSYNC (dir)) - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );f2fs_balance_fs (sbi, true); out:@@ -787,7 +787,7 @@ static struct dentry *f2fs_mkdir(struct mnt_idmap *idmap, struct inode *dir,d_instantiate_new (dentry, inode);if (IS_DIRSYNC (dir)) { - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (err)return ERR_PTR (err); }@@ -845,7 +845,7 @@ static int f2fs_mknod(struct mnt_idmap *idmap, struct inode *dir,d_instantiate_new (dentry, inode);if (IS_DIRSYNC (dir)) { - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (err)return err; }@@ -1148,7 +1148,7 @@ static int f2fs_rename(struct mnt_idmap *idmap, struct inode *old_dir,f2fs_unlock_op (sbi, &lc);if (IS_DIRSYNC (old_dir) ||IS_DIRSYNC (new_dir)) { - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (err)return err; }@@ -1318,7 +1318,7 @@ static int f2fs_cross_rename(struct inode *old_dir, struct dentry *old_dentry,f2fs_unlock_op (sbi, &lc);if (IS_DIRSYNC (old_dir) ||IS_DIRSYNC (new_dir)) { - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (err)return err; }fs/f2fs/segment.c +2
-2@@ -550,7 +550,7 @@ void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi, bool from_bg)mutex_unlock (&sbi->flush_lock); }stat_inc_cp_call_count (sbi,BACKGROUND ); -f2fs_sync_fs (sbi->sb,1 ); +__f2fs_sync_fs (sbi->sb,1 ); } static int __submit_flush_wait(struct f2fs_sb_info *sbi,@@ -3478,7 +3478,7 @@ int f2fs_allocate_pinning_section(struct f2fs_sb_info *sbi) true, ZONED_PIN_SEC_REQUIRED_COUNT, true);if (err)return err; - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (!err) { gc_required = false; goto retry;fs/f2fs/super.c +1
-1@@ -2131,7 +2131,7 @@ static void f2fs_put_super(struct super_block *sb) } } -int f2fs_sync_fs (struct super_block *sb,int sync) +int __f2fs_sync_fs (struct super_block *sb,int sync) {struct f2fs_sb_info *sbi =F2FS_SB (sb);int err =0 ;fs/f2fs/super.c int f2fs_sync_fs(struct super_block *sb, int sync) · line 2161
Quoted 8 lines
fs/f2fs/super.c +5
-0@@ -2154,6 +2154,25 @@ int f2fs_sync_fs(struct super_block *sb, int sync)return err; } +static int f2fs_sync_fs (struct super_block *sb,int sync) +{ +struct f2fs_sb_info *sbi =F2FS_SB (sb); +bool freeze_sync = sync && + sb->s_writers.frozen ==SB_FREEZE_PAGEFAULT ;How about this to make sure
freeze_syncwill only be true infreeze_super()?Quoted 5 lines
bool
freeze_sync= sync &&rwsem_is_locked(&sb->s_umount)&&sb->s_writers.frozen == SB_FREEZE_PAGEFAULT;And it's not needed to rename
f2fs_sync_fs()to__f2fs_sync_fs()?Sorry for the late reply.
rwsem_is_locked()doesn't tell us whether current owns the lock, so I'm concerned about the following race:Quoted 7 lines
Freezer A Directory fsync B
holdss_umountwrite lock
stage =SB_FREEZE_PAGEFAULT
holder =current_A
locksgc_lock
holder =current_Bwaits forgc_lock
Quoted 4 lines
Oh, right, fsync won't call sb_start_*().
One more question, if we set holder under
gc_lock, will it resolve this race case?
Setting holder under gc_lock prevents the overwrite race, but a later checkpoint, even from a direct fsync, may outlive the freezer's s_umount write lock:
Freezer A Fsync task / checkpoint worker B
holds s_umount for write
finishes its own checkpoint
acquires gc_lock
sees SB_FREEZE_PAGEFAULT sets holder = current B computes need_lock = false
freeze may fails on dirty check
without waiting for B
releases s_umount
runs quota sync without s_umount
So I think we still need to identify whether the current task actually holds s_umount.
Thanks,
Quoted 65 lines
Thanks,
Quoted 62 lines
holder !=
current_As_umountread trylock fails
retry limit ->QUOTA_SKIP_FLUSH
setsQUOTA_NEED_FLUSH
commits CP withquota_need_fsck
clearsIS_DIRTY
unlocksgc_lock
holder = NULL
stage =SB_FREEZE_FSlocks gc_lock !IS_DIRTY && CP_SYNC -> returns before quota flush unlocks gc_lock holder = NULLcompletes
f2fs_freeze()
unlockss_umount
FIFREEZE returnsCould we use a separate
f2fs_sync_fs_super()wrapper for the VFS callback and keep freeze holder management there, leavingf2fs_sync_fs()for internal callers?Thanks,
Quoted 38 lines
Thanks,
Quoted 35 lines
fs/f2fs/super.c +16
-2+int err; + +/* freeze_super() holds s_umount for write during this sync pass. */ +if (freeze_sync) + sbi->umount_lock_holder = current; + + err =__f2fs_sync_fs (sb, sync); + +if (freeze_sync) + sbi->umount_lock_holder =NULL ; + +return err; +} +static int f2fs_freeze (struct super_block *sb) {struct f2fs_sb_info *sbi =F2FS_SB (sb);@@ -2807,7 +2826,7 @@ static int f2fs_enable_checkpoint(struct f2fs_sb_info *sbi)set_sbi_flag (sbi,SBI_IS_DIRTY );f2fs_up_write_trace (&sbi->gc_lock, &lc); - ret =f2fs_sync_fs (sbi->sb,1 ); + ret =__f2fs_sync_fs (sbi->sb,1 );if (ret)f2fs_err (sbi,"%s sync_fs failed, ret: %d" , __func__, ret);@@ -2993,7 +3012,7 @@ static int __f2fs_remount(struct fs_context *fc, struct super_block *sb)set_sbi_flag (sbi,SBI_IS_DIRTY );set_sbi_flag (sbi,SBI_IS_CLOSE ); - err =f2fs_sync_fs (sb,1 ); + err =__f2fs_sync_fs (sb,1 );if (err) goto restore_gc;clear_sbi_flag (sbi,SBI_IS_CLOSE );
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Sorry for the delay.
Quoted 249 lines · Jianan Huang
Quoted 239 lines · Chao Yu <[email protected]> 于2026年9月16日周三 09:59写道:
Quoted 229 lines · Jianan Huang
Quoted 219 lines · Chao Yu <[email protected]> 于2026年9月9日周三 19:43写道:
Quoted 206 lines · Jianan Huang
Quota flush retries can be exhausted during filesystem freeze.
freeze_super()and the quota checkpoint may race as below.
freeze_super()f2fs_ckpt
-down_write(&sb->s_umount)
-sb->s_writers.frozen=SB_FREEZE_PAGEFAULT
-sync_filesystem()
-f2fs_sync_fs()
-f2fs_issue_checkpoint()
- queueCP_SYNC-----------------> -block_operations()
-down_read_trylock(s_umount): fails; freeze holds write lock
- quota flush retries exhausted
- setCP_QUOTA_NEED_FSCK_FLAGDuring the PAGEFAULT sync pass,
freeze_super()holdss_umountfor write, butumount_lock_holderis not set untilf2fs_freeze(). Thus quota writeback tries to acquires_umountagain and can exhaust retries.With checkpoint merge enabled,
f2fs_issue_checkpoint()may dispatchCP_SYNCtof2fs_ckpt. That thread also cannot acquire the freeze lock.Split the F2FS-internal sync implementation from the super-operation callback. For the VFS PAGEFAULT freeze sync, record current as holder around the internal sync. This lets quota writeback use the existing lock and makes
CP_SYNCrun directly in the freeze caller.Convert F2FS-internal callers to the internal helper so they cannot be mistaken for the freeze owner while the filesystem is frozen.
Fixes eb85c2410d6f ("f2fs: quota: fix to avoid warning in dquot_writeback_dquots()")Signed-off-by Jianan Huang <[email protected]>--- fs/f2fs/f2fs.h | 2 +- fs/f2fs/file.c | 8 ++++---- fs/f2fs/namei.c | 16 ++++++++-------- fs/f2fs/segment.c | 4 ++-- fs/f2fs/super.c | 25 ++++++++++++++++++++++--- 5 files changed, 37 insertions(+), 18 deletions(-)fs/f2fs/f2fs.h +1
-1@@ -3977,7 +3977,7 @@ void f2fs_quota_off_umount(struct super_block *sb);void f2fs_save_errors (struct f2fs_sb_info *sbi,unsigned char flag);void f2fs_handle_error (struct f2fs_sb_info *sbi,unsigned char error);int f2fs_commit_super (struct f2fs_sb_info *sbi,bool recover); -int f2fs_sync_fs (struct super_block *sb,int sync); +int __f2fs_sync_fs (struct super_block *sb,int sync);int f2fs_sanity_check_ckpt (struct f2fs_sb_info *sbi);/* fs/f2fs/file.c +4
-4@@ -408,7 +408,7 @@ static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end,if (cp_reason) {/* all the dirty node pages should be flushed for POR */ - ret =f2fs_sync_fs (inode->i_sb,1 ); + ret =__f2fs_sync_fs (inode->i_sb,1 );/* * We've secured consistency through sync_fs. Following pino @@ -2548,7 +2548,7 @@ int f2fs_do_shutdown(struct f2fs_sb_info *sbi, unsigned int flag,break ;case F2FS_GOING_DOWN_METASYNC :/* do checkpoint only */ - ret =f2fs_sync_fs (sb,1 ); + ret =__f2fs_sync_fs (sb,1 );if (ret) {if (ret == -EIO ) ret =0 ;@@ -2568,7 +2568,7 @@ int f2fs_do_shutdown(struct f2fs_sb_info *sbi, unsigned int flag,set_sbi_flag (sbi,SBI_CP_DISABLED_QUICK );set_sbi_flag (sbi,SBI_IS_DIRTY );/* do checkpoint only */ - ret =f2fs_sync_fs (sb,1 ); + ret =__f2fs_sync_fs (sb,1 );if (ret == -EIO ) ret =0 ; goto out;@@ -2988,7 +2988,7 @@ static int f2fs_ioc_write_checkpoint(struct file *filp)if (ret)return ret; - ret =f2fs_sync_fs (sbi->sb,1 ); + ret =__f2fs_sync_fs (sbi->sb,1 );mnt_drop_write_file (filp);return ret;fs/f2fs/namei.c +8
-8@@ -403,7 +403,7 @@ static int f2fs_create(struct mnt_idmap *idmap, struct inode *dir,d_instantiate_new (dentry, inode);if (IS_DIRSYNC (dir)) { - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (err)return err; }@@ -459,7 +459,7 @@ static int f2fs_link(struct dentry *old_dentry, struct inode *dir,d_instantiate (dentry, inode);if (IS_DIRSYNC (dir)) { - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (err)return err; }@@ -641,7 +641,7 @@ static int f2fs_unlink(struct inode *dir, struct dentry *dentry)d_invalidate (dentry);if (IS_DIRSYNC (dir)) - err =f2fs_sync_fs (F2FS_I_SB (dir)->sb,1 ); + err =__f2fs_sync_fs (F2FS_I_SB (dir)->sb,1 ); out:trace_f2fs_unlink_exit (d_inode (dentry), err);return err;@@ -729,7 +729,7 @@ static int f2fs_symlink(struct mnt_idmap *idmap, struct inode *dir, ret =filemap_write_and_wait_range (inode->i_mapping,0 , disk_link.len -1 );if (!ret &&IS_DIRSYNC (dir)) - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );f2fs_balance_fs (sbi, true); out:@@ -787,7 +787,7 @@ static struct dentry *f2fs_mkdir(struct mnt_idmap *idmap, struct inode *dir,d_instantiate_new (dentry, inode);if (IS_DIRSYNC (dir)) { - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (err)return ERR_PTR (err); }@@ -845,7 +845,7 @@ static int f2fs_mknod(struct mnt_idmap *idmap, struct inode *dir,d_instantiate_new (dentry, inode);if (IS_DIRSYNC (dir)) { - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (err)return err; }@@ -1148,7 +1148,7 @@ static int f2fs_rename(struct mnt_idmap *idmap, struct inode *old_dir,f2fs_unlock_op (sbi, &lc);if (IS_DIRSYNC (old_dir) ||IS_DIRSYNC (new_dir)) { - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (err)return err; }@@ -1318,7 +1318,7 @@ static int f2fs_cross_rename(struct inode *old_dir, struct dentry *old_dentry,f2fs_unlock_op (sbi, &lc);if (IS_DIRSYNC (old_dir) ||IS_DIRSYNC (new_dir)) { - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (err)return err; }fs/f2fs/segment.c +2
-2@@ -550,7 +550,7 @@ void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi, bool from_bg)mutex_unlock (&sbi->flush_lock); }stat_inc_cp_call_count (sbi,BACKGROUND ); -f2fs_sync_fs (sbi->sb,1 ); +__f2fs_sync_fs (sbi->sb,1 ); } static int __submit_flush_wait(struct f2fs_sb_info *sbi,@@ -3478,7 +3478,7 @@ int f2fs_allocate_pinning_section(struct f2fs_sb_info *sbi) true, ZONED_PIN_SEC_REQUIRED_COUNT, true);if (err)return err; - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (!err) { gc_required = false; goto retry;fs/f2fs/super.c +1
-1@@ -2131,7 +2131,7 @@ static void f2fs_put_super(struct super_block *sb) } } -int f2fs_sync_fs (struct super_block *sb,int sync) +int __f2fs_sync_fs (struct super_block *sb,int sync) {struct f2fs_sb_info *sbi =F2FS_SB (sb);int err =0 ;fs/f2fs/super.c int f2fs_sync_fs(struct super_block *sb, int sync) · line 2161
Quoted 8 lines
fs/f2fs/super.c +5
-0@@ -2154,6 +2154,25 @@ int f2fs_sync_fs(struct super_block *sb, int sync)return err; } +static int f2fs_sync_fs (struct super_block *sb,int sync) +{ +struct f2fs_sb_info *sbi =F2FS_SB (sb); +bool freeze_sync = sync && + sb->s_writers.frozen ==SB_FREEZE_PAGEFAULT ;How about this to make sure
freeze_syncwill only be true infreeze_super()?Quoted 5 lines
bool
freeze_sync= sync &&rwsem_is_locked(&sb->s_umount)&&sb->s_writers.frozen == SB_FREEZE_PAGEFAULT;And it's not needed to rename
f2fs_sync_fs()to__f2fs_sync_fs()?Sorry for the late reply.
rwsem_is_locked()doesn't tell us whether current owns the lock, so I'm concerned about the following race:Quoted 7 lines
Freezer A Directory fsync B
holdss_umountwrite lock
stage =SB_FREEZE_PAGEFAULT
holder =current_A
locksgc_lock
holder =current_Bwaits forgc_lockQuoted 4 lines
Oh, right, fsync won't call sb_start_*().
One more question, if we set holder under
gc_lock, will it resolve this race case?Setting holder under
gc_lockprevents the overwrite race, but a later checkpoint, even from a direct fsync, may outlive the freezer'ss_umountwrite lock:
Quoted 11 lines
Freezer A Fsync task / checkpoint worker B
holdss_umountfor write
finishes its own checkpoint
acquiresgc_lock
seesSB_FREEZE_PAGEFAULTsets holder = current B computesneed_lock= false
freeze may fails on dirty check
without waiting for B
releasess_umount
runs quota sync withouts_umount
Thanks for correcting.
Quoted 3 lines
So I think we still need to identify whether the current task actually holds
s_umount.
Yes, I agreed.
Thanks,
Quoted 68 lines
Thanks,
Quoted 65 lines
Thanks,
Quoted 62 lines
holder !=
current_As_umountread trylock fails
retry limit ->QUOTA_SKIP_FLUSH
setsQUOTA_NEED_FLUSH
commits CP withquota_need_fsck
clearsIS_DIRTY
unlocksgc_lock
holder = NULL
stage =SB_FREEZE_FSlocks gc_lock !IS_DIRTY && CP_SYNC -> returns before quota flush unlocks gc_lock holder = NULLcompletes
f2fs_freeze()
unlockss_umount
FIFREEZE returnsCould we use a separate
f2fs_sync_fs_super()wrapper for the VFS callback and keep freeze holder management there, leavingf2fs_sync_fs()for internal callers?Thanks,
Quoted 38 lines
Thanks,
Quoted 35 lines
fs/f2fs/super.c +16
-2+int err; + +/* freeze_super() holds s_umount for write during this sync pass. */ +if (freeze_sync) + sbi->umount_lock_holder = current; + + err =__f2fs_sync_fs (sb, sync); + +if (freeze_sync) + sbi->umount_lock_holder =NULL ; + +return err; +} +static int f2fs_freeze (struct super_block *sb) {struct f2fs_sb_info *sbi =F2FS_SB (sb);@@ -2807,7 +2826,7 @@ static int f2fs_enable_checkpoint(struct f2fs_sb_info *sbi)set_sbi_flag (sbi,SBI_IS_DIRTY );f2fs_up_write_trace (&sbi->gc_lock, &lc); - ret =f2fs_sync_fs (sbi->sb,1 ); + ret =__f2fs_sync_fs (sbi->sb,1 );if (ret)f2fs_err (sbi,"%s sync_fs failed, ret: %d" , __func__, ret);@@ -2993,7 +3012,7 @@ static int __f2fs_remount(struct fs_context *fc, struct super_block *sb)set_sbi_flag (sbi,SBI_IS_DIRTY );set_sbi_flag (sbi,SBI_IS_CLOSE ); - err =f2fs_sync_fs (sb,1 ); + err =__f2fs_sync_fs (sb,1 );if (err) goto restore_gc;clear_sbi_flag (sbi,SBI_IS_CLOSE );
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 265 lines · Chao Yu <[email protected]> 于2026年10月11日周日 19:58写道:
Sorry for the delay.
Quoted 249 lines · Jianan Huang
Quoted 239 lines · Chao Yu <[email protected]> 于2026年9月16日周三 09:59写道:
Quoted 229 lines · Jianan Huang
Quoted 219 lines · Chao Yu <[email protected]> 于2026年9月9日周三 19:43写道:
Quoted 206 lines · Jianan Huang
Quota flush retries can be exhausted during filesystem freeze.
freeze_super()and the quota checkpoint may race as below.
freeze_super()f2fs_ckpt
-down_write(&sb->s_umount)
-sb->s_writers.frozen=SB_FREEZE_PAGEFAULT
-sync_filesystem()
-f2fs_sync_fs()
-f2fs_issue_checkpoint()
- queueCP_SYNC-----------------> -block_operations()
-down_read_trylock(s_umount): fails; freeze holds write lock
- quota flush retries exhausted
- setCP_QUOTA_NEED_FSCK_FLAGDuring the PAGEFAULT sync pass,
freeze_super()holdss_umountfor write, butumount_lock_holderis not set untilf2fs_freeze(). Thus quota writeback tries to acquires_umountagain and can exhaust retries.With checkpoint merge enabled,
f2fs_issue_checkpoint()may dispatchCP_SYNCtof2fs_ckpt. That thread also cannot acquire the freeze lock.Split the F2FS-internal sync implementation from the super-operation callback. For the VFS PAGEFAULT freeze sync, record current as holder around the internal sync. This lets quota writeback use the existing lock and makes
CP_SYNCrun directly in the freeze caller.Convert F2FS-internal callers to the internal helper so they cannot be mistaken for the freeze owner while the filesystem is frozen.
Fixes eb85c2410d6f ("f2fs: quota: fix to avoid warning in dquot_writeback_dquots()")Signed-off-by Jianan Huang <[email protected]>--- fs/f2fs/f2fs.h | 2 +- fs/f2fs/file.c | 8 ++++---- fs/f2fs/namei.c | 16 ++++++++-------- fs/f2fs/segment.c | 4 ++-- fs/f2fs/super.c | 25 ++++++++++++++++++++++--- 5 files changed, 37 insertions(+), 18 deletions(-)fs/f2fs/f2fs.h +1
-1@@ -3977,7 +3977,7 @@ void f2fs_quota_off_umount(struct super_block *sb);void f2fs_save_errors (struct f2fs_sb_info *sbi,unsigned char flag);void f2fs_handle_error (struct f2fs_sb_info *sbi,unsigned char error);int f2fs_commit_super (struct f2fs_sb_info *sbi,bool recover); -int f2fs_sync_fs (struct super_block *sb,int sync); +int __f2fs_sync_fs (struct super_block *sb,int sync);int f2fs_sanity_check_ckpt (struct f2fs_sb_info *sbi);/* fs/f2fs/file.c +4
-4@@ -408,7 +408,7 @@ static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end,if (cp_reason) {/* all the dirty node pages should be flushed for POR */ - ret =f2fs_sync_fs (inode->i_sb,1 ); + ret =__f2fs_sync_fs (inode->i_sb,1 );/* * We've secured consistency through sync_fs. Following pino @@ -2548,7 +2548,7 @@ int f2fs_do_shutdown(struct f2fs_sb_info *sbi, unsigned int flag,break ;case F2FS_GOING_DOWN_METASYNC :/* do checkpoint only */ - ret =f2fs_sync_fs (sb,1 ); + ret =__f2fs_sync_fs (sb,1 );if (ret) {if (ret == -EIO ) ret =0 ;@@ -2568,7 +2568,7 @@ int f2fs_do_shutdown(struct f2fs_sb_info *sbi, unsigned int flag,set_sbi_flag (sbi,SBI_CP_DISABLED_QUICK );set_sbi_flag (sbi,SBI_IS_DIRTY );/* do checkpoint only */ - ret =f2fs_sync_fs (sb,1 ); + ret =__f2fs_sync_fs (sb,1 );if (ret == -EIO ) ret =0 ; goto out;@@ -2988,7 +2988,7 @@ static int f2fs_ioc_write_checkpoint(struct file *filp)if (ret)return ret; - ret =f2fs_sync_fs (sbi->sb,1 ); + ret =__f2fs_sync_fs (sbi->sb,1 );mnt_drop_write_file (filp);return ret;fs/f2fs/namei.c +8
-8@@ -403,7 +403,7 @@ static int f2fs_create(struct mnt_idmap *idmap, struct inode *dir,d_instantiate_new (dentry, inode);if (IS_DIRSYNC (dir)) { - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (err)return err; }@@ -459,7 +459,7 @@ static int f2fs_link(struct dentry *old_dentry, struct inode *dir,d_instantiate (dentry, inode);if (IS_DIRSYNC (dir)) { - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (err)return err; }@@ -641,7 +641,7 @@ static int f2fs_unlink(struct inode *dir, struct dentry *dentry)d_invalidate (dentry);if (IS_DIRSYNC (dir)) - err =f2fs_sync_fs (F2FS_I_SB (dir)->sb,1 ); + err =__f2fs_sync_fs (F2FS_I_SB (dir)->sb,1 ); out:trace_f2fs_unlink_exit (d_inode (dentry), err);return err;@@ -729,7 +729,7 @@ static int f2fs_symlink(struct mnt_idmap *idmap, struct inode *dir, ret =filemap_write_and_wait_range (inode->i_mapping,0 , disk_link.len -1 );if (!ret &&IS_DIRSYNC (dir)) - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );f2fs_balance_fs (sbi, true); out:@@ -787,7 +787,7 @@ static struct dentry *f2fs_mkdir(struct mnt_idmap *idmap, struct inode *dir,d_instantiate_new (dentry, inode);if (IS_DIRSYNC (dir)) { - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (err)return ERR_PTR (err); }@@ -845,7 +845,7 @@ static int f2fs_mknod(struct mnt_idmap *idmap, struct inode *dir,d_instantiate_new (dentry, inode);if (IS_DIRSYNC (dir)) { - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (err)return err; }@@ -1148,7 +1148,7 @@ static int f2fs_rename(struct mnt_idmap *idmap, struct inode *old_dir,f2fs_unlock_op (sbi, &lc);if (IS_DIRSYNC (old_dir) ||IS_DIRSYNC (new_dir)) { - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (err)return err; }@@ -1318,7 +1318,7 @@ static int f2fs_cross_rename(struct inode *old_dir, struct dentry *old_dentry,f2fs_unlock_op (sbi, &lc);if (IS_DIRSYNC (old_dir) ||IS_DIRSYNC (new_dir)) { - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (err)return err; }fs/f2fs/segment.c +2
-2@@ -550,7 +550,7 @@ void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi, bool from_bg)mutex_unlock (&sbi->flush_lock); }stat_inc_cp_call_count (sbi,BACKGROUND ); -f2fs_sync_fs (sbi->sb,1 ); +__f2fs_sync_fs (sbi->sb,1 ); } static int __submit_flush_wait(struct f2fs_sb_info *sbi,@@ -3478,7 +3478,7 @@ int f2fs_allocate_pinning_section(struct f2fs_sb_info *sbi) true, ZONED_PIN_SEC_REQUIRED_COUNT, true);if (err)return err; - err =f2fs_sync_fs (sbi->sb,1 ); + err =__f2fs_sync_fs (sbi->sb,1 );if (!err) { gc_required = false; goto retry;fs/f2fs/super.c +1
-1@@ -2131,7 +2131,7 @@ static void f2fs_put_super(struct super_block *sb) } } -int f2fs_sync_fs (struct super_block *sb,int sync) +int __f2fs_sync_fs (struct super_block *sb,int sync) {struct f2fs_sb_info *sbi =F2FS_SB (sb);int err =0 ;fs/f2fs/super.c int f2fs_sync_fs(struct super_block *sb, int sync) · line 2161
Quoted 8 lines
fs/f2fs/super.c +5
-0@@ -2154,6 +2154,25 @@ int f2fs_sync_fs(struct super_block *sb, int sync)return err; } +static int f2fs_sync_fs (struct super_block *sb,int sync) +{ +struct f2fs_sb_info *sbi =F2FS_SB (sb); +bool freeze_sync = sync && + sb->s_writers.frozen ==SB_FREEZE_PAGEFAULT ;How about this to make sure
freeze_syncwill only be true infreeze_super()?Quoted 5 lines
bool
freeze_sync= sync &&rwsem_is_locked(&sb->s_umount)&&sb->s_writers.frozen == SB_FREEZE_PAGEFAULT;And it's not needed to rename
f2fs_sync_fs()to__f2fs_sync_fs()?Sorry for the late reply.
rwsem_is_locked()doesn't tell us whether current owns the lock, so I'm concerned about the following race:Quoted 7 lines
Freezer A Directory fsync B
holdss_umountwrite lock
stage =SB_FREEZE_PAGEFAULT
holder =current_A
locksgc_lock
holder =current_Bwaits forgc_lockQuoted 4 lines
Oh, right, fsync won't call sb_start_*().
One more question, if we set holder under
gc_lock, will it resolve this race case?Setting holder under
gc_lockprevents the overwrite race, but a later checkpoint, even from a direct fsync, may outlive the freezer'ss_umountwrite lock:Quoted 11 lines
Freezer A Fsync task / checkpoint worker B
holdss_umountfor write
finishes its own checkpoint
acquiresgc_lock
seesSB_FREEZE_PAGEFAULTsets holder = current B computesneed_lock= false
freeze may fails on dirty check
without waiting for B
releasess_umount
runs quota sync withouts_umount
Quoted 8 lines
Thanks for correcting.
Quoted 3 lines
So I think we still need to identify whether the current task actually holds
s_umount.Yes, I agreed.
I've sent v2, using a separate function to avoid renaming f2fs_sync_fs().
Thanks,
Quoted 72 lines
Thanks,
Quoted 68 lines
Thanks,
Quoted 65 lines
Thanks,
Quoted 62 lines
holder !=
current_As_umountread trylock fails
retry limit ->QUOTA_SKIP_FLUSH
setsQUOTA_NEED_FLUSH
commits CP withquota_need_fsck
clearsIS_DIRTY
unlocksgc_lock
holder = NULL
stage =SB_FREEZE_FSlocks gc_lock !IS_DIRTY && CP_SYNC -> returns before quota flush unlocks gc_lock holder = NULLcompletes
f2fs_freeze()
unlockss_umount
FIFREEZE returnsCould we use a separate
f2fs_sync_fs_super()wrapper for the VFS callback and keep freeze holder management there, leavingf2fs_sync_fs()for internal callers?Thanks,
Quoted 38 lines
Thanks,
Quoted 35 lines
fs/f2fs/super.c +16
-2+int err; + +/* freeze_super() holds s_umount for write during this sync pass. */ +if (freeze_sync) + sbi->umount_lock_holder = current; + + err =__f2fs_sync_fs (sb, sync); + +if (freeze_sync) + sbi->umount_lock_holder =NULL ; + +return err; +} +static int f2fs_freeze (struct super_block *sb) {struct f2fs_sb_info *sbi =F2FS_SB (sb);@@ -2807,7 +2826,7 @@ static int f2fs_enable_checkpoint(struct f2fs_sb_info *sbi)set_sbi_flag (sbi,SBI_IS_DIRTY );f2fs_up_write_trace (&sbi->gc_lock, &lc); - ret =f2fs_sync_fs (sbi->sb,1 ); + ret =__f2fs_sync_fs (sbi->sb,1 );if (ret)f2fs_err (sbi,"%s sync_fs failed, ret: %d" , __func__, ret);@@ -2993,7 +3012,7 @@ static int __f2fs_remount(struct fs_context *fc, struct super_block *sb)set_sbi_flag (sbi,SBI_IS_DIRTY );set_sbi_flag (sbi,SBI_IS_CLOSE ); - err =f2fs_sync_fs (sb,1 ); + err =__f2fs_sync_fs (sb,1 );if (err) goto restore_gc;clear_sbi_flag (sbi,SBI_IS_CLOSE );
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel