Skip to content

Commit 54c78d4

Browse files
Li Zetaokdave
authored andcommitted
btrfs: convert zlib_decompress() to take a folio
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. And memcpy_to_page() can be replaced with memcpy_to_folio(). But there is no memzero_folio(), but it can be replaced equivalently by folio_zero_range(). Signed-off-by: Li Zetao <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 046c0d6 commit 54c78d4

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

fs/btrfs/compression.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ static int compression_decompress(int type, struct list_head *ws,
142142
unsigned long dest_pgoff, size_t srclen, size_t destlen)
143143
{
144144
switch (type) {
145-
case BTRFS_COMPRESS_ZLIB: return zlib_decompress(ws, data_in, dest_page,
145+
case BTRFS_COMPRESS_ZLIB: return zlib_decompress(ws, data_in, page_folio(dest_page),
146146
dest_pgoff, srclen, destlen);
147147
case BTRFS_COMPRESS_LZO: return lzo_decompress(ws, data_in, dest_page,
148148
dest_pgoff, srclen, destlen);

fs/btrfs/compression.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ int zlib_compress_folios(struct list_head *ws, struct address_space *mapping,
162162
unsigned long *total_in, unsigned long *total_out);
163163
int zlib_decompress_bio(struct list_head *ws, struct compressed_bio *cb);
164164
int zlib_decompress(struct list_head *ws, const u8 *data_in,
165-
struct page *dest_page, unsigned long dest_pgoff, size_t srclen,
165+
struct folio *dest_folio, unsigned long dest_pgoff, size_t srclen,
166166
size_t destlen);
167167
struct list_head *zlib_alloc_workspace(unsigned int level);
168168
void zlib_free_workspace(struct list_head *ws);

fs/btrfs/zlib.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ int zlib_decompress_bio(struct list_head *ws, struct compressed_bio *cb)
393393
}
394394

395395
int zlib_decompress(struct list_head *ws, const u8 *data_in,
396-
struct page *dest_page, unsigned long dest_pgoff, size_t srclen,
396+
struct folio *dest_folio, unsigned long dest_pgoff, size_t srclen,
397397
size_t destlen)
398398
{
399399
struct workspace *workspace = list_entry(ws, struct workspace, list);
@@ -421,12 +421,12 @@ int zlib_decompress(struct list_head *ws, const u8 *data_in,
421421

422422
ret = zlib_inflateInit2(&workspace->strm, wbits);
423423
if (unlikely(ret != Z_OK)) {
424-
struct btrfs_inode *inode = BTRFS_I(dest_page->mapping->host);
424+
struct btrfs_inode *inode = folio_to_inode(dest_folio);
425425

426426
btrfs_err(inode->root->fs_info,
427427
"zlib decompression init failed, error %d root %llu inode %llu offset %llu",
428428
ret, btrfs_root_id(inode->root), btrfs_ino(inode),
429-
page_offset(dest_page));
429+
folio_pos(dest_folio));
430430
return -EIO;
431431
}
432432

@@ -439,16 +439,16 @@ int zlib_decompress(struct list_head *ws, const u8 *data_in,
439439
if (ret != Z_STREAM_END)
440440
goto out;
441441

442-
memcpy_to_page(dest_page, dest_pgoff, workspace->buf, to_copy);
442+
memcpy_to_folio(dest_folio, dest_pgoff, workspace->buf, to_copy);
443443

444444
out:
445445
if (unlikely(to_copy != destlen)) {
446-
struct btrfs_inode *inode = BTRFS_I(dest_page->mapping->host);
446+
struct btrfs_inode *inode = folio_to_inode(dest_folio);
447447

448448
btrfs_err(inode->root->fs_info,
449449
"zlib decompression failed, error %d root %llu inode %llu offset %llu decompressed %lu expected %zu",
450450
ret, btrfs_root_id(inode->root), btrfs_ino(inode),
451-
page_offset(dest_page), to_copy, destlen);
451+
folio_pos(dest_folio), to_copy, destlen);
452452
ret = -EIO;
453453
} else {
454454
ret = 0;
@@ -457,7 +457,7 @@ int zlib_decompress(struct list_head *ws, const u8 *data_in,
457457
zlib_inflateEnd(&workspace->strm);
458458

459459
if (unlikely(to_copy < destlen))
460-
memzero_page(dest_page, dest_pgoff + to_copy, destlen - to_copy);
460+
folio_zero_range(dest_folio, dest_pgoff + to_copy, destlen - to_copy);
461461
return ret;
462462
}
463463

0 commit comments

Comments
 (0)