From 4f9474a25905de165449c899f20f2db0fc39eae0 Mon Sep 17 00:00:00 2001 From: Josef Bacik Date: Fri, 14 Sep 2012 11:22:38 -0400 Subject: [PATCH] --- yaml --- r: 332575 b: refs/heads/master c: 98114659e0d467e2c0ee6f24f2429329328fc312 h: refs/heads/master i: 332573: 92398b424300456652235387591eab66f4decbff 332571: 9c61d8b92afb682092dc03ce6ad6e0cfe9943479 332567: b7bb3e161b853b43b0bdf4453e66888eb9446bd8 332559: cd630e9a8c55423f911bab62954d49f84e0f9b19 332543: b713f647912c12be11d881f46b2ea47b149cd17a v: v3 --- [refs] | 2 +- trunk/fs/btrfs/transaction.c | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/[refs] b/[refs] index 5908529d3d41..1175ea60ca2d 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 6bbe3a9c805fcb8cd8d396dafd32078181a7cdd5 +refs/heads/master: 98114659e0d467e2c0ee6f24f2429329328fc312 diff --git a/trunk/fs/btrfs/transaction.c b/trunk/fs/btrfs/transaction.c index c9265a603488..a4fe5494d01b 100644 --- a/trunk/fs/btrfs/transaction.c +++ b/trunk/fs/btrfs/transaction.c @@ -342,7 +342,15 @@ static struct btrfs_trans_handle *start_transaction(struct btrfs_root *root, if (!h) return ERR_PTR(-ENOMEM); - if (!__sb_start_write(root->fs_info->sb, SB_FREEZE_FS, false)) { + /* + * If we are JOIN_NOLOCK we're already committing a transaction and + * waiting on this guy, so we don't need to do the sb_start_intwrite + * because we're already holding a ref. We need this because we could + * have raced in and did an fsync() on a file which can kick a commit + * and then we deadlock with somebody doing a freeze. + */ + if (type != TRANS_JOIN_NOLOCK && + !__sb_start_write(root->fs_info->sb, SB_FREEZE_FS, false)) { if (type == TRANS_JOIN_FREEZE) return ERR_PTR(-EPERM); sb_start_intwrite(root->fs_info->sb); @@ -601,7 +609,8 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans, } } - sb_end_intwrite(root->fs_info->sb); + if (lock) + sb_end_intwrite(root->fs_info->sb); WARN_ON(cur_trans != info->running_transaction); WARN_ON(atomic_read(&cur_trans->num_writers) < 1);