Skip to content

Commit a2caab2

Browse files
fdmananakdave
authored andcommitted
btrfs: error when COWing block from a root that is being deleted
At btrfs_cow_block() we check if the block being COWed belongs to a root that is being deleted and if so we log an error message. However this is an unexpected case and it indicates a bug somewhere, so we should return an error and abort the transaction. So change this in the following ways: 1) Abort the transaction with -EUCLEAN, so that if the issue ever happens it can easily be noticed; 2) Change the logged message level from error to critical, and change the message itself to print the block's logical address and the ID of the root; 3) Return -EUCLEAN to the caller; 4) As this is an unexpected scenario, that should never happen, mark the check as unlikely, allowing the compiler to potentially generate better code. Signed-off-by: Filipe Manana <fdmanana@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 48774f3 commit a2caab2

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

fs/btrfs/ctree.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -682,9 +682,13 @@ noinline int btrfs_cow_block(struct btrfs_trans_handle *trans,
682682
u64 search_start;
683683
int ret;
684684

685-
if (test_bit(BTRFS_ROOT_DELETING, &root->state))
686-
btrfs_err(fs_info,
687-
"COW'ing blocks on a fs root that's being dropped");
685+
if (unlikely(test_bit(BTRFS_ROOT_DELETING, &root->state))) {
686+
btrfs_abort_transaction(trans, -EUCLEAN);
687+
btrfs_crit(fs_info,
688+
"attempt to COW block %llu on root %llu that is being deleted",
689+
buf->start, btrfs_root_id(root));
690+
return -EUCLEAN;
691+
}
688692

689693
/*
690694
* COWing must happen through a running transaction, which always

0 commit comments

Comments
 (0)