From nobody Tue May 7 01:05:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1635960749735351.1221910140715; Wed, 3 Nov 2021 10:32:29 -0700 (PDT) Received: from localhost ([::1]:38734 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1miK7g-0003cS-ET for importer@patchew.org; Wed, 03 Nov 2021 13:32:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41972) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1miK5f-0000nw-2a for qemu-devel@nongnu.org; Wed, 03 Nov 2021 13:30:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:30155) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1miK5b-0001IO-El for qemu-devel@nongnu.org; Wed, 03 Nov 2021 13:30:21 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-245-6znBwnKHNeaEDmHct62JTw-1; Wed, 03 Nov 2021 13:30:16 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 637AF806688 for ; Wed, 3 Nov 2021 17:30:15 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.193.213]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6B5E1794DE; Wed, 3 Nov 2021 17:30:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635960617; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OVvbInFKSgK0TmjPAgDP+1Hq7QXSUbBoQi6FBr5BeRs=; b=WHaWk1dM2JinHSqgMaPzu/9vewLRhPDbTLQ+IB8kyNKipJFv78d1Q86ITjLNfc8IuC+lfJ klZXI7M0aEFJIBfYkI54+oSIL1bLS2cbKQAKMz4yLHP8mN00ASB8sZFt/ddjCrQ46DowmR Z80LdriEIUL6fWVHwVEM2MxPEHb5brs= X-MC-Unique: 6znBwnKHNeaEDmHct62JTw-1 From: Kevin Wolf To: qemu-devel@nongnu.org Subject: [RFC PATCH 01/12] qapi: Add visit_next_struct_member() Date: Wed, 3 Nov 2021 18:29:51 +0100 Message-Id: <20211103173002.209906-2-kwolf@redhat.com> In-Reply-To: <20211103173002.209906-1-kwolf@redhat.com> References: <20211103173002.209906-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.717, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, berrange@redhat.com, ehabkost@redhat.com, armbru@redhat.com, pbonzini@redhat.com, eblake@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1635960751362100003 Content-Type: text/plain; charset="utf-8" This adds a way to generically deal with an unknown set of members in input visitors by just getting the name of the next unvisited member. QOM object creation code will use it to have generic code that calls property setters which then in turn have the more specific knowledge how to visit the respective member. Signed-off-by: Kevin Wolf --- include/qapi/visitor-impl.h | 3 +++ include/qapi/visitor.h | 2 ++ qapi/qapi-visit-core.c | 6 ++++++ qapi/qobject-input-visitor.c | 16 ++++++++++++++++ qapi/trace-events | 1 + 5 files changed, 28 insertions(+) diff --git a/include/qapi/visitor-impl.h b/include/qapi/visitor-impl.h index 2badec5ba4..af66a850ed 100644 --- a/include/qapi/visitor-impl.h +++ b/include/qapi/visitor-impl.h @@ -57,6 +57,9 @@ struct Visitor /* Must be set to visit structs */ void (*end_struct)(Visitor *v, void **obj); =20 + /* Must be set for input visitors to visit structs */ + const char *(*next_struct_member)(Visitor *v); + /* Must be set; implementations may require @list to be non-null, * but must document it. */ bool (*start_list)(Visitor *v, const char *name, GenericList **list, diff --git a/include/qapi/visitor.h b/include/qapi/visitor.h index d53a84c9ba..5a1a28f9ad 100644 --- a/include/qapi/visitor.h +++ b/include/qapi/visitor.h @@ -326,6 +326,8 @@ bool visit_check_struct(Visitor *v, Error **errp); */ void visit_end_struct(Visitor *v, void **obj); =20 +/* TODO */ +const char *visit_next_struct_member(Visitor *v); =20 /*** Visiting lists ***/ =20 diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c index 6c13510a2b..82fb63e459 100644 --- a/qapi/qapi-visit-core.c +++ b/qapi/qapi-visit-core.c @@ -70,6 +70,12 @@ void visit_end_struct(Visitor *v, void **obj) v->end_struct(v, obj); } =20 +const char *visit_next_struct_member(Visitor *v) +{ + trace_visit_next_struct_member(v); + return v->next_struct_member(v); +} + bool visit_start_list(Visitor *v, const char *name, GenericList **list, size_t size, Error **errp) { diff --git a/qapi/qobject-input-visitor.c b/qapi/qobject-input-visitor.c index f0b4c7ca9d..a409b841af 100644 --- a/qapi/qobject-input-visitor.c +++ b/qapi/qobject-input-visitor.c @@ -310,6 +310,21 @@ static void qobject_input_end_struct(Visitor *v, void = **obj) qobject_input_pop(v, obj); } =20 +static const char *qobject_input_next_struct_member(Visitor *v) +{ + QObjectInputVisitor *qiv =3D to_qiv(v); + StackObject *tos =3D QSLIST_FIRST(&qiv->stack); + GHashTableIter iter; + const char *key; + + assert(qobject_type(tos->obj) =3D=3D QTYPE_QDICT && tos->h); + g_hash_table_iter_init(&iter, tos->h); + if (g_hash_table_iter_next(&iter, (void **)&key, NULL)) { + return key; + } + return false; +} + =20 static bool qobject_input_start_list(Visitor *v, const char *name, GenericList **list, size_t size, @@ -700,6 +715,7 @@ static QObjectInputVisitor *qobject_input_visitor_base_= new(QObject *obj) v->visitor.start_struct =3D qobject_input_start_struct; v->visitor.check_struct =3D qobject_input_check_struct; v->visitor.end_struct =3D qobject_input_end_struct; + v->visitor.next_struct_member =3D qobject_input_next_struct_member; v->visitor.start_list =3D qobject_input_start_list; v->visitor.next_list =3D qobject_input_next_list; v->visitor.check_list =3D qobject_input_check_list; diff --git a/qapi/trace-events b/qapi/trace-events index ab108c4f0e..2d91bb6ae3 100644 --- a/qapi/trace-events +++ b/qapi/trace-events @@ -7,6 +7,7 @@ visit_complete(void *v, void *opaque) "v=3D%p opaque=3D%p" visit_start_struct(void *v, const char *name, void *obj, size_t size) "v= =3D%p name=3D%s obj=3D%p size=3D%zu" visit_check_struct(void *v) "v=3D%p" visit_end_struct(void *v, void *obj) "v=3D%p obj=3D%p" +visit_next_struct_member(void *v) "v=3D%p" =20 visit_start_list(void *v, const char *name, void *obj, size_t size) "v=3D%= p name=3D%s obj=3D%p size=3D%zu" visit_next_list(void *v, void *tail, size_t size) "v=3D%p tail=3D%p size= =3D%zu" --=20 2.31.1 From nobody Tue May 7 01:05:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1635960905861951.7713631993547; Wed, 3 Nov 2021 10:35:05 -0700 (PDT) Received: from localhost ([::1]:47610 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1miKAC-0001GE-UX for importer@patchew.org; Wed, 03 Nov 2021 13:35:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41996) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1miK5g-0000oi-0D for qemu-devel@nongnu.org; Wed, 03 Nov 2021 13:30:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:54534) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1miK5b-0001JG-QP for qemu-devel@nongnu.org; Wed, 03 Nov 2021 13:30:22 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-253-MXe1EEm7Mfa3HjOWb7XtVw-1; Wed, 03 Nov 2021 13:30:18 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2B098101F7B0 for ; Wed, 3 Nov 2021 17:30:17 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.193.213]) by smtp.corp.redhat.com (Postfix) with ESMTP id AE98A68D7D; Wed, 3 Nov 2021 17:30:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635960619; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lOT7L/i7CxEJH2QSDpk9ekZd4sA5KDsKlLG6lbGAxdg=; b=LuYw2M6hu4BVTtktslHwoRLiJDcmK1mTcGTYiKROHtFd3ZOtgMS9Z7pq2hTvvK9u4rQXAS IF2icE/or22QB5Dk7S0oqqYL3+XSV9fTqi8VaUPPQao8qo85XrdSm6JqNshqFbB/+tQulu qh2nvQxFXh09JjivC0FuYV0t/E2rgfg= X-MC-Unique: MXe1EEm7Mfa3HjOWb7XtVw-1 From: Kevin Wolf To: qemu-devel@nongnu.org Subject: [RFC PATCH 02/12] qom: Create object_configure() Date: Wed, 3 Nov 2021 18:29:52 +0100 Message-Id: <20211103173002.209906-3-kwolf@redhat.com> In-Reply-To: <20211103173002.209906-1-kwolf@redhat.com> References: <20211103173002.209906-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.717, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, berrange@redhat.com, ehabkost@redhat.com, armbru@redhat.com, pbonzini@redhat.com, eblake@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1635960907523100001 Content-Type: text/plain; charset="utf-8" This renames object_set_properties_from_qdict() to object_configure() and removes the QDict parameter from it: With visit_next_struct_member() it can set all properties without looking at the keys of the QDict. Signed-off-by: Kevin Wolf --- qom/object_interfaces.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c index 3b61c195c5..f9f5608194 100644 --- a/qom/object_interfaces.c +++ b/qom/object_interfaces.c @@ -42,16 +42,15 @@ bool user_creatable_can_be_deleted(UserCreatable *uc) } } =20 -static void object_set_properties_from_qdict(Object *obj, const QDict *qdi= ct, - Visitor *v, Error **errp) +static void object_configure(Object *obj, Visitor *v, Error **errp) { - const QDictEntry *e; + const char *key; =20 if (!visit_start_struct(v, NULL, NULL, 0, errp)) { return; } - for (e =3D qdict_first(qdict); e; e =3D qdict_next(qdict, e)) { - if (!object_property_set(obj, e->key, v, errp)) { + while ((key =3D visit_next_struct_member(v))) { + if (!object_property_set(obj, key, v, errp)) { goto out; } } @@ -69,7 +68,7 @@ void object_set_properties_from_keyval(Object *obj, const= QDict *qdict, } else { v =3D qobject_input_visitor_new_keyval(QOBJECT(qdict)); } - object_set_properties_from_qdict(obj, qdict, v, errp); + object_configure(obj, v, errp); visit_free(v); } =20 @@ -108,7 +107,7 @@ Object *user_creatable_add_type(const char *type, const= char *id, =20 assert(qdict); obj =3D object_new(type); - object_set_properties_from_qdict(obj, qdict, v, &local_err); + object_configure(obj, v, &local_err); if (local_err) { goto out; } --=20 2.31.1 From nobody Tue May 7 01:05:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1635960898426576.0892560610049; Wed, 3 Nov 2021 10:34:58 -0700 (PDT) Received: from localhost ([::1]:46916 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1miKA5-0000mp-5f for importer@patchew.org; Wed, 03 Nov 2021 13:34:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42036) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1miK5h-0000qx-DD for qemu-devel@nongnu.org; Wed, 03 Nov 2021 13:30:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:34903) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1miK5f-0001L5-CR for qemu-devel@nongnu.org; Wed, 03 Nov 2021 13:30:25 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-351-lfDnudOzNJe8rBqhYqLNOQ-1; Wed, 03 Nov 2021 13:30:21 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E67C48735EC for ; Wed, 3 Nov 2021 17:30:18 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.193.213]) by smtp.corp.redhat.com (Postfix) with ESMTP id 74D59171FF; Wed, 3 Nov 2021 17:30:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635960622; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ol7PxkSSx7cJjFOixdCvzTwqnTP555k0oF2xfT/BYG0=; b=FVHYSB8oSszMPFXct6LDNTBP+nd/35KDEiQwnWGo2QvmOgeKqov+LE/XmUQ43j/pHiESBs pBRNSUSVa7yKUDFF8q5Ft2VPwLPy2CU2/aTdXj1n0k9MluxSXlPlnb/CVnexMuGxWOQDOs nFDffPs1XY0agqfalNRFjz6rMX/A6S8= X-MC-Unique: lfDnudOzNJe8rBqhYqLNOQ-1 From: Kevin Wolf To: qemu-devel@nongnu.org Subject: [RFC PATCH 03/12] qom: Make object_configure() public Date: Wed, 3 Nov 2021 18:29:53 +0100 Message-Id: <20211103173002.209906-4-kwolf@redhat.com> In-Reply-To: <20211103173002.209906-1-kwolf@redhat.com> References: <20211103173002.209906-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.717, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, berrange@redhat.com, ehabkost@redhat.com, armbru@redhat.com, pbonzini@redhat.com, eblake@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1635960900378100001 Content-Type: text/plain; charset="utf-8" This makes object_configure() public and moves it to qom/object.c because it will need to access TypeImpl in the future. Signed-off-by: Kevin Wolf --- include/qom/object.h | 3 +++ qom/object.c | 17 +++++++++++++++++ qom/object_interfaces.c | 17 ----------------- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/include/qom/object.h b/include/qom/object.h index faae0d841f..d67ba2411d 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -770,6 +770,9 @@ void object_initialize_child_internal(Object *parent, c= onst char *propname, void *child, size_t size, const char *type); =20 +/** TODO */ +void object_configure(Object *obj, Visitor *v, Error **errp); + /** * object_dynamic_cast: * @obj: The object to cast. diff --git a/qom/object.c b/qom/object.c index 6be710bc40..d8da362987 100644 --- a/qom/object.c +++ b/qom/object.c @@ -605,6 +605,23 @@ void object_initialize_child_internal(Object *parent, &error_abort, NULL); } =20 +void object_configure(Object *obj, Visitor *v, Error **errp) +{ + const char *key; + + if (!visit_start_struct(v, NULL, NULL, 0, errp)) { + return; + } + while ((key =3D visit_next_struct_member(v))) { + if (!object_property_set(obj, key, v, errp)) { + goto out; + } + } + visit_check_struct(v, errp); +out: + visit_end_struct(v, NULL); +} + static inline bool object_property_is_child(ObjectProperty *prop) { return strstart(prop->type, "child<", NULL); diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c index f9f5608194..0e8875bf04 100644 --- a/qom/object_interfaces.c +++ b/qom/object_interfaces.c @@ -42,23 +42,6 @@ bool user_creatable_can_be_deleted(UserCreatable *uc) } } =20 -static void object_configure(Object *obj, Visitor *v, Error **errp) -{ - const char *key; - - if (!visit_start_struct(v, NULL, NULL, 0, errp)) { - return; - } - while ((key =3D visit_next_struct_member(v))) { - if (!object_property_set(obj, key, v, errp)) { - goto out; - } - } - visit_check_struct(v, errp); -out: - visit_end_struct(v, NULL); -} - void object_set_properties_from_keyval(Object *obj, const QDict *qdict, bool from_json, Error **errp) { --=20 2.31.1 From nobody Tue May 7 01:05:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 163596106018879.39113319279068; Wed, 3 Nov 2021 10:37:40 -0700 (PDT) Received: from localhost ([::1]:55648 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1miKCg-00080K-Vh for importer@patchew.org; Wed, 03 Nov 2021 13:37:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42108) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1miK5l-0000uq-Pe for qemu-devel@nongnu.org; Wed, 03 Nov 2021 13:30:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:58699) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1miK5k-0001PV-94 for qemu-devel@nongnu.org; Wed, 03 Nov 2021 13:30:29 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-294-yo5EqnhBMFqYw6Vs8hK4Ag-1; Wed, 03 Nov 2021 13:30:26 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AD4CF81CB08 for ; Wed, 3 Nov 2021 17:30:20 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.193.213]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3C12C77E26; Wed, 3 Nov 2021 17:30:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635960627; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VLRZYfvGfxA/IHhwB3u7yy3Z7nW8bMr/gA0BMGHDRoM=; b=HhTWtKve5TElRcljgGLUEUSVfPPghKt6D1S0ha7O2XgV2WLg52smdvlCpvX0zSrKdL0Ygv pLHIGyXi5KNDEfJ9Au3VQEBlnJ+QchDgzT+s6eN8RO1EgZoIg9CKLp3aZn1xFFPk151iee AqYQ0ran2AA3xe2/BMLBIbFiJkCkUxw= X-MC-Unique: yo5EqnhBMFqYw6Vs8hK4Ag-1 From: Kevin Wolf To: qemu-devel@nongnu.org Subject: [RFC PATCH 04/12] qom: Add instance_config() to TypeInfo Date: Wed, 3 Nov 2021 18:29:54 +0100 Message-Id: <20211103173002.209906-5-kwolf@redhat.com> In-Reply-To: <20211103173002.209906-1-kwolf@redhat.com> References: <20211103173002.209906-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.717, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, berrange@redhat.com, ehabkost@redhat.com, armbru@redhat.com, pbonzini@redhat.com, eblake@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1635961062416100001 Content-Type: text/plain; charset="utf-8" Instead of providing the whole configuration through property setters, object_config() can now use the instance_config() callback. Options that are not consumed by the callback (e.g. because they belong to a parent class that hasn't been converted to the new callback yet) are still set as properties. Signed-off-by: Kevin Wolf --- include/qom/object.h | 4 ++++ qom/object.c | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/qom/object.h b/include/qom/object.h index d67ba2411d..e60cacb54b 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -384,6 +384,9 @@ struct Object * for initializing its own members. * @instance_post_init: This function is called to finish initialization of * an object, after all @instance_init functions were called. + * @instance_config: This function is called to set the initial configurat= ion + * of an object. If not provided, configuration is done through property + * setters. * @instance_finalize: This function is called during object destruction. = This * is called before the parent @instance_finalize function has been call= ed. * An object should only free the members that are unique to its type in= this @@ -419,6 +422,7 @@ struct TypeInfo size_t instance_align; void (*instance_init)(Object *obj); void (*instance_post_init)(Object *obj); + bool (*instance_config)(Object *obj, Visitor *v, Error **errp); void (*instance_finalize)(Object *obj); =20 bool abstract; diff --git a/qom/object.c b/qom/object.c index d8da362987..6cacfa9ab1 100644 --- a/qom/object.c +++ b/qom/object.c @@ -60,6 +60,7 @@ struct TypeImpl =20 void (*instance_init)(Object *obj); void (*instance_post_init)(Object *obj); + bool (*instance_config)(Object *obj, Visitor *v, Error **errp); void (*instance_finalize)(Object *obj); =20 bool abstract; @@ -124,6 +125,7 @@ static TypeImpl *type_new(const TypeInfo *info) =20 ti->instance_init =3D info->instance_init; ti->instance_post_init =3D info->instance_post_init; + ti->instance_config =3D info->instance_config; ti->instance_finalize =3D info->instance_finalize; =20 ti->abstract =3D info->abstract; @@ -303,6 +305,7 @@ static void type_initialize(TypeImpl *ti) assert(ti->abstract); assert(!ti->instance_init); assert(!ti->instance_post_init); + assert(!ti->instance_config); assert(!ti->instance_finalize); assert(!ti->num_interfaces); } @@ -607,11 +610,23 @@ void object_initialize_child_internal(Object *parent, =20 void object_configure(Object *obj, Visitor *v, Error **errp) { + TypeImpl *ti; const char *key; =20 if (!visit_start_struct(v, NULL, NULL, 0, errp)) { return; } + + /* Call .instance_config, including for all parent classes */ + for (ti =3D obj->class->type; ti; ti =3D ti->parent_type) { + if (ti->instance_config) { + if (!ti->instance_config(obj, v, errp)) { + goto out; + } + } + } + + /* Set options not consumed by .instance_config as properties */ while ((key =3D visit_next_struct_member(v))) { if (!object_property_set(obj, key, v, errp)) { goto out; --=20 2.31.1 From nobody Tue May 7 01:05:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 163596081450390.29678481881979; Wed, 3 Nov 2021 10:33:34 -0700 (PDT) Received: from localhost ([::1]:42408 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1miK8j-0006Am-GY for importer@patchew.org; Wed, 03 Nov 2021 13:33:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42156) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1miK5s-00016A-5h for qemu-devel@nongnu.org; Wed, 03 Nov 2021 13:30:36 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:32346) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1miK5o-0001Pn-WF for qemu-devel@nongnu.org; Wed, 03 Nov 2021 13:30:35 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-352-b9VoA6SyMCOJzenTeWv22w-1; Wed, 03 Nov 2021 13:30:31 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7636A18A0766 for ; Wed, 3 Nov 2021 17:30:22 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.193.213]) by smtp.corp.redhat.com (Postfix) with ESMTP id 00BE05C1C5; Wed, 3 Nov 2021 17:30:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635960632; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zQpXDjLe7F+y+n6siT8saKtxHP0CQFbjEa/vW15holU=; b=I5YlfrcmhifpqBn2qTGshhosNs7xwctzefZNQEMpzsaZK2PbfPCKPNkKsuaIM85c/wCVj1 Yk7wC0EmhRT2Thj+0v+Hii33L+kL0Dqj7/mv/QugQlIvU/NmdIlZR9h6H0bxcXnBKf9++n SmLw/BjJRBTS20XZg1C3d4IQ9wJawKU= X-MC-Unique: b9VoA6SyMCOJzenTeWv22w-1 From: Kevin Wolf To: qemu-devel@nongnu.org Subject: [RFC PATCH 05/12] rng-random: Implement .instance_config Date: Wed, 3 Nov 2021 18:29:55 +0100 Message-Id: <20211103173002.209906-6-kwolf@redhat.com> In-Reply-To: <20211103173002.209906-1-kwolf@redhat.com> References: <20211103173002.209906-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.717, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, berrange@redhat.com, ehabkost@redhat.com, armbru@redhat.com, pbonzini@redhat.com, eblake@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1635960815505100001 Content-Type: text/plain; charset="utf-8" This adds an implementation for .instance_config to the rng-random object. It is split into a function doing the actual configuration and providing a native C interface and a marshalling function with a visitor interface that we want to generate from the QAPI schema later. rng-random objects are not created internally, so all callers use the .instance_config interface, and setting the 'filename' property fails after object creation, so the property setter for it can be removed now. This commit demonstrates that you can have subclasses implementing .instance_config while the parent class still uses properties for initialisation. Signed-off-by: Kevin Wolf --- backends/rng-random.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/backends/rng-random.c b/backends/rng-random.c index 7add272edd..b221308091 100644 --- a/backends/rng-random.c +++ b/backends/rng-random.c @@ -14,6 +14,7 @@ #include "sysemu/rng-random.h" #include "sysemu/rng.h" #include "qapi/error.h" +#include "qapi/visitor.h" #include "qapi/qmp/qerror.h" #include "qemu/main-loop.h" #include "qemu/module.h" @@ -89,19 +90,25 @@ static char *rng_random_get_filename(Object *obj, Error= **errp) return g_strdup(s->filename); } =20 -static void rng_random_set_filename(Object *obj, const char *filename, - Error **errp) +static bool rng_random_config(Object *obj, const char *filename, Error **e= rrp) { - RngBackend *b =3D RNG_BACKEND(obj); RngRandom *s =3D RNG_RANDOM(obj); =20 - if (b->opened) { - error_setg(errp, QERR_PERMISSION_DENIED); - return; - } - g_free(s->filename); s->filename =3D g_strdup(filename); + + return true; +} + +static bool rng_random_marshal_config(Object *obj, Visitor *v, Error **err= p) +{ + g_autofree char *filename =3D NULL; + + if (!visit_type_str(v, "filename", &filename, errp)) { + return false; + } + + return rng_random_config(obj, filename, errp); } =20 static void rng_random_init(Object *obj) @@ -131,8 +138,7 @@ static void rng_random_class_init(ObjectClass *klass, v= oid *data) rbc->request_entropy =3D rng_random_request_entropy; rbc->opened =3D rng_random_opened; object_class_property_add_str(klass, "filename", - rng_random_get_filename, - rng_random_set_filename); + rng_random_get_filename, NULL); =20 } =20 @@ -142,6 +148,7 @@ static const TypeInfo rng_random_info =3D { .instance_size =3D sizeof(RngRandom), .class_init =3D rng_random_class_init, .instance_init =3D rng_random_init, + .instance_config =3D rng_random_marshal_config, .instance_finalize =3D rng_random_finalize, }; =20 --=20 2.31.1 From nobody Tue May 7 01:05:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1635961080258727.7820459803979; Wed, 3 Nov 2021 10:38:00 -0700 (PDT) Received: from localhost ([::1]:56260 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1miKD0-0008Tv-6W for importer@patchew.org; Wed, 03 Nov 2021 13:37:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42178) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1miK60-0001DZ-S1 for qemu-devel@nongnu.org; Wed, 03 Nov 2021 13:30:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:48517) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1miK5u-0001RI-2X for qemu-devel@nongnu.org; Wed, 03 Nov 2021 13:30:39 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-191-WMihyNmNOXaAYFs8XxZM7A-1; Wed, 03 Nov 2021 13:30:35 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 36930112B8EC for ; Wed, 3 Nov 2021 17:30:24 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.193.213]) by smtp.corp.redhat.com (Postfix) with ESMTP id BA4535C1D5; Wed, 3 Nov 2021 17:30:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635960637; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vBUO77zANQCc4UOMKHc/W6RQA0bIXLxZoVHcgvcpk28=; b=gHIXB/apMo6oxHE8EG7zlSMRfLa8K6y8q/NGYOpdkcYY8nG+oKzCpQQ5cgaKixQpK9GvTR aiS3Z3S/N9mbq5Plfb5llp8ZCnmUMeocb2aEqIpaCU1nzEAPD+3e44ss+Kzn9etbXUnMba HczuG6vbZ0IvxEpIKNiFbcWZDzQ4SfI= X-MC-Unique: WMihyNmNOXaAYFs8XxZM7A-1 From: Kevin Wolf To: qemu-devel@nongnu.org Subject: [RFC PATCH 06/12] rng-backend: Implement .instance_config Date: Wed, 3 Nov 2021 18:29:56 +0100 Message-Id: <20211103173002.209906-7-kwolf@redhat.com> In-Reply-To: <20211103173002.209906-1-kwolf@redhat.com> References: <20211103173002.209906-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.717, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, berrange@redhat.com, ehabkost@redhat.com, armbru@redhat.com, pbonzini@redhat.com, eblake@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1635961081672100001 Content-Type: text/plain; charset="utf-8" This commit really only serves as an illustration because the only property in rng-backend is 'opened', which is useless and deprecated. Implement .instance_config in order to show that .instance_config is working both when parent class and subclass implement it (rng-random) and when only the parent class implements it (rng-egd). 'opened' cannot be set after creation any more with this change. This is an incompatible change, but its deprecation period is up anyway. Signed-off-by: Kevin Wolf --- backends/rng.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/backends/rng.c b/backends/rng.c index 3757b04485..840daf0392 100644 --- a/backends/rng.c +++ b/backends/rng.c @@ -46,11 +46,6 @@ static bool rng_backend_prop_get_opened(Object *obj, Err= or **errp) return s->opened; } =20 -static void rng_backend_complete(UserCreatable *uc, Error **errp) -{ - object_property_set_bool(OBJECT(uc), "opened", true, errp); -} - static void rng_backend_prop_set_opened(Object *obj, bool value, Error **e= rrp) { RngBackend *s =3D RNG_BACKEND(obj); @@ -77,6 +72,29 @@ static void rng_backend_prop_set_opened(Object *obj, boo= l value, Error **errp) s->opened =3D true; } =20 +static void rng_backend_complete(UserCreatable *uc, Error **errp) +{ + rng_backend_prop_set_opened(OBJECT(uc), true, errp); +} + +static bool rng_backend_config(Object *obj, bool opened, Error **errp) +{ + ERRP_GUARD(); + rng_backend_prop_set_opened(obj, opened, errp); + return *errp =3D=3D NULL; +} + +static bool rng_backend_marshal_config(Object *obj, Visitor *v, Error **er= rp) +{ + bool opened; + + if (!visit_type_bool(v, "opened", &opened, errp)) { + return false; + } + + return rng_backend_config(obj, opened, errp); +} + static void rng_backend_free_request(RngRequest *req) { g_free(req->data); @@ -122,7 +140,7 @@ static void rng_backend_class_init(ObjectClass *oc, voi= d *data) =20 object_class_property_add_bool(oc, "opened", rng_backend_prop_get_opened, - rng_backend_prop_set_opened); + NULL); } =20 static const TypeInfo rng_backend_info =3D { @@ -130,6 +148,7 @@ static const TypeInfo rng_backend_info =3D { .parent =3D TYPE_OBJECT, .instance_size =3D sizeof(RngBackend), .instance_init =3D rng_backend_init, + .instance_config =3D rng_backend_marshal_config, .instance_finalize =3D rng_backend_finalize, .class_size =3D sizeof(RngBackendClass), .class_init =3D rng_backend_class_init, --=20 2.31.1 From nobody Tue May 7 01:05:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1635961584857998.692353985757; Wed, 3 Nov 2021 10:46:24 -0700 (PDT) Received: from localhost ([::1]:35184 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1miKL9-0007n7-Jo for importer@patchew.org; Wed, 03 Nov 2021 13:46:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42214) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1miK64-0001Fy-8P for qemu-devel@nongnu.org; Wed, 03 Nov 2021 13:30:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:56259) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1miK62-0001WL-9A for qemu-devel@nongnu.org; Wed, 03 Nov 2021 13:30:47 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-476-ZVTzjOdHPqqQ9wUDIr6BhA-1; Wed, 03 Nov 2021 13:30:42 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F07DF8C24C9 for ; Wed, 3 Nov 2021 17:30:25 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.193.213]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7D3C45C1D5; Wed, 3 Nov 2021 17:30:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635960645; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=czEdOd7Z3TVGN6zMECsEDXntu810MsjqgXwnoMc17og=; b=Q/QwHWAhnHNHn0yKXd9VlImJkVVT9SiewKYD2aMFaBUuovzE5qnhKNq6+47RNOSls+G5TQ BGXLp7kU6kfj0V3FhL1mkON9+lEOPOaSm9cGDrQ0jMy9kIQJMyZs2ApxOtQoMNnwzFyZPi MMfxOSu7fNwqEr/ylUBdlRhyiAzlWeA= X-MC-Unique: ZVTzjOdHPqqQ9wUDIr6BhA-1 From: Kevin Wolf To: qemu-devel@nongnu.org Subject: [RFC PATCH 07/12] qapi: Allow defining QOM classes Date: Wed, 3 Nov 2021 18:29:57 +0100 Message-Id: <20211103173002.209906-8-kwolf@redhat.com> In-Reply-To: <20211103173002.209906-1-kwolf@redhat.com> References: <20211103173002.209906-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.717, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, berrange@redhat.com, ehabkost@redhat.com, armbru@redhat.com, pbonzini@redhat.com, eblake@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1635961587118100003 Content-Type: text/plain; charset="utf-8" Signed-off-by: Kevin Wolf --- scripts/qapi/expr.py | 28 +++++++++++++++++- scripts/qapi/schema.py | 66 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+), 1 deletion(-) diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index 3cb389e875..77550629f3 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -181,6 +181,8 @@ def check_defn_name_str(name: str, info: QAPISourceInfo= , meta: str) -> None: """ if meta =3D=3D 'event': check_name_upper(name, info, meta) + elif meta =3D=3D 'class': + check_name_str(name, info, meta) elif meta =3D=3D 'command': check_name_lower( name, info, meta, @@ -557,6 +559,24 @@ def check_alternate(expr: _JSONObject, info: QAPISourc= eInfo) -> None: check_type(value['type'], info, source) =20 =20 +def check_class(expr: _JSONObject, info: QAPISourceInfo) -> None: + """ + Normalize and validate this expression as a ``class`` definition. + + :param expr: The expression to validate. + :param info: QAPI schema source file information. + + :raise QAPISemError: When ``expr`` is not a valid ``class``. + :return: None, ``expr`` is normalized in-place as needed. + """ + config =3D expr.get('config') + config_boxed =3D expr.get('config-boxed', False) + + if config_boxed and config is None: + raise QAPISemError(info, "'boxed': true requires 'config'") + check_type(config, info, "'config'", allow_dict=3Dnot config_boxed) + + def check_command(expr: _JSONObject, info: QAPISourceInfo) -> None: """ Normalize and validate this expression as a ``command`` definition. @@ -627,7 +647,7 @@ def check_exprs(exprs: List[_JSONObject]) -> List[_JSON= Object]: continue =20 metas =3D expr.keys() & {'enum', 'struct', 'union', 'alternate', - 'command', 'event'} + 'class', 'command', 'event'} if len(metas) !=3D 1: raise QAPISemError( info, @@ -671,6 +691,12 @@ def check_exprs(exprs: List[_JSONObject]) -> List[_JSO= NObject]: ['struct', 'data'], ['base', 'if', 'features']) normalize_members(expr['data']) check_struct(expr, info) + elif meta =3D=3D 'class': + check_keys(expr, info, meta, + ['class'], ['if', 'features', 'parent', 'config', + 'config-boxed']) + normalize_members(expr.get('config')) + check_class(expr, info) elif meta =3D=3D 'command': check_keys(expr, info, meta, ['command'], diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index b7b3fc0ce4..ebf69341d7 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -155,6 +155,9 @@ def visit_object_type_flat(self, name, info, ifcond, fe= atures, def visit_alternate_type(self, name, info, ifcond, features, variants): pass =20 + def visit_class(self, entity): + pass + def visit_command(self, name, info, ifcond, features, arg_type, ret_type, gen, success_response, boxed, allow_oob, allow_preconfig, coroutine): @@ -766,6 +769,50 @@ def __init__(self, name, info, typ, ifcond=3DNone): super().__init__(name, info, typ, False, ifcond) =20 =20 +class QAPISchemaClass(QAPISchemaEntity): + meta =3D 'class' + + def __init__(self, name, info, doc, ifcond, features, parent, + config_type, config_boxed): + super().__init__(name, info, doc, ifcond, features) + + assert not parent or isinstance(parent, str) + assert not config_type or isinstance(config_type, str) + self._parent_name =3D parent + self.parent =3D None + self._config_type_name =3D config_type + self.config_type =3D None + self.config_boxed =3D config_boxed + + def check(self, schema): + super().check(schema) + + if self._parent_name: + self.parent =3D schema.lookup_entity(self._parent_name, + QAPISchemaClass) + if not self.parent: + raise QAPISemError( + self.info, + "Unknown parent class '%s'" % self._parent_name) + + if self._config_type_name: + self.config_type =3D schema.resolve_type( + self._config_type_name, self.info, "class 'config'") + if not isinstance(self.config_type, QAPISchemaObjectType): + raise QAPISemError( + self.info, + "class 'config' cannot take %s" + % self.config_type.describe()) + if self.config_type.variants and not self.boxed: + raise QAPISemError( + self.info, + "class 'config' can take %s only with 'boxed': true" + % self.config_type.describe()) + + def visit(self, visitor): + super().visit(visitor) + visitor.visit_class(self) + class QAPISchemaCommand(QAPISchemaEntity): meta =3D 'command' =20 @@ -1110,6 +1157,23 @@ def _def_alternate_type(self, expr, info, doc): QAPISchemaVariants( None, info, tag_member, variants))) =20 + def _def_class(self, expr, info, doc): + name =3D expr['class'] + ifcond =3D QAPISchemaIfCond(expr.get('if')) + features =3D self._make_features(expr.get('features'), info) + parent =3D expr.get('parent') + config_type =3D expr.get('config') + config_boxed =3D expr.get('config-boxed') + + if isinstance(config_type, OrderedDict): + config_type =3D self._make_implicit_object_type( + name, info, ifcond, + 'config', self._make_members(config_type, info)) + + self._def_entity(QAPISchemaClass( + name, info, doc, ifcond, features, parent, config_type, + config_boxed)) + def _def_command(self, expr, info, doc): name =3D expr['command'] data =3D expr.get('data') @@ -1161,6 +1225,8 @@ def _def_exprs(self, exprs): self._def_union_type(expr, info, doc) elif 'alternate' in expr: self._def_alternate_type(expr, info, doc) + elif 'class' in expr: + self._def_class(expr, info, doc) elif 'command' in expr: self._def_command(expr, info, doc) elif 'event' in expr: --=20 2.31.1 From nobody Tue May 7 01:05:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1635961563833416.70256337645003; Wed, 3 Nov 2021 10:46:03 -0700 (PDT) Received: from localhost ([::1]:34772 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1miKKn-000787-F3 for importer@patchew.org; Wed, 03 Nov 2021 13:46:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42258) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1miK68-0001La-Bn for qemu-devel@nongnu.org; Wed, 03 Nov 2021 13:30:52 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:41186) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1miK66-0001Xw-OO for qemu-devel@nongnu.org; Wed, 03 Nov 2021 13:30:52 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-299-XJwdJ3EfND6m9AeZsD-zGQ-1; Wed, 03 Nov 2021 13:30:48 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AFA1B108AB60 for ; Wed, 3 Nov 2021 17:30:27 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.193.213]) by smtp.corp.redhat.com (Postfix) with ESMTP id 45C485C1C5; Wed, 3 Nov 2021 17:30:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635960650; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wd/r6iypcmX5AQ83gBh+ngsuji95/IwW/2rA2wNNORI=; b=iygmOZXw7NdWOUOvNMjjemn4oSJlMdS3Y1eLTar8l10P+4I9QFd4K9oHtlYv4rXgRpKgn3 DM4m8z8tXwuIhVN3SZSKHX5zc4D+QELw1fhV5JoGfP64FtKWqm8Ut9GQtNBJgdGGVNT5Wt E5nSLHwQaq02bH5f8evud1f/nfW2H3k= X-MC-Unique: XJwdJ3EfND6m9AeZsD-zGQ-1 From: Kevin Wolf To: qemu-devel@nongnu.org Subject: [RFC PATCH 08/12] qapi: Create qom-config:... type for classes Date: Wed, 3 Nov 2021 18:29:58 +0100 Message-Id: <20211103173002.209906-9-kwolf@redhat.com> In-Reply-To: <20211103173002.209906-1-kwolf@redhat.com> References: <20211103173002.209906-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.717, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, berrange@redhat.com, ehabkost@redhat.com, armbru@redhat.com, pbonzini@redhat.com, eblake@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1635961564544100003 Content-Type: text/plain; charset="utf-8" For every class that has a 'config' definition, a corresponding 'qom-config:$QOM_TYPE' type is automatically created that contains the configuration for the class and all of its parent classes. Signed-off-by: Kevin Wolf --- scripts/qapi/schema.py | 60 +++++++++++++++++++++++++++++++++++------- 1 file changed, 50 insertions(+), 10 deletions(-) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index ebf69341d7..79db42b810 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -761,6 +761,13 @@ def connect_doc(self, doc): for f in self.features: doc.connect_feature(f) =20 + def clone(self): + features =3D [QAPISchemaFeature(f.name, f.info, f.ifcond) + for f in self.features] + return QAPISchemaObjectTypeMember( + self.name, self.info, self._type_name, self.optional, + self.ifcond, features) + =20 class QAPISchemaVariant(QAPISchemaObjectTypeMember): role =3D 'branch' @@ -783,17 +790,11 @@ def __init__(self, name, info, doc, ifcond, features,= parent, self._config_type_name =3D config_type self.config_type =3D None self.config_boxed =3D config_boxed + self.full_config_type =3D None =20 - def check(self, schema): - super().check(schema) - - if self._parent_name: - self.parent =3D schema.lookup_entity(self._parent_name, - QAPISchemaClass) - if not self.parent: - raise QAPISemError( - self.info, - "Unknown parent class '%s'" % self._parent_name) + def get_qom_config_type(self, schema): + if self.full_config_type: + return self.full_config_type =20 if self._config_type_name: self.config_type =3D schema.resolve_type( @@ -809,6 +810,40 @@ def check(self, schema): "class 'config' can take %s only with 'boxed': true" % self.config_type.describe()) =20 + # FIXME That's a bit ugly + self.config_type.check(schema) + members =3D [m.clone() for m in self.config_type.members] + else: + members =3D [] + + if self._parent_name: + self.parent =3D schema.lookup_entity(self._parent_name, + QAPISchemaClass) + if not self.parent: + raise QAPISemError( + self.info, + "Unknown parent class '%s'" % self._parent_name) + + self.parent.get_qom_config_type(schema) + members +=3D [m.clone() for m in self.parent.config_type.membe= rs] + + self.full_config_type =3D QAPISchemaObjectType( + f"qom-config:{self.name}", self.info, None, self._ifcond, + self.features, None, members, None) + + return self.full_config_type + + def check(self, schema): + super().check(schema) + assert self.full_config_type + + def connect_doc(self, doc=3DNone): + super().connect_doc(doc) + doc =3D doc or self.doc + if doc: + if self.config_type and self.config_type.is_implicit(): + self.config_type.connect_doc(doc) + def visit(self, visitor): super().visit(visitor) visitor.visit_class(self) @@ -1236,6 +1271,11 @@ def _def_exprs(self, exprs): else: assert False =20 + classes =3D [c for c in self._entity_list + if isinstance(c,QAPISchemaClass)] + for c in classes: + self._def_entity(c.get_qom_config_type(self)) + def check(self): for ent in self._entity_list: ent.check(self) --=20 2.31.1 From nobody Tue May 7 01:05:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1635960772400139.3634861962172; Wed, 3 Nov 2021 10:32:52 -0700 (PDT) Received: from localhost ([::1]:39736 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1miK83-0004Iw-AG for importer@patchew.org; Wed, 03 Nov 2021 13:32:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42330) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1miK6F-0001Q6-V5 for qemu-devel@nongnu.org; Wed, 03 Nov 2021 13:31:01 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:52340) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1miK6E-0001Yn-DC for qemu-devel@nongnu.org; Wed, 03 Nov 2021 13:30:59 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-18-S429TtoRMVSqo0NEkRkRhA-1; Wed, 03 Nov 2021 13:30:54 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 820398C7096 for ; Wed, 3 Nov 2021 17:30:29 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.193.213]) by smtp.corp.redhat.com (Postfix) with ESMTP id 04EBF76608; Wed, 3 Nov 2021 17:30:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635960657; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SDtvmRKU5xyJhjzgQFrXlFks4jjBeGlE1v0HtMmk894=; b=R+t8SBwoLxIaQIfKM5Bzn5JIndMu165Kg1/VlVytRTt8jvXdLwkE5L4zwm2JJfkzCDz0hU h1ilkys8R+RKnYakxf86ICtgDiHEUP51HY5qG9+m7COPztcafVjRIgv8DLmy2nYczU4mz4 irrhcWZirXVykJP5nFFLf8w3qKaJZHc= X-MC-Unique: S429TtoRMVSqo0NEkRkRhA-1 From: Kevin Wolf To: qemu-devel@nongnu.org Subject: [RFC PATCH 09/12] qapi/qom: Convert rng-backend/random to class Date: Wed, 3 Nov 2021 18:29:59 +0100 Message-Id: <20211103173002.209906-10-kwolf@redhat.com> In-Reply-To: <20211103173002.209906-1-kwolf@redhat.com> References: <20211103173002.209906-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.717, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, berrange@redhat.com, ehabkost@redhat.com, armbru@redhat.com, pbonzini@redhat.com, eblake@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1635960773965100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Kevin Wolf --- qapi/qom.json | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/qapi/qom.json b/qapi/qom.json index ccd1167808..a167e91f67 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -721,6 +721,16 @@ { 'struct': 'RngProperties', 'data': { '*opened': { 'type': 'bool', 'features': ['deprecated'] } } } =20 +## +# @rng-backend: +# +# Base class for random number generator backends +# +# Since: 1.3 +## +{ 'class': 'rng-backend', + 'config': 'RngProperties' } + ## # @RngEgdProperties: # @@ -736,18 +746,18 @@ 'data': { 'chardev': 'str' } } =20 ## -# @RngRandomProperties: +# @rng-random: # -# Properties for rng-random objects. +# Random number generator backend using a host random number device # # @filename: the filename of the device on the host to obtain entropy from # (default: "/dev/urandom") # # Since: 1.3 ## -{ 'struct': 'RngRandomProperties', - 'base': 'RngProperties', - 'data': { '*filename': 'str' } } +{ 'class': 'rng-random', + 'parent': 'rng-backend', + 'config': { '*filename': 'str' } } =20 ## # @SevGuestProperties: @@ -889,7 +899,7 @@ 'qtest': 'QtestProperties', 'rng-builtin': 'RngProperties', 'rng-egd': 'RngEgdProperties', - 'rng-random': { 'type': 'RngRandomProperties', + 'rng-random': { 'type': 'qom-config:rng-random', 'if': 'CONFIG_POSIX' }, 'secret': 'SecretProperties', 'secret_keyring': { 'type': 'SecretKeyringProperties', --=20 2.31.1 From nobody Tue May 7 01:05:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1635960990595582.1968366333597; Wed, 3 Nov 2021 10:36:30 -0700 (PDT) Received: from localhost ([::1]:51072 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1miKBZ-0003gZ-Ez for importer@patchew.org; Wed, 03 Nov 2021 13:36:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42362) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1miK6H-0001Q8-23 for qemu-devel@nongnu.org; Wed, 03 Nov 2021 13:31:01 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:59695) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1miK6E-0001Yp-Ef for qemu-devel@nongnu.org; Wed, 03 Nov 2021 13:31:00 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-536-4dznlLn1MF2Ij9xbZ3-cIQ-1; Wed, 03 Nov 2021 13:30:56 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4A3248EDBEE for ; Wed, 3 Nov 2021 17:30:31 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.193.213]) by smtp.corp.redhat.com (Postfix) with ESMTP id CD5955C1C5; Wed, 3 Nov 2021 17:30:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635960657; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=khb5l0Mm9/OtR+1VGLQk/CI1QG5XhE4pFLTNNFIE7xg=; b=ZHGmFyIqHSuUVSMcQUgv6+OIGwAKehm+wWuh5ep9aMK/PHSIOXbKSnxyCwaQUurN/lGZ/v uMOEp0Pj8qLkpDxIw4/Y8XWbG7st/gGcVwHWxGBoBuMk3Q4YUI8dgnOOvML6YGfLRsyWl5 mrCoW4YqytJ3mU7HoUhy6JX8Of/wVpw= X-MC-Unique: 4dznlLn1MF2Ij9xbZ3-cIQ-1 From: Kevin Wolf To: qemu-devel@nongnu.org Subject: [RFC PATCH 10/12] qapi: Generate QOM config marshalling code Date: Wed, 3 Nov 2021 18:30:00 +0100 Message-Id: <20211103173002.209906-11-kwolf@redhat.com> In-Reply-To: <20211103173002.209906-1-kwolf@redhat.com> References: <20211103173002.209906-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.717, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, berrange@redhat.com, ehabkost@redhat.com, armbru@redhat.com, pbonzini@redhat.com, eblake@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1635960992317100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Kevin Wolf --- backends/rng-random.c | 17 ++------ backends/rng.c | 17 ++------ scripts/qapi/main.py | 2 + scripts/qapi/qom.py | 91 +++++++++++++++++++++++++++++++++++++++++++ qapi/meson.build | 3 ++ 5 files changed, 104 insertions(+), 26 deletions(-) create mode 100644 scripts/qapi/qom.py diff --git a/backends/rng-random.c b/backends/rng-random.c index b221308091..35738df3c6 100644 --- a/backends/rng-random.c +++ b/backends/rng-random.c @@ -14,6 +14,7 @@ #include "sysemu/rng-random.h" #include "sysemu/rng.h" #include "qapi/error.h" +#include "qapi/qapi-qom-qom.h" #include "qapi/visitor.h" #include "qapi/qmp/qerror.h" #include "qemu/main-loop.h" @@ -90,7 +91,8 @@ static char *rng_random_get_filename(Object *obj, Error *= *errp) return g_strdup(s->filename); } =20 -static bool rng_random_config(Object *obj, const char *filename, Error **e= rrp) +bool qom_rng_random_config(Object *obj, bool has_filename, + const char *filename, Error **errp) { RngRandom *s =3D RNG_RANDOM(obj); =20 @@ -100,17 +102,6 @@ static bool rng_random_config(Object *obj, const char = *filename, Error **errp) return true; } =20 -static bool rng_random_marshal_config(Object *obj, Visitor *v, Error **err= p) -{ - g_autofree char *filename =3D NULL; - - if (!visit_type_str(v, "filename", &filename, errp)) { - return false; - } - - return rng_random_config(obj, filename, errp); -} - static void rng_random_init(Object *obj) { RngRandom *s =3D RNG_RANDOM(obj); @@ -148,7 +139,7 @@ static const TypeInfo rng_random_info =3D { .instance_size =3D sizeof(RngRandom), .class_init =3D rng_random_class_init, .instance_init =3D rng_random_init, - .instance_config =3D rng_random_marshal_config, + .instance_config =3D qom_rng_random_marshal_config, .instance_finalize =3D rng_random_finalize, }; =20 diff --git a/backends/rng.c b/backends/rng.c index 840daf0392..d560bd7b5d 100644 --- a/backends/rng.c +++ b/backends/rng.c @@ -13,6 +13,7 @@ #include "qemu/osdep.h" #include "sysemu/rng.h" #include "qapi/error.h" +#include "qapi/qapi-qom-qom.h" #include "qapi/qmp/qerror.h" #include "qemu/module.h" #include "qom/object_interfaces.h" @@ -77,24 +78,14 @@ static void rng_backend_complete(UserCreatable *uc, Err= or **errp) rng_backend_prop_set_opened(OBJECT(uc), true, errp); } =20 -static bool rng_backend_config(Object *obj, bool opened, Error **errp) +bool qom_rng_backend_config(Object *obj, bool has_opened, bool opened, + Error **errp) { ERRP_GUARD(); rng_backend_prop_set_opened(obj, opened, errp); return *errp =3D=3D NULL; } =20 -static bool rng_backend_marshal_config(Object *obj, Visitor *v, Error **er= rp) -{ - bool opened; - - if (!visit_type_bool(v, "opened", &opened, errp)) { - return false; - } - - return rng_backend_config(obj, opened, errp); -} - static void rng_backend_free_request(RngRequest *req) { g_free(req->data); @@ -148,7 +139,7 @@ static const TypeInfo rng_backend_info =3D { .parent =3D TYPE_OBJECT, .instance_size =3D sizeof(RngBackend), .instance_init =3D rng_backend_init, - .instance_config =3D rng_backend_marshal_config, + .instance_config =3D qom_rng_backend_marshal_config, .instance_finalize =3D rng_backend_finalize, .class_size =3D sizeof(RngBackendClass), .class_init =3D rng_backend_class_init, diff --git a/scripts/qapi/main.py b/scripts/qapi/main.py index f2ea6e0ce4..b6b4a4a74d 100644 --- a/scripts/qapi/main.py +++ b/scripts/qapi/main.py @@ -16,6 +16,7 @@ from .error import QAPIError from .events import gen_events from .introspect import gen_introspect +from .qom import gen_qom from .schema import QAPISchema from .types import gen_types from .visit import gen_visit @@ -52,6 +53,7 @@ def generate(schema_file: str, gen_commands(schema, output_dir, prefix) gen_events(schema, output_dir, prefix) gen_introspect(schema, output_dir, prefix, unmask) + gen_qom(schema, output_dir, prefix) =20 =20 def main() -> int: diff --git a/scripts/qapi/qom.py b/scripts/qapi/qom.py new file mode 100644 index 0000000000..1cca94890f --- /dev/null +++ b/scripts/qapi/qom.py @@ -0,0 +1,91 @@ +""" +QAPI QOM boilerplate generator + +Copyright (c) 2021 Red Hat Inc. + +Authors: + Kevin Wolf + +This work is licensed under the terms of the GNU GPL, version 2. +See the COPYING file in the top-level directory. +""" + +from .common import c_name, mcgen +from .gen import ( + build_params, + QAPISchemaModularCVisitor, +) +from .schema import ( + QAPISchema, + QAPISchemaClass, +) + + +def gen_config_decl(c: QAPISchemaClass) -> str: + params =3D build_params(c.config_type, c.config_boxed, 'Error **errp') + return mcgen(''' +bool qom_%(name)s_marshal_config(Object *obj, Visitor *v, Error **errp); +bool qom_%(name)s_config(Object *obj, %(params)s); +''', name=3Dc.c_name(), params=3Dparams) + + +def gen_config_call(c: QAPISchemaClass) -> str: + if c.config_boxed: + argstr =3D '&config, ' + else: + assert not c.config_type.variants + argstr =3D '' + for m in c.config_type.members: + if m.optional: + argstr +=3D 'config.has_%s, ' % c_name(m.name) + argstr +=3D 'config.%s, ' % c_name(m.name) + + return f'qom_{c.c_name()}_config(obj, {argstr}errp)' + +def gen_config(c: QAPISchemaClass) -> str: + return mcgen(''' +bool qom_%(qom_type)s_marshal_config(Object *obj, Visitor *v, Error **errp) +{ + %(config_name)s config =3D {0}; + + if (!visit_type_%(config_name)s_members(v, &config, errp)) { + return false; + } + + return %(call)s; +} + +''', qom_type=3Dc.c_name(), config_name=3Dc.config_type.c_name(), + call=3Dgen_config_call(c)) + + +class QAPISchemaGenQOMVisitor(QAPISchemaModularCVisitor): + + def __init__(self, prefix: str): + super().__init__( + prefix, 'qapi-qom', ' * Schema-defined QOM types', + None, __doc__) + + def _begin_user_module(self, name: str) -> None: + qom =3D self._module_basename('qapi-qom', name) + types =3D self._module_basename('qapi-types', name) + visit =3D self._module_basename('qapi-visit', name) + self._genc.add(mcgen(''' +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "%(qom)s.h" +#include "%(types)s.h" +#include "%(visit)s.h" + +''', types=3Dtypes, visit=3Dvisit, qom=3Dqom)) + + def visit_class(self, c: QAPISchemaClass) -> None: + if c.config_type: + self._genh.add(gen_config_decl(c)) + self._genc.add(gen_config(c)) + + +def gen_qom(schema: QAPISchema, output_dir: str, prefix: str) -> None: + vis =3D QAPISchemaGenQOMVisitor(prefix) + schema.visit(vis) + vis.write(output_dir) diff --git a/qapi/meson.build b/qapi/meson.build index c356a385e3..10c412f1ad 100644 --- a/qapi/meson.build +++ b/qapi/meson.build @@ -87,6 +87,7 @@ qapi_nonmodule_outputs =3D [ 'qapi-init-commands.h', 'qapi-init-commands.c', 'qapi-events.h', 'qapi-events.c', 'qapi-emit-events.c', 'qapi-emit-events.h', + 'qapi-qom.h', 'qapi-qom.c', ] =20 # First build all sources @@ -111,6 +112,8 @@ foreach module : qapi_all_modules 'qapi-events-@0@.h'.format(module), 'qapi-commands-@0@.c'.format(module), 'qapi-commands-@0@.h'.format(module), + 'qapi-qom-@0@.c'.format(module), + 'qapi-qom-@0@.h'.format(module), ] endif if module.endswith('-target') --=20 2.31.1 From nobody Tue May 7 01:05:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1635961038412874.4880067776639; Wed, 3 Nov 2021 10:37:18 -0700 (PDT) Received: from localhost ([::1]:53900 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1miKCL-0006YZ-8P for importer@patchew.org; Wed, 03 Nov 2021 13:37:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42328) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1miK6F-0001Q2-Hw for qemu-devel@nongnu.org; Wed, 03 Nov 2021 13:31:01 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:59596) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1miK6D-0001Yc-I4 for qemu-devel@nongnu.org; Wed, 03 Nov 2021 13:30:59 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-153-WHRPcP-INq6tQlTx8V__YA-1; Wed, 03 Nov 2021 13:30:55 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 062B78AF873 for ; Wed, 3 Nov 2021 17:30:33 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.193.213]) by smtp.corp.redhat.com (Postfix) with ESMTP id 930E65C1C5; Wed, 3 Nov 2021 17:30:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635960657; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=56cyg3ToiN4nDVVcf4tmfjZ7QvgUZfiqwwHpGqX5a2o=; b=aiIqGbs91x/g5dpneUscRV5NrRmXvSkxulYeZsLo9S2A4Jqy3gbsIhnbn+aNO4Ldathp1/ k8N8zllqhq6mrqQHjN+Ij+pSign9D9vrbjK3woQ3dIkneFPlHr1UtN6WbSHYOSZGlMc64C xl31W+M3NiuA6SPv9EdRHfFeX8AYBkQ= X-MC-Unique: WHRPcP-INq6tQlTx8V__YA-1 From: Kevin Wolf To: qemu-devel@nongnu.org Subject: [RFC PATCH 11/12] qapi/qom: Add class definition for rng-builtin Date: Wed, 3 Nov 2021 18:30:01 +0100 Message-Id: <20211103173002.209906-12-kwolf@redhat.com> In-Reply-To: <20211103173002.209906-1-kwolf@redhat.com> References: <20211103173002.209906-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.717, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, berrange@redhat.com, ehabkost@redhat.com, armbru@redhat.com, pbonzini@redhat.com, eblake@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1635961039484100001 Content-Type: text/plain; charset="utf-8" This doesn't add any configuration options compared to its parent class, so this just makes the schema a little more descriptive with no other code changes. Signed-off-by: Kevin Wolf --- qapi/qom.json | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/qapi/qom.json b/qapi/qom.json index a167e91f67..864c6a658b 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -731,6 +731,16 @@ { 'class': 'rng-backend', 'config': 'RngProperties' } =20 +## +# @rng-builtin: +# +# Built-in random number generator backend +# +# Since: 1.3 +## +{ 'class': 'rng-builtin', + 'parent': 'rng-backend' } + ## # @RngEgdProperties: # @@ -897,7 +907,7 @@ 'pr-manager-helper': { 'type': 'PrManagerHelperProperties', 'if': 'CONFIG_LINUX' }, 'qtest': 'QtestProperties', - 'rng-builtin': 'RngProperties', + 'rng-builtin': 'qom-config:rng-builtin', 'rng-egd': 'RngEgdProperties', 'rng-random': { 'type': 'qom-config:rng-random', 'if': 'CONFIG_POSIX' }, --=20 2.31.1 From nobody Tue May 7 01:05:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1635961877195373.8326574061482; Wed, 3 Nov 2021 10:51:17 -0700 (PDT) Received: from localhost ([::1]:43228 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1miKPs-0002Zo-7A for importer@patchew.org; Wed, 03 Nov 2021 13:51:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42366) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1miK6H-0001Qi-LA for qemu-devel@nongnu.org; Wed, 03 Nov 2021 13:31:01 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:39684) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1miK6G-0001ZV-0x for qemu-devel@nongnu.org; Wed, 03 Nov 2021 13:31:01 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-194-G3SnlGWWMWOh2CBOY8-yaw-1; Wed, 03 Nov 2021 13:30:58 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B8522EC1B5 for ; Wed, 3 Nov 2021 17:30:34 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.193.213]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4F2D15C1C5; Wed, 3 Nov 2021 17:30:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635960659; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=v0gRVdbdei3KvN7oEqfXcjaFn66/4qm3PHrC/OfMAE0=; b=Tce96AjsR7AjgpIyZriZ0CBoqEmdgt4x5pMlPDualOf42OOsL4zbxh/EArbPVsbyB7apkn nOHxva+e52h7JIPjP+Rsn/jeaCCr/EMtKKelNWTLxAq8w29MftPoYaVHitdiPlqtXjoNaC q9ArCu72L6J7A2cvJ+10KEtNyZPL2bo= X-MC-Unique: G3SnlGWWMWOh2CBOY8-yaw-1 From: Kevin Wolf To: qemu-devel@nongnu.org Subject: [RFC PATCH 12/12] qapi/qom: Add class definition for rng-egd Date: Wed, 3 Nov 2021 18:30:02 +0100 Message-Id: <20211103173002.209906-13-kwolf@redhat.com> In-Reply-To: <20211103173002.209906-1-kwolf@redhat.com> References: <20211103173002.209906-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.717, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, berrange@redhat.com, ehabkost@redhat.com, armbru@redhat.com, pbonzini@redhat.com, eblake@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1635961878768100001 Content-Type: text/plain; charset="utf-8" Switch object creation to .instance_config and remove the property setter that would only return an error after creation anyway. Signed-off-by: Kevin Wolf --- qapi/qom.json | 12 ++++++------ backends/rng-egd.c | 18 +++++++----------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/qapi/qom.json b/qapi/qom.json index 864c6a658b..fce24428f8 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -742,18 +742,18 @@ 'parent': 'rng-backend' } =20 ## -# @RngEgdProperties: +# @rng-egd: # -# Properties for rng-egd objects. +# Random number generator backend connecting to an EGD-compatible daemon # # @chardev: the name of a character device backend that provides the conne= ction # to the RNG daemon # # Since: 1.3 ## -{ 'struct': 'RngEgdProperties', - 'base': 'RngProperties', - 'data': { 'chardev': 'str' } } +{ 'class': 'rng-egd', + 'parent': 'rng-backend', + 'config': { 'chardev': 'str' } } =20 ## # @rng-random: @@ -908,7 +908,7 @@ 'if': 'CONFIG_LINUX' }, 'qtest': 'QtestProperties', 'rng-builtin': 'qom-config:rng-builtin', - 'rng-egd': 'RngEgdProperties', + 'rng-egd': 'qom-config:rng-egd', 'rng-random': { 'type': 'qom-config:rng-random', 'if': 'CONFIG_POSIX' }, 'secret': 'SecretProperties', diff --git a/backends/rng-egd.c b/backends/rng-egd.c index 4de142b9dc..89255dc6fa 100644 --- a/backends/rng-egd.c +++ b/backends/rng-egd.c @@ -15,6 +15,7 @@ #include "chardev/char-fe.h" #include "qapi/error.h" #include "qapi/qmp/qerror.h" +#include "qapi/qapi-qom-qom.h" #include "qemu/module.h" #include "qom/object.h" =20 @@ -110,17 +111,12 @@ static void rng_egd_opened(RngBackend *b, Error **err= p) rng_egd_chr_read, NULL, NULL, s, NULL, true); } =20 -static void rng_egd_set_chardev(Object *obj, const char *value, Error **er= rp) +bool qom_rng_egd_config(Object *obj, const char *chardev, Error **errp) { - RngBackend *b =3D RNG_BACKEND(obj); - RngEgd *s =3D RNG_EGD(b); + RngEgd *s =3D RNG_EGD(obj); =20 - if (b->opened) { - error_setg(errp, QERR_PERMISSION_DENIED); - } else { - g_free(s->chr_name); - s->chr_name =3D g_strdup(value); - } + s->chr_name =3D g_strdup(chardev); + return true; } =20 static char *rng_egd_get_chardev(Object *obj, Error **errp) @@ -149,8 +145,7 @@ static void rng_egd_class_init(ObjectClass *klass, void= *data) =20 rbc->request_entropy =3D rng_egd_request_entropy; rbc->opened =3D rng_egd_opened; - object_class_property_add_str(klass, "chardev", - rng_egd_get_chardev, rng_egd_set_chardev= ); + object_class_property_add_str(klass, "chardev", rng_egd_get_chardev, N= ULL); } =20 static const TypeInfo rng_egd_info =3D { @@ -158,6 +153,7 @@ static const TypeInfo rng_egd_info =3D { .parent =3D TYPE_RNG_BACKEND, .instance_size =3D sizeof(RngEgd), .class_init =3D rng_egd_class_init, + .instance_config =3D qom_rng_egd_marshal_config, .instance_finalize =3D rng_egd_finalize, }; =20 --=20 2.31.1