Skip to content

Commit 650c9ca

Browse files
fdmananakdave
authored andcommitted
btrfs: do not BUG_ON() on failure to migrate space when replacing extents
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 <[email protected]> Signed-off-by: Filipe Manana <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 983d820 commit 650c9ca

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

fs/btrfs/file.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2718,7 +2718,8 @@ int btrfs_replace_file_extents(struct btrfs_inode *inode,
27182718

27192719
ret = btrfs_block_rsv_migrate(&fs_info->trans_block_rsv, rsv,
27202720
min_size, false);
2721-
BUG_ON(ret);
2721+
if (WARN_ON(ret))
2722+
goto out_trans;
27222723
trans->block_rsv = rsv;
27232724

27242725
cur_offset = start;
@@ -2837,7 +2838,8 @@ int btrfs_replace_file_extents(struct btrfs_inode *inode,
28372838

28382839
ret = btrfs_block_rsv_migrate(&fs_info->trans_block_rsv,
28392840
rsv, min_size, false);
2840-
BUG_ON(ret); /* shouldn't happen */
2841+
if (WARN_ON(ret))
2842+
break;
28412843
trans->block_rsv = rsv;
28422844

28432845
cur_offset = drop_args.drop_end;

0 commit comments

Comments
 (0)