[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 05/11] qdev: Add machine_get_container()
From: |
Philippe Mathieu-Daudé |
Subject: |
[PULL 05/11] qdev: Add machine_get_container() |
Date: |
Thu, 9 Jan 2025 18:19:42 +0100 |
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>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
include/hw/qdev-core.h | 10 ++++++++++
hw/core/qdev.c | 11 +++++++++++
2 files changed, 21 insertions(+)
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index 50cbbf81211..89575e74e27 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.
diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index 48bc9a7b9c7..9abc4e8322f 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);
--
2.47.1
- [PULL 00/11] QOM / QDev patches for 2025-01-09, Philippe Mathieu-Daudé, 2025/01/09
- [PULL 01/11] hw/pci: Use -1 as the default value for rombar, Philippe Mathieu-Daudé, 2025/01/09
- [PULL 02/11] qdev: Remove opts member, Philippe Mathieu-Daudé, 2025/01/09
- [PULL 03/11] qdev: Implement qdev_create_fake_machine() for user emulation, Philippe Mathieu-Daudé, 2025/01/09
- [PULL 04/11] qdev: Make qdev_get_machine() not use container_get(), Philippe Mathieu-Daudé, 2025/01/09
- [PULL 05/11] qdev: Add machine_get_container(),
Philippe Mathieu-Daudé <=
- [PULL 06/11] qdev: Use machine_get_container(), Philippe Mathieu-Daudé, 2025/01/09
- [PULL 07/11] qom: Add object_get_container(), Philippe Mathieu-Daudé, 2025/01/09
- [PULL 08/11] qom: Use object_get_container(), Philippe Mathieu-Daudé, 2025/01/09
- [PULL 09/11] qom: Remove container_get(), Philippe Mathieu-Daudé, 2025/01/09
- [PULL 10/11] qom: remove unused InterfaceInfo::concrete_class field, Philippe Mathieu-Daudé, 2025/01/09
- [PULL 11/11] system: Inline machine_containers[] in qemu_create_machine_containers(), Philippe Mathieu-Daudé, 2025/01/09