]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
f2fs: flush pending checkpoints when freezing super
authorJaegeuk Kim <jaegeuk@kernel.org>
Fri, 19 Aug 2022 22:52:02 +0000 (15:52 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 24 Oct 2022 07:56:53 +0000 (09:56 +0200)
commit c7b58576370147833999fd4cc874d0f918bdf9ca upstream.

This avoids -EINVAL when trying to freeze f2fs.

Cc: stable@vger.kernel.org
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/f2fs/checkpoint.c
fs/f2fs/f2fs.h
fs/f2fs/super.c

index 6d8b2bf14de0fd86a07e9cffd6e381868517725a..5f96eb4cc363dd6dc2a24279408c8b9dac906bcd 100644 (file)
@@ -1894,15 +1894,27 @@ int f2fs_start_ckpt_thread(struct f2fs_sb_info *sbi)
 void f2fs_stop_ckpt_thread(struct f2fs_sb_info *sbi)
 {
        struct ckpt_req_control *cprc = &sbi->cprc_info;
+       struct task_struct *ckpt_task;
 
-       if (cprc->f2fs_issue_ckpt) {
-               struct task_struct *ckpt_task = cprc->f2fs_issue_ckpt;
+       if (!cprc->f2fs_issue_ckpt)
+               return;
 
-               cprc->f2fs_issue_ckpt = NULL;
-               kthread_stop(ckpt_task);
+       ckpt_task = cprc->f2fs_issue_ckpt;
+       cprc->f2fs_issue_ckpt = NULL;
+       kthread_stop(ckpt_task);
 
-               flush_remained_ckpt_reqs(sbi, NULL);
-       }
+       f2fs_flush_ckpt_thread(sbi);
+}
+
+void f2fs_flush_ckpt_thread(struct f2fs_sb_info *sbi)
+{
+       struct ckpt_req_control *cprc = &sbi->cprc_info;
+
+       flush_remained_ckpt_reqs(sbi, NULL);
+
+       /* Let's wait for the previous dispatched checkpoint. */
+       while (atomic_read(&cprc->queued_ckpt))
+               io_schedule_timeout(DEFAULT_IO_TIMEOUT);
 }
 
 void f2fs_init_ckpt_req_control(struct f2fs_sb_info *sbi)
index 7006fa7dd5cb813a726d719df5ec527a11a8927f..698a8ff1b4802749db28da100180219153a8f066 100644 (file)
@@ -3676,6 +3676,7 @@ static inline bool f2fs_need_rand_seg(struct f2fs_sb_info *sbi)
  * checkpoint.c
  */
 void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io);
+void f2fs_flush_ckpt_thread(struct f2fs_sb_info *sbi);
 struct page *f2fs_grab_meta_page(struct f2fs_sb_info *sbi, pgoff_t index);
 struct page *f2fs_get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index);
 struct page *f2fs_get_meta_page_retry(struct f2fs_sb_info *sbi, pgoff_t index);
index bc4a7ee16af986c4b2ec171cb00161bdb0b824ab..5aaa91665ac19269047739c166d6a3ce7780c5c6 100644 (file)
@@ -1637,9 +1637,8 @@ static int f2fs_freeze(struct super_block *sb)
        if (is_sbi_flag_set(F2FS_SB(sb), SBI_IS_DIRTY))
                return -EINVAL;
 
-       /* ensure no checkpoint required */
-       if (!llist_empty(&F2FS_SB(sb)->cprc_info.issue_list))
-               return -EINVAL;
+       /* Let's flush checkpoints and stop the thread. */
+       f2fs_flush_ckpt_thread(F2FS_SB(sb));
 
        /* to avoid deadlock on f2fs_evict_inode->SB_FREEZE_FS */
        set_sbi_flag(F2FS_SB(sb), SBI_IS_FREEZING);