Skip to content

Commit

Permalink
btrfs: push errors up from add_async_extent()
Browse files Browse the repository at this point in the history
The memory allocation error in add_async_extent() is not handled
properly, return an error and push the BUG_ON to the caller. Handling it
there is not trivial so at least make it visible.

Signed-off-by: David Sterba <[email protected]>
  • Loading branch information
kdave committed Mar 4, 2024
1 parent 4e94ee8 commit dbe6cda
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions fs/btrfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,8 @@ static noinline int add_async_extent(struct async_chunk *cow,
struct async_extent *async_extent;

async_extent = kmalloc(sizeof(*async_extent), GFP_NOFS);
BUG_ON(!async_extent); /* -ENOMEM */
if (!async_extent)
return -ENOMEM;
async_extent->start = start;
async_extent->ram_size = ram_size;
async_extent->compressed_size = compressed_size;
Expand Down Expand Up @@ -1025,8 +1026,9 @@ static void compress_file_range(struct btrfs_work *work)
* The async work queues will take care of doing actual allocation on
* disk for these compressed pages, and will submit the bios.
*/
add_async_extent(async_chunk, start, total_in, total_compressed, pages,
nr_pages, compress_type);
ret = add_async_extent(async_chunk, start, total_in, total_compressed, pages,
nr_pages, compress_type);
BUG_ON(ret);
if (start + total_in < end) {
start += total_in;
cond_resched();
Expand All @@ -1038,8 +1040,9 @@ static void compress_file_range(struct btrfs_work *work)
if (!btrfs_test_opt(fs_info, FORCE_COMPRESS) && !inode->prop_compress)
inode->flags |= BTRFS_INODE_NOCOMPRESS;
cleanup_and_bail_uncompressed:
add_async_extent(async_chunk, start, end - start + 1, 0, NULL, 0,
BTRFS_COMPRESS_NONE);
ret = add_async_extent(async_chunk, start, end - start + 1, 0, NULL, 0,
BTRFS_COMPRESS_NONE);
BUG_ON(ret);
free_pages:
if (pages) {
for (i = 0; i < nr_pages; i++) {
Expand Down

0 comments on commit dbe6cda

Please sign in to comment.