[libvirt] [PATCH v2 16/24] network_conf: Introduce locked versions of lookup functions
Peter Krempa
pkrempa at redhat.com
Thu Mar 5 15:58:08 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];
This also creates a deadlock that you fix in the next one. Looks like a
rebase artifact.
> + virObjectUnlock(nets->objs[i]);
> + }
> +
> + return NULL;
> +}
-------------- 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/742328a9/attachment-0001.sig>
More information about the libvir-list
mailing list