From 41fc91772841c93c218df78d7e359cb2cd00dff5 Mon Sep 17 00:00:00 2001 From: Peter Xu Date: Thu, 21 Nov 2024 14:21:58 -0500 Subject: [PATCH] qdev: Add machine_get_container() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Add a helper to fetch machine containers. Add some sanity check around. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Peter Xu Message-ID: <20241121192202.4155849-10-peterx@redhat.com> Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson --- hw/core/qdev.c | 11 +++++++++++ include/hw/qdev-core.h | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 48bc9a7b9c..9abc4e8322 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -828,6 +828,17 @@ Object *qdev_get_machine(void) return dev; } +Object *machine_get_container(const char *name) +{ + Object *container, *machine; + + machine = qdev_get_machine(); + container = object_resolve_path_component(machine, name); + assert(object_dynamic_cast(container, TYPE_CONTAINER)); + + return container; +} + char *qdev_get_human_name(DeviceState *dev) { g_assert(dev != NULL); diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 50cbbf8121..89575e74e2 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -1033,6 +1033,16 @@ Object *qdev_get_machine(void); */ void qdev_create_fake_machine(void); +/** + * machine_get_container: + * @name: The name of container to lookup + * + * Get a container of the machine (QOM path "/machine/NAME"). + * + * Returns: the machine container object. + */ +Object *machine_get_container(const char *name); + /** * qdev_get_human_name() - Return a human-readable name for a device * @dev: The device. Must be a valid and non-NULL pointer. -- 2.30.2