aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorJosef Bacik <jbacik@fusionio.com>2013-01-30 16:03:59 -0500
committerJosef Bacik <jbacik@fusionio.com>2013-02-20 12:59:27 -0500
commiteb12db690c7eb0f6593ba5792f5861409e88bc03 (patch)
tree598ead6ef59b9e511ec5bfe94e8fdbe52db551bf /fs
parent063d006fa06fbf73fab370921120380333a33e85 (diff)
Btrfs: fix freeing delayed ref head while still holding its mutex
I hit this error when reproducing a bug that would end in a transaction abort. We take the delayed ref head's mutex to keep anybody from processing it while we're destroying it, but we fail to drop the mutex before we carry on and free the damned thing. Fix this by doing the remove logic for the head ourselves and unlock the mutex, that way we can avoid use after free's or hung tasks waiting on that mutex to come back so they know the delayed ref completed. Thanks, Signed-off-by: Josef Bacik <jbacik@fusionio.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/btrfs/disk-io.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index bd48bf21118e..8140cb01951f 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -3615,11 +3615,11 @@ int btrfs_destroy_delayed_refs(struct btrfs_transaction *trans,
3615 } 3615 }
3616 3616
3617 while ((node = rb_first(&delayed_refs->root)) != NULL) { 3617 while ((node = rb_first(&delayed_refs->root)) != NULL) {
3618 ref = rb_entry(node, struct btrfs_delayed_ref_node, rb_node); 3618 struct btrfs_delayed_ref_head *head = NULL;
3619 3619
3620 ref = rb_entry(node, struct btrfs_delayed_ref_node, rb_node);
3620 atomic_set(&ref->refs, 1); 3621 atomic_set(&ref->refs, 1);
3621 if (btrfs_delayed_ref_is_head(ref)) { 3622 if (btrfs_delayed_ref_is_head(ref)) {
3622 struct btrfs_delayed_ref_head *head;
3623 3623
3624 head = btrfs_delayed_node_to_head(ref); 3624 head = btrfs_delayed_node_to_head(ref);
3625 if (!mutex_trylock(&head->mutex)) { 3625 if (!mutex_trylock(&head->mutex)) {
@@ -3641,10 +3641,12 @@ int btrfs_destroy_delayed_refs(struct btrfs_transaction *trans,
3641 delayed_refs->num_heads_ready--; 3641 delayed_refs->num_heads_ready--;
3642 list_del_init(&head->cluster); 3642 list_del_init(&head->cluster);
3643 } 3643 }
3644
3644 ref->in_tree = 0; 3645 ref->in_tree = 0;
3645 rb_erase(&ref->rb_node, &delayed_refs->root); 3646 rb_erase(&ref->rb_node, &delayed_refs->root);
3646 delayed_refs->num_entries--; 3647 delayed_refs->num_entries--;
3647 3648 if (head)
3649 mutex_unlock(&head->mutex);
3648 spin_unlock(&delayed_refs->lock); 3650 spin_unlock(&delayed_refs->lock);
3649 btrfs_put_delayed_ref(ref); 3651 btrfs_put_delayed_ref(ref);
3650 3652