@@ -682,10 +682,6 @@ noinline int btrfs_cow_block(struct btrfs_trans_handle *trans,
u64 search_start;
int ret;
- if (test_bit(BTRFS_ROOT_DELETING, &root->state))
- btrfs_err(fs_info,
- "COW'ing blocks on a fs root that's being dropped");
-
/*
* COWing must happen through a running transaction, which always
* matches the current fs generation (it's a transaction with a state
@@ -703,6 +699,14 @@ noinline int btrfs_cow_block(struct btrfs_trans_handle *trans,
return -EUCLEAN;
}
+ if (unlikely(test_bit(BTRFS_ROOT_DELETING, &root->state))) {
+ btrfs_abort_transaction(trans, -EUCLEAN);
+ btrfs_crit(fs_info,
+ "attempt to COW block %llu on root %llu that is being deleted",
+ buf->start, btrfs_root_id(root));
+ return -EUCLEAN;
+ }
+
if (!should_cow_block(trans, root, buf)) {
*cow_ret = buf;
return 0;