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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
> ---
>  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

Attachment: signature.asc
Description: Digital signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]