diff options
author | Pan Nengyuan <pannengyuan@huawei.com> | 2019-12-05 11:45:27 +0800 |
---|---|---|
committer | Eric Blake <eblake@redhat.com> | 2020-02-26 17:28:08 -0600 |
commit | 7f493662be4045146a8f45119d8834c9088a0ad6 (patch) | |
tree | 7baf7d68754ec35fe2a69d492a5c6262eaea32a0 | |
parent | 2485f22fe9211b2e80970f83199b320eee211319 (diff) | |
download | qemu-7f493662be4045146a8f45119d8834c9088a0ad6.zip qemu-7f493662be4045146a8f45119d8834c9088a0ad6.tar.gz qemu-7f493662be4045146a8f45119d8834c9088a0ad6.tar.bz2 |
block/nbd: extract the common cleanup code
The BDRVNBDState cleanup code is common in two places, add
nbd_clear_bdrvstate() function to do these cleanups.
Suggested-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <1575517528-44312-2-git-send-email-pannengyuan@huawei.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
[eblake: fix compilation error and commit message]
Signed-off-by: Eric Blake <eblake@redhat.com>
-rw-r--r-- | block/nbd.c | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/block/nbd.c b/block/nbd.c index f69e61e..ed0f93a 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -95,6 +95,19 @@ typedef struct BDRVNBDState { static int nbd_client_connect(BlockDriverState *bs, Error **errp); +static 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) { @@ -1879,11 +1892,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); - g_free(s->x_dirty_bitmap); + nbd_clear_bdrvstate(s); } qemu_opts_del(opts); return ret; @@ -1962,12 +1971,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) |