Marek Marczykowski-Górecki wrote:
> While iterating with virDomainObjListForEach it is safe to remove
> current element. But while iterating, 'doms' lock is already taken, so
> can't use standard virDomainObjListRemove. So introduce
> virDomainObjListRemoveLocked for this purpose.
>
> Changes in v2:
>  - fix indentation
>
> Signed-off-by: Marek Marczykowski-Górecki <marma...@invisiblethingslab.com>
> ---
>  src/conf/domain_conf.c   | 17 +++++++++++++++++
>  src/conf/domain_conf.h   |  2 ++
>  src/libvirt_private.syms |  1 +
>  3 files changed, 20 insertions(+)
>
> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> index 5350c56..a4010da 100644
> --- a/src/conf/domain_conf.c
> +++ b/src/conf/domain_conf.c
> @@ -2336,6 +2336,23 @@ void virDomainObjListRemove(virDomainObjListPtr doms,
>      virObjectUnlock(doms);
>  }
>  
> +/* The caller must hold lock on 'doms' in addition to 
> 'virDomainObjListRemove'
> + * requirements
> + *
> + * Can be used to remove current element while iterating with
> + * virDomainObjListForEach
> + */
> +void virDomainObjListRemoveLocked(virDomainObjListPtr doms,
> +                                  virDomainObjPtr dom)
> +{
> +    char uuidstr[VIR_UUID_STRING_BUFLEN];
> +
> +    virUUIDFormat(dom->def->uuid, uuidstr);
> +    virObjectUnlock(dom);
> +
> +    virHashRemoveEntry(doms->objs, uuidstr);
>   

Peter fixed a race in virDomainObjListRemove with commit b7c98329, and
although this function expects the domain obj list to be locked on
entry, it still seems some aspect of the race might exist here.  Is it
possible for another thread to lock the dom and execute some code on it
after the freeing function has been triggered?

Regards,
Jim

> +}
> +
>  static int
>  virDomainDeviceCCWAddressIsValid(virDomainDeviceCCWAddressPtr addr)
>  {
> diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
> index 24d3809..b8dfe19 100644
> --- a/src/conf/domain_conf.h
> +++ b/src/conf/domain_conf.h
> @@ -2234,6 +2234,8 @@ virDomainDefPtr 
> virDomainObjCopyPersistentDef(virDomainObjPtr dom,
>  
>  void virDomainObjListRemove(virDomainObjListPtr doms,
>                              virDomainObjPtr dom);
> +void virDomainObjListRemoveLocked(virDomainObjListPtr doms,
> +                                  virDomainObjPtr dom);
>  
>  virDomainDeviceDefPtr virDomainDeviceDefParse(const char *xmlStr,
>                                                virDomainDefPtr def,
> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
> index 042081f..e21a14d 100644
> --- a/src/libvirt_private.syms
> +++ b/src/libvirt_private.syms
> @@ -274,6 +274,7 @@ virDomainObjListLoadAllConfigs;
>  virDomainObjListNew;
>  virDomainObjListNumOfDomains;
>  virDomainObjListRemove;
> +virDomainObjListRemoveLocked;
>  virDomainObjNew;
>  virDomainObjSetDefTransient;
>  virDomainObjSetState;
>   

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

Reply via email to