aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosef Bacik <josef@toxicpanda.com>2020-01-24 09:32:30 -0500
committerDavid Sterba <dsterba@suse.com>2020-02-10 14:40:29 +0100
commit5f526def3313a6f2536b1fb27f721f6f67288496 (patch)
tree1022d3605dae64ba6ec33c843a5ec6176cce2ea6
parentbf34b1a99de01cf4580e4dd7aeec58d1c1e58da0 (diff)
downloadbtrfs-next-5f526def3313a6f2536b1fb27f721f6f67288496.tar.gz
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 746d569d234e62..ae8b3765658e50 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;