btrfs: convert btrfs_decompress() to take a folio
authorLi Zetao <lizetao1@huawei.com>
Wed, 28 Aug 2024 18:29:07 +0000 (02:29 +0800)
committerDavid Sterba <dsterba@suse.com>
Tue, 10 Sep 2024 14:51:21 +0000 (16:51 +0200)
The old page API is being gradually replaced and converted to use folio
to improve code readability and avoid repeated conversion between page
and folio. Based on the previous patch, the compression path can be
directly used in folio without converting to page.

Signed-off-by: Li Zetao <lizetao1@huawei.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/compression.c
fs/btrfs/compression.h
fs/btrfs/inode.c
fs/btrfs/reflink.c

index a5f7cbe1c06ed26fee839509d69540e8082aa121..90aef2627ca27b104e9929a1b384c35348ed103b 100644 (file)
@@ -138,15 +138,15 @@ static int compression_decompress_bio(struct list_head *ws,
 }
 
 static int compression_decompress(int type, struct list_head *ws,
-               const u8 *data_in, struct page *dest_page,
+               const u8 *data_in, struct folio *dest_folio,
                unsigned long dest_pgoff, size_t srclen, size_t destlen)
 {
        switch (type) {
-       case BTRFS_COMPRESS_ZLIB: return zlib_decompress(ws, data_in, page_folio(dest_page),
+       case BTRFS_COMPRESS_ZLIB: return zlib_decompress(ws, data_in, dest_folio,
                                                dest_pgoff, srclen, destlen);
-       case BTRFS_COMPRESS_LZO:  return lzo_decompress(ws, data_in, page_folio(dest_page),
+       case BTRFS_COMPRESS_LZO:  return lzo_decompress(ws, data_in, dest_folio,
                                                dest_pgoff, srclen, destlen);
-       case BTRFS_COMPRESS_ZSTD: return zstd_decompress(ws, data_in, page_folio(dest_page),
+       case BTRFS_COMPRESS_ZSTD: return zstd_decompress(ws, data_in, dest_folio,
                                                dest_pgoff, srclen, destlen);
        case BTRFS_COMPRESS_NONE:
        default:
@@ -1061,10 +1061,10 @@ static int btrfs_decompress_bio(struct compressed_bio *cb)
  * single page, and we want to read a single page out of it.
  * start_byte tells us the offset into the compressed data we're interested in
  */
-int btrfs_decompress(int type, const u8 *data_in, struct page *dest_page,
+int btrfs_decompress(int type, const u8 *data_in, struct folio *dest_folio,
                     unsigned long dest_pgoff, size_t srclen, size_t destlen)
 {
-       struct btrfs_fs_info *fs_info = page_to_fs_info(dest_page);
+       struct btrfs_fs_info *fs_info = folio_to_fs_info(dest_folio);
        struct list_head *workspace;
        const u32 sectorsize = fs_info->sectorsize;
        int ret;
@@ -1077,7 +1077,7 @@ int btrfs_decompress(int type, const u8 *data_in, struct page *dest_page,
        ASSERT(dest_pgoff + destlen <= PAGE_SIZE && destlen <= sectorsize);
 
        workspace = get_workspace(type, 0);
-       ret = compression_decompress(type, workspace, data_in, dest_page,
+       ret = compression_decompress(type, workspace, data_in, dest_folio,
                                     dest_pgoff, srclen, destlen);
        put_workspace(type, workspace);
 
index d2453cf28eef8ec43dd75f31533b9290e9036211..b6563b6a333e5d31b93c65c9fe2cdaf57d67a68f 100644 (file)
@@ -96,7 +96,7 @@ void __cold btrfs_exit_compress(void);
 int btrfs_compress_folios(unsigned int type_level, struct address_space *mapping,
                          u64 start, struct folio **folios, unsigned long *out_folios,
                         unsigned long *total_in, unsigned long *total_out);
-int btrfs_decompress(int type, const u8 *data_in, struct page *dest_page,
+int btrfs_decompress(int type, const u8 *data_in, struct folio *dest_folio,
                     unsigned long start_byte, size_t srclen, size_t destlen);
 int btrfs_decompress_buf2page(const char *buf, u32 buf_len,
                              struct compressed_bio *cb, u32 decompressed);
index 1483e33127b7729789ea77438bfc7b52f2cd783d..edac499fd83d29181f8374b4f505cd177ded7018 100644 (file)
@@ -6746,7 +6746,7 @@ static noinline int uncompress_inline(struct btrfs_path *path,
        read_extent_buffer(leaf, tmp, ptr, inline_size);
 
        max_size = min_t(unsigned long, PAGE_SIZE, max_size);
-       ret = btrfs_decompress(compress_type, tmp, &folio->page, 0, inline_size,
+       ret = btrfs_decompress(compress_type, tmp, folio, 0, inline_size,
                               max_size);
 
        /*
index df6b93b927cd8587545f7d2f9b5486302d06976b..b768e590a44c224250320bbe3ddcd7bda6aab023 100644 (file)
@@ -118,7 +118,7 @@ static int copy_inline_to_page(struct btrfs_inode *inode,
                memcpy_to_page(page, offset_in_page(file_offset), data_start,
                               datal);
        } else {
-               ret = btrfs_decompress(comp_type, data_start, page,
+               ret = btrfs_decompress(comp_type, data_start, page_folio(page),
                                       offset_in_page(file_offset),
                                       inline_size, datal);
                if (ret)