diff mbox series

[17/44] btrfs: hold a ref on the root in btrfs_search_path_in_tree

Message ID 20200124143301.2186319-18-josef@toxicpanda.com (mailing list archive)
State New, archived
Headers show
Series Cleanup how we handle root refs, part 1 | expand

Commit Message

Josef Bacik Jan. 24, 2020, 2:32 p.m. UTC
We look up an arbitrary fs root, we need to hold a ref on it while we're
doing our search.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/ioctl.c | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

David Sterba Feb. 5, 2020, 2:30 p.m. UTC | #1
On Fri, Jan 24, 2020 at 09:32:34AM -0500, Josef Bacik wrote:
> We look up an arbitrary fs root, we need to hold a ref on it while we're
> doing our search.
> 
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>
> ---
>  fs/btrfs/ioctl.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
> index 62dd06b65686..c721b4fce1c0 100644
> --- a/fs/btrfs/ioctl.c
> +++ b/fs/btrfs/ioctl.c
> @@ -2328,6 +2328,12 @@ static noinline int btrfs_search_path_in_tree(struct btrfs_fs_info *info,
>  	root = btrfs_get_fs_root(info, &key, true);
>  	if (IS_ERR(root)) {
>  		ret = PTR_ERR(root);
> +		root = NULL;
> +		goto out;
> +	}
> +	if (!btrfs_grab_fs_root(root)) {
> +		ret = -ENOENT;
> +		root = NULL;
>  		goto out;
>  	}
>  
> @@ -2378,6 +2384,8 @@ static noinline int btrfs_search_path_in_tree(struct btrfs_fs_info *info,
>  	name[total_len] = '\0';
>  	ret = 0;
>  out:
> +	if (root)
> +		btrfs_put_fs_root(root);

The NULL check is not necessary, you added that into btrfs_put_fs_root
and I think it's readable without it here.

>  	btrfs_free_path(path);
>  	return ret;
>  }
> -- 
> 2.24.1
diff mbox series

Patch

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 62dd06b65686..c721b4fce1c0 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -2328,6 +2328,12 @@  static noinline int btrfs_search_path_in_tree(struct btrfs_fs_info *info,
 	root = btrfs_get_fs_root(info, &key, true);
 	if (IS_ERR(root)) {
 		ret = PTR_ERR(root);
+		root = NULL;
+		goto out;
+	}
+	if (!btrfs_grab_fs_root(root)) {
+		ret = -ENOENT;
+		root = NULL;
 		goto out;
 	}
 
@@ -2378,6 +2384,8 @@  static noinline int btrfs_search_path_in_tree(struct btrfs_fs_info *info,
 	name[total_len] = '\0';
 	ret = 0;
 out:
+	if (root)
+		btrfs_put_fs_root(root);
 	btrfs_free_path(path);
 	return ret;
 }