diff options
author | Qu Wenruo <wqu@suse.com> | 2024-01-29 10:46:06 +0100 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2024-05-07 21:31:02 +0200 |
commit | 6de3595473b0bae11102ef6db40e6f2334f13ed2 (patch) | |
tree | eda606a551da51c5cb017e94ecb6683cc25a332a /fs/btrfs/zstd.c | |
parent | btrfs: stop locking the source extent range during reflink (diff) | |
download | linux-6de3595473b0bae11102ef6db40e6f2334f13ed2.tar.xz linux-6de3595473b0bae11102ef6db40e6f2334f13ed2.zip |
btrfs: compression: add error handling for missed page cache
For all the supported compression algorithms, the compression path would
always need to grab the page cache, then do the compression.
Normally we would get a page reference without any problem, since the
write path should have already locked the pages in the write range.
For the sake of error handling, we should handle the page cache miss
case.
Adds a common wrapper, btrfs_compress_find_get_page(), which calls
find_get_page(), and do the error handling along with an error message.
Callers inside compression path would only need to call
btrfs_compress_find_get_page(), and error out if it returned any error.
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'fs/btrfs/zstd.c')
-rw-r--r-- | fs/btrfs/zstd.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/fs/btrfs/zstd.c b/fs/btrfs/zstd.c index 92b3744b819b..b647ad036af3 100644 --- a/fs/btrfs/zstd.c +++ b/fs/btrfs/zstd.c @@ -406,7 +406,9 @@ int zstd_compress_pages(struct list_head *ws, struct address_space *mapping, } /* map in the first page of input data */ - in_page = find_get_page(mapping, start >> PAGE_SHIFT); + ret = btrfs_compress_find_get_page(mapping, start, &in_page); + if (ret < 0) + goto out; workspace->in_buf.src = kmap_local_page(in_page); workspace->in_buf.pos = 0; workspace->in_buf.size = min_t(size_t, len, PAGE_SIZE); @@ -479,10 +481,13 @@ int zstd_compress_pages(struct list_head *ws, struct address_space *mapping, if (workspace->in_buf.pos == workspace->in_buf.size) { tot_in += PAGE_SIZE; kunmap_local(workspace->in_buf.src); + workspace->in_buf.src = NULL; put_page(in_page); start += PAGE_SIZE; len -= PAGE_SIZE; - in_page = find_get_page(mapping, start >> PAGE_SHIFT); + ret = btrfs_compress_find_get_page(mapping, start, &in_page); + if (ret < 0) + goto out; workspace->in_buf.src = kmap_local_page(in_page); workspace->in_buf.pos = 0; workspace->in_buf.size = min_t(size_t, len, PAGE_SIZE); |