On Fri, Jan 24, 2020 at 09:32:38AM -0500, Josef Bacik wrote:
> This is trickier than the previous conversions. We have backref_node's
> that need to hold onto their root for their lifetime. Do the read of
> the root and grab the ref. If at any point we don't use the root we
> discard it, however if we use it in our backref node we don't free it
> until we free the backref node. Any time we switch the root's for the
> backref node we need to drop our ref on the old root and grab the ref on
> the new root, and if we dupe a node we need to get a ref on the root
> there as well.
>
> Signed-off-by: Josef Bacik <josef@xxxxxxxxxxxxxx>
> ---
> fs/btrfs/relocation.c | 39 ++++++++++++++++++++++++++++++---------
> 1 file changed, 30 insertions(+), 9 deletions(-)
>
> diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
> index aa3aa8e0c0ea..990595a27a15 100644
> --- a/fs/btrfs/relocation.c
> +++ b/fs/btrfs/relocation.c
> @@ -256,6 +256,8 @@ static void free_backref_node(struct backref_cache *cache,
> {
> if (node) {
> cache->nr_nodes--;
> + if (node->root)
> + btrfs_put_fs_root(node->root);
And here the check can be dropped too, to be consistent with the rest.
> kfree(node);
> }
> }