[libvirt] [PATCH v2 16/24] network_conf: Introduce locked versions of lookup functions

Peter Krempa pkrempa at redhat.com
Thu Mar 5 15:55:56 UTC 2015


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 at 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];
> +        virObjectUnlock(nets->objs[i]);
> +    }
> +
> +    return NULL;
> +}
> +
>  virNetworkObjPtr virNetworkObjFindByUUID(virNetworkObjListPtr nets,
>                                           const unsigned char *uuid)
>  {
> +    virNetworkObjPtr ret;
> +
> +    virObjectLock(nets);
> +    ret = virNetworkObjFindByUUIDLocked(nets, uuid);
> +    virObjectUnlock(nets);
> +    return ret;
> +}
> +
> +virNetworkObjPtr
> +virNetworkObjFindByNameLocked(virNetworkObjListPtr nets,
> +                              const char *name)
> +{
>      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))
> +        if (STREQ(nets->objs[i]->def->name, name))
>              return nets->objs[i];
>          virObjectUnlock(nets->objs[i]);
>      }
>  
>      return NULL;
>  }
> -

This deletes the whitespace between functions.

>  virNetworkObjPtr virNetworkObjFindByName(virNetworkObjListPtr nets,
>                                           const char *name)a

ACK without damaging the serenity of whitespace :D

Peter
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20150305/2a22d63f/attachment-0001.sig>


More information about the libvir-list mailing list