]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
btrfs: zlib: make the compression path to handle sector size < page size
authorQu Wenruo <wqu@suse.com>
Fri, 6 Sep 2024 04:44:55 +0000 (14:14 +0930)
committerDavid Sterba <dsterba@suse.com>
Mon, 11 Nov 2024 13:34:12 +0000 (14:34 +0100)
Inside zlib_compress_folios(), each time we switch the input page cache,
the @start is increased by PAGE_SIZE.

But for the incoming compression support for sector size < page size
(previously we support compression only when the range is fully page
aligned), this is not going to handle the following case:

    0          32K         64K          96K
    |          |///////////||///////////|

@start has the initial value 32K, indicating the start filepos of the
to-be-compressed range.

And when grabbing the first page as input, we always call "start +=
PAGE_SIZE;".

But since @start is starting at 32K, it will be increased by 64K,
resulting it to be 96K for the next range, causing incorrect input range
and corruption for the future subpage compression.

Fix it by only increase @start by the input size.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/zlib.c

index 100abc00b794caffde06745c7afb4abad4cae982..ddf0d5a448a7412fb86c10a805f0b7ed7ee1d031 100644 (file)
@@ -194,7 +194,7 @@ int zlib_compress_folios(struct list_head *ws, struct address_space *mapping,
                                pg_off = offset_in_page(start);
                                cur_len = btrfs_calc_input_length(orig_end, start);
                                data_in = kmap_local_folio(in_folio, pg_off);
-                               start += PAGE_SIZE;
+                               start += cur_len;
                                workspace->strm.next_in = data_in;
                                workspace->strm.avail_in = cur_len;
                        }