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>
This commit is contained in:
parent
2485f22fe9
commit
7f493662be
26
block/nbd.c
26
block/nbd.c
|
@ -95,6 +95,19 @@ typedef struct BDRVNBDState {
|
||||||
|
|
||||||
static int nbd_client_connect(BlockDriverState *bs, Error **errp);
|
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)
|
static void nbd_channel_error(BDRVNBDState *s, int ret)
|
||||||
{
|
{
|
||||||
if (ret == -EIO) {
|
if (ret == -EIO) {
|
||||||
|
@ -1879,11 +1892,7 @@ static int nbd_process_options(BlockDriverState *bs, QDict *options,
|
||||||
|
|
||||||
error:
|
error:
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
object_unref(OBJECT(s->tlscreds));
|
nbd_clear_bdrvstate(s);
|
||||||
qapi_free_SocketAddress(s->saddr);
|
|
||||||
g_free(s->export);
|
|
||||||
g_free(s->tlscredsid);
|
|
||||||
g_free(s->x_dirty_bitmap);
|
|
||||||
}
|
}
|
||||||
qemu_opts_del(opts);
|
qemu_opts_del(opts);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -1962,12 +1971,7 @@ static void nbd_close(BlockDriverState *bs)
|
||||||
BDRVNBDState *s = bs->opaque;
|
BDRVNBDState *s = bs->opaque;
|
||||||
|
|
||||||
nbd_client_close(bs);
|
nbd_client_close(bs);
|
||||||
|
nbd_clear_bdrvstate(s);
|
||||||
object_unref(OBJECT(s->tlscreds));
|
|
||||||
qapi_free_SocketAddress(s->saddr);
|
|
||||||
g_free(s->export);
|
|
||||||
g_free(s->tlscredsid);
|
|
||||||
g_free(s->x_dirty_bitmap);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int64_t nbd_getlength(BlockDriverState *bs)
|
static int64_t nbd_getlength(BlockDriverState *bs)
|
||||||
|
|
Loading…
Reference in New Issue