On Tue, Mar 10, 2015 at 17:45:16 +0100, Michal Privoznik wrote:
This patch turns both virNetworkObjFindByUUID() and
virNetworkObjFindByName() to return an referenced object so that
even if caller unlocks it, it's for sure that object won't
disappear meanwhile. Especially if the object (in general) is
locked and unlocked during the caller run.
Moreover, this commit is nicely small, since the object unrefing
can be done in virNetworkObjEndAPI().
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/conf/network_conf.c | 15 ++++++++++-----
src/network/bridge_driver.c | 18 +++++-------------
src/test/test_driver.c | 10 ++++------
3 files changed, 19 insertions(+), 24 deletions(-)
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 98342f9..a2aa4dc 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -143,6 +143,7 @@ virNetworkObjEndAPI(virNetworkObjPtr *net)
return;
virObjectUnlock(*net);
+ virObjectUnref(*net);
*net = NULL;
}
@@ -175,7 +176,7 @@ virNetworkObjFindByUUIDLocked(virNetworkObjListPtr nets,
ret = virHashLookup(nets->objs, uuidstr);
if (ret)
- virObjectLock(ret);
+ virObjectRef(ret);
return ret;
Since this ...
}
@@ -188,6 +189,8 @@ virNetworkObjFindByUUID(virNetworkObjListPtr nets,
virObjectLock(nets);
ret = virNetworkObjFindByUUIDLocked(nets, uuid);
virObjectUnlock(nets);
+ if (ret)
+ virObjectLock(ret);
and this function now differ not only in the fact that they require the
@nets object to be locked or not but in the state of the returned object
they deserve a comment telling the difference.
return ret;
}
@@ -214,7 +217,7 @@ virNetworkObjFindByNameLocked(virNetworkObjListPtr nets,
ret = virHashSearch(nets->objs, virNetworkObjSearchName, name);
if (ret)
- virObjectLock(ret);
+ virObjectRef(ret);
return ret;
}
@@ -227,6 +230,8 @@ virNetworkObjFindByName(virNetworkObjListPtr nets,
virObjectLock(nets);
ret = virNetworkObjFindByNameLocked(nets, name);
virObjectUnlock(nets);
+ if (ret)
+ virObjectLock(ret);
Same here.
return ret;
}
ACK,
Peter