Skip to content

Commit b70f3a4

Browse files
Li Zetaokdave
authored andcommitted
btrfs: convert zstd_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 9f9a4e4 commit b70f3a4

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

fs/btrfs/compression.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ static int compression_decompress(int type, struct list_head *ws,
146146
dest_pgoff, srclen, destlen);
147147
case BTRFS_COMPRESS_LZO: return lzo_decompress(ws, data_in, page_folio(dest_page),
148148
dest_pgoff, srclen, destlen);
149-
case BTRFS_COMPRESS_ZSTD: return zstd_decompress(ws, data_in, dest_page,
149+
case BTRFS_COMPRESS_ZSTD: return zstd_decompress(ws, data_in, page_folio(dest_page),
150150
dest_pgoff, srclen, destlen);
151151
case BTRFS_COMPRESS_NONE:
152152
default:

fs/btrfs/compression.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ int zstd_compress_folios(struct list_head *ws, struct address_space *mapping,
183183
unsigned long *total_in, unsigned long *total_out);
184184
int zstd_decompress_bio(struct list_head *ws, struct compressed_bio *cb);
185185
int zstd_decompress(struct list_head *ws, const u8 *data_in,
186-
struct page *dest_page, unsigned long dest_pgoff, size_t srclen,
186+
struct folio *dest_folio, unsigned long dest_pgoff, size_t srclen,
187187
size_t destlen);
188188
void zstd_init_workspace_manager(void);
189189
void zstd_cleanup_workspace_manager(void);

fs/btrfs/zstd.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -656,11 +656,11 @@ int zstd_decompress_bio(struct list_head *ws, struct compressed_bio *cb)
656656
}
657657

658658
int zstd_decompress(struct list_head *ws, const u8 *data_in,
659-
struct page *dest_page, unsigned long dest_pgoff, size_t srclen,
659+
struct folio *dest_folio, unsigned long dest_pgoff, size_t srclen,
660660
size_t destlen)
661661
{
662662
struct workspace *workspace = list_entry(ws, struct workspace, list);
663-
struct btrfs_fs_info *fs_info = btrfs_sb(dest_page->mapping->host->i_sb);
663+
struct btrfs_fs_info *fs_info = btrfs_sb(folio_inode(dest_folio)->i_sb);
664664
const u32 sectorsize = fs_info->sectorsize;
665665
zstd_dstream *stream;
666666
int ret = 0;
@@ -669,12 +669,12 @@ int zstd_decompress(struct list_head *ws, const u8 *data_in,
669669
stream = zstd_init_dstream(
670670
ZSTD_BTRFS_MAX_INPUT, workspace->mem, workspace->size);
671671
if (unlikely(!stream)) {
672-
struct btrfs_inode *inode = BTRFS_I(dest_page->mapping->host);
672+
struct btrfs_inode *inode = folio_to_inode(dest_folio);
673673

674674
btrfs_err(inode->root->fs_info,
675675
"zstd decompression init failed, root %llu inode %llu offset %llu",
676676
btrfs_root_id(inode->root), btrfs_ino(inode),
677-
page_offset(dest_page));
677+
folio_pos(dest_folio));
678678
ret = -EIO;
679679
goto finish;
680680
}
@@ -693,21 +693,21 @@ int zstd_decompress(struct list_head *ws, const u8 *data_in,
693693
*/
694694
ret = zstd_decompress_stream(stream, &workspace->out_buf, &workspace->in_buf);
695695
if (unlikely(zstd_is_error(ret))) {
696-
struct btrfs_inode *inode = BTRFS_I(dest_page->mapping->host);
696+
struct btrfs_inode *inode = folio_to_inode(dest_folio);
697697

698698
btrfs_err(inode->root->fs_info,
699699
"zstd decompression failed, error %d root %llu inode %llu offset %llu",
700700
zstd_get_error_code(ret), btrfs_root_id(inode->root),
701-
btrfs_ino(inode), page_offset(dest_page));
701+
btrfs_ino(inode), folio_pos(dest_folio));
702702
goto finish;
703703
}
704704
to_copy = workspace->out_buf.pos;
705-
memcpy_to_page(dest_page, dest_pgoff, workspace->out_buf.dst, to_copy);
705+
memcpy_to_folio(dest_folio, dest_pgoff, workspace->out_buf.dst, to_copy);
706706
finish:
707707
/* Error or early end. */
708708
if (unlikely(to_copy < destlen)) {
709709
ret = -EIO;
710-
memzero_page(dest_page, dest_pgoff + to_copy, destlen - to_copy);
710+
folio_zero_range(dest_folio, dest_pgoff + to_copy, destlen - to_copy);
711711
}
712712
return ret;
713713
}

0 commit comments

Comments
 (0)