linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Btrfs: convert to add transaction protection for btrfs send
@ 2014-01-29 15:32 Wang Shilong
  2014-01-29 15:32 ` Wang Shilong
  2014-01-29 19:00 ` Josef Bacik
  0 siblings, 2 replies; 16+ messages in thread
From: Wang Shilong @ 2014-01-29 15:32 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Wang Shilong, Josef Bacik

From: Wang Shilong <wangsl.fnst@cn.fujitsu.com>

I sent a patch to kick off transaction from btrfs send, however it gets
a regression that btrfs send try to search extent commit root without
transaction protection.

To fix this regression, we have two ideas:

 1. don't use extent commit root for sending.

 2. add transaction protection to use extent commit root safely.

Both approaches need transaction actually, however, the first approach
will add extent tree lock contention, so we'd better adopt the second
approach.

Luckily, now we only need transaction protection when iterating
extent root, the protection's *range* is smaller than before.

Cc: Josef Bacik <jbacik@fb.com>
Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
---
 fs/btrfs/send.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c
index 04c07ed..8d5e151 100644
--- a/fs/btrfs/send.c
+++ b/fs/btrfs/send.c
@@ -4511,6 +4511,7 @@ static int process_extent(struct send_ctx *sctx,
 			  struct btrfs_key *key)
 {
 	struct clone_root *found_clone = NULL;
+	struct btrfs_trans_handle *trans;
 	int ret = 0;
 
 	if (S_ISLNK(sctx->cur_inode_mode))
@@ -4551,10 +4552,24 @@ static int process_extent(struct send_ctx *sctx,
 			}
 		}
 	}
+	/*
+	 * We need to make sure the transaction does not get committed
+	 * while we are walking backrefs on extent commit root.
+	 */
+	trans = btrfs_join_transaction(sctx->send_root);
+	if (IS_ERR(trans)) {
+		ret = PTR_ERR(trans);
+		goto out;
+	}
 
 	ret = find_extent_clone(sctx, path, key->objectid, key->offset,
 			sctx->cur_inode_size, &found_clone);
-	if (ret != -ENOENT && ret < 0)
+	if (ret != -ENOENT && ret < 0) {
+		btrfs_end_transaction(trans, sctx->send_root);
+		goto out;
+	}
+	ret = btrfs_end_transaction(trans, sctx->send_root);
+	if (ret)
 		goto out;
 
 	ret = send_write_or_clone(sctx, path, key, found_clone);
-- 
1.8.4


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

end of thread, other threads:[~2014-02-08  3:07 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-29 15:32 [PATCH] Btrfs: convert to add transaction protection for btrfs send Wang Shilong
2014-01-29 15:32 ` Wang Shilong
2014-01-29 19:00 ` Josef Bacik
2014-01-30  9:42   ` Wang Shilong
2014-01-30 16:08     ` Josef Bacik
2014-01-30 16:20       ` Wang Shilong
2014-01-30 16:23         ` Josef Bacik
2014-01-30 16:42           ` Wang Shilong
2014-01-31 16:37             ` Wang Shilong
2014-01-31 23:40               ` Josef Bacik
2014-02-03 21:31               ` Josef Bacik
2014-02-05  8:59                 ` Wang Shilong
2014-02-05 14:04                   ` Josef Bacik
2014-02-05 17:23                     ` Wang Shilong
2014-02-05 20:47                       ` Josef Bacik
2014-02-08  3:06                         ` Wang Shilong

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).