ec46089
From: Josh Boyer <jwboyer@fedoraproject.org>
ec46089
Date: Wed, 15 Oct 2014 10:09:50 -0400
ec46089
Subject: [PATCH] Revert "Btrfs: race free update of commit root for ro
ec46089
 snapshots"
ec46089
ec46089
This reverts commit 9c3b306e1c9e6be4be09e99a8fe2227d1005effc.
ec46089
---
ec46089
 fs/btrfs/inode.c | 36 ------------------------------------
ec46089
 fs/btrfs/ioctl.c | 33 +++++++++++++++++++++++++++++++++
ec46089
 2 files changed, 33 insertions(+), 36 deletions(-)
ec46089
ec46089
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
ec46089
index fc9c0439caa3..d23362f4464e 100644
ec46089
--- a/fs/btrfs/inode.c
ec46089
+++ b/fs/btrfs/inode.c
ec46089
@@ -5261,42 +5261,6 @@ struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry)
ec46089
 			iput(inode);
ec46089
 			inode = ERR_PTR(ret);
ec46089
 		}
ec46089
-		/*
ec46089
-		 * If orphan cleanup did remove any orphans, it means the tree
ec46089
-		 * was modified and therefore the commit root is not the same as
ec46089
-		 * the current root anymore. This is a problem, because send
ec46089
-		 * uses the commit root and therefore can see inode items that
ec46089
-		 * don't exist in the current root anymore, and for example make
ec46089
-		 * calls to btrfs_iget, which will do tree lookups based on the
ec46089
-		 * current root and not on the commit root. Those lookups will
ec46089
-		 * fail, returning a -ESTALE error, and making send fail with
ec46089
-		 * that error. So make sure a send does not see any orphans we
ec46089
-		 * have just removed, and that it will see the same inodes
ec46089
-		 * regardless of whether a transaction commit happened before
ec46089
-		 * it started (meaning that the commit root will be the same as
ec46089
-		 * the current root) or not.
ec46089
-		 */
ec46089
-		if (sub_root->node != sub_root->commit_root) {
ec46089
-			u64 sub_flags = btrfs_root_flags(&sub_root->root_item);
ec46089
-
ec46089
-			if (sub_flags & BTRFS_ROOT_SUBVOL_RDONLY) {
ec46089
-				struct extent_buffer *eb;
ec46089
-
ec46089
-				/*
ec46089
-				 * Assert we can't have races between dentry
ec46089
-				 * lookup called through the snapshot creation
ec46089
-				 * ioctl and the VFS.
ec46089
-				 */
ec46089
-				ASSERT(mutex_is_locked(&dir->i_mutex));
ec46089
-
ec46089
-				down_write(&root->fs_info->commit_root_sem);
ec46089
-				eb = sub_root->commit_root;
ec46089
-				sub_root->commit_root =
ec46089
-					btrfs_root_node(sub_root);
ec46089
-				up_write(&root->fs_info->commit_root_sem);
ec46089
-				free_extent_buffer(eb);
ec46089
-			}
ec46089
-		}
ec46089
 	}
ec46089
 
ec46089
 	return inode;
ec46089
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
ec46089
index 0fe1aa047f15..8d2b76e29d3b 100644
ec46089
--- a/fs/btrfs/ioctl.c
ec46089
+++ b/fs/btrfs/ioctl.c
ec46089
@@ -713,6 +713,39 @@ static int create_snapshot(struct btrfs_root *root, struct inode *dir,
ec46089
 	if (ret)
ec46089
 		goto fail;
ec46089
 
ec46089
+	ret = btrfs_orphan_cleanup(pending_snapshot->snap);
ec46089
+	if (ret)
ec46089
+		goto fail;
ec46089
+
ec46089
+	/*
ec46089
+	 * If orphan cleanup did remove any orphans, it means the tree was
ec46089
+	 * modified and therefore the commit root is not the same as the
ec46089
+	 * current root anymore. This is a problem, because send uses the
ec46089
+	 * commit root and therefore can see inode items that don't exist
ec46089
+	 * in the current root anymore, and for example make calls to
ec46089
+	 * btrfs_iget, which will do tree lookups based on the current root
ec46089
+	 * and not on the commit root. Those lookups will fail, returning a
ec46089
+	 * -ESTALE error, and making send fail with that error. So make sure
ec46089
+	 * a send does not see any orphans we have just removed, and that it
ec46089
+	 * will see the same inodes regardless of whether a transaction
ec46089
+	 * commit happened before it started (meaning that the commit root
ec46089
+	 * will be the same as the current root) or not.
ec46089
+	 */
ec46089
+	if (readonly && pending_snapshot->snap->node !=
ec46089
+	    pending_snapshot->snap->commit_root) {
ec46089
+		trans = btrfs_join_transaction(pending_snapshot->snap);
ec46089
+		if (IS_ERR(trans) && PTR_ERR(trans) != -ENOENT) {
ec46089
+			ret = PTR_ERR(trans);
ec46089
+			goto fail;
ec46089
+		}
ec46089
+		if (!IS_ERR(trans)) {
ec46089
+			ret = btrfs_commit_transaction(trans,
ec46089
+						       pending_snapshot->snap);
ec46089
+			if (ret)
ec46089
+				goto fail;
ec46089
+		}
ec46089
+	}
ec46089
+
ec46089
 	inode = btrfs_lookup_dentry(dentry->d_parent->d_inode, dentry);
ec46089
 	if (IS_ERR(inode)) {
ec46089
 		ret = PTR_ERR(inode);
ec46089
-- 
ec46089
1.9.3
ec46089