summaryrefslogtreecommitdiffstats
path: root/fs/btrfs
diff options
context:
space:
mode:
authorChris Mason <clm@fb.com>2016-04-27 09:59:38 -0400
committerChris Mason <clm@fb.com>2016-06-22 17:54:18 -0700
commit0f873eca82a0bee45f38862e0ea2ac7b1c2a31bd (patch)
tree75b28a6c1e173e4a36e63d90b2e6122699158d01 /fs/btrfs
parent31b9655f439a26856edca0f3f8daa368a61f16d5 (diff)
downloadlinux-0f873eca82a0bee45f38862e0ea2ac7b1c2a31bd.tar.gz
linux-0f873eca82a0bee45f38862e0ea2ac7b1c2a31bd.tar.bz2
linux-0f873eca82a0bee45f38862e0ea2ac7b1c2a31bd.zip
btrfs: fix deadlock in delayed_ref_async_start
"Btrfs: track transid for delayed ref flushing" was deadlocking on btrfs_attach_transaction because its not safe to call from the async delayed ref start code. This commit brings back btrfs_join_transaction instead and checks for a blocked commit. Signed-off-by: Josef Bacik <jbacik@fb.com> Signed-off-by: Chris Mason <clm@fb.com>
Diffstat (limited to 'fs/btrfs')
-rw-r--r--fs/btrfs/extent-tree.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index ecfa52002363..82b912a293ab 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -2851,16 +2851,13 @@ static void delayed_ref_async_start(struct btrfs_work *work)
async = container_of(work, struct async_delayed_refs, work);
- trans = btrfs_attach_transaction(async->root);
- if (IS_ERR(trans)) {
- if (PTR_ERR(trans) != -ENOENT)
- async->error = PTR_ERR(trans);
+ /* if the commit is already started, we don't need to wait here */
+ if (btrfs_transaction_blocked(async->root->fs_info))
goto done;
- }
- /* Don't bother flushing if we got into a different transaction */
- if (trans->transid != async->transid) {
- btrfs_end_transaction(trans, async->root);
+ trans = btrfs_join_transaction(async->root);
+ if (IS_ERR(trans)) {
+ async->error = PTR_ERR(trans);
goto done;
}
@@ -2869,10 +2866,15 @@ static void delayed_ref_async_start(struct btrfs_work *work)
* wait on delayed refs
*/
trans->sync = true;
+
+ /* Don't bother flushing if we got into a different transaction */
+ if (trans->transid > async->transid)
+ goto end;
+
ret = btrfs_run_delayed_refs(trans, async->root, async->count);
if (ret)
async->error = ret;
-
+end:
ret = btrfs_end_transaction(trans, async->root);
if (ret && !async->error)
async->error = ret;