btrfs: pass btrfs_inode pointer directly into btrfs_compress_folios()
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>
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
+3
-2
@@ -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;
|
||||
|
||||
+2
-5
@@ -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),
|
||||
|
||||
+2
-7
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user