From nobody Mon Feb 9 05:18:56 2026 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 ARC-Seal: i=1; a=rsa-sha256; t=1605219098; cv=none; d=zohomail.com; s=zohoarc; b=a7hBfTNajUo/J8lVIWGOuLNNpcr4IhDb8bi5HTlvwBEHAH0shFDFA8M9GJ1mIVwkA1zEXuVeeC91gok2iTdlzWt2TK3L7bo7U2yg0ceGW2MQdooqN4s+c5Cm91wkswe86E1Ry7DOwg/bBwsEA33NK5mkIasUM7MxtVCb89ntF+8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605219098; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=EEDG9Rp82MKd8keWELsCUMQrOmi76cKVVr3EnZnuOn4=; b=Ydu1tH1plFBHwU7wh+grUy1ccJAYO+/Pealw9iw5Quif13Nl2fnO8mQwqSK4kwdHh8xHA/MSOQCDmFt3uuNz7aAp5cmCbFZj6GroVEbRaP/23PYLJX8U1VXnTG/gGvVYF+0ZdfuzvfYvHmCzSkrWtRAmr/ZFHWlZ4wxaGpmVv5o= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1605219098113923.7178531606313; Thu, 12 Nov 2020 14:11:38 -0800 (PST) Received: from localhost ([::1]:42238 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kdKob-0003uC-16 for importer@patchew.org; Thu, 12 Nov 2020 17:11:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33714) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kdKQQ-0007k5-RZ for qemu-devel@nongnu.org; Thu, 12 Nov 2020 16:46:42 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:25401) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kdKQO-0003eO-IZ for qemu-devel@nongnu.org; Thu, 12 Nov 2020 16:46:38 -0500 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-205-W0ZsSr8DMA6Q4ZLgb-DV8A-1; Thu, 12 Nov 2020 16:46:32 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 08A568049D5; Thu, 12 Nov 2020 21:46:31 +0000 (UTC) Received: from localhost (ovpn-114-68.rdu2.redhat.com [10.10.114.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id BCA865D9CA; Thu, 12 Nov 2020 21:46:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605217595; 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=EEDG9Rp82MKd8keWELsCUMQrOmi76cKVVr3EnZnuOn4=; b=ewI1bnrkhZjIG0LqfN3NJKkuEXbUoD5WxWIGpr7rVCh67GxVH+B0JACwAhP0iL/9nMJwoT mCsOPzEeAbpPmYr46516k57y0+oXhV8S2ZUJdtS+I61lEY8vWoSIkkyrj7VQPx4y0xUeWe +TgQobmDOm0m0b/MCA50iv5kCN0SzKY= X-MC-Unique: W0ZsSr8DMA6Q4ZLgb-DV8A-1 From: Eduardo Habkost To: qemu-devel@nongnu.org Subject: [PATCH v3 34/53] qdev: Make qdev_prop_allow_set() a ObjectProperty.allow_set callback Date: Thu, 12 Nov 2020 16:43:31 -0500 Message-Id: <20201112214350.872250-35-ehabkost@redhat.com> In-Reply-To: <20201112214350.872250-1-ehabkost@redhat.com> References: <20201112214350.872250-1-ehabkost@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=ehabkost@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" 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=ehabkost@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/12 08:00:44 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , "Daniel P. Berrange" , John Snow , Markus Armbruster , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Igor Mammedov , Stefan Berger Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Add a new allow_set parameter to object*_property_add_field(), and pass qdev_prop_allow_set as argument in the qdev registration code. This removes the last remaining line of code inside the core field property code that's specific to TYPE_DEVICE, and will allow us to make field properties a core QOM feature. The array property also needs to set PropertyInfo.allow_set manually, but this will be cleaned up later (that code will be changed to use object_class_property_add_field() too). Signed-off-by: Eduardo Habkost --- Changes v2 -> v3: * Moved earlier in the series, before array property cleanup (I did this to allow us to move the code to QOM earlier) * Redone after object_class_add_field_properties() was reintroduced Changes v1 -> v2: * Redone patch on top of changes in previous patches in the series * Forbid allow_set=3D=3DNULL to avoid confusion with link property semantics (where NULL makes the property read only) --- Cc: Paolo Bonzini Cc: "Daniel P. Berrang=C3=A9" Cc: Eduardo Habkost Cc: qemu-devel@nongnu.org --- hw/core/qdev-prop-internal.h | 16 ++++++++--- hw/core/qdev-properties.c | 51 ++++++++++++++++++++++-------------- 2 files changed, 45 insertions(+), 22 deletions(-) diff --git a/hw/core/qdev-prop-internal.h b/hw/core/qdev-prop-internal.h index 740a5e530b..47bab46810 100644 --- a/hw/core/qdev-prop-internal.h +++ b/hw/core/qdev-prop-internal.h @@ -30,34 +30,43 @@ void field_prop_get_size32(Object *obj, Visitor *v, con= st char *name, * @obj: object instance * @name: property name * @prop: property definition + * @allow_set: check function called when property is set * * This function should not be used in new code. Please add class propert= ies * instead, using object_class_add_field(). */ ObjectProperty * object_property_add_field(Object *obj, const char *name, - Property *prop); + Property *prop, + ObjectPropertyAllowSet allow_set); =20 /** * object_class_property_add_field_static: Add a field property to object = class * @oc: object class * @name: property name * @prop: property definition + * @allow_set: check function called when property is set * * Add a field property to an object class. A field property is * a property that will change a field at a specific offset of the * object instance struct. * * *@prop must have static life time. + * + * @allow_set should not be NULL. If the property can always be + * set, `prop_allow_set_always` can be used. If the property can + * never be set, `prop_allow_set_never` can be used. */ ObjectProperty * object_class_property_add_field_static(ObjectClass *oc, const char *name, - Property *prop); + Property *prop, + ObjectPropertyAllowSet allow_set); =20 /** * object_class_add_field_properties: Add field properties from array to a= class * @oc: object class * @props: array of property definitions + * @allow_set: check function called when property is set * * Register an array of field properties to a class, using * object_class_property_add_field_static() for each array element. @@ -65,6 +74,7 @@ object_class_property_add_field_static(ObjectClass *oc, c= onst char *name, * The array at @props must end with DEFINE_PROP_END_OF_LIST(), and * must have static life time. */ -void object_class_add_field_properties(ObjectClass *oc, Property *props); +void object_class_add_field_properties(ObjectClass *oc, Property *props, + ObjectPropertyAllowSet allow_set); =20 #endif diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index 9d25b49fc1..638daf1ebf 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -25,13 +25,13 @@ void qdev_prop_set_after_realize(DeviceState *dev, cons= t char *name, } =20 /* returns: true if property is allowed to be set, false otherwise */ -static bool qdev_prop_allow_set(Object *obj, const char *name, +static bool qdev_prop_allow_set(Object *obj, ObjectProperty *op, Error **errp) { DeviceState *dev =3D DEVICE(obj); =20 if (dev->realized) { - qdev_prop_set_after_realize(dev, name, errp); + qdev_prop_set_after_realize(dev, op->name, errp); return false; } return true; @@ -79,10 +79,6 @@ static void field_prop_set(Object *obj, Visitor *v, cons= t char *name, { Property *prop =3D opaque; =20 - if (!qdev_prop_allow_set(obj, name, errp)) { - return; - } - return prop->info->set(obj, v, name, opaque, errp); } =20 @@ -560,6 +556,7 @@ static void set_prop_arraylen(Object *obj, Visitor *v, = const char *name, * array itself and dynamically add the corresponding properties. */ Property *prop =3D opaque; + ObjectProperty *op =3D object_property_find_err(obj, name, &error_abor= t); uint32_t *alenptr =3D object_field_prop_ptr(obj, prop); void **arrayptr =3D (void *)obj + prop->arrayoffset; void *eltptr; @@ -592,6 +589,7 @@ static void set_prop_arraylen(Object *obj, Visitor *v, = const char *name, for (i =3D 0; i < *alenptr; i++, eltptr +=3D prop->arrayfieldsize) { char *propname =3D g_strdup_printf("%s[%d]", arrayname, i); ArrayElementProperty *arrayprop =3D g_new0(ArrayElementProperty, 1= ); + ObjectProperty *elmop; arrayprop->release =3D prop->arrayinfo->release; arrayprop->propname =3D propname; arrayprop->prop.info =3D prop->arrayinfo; @@ -603,12 +601,13 @@ static void set_prop_arraylen(Object *obj, Visitor *v= , const char *name, */ arrayprop->prop.offset =3D eltptr - (void *)obj; assert(object_field_prop_ptr(obj, &arrayprop->prop) =3D=3D eltptr); - object_property_add(obj, propname, - arrayprop->prop.info->name, - field_prop_getter(arrayprop->prop.info), - field_prop_setter(arrayprop->prop.info), - array_element_release, - arrayprop); + elmop =3D object_property_add(obj, propname, + arrayprop->prop.info->name, + field_prop_getter(arrayprop->prop.info= ), + field_prop_setter(arrayprop->prop.info= ), + array_element_release, + arrayprop); + elmop->allow_set =3D op->allow_set; } } =20 @@ -823,9 +822,13 @@ const PropertyInfo prop_info_size =3D { static ObjectProperty *create_link_property(ObjectClass *oc, const char *n= ame, Property *prop) { + /* + * NOTE: object_property_allow_set_link is unconditional, but + * ObjectProperty.allow_set may be set for the property too. + */ return object_class_property_add_link(oc, name, prop->link_type, prop->offset, - qdev_prop_allow_set_link_before_= realize, + object_property_allow_set_link, OBJ_PROP_LINK_STRONG); } =20 @@ -836,10 +839,12 @@ const PropertyInfo prop_info_link =3D { =20 ObjectProperty * object_property_add_field(Object *obj, const char *name, - Property *prop) + Property *prop, + ObjectPropertyAllowSet allow_set) { ObjectProperty *op; =20 + assert(allow_set); assert(!prop->info->create); =20 op =3D object_property_add(obj, name, prop->info->name, @@ -858,15 +863,19 @@ object_property_add_field(Object *obj, const char *na= me, } } =20 + op->allow_set =3D allow_set; return op; } =20 ObjectProperty * object_class_property_add_field_static(ObjectClass *oc, const char *name, - Property *prop) + Property *prop, + ObjectPropertyAllowSet allow_set) { ObjectProperty *op; =20 + assert(allow_set); + if (prop->info->create) { op =3D prop->info->create(oc, name, prop); } else { @@ -884,22 +893,26 @@ object_class_property_add_field_static(ObjectClass *o= c, const char *name, object_class_property_set_description(oc, name, prop->info->description); } + + op->allow_set =3D allow_set; return op; } =20 -void object_class_add_field_properties(ObjectClass *oc, Property *props) +void object_class_add_field_properties(ObjectClass *oc, Property *props, + ObjectPropertyAllowSet allow_set) { Property *prop; =20 for (prop =3D props; prop && prop->name; prop++) { - object_class_property_add_field_static(oc, prop->name, prop); + object_class_property_add_field_static(oc, prop->name, prop, allow= _set); } } =20 =20 void qdev_property_add_static(DeviceState *dev, Property *prop) { - object_property_add_field(OBJECT(dev), prop->name, prop); + object_property_add_field(OBJECT(dev), prop->name, prop, + qdev_prop_allow_set); } =20 /** @@ -958,7 +971,7 @@ void device_class_set_props(DeviceClass *dc, Property *= props) qdev_class_add_legacy_property(dc, prop); } =20 - object_class_add_field_properties(oc, props); + object_class_add_field_properties(oc, props, qdev_prop_allow_set); } =20 void qdev_alias_all_properties(DeviceState *target, Object *source) --=20 2.28.0