[PATCH 15/44] btrfs: grab a ref on the root in relink_extent_backref

Josef Bacik
2019-12-06T14:46:10Z

We're doing an arbitrary lookup on an fs_root, we need to hold a ref on
that root.

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

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 88f3d6eace7a..3dc9bc9530e2 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -2711,6 +2711,9 @@ static noinline int relink_extent_backref(struct btrfs_path *path,
return PTR_ERR(root);
}

+ if (!btrfs_grab_fs_root(root))
+ return 0;
+
if (btrfs_root_readonly(root)) {
srcu_read_unlock(&fs_info->subvol_srcu, index);
return 0;
@@ -2722,6 +2725,7 @@ static noinline int relink_extent_backref(struct btrfs_path *path,
key.offset = 0;

inode = btrfs_iget(fs_info->sb, &key, root);
+ btrfs_put_fs_root(root);
if (IS_ERR(inode)) {
srcu_read_unlock(&fs_info->subvol_srcu, index);
return 0;
--
2.23.0