Re: [PATCH v3 10/15] virNetworkObjFindBy*: Return an reference to found object

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

 



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

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]