]> git.hungrycats.org Git - linux/commitdiff
btrfs: hold a ref for the root in record_one_backref
authorJosef Bacik <josef@toxicpanda.com>
Wed, 20 Nov 2019 16:04:36 +0000 (08:04 -0800)
committerJosef Bacik <josef@toxicpanda.com>
Fri, 6 Dec 2019 16:34:48 +0000 (08:34 -0800)
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

index 138c21f5ed120571503375bcf6eeaac5a732f27a..88f3d6eace7a31f31c31de0397a54a9d7bd28fde 100644 (file)
@@ -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;