From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53608) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a0tXR-0004u6-VY for qemu-devel@nongnu.org; Mon, 23 Nov 2015 11:00:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a0tXQ-0006jI-8I for qemu-devel@nongnu.org; Mon, 23 Nov 2015 11:00:21 -0500 From: Kevin Wolf Date: Mon, 23 Nov 2015 16:59:46 +0100 Message-Id: <1448294400-476-8-git-send-email-kwolf@redhat.com> In-Reply-To: <1448294400-476-1-git-send-email-kwolf@redhat.com> References: <1448294400-476-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH v2 07/21] block: Pass driver-specific options to .bdrv_refresh_filename() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-block@nongnu.org Cc: kwolf@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com In order to decide whether a blkdebug: filename can be produced or a json: one is necessary, blkdebug checked whether bs->options had more options than just "config", "x-image" or "image" (the latter including nested options). That doesn't work well when generic block layer options are present. This patch passes an option QDict to the driver that contains only driver-specific options, i.e. the options for the general block layer as well as child nodes are already filtered out. Works much better this way. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block.c | 5 ++++- block/blkdebug.c | 17 ++++++----------- block/blkverify.c | 2 +- block/nbd.c | 10 +++++----- block/quorum.c | 2 +- include/block/block_int.h | 2 +- 6 files changed, 18 insertions(+), 20 deletions(-) diff --git a/block.c b/block.c index 02125e2..be449b9 100644 --- a/block.c +++ b/block.c @@ -4027,7 +4027,10 @@ void bdrv_refresh_filename(BlockDriverState *bs) bs->full_open_options = NULL; } - drv->bdrv_refresh_filename(bs); + opts = qdict_new(); + append_open_options(opts, bs); + drv->bdrv_refresh_filename(bs, opts); + QDECREF(opts); } else if (bs->file) { /* Try to reconstruct valid information from the underlying file */ bool has_open_options; diff --git a/block/blkdebug.c b/block/blkdebug.c index 6860a2b..bc0f041 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -726,17 +726,15 @@ static int blkdebug_truncate(BlockDriverState *bs, int64_t offset) return bdrv_truncate(bs->file->bs, offset); } -static void blkdebug_refresh_filename(BlockDriverState *bs) +static void blkdebug_refresh_filename(BlockDriverState *bs, QDict *options) { QDict *opts; const QDictEntry *e; bool force_json = false; - for (e = qdict_first(bs->options); e; e = qdict_next(bs->options, e)) { + for (e = qdict_first(options); e; e = qdict_next(options, e)) { if (strcmp(qdict_entry_key(e), "config") && - strcmp(qdict_entry_key(e), "x-image") && - strcmp(qdict_entry_key(e), "image") && - strncmp(qdict_entry_key(e), "image.", strlen("image."))) + strcmp(qdict_entry_key(e), "x-image")) { force_json = true; break; @@ -752,7 +750,7 @@ static void blkdebug_refresh_filename(BlockDriverState *bs) if (!force_json && bs->file->bs->exact_filename[0]) { snprintf(bs->exact_filename, sizeof(bs->exact_filename), "blkdebug:%s:%s", - qdict_get_try_str(bs->options, "config") ?: "", + qdict_get_try_str(options, "config") ?: "", bs->file->bs->exact_filename); } @@ -762,11 +760,8 @@ static void blkdebug_refresh_filename(BlockDriverState *bs) QINCREF(bs->file->bs->full_open_options); qdict_put_obj(opts, "image", QOBJECT(bs->file->bs->full_open_options)); - for (e = qdict_first(bs->options); e; e = qdict_next(bs->options, e)) { - if (strcmp(qdict_entry_key(e), "x-image") && - strcmp(qdict_entry_key(e), "image") && - strncmp(qdict_entry_key(e), "image.", strlen("image."))) - { + for (e = qdict_first(options); e; e = qdict_next(options, e)) { + if (strcmp(qdict_entry_key(e), "x-image")) { qobject_incref(qdict_entry_value(e)); qdict_put_obj(opts, qdict_entry_key(e), qdict_entry_value(e)); } diff --git a/block/blkverify.c b/block/blkverify.c index c5f8e8d..1d75449 100644 --- a/block/blkverify.c +++ b/block/blkverify.c @@ -307,7 +307,7 @@ static void blkverify_attach_aio_context(BlockDriverState *bs, bdrv_attach_aio_context(s->test_file->bs, new_context); } -static void blkverify_refresh_filename(BlockDriverState *bs) +static void blkverify_refresh_filename(BlockDriverState *bs, QDict *options) { BDRVBlkverifyState *s = bs->opaque; diff --git a/block/nbd.c b/block/nbd.c index cd6a587..416f42b 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -342,13 +342,13 @@ static void nbd_attach_aio_context(BlockDriverState *bs, nbd_client_attach_aio_context(bs, new_context); } -static void nbd_refresh_filename(BlockDriverState *bs) +static void nbd_refresh_filename(BlockDriverState *bs, QDict *options) { QDict *opts = qdict_new(); - const char *path = qdict_get_try_str(bs->options, "path"); - const char *host = qdict_get_try_str(bs->options, "host"); - const char *port = qdict_get_try_str(bs->options, "port"); - const char *export = qdict_get_try_str(bs->options, "export"); + const char *path = qdict_get_try_str(options, "path"); + const char *host = qdict_get_try_str(options, "host"); + const char *port = qdict_get_try_str(options, "port"); + const char *export = qdict_get_try_str(options, "export"); qdict_put_obj(opts, "driver", QOBJECT(qstring_from_str("nbd"))); diff --git a/block/quorum.c b/block/quorum.c index b9ba028..2810e37 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -997,7 +997,7 @@ static void quorum_attach_aio_context(BlockDriverState *bs, } } -static void quorum_refresh_filename(BlockDriverState *bs) +static void quorum_refresh_filename(BlockDriverState *bs, QDict *options) { BDRVQuorumState *s = bs->opaque; QDict *opts; diff --git a/include/block/block_int.h b/include/block/block_int.h index b2325aa..d6d7b42 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -136,7 +136,7 @@ struct BlockDriver { int (*bdrv_set_key)(BlockDriverState *bs, const char *key); int (*bdrv_make_empty)(BlockDriverState *bs); - void (*bdrv_refresh_filename)(BlockDriverState *bs); + void (*bdrv_refresh_filename)(BlockDriverState *bs, QDict *options); /* aio */ BlockAIOCB *(*bdrv_aio_readv)(BlockDriverState *bs, -- 1.8.3.1