Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

btrfs: abort transaction on btrfs_reloc_cow_block()

When btrfs_reloc_cow_block() failed in __btrfs_cow_block(), current
code just return a err-value to caller, but leave new_created extent
buffer exist and locked.

Then subsequent code (in relocate) try to lock above eb again,
and caused deadlock without any dmesg.
(eb lock use wait_event(), so no lockdep message)

It is hard to do recover work in __btrfs_cow_block() at this error
point, but we can abort transaction to avoid deadlock and operate on
unstable state.a

It also helps developer to find wrong place quickly.
(better than a frozen fs without any dmesg before patch)

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: Chris Mason <clm@fb.com>

authored by

Zhaolei and committed by
Chris Mason
93314e3b 147d256e

+3 -1
+3 -1
fs/btrfs/ctree.c
··· 1159 1159 1160 1160 if (test_bit(BTRFS_ROOT_REF_COWS, &root->state)) { 1161 1161 ret = btrfs_reloc_cow_block(trans, root, buf, cow); 1162 - if (ret) 1162 + if (ret) { 1163 + btrfs_abort_transaction(trans, root, ret); 1163 1164 return ret; 1165 + } 1164 1166 } 1165 1167 1166 1168 if (buf == root->node) {