]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
f2fs: compress: fix to assign cc.cluster_idx correctly
authorChao Yu <yuchao0@huawei.com>
Mon, 10 May 2021 09:30:32 +0000 (17:30 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 19 May 2021 08:56:39 +0000 (10:56 +0200)
[ Upstream commit 8bfbfb0ddd706b1ce2e89259ecc45f192c0ec2bf ]

In f2fs_destroy_compress_ctx(), after f2fs_destroy_compress_ctx(),
cc.cluster_idx will be cleared w/ NULL_CLUSTER, f2fs_cluster_blocks()
may check wrong cluster metadata, fix it.

Fixes: 4c8ff7095bef ("f2fs: support data compression")
Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/f2fs/compress.c
fs/f2fs/data.c
fs/f2fs/f2fs.h

index b7ab3bdf2259113893b8676ed28b799d5376520f..66dd525a85542090cbfd24ee6f8fb675f1846be8 100644 (file)
@@ -151,13 +151,14 @@ int f2fs_init_compress_ctx(struct compress_ctx *cc)
        return cc->rpages ? 0 : -ENOMEM;
 }
 
-void f2fs_destroy_compress_ctx(struct compress_ctx *cc)
+void f2fs_destroy_compress_ctx(struct compress_ctx *cc, bool reuse)
 {
        page_array_free(cc->inode, cc->rpages, cc->cluster_size);
        cc->rpages = NULL;
        cc->nr_rpages = 0;
        cc->nr_cpages = 0;
-       cc->cluster_idx = NULL_CLUSTER;
+       if (!reuse)
+               cc->cluster_idx = NULL_CLUSTER;
 }
 
 void f2fs_compress_ctx_add_page(struct compress_ctx *cc, struct page *page)
@@ -1046,7 +1047,7 @@ retry:
                ret = f2fs_read_multi_pages(cc, &bio, cc->cluster_size,
                                        &last_block_in_bio, false, true);
                f2fs_put_rpages(cc);
-               f2fs_destroy_compress_ctx(cc);
+               f2fs_destroy_compress_ctx(cc, true);
                if (ret)
                        goto out;
                if (bio)
@@ -1073,7 +1074,7 @@ retry:
 release_and_retry:
                        f2fs_put_rpages(cc);
                        f2fs_unlock_rpages(cc, i + 1);
-                       f2fs_destroy_compress_ctx(cc);
+                       f2fs_destroy_compress_ctx(cc, true);
                        goto retry;
                }
        }
@@ -1106,7 +1107,7 @@ release_and_retry:
 unlock_pages:
        f2fs_put_rpages(cc);
        f2fs_unlock_rpages(cc, i);
-       f2fs_destroy_compress_ctx(cc);
+       f2fs_destroy_compress_ctx(cc, true);
 out:
        return ret;
 }
@@ -1142,7 +1143,7 @@ bool f2fs_compress_write_end(struct inode *inode, void *fsdata,
                set_cluster_dirty(&cc);
 
        f2fs_put_rpages_wbc(&cc, NULL, false, 1);
-       f2fs_destroy_compress_ctx(&cc);
+       f2fs_destroy_compress_ctx(&cc, false);
 
        return first_index;
 }
@@ -1361,7 +1362,7 @@ unlock_continue:
        f2fs_put_rpages(cc);
        page_array_free(cc->inode, cc->cpages, cc->nr_cpages);
        cc->cpages = NULL;
-       f2fs_destroy_compress_ctx(cc);
+       f2fs_destroy_compress_ctx(cc, false);
        return 0;
 
 out_destroy_crypt:
@@ -1523,7 +1524,7 @@ write:
        err = f2fs_write_raw_pages(cc, submitted, wbc, io_type);
        f2fs_put_rpages_wbc(cc, wbc, false, 0);
 destroy_out:
-       f2fs_destroy_compress_ctx(cc);
+       f2fs_destroy_compress_ctx(cc, false);
        return err;
 }
 
index 4e5257c763d014dc7490cf89cee10c1ce1bb536a..8804a5d51380196b6b0de7e5f6b1c5b9e6894ff0 100644 (file)
@@ -2276,7 +2276,7 @@ static int f2fs_mpage_readpages(struct inode *inode,
                                                        max_nr_pages,
                                                        &last_block_in_bio,
                                                        rac != NULL, false);
-                               f2fs_destroy_compress_ctx(&cc);
+                               f2fs_destroy_compress_ctx(&cc, false);
                                if (ret)
                                        goto set_error_page;
                        }
@@ -2321,7 +2321,7 @@ next_page:
                                                        max_nr_pages,
                                                        &last_block_in_bio,
                                                        rac != NULL, false);
-                               f2fs_destroy_compress_ctx(&cc);
+                               f2fs_destroy_compress_ctx(&cc, false);
                        }
                }
 #endif
@@ -3022,7 +3022,7 @@ next:
                }
        }
        if (f2fs_compressed_file(inode))
-               f2fs_destroy_compress_ctx(&cc);
+               f2fs_destroy_compress_ctx(&cc, false);
 #endif
        if (retry) {
                index = 0;
index eaf6f62206de3dd0b6a3a19440d8095fcb0eeeff..f3fabb1edfe970e520799f5422ec9b2cf00bc001 100644 (file)
@@ -3950,7 +3950,7 @@ struct decompress_io_ctx *f2fs_alloc_dic(struct compress_ctx *cc);
 void f2fs_decompress_end_io(struct decompress_io_ctx *dic, bool failed);
 void f2fs_put_page_dic(struct page *page);
 int f2fs_init_compress_ctx(struct compress_ctx *cc);
-void f2fs_destroy_compress_ctx(struct compress_ctx *cc);
+void f2fs_destroy_compress_ctx(struct compress_ctx *cc, bool reuse);
 void f2fs_init_compress_info(struct f2fs_sb_info *sbi);
 int f2fs_init_page_array_cache(struct f2fs_sb_info *sbi);
 void f2fs_destroy_page_array_cache(struct f2fs_sb_info *sbi);