Skip to content

Commit be1a556

Browse files
Mark Fashehkdave
authored andcommitted
btrfs: Don't BUG_ON() errors in update_ref_for_cow()
The only caller of update_ref_for_cow() is __btrfs_cow_block() which was originally ignoring any return values. update_ref_for_cow() however doesn't look like a candidate to become a void function - there are a few places where errors can occur. So instead I changed update_ref_for_cow() to bubble all errors up (instead of BUG_ON). __btrfs_cow_block() was then updated to catch and BUG_ON() any errors from update_ref_for_cow(). The end effect is that we have no change in behavior, but about 8 different places where a BUG_ON(ret) was removed. Obviously a future patch will have to address the BUG_ON() in __btrfs_cow_block(). Signed-off-by: Mark Fasheh <[email protected]>
1 parent ce59897 commit be1a556

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

fs/btrfs/ctree.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,8 @@ static noinline int update_ref_for_cow(struct btrfs_trans_handle *trans,
331331
if (btrfs_block_can_be_shared(root, buf)) {
332332
ret = btrfs_lookup_extent_info(trans, root, buf->start,
333333
buf->len, &refs, &flags);
334-
BUG_ON(ret);
334+
if (ret)
335+
return ret;
335336
BUG_ON(refs == 0);
336337
} else {
337338
refs = 1;
@@ -375,7 +376,8 @@ static noinline int update_ref_for_cow(struct btrfs_trans_handle *trans,
375376
buf->start,
376377
buf->len,
377378
new_flags, 0);
378-
BUG_ON(ret);
379+
if (ret)
380+
return ret;
379381
}
380382
} else {
381383
if (flags & BTRFS_BLOCK_FLAG_FULL_BACKREF) {
@@ -415,7 +417,7 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
415417
{
416418
struct btrfs_disk_key disk_key;
417419
struct extent_buffer *cow;
418-
int level;
420+
int level, ret;
419421
int last_ref = 0;
420422
int unlock_orig = 0;
421423
u64 parent_start;
@@ -467,7 +469,8 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
467469
(unsigned long)btrfs_header_fsid(cow),
468470
BTRFS_FSID_SIZE);
469471

470-
update_ref_for_cow(trans, root, buf, cow, &last_ref);
472+
ret = update_ref_for_cow(trans, root, buf, cow, &last_ref);
473+
BUG_ON(ret);
471474

472475
if (root->ref_cows)
473476
btrfs_reloc_cow_block(trans, root, buf, cow);

0 commit comments

Comments
 (0)