On Thu, Mar 05, 2015 at 16:58:08 +0100, Peter Krempa wrote:
On Thu, Mar 05, 2015 at 12:05:17 +0100, Michal Privoznik wrote:
> This is going to be needed later, when some functions needs to avoid
> calling multiple times at once. It will work like this:
>
> 1) gain the object list mutex
> 2) find the object to work on
> 3) do the work
> 4) release the mutex
>
> As an example of such function is virNetworkAssignDef(). The other
> use case might be in virNetworkObjListForEach() callback.
>
> Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
> ---
> src/conf/network_conf.c | 45 ++++++++++++++++++++++++++++++++++-----------
> src/conf/network_conf.h | 4 ++++
> src/libvirt_private.syms | 2 ++
> 3 files changed, 40 insertions(+), 11 deletions(-)
>
> diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
> index a821f6c..8cf9ffd 100644
> --- a/src/conf/network_conf.c
> +++ b/src/conf/network_conf.c
> @@ -153,34 +153,57 @@ virNetworkObjListPtr virNetworkObjListNew(void)
> return nets;
> }
>
> +virNetworkObjPtr
> +virNetworkObjFindByUUIDLocked(virNetworkObjListPtr nets,
> + const unsigned char *uuid)
> +{
> + size_t i;
> +
> + for (i = 0; i < nets->count; i++) {
> + virObjectLock(nets->objs[i]);
> + if (!memcmp(nets->objs[i]->def->uuid, uuid, VIR_UUID_BUFLEN))
> + return nets->objs[i];
This also creates a deadlock that you fix in the next one. Looks like a
rebase artifact.
Disregard this please, the locking is right, just the changes in the
next patch confused me at first.
Peter