From patchwork Thu Apr 5 11:21:46 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andreas_F=C3=A4rber?= X-Patchwork-Id: 151041 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 7E5C2B6FCF for ; Fri, 6 Apr 2012 10:17:29 +1000 (EST) Received: from localhost ([::1]:38014 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SFuLu-0008TB-R8 for incoming@patchwork.ozlabs.org; Thu, 05 Apr 2012 17:36:22 -0400 Received: from eggs.gnu.org ([208.118.235.92]:47305) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SFklL-00020V-Lv for qemu-devel@nongnu.org; Thu, 05 Apr 2012 07:22:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SFklF-0004l8-ED for qemu-devel@nongnu.org; Thu, 05 Apr 2012 07:21:59 -0400 Received: from cantor2.suse.de ([195.135.220.15]:52077 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SFklF-0004kx-4s for qemu-devel@nongnu.org; Thu, 05 Apr 2012 07:21:53 -0400 Received: from relay1.suse.de (unknown [195.135.220.254]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id C90BB943C9; Thu, 5 Apr 2012 13:21:46 +0200 (CEST) From: =?UTF-8?q?Andreas=20F=C3=A4rber?= To: qemu-devel@nongnu.org Date: Thu, 5 Apr 2012 13:21:46 +0200 Message-Id: <1333624906-7870-1-git-send-email-afaerber@suse.de> X-Mailer: git-send-email 1.7.7 In-Reply-To: <4F732C0F.8030005@redhat.com> References: <4F732C0F.8030005@redhat.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 X-Received-From: 195.135.220.15 Cc: Paolo Bonzini , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Anthony Liguori Subject: [Qemu-devel] [PATCH] qom: Refine container_get() to allow using a custom root 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 Specify the root to search from as argument. This avoids hardcoding "/machine" in some places and makes it more flexible. Signed-off-by: Andreas Färber Cc: Paolo Bonzini Cc: Anthony Liguori --- hw/qdev-monitor.c | 4 ++-- hw/qdev.c | 7 ++++--- include/qemu/object.h | 3 ++- qom/container.c | 4 ++-- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/hw/qdev-monitor.c b/hw/qdev-monitor.c index 4783366..67f296b 100644 --- a/hw/qdev-monitor.c +++ b/hw/qdev-monitor.c @@ -180,7 +180,7 @@ static Object *qdev_get_peripheral(void) static Object *dev; if (dev == NULL) { - dev = container_get("/machine/peripheral"); + dev = container_get(qdev_get_machine(), "/peripheral"); } return dev; @@ -191,7 +191,7 @@ static Object *qdev_get_peripheral_anon(void) static Object *dev; if (dev == NULL) { - dev = container_get("/machine/peripheral-anon"); + dev = container_get(qdev_get_machine(), "/peripheral-anon"); } return dev; diff --git a/hw/qdev.c b/hw/qdev.c index 0d3c0fc..efa4c5d 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -157,8 +157,9 @@ int qdev_init(DeviceState *dev) static int unattached_count = 0; gchar *name = g_strdup_printf("device[%d]", unattached_count++); - object_property_add_child(container_get("/machine/unattached"), name, - OBJECT(dev), NULL); + object_property_add_child(container_get(qdev_get_machine(), + "/unattached"), + name, OBJECT(dev), NULL); g_free(name); } @@ -673,7 +674,7 @@ Object *qdev_get_machine(void) static Object *dev; if (dev == NULL) { - dev = container_get("/machine"); + dev = container_get(object_get_root(), "/machine"); } return dev; diff --git a/include/qemu/object.h b/include/qemu/object.h index a675937..ca1649c 100644 --- a/include/qemu/object.h +++ b/include/qemu/object.h @@ -905,6 +905,7 @@ void object_property_add_str(Object *obj, const char *name, /** * container_get: + * @root: root of the #path, e.g., object_get_root() * @path: path to the container * * Return a container object whose path is @path. Create more containers @@ -912,7 +913,7 @@ void object_property_add_str(Object *obj, const char *name, * * Returns: the container object. */ -Object *container_get(const char *path); +Object *container_get(Object *root, const char *path); #endif diff --git a/qom/container.c b/qom/container.c index 67e9e8a..c9940ab 100644 --- a/qom/container.c +++ b/qom/container.c @@ -25,7 +25,7 @@ static void container_register_types(void) type_register_static(&container_info); } -Object *container_get(const char *path) +Object *container_get(Object *root, const char *path) { Object *obj, *child; gchar **parts; @@ -33,7 +33,7 @@ Object *container_get(const char *path) parts = g_strsplit(path, "/", 0); assert(parts != NULL && parts[0] != NULL && !parts[0][0]); - obj = object_get_root(); + obj = root; for (i = 1; parts[i] != NULL; i++, obj = child) { child = object_resolve_path_component(obj, parts[i]);