summary refs log tree commit diff stats
path: root/qom/object.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/object.c
parentcefc898806e0346eef87d15ddaac9475b57b7d84 (diff)
downloadfocaccia-qemu-a612b2a6635fa1a3a29a8bcf41b31f1f3fae1110.tar.gz
focaccia-qemu-a612b2a6635fa1a3a29a8bcf41b31f1f3fae1110.zip
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/object.c')
-rw-r--r--qom/object.c33
1 files changed, 17 insertions, 16 deletions
diff --git a/qom/object.c b/qom/object.c
index 9cd9506eb5..e721fc28fb 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -1022,12 +1022,27 @@ gchar *object_get_canonical_path(Object *obj)
     return newpath;
 }
 
+Object *object_resolve_path_component(Object *parent, gchar *part)
+{
+    ObjectProperty *prop = object_property_find(parent, part);
+    if (prop == NULL) {
+        return NULL;
+    }
+
+    if (strstart(prop->type, "link<", NULL)) {
+        return *(Object **)prop->opaque;
+    } else if (strstart(prop->type, "child<", NULL)) {
+        return prop->opaque;
+    } else {
+        return NULL;
+    }
+}
+
 static Object *object_resolve_abs_path(Object *parent,
                                           gchar **parts,
                                           const char *typename,
                                           int index)
 {
-    ObjectProperty *prop;
     Object *child;
 
     if (parts[index] == NULL) {
@@ -1038,21 +1053,7 @@ static Object *object_resolve_abs_path(Object *parent,
         return object_resolve_abs_path(parent, parts, typename, index + 1);
     }
 
-    prop = object_property_find(parent, parts[index]);
-    if (prop == NULL) {
-        return NULL;
-    }
-
-    child = NULL;
-    if (strstart(prop->type, "link<", NULL)) {
-        Object **pchild = prop->opaque;
-        if (*pchild) {
-            child = *pchild;
-        }
-    } else if (strstart(prop->type, "child<", NULL)) {
-        child = prop->opaque;
-    }
-
+    child = object_resolve_path_component(parent, parts[index]);
     if (!child) {
         return NULL;
     }