summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQu Wenruo <wqu@suse.com>2026-01-20 10:30:09 +1030
committerDavid Sterba <dsterba@suse.com>2026-02-03 07:56:18 +0100
commit20c993134e105368b9165cb9af8d8c1c2ac59a2d (patch)
treeabf423cc46d12f0b29bf940393e79e14b490557f
parent37cc07cab7dc311f2b7aeaaa7598face53eddcab (diff)
btrfs: zlib: use folio_iter to handle zlib_decompress_bio()
Currently zlib_decompress_bio() is using compressed_bio->compressed_folios[] array to grab each compressed folio. However cb->compressed_folios[] is just a pointer to each folio of the compressed bio, meaning we can just replace the compressed_folios[] array by just grabbing the folio inside the compressed bio. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r--fs/btrfs/zlib.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/fs/btrfs/zlib.c b/fs/btrfs/zlib.c
index 10ed48d4a846..a004aa4ee9e2 100644
--- a/fs/btrfs/zlib.c
+++ b/fs/btrfs/zlib.c
@@ -338,18 +338,23 @@ int zlib_decompress_bio(struct list_head *ws, struct compressed_bio *cb)
{
struct btrfs_fs_info *fs_info = cb_to_fs_info(cb);
struct workspace *workspace = list_entry(ws, struct workspace, list);
+ struct folio_iter fi;
const u32 min_folio_size = btrfs_min_folio_size(fs_info);
int ret = 0, ret2;
int wbits = MAX_WBITS;
char *data_in;
size_t total_out = 0;
- unsigned long folio_in_index = 0;
size_t srclen = cb->compressed_len;
- unsigned long total_folios_in = DIV_ROUND_UP(srclen, min_folio_size);
unsigned long buf_start;
- struct folio **folios_in = cb->compressed_folios;
- data_in = kmap_local_folio(folios_in[folio_in_index], 0);
+ bio_first_folio(&fi, &cb->bbio.bio, 0);
+
+ /* We must have at least one folio here, that has the correct size. */
+ if (unlikely(!fi.folio))
+ return -EINVAL;
+ ASSERT(folio_size(fi.folio) == min_folio_size);
+
+ data_in = kmap_local_folio(fi.folio, 0);
workspace->strm.next_in = data_in;
workspace->strm.avail_in = min_t(size_t, srclen, min_folio_size);
workspace->strm.total_in = 0;
@@ -404,12 +409,13 @@ int zlib_decompress_bio(struct list_head *ws, struct compressed_bio *cb)
if (workspace->strm.avail_in == 0) {
unsigned long tmp;
kunmap_local(data_in);
- folio_in_index++;
- if (folio_in_index >= total_folios_in) {
+ bio_next_folio(&fi, &cb->bbio.bio);
+ if (!fi.folio) {
data_in = NULL;
break;
}
- data_in = kmap_local_folio(folios_in[folio_in_index], 0);
+ ASSERT(folio_size(fi.folio) == min_folio_size);
+ data_in = kmap_local_folio(fi.folio, 0);
workspace->strm.next_in = data_in;
tmp = srclen - workspace->strm.total_in;
workspace->strm.avail_in = min(tmp, min_folio_size);