From patchwork Sun Nov 27 01:56:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 9448665 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8CBEA60487 for ; Sun, 27 Nov 2016 02:22:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 81ED223B3C for ; Sun, 27 Nov 2016 02:22:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7661126785; Sun, 27 Nov 2016 02:22:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4B0FD23B3C for ; Sun, 27 Nov 2016 02:22:44 +0000 (UTC) Received: from localhost ([::1]:52525 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cAp75-0005La-Cm for patchwork-qemu-devel@patchwork.kernel.org; Sat, 26 Nov 2016 21:22:43 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43313) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cAoic-0002Te-5s for qemu-devel@nongnu.org; Sat, 26 Nov 2016 20:57:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cAoiZ-00071G-I4 for qemu-devel@nongnu.org; Sat, 26 Nov 2016 20:57:26 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54378) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cAoiU-0006zN-DO; Sat, 26 Nov 2016 20:57:18 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7138080083; Sun, 27 Nov 2016 01:57:17 +0000 (UTC) Received: from localhost (ovpn-116-37.phx2.redhat.com [10.3.116.37]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uAR1vFRQ018155 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Sat, 26 Nov 2016 20:57:16 -0500 From: Max Reitz To: qemu-block@nongnu.org Date: Sun, 27 Nov 2016 02:56:19 +0100 Message-Id: <20161127015622.24105-22-mreitz@redhat.com> In-Reply-To: <20161127015622.24105-1-mreitz@redhat.com> References: <20161127015622.24105-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Sun, 27 Nov 2016 01:57:17 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 21/24] block: Purify .bdrv_refresh_filename() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Alberto Garcia , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Currently, BlockDriver.bdrv_refresh_filename() is supposed to both refresh the filename (BDS.exact_filename) and set BDS.full_open_options. Now that we have generic code in the central bdrv_refresh_filename() for creating BDS.full_open_options, we can drop the latter part from all BlockDriver.bdrv_refresh_filename() implementations. This also means that we can drop all of the existing default code for this from the global bdrv_refresh_filename() itself. Furthermore, we now have to call BlockDriver.bdrv_refresh_filename() after having set BDS.full_open_options, because the block driver's implementation should now be allowed to depend on BDS.full_open_options being set correctly. Finally, with this patch we can drop the @options parameter from BlockDriver.bdrv_refresh_filename(). Signed-off-by: Max Reitz --- block.c | 149 +++++++--------------------------------------- block/blkdebug.c | 44 ++++---------- block/blkverify.c | 17 +----- block/nbd.c | 25 +------- block/nfs.c | 41 +------------ block/null.c | 23 ++++--- block/quorum.c | 34 ----------- include/block/block_int.h | 2 +- 8 files changed, 52 insertions(+), 283 deletions(-) diff --git a/block.c b/block.c index 9a84506..187ce10 100644 --- a/block.c +++ b/block.c @@ -4022,47 +4022,6 @@ static bool append_significant_runtime_options(QDict *d, BlockDriverState *bs) return found_any; } -static bool append_open_options(QDict *d, BlockDriverState *bs) -{ - const QDictEntry *entry; - QemuOptDesc *desc; - BdrvChild *child; - bool found_any = false; - const char *p; - - for (entry = qdict_first(bs->options); entry; - entry = qdict_next(bs->options, entry)) - { - /* Exclude options for children */ - QLIST_FOREACH(child, &bs->children, next) { - if (strstart(qdict_entry_key(entry), child->name, &p) - && (!*p || *p == '.')) - { - break; - } - } - if (child) { - continue; - } - - /* And exclude all non-driver-specific options */ - for (desc = bdrv_runtime_opts.desc; desc->name; desc++) { - if (!strcmp(qdict_entry_key(entry), desc->name)) { - break; - } - } - if (desc->name) { - continue; - } - - qobject_incref(qdict_entry_value(entry)); - qdict_put_obj(d, qdict_entry_key(entry), qdict_entry_value(entry)); - found_any = true; - } - - return found_any; -} - /* Updates the following BDS fields: * - exact_filename: A filename which may be used for opening a block device * which (mostly) equals the given BDS (even without any @@ -4080,6 +4039,8 @@ void bdrv_refresh_filename(BlockDriverState *bs) BlockDriver *drv = bs->drv; BdrvChild *child; QDict *opts; + bool generate_json_filename; /* Whether our default implementation should + fill exact_filename (false) or not (true) */ if (!drv) { return; @@ -4095,94 +4056,10 @@ void bdrv_refresh_filename(BlockDriverState *bs) } } - if (drv->bdrv_refresh_filename) { - /* Obsolete information is of no use here, so drop the old file name - * information before refreshing it */ - bs->exact_filename[0] = '\0'; - if (bs->full_open_options) { - QDECREF(bs->full_open_options); - bs->full_open_options = NULL; - } - - 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; - - bs->exact_filename[0] = '\0'; - if (bs->full_open_options) { - QDECREF(bs->full_open_options); - bs->full_open_options = NULL; - } - - opts = qdict_new(); - has_open_options = append_open_options(opts, bs); - has_open_options |= bs->backing_overridden; - - /* If no specific options have been given for this BDS, the filename of - * the underlying file should suffice for this one as well */ - if (bs->file->bs->exact_filename[0] && !has_open_options) { - strcpy(bs->exact_filename, bs->file->bs->exact_filename); - } - /* Reconstructing the full options QDict is simple for most format block - * drivers, as long as the full options are known for the underlying - * file BDS. The full options QDict of that file BDS should somehow - * contain a representation of the filename, therefore the following - * suffices without querying the (exact_)filename of this BDS. */ - if (bs->file->bs->full_open_options && - (!bs->backing || bs->backing->bs->full_open_options)) - { - qdict_put_obj(opts, "driver", - QOBJECT(qstring_from_str(drv->format_name))); - QINCREF(bs->file->bs->full_open_options); - qdict_put_obj(opts, "file", - QOBJECT(bs->file->bs->full_open_options)); - - if (bs->backing) { - QINCREF(bs->backing->bs->full_open_options); - qdict_put(opts, "backing", bs->backing->bs->full_open_options); - } else if (bs->backing_overridden && !bs->backing) { - qdict_put(opts, "backing", qstring_new()); - } - - bs->full_open_options = opts; - } else { - QDECREF(opts); - } - } else if (!bs->full_open_options && qdict_size(bs->options)) { - /* There is no underlying file BDS (at least referenced by BDS.file), - * so the full options QDict should be equal to the options given - * specifically for this block device when it was opened (plus the - * driver specification). - * Because those options don't change, there is no need to update - * full_open_options when it's already set. */ - - opts = qdict_new(); - append_open_options(opts, bs); - qdict_put_obj(opts, "driver", - QOBJECT(qstring_from_str(drv->format_name))); - - if (bs->exact_filename[0]) { - /* This may not work for all block protocol drivers (some may - * require this filename to be parsed), but we have to find some - * default solution here, so just include it. If some block driver - * does not support pure options without any filename at all or - * needs some special format of the options QDict, it needs to - * implement the driver-specific bdrv_refresh_filename() function. - */ - qdict_put_obj(opts, "filename", - QOBJECT(qstring_from_str(bs->exact_filename))); - } - - bs->full_open_options = opts; - } - /* Gather the options QDict */ opts = qdict_new(); - append_significant_runtime_options(opts, bs); + generate_json_filename = append_significant_runtime_options(opts, bs); + generate_json_filename |= bs->backing_overridden; if (drv->bdrv_gather_child_options) { /* Some block drivers may not want to present all of their children's @@ -4208,6 +4085,24 @@ void bdrv_refresh_filename(BlockDriverState *bs) QDECREF(bs->full_open_options); bs->full_open_options = opts; + if (drv->bdrv_refresh_filename) { + /* Obsolete information is of no use here, so drop the old file name + * information before refreshing it */ + bs->exact_filename[0] = '\0'; + + drv->bdrv_refresh_filename(bs); + } else if (bs->file) { + /* Try to reconstruct valid information from the underlying file */ + + bs->exact_filename[0] = '\0'; + + /* If no specific options have been given for this BDS, the filename of + * the underlying file should suffice for this one as well */ + if (bs->file->bs->exact_filename[0] && !generate_json_filename) { + strcpy(bs->exact_filename, bs->file->bs->exact_filename); + } + } + if (bs->exact_filename[0]) { pstrcpy(bs->filename, sizeof(bs->filename), bs->exact_filename); } else { diff --git a/block/blkdebug.c b/block/blkdebug.c index 5de6fad..6b18120 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -679,48 +679,28 @@ static int blkdebug_truncate(BlockDriverState *bs, int64_t offset) return bdrv_truncate(bs->file->bs, offset); } -static void blkdebug_refresh_filename(BlockDriverState *bs, QDict *options) +static void blkdebug_refresh_filename(BlockDriverState *bs) { BDRVBlkdebugState *s = bs->opaque; - QDict *opts; const QDictEntry *e; - bool force_json = false; - 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")) - { - force_json = true; - break; - } - } - - if (force_json && !bs->file->bs->full_open_options) { - /* The config file cannot be recreated, so creating a plain filename - * is impossible */ + if (!bs->file->bs->exact_filename[0]) { return; } - if (!force_json && bs->file->bs->exact_filename[0]) { - snprintf(bs->exact_filename, sizeof(bs->exact_filename), - "blkdebug:%s:%s", s->config_file ?: "", - bs->file->bs->exact_filename); - } - - opts = qdict_new(); - qdict_put_obj(opts, "driver", QOBJECT(qstring_from_str("blkdebug"))); - - QINCREF(bs->file->bs->full_open_options); - qdict_put_obj(opts, "image", QOBJECT(bs->file->bs->full_open_options)); - - 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)); + for (e = qdict_first(bs->full_open_options); e; + e = qdict_next(bs->full_open_options, e)) + { + if (strcmp(qdict_entry_key(e), "config") && + strcmp(qdict_entry_key(e), "image") && + strcmp(qdict_entry_key(e), "driver")) + { + return; } } - bs->full_open_options = opts; + snprintf(bs->exact_filename, sizeof(bs->exact_filename), "blkdebug:%s:%s", + s->config_file ?: "", bs->file->bs->exact_filename); } static void blkdebug_refresh_limits(BlockDriverState *bs, Error **errp) diff --git a/block/blkverify.c b/block/blkverify.c index d6e57e0..caf267c 100644 --- a/block/blkverify.c +++ b/block/blkverify.c @@ -289,25 +289,10 @@ static bool blkverify_recurse_is_first_non_filter(BlockDriverState *bs, return bdrv_recurse_is_first_non_filter(s->test_file->bs, candidate); } -static void blkverify_refresh_filename(BlockDriverState *bs, QDict *options) +static void blkverify_refresh_filename(BlockDriverState *bs) { BDRVBlkverifyState *s = bs->opaque; - if (bs->file->bs->full_open_options - && s->test_file->bs->full_open_options) - { - QDict *opts = qdict_new(); - qdict_put_obj(opts, "driver", QOBJECT(qstring_from_str("blkverify"))); - - QINCREF(bs->file->bs->full_open_options); - qdict_put_obj(opts, "raw", QOBJECT(bs->file->bs->full_open_options)); - QINCREF(s->test_file->bs->full_open_options); - qdict_put_obj(opts, "test", - QOBJECT(s->test_file->bs->full_open_options)); - - bs->full_open_options = opts; - } - if (bs->file->bs->exact_filename[0] && s->test_file->bs->exact_filename[0]) { diff --git a/block/nbd.c b/block/nbd.c index 1307989..ea5d7a8 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -499,12 +499,9 @@ static void nbd_attach_aio_context(BlockDriverState *bs, nbd_client_attach_aio_context(bs, new_context); } -static void nbd_refresh_filename(BlockDriverState *bs, QDict *options) +static void nbd_refresh_filename(BlockDriverState *bs) { BDRVNBDState *s = bs->opaque; - QDict *opts = qdict_new(); - QObject *saddr_qdict; - Visitor *ov; const char *host = NULL, *port = NULL, *path = NULL; if (s->saddr->type == SOCKET_ADDRESS_KIND_INET) { @@ -517,8 +514,6 @@ static void nbd_refresh_filename(BlockDriverState *bs, QDict *options) path = s->saddr->u.q_unix.data->path; } - qdict_put(opts, "driver", qstring_from_str("nbd")); - if (path && s->export) { snprintf(bs->exact_filename, sizeof(bs->exact_filename), "nbd+unix:///%s?socket=%s", s->export, path); @@ -532,24 +527,6 @@ static void nbd_refresh_filename(BlockDriverState *bs, QDict *options) snprintf(bs->exact_filename, sizeof(bs->exact_filename), "nbd://%s:%s", host, port); } - - ov = qobject_output_visitor_new(&saddr_qdict); - visit_type_SocketAddress(ov, NULL, &s->saddr, &error_abort); - visit_complete(ov, &saddr_qdict); - visit_free(ov); - assert(qobject_type(saddr_qdict) == QTYPE_QDICT); - - qdict_put_obj(opts, "server", saddr_qdict); - - if (s->export) { - qdict_put(opts, "export", qstring_from_str(s->export)); - } - if (s->tlscredsid) { - qdict_put(opts, "tls-creds", qstring_from_str(s->tlscredsid)); - } - - qdict_flatten(opts); - bs->full_open_options = opts; } static char *nbd_dirname(BlockDriverState *bs, Error **errp) diff --git a/block/nfs.c b/block/nfs.c index 6ffdede..eac4010 100644 --- a/block/nfs.c +++ b/block/nfs.c @@ -767,14 +767,9 @@ static int nfs_reopen_prepare(BDRVReopenState *state, return 0; } -static void nfs_refresh_filename(BlockDriverState *bs, QDict *options) +static void nfs_refresh_filename(BlockDriverState *bs) { NFSClient *client = bs->opaque; - QDict *opts = qdict_new(); - QObject *server_qdict; - Visitor *ov; - - qdict_put(opts, "driver", qstring_from_str("nfs")); if (client->uid && !client->gid) { snprintf(bs->exact_filename, sizeof(bs->exact_filename), @@ -792,40 +787,6 @@ static void nfs_refresh_filename(BlockDriverState *bs, QDict *options) snprintf(bs->exact_filename, sizeof(bs->exact_filename), "nfs://%s%s", client->server->host, client->path); } - - ov = qobject_output_visitor_new(&server_qdict); - visit_type_NFSServer(ov, NULL, &client->server, &error_abort); - visit_complete(ov, &server_qdict); - assert(qobject_type(server_qdict) == QTYPE_QDICT); - - qdict_put_obj(opts, "server", server_qdict); - qdict_put(opts, "path", qstring_from_str(client->path)); - - if (client->uid) { - qdict_put(opts, "uid", qint_from_int(client->uid)); - } - if (client->gid) { - qdict_put(opts, "gid", qint_from_int(client->gid)); - } - if (client->tcp_syncnt) { - qdict_put(opts, "tcp-syncnt", - qint_from_int(client->tcp_syncnt)); - } - if (client->readahead) { - qdict_put(opts, "readahead", - qint_from_int(client->readahead)); - } - if (client->pagecache) { - qdict_put(opts, "pagecache", - qint_from_int(client->pagecache)); - } - if (client->debug) { - qdict_put(opts, "debug", qint_from_int(client->debug)); - } - - visit_free(ov); - qdict_flatten(opts); - bs->full_open_options = opts; } static char *nfs_dirname(BlockDriverState *bs, Error **errp) diff --git a/block/null.c b/block/null.c index 16ef8b2..fb03fb9 100644 --- a/block/null.c +++ b/block/null.c @@ -222,18 +222,23 @@ static int64_t coroutine_fn null_co_get_block_status(BlockDriverState *bs, } } -static void null_refresh_filename(BlockDriverState *bs, QDict *opts) +static void null_refresh_filename(BlockDriverState *bs) { - QINCREF(opts); - qdict_del(opts, "filename"); - - if (!qdict_size(opts)) { - snprintf(bs->exact_filename, sizeof(bs->exact_filename), "%s://", - bs->drv->format_name); + const QDictEntry *e; + + for (e = qdict_first(bs->full_open_options); e; + e = qdict_next(bs->full_open_options, e)) + { + /* These options can be ignored */ + if (strcmp(qdict_entry_key(e), "filename") && + strcmp(qdict_entry_key(e), "driver")) + { + return; + } } - qdict_put(opts, "driver", qstring_from_str(bs->drv->format_name)); - bs->full_open_options = opts; + snprintf(bs->exact_filename, sizeof(bs->exact_filename), "%s://", + bs->drv->format_name); } static const char *const null_sgfnt_runtime_opts[] = { diff --git a/block/quorum.c b/block/quorum.c index 126127c..09c4add 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -1050,39 +1050,6 @@ static void quorum_del_child(BlockDriverState *bs, BdrvChild *child, bdrv_drained_end(bs); } -static void quorum_refresh_filename(BlockDriverState *bs, QDict *options) -{ - BDRVQuorumState *s = bs->opaque; - QDict *opts; - QList *children; - int i; - - for (i = 0; i < s->num_children; i++) { - if (!s->children[i]->bs->full_open_options) { - return; - } - } - - children = qlist_new(); - for (i = 0; i < s->num_children; i++) { - QINCREF(s->children[i]->bs->full_open_options); - qlist_append_obj(children, - QOBJECT(s->children[i]->bs->full_open_options)); - } - - opts = qdict_new(); - qdict_put_obj(opts, "driver", QOBJECT(qstring_from_str("quorum"))); - qdict_put_obj(opts, QUORUM_OPT_VOTE_THRESHOLD, - QOBJECT(qint_from_int(s->threshold))); - qdict_put_obj(opts, QUORUM_OPT_BLKVERIFY, - QOBJECT(qbool_from_bool(s->is_blkverify))); - qdict_put_obj(opts, QUORUM_OPT_REWRITE, - QOBJECT(qbool_from_bool(s->rewrite_corrupted))); - qdict_put_obj(opts, "children", QOBJECT(children)); - - bs->full_open_options = opts; -} - static void quorum_gather_child_options(BlockDriverState *bs, QDict *target) { BDRVQuorumState *s = bs->opaque; @@ -1130,7 +1097,6 @@ static BlockDriver bdrv_quorum = { .bdrv_file_open = quorum_open, .bdrv_close = quorum_close, - .bdrv_refresh_filename = quorum_refresh_filename, .bdrv_gather_child_options = quorum_gather_child_options, .bdrv_dirname = quorum_dirname, diff --git a/include/block/block_int.h b/include/block/block_int.h index cfb8cf3..0c65c58 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -129,7 +129,7 @@ struct BlockDriver { int (*bdrv_set_key)(BlockDriverState *bs, const char *key); int (*bdrv_make_empty)(BlockDriverState *bs); - void (*bdrv_refresh_filename)(BlockDriverState *bs, QDict *options); + void (*bdrv_refresh_filename)(BlockDriverState *bs); void (*bdrv_gather_child_options)(BlockDriverState *bs, QDict *target); char *(*bdrv_dirname)(BlockDriverState *bs, Error **errp);