aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2020-02-27 18:16:03 +0000
committerPeter Maydell <peter.maydell@linaro.org>2020-02-27 18:16:03 +0000
commita7cfd219d5b956fb189e787fc33dd9c54f14cdc9 (patch)
tree68950035c4f8c2462eef2d70d2b453673e8bfbe9
parent8b6269c8ec14b9213dd22200c1c05aaecd6cbb9d (diff)
parent8198cf5ef0ef98118b4176970d1cd998d93ec849 (diff)
downloadqemu-a7cfd219d5b956fb189e787fc33dd9c54f14cdc9.zip
qemu-a7cfd219d5b956fb189e787fc33dd9c54f14cdc9.tar.gz
qemu-a7cfd219d5b956fb189e787fc33dd9c54f14cdc9.tar.bz2
Merge remote-tracking branch 'remotes/ericb/tags/pull-nbd-2020-02-26' into staging
nbd patches for 2020-02-26 - ensure multiple meta contexts work - allow leading / in export names - fix a failure path memory leak # gpg: Signature made Thu 27 Feb 2020 01:53:03 GMT # gpg: using RSA key 71C2CC22B1C4602927D2F3AAA7A16B4A2527436A # gpg: Good signature from "Eric Blake <eblake@redhat.com>" [full] # gpg: aka "Eric Blake (Free Software Programmer) <ebb9@byu.net>" [full] # gpg: aka "[jpeg image of size 6874]" [full] # Primary key fingerprint: 71C2 CC22 B1C4 6029 27D2 F3AA A7A1 6B4A 2527 436A * remotes/ericb/tags/pull-nbd-2020-02-26: block/nbd: fix memory leak in nbd_open() block/nbd: extract the common cleanup code nbd-client: Support leading / in NBD URI nbd: Fix regression with multiple meta contexts Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
-rw-r--r--block/nbd.c33
-rw-r--r--nbd/server.c12
2 files changed, 30 insertions, 15 deletions
diff --git a/block/nbd.c b/block/nbd.c
index 6d3b22f..976be76 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) {
@@ -1528,8 +1541,10 @@ static int nbd_parse_uri(const char *filename, QDict *options)
goto out;
}
- p = uri->path ? uri->path : "/";
- p += strspn(p, "/");
+ p = uri->path ? uri->path : "";
+ if (p[0] == '/') {
+ p++;
+ }
if (p[0]) {
qdict_put_str(options, "export", p);
}
@@ -1877,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;
@@ -1904,6 +1915,7 @@ static int nbd_open(BlockDriverState *bs, QDict *options, int flags,
ret = nbd_client_connect(bs, errp);
if (ret < 0) {
+ nbd_clear_bdrvstate(s);
return ret;
}
/* successfully connected */
@@ -1960,12 +1972,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)
diff --git a/nbd/server.c b/nbd/server.c
index 87fcd2e..11a3109 100644
--- a/nbd/server.c
+++ b/nbd/server.c
@@ -2384,15 +2384,23 @@ static coroutine_fn int nbd_handle_request(NBDClient *client,
!client->export_meta.bitmap,
NBD_META_ID_BASE_ALLOCATION,
errp);
- } else { /* client->export_meta.bitmap */
+ if (ret < 0) {
+ return ret;
+ }
+ }
+
+ if (client->export_meta.bitmap) {
ret = nbd_co_send_bitmap(client, request->handle,
client->exp->export_bitmap,
request->from, request->len,
dont_fragment,
true, NBD_META_ID_DIRTY_BITMAP, errp);
+ if (ret < 0) {
+ return ret;
+ }
}
- return ret;
+ return 0;
} else {
return nbd_send_generic_reply(client, request->handle, -EINVAL,
"CMD_BLOCK_STATUS not negotiated",