Skip to content

Commit 692826b

Browse files
jeffmahoneykdave
authored andcommitted
btrfs: handle errors while updating refcounts in update_ref_for_cow
Since commit fb235dc (btrfs: qgroup: Move half of the qgroup accounting time out of commit trans) the assumption that btrfs_add_delayed_{data,tree}_ref can only return 0 or -ENOMEM has been false. The qgroup operations call into btrfs_search_slot and friends and can now return the full spectrum of error codes. Fortunately, the fix here is easy since update_ref_for_cow failing is already handled so we just need to bail early with the error code. Fixes: fb235dc (btrfs: qgroup: Move half of the qgroup accounting ...) Cc: <[email protected]> # v4.11+ Signed-off-by: Jeff Mahoney <[email protected]> Reviewed-by: Edmund Nadolski <[email protected]> Reviewed-by: Qu Wenruo <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent b430b77 commit 692826b

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

fs/btrfs/ctree.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,14 +1032,17 @@ static noinline int update_ref_for_cow(struct btrfs_trans_handle *trans,
10321032
root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) &&
10331033
!(flags & BTRFS_BLOCK_FLAG_FULL_BACKREF)) {
10341034
ret = btrfs_inc_ref(trans, root, buf, 1);
1035-
BUG_ON(ret); /* -ENOMEM */
1035+
if (ret)
1036+
return ret;
10361037

10371038
if (root->root_key.objectid ==
10381039
BTRFS_TREE_RELOC_OBJECTID) {
10391040
ret = btrfs_dec_ref(trans, root, buf, 0);
1040-
BUG_ON(ret); /* -ENOMEM */
1041+
if (ret)
1042+
return ret;
10411043
ret = btrfs_inc_ref(trans, root, cow, 1);
1042-
BUG_ON(ret); /* -ENOMEM */
1044+
if (ret)
1045+
return ret;
10431046
}
10441047
new_flags |= BTRFS_BLOCK_FLAG_FULL_BACKREF;
10451048
} else {
@@ -1049,7 +1052,8 @@ static noinline int update_ref_for_cow(struct btrfs_trans_handle *trans,
10491052
ret = btrfs_inc_ref(trans, root, cow, 1);
10501053
else
10511054
ret = btrfs_inc_ref(trans, root, cow, 0);
1052-
BUG_ON(ret); /* -ENOMEM */
1055+
if (ret)
1056+
return ret;
10531057
}
10541058
if (new_flags != 0) {
10551059
int level = btrfs_header_level(buf);
@@ -1068,9 +1072,11 @@ static noinline int update_ref_for_cow(struct btrfs_trans_handle *trans,
10681072
ret = btrfs_inc_ref(trans, root, cow, 1);
10691073
else
10701074
ret = btrfs_inc_ref(trans, root, cow, 0);
1071-
BUG_ON(ret); /* -ENOMEM */
1075+
if (ret)
1076+
return ret;
10721077
ret = btrfs_dec_ref(trans, root, buf, 1);
1073-
BUG_ON(ret); /* -ENOMEM */
1078+
if (ret)
1079+
return ret;
10741080
}
10751081
clean_tree_block(fs_info, buf);
10761082
*last_ref = 1;

0 commit comments

Comments
 (0)