]> git.hungrycats.org Git - linux/commitdiff
btrfs: hold a ref on the root in create_subvol
authorJosef Bacik <josef@toxicpanda.com>
Wed, 20 Nov 2019 18:39:24 +0000 (10:39 -0800)
committerJosef Bacik <josef@toxicpanda.com>
Fri, 6 Dec 2019 16:34:48 +0000 (08:34 -0800)
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>
fs/btrfs/ioctl.c

index 95b0488b7da6de6b4ca51533cfda14af6e4b95a5..29c363a70fe7a4f3ca1c8e19e7ccf638c1e8a4b3 100644 (file)
@@ -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);