Re: [PATCH] Fix thread safety in LXC callback handling

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

 



On 22.03.2013 13:11, Daniel P. Berrange wrote:
> From: "Daniel P. Berrange" <berrange@xxxxxxxxxx>
> 
> Some of the LXC callbacks did not lock the virDomainObjPtr
> instance. This caused transient errors like
> 
> error: Failed to start domain busy-mount
> error: cannot rename file '/var/run/libvirt/lxc/busy-mount.xml.new' as '/var/run/libvirt/lxc/busy-mount.xml': No such file or directory
> 
> as 2 threads tried to update the status file concurrently
> 
> Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx>
> ---
>  src/lxc/lxc_process.c | 17 ++++++++++++++++-
>  1 file changed, 16 insertions(+), 1 deletion(-)
> 
> diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c
> index 670a032..39a6ea2 100644
> --- a/src/lxc/lxc_process.c
> +++ b/src/lxc/lxc_process.c
> @@ -610,8 +610,13 @@ static void virLXCProcessMonitorExitNotify(virLXCMonitorPtr mon ATTRIBUTE_UNUSED
>                                             virLXCMonitorExitStatus status,
>                                             virDomainObjPtr vm)
>  {
> +    virLXCDriverPtr driver = lxc_driver;
>      virLXCDomainObjPrivatePtr priv = vm->privateData;
>  
> +    lxcDriverLock(driver);
> +    virObjectLock(vm);
> +    lxcDriverUnlock(driver);
> +
>      switch (status) {
>      case VIR_LXC_MONITOR_EXIT_STATUS_SHUTDOWN:
>          priv->stopReason = VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN;
> @@ -629,6 +634,8 @@ static void virLXCProcessMonitorExitNotify(virLXCMonitorPtr mon ATTRIBUTE_UNUSED
>      }
>      VIR_DEBUG("Domain shutoff reason %d (from status %d)",
>                priv->stopReason, status);
> +
> +    virObjectUnlock(vm);
>  }
>  
>  static int
> @@ -667,9 +674,15 @@ static void virLXCProcessMonitorInitNotify(virLXCMonitorPtr mon ATTRIBUTE_UNUSED
>                                             pid_t initpid,
>                                             virDomainObjPtr vm)
>  {
> -    virLXCDomainObjPrivatePtr priv = vm->privateData;
> +    virLXCDriverPtr driver = lxc_driver;
> +    virLXCDomainObjPrivatePtr priv;
>      ino_t inode;
>  
> +    lxcDriverLock(driver);
> +    virObjectLock(vm);
> +    lxcDriverUnlock(driver);
> +
> +    priv = vm->privateData;
>      priv->initpid = initpid;
>  
>      if (virLXCProcessGetNsInode(initpid, "pid", &inode) < 0) {
> @@ -684,6 +697,8 @@ static void virLXCProcessMonitorInitNotify(virLXCMonitorPtr mon ATTRIBUTE_UNUSED
>  
>      if (virDomainSaveStatus(lxc_driver->xmlconf, lxc_driver->stateDir, vm) < 0)
>          VIR_WARN("Cannot update XML with PID for LXC %s", vm->def->name);
> +
> +    virObjectUnlock(vm);
>  }
>  
>  static virLXCMonitorCallbacks monitorCallbacks = {
> 

ACK

Michal

--
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]