From patchwork Wed Jun 4 17:52:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 356058 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 80184140094 for ; Thu, 5 Jun 2014 03:57:07 +1000 (EST) Received: from localhost ([::1]:35872 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WsFQu-0003mi-PQ for incoming@patchwork.ozlabs.org; Wed, 04 Jun 2014 13:57:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38368) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WsFQF-0002ZI-V6 for qemu-devel@nongnu.org; Wed, 04 Jun 2014 13:56:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WsFQ9-0001J5-Mc for qemu-devel@nongnu.org; Wed, 04 Jun 2014 13:56:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:30384) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WsFQ9-0001Iq-FE for qemu-devel@nongnu.org; Wed, 04 Jun 2014 13:56:17 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s54HuE0Y028581 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 4 Jun 2014 13:56:15 -0400 Received: from amt.cnet (vpn1-6-9.gru2.redhat.com [10.97.6.9]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s54HuDC9023482; Wed, 4 Jun 2014 13:56:13 -0400 Received: from amt.cnet (localhost [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id 62FE61003DA; Wed, 4 Jun 2014 14:55:53 -0300 (BRT) Received: (from marcelo@localhost) by amt.cnet (8.14.7/8.14.7/Submit) id s54Htrb3031275; Wed, 4 Jun 2014 14:55:53 -0300 Message-Id: <20140604175446.484888751@amt.cnet> User-Agent: quilt/0.60-1 Date: Wed, 04 Jun 2014 14:52:02 -0300 From: mtosatti@redhat.com To: qemu-devel@nongnu.org References: <20140604175200.667995104@amt.cnet> Content-Disposition: inline; filename=qom-add-alias X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: gleb@kernel.org, mprivozn@redhat.com, Marcelo Tosatti , armbru@redhat.com, pbonzini@redhat.com Subject: [Qemu-devel] [patch 2/3] 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 Allowing addition of a link without keeping pointer-to-pointer. Signed-off-by: Marcelo Tosatti --- include/qom/object.h | 13 +++++++++ qom/object.c | 73 +++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 72 insertions(+), 14 deletions(-) Index: qemu/include/qom/object.h =================================================================== --- qemu.orig/include/qom/object.h 2014-06-02 23:12:51.875693325 -0300 +++ qemu/include/qom/object.h 2014-06-02 23:14:13.045432426 -0300 @@ -1073,6 +1073,19 @@ } ObjectPropertyLinkFlags; /** + * object_property_add_alias: + * @obj: the object to add a property to + * @name: the name of the property + * @alias: the alias object + * @errp: if an error occurs, a pointer to an area to store the area + * + * Add a link under obj, named name, pointing to alias. + * + */ +void object_property_add_alias(Object *obj, const char *name, + Object *alias, Error **errp); + +/** * object_property_allow_set_link: * * The default implementation of the object_property_add_link() check() Index: qemu/qom/object.c =================================================================== --- qemu.orig/qom/object.c 2014-06-02 23:12:51.875693325 -0300 +++ qemu/qom/object.c 2014-06-02 23:14:13.046432423 -0300 @@ -1023,27 +1023,71 @@ g_free(type); } +typedef struct { + Object *child; + Object **childp; + void (*check)(Object *, const char *, Object *, Error **); + ObjectPropertyLinkFlags flags; +} LinkProperty; + +static void object_get_alias_property(Object *obj, Visitor *v, void *opaque, + const char *name, Error **errp) +{ + LinkProperty *prop = opaque; + Object *child = prop->child; + gchar *path; + + path = object_get_canonical_path(child); + visit_type_str(v, &path, name, errp); + g_free(path); +} + +static void object_release_alias_property(Object *obj, const char *name, + void *opaque) +{ + LinkProperty *prop = opaque; + + g_free(prop); +} + +void object_property_add_alias(Object *obj, const char *name, + Object *alias, Error **errp) +{ + Error *local_err = NULL; + gchar *type; + LinkProperty *prop = g_malloc(sizeof(*prop)); + + type = g_strdup_printf("link<%s>", object_get_typename(OBJECT(alias))); + + prop->child = alias; + prop->check = NULL; + prop->flags = 0; + + object_property_add(obj, name, type, object_get_alias_property, NULL, + object_release_alias_property, prop, &local_err); + if (local_err) { + g_free(prop); + error_propagate(errp, local_err); + } + + g_free(type); +} + void object_property_allow_set_link(Object *obj, const char *name, Object *val, Error **errp) { /* Allow the link to be set, always */ } -typedef struct { - Object **child; - void (*check)(Object *, const char *, Object *, Error **); - ObjectPropertyLinkFlags flags; -} LinkProperty; - static void object_get_link_property(Object *obj, Visitor *v, void *opaque, const char *name, Error **errp) { LinkProperty *lprop = opaque; - Object **child = lprop->child; + Object *child = lprop->child; gchar *path; - if (*child) { - path = object_get_canonical_path(*child); + if (child) { + path = object_get_canonical_path(child); visit_type_str(v, &path, name, errp); g_free(path); } else { @@ -1096,7 +1140,7 @@ { Error *local_err = NULL; LinkProperty *prop = opaque; - Object **child = prop->child; + Object **child = prop->childp; Object *old_target = *child; Object *new_target = NULL; char *path = NULL; @@ -1133,8 +1177,8 @@ { LinkProperty *prop = opaque; - if ((prop->flags & OBJ_PROP_LINK_UNREF_ON_RELEASE) && *prop->child) { - object_unref(*prop->child); + if ((prop->flags & OBJ_PROP_LINK_UNREF_ON_RELEASE) && prop->child) { + object_unref(prop->child); } g_free(prop); } @@ -1150,7 +1194,8 @@ LinkProperty *prop = g_malloc(sizeof(*prop)); gchar *full_type; - prop->child = child; + prop->childp = child; + prop->child = *child; prop->check = check; prop->flags = flags; @@ -1227,7 +1272,7 @@ if (object_property_is_link(prop)) { LinkProperty *lprop = prop->opaque; - return *lprop->child; + return lprop->child; } else if (object_property_is_child(prop)) { return prop->opaque; } else {