]> git.baikalelectronics.ru Git - kernel.git/commit
Btrfs: fix deadlock with nested trans handles
authorJosef Bacik <jbacik@fb.com>
Fri, 7 Mar 2014 00:01:07 +0000 (19:01 -0500)
committerChris Mason <clm@fb.com>
Fri, 21 Mar 2014 00:15:27 +0000 (17:15 -0700)
commit1fbd1f75afd269fed0e9bf49bc777a240160befa
tree502204ad927a0b743a3c0649fd7a79d644f5f6bc
parent12a1977ee9fc19ebbfdfff239270e2d97a692e24
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>
fs/btrfs/transaction.c