Skip to content

Commit 41fc917

Browse files
xzpeterphilmd
authored andcommitted
qdev: Add machine_get_container()
Add a helper to fetch machine containers. Add some sanity check around. Reviewed-by: Philippe Mathieu-Daudé <[email protected]> Signed-off-by: Peter Xu <[email protected]> Message-ID: <[email protected]> Signed-off-by: Philippe Mathieu-Daudé <[email protected]> Reviewed-by: Richard Henderson <[email protected]>
1 parent 63450f3 commit 41fc917

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

hw/core/qdev.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,17 @@ Object *qdev_get_machine(void)
828828
return dev;
829829
}
830830

831+
Object *machine_get_container(const char *name)
832+
{
833+
Object *container, *machine;
834+
835+
machine = qdev_get_machine();
836+
container = object_resolve_path_component(machine, name);
837+
assert(object_dynamic_cast(container, TYPE_CONTAINER));
838+
839+
return container;
840+
}
841+
831842
char *qdev_get_human_name(DeviceState *dev)
832843
{
833844
g_assert(dev != NULL);

include/hw/qdev-core.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,16 @@ Object *qdev_get_machine(void);
10331033
*/
10341034
void qdev_create_fake_machine(void);
10351035

1036+
/**
1037+
* machine_get_container:
1038+
* @name: The name of container to lookup
1039+
*
1040+
* Get a container of the machine (QOM path "/machine/NAME").
1041+
*
1042+
* Returns: the machine container object.
1043+
*/
1044+
Object *machine_get_container(const char *name);
1045+
10361046
/**
10371047
* qdev_get_human_name() - Return a human-readable name for a device
10381048
* @dev: The device. Must be a valid and non-NULL pointer.

0 commit comments

Comments
 (0)