qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [RFC PATCH 16/22] block/export: Allocate BlockExport in blk_exp_add(


From: Max Reitz
Subject: Re: [RFC PATCH 16/22] block/export: Allocate BlockExport in blk_exp_add()
Date: Tue, 18 Aug 2020 16:25:27 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0

On 13.08.20 18:29, Kevin Wolf wrote:
> Instead of letting the driver allocate and return the BlockExport
> object, allocate it already in blk_exp_add() and pass it. This allows us
> to initialise the generic part before calling into the driver so that
> the driver can just use these values instead of having to parse the
> options a second time.
> 
> For symmetry, move freeing the BlockExport to blk_exp_unref().
> 
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
>  include/block/export.h |  3 ++-
>  include/block/nbd.h    | 11 ++++++-----
>  block/export/export.c  | 17 ++++++++++++++++-
>  blockdev-nbd.c         | 24 +++++++++++++-----------
>  nbd/server.c           | 30 +++++++++++++-----------------
>  5 files changed, 50 insertions(+), 35 deletions(-)

[...]

> diff --git a/block/export/export.c b/block/export/export.c
> index ef86bf892b..9de108cbc1 100644
> --- a/block/export/export.c
> +++ b/block/export/export.c

[...]

> @@ -46,7 +48,19 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Error 
> **errp)
>          return NULL;
>      }
>  
> -    return drv->create(export, errp);

assert(drv->instance_size >= sizeof(BlockExport)) might be nice before
dereferencing *exp.

With that:

Reviewed-by: Max Reitz <mreitz@redhat.com>

> +    exp = g_malloc0(drv->instance_size);
> +    *exp = (BlockExport) {
> +        .drv        = &blk_exp_nbd,
> +        .refcount   = 1,
> +    };

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]