Skip to content

Commit 0f0f0ba

Browse files
adam900710kdave
authored andcommitted
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 <[email protected]> Signed-off-by: Qu Wenruo <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 1b4ef57 commit 0f0f0ba

File tree

6 files changed

+18
-25
lines changed

6 files changed

+18
-25
lines changed

fs/btrfs/compression.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,19 +90,19 @@ bool btrfs_compress_is_valid_type(const char *str, size_t len)
9090
}
9191

9292
static int compression_compress_pages(int type, struct list_head *ws,
93-
struct address_space *mapping, u64 start,
93+
struct btrfs_inode *inode, u64 start,
9494
struct folio **folios, unsigned long *out_folios,
9595
unsigned long *total_in, unsigned long *total_out)
9696
{
9797
switch (type) {
9898
case BTRFS_COMPRESS_ZLIB:
99-
return zlib_compress_folios(ws, mapping, start, folios,
99+
return zlib_compress_folios(ws, inode, start, folios,
100100
out_folios, total_in, total_out);
101101
case BTRFS_COMPRESS_LZO:
102-
return lzo_compress_folios(ws, mapping, start, folios,
102+
return lzo_compress_folios(ws, inode, start, folios,
103103
out_folios, total_in, total_out);
104104
case BTRFS_COMPRESS_ZSTD:
105-
return zstd_compress_folios(ws, mapping, start, folios,
105+
return zstd_compress_folios(ws, inode, start, folios,
106106
out_folios, total_in, total_out);
107107
case BTRFS_COMPRESS_NONE:
108108
default:
@@ -1034,7 +1034,7 @@ int btrfs_compress_filemap_get_folio(struct address_space *mapping, u64 start,
10341034
* @total_out is an in/out parameter, must be set to the input length and will
10351035
* be also used to return the total number of compressed bytes
10361036
*/
1037-
int btrfs_compress_folios(unsigned int type, int level, struct address_space *mapping,
1037+
int btrfs_compress_folios(unsigned int type, int level, struct btrfs_inode *inode,
10381038
u64 start, struct folio **folios, unsigned long *out_folios,
10391039
unsigned long *total_in, unsigned long *total_out)
10401040
{
@@ -1044,7 +1044,7 @@ int btrfs_compress_folios(unsigned int type, int level, struct address_space *ma
10441044

10451045
level = btrfs_compress_set_level(type, level);
10461046
workspace = get_workspace(type, level);
1047-
ret = compression_compress_pages(type, workspace, mapping, start, folios,
1047+
ret = compression_compress_pages(type, workspace, inode, start, folios,
10481048
out_folios, total_in, total_out);
10491049
/* The total read-in bytes should be no larger than the input. */
10501050
ASSERT(*total_in <= orig_len);

fs/btrfs/compression.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ int __init btrfs_init_compress(void);
8888
void __cold btrfs_exit_compress(void);
8989

9090
bool btrfs_compress_level_valid(unsigned int type, int level);
91-
int btrfs_compress_folios(unsigned int type, int level, struct address_space *mapping,
91+
int btrfs_compress_folios(unsigned int type, int level, struct btrfs_inode *inode,
9292
u64 start, struct folio **folios, unsigned long *out_folios,
9393
unsigned long *total_in, unsigned long *total_out);
9494
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);
155155
int btrfs_compress_filemap_get_folio(struct address_space *mapping, u64 start,
156156
struct folio **in_folio_ret);
157157

158-
int zlib_compress_folios(struct list_head *ws, struct address_space *mapping,
158+
int zlib_compress_folios(struct list_head *ws, struct btrfs_inode *inode,
159159
u64 start, struct folio **folios, unsigned long *out_folios,
160160
unsigned long *total_in, unsigned long *total_out);
161161
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);
166166
void zlib_free_workspace(struct list_head *ws);
167167
struct list_head *zlib_get_workspace(unsigned int level);
168168

169-
int lzo_compress_folios(struct list_head *ws, struct address_space *mapping,
169+
int lzo_compress_folios(struct list_head *ws, struct btrfs_inode *inode,
170170
u64 start, struct folio **folios, unsigned long *out_folios,
171171
unsigned long *total_in, unsigned long *total_out);
172172
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,
176176
struct list_head *lzo_alloc_workspace(void);
177177
void lzo_free_workspace(struct list_head *ws);
178178

179-
int zstd_compress_folios(struct list_head *ws, struct address_space *mapping,
179+
int zstd_compress_folios(struct list_head *ws, struct btrfs_inode *inode,
180180
u64 start, struct folio **folios, unsigned long *out_folios,
181181
unsigned long *total_in, unsigned long *total_out);
182182
int zstd_decompress_bio(struct list_head *ws, struct compressed_bio *cb);

fs/btrfs/inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,7 @@ static void compress_file_range(struct btrfs_work *work)
959959

960960
/* Compression level is applied here. */
961961
ret = btrfs_compress_folios(compress_type, compress_level,
962-
mapping, start, folios, &nr_folios, &total_in,
962+
inode, start, folios, &nr_folios, &total_in,
963963
&total_compressed);
964964
if (ret)
965965
goto mark_incompressible;

fs/btrfs/lzo.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,13 @@ static int copy_compressed_data_to_page(char *compressed_data,
209209
return 0;
210210
}
211211

212-
int lzo_compress_folios(struct list_head *ws, struct address_space *mapping,
212+
int lzo_compress_folios(struct list_head *ws, struct btrfs_inode *inode,
213213
u64 start, struct folio **folios, unsigned long *out_folios,
214214
unsigned long *total_in, unsigned long *total_out)
215215
{
216216
struct workspace *workspace = list_entry(ws, struct workspace, list);
217-
const u32 sectorsize = inode_to_fs_info(mapping->host)->sectorsize;
217+
const u32 sectorsize = inode->root->fs_info->sectorsize;
218+
struct address_space *mapping = inode->vfs_inode.i_mapping;
218219
struct folio *folio_in = NULL;
219220
char *sizes_ptr;
220221
const unsigned long max_nr_folio = *out_folios;

fs/btrfs/zlib.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,12 @@ static int copy_data_into_buffer(struct address_space *mapping,
133133
return 0;
134134
}
135135

136-
int zlib_compress_folios(struct list_head *ws, struct address_space *mapping,
136+
int zlib_compress_folios(struct list_head *ws, struct btrfs_inode *inode,
137137
u64 start, struct folio **folios, unsigned long *out_folios,
138138
unsigned long *total_in, unsigned long *total_out)
139139
{
140140
struct workspace *workspace = list_entry(ws, struct workspace, list);
141+
struct address_space *mapping = inode->vfs_inode.i_mapping;
141142
int ret;
142143
char *data_in = NULL;
143144
char *cfolio_out;
@@ -155,8 +156,6 @@ int zlib_compress_folios(struct list_head *ws, struct address_space *mapping,
155156

156157
ret = zlib_deflateInit(&workspace->strm, workspace->level);
157158
if (unlikely(ret != Z_OK)) {
158-
struct btrfs_inode *inode = BTRFS_I(mapping->host);
159-
160159
btrfs_err(inode->root->fs_info,
161160
"zlib compression init failed, error %d root %llu inode %llu offset %llu",
162161
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,
225224

226225
ret = zlib_deflate(&workspace->strm, Z_SYNC_FLUSH);
227226
if (unlikely(ret != Z_OK)) {
228-
struct btrfs_inode *inode = BTRFS_I(mapping->host);
229-
230227
btrfs_warn(inode->root->fs_info,
231228
"zlib compression failed, error %d root %llu inode %llu offset %llu",
232229
ret, btrfs_root_id(inode->root), btrfs_ino(inode),

fs/btrfs/zstd.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -384,11 +384,12 @@ struct list_head *zstd_alloc_workspace(int level)
384384
return ERR_PTR(-ENOMEM);
385385
}
386386

387-
int zstd_compress_folios(struct list_head *ws, struct address_space *mapping,
387+
int zstd_compress_folios(struct list_head *ws, struct btrfs_inode *inode,
388388
u64 start, struct folio **folios, unsigned long *out_folios,
389389
unsigned long *total_in, unsigned long *total_out)
390390
{
391391
struct workspace *workspace = list_entry(ws, struct workspace, list);
392+
struct address_space *mapping = inode->vfs_inode.i_mapping;
392393
zstd_cstream *stream;
393394
int ret = 0;
394395
int nr_folios = 0;
@@ -411,8 +412,6 @@ int zstd_compress_folios(struct list_head *ws, struct address_space *mapping,
411412
stream = zstd_init_cstream(&workspace->params, len, workspace->mem,
412413
workspace->size);
413414
if (unlikely(!stream)) {
414-
struct btrfs_inode *inode = BTRFS_I(mapping->host);
415-
416415
btrfs_err(inode->root->fs_info,
417416
"zstd compression init level %d failed, root %llu inode %llu offset %llu",
418417
workspace->req_level, btrfs_root_id(inode->root),
@@ -447,8 +446,6 @@ int zstd_compress_folios(struct list_head *ws, struct address_space *mapping,
447446
ret2 = zstd_compress_stream(stream, &workspace->out_buf,
448447
&workspace->in_buf);
449448
if (unlikely(zstd_is_error(ret2))) {
450-
struct btrfs_inode *inode = BTRFS_I(mapping->host);
451-
452449
btrfs_warn(inode->root->fs_info,
453450
"zstd compression level %d failed, error %d root %llu inode %llu offset %llu",
454451
workspace->req_level, zstd_get_error_code(ret2),
@@ -522,8 +519,6 @@ int zstd_compress_folios(struct list_head *ws, struct address_space *mapping,
522519

523520
ret2 = zstd_end_stream(stream, &workspace->out_buf);
524521
if (unlikely(zstd_is_error(ret2))) {
525-
struct btrfs_inode *inode = BTRFS_I(mapping->host);
526-
527522
btrfs_err(inode->root->fs_info,
528523
"zstd compression end level %d failed, error %d root %llu inode %llu offset %llu",
529524
workspace->req_level, zstd_get_error_code(ret2),

0 commit comments

Comments
 (0)