From: Pan Nengyuan <pannengyuan@huawei.com>
The BDRVNBDState cleanup code is common in two places, add
nbd_clear_bdrvstate() function to do these cleanups.
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
v3:
- new patch, split form 2/2 patch (suggested by Stefano Garzarella)
Changes v4 to v3:
- replace function name from nbd_free_bdrvstate_prop to
nbd_clear_bdrvstate and set cleared fields to NULL (suggested by Eric
Blake)
- remove static function prototype. (suggested by Eric Blake)
---
Changes v5 to v4:
- correct the wrong email address
---
block/nbd.c | 25 +++++++++++++++----------
1 file changed, 15 insertions(+), 10 deletions(-)
diff --git a/block/nbd.c b/block/nbd.c
index 1239761..8b4a65a 100644
--- a/block/nbd.c
+++ b/block/nbd.c
@@ -94,6 +94,19 @@ typedef struct BDRVNBDState {
static int nbd_client_connect(BlockDriverState *bs, Error **errp);
+void nbd_clear_bdrvstate(BDRVNBDState *s)
+{
+ object_unref(OBJECT(s->tlscreds));
+ qapi_free_SocketAddress(s->saddr);
+ s->saddr = NULL;
+ g_free(s->export);
+ s->export = NULL;
+ g_free(s->tlscredsid);
+ s->tlscredsid = NULL;
+ g_free(s->x_dirty_bitmap);
+ s->x_dirty_bitmap = NULL;
+}
+
static void nbd_channel_error(BDRVNBDState *s, int ret)
{
if (ret == -EIO) {
@@ -1855,10 +1868,7 @@ static int nbd_process_options(BlockDriverState *bs, QDict *options,
error:
if (ret < 0) {
- object_unref(OBJECT(s->tlscreds));
- qapi_free_SocketAddress(s->saddr);
- g_free(s->export);
- g_free(s->tlscredsid);
+ nbd_clear_bdrvstate(s);
}
qemu_opts_del(opts);
return ret;
@@ -1937,12 +1947,7 @@ static void nbd_close(BlockDriverState *bs)
BDRVNBDState *s = bs->opaque;
nbd_client_close(bs);
-
- object_unref(OBJECT(s->tlscreds));
- qapi_free_SocketAddress(s->saddr);
- g_free(s->export);
- g_free(s->tlscredsid);
- g_free(s->x_dirty_bitmap);
+ nbd_clear_bdrvstate(s);
}
static int64_t nbd_getlength(BlockDriverState *bs)
--
2.7.2.windows.1
Hi Pan,
On Thu, Dec 05, 2019 at 11:45:27AM +0800, pannengyuan@huawei.com wrote:
> From: Pan Nengyuan <pannengyuan@huawei.com>
>
> The BDRVNBDState cleanup code is common in two places, add
> nbd_clear_bdrvstate() function to do these cleanups.
>
> Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
I only suggested this change, so I think is better to change it in:
Suggested-by: Stefano Garzarella <sgarzare@redhat.com>
Thanks,
Stefano
> Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>
> Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
> v3:
> - new patch, split form 2/2 patch (suggested by Stefano Garzarella)
> Changes v4 to v3:
> - replace function name from nbd_free_bdrvstate_prop to
> nbd_clear_bdrvstate and set cleared fields to NULL (suggested by Eric
> Blake)
> - remove static function prototype. (suggested by Eric Blake)
> ---
> Changes v5 to v4:
> - correct the wrong email address
> ---
> block/nbd.c | 25 +++++++++++++++----------
> 1 file changed, 15 insertions(+), 10 deletions(-)
>
> diff --git a/block/nbd.c b/block/nbd.c
> index 1239761..8b4a65a 100644
> --- a/block/nbd.c
> +++ b/block/nbd.c
> @@ -94,6 +94,19 @@ typedef struct BDRVNBDState {
>
> static int nbd_client_connect(BlockDriverState *bs, Error **errp);
>
> +void nbd_clear_bdrvstate(BDRVNBDState *s)
> +{
> + object_unref(OBJECT(s->tlscreds));
> + qapi_free_SocketAddress(s->saddr);
> + s->saddr = NULL;
> + g_free(s->export);
> + s->export = NULL;
> + g_free(s->tlscredsid);
> + s->tlscredsid = NULL;
> + g_free(s->x_dirty_bitmap);
> + s->x_dirty_bitmap = NULL;
> +}
> +
> static void nbd_channel_error(BDRVNBDState *s, int ret)
> {
> if (ret == -EIO) {
> @@ -1855,10 +1868,7 @@ static int nbd_process_options(BlockDriverState *bs, QDict *options,
>
> error:
> if (ret < 0) {
> - object_unref(OBJECT(s->tlscreds));
> - qapi_free_SocketAddress(s->saddr);
> - g_free(s->export);
> - g_free(s->tlscredsid);
> + nbd_clear_bdrvstate(s);
> }
> qemu_opts_del(opts);
> return ret;
> @@ -1937,12 +1947,7 @@ static void nbd_close(BlockDriverState *bs)
> BDRVNBDState *s = bs->opaque;
>
> nbd_client_close(bs);
> -
> - object_unref(OBJECT(s->tlscreds));
> - qapi_free_SocketAddress(s->saddr);
> - g_free(s->export);
> - g_free(s->tlscredsid);
> - g_free(s->x_dirty_bitmap);
> + nbd_clear_bdrvstate(s);
> }
>
> static int64_t nbd_getlength(BlockDriverState *bs)
> --
> 2.7.2.windows.1
>
>
--
On 12/5/19 3:42 AM, Stefano Garzarella wrote: > Hi Pan, > > On Thu, Dec 05, 2019 at 11:45:27AM +0800, pannengyuan@huawei.com wrote: >> From: Pan Nengyuan <pannengyuan@huawei.com> >> >> The BDRVNBDState cleanup code is common in two places, add >> nbd_clear_bdrvstate() function to do these cleanups. >> >> Signed-off-by: Stefano Garzarella <sgarzare@redhat.com> > > I only suggested this change, so I think is better to change it in: > Suggested-by: Stefano Garzarella <sgarzare@redhat.com> Concur. I'll make that change while queuing this series through my NBD tree for 5.0. Reviewed-by: Eric Blake <eblake@redhat.com> -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
On 05.12.19 15:04, Eric Blake wrote: > On 12/5/19 3:42 AM, Stefano Garzarella wrote: >> Hi Pan, >> >> On Thu, Dec 05, 2019 at 11:45:27AM +0800, pannengyuan@huawei.com wrote: >>> From: Pan Nengyuan <pannengyuan@huawei.com> >>> >>> The BDRVNBDState cleanup code is common in two places, add >>> nbd_clear_bdrvstate() function to do these cleanups. >>> >>> Signed-off-by: Stefano Garzarella <sgarzare@redhat.com> >> >> I only suggested this change, so I think is better to change it in: >> Suggested-by: Stefano Garzarella <sgarzare@redhat.com> > > Concur. I'll make that change while queuing this series through my NBD > tree for 5.0. Ping on that O:) (Just going through mails in my inbox) Max
On 12/4/19 9:45 PM, pannengyuan@huawei.com wrote:
> From: Pan Nengyuan <pannengyuan@huawei.com>
>
> The BDRVNBDState cleanup code is common in two places, add
> nbd_clear_bdrvstate() function to do these cleanups.
>
> Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
> Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>
> Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
> +++ b/block/nbd.c
> @@ -94,6 +94,19 @@ typedef struct BDRVNBDState {
>
> static int nbd_client_connect(BlockDriverState *bs, Error **errp);
>
> +void nbd_clear_bdrvstate(BDRVNBDState *s)
> +{
Compilation fails if this is not static (no prior prototype). I've
fixed that and now queued this series in my NBD tree, pull request
coming soon.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org
© 2016 - 2026 Red Hat, Inc.