linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Btrfs: pass lockdep rwsem metadata to async commit transaction
@ 2012-08-24 22:44 Sage Weil
  2012-08-24 22:47 ` Sage Weil
  0 siblings, 1 reply; 5+ messages in thread
From: Sage Weil @ 2012-08-24 22:44 UTC (permalink / raw)
  To: linux-btrfs

The freeze rwsem is taken by sb_start_intwrite() and dropped during the
commit_ or end_transaction().  In the async case, that happens in a worker
thread.  Tell lockdep the calling thread is releasing ownership of the
rwsem and the async thread is picking it up.

Josef and I worked out a more complicated solution that made the async 
commit thread join and potentially get a later transaction, but it failed 
my initial smoke test and Dave pointed out that XFS avoids the issue by 
just telling lockdep what's up.  This is much simpler.  XFS does the same
thing in fs/xfs/xfs_aops.c.

Signed-off-by: Sage Weil <sage@inktank.com>
---
 fs/btrfs/transaction.c |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index 17be3de..efc41a5 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -1228,6 +1228,14 @@ static void do_async_commit(struct work_struct *work)
 	struct btrfs_async_commit *ac =
 		container_of(work, struct btrfs_async_commit, work.work);
 
+	/*
+	 * We've got freeze protection passed with the transaction.
+	 * Tell lockdep about it.
+	 */
+	rwsem_acquire_read(
+		&ac->root->fs_info->sb->s_writers.lock_map[SB_FREEZE_FS-1],
+		0, 1, _THIS_IP_);
+
 	btrfs_commit_transaction(ac->newtrans, ac->root);
 	kfree(ac);
 }
@@ -1257,6 +1265,14 @@ int btrfs_commit_transaction_async(struct btrfs_trans_handle *trans,
 	atomic_inc(&cur_trans->use_count);
 
 	btrfs_end_transaction(trans, root);
+
+	/*
+	 * Tell lockdep we've released the freeze rwsem, since the
+	 * async commit thread will be the one to unlock it.
+	 */
+	rwsem_release(&root->fs_info->sb->s_writers.lock_map[SB_FREEZE_FS-1],
+		      1, _THIS_IP_);
+
 	schedule_delayed_work(&ac->work, 0);
 
 	/* wait for transaction to start and unblock */
-- 
1.7.9


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

end of thread, other threads:[~2012-08-27 22:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-24 22:44 [PATCH] Btrfs: pass lockdep rwsem metadata to async commit transaction Sage Weil
2012-08-24 22:47 ` Sage Weil
2012-08-26 21:13   ` Josef Bacik
2012-08-27 22:05     ` Sage Weil
2012-08-27 22:29       ` 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).