Skip to content

Commit

Permalink
btrfs: do not BUG_ON() on failure to migrate space when replacing ext…
Browse files Browse the repository at this point in the history
…ents

At btrfs_replace_file_extents(), if we fail to migrate reserved metadata
space from the transaction block reserve into the local block reserve,
we trigger a BUG_ON(). This is because it should not be possible to have
a failure here, as we reserved more space when we started the transaction
than the space we want to migrate. However having a BUG_ON() is way too
drastic, we can perfectly handle the failure and return the error to the
caller. So just do that instead, and add a WARN_ON() to make it easier
to notice the failure if it ever happens (which is particularly useful
for fstests, and the warning will trigger a failure of a test case).

Reviewed-by: Boris Burkov <boris@bur.io>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
  • Loading branch information
Filipe Manana authored and David Sterba committed Jun 21, 2022
1 parent 983d820 commit 650c9ca
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions fs/btrfs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -2718,7 +2718,8 @@ int btrfs_replace_file_extents(struct btrfs_inode *inode,

ret = btrfs_block_rsv_migrate(&fs_info->trans_block_rsv, rsv,
min_size, false);
BUG_ON(ret);
if (WARN_ON(ret))
goto out_trans;
trans->block_rsv = rsv;

cur_offset = start;
Expand Down Expand Up @@ -2837,7 +2838,8 @@ int btrfs_replace_file_extents(struct btrfs_inode *inode,

ret = btrfs_block_rsv_migrate(&fs_info->trans_block_rsv,
rsv, min_size, false);
BUG_ON(ret); /* shouldn't happen */
if (WARN_ON(ret))
break;
trans->block_rsv = rsv;

cur_offset = drop_args.drop_end;
Expand Down

0 comments on commit 650c9ca

Please sign in to comment.