Message ID | 20250102211800.79235-4-philmd@linaro.org |
---|---|
State | New |
Headers | show |
Series | QOM: container_get() removal | expand |
On 1/2/25 13:17, Philippe Mathieu-Daudé wrote: > From: Peter Xu <peterx@redhat.com> > > Add a helper to fetch machine containers. Add some sanity check around. > > Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> > Signed-off-by: Peter Xu <peterx@redhat.com> > Message-ID: <20241121192202.4155849-10-peterx@redhat.com> > Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> > --- > include/hw/qdev-core.h | 10 ++++++++++ > hw/core/qdev.c | 11 +++++++++++ > 2 files changed, 21 insertions(+) Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index b83b1439968..2434065bad2 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -1037,6 +1037,16 @@ Object *qdev_get_machine(void); */ Object *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. diff --git a/hw/core/qdev.c b/hw/core/qdev.c index bc5b60212a7..9973e029ffa 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -829,6 +829,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);