From patchwork Thu Jun 5 11:23:55 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 356306 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 52470140080 for ; Thu, 5 Jun 2014 21:24:58 +1000 (EST) Received: from localhost ([::1]:39973 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WsVmy-0001jD-03 for incoming@patchwork.ozlabs.org; Thu, 05 Jun 2014 07:24:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53029) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WsVmI-0000mS-5P for qemu-devel@nongnu.org; Thu, 05 Jun 2014 07:24:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WsVm7-0003P0-ND for qemu-devel@nongnu.org; Thu, 05 Jun 2014 07:24:14 -0400 Received: from mail-wg0-x22a.google.com ([2a00:1450:400c:c00::22a]:60087) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WsVm7-0003Oo-Gb for qemu-devel@nongnu.org; Thu, 05 Jun 2014 07:24:03 -0400 Received: by mail-wg0-f42.google.com with SMTP id y10so901864wgg.25 for ; Thu, 05 Jun 2014 04:24:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=qCtFDyraYqykBljKawGNwCfK3Nfsi7bAAZTQo6cvw4k=; b=jFeMWY4JbWqY1gs5yzeJnbX524hOBAgK96ZTF6kY0KJLAj8CWxVj7WMXiTLPI3j5Jp AaZl6PXz32vxS6AZq+IhWcj2A53bxOzsWeNwQiPcaj8lX04cmA2s0+wDwJ0ks0+yKV6a BEMQBsqHORZQJ9Y+ufL5Ge4szPodWnoeFkmmXXRaWYUwB9KmuXvVKkpzZyWi2pQsoSYg TYK8k2cxylOoFtiYXwGx8XDxvmuBesI5as9I6InZNvZrfwU58q3Ie+6AjevEULZe200L YKUJSuDSV6E/kS7E6ng0exfBoPX+QfhpgpWcSAQu0lMQ7tF3rjH7GIKBQpxVSJ+3zU7s p64g== X-Received: by 10.14.127.129 with SMTP id d1mr47119eei.108.1401967442695; Thu, 05 Jun 2014 04:24:02 -0700 (PDT) Received: from playground.station (net-37-117-132-7.cust.vodafonedsl.it. [37.117.132.7]) by mx.google.com with ESMTPSA id z5sm13783650eee.31.2014.06.05.04.24.01 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Jun 2014 04:24:02 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 5 Jun 2014 13:23:55 +0200 Message-Id: <1401967435-17751-3-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1401967435-17751-1-git-send-email-pbonzini@redhat.com> References: <1401967435-17751-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c00::22a Cc: peter.crosthwaite@xilinx.com, mtosatti@redhat.com, afaerber@suse.de Subject: [Qemu-devel] [PATCH 2/2] qom: add object_property_add_alias 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 Similar to object_property_add_link, alias properties provide an alternative, non-canonical path to an object. In fact, external observers cannot distinguish alias properties from other links. Aliases differ from links in that they are immutable and typically managed by the target of the alias in order to add a link to itself at a well-known location. For example, a real-time clock device might add a link to itself at "/machine/rtc". Such well-known locations can then expose a standard set of properties that can be accessed via the "qom-get" and "qom-set" commands. Signed-off-by: Paolo Bonzini --- include/qom/object.h | 25 +++++++++++++++++++++++++ qom/object.c | 13 +++++++++++++ 2 files changed, 38 insertions(+) diff --git a/include/qom/object.h b/include/qom/object.h index f8ab845..fc80078 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -1116,6 +1116,31 @@ Object *object_resolve_path_component(Object *parent, const gchar *part); void object_property_add_child(Object *obj, const char *name, Object *child, Error **errp); +/** + * object_property_add_alias: + * @obj: the object to add a property to + * @name: the name of the property + * @dest: the destination of the alias + * @errp: if an error occurs, a pointer to an area to store the area + * + * Similar to @object_property_add_link, alias properties provide an + * alternative, non-canonical path to an object. In fact, external + * observers cannot distinguish alias properties from other links. + * + * Aliases differ from links in that they are immutable and typically + * managed by the target of the alias (@dest) in order to add a link to + * itself at a well-known location. For example, a real-time clock device + * might add a link to itself at "/machine/rtc". Such well-known locations + * can then expose a standard set of properties that can be accessed via + * the "qom-get" and "qom-set" commands. + * + * @object_property_add_alias does not add a reference to @dest. + * It is @dest's responsibility to remove the alias in its + * @instance_finalize function. + */ +void object_property_add_alias(Object *obj, const char *name, + Object *dest, Error **errp); + typedef enum { /* Unref the link pointer when the property is deleted */ OBJ_PROP_LINK_UNREF_ON_RELEASE = 0x1, diff --git a/qom/object.c b/qom/object.c index fcdd0da..46d60c8 100644 --- a/qom/object.c +++ b/qom/object.c @@ -1036,6 +1036,19 @@ out: g_free(type); } +void object_property_add_alias(Object *obj, const char *name, + Object *dest, Error **errp) +{ + gchar *type; + + type = g_strdup_printf("link<%s>", object_get_typename(OBJECT(dest))); + + object_property_add_full(obj, name, type, object_get_child_property, NULL, + object_resolve_child_property, + NULL, dest, errp); + g_free(type); +} + void object_property_allow_set_link(Object *obj, const char *name, Object *val, Error **errp) {