aboutsummaryrefslogtreecommitdiff
path: root/qom
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2020-01-10 19:30:27 +0400
committerPaolo Bonzini <pbonzini@redhat.com>2020-01-24 20:59:14 +0100
commit9941d37b4d159da0f18edbd2bd7b9fd19484a286 (patch)
treeefb756984c29fc356d739fc333b8347648ce4171 /qom
parent36854207f093c60eecde377b2ec5d20b8614460c (diff)
object: add direct link flag
Allow the link property to hold the pointer to the target, instead of indirectly through another variable. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20200110153039.1379601-15-marcandre.lureau@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'qom')
-rw-r--r--qom/object.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/qom/object.c b/qom/object.c
index bb5b739c61..a9760d5276 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -1713,17 +1713,30 @@ void object_property_allow_set_link(const Object *obj, const char *name,
}
typedef struct {
- Object **targetp;
+ union {
+ Object **targetp;
+ Object *target; /* if OBJ_PROP_LINK_DIRECT, when holding the pointer */
+ };
void (*check)(const Object *, const char *, Object *, Error **);
ObjectPropertyLinkFlags flags;
} LinkProperty;
+static Object **
+object_link_get_targetp(Object *obj, LinkProperty *lprop)
+{
+ if (lprop->flags & OBJ_PROP_LINK_DIRECT) {
+ return &lprop->target;
+ } else {
+ return lprop->targetp;
+ }
+}
+
static void object_get_link_property(Object *obj, Visitor *v,
const char *name, void *opaque,
Error **errp)
{
LinkProperty *lprop = opaque;
- Object **targetp = lprop->targetp;
+ Object **targetp = object_link_get_targetp(obj, lprop);
gchar *path;
if (*targetp) {
@@ -1782,7 +1795,7 @@ static void object_set_link_property(Object *obj, Visitor *v,
{
Error *local_err = NULL;
LinkProperty *prop = opaque;
- Object **targetp = prop->targetp;
+ Object **targetp = object_link_get_targetp(obj, prop);
Object *old_target = *targetp;
Object *new_target = NULL;
char *path = NULL;
@@ -1816,16 +1829,17 @@ static Object *object_resolve_link_property(Object *parent, void *opaque, const
{
LinkProperty *lprop = opaque;
- return *lprop->targetp;
+ return *object_link_get_targetp(parent, lprop);
}
static void object_release_link_property(Object *obj, const char *name,
void *opaque)
{
LinkProperty *prop = opaque;
+ Object **targetp = object_link_get_targetp(obj, prop);
- if ((prop->flags & OBJ_PROP_LINK_STRONG) && *prop->targetp) {
- object_unref(*prop->targetp);
+ if ((prop->flags & OBJ_PROP_LINK_STRONG) && *targetp) {
+ object_unref(*targetp);
}
g_free(prop);
}