linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Btrfs: fix the deadlock between the transaction attach and commit
@ 2013-02-08  6:55 Miao Xie
  2013-02-11 20:35 ` Josef Bacik
  2013-02-12 14:39 ` Josef Bacik
  0 siblings, 2 replies; 5+ messages in thread
From: Miao Xie @ 2013-02-08  6:55 UTC (permalink / raw)
  To: Linux Btrfs

Here is the whole story:
	Trans_Attach_Task		Trans_Commit_Task
					btrfs_commit_transaction()
					 |->wait writers to be 1
	btrfs_attach_transaction()	 |
	btrfs_commit_transaction()	 |
	 |				 |->set trans_no_join to 1
	 |				 |  (close join transaction)
	 |->btrfs_run_ordered_operations |
	    (Those ordered operations	 |
	     are added when releasing	 |
	     file)			 |
	     |->btrfs_join_transaction() |
		|->wait_commit()	 |
					 |->wait writers to be 1

Then these two tasks waited for each other.

As we know, btrfs_attach_transaction() is used to catch the current
transaction, and commit it, so if someone has committed the transaction,
it is unnecessary to join it and commit it, wait is the best choice
for it. In this way, we can fix the above problem.

Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
---
 fs/btrfs/transaction.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index f154946..7be9d5e 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -285,6 +285,14 @@ static int may_wait_transaction(struct btrfs_root *root, int type)
 	if (type == TRANS_USERSPACE)
 		return 1;
 
+	/*
+	 * If we are ATTACH, it means we just want to catch the current
+	 * transaction and commit it. So if someone is committing the
+	 * current transaction now, it is very glad to wait it.
+	 */
+	if (type == TRANS_ATTACH)
+		return 1;
+
 	if (type == TRANS_START &&
 	    !atomic_read(&root->fs_info->open_ioctl_trans))
 		return 1;
-- 
1.6.5.2

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-02-18 10:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-02-08  6:55 [PATCH] Btrfs: fix the deadlock between the transaction attach and commit Miao Xie
2013-02-11 20:35 ` Josef Bacik
2013-02-12 12:56   ` David Sterba
2013-02-18 10:36     ` Miao Xie
2013-02-12 14:39 ` Josef Bacik

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).