浏览代码

qom: Refine container_get() to allow using a custom root

Specify the root to search from as argument. This avoids hardcoding
"/machine" in some places and makes it more flexible.

Signed-off-by: Andreas Färber <afaerber@suse.de>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Anthony Liguori <anthony@codemonkey.ws>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Andreas Färber 13 年之前
父节点
当前提交
dfe47e7029
共有 4 个文件被更改,包括 10 次插入8 次删除
  1. 2 2
      hw/qdev-monitor.c
  2. 4 3
      hw/qdev.c
  3. 2 1
      include/qemu/object.h
  4. 2 2
      qom/container.c

+ 2 - 2
hw/qdev-monitor.c

@@ -181,7 +181,7 @@ static Object *qdev_get_peripheral(void)
     static Object *dev;
     static Object *dev;
 
 
     if (dev == NULL) {
     if (dev == NULL) {
-        dev = container_get("/machine/peripheral");
+        dev = container_get(qdev_get_machine(), "/peripheral");
     }
     }
 
 
     return dev;
     return dev;
@@ -192,7 +192,7 @@ static Object *qdev_get_peripheral_anon(void)
     static Object *dev;
     static Object *dev;
 
 
     if (dev == NULL) {
     if (dev == NULL) {
-        dev = container_get("/machine/peripheral-anon");
+        dev = container_get(qdev_get_machine(), "/peripheral-anon");
     }
     }
 
 
     return dev;
     return dev;

+ 4 - 3
hw/qdev.c

@@ -158,8 +158,9 @@ int qdev_init(DeviceState *dev)
         static int unattached_count = 0;
         static int unattached_count = 0;
         gchar *name = g_strdup_printf("device[%d]", unattached_count++);
         gchar *name = g_strdup_printf("device[%d]", unattached_count++);
 
 
-        object_property_add_child(container_get("/machine/unattached"), name,
-                                  OBJECT(dev), NULL);
+        object_property_add_child(container_get(qdev_get_machine(),
+                                                "/unattached"),
+                                  name, OBJECT(dev), NULL);
         g_free(name);
         g_free(name);
     }
     }
 
 
@@ -677,7 +678,7 @@ Object *qdev_get_machine(void)
     static Object *dev;
     static Object *dev;
 
 
     if (dev == NULL) {
     if (dev == NULL) {
-        dev = container_get("/machine");
+        dev = container_get(object_get_root(), "/machine");
     }
     }
 
 
     return dev;
     return dev;

+ 2 - 1
include/qemu/object.h

@@ -905,6 +905,7 @@ void object_property_add_str(Object *obj, const char *name,
 
 
 /**
 /**
  * container_get:
  * container_get:
+ * @root: root of the #path, e.g., object_get_root()
  * @path: path to the container
  * @path: path to the container
  *
  *
  * Return a container object whose path is @path.  Create more containers
  * Return a container object whose path is @path.  Create more containers
@@ -912,7 +913,7 @@ void object_property_add_str(Object *obj, const char *name,
  *
  *
  * Returns: the container object.
  * Returns: the container object.
  */
  */
-Object *container_get(const char *path);
+Object *container_get(Object *root, const char *path);
 
 
 
 
 #endif
 #endif

+ 2 - 2
qom/container.c

@@ -25,7 +25,7 @@ static void container_register_types(void)
     type_register_static(&container_info);
     type_register_static(&container_info);
 }
 }
 
 
-Object *container_get(const char *path)
+Object *container_get(Object *root, const char *path)
 {
 {
     Object *obj, *child;
     Object *obj, *child;
     gchar **parts;
     gchar **parts;
@@ -33,7 +33,7 @@ Object *container_get(const char *path)
 
 
     parts = g_strsplit(path, "/", 0);
     parts = g_strsplit(path, "/", 0);
     assert(parts != NULL && parts[0] != NULL && !parts[0][0]);
     assert(parts != NULL && parts[0] != NULL && !parts[0][0]);
-    obj = object_get_root();
+    obj = root;
 
 
     for (i = 1; parts[i] != NULL; i++, obj = child) {
     for (i = 1; parts[i] != NULL; i++, obj = child) {
         child = object_resolve_path_component(obj, parts[i]);
         child = object_resolve_path_component(obj, parts[i]);