]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
btrfs: pass btrfs_inode pointer directly into btrfs_compress_folios()
authorQu Wenruo <wqu@suse.com>
Sun, 10 Aug 2025 10:44:57 +0000 (20:14 +0930)
committerDavid Sterba <dsterba@suse.com>
Mon, 22 Sep 2025 08:54:31 +0000 (10:54 +0200)
For the 3 supported compression algorithms, two of them (zstd and zlib)
are already grabbing the btrfs inode for error messages.

It's more common to pass btrfs_inode and grab the address space from it.

Reviewed-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: Qu Wenruo <wqu@suse.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/lzo.c
fs/btrfs/zlib.c
fs/btrfs/zstd.c

index 06e119ee2649242ac12c0db49b69801ca96a106a..839c8c33aa5aa439dc03c94ed269f94289de009b 100644 (file)
@@ -90,19 +90,19 @@ bool btrfs_compress_is_valid_type(const char *str, size_t len)
 }
 
 static int compression_compress_pages(int type, struct list_head *ws,
-                                     struct address_space *mapping, u64 start,
+                                     struct btrfs_inode *inode, u64 start,
                                      struct folio **folios, unsigned long *out_folios,
                                      unsigned long *total_in, unsigned long *total_out)
 {
        switch (type) {
        case BTRFS_COMPRESS_ZLIB:
-               return zlib_compress_folios(ws, mapping, start, folios,
+               return zlib_compress_folios(ws, inode, start, folios,
                                            out_folios, total_in, total_out);
        case BTRFS_COMPRESS_LZO:
-               return lzo_compress_folios(ws, mapping, start, folios,
+               return lzo_compress_folios(ws, inode, start, folios,
                                           out_folios, total_in, total_out);
        case BTRFS_COMPRESS_ZSTD:
-               return zstd_compress_folios(ws, mapping, start, folios,
+               return zstd_compress_folios(ws, inode, start, folios,
                                            out_folios, total_in, total_out);
        case BTRFS_COMPRESS_NONE:
        default:
@@ -1034,7 +1034,7 @@ int btrfs_compress_filemap_get_folio(struct address_space *mapping, u64 start,
  * @total_out is an in/out parameter, must be set to the input length and will
  * be also used to return the total number of compressed bytes
  */
-int btrfs_compress_folios(unsigned int type, int level, struct address_space *mapping,
+int btrfs_compress_folios(unsigned int type, int level, struct btrfs_inode *inode,
                         u64 start, struct folio **folios, unsigned long *out_folios,
                         unsigned long *total_in, unsigned long *total_out)
 {
@@ -1044,7 +1044,7 @@ int btrfs_compress_folios(unsigned int type, int level, struct address_space *ma
 
        level = btrfs_compress_set_level(type, level);
        workspace = get_workspace(type, level);
-       ret = compression_compress_pages(type, workspace, mapping, start, folios,
+       ret = compression_compress_pages(type, workspace, inode, start, folios,
                                         out_folios, total_in, total_out);
        /* The total read-in bytes should be no larger than the input. */
        ASSERT(*total_in <= orig_len);
index 7b41b2b5ff448847a5cecb5947d39af62c03b498..e7282fb7c13b9756cc657bbbaf85b3fa1249f468 100644 (file)
@@ -88,7 +88,7 @@ int __init btrfs_init_compress(void);
 void __cold btrfs_exit_compress(void);
 
 bool btrfs_compress_level_valid(unsigned int type, int level);
-int btrfs_compress_folios(unsigned int type, int level, struct address_space *mapping,
+int btrfs_compress_folios(unsigned int type, int level, struct btrfs_inode *inode,
                          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 folio *dest_folio,
@@ -155,7 +155,7 @@ int btrfs_compress_heuristic(struct btrfs_inode *inode, u64 start, u64 end);
 int btrfs_compress_filemap_get_folio(struct address_space *mapping, u64 start,
                                     struct folio **in_folio_ret);
 
-int zlib_compress_folios(struct list_head *ws, struct address_space *mapping,
+int zlib_compress_folios(struct list_head *ws, struct btrfs_inode *inode,
                         u64 start, struct folio **folios, unsigned long *out_folios,
                unsigned long *total_in, unsigned long *total_out);
 int zlib_decompress_bio(struct list_head *ws, struct compressed_bio *cb);
@@ -166,7 +166,7 @@ struct list_head *zlib_alloc_workspace(unsigned int level);
 void zlib_free_workspace(struct list_head *ws);
 struct list_head *zlib_get_workspace(unsigned int level);
 
-int lzo_compress_folios(struct list_head *ws, struct address_space *mapping,
+int lzo_compress_folios(struct list_head *ws, struct btrfs_inode *inode,
                        u64 start, struct folio **folios, unsigned long *out_folios,
                unsigned long *total_in, unsigned long *total_out);
 int lzo_decompress_bio(struct list_head *ws, struct compressed_bio *cb);
@@ -176,7 +176,7 @@ int lzo_decompress(struct list_head *ws, const u8 *data_in,
 struct list_head *lzo_alloc_workspace(void);
 void lzo_free_workspace(struct list_head *ws);
 
-int zstd_compress_folios(struct list_head *ws, struct address_space *mapping,
+int zstd_compress_folios(struct list_head *ws, struct btrfs_inode *inode,
                         u64 start, struct folio **folios, unsigned long *out_folios,
                unsigned long *total_in, unsigned long *total_out);
 int zstd_decompress_bio(struct list_head *ws, struct compressed_bio *cb);
index 9eb0253507a08eb268e846f4ae0779c5c2046176..bdbef8e24f932a3db827524378e5187e42ed2261 100644 (file)
@@ -959,7 +959,7 @@ again:
 
        /* Compression level is applied here. */
        ret = btrfs_compress_folios(compress_type, compress_level,
-                                   mapping, start, folios, &nr_folios, &total_in,
+                                   inode, start, folios, &nr_folios, &total_in,
                                    &total_compressed);
        if (ret)
                goto mark_incompressible;
index d403641889caf3346b241833c58f97faa34a67bf..7b46aef7dd93afb5a86dd04c400298750fd737a9 100644 (file)
@@ -209,12 +209,13 @@ out:
        return 0;
 }
 
-int lzo_compress_folios(struct list_head *ws, struct address_space *mapping,
+int lzo_compress_folios(struct list_head *ws, struct btrfs_inode *inode,
                        u64 start, struct folio **folios, unsigned long *out_folios,
                        unsigned long *total_in, unsigned long *total_out)
 {
        struct workspace *workspace = list_entry(ws, struct workspace, list);
-       const u32 sectorsize = inode_to_fs_info(mapping->host)->sectorsize;
+       const u32 sectorsize = inode->root->fs_info->sectorsize;
+       struct address_space *mapping = inode->vfs_inode.i_mapping;
        struct folio *folio_in = NULL;
        char *sizes_ptr;
        const unsigned long max_nr_folio = *out_folios;
index 5292cd341f70f24e2046f3834f9c217584944e38..21af68f93a2d1fb4c0c5f57653d52f022688d195 100644 (file)
@@ -133,11 +133,12 @@ static int copy_data_into_buffer(struct address_space *mapping,
        return 0;
 }
 
-int zlib_compress_folios(struct list_head *ws, struct address_space *mapping,
+int zlib_compress_folios(struct list_head *ws, struct btrfs_inode *inode,
                         u64 start, struct folio **folios, unsigned long *out_folios,
                         unsigned long *total_in, unsigned long *total_out)
 {
        struct workspace *workspace = list_entry(ws, struct workspace, list);
+       struct address_space *mapping = inode->vfs_inode.i_mapping;
        int ret;
        char *data_in = NULL;
        char *cfolio_out;
@@ -155,8 +156,6 @@ int zlib_compress_folios(struct list_head *ws, struct address_space *mapping,
 
        ret = zlib_deflateInit(&workspace->strm, workspace->level);
        if (unlikely(ret != Z_OK)) {
-               struct btrfs_inode *inode = BTRFS_I(mapping->host);
-
                btrfs_err(inode->root->fs_info,
        "zlib compression init failed, error %d root %llu inode %llu offset %llu",
                          ret, btrfs_root_id(inode->root), btrfs_ino(inode), start);
@@ -225,8 +224,6 @@ int zlib_compress_folios(struct list_head *ws, struct address_space *mapping,
 
                ret = zlib_deflate(&workspace->strm, Z_SYNC_FLUSH);
                if (unlikely(ret != Z_OK)) {
-                       struct btrfs_inode *inode = BTRFS_I(mapping->host);
-
                        btrfs_warn(inode->root->fs_info,
                "zlib compression failed, error %d root %llu inode %llu offset %llu",
                                   ret, btrfs_root_id(inode->root), btrfs_ino(inode),
index ff0292615e1f37a2396fd75710a93413af910316..00159e0e921ea5fc290a75569a81992d834c9a37 100644 (file)
@@ -384,11 +384,12 @@ fail:
        return ERR_PTR(-ENOMEM);
 }
 
-int zstd_compress_folios(struct list_head *ws, struct address_space *mapping,
+int zstd_compress_folios(struct list_head *ws, struct btrfs_inode *inode,
                         u64 start, struct folio **folios, unsigned long *out_folios,
                         unsigned long *total_in, unsigned long *total_out)
 {
        struct workspace *workspace = list_entry(ws, struct workspace, list);
+       struct address_space *mapping = inode->vfs_inode.i_mapping;
        zstd_cstream *stream;
        int ret = 0;
        int nr_folios = 0;
@@ -411,8 +412,6 @@ int zstd_compress_folios(struct list_head *ws, struct address_space *mapping,
        stream = zstd_init_cstream(&workspace->params, len, workspace->mem,
                        workspace->size);
        if (unlikely(!stream)) {
-               struct btrfs_inode *inode = BTRFS_I(mapping->host);
-
                btrfs_err(inode->root->fs_info,
        "zstd compression init level %d failed, root %llu inode %llu offset %llu",
                          workspace->req_level, btrfs_root_id(inode->root),
@@ -447,8 +446,6 @@ int zstd_compress_folios(struct list_head *ws, struct address_space *mapping,
                ret2 = zstd_compress_stream(stream, &workspace->out_buf,
                                &workspace->in_buf);
                if (unlikely(zstd_is_error(ret2))) {
-                       struct btrfs_inode *inode = BTRFS_I(mapping->host);
-
                        btrfs_warn(inode->root->fs_info,
 "zstd compression level %d failed, error %d root %llu inode %llu offset %llu",
                                   workspace->req_level, zstd_get_error_code(ret2),
@@ -522,8 +519,6 @@ int zstd_compress_folios(struct list_head *ws, struct address_space *mapping,
 
                ret2 = zstd_end_stream(stream, &workspace->out_buf);
                if (unlikely(zstd_is_error(ret2))) {
-                       struct btrfs_inode *inode = BTRFS_I(mapping->host);
-
                        btrfs_err(inode->root->fs_info,
 "zstd compression end level %d failed, error %d root %llu inode %llu offset %llu",
                                  workspace->req_level, zstd_get_error_code(ret2),