diff options
author | Jaegeuk Kim <jaegeuk@kernel.org> | 2021-08-19 14:00:57 -0700 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2021-09-15 10:02:32 +0200 |
commit | 889008de3ea2b84aaa9bf354d55fe2d032b60167 (patch) | |
tree | d8080142a818e0b4920e7bf98d9021c29553cb2e | |
parent | 307726060e64273627b6a77020eb479ba420f1b1 (diff) | |
download | linux-stable-889008de3ea2b84aaa9bf354d55fe2d032b60167.tar.gz linux-stable-889008de3ea2b84aaa9bf354d55fe2d032b60167.tar.bz2 linux-stable-889008de3ea2b84aaa9bf354d55fe2d032b60167.zip |
f2fs: guarantee to write dirty data when enabling checkpoint back
commit dddd3d65293a52c2c3850c19b1e5115712e534d8 upstream.
We must flush all the dirty data when enabling checkpoint back. Let's guarantee
that first by adding a retry logic on sync_inodes_sb(). In addition to that,
this patch adds to flush data in fsync when checkpoint is disabled, which can
mitigate the sync_inodes_sb() failures in advance.
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | fs/f2fs/file.c | 5 | ||||
-rw-r--r-- | fs/f2fs/super.c | 11 |
2 files changed, 12 insertions, 4 deletions
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 6afd4562335f..97d48c5bdebc 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -261,8 +261,7 @@ static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end, }; unsigned int seq_id = 0; - if (unlikely(f2fs_readonly(inode->i_sb) || - is_sbi_flag_set(sbi, SBI_CP_DISABLED))) + if (unlikely(f2fs_readonly(inode->i_sb))) return 0; trace_f2fs_sync_file_enter(inode); @@ -276,7 +275,7 @@ static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end, ret = file_write_and_wait_range(file, start, end); clear_inode_flag(inode, FI_NEED_IPU); - if (ret) { + if (ret || is_sbi_flag_set(sbi, SBI_CP_DISABLED)) { trace_f2fs_sync_file_exit(inode, cp_reason, datasync, ret); return ret; } diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 8fecd3050ccd..ce703e6fdafc 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -2039,8 +2039,17 @@ restore_flag: static void f2fs_enable_checkpoint(struct f2fs_sb_info *sbi) { + int retry = DEFAULT_RETRY_IO_COUNT; + /* we should flush all the data to keep data consistency */ - sync_inodes_sb(sbi->sb); + do { + sync_inodes_sb(sbi->sb); + cond_resched(); + congestion_wait(BLK_RW_ASYNC, DEFAULT_IO_TIMEOUT); + } while (get_pages(sbi, F2FS_DIRTY_DATA) && retry--); + + if (unlikely(retry < 0)) + f2fs_warn(sbi, "checkpoint=enable has some unwritten data."); down_write(&sbi->gc_lock); f2fs_dirty_to_prefree(sbi); |