Skip to content

Commit 0035b84

Browse files
Jaegeuk Kimgregkh
authored andcommitted
f2fs: flush pending checkpoints when freezing super
commit c7b5857 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>
1 parent ab49589 commit 0035b84

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

fs/f2fs/checkpoint.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1892,15 +1892,27 @@ int f2fs_start_ckpt_thread(struct f2fs_sb_info *sbi)
18921892
void f2fs_stop_ckpt_thread(struct f2fs_sb_info *sbi)
18931893
{
18941894
struct ckpt_req_control *cprc = &sbi->cprc_info;
1895+
struct task_struct *ckpt_task;
18951896

1896-
if (cprc->f2fs_issue_ckpt) {
1897-
struct task_struct *ckpt_task = cprc->f2fs_issue_ckpt;
1897+
if (!cprc->f2fs_issue_ckpt)
1898+
return;
18981899

1899-
cprc->f2fs_issue_ckpt = NULL;
1900-
kthread_stop(ckpt_task);
1900+
ckpt_task = cprc->f2fs_issue_ckpt;
1901+
cprc->f2fs_issue_ckpt = NULL;
1902+
kthread_stop(ckpt_task);
19011903

1902-
flush_remained_ckpt_reqs(sbi, NULL);
1903-
}
1904+
f2fs_flush_ckpt_thread(sbi);
1905+
}
1906+
1907+
void f2fs_flush_ckpt_thread(struct f2fs_sb_info *sbi)
1908+
{
1909+
struct ckpt_req_control *cprc = &sbi->cprc_info;
1910+
1911+
flush_remained_ckpt_reqs(sbi, NULL);
1912+
1913+
/* Let's wait for the previous dispatched checkpoint. */
1914+
while (atomic_read(&cprc->queued_ckpt))
1915+
io_schedule_timeout(DEFAULT_IO_TIMEOUT);
19041916
}
19051917

19061918
void f2fs_init_ckpt_req_control(struct f2fs_sb_info *sbi)

fs/f2fs/f2fs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3540,6 +3540,7 @@ unsigned int f2fs_usable_blks_in_seg(struct f2fs_sb_info *sbi,
35403540
* checkpoint.c
35413541
*/
35423542
void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io);
3543+
void f2fs_flush_ckpt_thread(struct f2fs_sb_info *sbi);
35433544
struct page *f2fs_grab_meta_page(struct f2fs_sb_info *sbi, pgoff_t index);
35443545
struct page *f2fs_get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index);
35453546
struct page *f2fs_get_meta_page_retry(struct f2fs_sb_info *sbi, pgoff_t index);

fs/f2fs/super.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,9 +1661,8 @@ static int f2fs_freeze(struct super_block *sb)
16611661
if (is_sbi_flag_set(F2FS_SB(sb), SBI_IS_DIRTY))
16621662
return -EINVAL;
16631663

1664-
/* ensure no checkpoint required */
1665-
if (!llist_empty(&F2FS_SB(sb)->cprc_info.issue_list))
1666-
return -EINVAL;
1664+
/* Let's flush checkpoints and stop the thread. */
1665+
f2fs_flush_ckpt_thread(F2FS_SB(sb));
16671666

16681667
/* to avoid deadlock on f2fs_evict_inode->SB_FREEZE_FS */
16691668
set_sbi_flag(F2FS_SB(sb), SBI_IS_FREEZING);

0 commit comments

Comments
 (0)