Commit 4cdfd930 authored by Josef Bacik's avatar Josef Bacik Committed by David Sterba

btrfs: handle NULL roots in btrfs_put/btrfs_grab_fs_root

We want to use this for dropping all roots, and in some error cases we
may not have a root, so handle this to make the cleanup code easier.
Make btrfs_grab_fs_root the same so we can use it in cases where the
root may not exist (like the quota root).
Reviewed-by: default avatarNikolay Borisov <nborisov@suse.com>
Signed-off-by: default avatarJosef Bacik <josef@toxicpanda.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent a98db0f3
...@@ -88,6 +88,8 @@ struct btrfs_root *btrfs_alloc_dummy_root(struct btrfs_fs_info *fs_info); ...@@ -88,6 +88,8 @@ struct btrfs_root *btrfs_alloc_dummy_root(struct btrfs_fs_info *fs_info);
*/ */
static inline struct btrfs_root *btrfs_grab_fs_root(struct btrfs_root *root) static inline struct btrfs_root *btrfs_grab_fs_root(struct btrfs_root *root)
{ {
if (!root)
return NULL;
if (refcount_inc_not_zero(&root->refs)) if (refcount_inc_not_zero(&root->refs))
return root; return root;
return NULL; return NULL;
...@@ -95,6 +97,8 @@ static inline struct btrfs_root *btrfs_grab_fs_root(struct btrfs_root *root) ...@@ -95,6 +97,8 @@ static inline struct btrfs_root *btrfs_grab_fs_root(struct btrfs_root *root)
static inline void btrfs_put_fs_root(struct btrfs_root *root) static inline void btrfs_put_fs_root(struct btrfs_root *root)
{ {
if (!root)
return;
if (refcount_dec_and_test(&root->refs)) if (refcount_dec_and_test(&root->refs))
kfree(root); kfree(root);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment