From nobody Mon Feb 9 15:11:09 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 14991511332161019.0132398877248; Mon, 3 Jul 2017 23:52:13 -0700 (PDT) Received: from localhost ([::1]:38913 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dSHgy-0002u1-31 for importer@patchew.org; Tue, 04 Jul 2017 02:52:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41582) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dSHZ2-0003qQ-1K for qemu-devel@nongnu.org; Tue, 04 Jul 2017 02:44:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dSHZ1-0002wl-5T for qemu-devel@nongnu.org; Tue, 04 Jul 2017 02:43:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49546) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dSHZ0-0002w4-Rs for qemu-devel@nongnu.org; Tue, 04 Jul 2017 02:43:59 -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 C83CEC0587FA for ; Tue, 4 Jul 2017 06:43:57 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-33.pek2.redhat.com [10.72.12.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3D11363F69; Tue, 4 Jul 2017 06:43:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C83CEC0587FA Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=famz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com C83CEC0587FA From: Fam Zheng To: qemu-devel@nongnu.org Date: Tue, 4 Jul 2017 14:43:30 +0800 Message-Id: <20170704064347.7022-4-famz@redhat.com> In-Reply-To: <20170704064347.7022-1-famz@redhat.com> References: <20170704064347.7022-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.32]); Tue, 04 Jul 2017 06:43:57 +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 v3 03/20] 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 , Igor Mammedov 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 | 18 ++++++++++++++++++ include/hw/qdev-core.h | 1 + include/hw/qdev-properties.h | 9 +++++++++ 3 files changed, 28 insertions(+) diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index 113ce7d..5429c63 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -1214,3 +1214,21 @@ 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, + qdev_prop_allow_set_link_before_realize, + OBJ_PROP_LINK_UNREF_ON_RELEASE, + 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..08d1d2c 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -233,6 +233,7 @@ struct Property { int arrayoffset; PropertyInfo *arrayinfo; int arrayfieldsize; + const char *link_type; }; =20 struct PropertyInfo { diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h index 9edded2..b150378 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,14 @@ extern PropertyInfo qdev_prop_arraylen; .arrayoffset =3D offsetof(_state, _arrayfield), \ } =20 +#define DEFINE_PROP_LINK(_name, _state, _field, _type) {\ + .name =3D (_name), \ + .info =3D &(qdev_prop_link), \ + .offset =3D offsetof(_state, _field) \ + + type_check(Object *, typeof_field(_state, _field)), \ + .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