diff options
author | Josef Bacik <jbacik@fb.com> | 2014-03-06 19:01:07 -0500 |
---|---|---|
committer | Chris Mason <clm@fb.com> | 2014-03-20 20:15:27 -0400 |
commit | 3bbb24b20a8800158c33eca8564f432dd14d0bf3 (patch) | |
tree | 502204ad927a0b743a3c0649fd7a79d644f5f6bc | |
parent | 573bfb72f7608eb7097d2dd036a714a6ab20cffe (diff) |
Btrfs: fix deadlock with nested trans handles
Zach found this deadlock that would happen like this
btrfs_end_transaction <- reduce trans->use_count to 0
btrfs_run_delayed_refs
btrfs_cow_block
find_free_extent
btrfs_start_transaction <- increase trans->use_count to 1
allocate chunk
btrfs_end_transaction <- decrease trans->use_count to 0
btrfs_run_delayed_refs
lock tree block we are cowing above ^^
We need to only decrease trans->use_count if it is above 1, otherwise leave it
alone. This will make nested trans be the only ones who decrease their added
ref, and will let us get rid of the trans->use_count++ hack if we have to commit
the transaction. Thanks,
cc: stable@vger.kernel.org
Reported-by: Zach Brown <zab@redhat.com>
Signed-off-by: Josef Bacik <jbacik@fb.com>
Tested-by: Zach Brown <zab@redhat.com>
Signed-off-by: Chris Mason <clm@fb.com>
-rw-r--r-- | fs/btrfs/transaction.c | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index a999b85d1176..a04707f740d6 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c | |||
@@ -683,7 +683,8 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans, | |||
683 | int lock = (trans->type != TRANS_JOIN_NOLOCK); | 683 | int lock = (trans->type != TRANS_JOIN_NOLOCK); |
684 | int err = 0; | 684 | int err = 0; |
685 | 685 | ||
686 | if (--trans->use_count) { | 686 | if (trans->use_count > 1) { |
687 | trans->use_count--; | ||
687 | trans->block_rsv = trans->orig_rsv; | 688 | trans->block_rsv = trans->orig_rsv; |
688 | return 0; | 689 | return 0; |
689 | } | 690 | } |
@@ -731,17 +732,10 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans, | |||
731 | } | 732 | } |
732 | 733 | ||
733 | if (lock && ACCESS_ONCE(cur_trans->state) == TRANS_STATE_BLOCKED) { | 734 | if (lock && ACCESS_ONCE(cur_trans->state) == TRANS_STATE_BLOCKED) { |
734 | if (throttle) { | 735 | if (throttle) |
735 | /* | ||
736 | * We may race with somebody else here so end up having | ||
737 | * to call end_transaction on ourselves again, so inc | ||
738 | * our use_count. | ||
739 | */ | ||
740 | trans->use_count++; | ||
741 | return btrfs_commit_transaction(trans, root); | 736 | return btrfs_commit_transaction(trans, root); |
742 | } else { | 737 | else |
743 | wake_up_process(info->transaction_kthread); | 738 | wake_up_process(info->transaction_kthread); |
744 | } | ||
745 | } | 739 | } |
746 | 740 | ||
747 | if (trans->type & __TRANS_FREEZABLE) | 741 | if (trans->type & __TRANS_FREEZABLE) |