We're looking up in an arbitrary root, we need to hold a ref on that
root.
Signed-off-by: Josef Bacik <josef@xxxxxxxxxxxxxx>
---
fs/btrfs/inode.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
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;
--
2.23.0