]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/6.7.11/f2fs-compress-fix-to-guarantee-persisting-compressed.patch
Linux 6.8.2
[thirdparty/kernel/stable-queue.git] / releases / 6.7.11 / f2fs-compress-fix-to-guarantee-persisting-compressed.patch
1 From 3e3ee6cccced10ac4c60085aa4bf0788660e0d61 Mon Sep 17 00:00:00 2001
2 From: Sasha Levin <sashal@kernel.org>
3 Date: Sat, 13 Jan 2024 03:41:27 +0800
4 Subject: f2fs: compress: fix to guarantee persisting compressed blocks by CP
5
6 From: Chao Yu <chao@kernel.org>
7
8 [ Upstream commit 8a430dd49e9cb021372b0ad91e60aeef9c6ced00 ]
9
10 If data block in compressed cluster is not persisted with metadata
11 during checkpoint, after SPOR, the data may be corrupted, let's
12 guarantee to write compressed page by checkpoint.
13
14 Fixes: 4c8ff7095bef ("f2fs: support data compression")
15 Reviewed-by: Daeho Jeong <daehojeong@google.com>
16 Signed-off-by: Chao Yu <chao@kernel.org>
17 Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
18 Signed-off-by: Sasha Levin <sashal@kernel.org>
19 ---
20 fs/f2fs/compress.c | 4 +++-
21 fs/f2fs/data.c | 17 +++++++++--------
22 fs/f2fs/f2fs.h | 4 +++-
23 3 files changed, 15 insertions(+), 10 deletions(-)
24
25 diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c
26 index 62119f3f7206d..8453a06630208 100644
27 --- a/fs/f2fs/compress.c
28 +++ b/fs/f2fs/compress.c
29 @@ -1420,6 +1420,8 @@ void f2fs_compress_write_end_io(struct bio *bio, struct page *page)
30 struct f2fs_sb_info *sbi = bio->bi_private;
31 struct compress_io_ctx *cic =
32 (struct compress_io_ctx *)page_private(page);
33 + enum count_type type = WB_DATA_TYPE(page,
34 + f2fs_is_compressed_page(page));
35 int i;
36
37 if (unlikely(bio->bi_status))
38 @@ -1427,7 +1429,7 @@ void f2fs_compress_write_end_io(struct bio *bio, struct page *page)
39
40 f2fs_compress_free_page(page);
41
42 - dec_page_count(sbi, F2FS_WB_DATA);
43 + dec_page_count(sbi, type);
44
45 if (atomic_dec_return(&cic->pending_pages))
46 return;
47 diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
48 index bc3f05d43b624..4b0c2ceb5dbfd 100644
49 --- a/fs/f2fs/data.c
50 +++ b/fs/f2fs/data.c
51 @@ -48,7 +48,7 @@ void f2fs_destroy_bioset(void)
52 bioset_exit(&f2fs_bioset);
53 }
54
55 -static bool __is_cp_guaranteed(struct page *page)
56 +bool f2fs_is_cp_guaranteed(struct page *page)
57 {
58 struct address_space *mapping = page->mapping;
59 struct inode *inode;
60 @@ -65,8 +65,6 @@ static bool __is_cp_guaranteed(struct page *page)
61 S_ISDIR(inode->i_mode))
62 return true;
63
64 - if (f2fs_is_compressed_page(page))
65 - return false;
66 if ((S_ISREG(inode->i_mode) && IS_NOQUOTA(inode)) ||
67 page_private_gcing(page))
68 return true;
69 @@ -338,7 +336,7 @@ static void f2fs_write_end_io(struct bio *bio)
70
71 bio_for_each_segment_all(bvec, bio, iter_all) {
72 struct page *page = bvec->bv_page;
73 - enum count_type type = WB_DATA_TYPE(page);
74 + enum count_type type = WB_DATA_TYPE(page, false);
75
76 if (page_private_dummy(page)) {
77 clear_page_private_dummy(page);
78 @@ -762,7 +760,7 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio)
79 wbc_account_cgroup_owner(fio->io_wbc, fio->page, PAGE_SIZE);
80
81 inc_page_count(fio->sbi, is_read_io(fio->op) ?
82 - __read_io_type(page) : WB_DATA_TYPE(fio->page));
83 + __read_io_type(page) : WB_DATA_TYPE(fio->page, false));
84
85 if (is_read_io(bio_op(bio)))
86 f2fs_submit_read_bio(fio->sbi, bio, fio->type);
87 @@ -973,7 +971,7 @@ int f2fs_merge_page_bio(struct f2fs_io_info *fio)
88 if (fio->io_wbc)
89 wbc_account_cgroup_owner(fio->io_wbc, fio->page, PAGE_SIZE);
90
91 - inc_page_count(fio->sbi, WB_DATA_TYPE(page));
92 + inc_page_count(fio->sbi, WB_DATA_TYPE(page, false));
93
94 *fio->last_block = fio->new_blkaddr;
95 *fio->bio = bio;
96 @@ -1007,6 +1005,7 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio)
97 enum page_type btype = PAGE_TYPE_OF_BIO(fio->type);
98 struct f2fs_bio_info *io = sbi->write_io[btype] + fio->temp;
99 struct page *bio_page;
100 + enum count_type type;
101
102 f2fs_bug_on(sbi, is_read_io(fio->op));
103
104 @@ -1046,7 +1045,8 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio)
105 /* set submitted = true as a return value */
106 fio->submitted = 1;
107
108 - inc_page_count(sbi, WB_DATA_TYPE(bio_page));
109 + type = WB_DATA_TYPE(bio_page, fio->compressed_page);
110 + inc_page_count(sbi, type);
111
112 if (io->bio &&
113 (!io_is_mergeable(sbi, io->bio, io, fio, io->last_block_in_bio,
114 @@ -1059,7 +1059,8 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio)
115 if (F2FS_IO_ALIGNED(sbi) &&
116 (fio->type == DATA || fio->type == NODE) &&
117 fio->new_blkaddr & F2FS_IO_SIZE_MASK(sbi)) {
118 - dec_page_count(sbi, WB_DATA_TYPE(bio_page));
119 + dec_page_count(sbi, WB_DATA_TYPE(bio_page,
120 + fio->compressed_page));
121 fio->retry = 1;
122 goto skip;
123 }
124 diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
125 index 46ad7604a8b62..2f899d54d1837 100644
126 --- a/fs/f2fs/f2fs.h
127 +++ b/fs/f2fs/f2fs.h
128 @@ -1075,7 +1075,8 @@ struct f2fs_sm_info {
129 * f2fs monitors the number of several block types such as on-writeback,
130 * dirty dentry blocks, dirty node blocks, and dirty meta blocks.
131 */
132 -#define WB_DATA_TYPE(p) (__is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA)
133 +#define WB_DATA_TYPE(p, f) \
134 + (f || f2fs_is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA)
135 enum count_type {
136 F2FS_DIRTY_DENTS,
137 F2FS_DIRTY_DATA,
138 @@ -3797,6 +3798,7 @@ void f2fs_init_ckpt_req_control(struct f2fs_sb_info *sbi);
139 */
140 int __init f2fs_init_bioset(void);
141 void f2fs_destroy_bioset(void);
142 +bool f2fs_is_cp_guaranteed(struct page *page);
143 int f2fs_init_bio_entry_cache(void);
144 void f2fs_destroy_bio_entry_cache(void);
145 void f2fs_submit_read_bio(struct f2fs_sb_info *sbi, struct bio *bio,
146 --
147 2.43.0
148