From patchwork Fri May 30 11:17:45 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 354070 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 964FB1400D6 for ; Fri, 30 May 2014 21:20:31 +1000 (EST) Received: from localhost ([::1]:53236 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WqKrN-0004or-9S for incoming@patchwork.ozlabs.org; Fri, 30 May 2014 07:20:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46961) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WqKpB-00006E-0g for qemu-devel@nongnu.org; Fri, 30 May 2014 07:18:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WqKp4-000334-Tc for qemu-devel@nongnu.org; Fri, 30 May 2014 07:18:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:10121) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WqKp4-00032o-KI for qemu-devel@nongnu.org; Fri, 30 May 2014 07:18:06 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s4UBI4fO017036 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 30 May 2014 07:18:04 -0400 Received: from localhost (ovpn-112-47.ams2.redhat.com [10.36.112.47]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s4UBI35H011509; Fri, 30 May 2014 07:18:04 -0400 From: Stefan Hajnoczi To: Date: Fri, 30 May 2014 13:17:45 +0200 Message-Id: <1401448669-4655-5-git-send-email-stefanha@redhat.com> In-Reply-To: <1401448669-4655-1-git-send-email-stefanha@redhat.com> References: <1401448669-4655-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: pbonzini@redhat.com, peter.crosthwaite@xilinx.com, afaerber@suse.de, Stefan Hajnoczi , fred.konrad@greensocs.com Subject: [Qemu-devel] [PATCH v3 4/8] qdev: add qdev_alias_all_properties() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The qdev_alias_all_properties() function creates QOM alias properties for each qdev property on a DeviceState. This is useful for parent objects that wish to forward property accesses to their children. Signed-off-by: Stefan Hajnoczi Reviewed-by: Peter Crosthwaite --- v3: * Split qdev_alias_all_properties() into its own patch [Peter Crosthwaite] * Do not dereference DEVICE_CLASS(class) inline [Peter Crosthwaite] --- hw/core/qdev.c | 21 +++++++++++++++++++++ include/hw/qdev-properties.h | 2 ++ 2 files changed, 23 insertions(+) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index e65a5aa..850cd9e 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -776,6 +776,27 @@ void qdev_property_add_static(DeviceState *dev, Property *prop, } } +/* @qdev_alias_all_properties - Add alias properties to the source object for + * all qdev properties on the target DeviceState. + */ +void qdev_alias_all_properties(DeviceState *target, Object *source) +{ + ObjectClass *class; + Property *prop; + + class = object_get_class(OBJECT(target)); + do { + DeviceClass *dc = DEVICE_CLASS(class); + + for (prop = dc->props; prop && prop->name; prop++) { + object_property_add_alias(source, prop->name, + OBJECT(target), prop->name, + &error_abort); + } + class = object_class_get_parent(class); + } while (class != object_class_by_name(TYPE_DEVICE)); +} + static bool device_get_realized(Object *obj, Error **errp) { DeviceState *dev = DEVICE(obj); diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h index c46e908..ffef425 100644 --- a/include/hw/qdev-properties.h +++ b/include/hw/qdev-properties.h @@ -192,6 +192,8 @@ void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev, */ void qdev_property_add_static(DeviceState *dev, Property *prop, Error **errp); +void qdev_alias_all_properties(DeviceState *target, Object *source); + /** * @qdev_prop_set_after_realize: * @dev: device