]> git.hungrycats.org Git - linux/commitdiff
btrfs: hold a ref on the root in get_subvol_name_from_objectid
authorJosef Bacik <josef@toxicpanda.com>
Wed, 20 Nov 2019 20:25:30 +0000 (12:25 -0800)
committerJosef Bacik <josef@toxicpanda.com>
Fri, 6 Dec 2019 16:34:48 +0000 (08:34 -0800)
We lookup the name of a subvol which means we'll cross into different
roots.  Hold a ref while we're doing the look ups in the fs_root we're
searching.

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

index e387ca1ac0e54f5689540c92dba7df7d1144fcbd..9c50bee71de97e9314566513c3aaff6c8d542d59 100644 (file)
@@ -1082,6 +1082,10 @@ static char *get_subvol_name_from_objectid(struct btrfs_fs_info *fs_info,
                        ret = PTR_ERR(fs_root);
                        goto err;
                }
+               if (!btrfs_grab_fs_root(fs_root)) {
+                       ret = -ENOENT;
+                       goto err;
+               }
 
                /*
                 * Walk up the filesystem tree by inode refs until we hit the
@@ -1094,13 +1098,16 @@ static char *get_subvol_name_from_objectid(struct btrfs_fs_info *fs_info,
 
                        ret = btrfs_search_slot(NULL, fs_root, &key, path, 0, 0);
                        if (ret < 0) {
+                               btrfs_put_fs_root(fs_root);
                                goto err;
                        } else if (ret > 0) {
                                ret = btrfs_previous_item(fs_root, path, dirid,
                                                          BTRFS_INODE_REF_KEY);
                                if (ret < 0) {
+                                       btrfs_put_fs_root(fs_root);
                                        goto err;
                                } else if (ret > 0) {
+                                       btrfs_put_fs_root(fs_root);
                                        ret = -ENOENT;
                                        goto err;
                                }
@@ -1117,6 +1124,7 @@ static char *get_subvol_name_from_objectid(struct btrfs_fs_info *fs_info,
                        ptr -= len + 1;
                        if (ptr < name) {
                                ret = -ENAMETOOLONG;
+                               btrfs_put_fs_root(fs_root);
                                goto err;
                        }
                        read_extent_buffer(path->nodes[0], ptr + 1,
@@ -1124,6 +1132,7 @@ static char *get_subvol_name_from_objectid(struct btrfs_fs_info *fs_info,
                        ptr[0] = '/';
                        btrfs_release_path(path);
                }
+               btrfs_put_fs_root(fs_root);
        }
 
        btrfs_free_path(path);