[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 05/10] qdev: Add machine_get_container()
From: |
Philippe Mathieu-Daudé |
Subject: |
[PATCH v3 05/10] qdev: Add machine_get_container() |
Date: |
Thu, 2 Jan 2025 16:12:39 +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>
---
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 bf8a0ee6486..bb4b085c9ce 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -1027,6 +1027,16 @@ const char *qdev_fw_name(DeviceState *dev);
void qdev_assert_realized_properly(void);
Object *qdev_get_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);
--
2.47.1
- [PATCH v3 00/10] QOM: container_get() removal, Philippe Mathieu-Daudé, 2025/01/02
- [PATCH v3 01/10] qdev: Expose qemu_create_machine(), Philippe Mathieu-Daudé, 2025/01/02
- [PATCH v3 02/10] qdev: Implement qemu_create_machine() for user emulation, Philippe Mathieu-Daudé, 2025/01/02
- [PATCH v3 04/10] qdev: Make qdev_get_machine() not use container_get(), Philippe Mathieu-Daudé, 2025/01/02
- [PATCH v3 05/10] qdev: Add machine_get_container(),
Philippe Mathieu-Daudé <=
- [PATCH v3 07/10] qom: Add object_get_container(), Philippe Mathieu-Daudé, 2025/01/02
- [PATCH v3 03/10] qdev: Call qemu_create_machine() on user emulation, Philippe Mathieu-Daudé, 2025/01/02
- [PATCH v3 06/10] qdev: Use machine_get_container(), Philippe Mathieu-Daudé, 2025/01/02
- [PATCH v3 08/10] qom: Use object_get_container(), Philippe Mathieu-Daudé, 2025/01/02
- [PATCH v3 09/10] qom: Remove container_get(), Philippe Mathieu-Daudé, 2025/01/02
- [PATCH v3 10/10] qdev: Inline machine_containers[] in qemu_create_machine_containers(), Philippe Mathieu-Daudé, 2025/01/02
- Re: [PATCH v3 00/10] QOM: container_get() removal, Peter Xu, 2025/01/02