aboutsummaryrefslogtreecommitdiff
path: root/qom/container.c
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2012-03-27 18:38:45 +0200
committerAnthony Liguori <aliguori@us.ibm.com>2012-04-02 15:04:15 -0500
commita612b2a6635fa1a3a29a8bcf41b31f1f3fae1110 (patch)
treead67b1ac99f0ba0a9fc8ba49b6cad26b186f0401 /qom/container.c
parentcefc898806e0346eef87d15ddaac9475b57b7d84 (diff)
qom: add container_get
This is QOM "mkdir -p". It is useful when referring to container objects such as "/machine". Reviewed-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'qom/container.c')
-rw-r--r--qom/container.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/qom/container.c b/qom/container.c
index f107208867..67e9e8a6f8 100644
--- a/qom/container.c
+++ b/qom/container.c
@@ -12,6 +12,7 @@
#include "qemu/object.h"
#include "module.h"
+#include <assert.h>
static TypeInfo container_info = {
.name = "container",
@@ -24,4 +25,26 @@ static void container_register_types(void)
type_register_static(&container_info);
}
+Object *container_get(const char *path)
+{
+ Object *obj, *child;
+ gchar **parts;
+ int i;
+
+ parts = g_strsplit(path, "/", 0);
+ assert(parts != NULL && parts[0] != NULL && !parts[0][0]);
+ obj = object_get_root();
+
+ for (i = 1; parts[i] != NULL; i++, obj = child) {
+ child = object_resolve_path_component(obj, parts[i]);
+ if (!child) {
+ child = object_new("container");
+ object_property_add_child(obj, parts[i], child, NULL);
+ }
+ }
+
+ return obj;
+}
+
+
type_init(container_register_types)