summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosef Bacik <josef@toxicpanda.com>2020-01-24 09:32:30 -0500
committerDavid Sterba <dsterba@suse.com>2020-03-23 17:01:27 +0100
commit02162a0265eb56742442ef42c58db8739ddd9b94 (patch)
tree812ea11083b5419dd09e061959b7b52b87b0553c
parentbdf70b9e75f54a04941dc450abe61694e03fead4 (diff)
downloadlinux-02162a0265eb56742442ef42c58db8739ddd9b94.tar.bz2
btrfs: hold a ref on the root in __btrfs_run_defrag_inode
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> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r--fs/btrfs/file.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 1bc7665f8ff0..27237bbaad65 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -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;