[14/44] btrfs: hold a ref for the root in record_one_backref
diff mbox series

Message ID 20191206144538.168112-15-josef@toxicpanda.com
State New
Headers show
Series
  • Cleanup how we handle root refs, part 1
Related show

Commit Message

Josef Bacik Dec. 6, 2019, 2:45 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(-)

Patch
diff mbox series

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;