Skip to content

Commit

Permalink
block/nbd: extract the common cleanup code
Browse files Browse the repository at this point in the history
The BDRVNBDState cleanup code is common in two places, add
nbd_clear_bdrvstate() function to do these cleanups.

Suggested-by: Stefano Garzarella <[email protected]>
Signed-off-by: Pan Nengyuan <[email protected]>
Reviewed-by: Vladimir Sementsov-Ogievskiy <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
[eblake: fix compilation error and commit message]
Signed-off-by: Eric Blake <[email protected]>
  • Loading branch information
panny060 authored and ebblake committed Feb 26, 2020
1 parent 2485f22 commit 7f49366
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions block/nbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 7f49366

Please sign in to comment.