From patchwork Thu Jun 9 16:48:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 9167453 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 C38F4604DB for ; Thu, 9 Jun 2016 16:54:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B454828342 for ; Thu, 9 Jun 2016 16:54:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A8C2728359; Thu, 9 Jun 2016 16:54:18 +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 EF69E28342 for ; Thu, 9 Jun 2016 16:54:17 +0000 (UTC) Received: from localhost ([::1]:35819 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bB3Dl-00083p-3b for patchwork-qemu-devel@patchwork.kernel.org; Thu, 09 Jun 2016 12:54:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51094) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bB38o-0003nO-8G for qemu-devel@nongnu.org; Thu, 09 Jun 2016 12:49:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bB38m-0002AQ-MB for qemu-devel@nongnu.org; Thu, 09 Jun 2016 12:49:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36325) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bB38X-00020l-HQ; Thu, 09 Jun 2016 12:48:53 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (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 14E9663E20; Thu, 9 Jun 2016 16:48:53 +0000 (UTC) Received: from red.redhat.com (ovpn-116-88.phx2.redhat.com [10.3.116.88]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u59GmmCn016618; Thu, 9 Jun 2016 12:48:52 -0400 From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 9 Jun 2016 10:48:36 -0600 Message-Id: <1465490926-28625-6-git-send-email-eblake@redhat.com> In-Reply-To: <1465490926-28625-1-git-send-email-eblake@redhat.com> References: <1465490926-28625-1-git-send-email-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 09 Jun 2016 16:48:53 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 05/15] opts-visitor: Favor new visit_free() function 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 , Michael Roth , "open list:Block layer core" , "Michael S. Tsirkin" , Jason Wang , armbru@redhat.com, Luiz Capitulino , Igor Mammedov , Max Reitz , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Eduardo Habkost Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Now that we have a polymorphic visit_free(), we no longer need opts_visitor_cleanup(); which in turn means we no longer need to return a subtype from opts_visitor_new() nor a public upcast function. Signed-off-by: Eric Blake --- v5: blank line after declaration v4: new patch --- include/qapi/opts-visitor.h | 4 +--- block/crypto.c | 30 ++++++++++++++---------------- hmp.c | 8 ++++---- hw/acpi/core.c | 8 ++++---- net/net.c | 5 ++--- numa.c | 6 +++--- qapi/opts-visitor.c | 26 ++++++-------------------- qom/object_interfaces.c | 8 ++++---- tests/test-opts-visitor.c | 9 ++++----- 9 files changed, 42 insertions(+), 62 deletions(-) diff --git a/include/qapi/opts-visitor.h b/include/qapi/opts-visitor.h index ae1bf7c..6462c96 100644 --- a/include/qapi/opts-visitor.h +++ b/include/qapi/opts-visitor.h @@ -35,8 +35,6 @@ typedef struct OptsVisitor OptsVisitor; * QTypes. It also requires a non-null list argument to * visit_start_list(). */ -OptsVisitor *opts_visitor_new(const QemuOpts *opts); -void opts_visitor_cleanup(OptsVisitor *nv); -Visitor *opts_get_visitor(OptsVisitor *nv); +Visitor *opts_visitor_new(const QemuOpts *opts); #endif diff --git a/block/crypto.c b/block/crypto.c index 5f0ab4d..9bb55d3 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -193,17 +193,16 @@ block_crypto_open_opts_init(QCryptoBlockFormat format, QemuOpts *opts, Error **errp) { - OptsVisitor *ov; + Visitor *v; QCryptoBlockOpenOptions *ret = NULL; Error *local_err = NULL; ret = g_new0(QCryptoBlockOpenOptions, 1); ret->format = format; - ov = opts_visitor_new(opts); + v = opts_visitor_new(opts); - visit_start_struct(opts_get_visitor(ov), - NULL, NULL, 0, &local_err); + visit_start_struct(v, NULL, NULL, 0, &local_err); if (local_err) { goto out; } @@ -211,7 +210,7 @@ block_crypto_open_opts_init(QCryptoBlockFormat format, switch (format) { case Q_CRYPTO_BLOCK_FORMAT_LUKS: visit_type_QCryptoBlockOptionsLUKS_members( - opts_get_visitor(ov), &ret->u.luks, &local_err); + v, &ret->u.luks, &local_err); break; default: @@ -219,10 +218,10 @@ block_crypto_open_opts_init(QCryptoBlockFormat format, break; } if (!local_err) { - visit_check_struct(opts_get_visitor(ov), &local_err); + visit_check_struct(v, &local_err); } - visit_end_struct(opts_get_visitor(ov), NULL); + visit_end_struct(v, NULL); out: if (local_err) { @@ -230,7 +229,7 @@ block_crypto_open_opts_init(QCryptoBlockFormat format, qapi_free_QCryptoBlockOpenOptions(ret); ret = NULL; } - opts_visitor_cleanup(ov); + visit_free(v); return ret; } @@ -240,17 +239,16 @@ block_crypto_create_opts_init(QCryptoBlockFormat format, QemuOpts *opts, Error **errp) { - OptsVisitor *ov; + Visitor *v; QCryptoBlockCreateOptions *ret = NULL; Error *local_err = NULL; ret = g_new0(QCryptoBlockCreateOptions, 1); ret->format = format; - ov = opts_visitor_new(opts); + v = opts_visitor_new(opts); - visit_start_struct(opts_get_visitor(ov), - NULL, NULL, 0, &local_err); + visit_start_struct(v, NULL, NULL, 0, &local_err); if (local_err) { goto out; } @@ -258,7 +256,7 @@ block_crypto_create_opts_init(QCryptoBlockFormat format, switch (format) { case Q_CRYPTO_BLOCK_FORMAT_LUKS: visit_type_QCryptoBlockCreateOptionsLUKS_members( - opts_get_visitor(ov), &ret->u.luks, &local_err); + v, &ret->u.luks, &local_err); break; default: @@ -266,10 +264,10 @@ block_crypto_create_opts_init(QCryptoBlockFormat format, break; } if (!local_err) { - visit_check_struct(opts_get_visitor(ov), &local_err); + visit_check_struct(v, &local_err); } - visit_end_struct(opts_get_visitor(ov), NULL); + visit_end_struct(v, NULL); out: if (local_err) { @@ -277,7 +275,7 @@ block_crypto_create_opts_init(QCryptoBlockFormat format, qapi_free_QCryptoBlockCreateOptions(ret); ret = NULL; } - opts_visitor_cleanup(ov); + visit_free(v); return ret; } diff --git a/hmp.c b/hmp.c index a4b1d3d..7578ee6 100644 --- a/hmp.c +++ b/hmp.c @@ -1718,7 +1718,7 @@ void hmp_object_add(Monitor *mon, const QDict *qdict) { Error *err = NULL; QemuOpts *opts; - OptsVisitor *ov; + Visitor *v; Object *obj = NULL; opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err); @@ -1727,9 +1727,9 @@ void hmp_object_add(Monitor *mon, const QDict *qdict) return; } - ov = opts_visitor_new(opts); - obj = user_creatable_add(qdict, opts_get_visitor(ov), &err); - opts_visitor_cleanup(ov); + v = opts_visitor_new(opts); + obj = user_creatable_add(qdict, v, &err); + visit_free(v); qemu_opts_del(opts); if (err) { diff --git a/hw/acpi/core.c b/hw/acpi/core.c index d24b9a9..e890a5d 100644 --- a/hw/acpi/core.c +++ b/hw/acpi/core.c @@ -239,11 +239,11 @@ void acpi_table_add(const QemuOpts *opts, Error **errp) char unsigned *blob = NULL; { - OptsVisitor *ov; + Visitor *v; - ov = opts_visitor_new(opts); - visit_type_AcpiTableOptions(opts_get_visitor(ov), NULL, &hdrs, &err); - opts_visitor_cleanup(ov); + v = opts_visitor_new(opts); + visit_type_AcpiTableOptions(v, NULL, &hdrs, &err); + visit_free(v); } if (err) { diff --git a/net/net.c b/net/net.c index 5f3e5a9..5e9e1e7 100644 --- a/net/net.c +++ b/net/net.c @@ -1024,8 +1024,7 @@ int net_client_init(QemuOpts *opts, int is_netdev, Error **errp) void *object = NULL; Error *err = NULL; int ret = -1; - OptsVisitor *ov = opts_visitor_new(opts); - Visitor *v = opts_get_visitor(ov); + Visitor *v = opts_visitor_new(opts); { /* Parse convenience option format ip6-net=fec0::0[/64] */ @@ -1075,7 +1074,7 @@ int net_client_init(QemuOpts *opts, int is_netdev, Error **errp) } error_propagate(errp, err); - opts_visitor_cleanup(ov); + visit_free(v); return ret; } diff --git a/numa.c b/numa.c index 572712c..cbae430 100644 --- a/numa.c +++ b/numa.c @@ -217,9 +217,9 @@ static int parse_numa(void *opaque, QemuOpts *opts, Error **errp) Error *err = NULL; { - OptsVisitor *ov = opts_visitor_new(opts); - visit_type_NumaOptions(opts_get_visitor(ov), NULL, &object, &err); - opts_visitor_cleanup(ov); + Visitor *v = opts_visitor_new(opts); + visit_type_NumaOptions(v, NULL, &object, &err); + visit_free(v); } if (err) { diff --git a/qapi/opts-visitor.c b/qapi/opts-visitor.c index 72c95ac..1048bbc 100644 --- a/qapi/opts-visitor.c +++ b/qapi/opts-visitor.c @@ -518,11 +518,15 @@ opts_free(Visitor *v) { OptsVisitor *ov = to_ov(v); - opts_visitor_cleanup(ov); + if (ov->unprocessed_opts != NULL) { + g_hash_table_destroy(ov->unprocessed_opts); + } + g_free(ov->fake_id_opt); + g_free(ov); } -OptsVisitor * +Visitor * opts_visitor_new(const QemuOpts *opts) { OptsVisitor *ov; @@ -553,23 +557,5 @@ opts_visitor_new(const QemuOpts *opts) ov->opts_root = opts; - return ov; -} - - -void -opts_visitor_cleanup(OptsVisitor *ov) -{ - if (ov->unprocessed_opts != NULL) { - g_hash_table_destroy(ov->unprocessed_opts); - } - g_free(ov->fake_id_opt); - g_free(ov); -} - - -Visitor * -opts_get_visitor(OptsVisitor *ov) -{ return &ov->visitor; } diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c index 926ec68..bf59846 100644 --- a/qom/object_interfaces.c +++ b/qom/object_interfaces.c @@ -156,15 +156,15 @@ out: Object *user_creatable_add_opts(QemuOpts *opts, Error **errp) { - OptsVisitor *ov; + Visitor *v; QDict *pdict; Object *obj = NULL; - ov = opts_visitor_new(opts); + v = opts_visitor_new(opts); pdict = qemu_opts_to_qdict(opts, NULL); - obj = user_creatable_add(pdict, opts_get_visitor(ov), errp); - opts_visitor_cleanup(ov); + obj = user_creatable_add(pdict, v, errp); + visit_free(v); QDECREF(pdict); return obj; } diff --git a/tests/test-opts-visitor.c b/tests/test-opts-visitor.c index d75b114..0a9e75f 100644 --- a/tests/test-opts-visitor.c +++ b/tests/test-opts-visitor.c @@ -37,16 +37,15 @@ setup_fixture(OptsVisitorFixture *f, gconstpointer test_data) { const char *opts_string = test_data; QemuOpts *opts; - OptsVisitor *ov; + Visitor *v; opts = qemu_opts_parse(qemu_find_opts("userdef"), opts_string, false, NULL); g_assert(opts != NULL); - ov = opts_visitor_new(opts); - visit_type_UserDefOptions(opts_get_visitor(ov), NULL, &f->userdef, - &f->err); - opts_visitor_cleanup(ov); + v = opts_visitor_new(opts); + visit_type_UserDefOptions(v, NULL, &f->userdef, &f->err); + visit_free(v); qemu_opts_del(opts); }