From nobody Thu Apr 25 13:48:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1502368018743703.6207907602409; Thu, 10 Aug 2017 05:26:58 -0700 (PDT) Received: from localhost ([::1]:52876 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dfmYD-0001Nk-9v for importer@patchew.org; Thu, 10 Aug 2017 08:26:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49328) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dfmWl-0000VT-PP for qemu-devel@nongnu.org; Thu, 10 Aug 2017 08:25:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dfmWi-0006B2-LG for qemu-devel@nongnu.org; Thu, 10 Aug 2017 08:25:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39704) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dfmWi-00069x-F5 for qemu-devel@nongnu.org; Thu, 10 Aug 2017 08:25:24 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6D06EC098D11; Thu, 10 Aug 2017 12:25:23 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-117-201.ams2.redhat.com [10.36.117.201]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E083597843; Thu, 10 Aug 2017 12:25:22 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 49322113864E; Thu, 10 Aug 2017 14:25:21 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6D06EC098D11 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=armbru@redhat.com From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 10 Aug 2017 14:25:20 +0200 Message-Id: <1502367921-17730-2-git-send-email-armbru@redhat.com> In-Reply-To: <1502367921-17730-1-git-send-email-armbru@redhat.com> References: <1502367921-17730-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 10 Aug 2017 12:25:23 +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 1/2] vl: Factor object_create() out of main() 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: kwolf@redhat.com, pbonzini@redhat.com, el13635@mail.ntua.gr Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- vl.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/vl.c b/vl.c index 8e247cc..fd98ed1 100644 --- a/vl.c +++ b/vl.c @@ -2845,7 +2845,6 @@ static bool object_create_initial(const char *type) return true; } =20 - /* * The remainder of object creation happens after the * creation of chardev, fsdev, net clients and device data types. @@ -2855,6 +2854,14 @@ static bool object_create_delayed(const char *type) return !object_create_initial(type); } =20 +static void object_create(bool (*type_predicate)(const char *)) +{ + if (qemu_opts_foreach(qemu_find_opts("object"), + user_creatable_add_opts_foreach, + type_predicate, NULL)) { + exit(1); + } +} =20 static void set_memory_options(uint64_t *ram_slots, ram_addr_t *maxram_siz= e, MachineClass *mc) @@ -4391,11 +4398,7 @@ int main(int argc, char **argv, char **envp) page_size_init(); socket_init(); =20 - if (qemu_opts_foreach(qemu_find_opts("object"), - user_creatable_add_opts_foreach, - object_create_initial, NULL)) { - exit(1); - } + object_create(object_create_initial); =20 if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func, NULL, NULL)) { @@ -4520,11 +4523,7 @@ int main(int argc, char **argv, char **envp) exit(1); } =20 - if (qemu_opts_foreach(qemu_find_opts("object"), - user_creatable_add_opts_foreach, - object_create_delayed, NULL)) { - exit(1); - } + object_create(object_create_delayed); =20 #ifdef CONFIG_TPM if (tpm_init() < 0) { --=20 2.7.5 From nobody Thu Apr 25 13:48:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1502368022128137.04827659504338; Thu, 10 Aug 2017 05:27:02 -0700 (PDT) Received: from localhost ([::1]:52877 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dfmYE-0001Og-TB for importer@patchew.org; Thu, 10 Aug 2017 08:26:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49327) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dfmWl-0000VS-P0 for qemu-devel@nongnu.org; Thu, 10 Aug 2017 08:25:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dfmWi-0006B8-MF for qemu-devel@nongnu.org; Thu, 10 Aug 2017 08:25:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47976) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dfmWi-00069r-Db for qemu-devel@nongnu.org; Thu, 10 Aug 2017 08:25:24 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 53FB02CE97C; Thu, 10 Aug 2017 12:25:23 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-117-201.ams2.redhat.com [10.36.117.201]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DF8C887CAF; Thu, 10 Aug 2017 12:25:22 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 4C0BC113864F; Thu, 10 Aug 2017 14:25:21 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 53FB02CE97C Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=armbru@redhat.com From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 10 Aug 2017 14:25:21 +0200 Message-Id: <1502367921-17730-3-git-send-email-armbru@redhat.com> In-Reply-To: <1502367921-17730-1-git-send-email-armbru@redhat.com> References: <1502367921-17730-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 10 Aug 2017 12:25:23 +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 2/2] vl: Partial support for non-scalar properties with -object 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: kwolf@redhat.com, pbonzini@redhat.com, el13635@mail.ntua.gr Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We've wanted -object to support non-scalar properties for a while. Dan Berrange tried in "[PATCH v4 00/10]Provide a QOM-based authorization API". Review led to the conclusion that we need to replace rather than add to QemuOpts. Initial work towards that goal has been merged to provide -blockdev (commit 8746709), but there's substantial work left, mostly due to an bewildering array of compatibility problems. Even if a full solution is still out of reach, we can have a partial solution now: accept -object argument in JSON syntax. This should unblock development work that needs non-scalar properties with -object The implementation is similar to -blockdev, except we use the new infrastructure only for the new JSON case, and stick to QemuOpts for the existing KEY=3DVALUE,... case, to sidestep compatibility problems. If we did this for more options, we'd have to factor out common code. But for one option, this will do. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- qapi-schema.json | 14 +++++++++++--- vl.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++= +++ 2 files changed, 66 insertions(+), 3 deletions(-) diff --git a/qapi-schema.json b/qapi-schema.json index 802ea53..7ed1db1 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -3618,15 +3618,23 @@ { 'command': 'netdev_del', 'data': {'id': 'str'} } =20 ## -# @object-add: +# @ObjectOptions: # -# Create a QOM object. +# Options for creating an object. # # @qom-type: the class name for the object to be created # # @id: the name of the new object # # @props: a dictionary of properties to be passed to the backend +## +{ 'struct': 'ObjectOptions', + 'data': {'qom-type': 'str', 'id': 'str', '*props': 'any'} } + +## +# @object-add: +# +# Create a QOM object. # # Returns: Nothing on success # Error if @qom-type is not a valid class name @@ -3642,7 +3650,7 @@ # ## { 'command': 'object-add', - 'data': {'qom-type': 'str', 'id': 'str', '*props': 'any'} } + 'data': 'ObjectOptions' } =20 ## # @object-del: diff --git a/vl.c b/vl.c index fd98ed1..db4680b 100644 --- a/vl.c +++ b/vl.c @@ -2854,8 +2854,32 @@ static bool object_create_delayed(const char *type) return !object_create_initial(type); } =20 +typedef struct ObjectOptionsQueueEntry { + ObjectOptions *oo; + Location loc; + QSIMPLEQ_ENTRY(ObjectOptionsQueueEntry) entry; +} ObjectOptionsQueueEntry; + +typedef QSIMPLEQ_HEAD(ObjectOptionsQueue, ObjectOptionsQueueEntry) + ObjectOptionsQueue; + +ObjectOptionsQueue oo_queue =3D QSIMPLEQ_HEAD_INITIALIZER(oo_queue); + + static void object_create(bool (*type_predicate)(const char *)) { + ObjectOptionsQueueEntry *e; + + QSIMPLEQ_FOREACH(e, &oo_queue, entry) { + if (!type_predicate(e->oo->qom_type)) { + continue; + } + loc_push_restore(&e->loc); + qmp_object_add(e->oo->qom_type, e->oo->id, + e->oo->has_props, e->oo->props, &error_fatal); + loc_pop(&e->loc); + } + if (qemu_opts_foreach(qemu_find_opts("object"), user_creatable_add_opts_foreach, type_predicate, NULL)) { @@ -4078,6 +4102,29 @@ int main(int argc, char **argv, char **envp) #endif break; case QEMU_OPTION_object: + /* + * TODO Use qobject_input_visitor_new_str() instead of + * QemuOpts, not in addition to. Not done now because + * keyval_parse() isn't wart-compatible with QemuOpts. + */ + if (optarg[0] =3D=3D '{') { + Visitor *v; + ObjectOptionsQueueEntry *e; + + v =3D qobject_input_visitor_new_str(optarg, "qom-type", + &err); + if (!v) { + error_report_err(err); + exit(1); + } + + e =3D g_new(ObjectOptionsQueueEntry, 1); + visit_type_ObjectOptions(v, NULL, &e->oo, &error_fatal= ); + visit_free(v); + loc_save(&e->loc); + QSIMPLEQ_INSERT_TAIL(&oo_queue, e, entry); + break; + } opts =3D qemu_opts_parse_noisily(qemu_find_opts("object"), optarg, true); if (!opts) { @@ -4525,6 +4572,14 @@ int main(int argc, char **argv, char **envp) =20 object_create(object_create_delayed); =20 + while (!QSIMPLEQ_EMPTY(&oo_queue)) { + ObjectOptionsQueueEntry *e =3D QSIMPLEQ_FIRST(&oo_queue); + + QSIMPLEQ_REMOVE_HEAD(&oo_queue, entry); + qapi_free_ObjectOptions(e->oo); + g_free(e); + } + #ifdef CONFIG_TPM if (tpm_init() < 0) { exit(1); --=20 2.7.5