]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-5.0/f2fs-sync-filesystem-after-roll-forward-recovery.patch
autosel patches for 5.0
[thirdparty/kernel/stable-queue.git] / queue-5.0 / f2fs-sync-filesystem-after-roll-forward-recovery.patch
1 From bd2207694b9f0780eabf985b9f1d2a73ce0a3721 Mon Sep 17 00:00:00 2001
2 From: Jaegeuk Kim <jaegeuk@kernel.org>
3 Date: Tue, 22 Jan 2019 14:04:33 -0800
4 Subject: f2fs: sync filesystem after roll-forward recovery
5
6 [ Upstream commit 812a95977fd2f0d1f220c716a98a7f22e22f488d ]
7
8 Some works after roll-forward recovery can get an error which will release
9 all the data structures. Let's flush them in order to make it clean.
10
11 One possible corruption came from:
12
13 [ 90.400500] list_del corruption. prev->next should be ffffffed1f566208, but was (null)
14 [ 90.675349] Call trace:
15 [ 90.677869] __list_del_entry_valid+0x94/0xb4
16 [ 90.682351] remove_dirty_inode+0xac/0x114
17 [ 90.686563] __f2fs_write_data_pages+0x6a8/0x6c8
18 [ 90.691302] f2fs_write_data_pages+0x40/0x4c
19 [ 90.695695] do_writepages+0x80/0xf0
20 [ 90.699372] __writeback_single_inode+0xdc/0x4ac
21 [ 90.704113] writeback_sb_inodes+0x280/0x440
22 [ 90.708501] wb_writeback+0x1b8/0x3d0
23 [ 90.712267] wb_workfn+0x1a8/0x4d4
24 [ 90.715765] process_one_work+0x1c0/0x3d4
25 [ 90.719883] worker_thread+0x224/0x344
26 [ 90.723739] kthread+0x120/0x130
27 [ 90.727055] ret_from_fork+0x10/0x18
28
29 Reported-by: Sahitya Tummala <stummala@codeaurora.org>
30 Reviewed-by: Chao Yu <yuchao0@huawei.com>
31 Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
32 Signed-off-by: Sasha Levin <sashal@kernel.org>
33 ---
34 fs/f2fs/checkpoint.c | 5 +++--
35 fs/f2fs/node.c | 4 +++-
36 fs/f2fs/super.c | 44 +++++++++++++++++++++++++++++++++-----------
37 3 files changed, 39 insertions(+), 14 deletions(-)
38
39 diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c
40 index f955cd3e0677..ccccf0ce2f06 100644
41 --- a/fs/f2fs/checkpoint.c
42 +++ b/fs/f2fs/checkpoint.c
43 @@ -306,8 +306,9 @@ static int f2fs_write_meta_pages(struct address_space *mapping,
44 goto skip_write;
45
46 /* collect a number of dirty meta pages and write together */
47 - if (wbc->for_kupdate ||
48 - get_pages(sbi, F2FS_DIRTY_META) < nr_pages_to_skip(sbi, META))
49 + if (wbc->sync_mode != WB_SYNC_ALL &&
50 + get_pages(sbi, F2FS_DIRTY_META) <
51 + nr_pages_to_skip(sbi, META))
52 goto skip_write;
53
54 /* if locked failed, cp will flush dirty pages instead */
55 diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
56 index 4f450e573312..f6ff84e29749 100644
57 --- a/fs/f2fs/node.c
58 +++ b/fs/f2fs/node.c
59 @@ -1920,7 +1920,9 @@ static int f2fs_write_node_pages(struct address_space *mapping,
60 f2fs_balance_fs_bg(sbi);
61
62 /* collect a number of dirty node pages and write together */
63 - if (get_pages(sbi, F2FS_DIRTY_NODES) < nr_pages_to_skip(sbi, NODE))
64 + if (wbc->sync_mode != WB_SYNC_ALL &&
65 + get_pages(sbi, F2FS_DIRTY_NODES) <
66 + nr_pages_to_skip(sbi, NODE))
67 goto skip_write;
68
69 if (wbc->sync_mode == WB_SYNC_ALL)
70 diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
71 index 5892fa3c885f..144ffba3ec5a 100644
72 --- a/fs/f2fs/super.c
73 +++ b/fs/f2fs/super.c
74 @@ -1460,9 +1460,16 @@ static int f2fs_enable_quotas(struct super_block *sb);
75
76 static int f2fs_disable_checkpoint(struct f2fs_sb_info *sbi)
77 {
78 + unsigned int s_flags = sbi->sb->s_flags;
79 struct cp_control cpc;
80 - int err;
81 + int err = 0;
82 + int ret;
83
84 + if (s_flags & SB_RDONLY) {
85 + f2fs_msg(sbi->sb, KERN_ERR,
86 + "checkpoint=disable on readonly fs");
87 + return -EINVAL;
88 + }
89 sbi->sb->s_flags |= SB_ACTIVE;
90
91 f2fs_update_time(sbi, DISABLE_TIME);
92 @@ -1470,18 +1477,24 @@ static int f2fs_disable_checkpoint(struct f2fs_sb_info *sbi)
93 while (!f2fs_time_over(sbi, DISABLE_TIME)) {
94 mutex_lock(&sbi->gc_mutex);
95 err = f2fs_gc(sbi, true, false, NULL_SEGNO);
96 - if (err == -ENODATA)
97 + if (err == -ENODATA) {
98 + err = 0;
99 break;
100 + }
101 if (err && err != -EAGAIN)
102 - return err;
103 + break;
104 }
105
106 - err = sync_filesystem(sbi->sb);
107 - if (err)
108 - return err;
109 + ret = sync_filesystem(sbi->sb);
110 + if (ret || err) {
111 + err = ret ? ret: err;
112 + goto restore_flag;
113 + }
114
115 - if (f2fs_disable_cp_again(sbi))
116 - return -EAGAIN;
117 + if (f2fs_disable_cp_again(sbi)) {
118 + err = -EAGAIN;
119 + goto restore_flag;
120 + }
121
122 mutex_lock(&sbi->gc_mutex);
123 cpc.reason = CP_PAUSE;
124 @@ -1490,7 +1503,9 @@ static int f2fs_disable_checkpoint(struct f2fs_sb_info *sbi)
125
126 sbi->unusable_block_count = 0;
127 mutex_unlock(&sbi->gc_mutex);
128 - return 0;
129 +restore_flag:
130 + sbi->sb->s_flags = s_flags; /* Restore MS_RDONLY status */
131 + return err;
132 }
133
134 static void f2fs_enable_checkpoint(struct f2fs_sb_info *sbi)
135 @@ -3359,7 +3374,7 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
136 if (test_opt(sbi, DISABLE_CHECKPOINT)) {
137 err = f2fs_disable_checkpoint(sbi);
138 if (err)
139 - goto free_meta;
140 + goto sync_free_meta;
141 } else if (is_set_ckpt_flags(sbi, CP_DISABLED_FLAG)) {
142 f2fs_enable_checkpoint(sbi);
143 }
144 @@ -3372,7 +3387,7 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
145 /* After POR, we can run background GC thread.*/
146 err = f2fs_start_gc_thread(sbi);
147 if (err)
148 - goto free_meta;
149 + goto sync_free_meta;
150 }
151 kvfree(options);
152
153 @@ -3394,6 +3409,11 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
154 f2fs_update_time(sbi, REQ_TIME);
155 return 0;
156
157 +sync_free_meta:
158 + /* safe to flush all the data */
159 + sync_filesystem(sbi->sb);
160 + retry = false;
161 +
162 free_meta:
163 #ifdef CONFIG_QUOTA
164 f2fs_truncate_quota_inode_pages(sb);
165 @@ -3407,6 +3427,8 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
166 * falls into an infinite loop in f2fs_sync_meta_pages().
167 */
168 truncate_inode_pages_final(META_MAPPING(sbi));
169 + /* evict some inodes being cached by GC */
170 + evict_inodes(sb);
171 f2fs_unregister_sysfs(sbi);
172 free_root_inode:
173 dput(sb->s_root);
174 --
175 2.19.1
176