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

[libvirt] [PATCH] Fix thread safety in LXC callback handling



From: "Daniel P. Berrange" <berrange redhat com>

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 redhat com>
---
 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 = {
-- 
1.7.11.7


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