Commit d71b419f authored by Qu Wenruo's avatar Qu Wenruo Committed by David Sterba
Browse files

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: default avatarAnand Jain <anand.jain@oracle.com>
Signed-off-by: default avatarQu Wenruo <wqu@suse.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 0d703963
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -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);
+4 −4
Original line number Diff line number Diff line
@@ -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
Original line number Diff line number Diff line
@@ -959,7 +959,7 @@ static void compress_file_range(struct btrfs_work *work)

	/* 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
Original line number Diff line number Diff line
@@ -209,12 +209,13 @@ static int copy_compressed_data_to_page(char *compressed_data,
	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
Original line number Diff line number Diff line
@@ -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),
Loading