Commit b70f3a45 authored by Li Zetao's avatar Li Zetao Committed by David Sterba

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: default avatarLi Zetao <lizetao1@huawei.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 9f9a4e43
...@@ -146,7 +146,7 @@ static int compression_decompress(int type, struct list_head *ws, ...@@ -146,7 +146,7 @@ static int compression_decompress(int type, struct list_head *ws,
dest_pgoff, srclen, destlen); dest_pgoff, srclen, destlen);
case BTRFS_COMPRESS_LZO: return lzo_decompress(ws, data_in, page_folio(dest_page), case BTRFS_COMPRESS_LZO: return lzo_decompress(ws, data_in, page_folio(dest_page),
dest_pgoff, srclen, destlen); dest_pgoff, srclen, destlen);
case BTRFS_COMPRESS_ZSTD: return zstd_decompress(ws, data_in, dest_page, case BTRFS_COMPRESS_ZSTD: return zstd_decompress(ws, data_in, page_folio(dest_page),
dest_pgoff, srclen, destlen); dest_pgoff, srclen, destlen);
case BTRFS_COMPRESS_NONE: case BTRFS_COMPRESS_NONE:
default: default:
......
...@@ -183,7 +183,7 @@ int zstd_compress_folios(struct list_head *ws, struct address_space *mapping, ...@@ -183,7 +183,7 @@ int zstd_compress_folios(struct list_head *ws, struct address_space *mapping,
unsigned long *total_in, unsigned long *total_out); unsigned long *total_in, unsigned long *total_out);
int zstd_decompress_bio(struct list_head *ws, struct compressed_bio *cb); int zstd_decompress_bio(struct list_head *ws, struct compressed_bio *cb);
int zstd_decompress(struct list_head *ws, const u8 *data_in, int zstd_decompress(struct list_head *ws, const u8 *data_in,
struct page *dest_page, unsigned long dest_pgoff, size_t srclen, struct folio *dest_folio, unsigned long dest_pgoff, size_t srclen,
size_t destlen); size_t destlen);
void zstd_init_workspace_manager(void); void zstd_init_workspace_manager(void);
void zstd_cleanup_workspace_manager(void); void zstd_cleanup_workspace_manager(void);
......
...@@ -656,11 +656,11 @@ int zstd_decompress_bio(struct list_head *ws, struct compressed_bio *cb) ...@@ -656,11 +656,11 @@ int zstd_decompress_bio(struct list_head *ws, struct compressed_bio *cb)
} }
int zstd_decompress(struct list_head *ws, const u8 *data_in, int zstd_decompress(struct list_head *ws, const u8 *data_in,
struct page *dest_page, unsigned long dest_pgoff, size_t srclen, struct folio *dest_folio, unsigned long dest_pgoff, size_t srclen,
size_t destlen) size_t destlen)
{ {
struct workspace *workspace = list_entry(ws, struct workspace, list); struct workspace *workspace = list_entry(ws, struct workspace, list);
struct btrfs_fs_info *fs_info = btrfs_sb(dest_page->mapping->host->i_sb); struct btrfs_fs_info *fs_info = btrfs_sb(folio_inode(dest_folio)->i_sb);
const u32 sectorsize = fs_info->sectorsize; const u32 sectorsize = fs_info->sectorsize;
zstd_dstream *stream; zstd_dstream *stream;
int ret = 0; int ret = 0;
...@@ -669,12 +669,12 @@ int zstd_decompress(struct list_head *ws, const u8 *data_in, ...@@ -669,12 +669,12 @@ int zstd_decompress(struct list_head *ws, const u8 *data_in,
stream = zstd_init_dstream( stream = zstd_init_dstream(
ZSTD_BTRFS_MAX_INPUT, workspace->mem, workspace->size); ZSTD_BTRFS_MAX_INPUT, workspace->mem, workspace->size);
if (unlikely(!stream)) { if (unlikely(!stream)) {
struct btrfs_inode *inode = BTRFS_I(dest_page->mapping->host); struct btrfs_inode *inode = folio_to_inode(dest_folio);
btrfs_err(inode->root->fs_info, btrfs_err(inode->root->fs_info,
"zstd decompression init failed, root %llu inode %llu offset %llu", "zstd decompression init failed, root %llu inode %llu offset %llu",
btrfs_root_id(inode->root), btrfs_ino(inode), btrfs_root_id(inode->root), btrfs_ino(inode),
page_offset(dest_page)); folio_pos(dest_folio));
ret = -EIO; ret = -EIO;
goto finish; goto finish;
} }
...@@ -693,21 +693,21 @@ int zstd_decompress(struct list_head *ws, const u8 *data_in, ...@@ -693,21 +693,21 @@ int zstd_decompress(struct list_head *ws, const u8 *data_in,
*/ */
ret = zstd_decompress_stream(stream, &workspace->out_buf, &workspace->in_buf); ret = zstd_decompress_stream(stream, &workspace->out_buf, &workspace->in_buf);
if (unlikely(zstd_is_error(ret))) { if (unlikely(zstd_is_error(ret))) {
struct btrfs_inode *inode = BTRFS_I(dest_page->mapping->host); struct btrfs_inode *inode = folio_to_inode(dest_folio);
btrfs_err(inode->root->fs_info, btrfs_err(inode->root->fs_info,
"zstd decompression failed, error %d root %llu inode %llu offset %llu", "zstd decompression failed, error %d root %llu inode %llu offset %llu",
zstd_get_error_code(ret), btrfs_root_id(inode->root), zstd_get_error_code(ret), btrfs_root_id(inode->root),
btrfs_ino(inode), page_offset(dest_page)); btrfs_ino(inode), folio_pos(dest_folio));
goto finish; goto finish;
} }
to_copy = workspace->out_buf.pos; to_copy = workspace->out_buf.pos;
memcpy_to_page(dest_page, dest_pgoff, workspace->out_buf.dst, to_copy); memcpy_to_folio(dest_folio, dest_pgoff, workspace->out_buf.dst, to_copy);
finish: finish:
/* Error or early end. */ /* Error or early end. */
if (unlikely(to_copy < destlen)) { if (unlikely(to_copy < destlen)) {
ret = -EIO; ret = -EIO;
memzero_page(dest_page, dest_pgoff + to_copy, destlen - to_copy); folio_zero_range(dest_folio, dest_pgoff + to_copy, destlen - to_copy);
} }
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment