aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosef Bacik <josef@toxicpanda.com>2020-01-24 09:32:32 -0500
committerDavid Sterba <dsterba@suse.com>2020-02-10 14:40:30 +0100
commit60e400697a4e6dca29ae0b471578c72184ddd98a (patch)
treee24741d6af0ccf9c7011f81eb6e03eecdb2c41c7
parentcb59b067893eb52ff698fd8e4d41bfafc0626d12 (diff)
downloadbtrfs-next-60e400697a4e6dca29ae0b471578c72184ddd98a.tar.gz
btrfs: hold a ref on the root in create_subvol
We're creating the new root here, but we should hold the ref until after we've initialized the inode for it. 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/ioctl.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 5342e4a2bb9ad8..0e524f3eaa9f2c 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -672,10 +672,16 @@ static noinline int create_subvol(struct inode *dir,
btrfs_abort_transaction(trans, ret);
goto fail;
}
+ if (!btrfs_grab_fs_root(new_root)) {
+ ret = -ENOENT;
+ btrfs_abort_transaction(trans, ret);
+ goto fail;
+ }
btrfs_record_root_in_trans(trans, new_root);
ret = btrfs_create_subvol_root(trans, new_root, root, new_dirid);
+ btrfs_put_fs_root(new_root);
if (ret) {
/* We potentially lose an unused inode item here */
btrfs_abort_transaction(trans, ret);