Skip to content

Commit

Permalink
qom: Add helper function for getting user objects root
Browse files Browse the repository at this point in the history
Add object_get_objects_root() function which is a convenience for
obtaining the Object * located at /objects in the object
composition tree. Convert existing code over to use the new
API where appropriate.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
  • Loading branch information
berrange authored and afaerber committed Jun 19, 2015
1 parent f08f927 commit bc2256c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
12 changes: 12 additions & 0 deletions include/qom/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,18 @@ const char *object_property_get_type(Object *obj, const char *name,
*/
Object *object_get_root(void);


/**
* object_get_objects_root:
*
* Get the container object that holds user created
* object instances. This is the object at path
* "/objects"
*
* Returns: the user object container
*/
Object *object_get_objects_root(void);

/**
* object_get_canonical_path_component:
*
Expand Down
4 changes: 1 addition & 3 deletions iothread.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
#include "qmp-commands.h"
#include "qemu/error-report.h"

#define IOTHREADS_PATH "/objects"

typedef ObjectClass IOThreadClass;

#define IOTHREAD_GET_CLASS(obj) \
Expand Down Expand Up @@ -160,7 +158,7 @@ IOThreadInfoList *qmp_query_iothreads(Error **errp)
{
IOThreadInfoList *head = NULL;
IOThreadInfoList **prev = &head;
Object *container = container_get(object_get_root(), IOTHREADS_PATH);
Object *container = object_get_objects_root();

object_child_foreach(container, query_one_iothread, &prev);
return head;
Expand Down
2 changes: 1 addition & 1 deletion numa.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ MemdevList *qmp_query_memdev(Error **errp)
Object *obj;
MemdevList *list = NULL;

obj = object_resolve_path("/objects", NULL);
obj = object_get_objects_root();
if (obj == NULL) {
return NULL;
}
Expand Down
6 changes: 3 additions & 3 deletions qmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -651,15 +651,15 @@ void object_add(const char *type, const char *id, const QDict *qdict,
}
}

object_property_add_child(container_get(object_get_root(), "/objects"),
object_property_add_child(object_get_objects_root(),
id, obj, &local_err);
if (local_err) {
goto out;
}

user_creatable_complete(obj, &local_err);
if (local_err) {
object_property_del(container_get(object_get_root(), "/objects"),
object_property_del(object_get_objects_root(),
id, &error_abort);
goto out;
}
Expand Down Expand Up @@ -706,7 +706,7 @@ void qmp_object_del(const char *id, Error **errp)
Object *container;
Object *obj;

container = container_get(object_get_root(), "/objects");
container = object_get_objects_root();
obj = object_resolve_path_component(container, id);
if (!obj) {
error_setg(errp, "object id not found");
Expand Down
5 changes: 5 additions & 0 deletions qom/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,11 @@ Object *object_get_root(void)
return root;
}

Object *object_get_objects_root(void)
{
return container_get(object_get_root(), "/objects");
}

static void object_get_child_property(Object *obj, Visitor *v, void *opaque,
const char *name, Error **errp)
{
Expand Down

0 comments on commit bc2256c

Please sign in to comment.