]> www.infradead.org Git - users/dwmw2/qemu.git/commitdiff
qdev: Add machine_get_container()
authorPeter Xu <peterx@redhat.com>
Thu, 21 Nov 2024 19:21:58 +0000 (14:21 -0500)
committerPhilippe Mathieu-Daudé <philmd@linaro.org>
Thu, 9 Jan 2025 17:16:24 +0000 (18:16 +0100)
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>
hw/core/qdev.c
include/hw/qdev-core.h

index 48bc9a7b9c7381ecaba5186afa37ad43974958f8..9abc4e8322f35cd3d9d3c075044bacebe42f9778 100644 (file)
@@ -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);
index 50cbbf81211967dc1f453bf9e790087ffb934c3a..89575e74e2733615d4e5269527bfd29079be39c0 100644 (file)
@@ -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.