From nobody Mon Feb 9 07:43:21 2026 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 149865423808217.052847333185696; Wed, 28 Jun 2017 05:50:38 -0700 (PDT) Received: from localhost ([::1]:33189 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQCQW-0003uZ-G9 for importer@patchew.org; Wed, 28 Jun 2017 08:50:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47129) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQCP3-0002rO-9T for qemu-devel@nongnu.org; Wed, 28 Jun 2017 08:49:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQCP2-00017m-Hv for qemu-devel@nongnu.org; Wed, 28 Jun 2017 08:49:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50143) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dQCP2-00017V-C8 for qemu-devel@nongnu.org; Wed, 28 Jun 2017 08:49:04 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F0E1F7A162; Wed, 28 Jun 2017 12:49:02 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-85.pek2.redhat.com [10.72.12.85]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8EB4E89E5A; Wed, 28 Jun 2017 12:48:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com F0E1F7A162 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 F0E1F7A162 From: Fam Zheng To: qemu-devel@nongnu.org Date: Wed, 28 Jun 2017 20:48:44 +0800 Message-Id: <20170628124850.12821-2-famz@redhat.com> In-Reply-To: <20170628124850.12821-1-famz@redhat.com> References: <20170628124850.12821-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 28 Jun 2017 12:49:03 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 1/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 , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Markus Armbruster , "Dr . David Alan Gilbert" 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/object.h | 13 +++++++++++++ qom/object.c | 18 ++++++------------ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/include/qom/object.h b/include/qom/object.h index abaeb8c..4659e6a 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -1613,4 +1613,17 @@ Object *container_get(Object *root, const char *path= ); * Returns the instance_size of the given @typename. */ size_t object_type_get_instance_size(const char *typename); + +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..3868370 100644 --- a/qom/object.c +++ b/qom/object.c @@ -1434,15 +1434,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 +1492,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 Mon Feb 9 07:43:21 2026 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 1498654323039856.6861484563485; Wed, 28 Jun 2017 05:52:03 -0700 (PDT) Received: from localhost ([::1]:33200 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQCRs-0004zF-O2 for importer@patchew.org; Wed, 28 Jun 2017 08:52:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47159) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQCPC-00034J-6o for qemu-devel@nongnu.org; Wed, 28 Jun 2017 08:49:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQCP9-00019P-5S for qemu-devel@nongnu.org; Wed, 28 Jun 2017 08:49:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47818) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dQCP8-000199-VC for qemu-devel@nongnu.org; Wed, 28 Jun 2017 08:49:11 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E4B3064D3; Wed, 28 Jun 2017 12:49:09 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-85.pek2.redhat.com [10.72.12.85]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8D36089E62; Wed, 28 Jun 2017 12:49:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E4B3064D3 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=famz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com E4B3064D3 From: Fam Zheng To: qemu-devel@nongnu.org Date: Wed, 28 Jun 2017 20:48:45 +0800 Message-Id: <20170628124850.12821-3-famz@redhat.com> In-Reply-To: <20170628124850.12821-1-famz@redhat.com> References: <20170628124850.12821-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 28 Jun 2017 12:49: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 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 , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Markus Armbruster , "Dr . David Alan Gilbert" 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 3868370..dd9c3fa 100644 --- a/qom/object.c +++ b/qom/object.c @@ -1470,7 +1470,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 Mon Feb 9 07:43:21 2026 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 149865453289390.52117304455464; Wed, 28 Jun 2017 05:55:32 -0700 (PDT) Received: from localhost ([::1]:33219 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQCVH-0008WM-Gi for importer@patchew.org; Wed, 28 Jun 2017 08:55:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47190) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQCPG-00035g-2T for qemu-devel@nongnu.org; Wed, 28 Jun 2017 08:49:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQCPF-0001CC-Bw for qemu-devel@nongnu.org; Wed, 28 Jun 2017 08:49:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38062) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dQCPF-0001Bh-5x for qemu-devel@nongnu.org; Wed, 28 Jun 2017 08:49:17 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 11CBA7F3F1; Wed, 28 Jun 2017 12:49:16 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-85.pek2.redhat.com [10.72.12.85]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2CE148AC2C; Wed, 28 Jun 2017 12:49:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 11CBA7F3F1 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 11CBA7F3F1 From: Fam Zheng To: qemu-devel@nongnu.org Date: Wed, 28 Jun 2017 20:48:46 +0800 Message-Id: <20170628124850.12821-4-famz@redhat.com> In-Reply-To: <20170628124850.12821-1-famz@redhat.com> References: <20170628124850.12821-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 28 Jun 2017 12:49:16 +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 3/7] qom: Save type name in LinkProperty 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 , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Markus Armbruster , "Dr . David Alan Gilbert" 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 --- include/qom/object.h | 1 + qom/object.c | 1 + 2 files changed, 2 insertions(+) diff --git a/include/qom/object.h b/include/qom/object.h index 4659e6a..262cd44 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -1618,6 +1618,7 @@ typedef struct { Object **child; void (*check)(Object *, const char *, Object *, Error **); ObjectPropertyLinkFlags flags; + const char *type; } LinkProperty; =20 void object_get_link_property(Object *obj, Visitor *v, diff --git a/qom/object.c b/qom/object.c index dd9c3fa..b3073a6 100644 --- a/qom/object.c +++ b/qom/object.c @@ -1562,6 +1562,7 @@ void object_property_add_link(Object *obj, const char= *name, prop->child =3D child; prop->check =3D check; prop->flags =3D flags; + prop->type =3D type; =20 full_type =3D g_strdup_printf("link<%s>", type); =20 --=20 2.9.4 From nobody Mon Feb 9 07:43:21 2026 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 1498654472293932.5118033836447; Wed, 28 Jun 2017 05:54:32 -0700 (PDT) Received: from localhost ([::1]:33209 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQCUI-0007EU-1O for importer@patchew.org; Wed, 28 Jun 2017 08:54:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47229) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQCPO-0003B7-0x for qemu-devel@nongnu.org; Wed, 28 Jun 2017 08:49:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQCPK-0001Ei-VS for qemu-devel@nongnu.org; Wed, 28 Jun 2017 08:49:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60484) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dQCPK-0001EP-Mh for qemu-devel@nongnu.org; Wed, 28 Jun 2017 08:49:22 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A6EF8C0467C5; Wed, 28 Jun 2017 12:49:21 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-85.pek2.redhat.com [10.72.12.85]) by smtp.corp.redhat.com (Postfix) with ESMTP id B9BC089A9B; Wed, 28 Jun 2017 12:49:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A6EF8C0467C5 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 A6EF8C0467C5 From: Fam Zheng To: qemu-devel@nongnu.org Date: Wed, 28 Jun 2017 20:48:47 +0800 Message-Id: <20170628124850.12821-5-famz@redhat.com> In-Reply-To: <20170628124850.12821-1-famz@redhat.com> References: <20170628124850.12821-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 28 Jun 2017 12:49:21 +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 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 , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Markus Armbruster , "Dr . David Alan Gilbert" 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. It's implemented by creating a wrapper property that basically forwards operations to a QOM "link-FOO" property, which handles the check callback and flags. The feature that is missing from QOM is the dynamic child pointer which is done in the added code with the usual "offset" approach. Signed-off-by: Fam Zheng --- hw/core/qdev-properties.c | 81 ++++++++++++++++++++++++++++++++++++++++= ++++ include/hw/qdev-core.h | 3 ++ include/hw/qdev-properties.h | 11 ++++++ 3 files changed, 95 insertions(+) diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index 68cd653..3801379 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -1192,3 +1192,84 @@ PropertyInfo qdev_prop_size =3D { .set =3D set_size, .set_default_value =3D set_default_value_uint, }; + +/* --- object link property --- */ + +static ObjectProperty *link_property_get_or_create(Object *obj, Property *= prop, + Error **errp) +{ + Error *local_err =3D NULL; + Object **child =3D qdev_get_prop_ptr(DEVICE(obj), prop); + char *link_prop_name =3D g_strdup_printf("link-%s", prop->name); + ObjectProperty *op =3D object_property_find(obj, link_prop_name, NULL); + + if (op) { + goto out; + } + object_property_add_link(obj, link_prop_name, prop->link.type, + child, prop->link.check, + prop->link.flags, &local_err); + + if (local_err) { + error_propagate(errp, local_err); + goto out; + } + op =3D object_property_find(obj, link_prop_name, errp); +out: + g_free(link_prop_name); + return op; +} + +static void get_link_property(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + Property *prop =3D opaque; + ObjectProperty *op =3D link_property_get_or_create(obj, prop, NULL); + char *link_prop_name; + + if (!op) { + return; + } + link_prop_name =3D g_strdup_printf("link-%s", name); + object_get_link_property(obj, v, link_prop_name, op->opaque, errp); + g_free(link_prop_name); +} + +static void set_link_property(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + Object *target; + Property *prop =3D opaque; + Object **link_ptr =3D qdev_get_prop_ptr(DEVICE(obj), prop); + ObjectProperty *op =3D link_property_get_or_create(obj, prop, errp); + char *link_prop_name; + Error *local_err =3D NULL; + + if (!op) { + return; + } + + link_prop_name =3D g_strdup_printf("link-%s", name); + object_set_link_property(obj, v, link_prop_name, op->opaque, &local_er= r); + if (local_err) { + error_propagate(errp, local_err); + goto out; + } + target =3D object_property_get_link(obj, link_prop_name, &local_err); + if (local_err) { + error_propagate(errp, local_err); + goto out; + } + *link_ptr =3D target; + +out: + g_free(link_prop_name); +} + +PropertyInfo qdev_prop_link =3D { + .name =3D "link", + .get =3D get_link_property, + .set =3D set_link_property, +}; diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 9d7c1c0..a520226 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -233,6 +233,9 @@ 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; }; =20 struct PropertyInfo { diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h index 39bf4b2..c9ccc9e 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 Mon Feb 9 07:43:21 2026 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 14986547156241007.3425307666485; Wed, 28 Jun 2017 05:58:35 -0700 (PDT) Received: from localhost ([::1]:33231 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQCYE-0002ki-1a for importer@patchew.org; Wed, 28 Jun 2017 08:58:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47255) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQCPR-0003FS-M2 for qemu-devel@nongnu.org; Wed, 28 Jun 2017 08:49:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQCPN-0001Fw-Qo for qemu-devel@nongnu.org; Wed, 28 Jun 2017 08:49:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:6634) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dQCPN-0001FY-IM for qemu-devel@nongnu.org; Wed, 28 Jun 2017 08:49:25 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7D0D843A2B; Wed, 28 Jun 2017 12:49:24 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-85.pek2.redhat.com [10.72.12.85]) by smtp.corp.redhat.com (Postfix) with ESMTP id 46B178AC2C; Wed, 28 Jun 2017 12:49:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7D0D843A2B 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 7D0D843A2B From: Fam Zheng To: qemu-devel@nongnu.org Date: Wed, 28 Jun 2017 20:48:48 +0800 Message-Id: <20170628124850.12821-6-famz@redhat.com> In-Reply-To: <20170628124850.12821-1-famz@redhat.com> References: <20170628124850.12821-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 28 Jun 2017 12:49:24 +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 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 , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Markus Armbruster , "Dr . David Alan Gilbert" 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 Mon Feb 9 07:43:21 2026 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 1498654616270446.5862356416916; Wed, 28 Jun 2017 05:56:56 -0700 (PDT) Received: from localhost ([::1]:33224 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQCWd-0001QN-54 for importer@patchew.org; Wed, 28 Jun 2017 08:56:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47261) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQCPS-0003Fy-5F for qemu-devel@nongnu.org; Wed, 28 Jun 2017 08:49:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQCPR-0001IY-Aj for qemu-devel@nongnu.org; Wed, 28 Jun 2017 08:49:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44474) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dQCPR-0001IA-1c for qemu-devel@nongnu.org; Wed, 28 Jun 2017 08:49:29 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0AA436540; Wed, 28 Jun 2017 12:49:28 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-85.pek2.redhat.com [10.72.12.85]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0620C89E5C; Wed, 28 Jun 2017 12:49:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0AA436540 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=famz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 0AA436540 From: Fam Zheng To: qemu-devel@nongnu.org Date: Wed, 28 Jun 2017 20:48:49 +0800 Message-Id: <20170628124850.12821-7-famz@redhat.com> In-Reply-To: <20170628124850.12821-1-famz@redhat.com> References: <20170628124850.12821-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 28 Jun 2017 12:49:28 +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 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 , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Markus Armbruster , "Dr . David Alan Gilbert" 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 Mon Feb 9 07:43:21 2026 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 1498654842522919.8467907043503; Wed, 28 Jun 2017 06:00:42 -0700 (PDT) Received: from localhost ([::1]:33247 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQCaH-00055r-5N for importer@patchew.org; Wed, 28 Jun 2017 09:00:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47287) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQCPX-0003L1-Op for qemu-devel@nongnu.org; Wed, 28 Jun 2017 08:49:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQCPU-0001K9-MK for qemu-devel@nongnu.org; Wed, 28 Jun 2017 08:49:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57528) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dQCPU-0001Jq-DJ for qemu-devel@nongnu.org; Wed, 28 Jun 2017 08:49:32 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4AB9E8553E; Wed, 28 Jun 2017 12:49:31 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-85.pek2.redhat.com [10.72.12.85]) by smtp.corp.redhat.com (Postfix) with ESMTP id AE17589A9B; Wed, 28 Jun 2017 12:49:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4AB9E8553E 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 4AB9E8553E From: Fam Zheng To: qemu-devel@nongnu.org Date: Wed, 28 Jun 2017 20:48:50 +0800 Message-Id: <20170628124850.12821-8-famz@redhat.com> In-Reply-To: <20170628124850.12821-1-famz@redhat.com> References: <20170628124850.12821-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 28 Jun 2017 12:49:31 +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 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 , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Markus Armbruster , "Dr . David Alan Gilbert" 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