diff mbox series

[14/45] btrfs: hold a ref for the root in record_one_backref

Message ID 20191217153635.44733-15-josef@toxicpanda.com (mailing list archive)
State New, archived
Headers show
Series Cleanup how we handle root refs, part 1 | expand

Commit Message

Josef Bacik Dec. 17, 2019, 3:36 p.m. UTC
We're looking up in an arbitrary root, we need to hold a ref on that
root.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/inode.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 138c21f5ed12..88f3d6eace7a 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -2523,6 +2523,8 @@  static noinline int record_one_backref(u64 inum, u64 offset, u64 root_id,
 			 inum, offset, root_id);
 		return PTR_ERR(root);
 	}
+	if (!btrfs_grab_fs_root(root))
+		return 0;
 
 	key.objectid = inum;
 	key.type = BTRFS_EXTENT_DATA_KEY;
@@ -2532,8 +2534,10 @@  static noinline int record_one_backref(u64 inum, u64 offset, u64 root_id,
 		key.offset = offset;
 
 	ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
-	if (WARN_ON(ret < 0))
+	if (WARN_ON(ret < 0)) {
+		btrfs_put_fs_root(root);
 		return ret;
+	}
 	ret = 0;
 
 	while (1) {
@@ -2603,6 +2607,7 @@  static noinline int record_one_backref(u64 inum, u64 offset, u64 root_id,
 	backref_insert(&new->root, backref);
 	old->count++;
 out:
+	btrfs_put_fs_root(root);
 	btrfs_release_path(path);
 	WARN_ON(ret);
 	return ret;