]> git.hungrycats.org Git - linux/commitdiff
btrfs: hold a ref on the root in __btrfs_run_defrag_inode
authorJosef Bacik <josef@toxicpanda.com>
Wed, 20 Nov 2019 16:00:25 +0000 (08:00 -0800)
committerJosef Bacik <josef@toxicpanda.com>
Fri, 6 Dec 2019 16:34:48 +0000 (08:34 -0800)
We are looking up an arbitrary inode, we need to hold a ref on the root
while we're doing this.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
fs/btrfs/file.c

index 8baa1b44d514cb0419e75ef14af3a9f5296afaf1..f8e16f44a97069cee9a7ac62d9bb5429e6640281 100644 (file)
@@ -292,11 +292,16 @@ static int __btrfs_run_defrag_inode(struct btrfs_fs_info *fs_info,
                ret = PTR_ERR(inode_root);
                goto cleanup;
        }
+       if (!btrfs_grab_fs_root(inode_root)) {
+               ret = -ENOENT;
+               goto cleanup;
+       }
 
        key.objectid = defrag->ino;
        key.type = BTRFS_INODE_ITEM_KEY;
        key.offset = 0;
        inode = btrfs_iget(fs_info->sb, &key, inode_root);
+       btrfs_put_fs_root(inode_root);
        if (IS_ERR(inode)) {
                ret = PTR_ERR(inode);
                goto cleanup;