On 13.05.19 15:46, Alberto Garcia wrote:
> A consequence of the previous patch is that bdrv_attach_child()
> transfers the reference to child_bs from the caller to parent_bs,
> which will drop it on bdrv_close() or when someone calls
> bdrv_unref_child().
> 
> But this only happens when bdrv_attach_child() succeeds. If it fails
> then the caller is responsible for dropping the reference to child_bs.
> 
> This patch makes bdrv_attach_child() take the reference also when
> there is an error, freeing the caller for having to do it.
> 
> A similar situation happens with bdrv_root_attach_child(), so the
> changes on this patch affect both functions.
> 
> Signed-off-by: Alberto Garcia <be...@igalia.com>
> ---
>  block.c               | 25 +++++++++++++++++--------
>  block/block-backend.c |  3 +--
>  block/quorum.c        |  1 -
>  blockjob.c            |  2 +-
>  4 files changed, 19 insertions(+), 12 deletions(-)
> 
> diff --git a/block.c b/block.c
> index 3c3bd0f8d2..df727314ff 100644
> --- a/block.c
> +++ b/block.c

[...]

> @@ -2569,10 +2582,6 @@ BdrvChild *bdrv_open_child(const char *filename,
>      }
>  
>      c = bdrv_attach_child(parent, bs, bdref_key, child_role, errp);
> -    if (!c) {
> -        bdrv_unref(bs);
> -        return NULL;
> -    }
>  
>      return c;
>  }

(That could have been simplified even further. *shrug*)

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to