From nobody Fri May 3 18:22:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1498723759353169.2375380598836; Thu, 29 Jun 2017 01:09:19 -0700 (PDT) Received: from localhost ([::1]:37536 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQUVo-0007WA-TB for importer@patchew.org; Thu, 29 Jun 2017 04:09:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59236) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQURh-0003px-KP for qemu-devel@nongnu.org; Thu, 29 Jun 2017 04:05:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQURg-0003Fv-L5 for qemu-devel@nongnu.org; Thu, 29 Jun 2017 04:05:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42222) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dQURg-0003FW-CD for qemu-devel@nongnu.org; Thu, 29 Jun 2017 04:05:00 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2369490907; Thu, 29 Jun 2017 08:04:59 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-36.pek2.redhat.com [10.72.12.36]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0419F89C95; Thu, 29 Jun 2017 08:04:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2369490907 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=famz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 2369490907 From: Fam Zheng To: qemu-devel@nongnu.org Date: Thu, 29 Jun 2017 16:04:46 +0800 Message-Id: <20170629080452.26470-2-famz@redhat.com> In-Reply-To: <20170629080452.26470-1-famz@redhat.com> References: <20170629080452.26470-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 29 Jun 2017 08:04:59 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 1/7] qom: Make link property API public X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , "Dr . David Alan Gilbert" , Markus Armbruster , =?UTF-8?q?Andreas=20F=C3=A4rber?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The get/set pair and the struct will be reused by qdev link prop, make them public. Signed-off-by: Fam Zheng --- include/qom/link-property.h | 31 +++++++++++++++++++++++++++++++ qom/object.c | 19 +++++++------------ 2 files changed, 38 insertions(+), 12 deletions(-) create mode 100644 include/qom/link-property.h diff --git a/include/qom/link-property.h b/include/qom/link-property.h new file mode 100644 index 0000000..f3c3816 --- /dev/null +++ b/include/qom/link-property.h @@ -0,0 +1,31 @@ +/* + * QOM link property + * + * Copyright IBM, Corp. 2011 + * + * Authors: + * Anthony Liguori + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + */ + +#ifndef QOM_LINK_PROPERTY_H +#define QOM_LINK_PROPERTY_H + +#include "qom/object.h" + +typedef struct { + Object **child; + void (*check)(Object *, const char *, Object *, Error **); + ObjectPropertyLinkFlags flags; +} LinkProperty; + +void object_get_link_property(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp); +void object_set_link_property(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp); +#endif diff --git a/qom/object.c b/qom/object.c index 5f6fdfa..fdb8f0d 100644 --- a/qom/object.c +++ b/qom/object.c @@ -28,6 +28,7 @@ #include "qapi/qmp/qobject.h" #include "qapi/qmp/qbool.h" #include "qapi/qmp/qstring.h" +#include "qom/link-property.h" =20 #define MAX_INTERFACES 32 =20 @@ -1434,15 +1435,9 @@ void object_property_allow_set_link(Object *obj, con= st char *name, /* Allow the link to be set, always */ } =20 -typedef struct { - Object **child; - void (*check)(Object *, const char *, Object *, Error **); - ObjectPropertyLinkFlags flags; -} LinkProperty; - -static void object_get_link_property(Object *obj, Visitor *v, - const char *name, void *opaque, - Error **errp) +void object_get_link_property(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) { LinkProperty *lprop =3D opaque; Object **child =3D lprop->child; @@ -1498,9 +1493,9 @@ static Object *object_resolve_link(Object *obj, const= char *name, return target; } =20 -static void object_set_link_property(Object *obj, Visitor *v, - const char *name, void *opaque, - Error **errp) +void object_set_link_property(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) { Error *local_err =3D NULL; LinkProperty *prop =3D opaque; --=20 2.9.4 From nobody Fri May 3 18:22:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1498723624378511.3250306721527; Thu, 29 Jun 2017 01:07:04 -0700 (PDT) Received: from localhost ([::1]:37529 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQUTe-00059K-Ua for importer@patchew.org; Thu, 29 Jun 2017 04:07:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59254) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQURk-0003rN-Cd for qemu-devel@nongnu.org; Thu, 29 Jun 2017 04:05:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQURj-0003H8-HY for qemu-devel@nongnu.org; Thu, 29 Jun 2017 04:05:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46456) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dQURj-0003Gu-CH for qemu-devel@nongnu.org; Thu, 29 Jun 2017 04:05:03 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0A11D8BD27; Thu, 29 Jun 2017 08:05:02 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-36.pek2.redhat.com [10.72.12.36]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8E82C89C95; Thu, 29 Jun 2017 08:04:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0A11D8BD27 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=famz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 0A11D8BD27 From: Fam Zheng To: qemu-devel@nongnu.org Date: Thu, 29 Jun 2017 16:04:47 +0800 Message-Id: <20170629080452.26470-3-famz@redhat.com> In-Reply-To: <20170629080452.26470-1-famz@redhat.com> References: <20170629080452.26470-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 29 Jun 2017 08:05:02 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 2/7] qom: Handle property lookup failure in object_resolve_link X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , "Dr . David Alan Gilbert" , Markus Armbruster , =?UTF-8?q?Andreas=20F=C3=A4rber?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Since we have made object_set_link_property a public function, it is possible that it will be called with a nonexistent property name. Let's survive this error case and report error to avoid segfault in the future. Signed-off-by: Fam Zheng --- qom/object.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/qom/object.c b/qom/object.c index fdb8f0d..7ce97d9 100644 --- a/qom/object.c +++ b/qom/object.c @@ -1471,7 +1471,10 @@ static Object *object_resolve_link(Object *obj, cons= t char *name, Object *target; =20 /* Go from link to FOO. */ - type =3D object_property_get_type(obj, name, NULL); + type =3D object_property_get_type(obj, name, errp); + if (!type) { + return NULL; + } target_type =3D g_strndup(&type[5], strlen(type) - 6); target =3D object_resolve_path_type(path, target_type, &ambiguous); =20 --=20 2.9.4 From nobody Fri May 3 18:22:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1498723667055809.9343806105892; Thu, 29 Jun 2017 01:07:47 -0700 (PDT) Received: from localhost ([::1]:37531 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQUUL-0005iY-MI for importer@patchew.org; Thu, 29 Jun 2017 04:07:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59285) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQURs-00042z-Av for qemu-devel@nongnu.org; Thu, 29 Jun 2017 04:05:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQURp-0003NR-0s for qemu-devel@nongnu.org; Thu, 29 Jun 2017 04:05:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58142) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dQURo-0003Mg-OI for qemu-devel@nongnu.org; Thu, 29 Jun 2017 04:05:08 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ACCDA8535D; Thu, 29 Jun 2017 08:05:07 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-36.pek2.redhat.com [10.72.12.36]) by smtp.corp.redhat.com (Postfix) with ESMTP id 658F59522E; Thu, 29 Jun 2017 08:05:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com ACCDA8535D Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=famz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com ACCDA8535D From: Fam Zheng To: qemu-devel@nongnu.org Date: Thu, 29 Jun 2017 16:04:48 +0800 Message-Id: <20170629080452.26470-4-famz@redhat.com> In-Reply-To: <20170629080452.26470-1-famz@redhat.com> References: <20170629080452.26470-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 29 Jun 2017 08:05:07 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 3/7] qdev: Introduce PropertyInfo.create X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , "Dr . David Alan Gilbert" , Markus Armbruster , =?UTF-8?q?Andreas=20F=C3=A4rber?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This allows property implementation to provide a specialized property creation method. Update conditions guarding property types accordingly. Signed-off-by: Fam Zheng --- hw/core/qdev.c | 31 +++++++++++++++++++------------ include/hw/qdev-core.h | 1 + 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 849952a..ec63fe0 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -744,6 +744,10 @@ static void qdev_property_add_legacy(DeviceState *dev,= Property *prop, return; } =20 + if (prop->info->create) { + return; + } + name =3D g_strdup_printf("legacy-%s", prop->name); object_property_add(OBJECT(dev), name, "str", prop->info->print ? qdev_get_legacy_property : pro= p->info->get, @@ -770,20 +774,23 @@ void qdev_property_add_static(DeviceState *dev, Prope= rty *prop, Error *local_err =3D NULL; Object *obj =3D OBJECT(dev); =20 - /* - * TODO qdev_prop_ptr does not have getters or setters. It must - * go now that it can be replaced with links. The test should be - * removed along with it: all static properties are read/write. - */ - if (!prop->info->get && !prop->info->set) { - return; + if (prop->info->create) { + prop->info->create(obj, prop, &local_err); + } else { + /* + * TODO qdev_prop_ptr does not have getters or setters. It must + * go now that it can be replaced with links. The test should be + * removed along with it: all static properties are read/write. + */ + if (!prop->info->get && !prop->info->set) { + return; + } + object_property_add(obj, prop->name, prop->info->name, + prop->info->get, prop->info->set, + prop->info->release, + prop, &local_err); } =20 - object_property_add(obj, prop->name, prop->info->name, - prop->info->get, prop->info->set, - prop->info->release, - prop, &local_err); - if (local_err) { error_propagate(errp, local_err); return; diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 9d7c1c0..33518ee 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -241,6 +241,7 @@ struct PropertyInfo { const char * const *enum_table; int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len); void (*set_default_value)(Object *obj, const Property *prop); + void (*create)(Object *obj, Property *prop, Error **errp); ObjectPropertyAccessor *get; ObjectPropertyAccessor *set; ObjectPropertyRelease *release; --=20 2.9.4 From nobody Fri May 3 18:22:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1498723785009811.9524493772705; Thu, 29 Jun 2017 01:09:45 -0700 (PDT) Received: from localhost ([::1]:37538 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQUWE-0007t5-FY for importer@patchew.org; Thu, 29 Jun 2017 04:09:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59359) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQUS1-00048M-Gk for qemu-devel@nongnu.org; Thu, 29 Jun 2017 04:05:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQURr-0003PJ-R0 for qemu-devel@nongnu.org; Thu, 29 Jun 2017 04:05:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36882) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dQURr-0003Or-Ih for qemu-devel@nongnu.org; Thu, 29 Jun 2017 04:05:11 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A6C7D3D970; Thu, 29 Jun 2017 08:05:10 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-36.pek2.redhat.com [10.72.12.36]) by smtp.corp.redhat.com (Postfix) with ESMTP id 43A3C89C95; Thu, 29 Jun 2017 08:05:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A6C7D3D970 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=famz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A6C7D3D970 From: Fam Zheng To: qemu-devel@nongnu.org Date: Thu, 29 Jun 2017 16:04:49 +0800 Message-Id: <20170629080452.26470-5-famz@redhat.com> In-Reply-To: <20170629080452.26470-1-famz@redhat.com> References: <20170629080452.26470-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 29 Jun 2017 08:05:10 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 4/7] qdev: Introduce DEFINE_PROP_LINK X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , "Dr . David Alan Gilbert" , Markus Armbruster , =?UTF-8?q?Andreas=20F=C3=A4rber?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This property can be used to replace the object_property_add_link in device code, to add a link to other objects, which is a common pattern. Signed-off-by: Fam Zheng --- hw/core/qdev-properties.c | 16 ++++++++++++++++ include/hw/qdev-core.h | 5 +++++ include/hw/qdev-properties.h | 11 +++++++++++ 3 files changed, 32 insertions(+) diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index 68cd653..7c11eb8 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -1192,3 +1192,19 @@ PropertyInfo qdev_prop_size =3D { .set =3D set_size, .set_default_value =3D set_default_value_uint, }; + +/* --- object link property --- */ + +static void create_link_property(Object *obj, Property *prop, Error **errp) +{ + Object **child =3D qdev_get_prop_ptr(DEVICE(obj), prop); + + object_property_add_link(obj, prop->name, prop->link_type, + child, prop->link.check, + prop->link.flags, errp); +} + +PropertyInfo qdev_prop_link =3D { + .name =3D "link", + .create =3D create_link_property, +}; diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 33518ee..40afb3d 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -5,6 +5,7 @@ #include "qemu/option.h" #include "qemu/bitmap.h" #include "qom/object.h" +#include "qom/link-property.h" #include "hw/irq.h" #include "hw/hotplug.h" =20 @@ -233,6 +234,10 @@ struct Property { int arrayoffset; PropertyInfo *arrayinfo; int arrayfieldsize; + /* Only @check and @flags are used; @child is unuseful because we need= a + * dynamic pointer in @obj as derived from @offset. */ + LinkProperty link; + const char *link_type; }; =20 struct PropertyInfo { diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h index 39bf4b2..767c10b 100644 --- a/include/hw/qdev-properties.h +++ b/include/hw/qdev-properties.h @@ -30,6 +30,7 @@ extern PropertyInfo qdev_prop_pci_devfn; extern PropertyInfo qdev_prop_blocksize; extern PropertyInfo qdev_prop_pci_host_devaddr; extern PropertyInfo qdev_prop_arraylen; +extern PropertyInfo qdev_prop_link; =20 #define DEFINE_PROP(_name, _state, _field, _prop, _type) { \ .name =3D (_name), \ @@ -117,6 +118,16 @@ extern PropertyInfo qdev_prop_arraylen; .arrayoffset =3D offsetof(_state, _arrayfield), \ } =20 +#define DEFINE_PROP_LINK(_name, _state, _field, _type, _check, _flags) {\ + .name =3D (_name), \ + .info =3D &(qdev_prop_link), \ + .offset =3D offsetof(_state, _field) \ + + type_check(Object *, typeof_field(_state, _field)), \ + .link.check =3D _check, \ + .link.flags =3D _flags, \ + .link_type =3D _type, \ + } + #define DEFINE_PROP_UINT8(_n, _s, _f, _d) \ DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint8, uint8_t) #define DEFINE_PROP_UINT16(_n, _s, _f, _d) \ --=20 2.9.4 From nobody Fri May 3 18:22:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1498723814554480.80230259746077; Thu, 29 Jun 2017 01:10:14 -0700 (PDT) Received: from localhost ([::1]:37539 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQUWj-0008KC-8y for importer@patchew.org; Thu, 29 Jun 2017 04:10:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59311) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQURw-00043s-2h for qemu-devel@nongnu.org; Thu, 29 Jun 2017 04:05:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQURu-0003QX-GW for qemu-devel@nongnu.org; Thu, 29 Jun 2017 04:05:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58342) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dQURu-0003QD-7w for qemu-devel@nongnu.org; Thu, 29 Jun 2017 04:05:14 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3DB8080E7C; Thu, 29 Jun 2017 08:05:13 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-36.pek2.redhat.com [10.72.12.36]) by smtp.corp.redhat.com (Postfix) with ESMTP id 402E789C94; Thu, 29 Jun 2017 08:05:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3DB8080E7C Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=famz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 3DB8080E7C From: Fam Zheng To: qemu-devel@nongnu.org Date: Thu, 29 Jun 2017 16:04:50 +0800 Message-Id: <20170629080452.26470-6-famz@redhat.com> In-Reply-To: <20170629080452.26470-1-famz@redhat.com> References: <20170629080452.26470-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 29 Jun 2017 08:05:13 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 5/7] virtio-blk: Use DEFINE_PROP_LINK X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , "Dr . David Alan Gilbert" , Markus Armbruster , =?UTF-8?q?Andreas=20F=C3=A4rber?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Fam Zheng --- hw/block/dataplane/virtio-blk.c | 2 +- hw/block/virtio-blk.c | 7 +++---- hw/virtio/virtio-pci.c | 2 -- include/hw/virtio/virtio-blk.h | 2 +- 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-bl= k.c index 5556f0e..6fdc6f6 100644 --- a/hw/block/dataplane/virtio-blk.c +++ b/hw/block/dataplane/virtio-blk.c @@ -116,7 +116,7 @@ void virtio_blk_data_plane_create(VirtIODevice *vdev, V= irtIOBlkConf *conf, s->conf =3D conf; =20 if (conf->iothread) { - s->iothread =3D conf->iothread; + s->iothread =3D IOTHREAD(conf->iothread); object_ref(OBJECT(s->iothread)); s->ctx =3D iothread_get_aio_context(s->iothread); } else { diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 604d37d..aa2c38c 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -981,10 +981,6 @@ static void virtio_blk_instance_init(Object *obj) { VirtIOBlock *s =3D VIRTIO_BLK(obj); =20 - object_property_add_link(obj, "iothread", TYPE_IOTHREAD, - (Object **)&s->conf.iothread, - qdev_prop_allow_set_link_before_realize, - OBJ_PROP_LINK_UNREF_ON_RELEASE, NULL); device_add_bootindex_property(obj, &s->conf.conf.bootindex, "bootindex", "/disk@0,0", DEVICE(obj), NULL); @@ -1012,6 +1008,9 @@ static Property virtio_blk_properties[] =3D { DEFINE_PROP_BIT("request-merging", VirtIOBlock, conf.request_merging, = 0, true), DEFINE_PROP_UINT16("num-queues", VirtIOBlock, conf.num_queues, 1), + DEFINE_PROP_LINK("iothread", VirtIOBlock, conf.iothread, TYPE_IOTHREAD, + qdev_prop_allow_set_link_before_realize, + OBJ_PROP_LINK_UNREF_ON_RELEASE), DEFINE_PROP_END_OF_LIST(), }; =20 diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 20d6a08..e6960ae 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -1996,8 +1996,6 @@ static void virtio_blk_pci_instance_init(Object *obj) =20 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_BLK); - object_property_add_alias(obj, "iothread", OBJECT(&dev->vdev),"iothrea= d", - &error_abort); object_property_add_alias(obj, "bootindex", OBJECT(&dev->vdev), "bootindex", &error_abort); } diff --git a/include/hw/virtio/virtio-blk.h b/include/hw/virtio/virtio-blk.h index d3c8a6f..94a9f0c 100644 --- a/include/hw/virtio/virtio-blk.h +++ b/include/hw/virtio/virtio-blk.h @@ -33,7 +33,7 @@ struct virtio_blk_inhdr struct VirtIOBlkConf { BlockConf conf; - IOThread *iothread; + Object *iothread; char *serial; uint32_t scsi; uint32_t config_wce; --=20 2.9.4 From nobody Fri May 3 18:22:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1498723631391779.8179133538589; Thu, 29 Jun 2017 01:07:11 -0700 (PDT) Received: from localhost ([::1]:37530 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQUTl-0005Dk-26 for importer@patchew.org; Thu, 29 Jun 2017 04:07:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59335) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQURy-00044n-2C for qemu-devel@nongnu.org; Thu, 29 Jun 2017 04:05:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQURw-0003RV-M1 for qemu-devel@nongnu.org; Thu, 29 Jun 2017 04:05:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60280) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dQURw-0003R9-E7 for qemu-devel@nongnu.org; Thu, 29 Jun 2017 04:05:16 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 806D57D0CA; Thu, 29 Jun 2017 08:05:15 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-36.pek2.redhat.com [10.72.12.36]) by smtp.corp.redhat.com (Postfix) with ESMTP id B168D89C98; Thu, 29 Jun 2017 08:05:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 806D57D0CA Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=famz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 806D57D0CA From: Fam Zheng To: qemu-devel@nongnu.org Date: Thu, 29 Jun 2017 16:04:51 +0800 Message-Id: <20170629080452.26470-7-famz@redhat.com> In-Reply-To: <20170629080452.26470-1-famz@redhat.com> References: <20170629080452.26470-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 29 Jun 2017 08:05:15 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 6/7] virtio-scsi: Use DEFINE_PROP_LINK X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , "Dr . David Alan Gilbert" , Markus Armbruster , =?UTF-8?q?Andreas=20F=C3=A4rber?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Fam Zheng --- hw/scsi/virtio-scsi-dataplane.c | 2 +- hw/scsi/virtio-scsi.c | 15 ++++----------- hw/virtio/virtio-pci.c | 2 -- include/hw/virtio/virtio-scsi.h | 2 +- 4 files changed, 6 insertions(+), 15 deletions(-) diff --git a/hw/scsi/virtio-scsi-dataplane.c b/hw/scsi/virtio-scsi-dataplan= e.c index 944ea4e..887c100 100644 --- a/hw/scsi/virtio-scsi-dataplane.c +++ b/hw/scsi/virtio-scsi-dataplane.c @@ -40,7 +40,7 @@ void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **e= rrp) error_setg(errp, "ioeventfd is required for iothread"); return; } - s->ctx =3D iothread_get_aio_context(vs->conf.iothread); + s->ctx =3D iothread_get_aio_context(IOTHREAD(vs->conf.iothread)); } else { if (!virtio_device_ioeventfd_enabled(vdev)) { return; diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c index f46f06d..afe4389 100644 --- a/hw/scsi/virtio-scsi.c +++ b/hw/scsi/virtio-scsi.c @@ -897,16 +897,6 @@ static void virtio_scsi_device_realize(DeviceState *de= v, Error **errp) virtio_scsi_dataplane_setup(s, errp); } =20 -static void virtio_scsi_instance_init(Object *obj) -{ - VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(obj); - - object_property_add_link(obj, "iothread", TYPE_IOTHREAD, - (Object **)&vs->conf.iothread, - qdev_prop_allow_set_link_before_realize, - OBJ_PROP_LINK_UNREF_ON_RELEASE, &error_abort); -} - void virtio_scsi_common_unrealize(DeviceState *dev, Error **errp) { VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); @@ -934,6 +924,10 @@ static Property virtio_scsi_properties[] =3D { VIRTIO_SCSI_F_HOTPLUG, true), DEFINE_PROP_BIT("param_change", VirtIOSCSI, host_features, VIRTIO_SCSI_F_CHANGE, true= ), + DEFINE_PROP_LINK("iothread", VirtIOSCSI, parent_obj.conf.iothread, + TYPE_IOTHREAD, + qdev_prop_allow_set_link_before_realize, + OBJ_PROP_LINK_UNREF_ON_RELEASE), DEFINE_PROP_END_OF_LIST(), }; =20 @@ -988,7 +982,6 @@ static const TypeInfo virtio_scsi_info =3D { .name =3D TYPE_VIRTIO_SCSI, .parent =3D TYPE_VIRTIO_SCSI_COMMON, .instance_size =3D sizeof(VirtIOSCSI), - .instance_init =3D virtio_scsi_instance_init, .class_init =3D virtio_scsi_class_init, .interfaces =3D (InterfaceInfo[]) { { TYPE_HOTPLUG_HANDLER }, diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index e6960ae..eb03ba5 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -2065,8 +2065,6 @@ static void virtio_scsi_pci_instance_init(Object *obj) =20 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_SCSI); - object_property_add_alias(obj, "iothread", OBJECT(&dev->vdev), "iothre= ad", - &error_abort); } =20 static const TypeInfo virtio_scsi_pci_info =3D { diff --git a/include/hw/virtio/virtio-scsi.h b/include/hw/virtio/virtio-scs= i.h index de6ae5a..1decc40 100644 --- a/include/hw/virtio/virtio-scsi.h +++ b/include/hw/virtio/virtio-scsi.h @@ -56,7 +56,7 @@ struct VirtIOSCSIConf { #endif CharBackend chardev; uint32_t boot_tpgt; - IOThread *iothread; + Object *iothread; }; =20 struct VirtIOSCSI; --=20 2.9.4 From nobody Fri May 3 18:22:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1498723905408728.1399178499664; Thu, 29 Jun 2017 01:11:45 -0700 (PDT) Received: from localhost ([::1]:37548 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQUYB-00011j-Sc for importer@patchew.org; Thu, 29 Jun 2017 04:11:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59368) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQUS4-0004BG-Kl for qemu-devel@nongnu.org; Thu, 29 Jun 2017 04:05:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQURz-0003Sl-QQ for qemu-devel@nongnu.org; Thu, 29 Jun 2017 04:05:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37996) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dQURz-0003SL-HU for qemu-devel@nongnu.org; Thu, 29 Jun 2017 04:05:19 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 86C73C04B32C; Thu, 29 Jun 2017 08:05:18 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-36.pek2.redhat.com [10.72.12.36]) by smtp.corp.redhat.com (Postfix) with ESMTP id 095CC89C98; Thu, 29 Jun 2017 08:05:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 86C73C04B32C Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=famz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 86C73C04B32C From: Fam Zheng To: qemu-devel@nongnu.org Date: Thu, 29 Jun 2017 16:04:52 +0800 Message-Id: <20170629080452.26470-8-famz@redhat.com> In-Reply-To: <20170629080452.26470-1-famz@redhat.com> References: <20170629080452.26470-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 29 Jun 2017 08:05:18 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 7/7] virtio-rng: Use DEFINE_PROP_LINK X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , "Dr . David Alan Gilbert" , Markus Armbruster , =?UTF-8?q?Andreas=20F=C3=A4rber?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Fam Zheng --- hw/virtio/virtio-pci.c | 2 -- hw/virtio/virtio-rng.c | 16 ++++------------ include/hw/virtio/virtio-rng.h | 2 +- 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index eb03ba5..0938db4 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -2459,8 +2459,6 @@ static void virtio_rng_initfn(Object *obj) =20 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_RNG); - object_property_add_alias(obj, "rng", OBJECT(&dev->vdev), "rng", - &error_abort); } =20 static const TypeInfo virtio_rng_pci_info =3D { diff --git a/hw/virtio/virtio-rng.c b/hw/virtio/virtio-rng.c index a6ee501..218778b 100644 --- a/hw/virtio/virtio-rng.c +++ b/hw/virtio/virtio-rng.c @@ -199,7 +199,7 @@ static void virtio_rng_device_realize(DeviceState *dev,= Error **errp) "rng", NULL); } =20 - vrng->rng =3D vrng->conf.rng; + vrng->rng =3D RNG_BACKEND(vrng->conf.rng); if (vrng->rng =3D=3D NULL) { error_setg(errp, "'rng' parameter expects a valid object"); return; @@ -246,6 +246,9 @@ static Property virtio_rng_properties[] =3D { */ DEFINE_PROP_UINT64("max-bytes", VirtIORNG, conf.max_bytes, INT64_MAX), DEFINE_PROP_UINT32("period", VirtIORNG, conf.period_ms, 1 << 16), + DEFINE_PROP_LINK("rng", VirtIORNG, conf.rng, TYPE_RNG_BACKEND, + qdev_prop_allow_set_link_before_realize, + OBJ_PROP_LINK_UNREF_ON_RELEASE), DEFINE_PROP_END_OF_LIST(), }; =20 @@ -262,21 +265,10 @@ static void virtio_rng_class_init(ObjectClass *klass,= void *data) vdc->get_features =3D get_features; } =20 -static void virtio_rng_initfn(Object *obj) -{ - VirtIORNG *vrng =3D VIRTIO_RNG(obj); - - object_property_add_link(obj, "rng", TYPE_RNG_BACKEND, - (Object **)&vrng->conf.rng, - qdev_prop_allow_set_link_before_realize, - OBJ_PROP_LINK_UNREF_ON_RELEASE, NULL); -} - static const TypeInfo virtio_rng_info =3D { .name =3D TYPE_VIRTIO_RNG, .parent =3D TYPE_VIRTIO_DEVICE, .instance_size =3D sizeof(VirtIORNG), - .instance_init =3D virtio_rng_initfn, .class_init =3D virtio_rng_class_init, }; =20 diff --git a/include/hw/virtio/virtio-rng.h b/include/hw/virtio/virtio-rng.h index 922dce7..8d45597 100644 --- a/include/hw/virtio/virtio-rng.h +++ b/include/hw/virtio/virtio-rng.h @@ -23,7 +23,7 @@ OBJECT_GET_PARENT_CLASS(obj, TYPE_VIRTIO_RNG) =20 struct VirtIORNGConf { - RngBackend *rng; + Object *rng; uint64_t max_bytes; uint32_t period_ms; RngRandom *default_backend; --=20 2.9.4