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

Re: [libvirt] Potential deadlock in libvirt lxc driver



Hey again,

attached is a patch against master that fixes the race condition for
me. Not sure if this is the best solution. My system is quite stable
now under load instead of dying every so often.

best,
Tom
From db8d9d3e674328b81fabc3dcb7981b4727a8e369 Mon Sep 17 00:00:00 2001
From: Thomas Hunger <tehunger gmail com>
Date: Wed, 14 Mar 2012 23:00:22 +0000
Subject: [PATCH] Use virDomainFindbyID and pass id instead of a pointer to lxcMontitorEvent.

This fixes a race condition where lxcDomainDestroyFlags would acquire the
driver lock. It would then kill processes in the cgroup and trigger
VIR_EVENT_HANDLE_HANGUP, which in turn triggers lxcMonitorEvent.

lxcMonitorEvent tries to acquire the driver lock itself, so it would block
until destroy has invalidated the data "vm" points to.

By using virDomainFindbyID lxcMonitorEvent avoids using an invalid vm
pointer.
---
 src/lxc/lxc_driver.c |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 3af8084..22763a3 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -1523,11 +1523,17 @@ static void lxcMonitorEvent(int watch,
                             void *data)
 {
     lxc_driver_t *driver = lxc_driver;
-    virDomainObjPtr vm = data;
+    int id = (int)data;
+    virDomainObjPtr vm = NULL;
     virDomainEventPtr event = NULL;
     lxcDomainObjPrivatePtr priv;
 
     lxcDriverLock(driver);
+    vm = virDomainFindByID(&driver->domains, id);
+    if (vm == NULL) {
+        lxcDriverUnlock(driver);
+        goto cleanup;
+    }
     virDomainObjLock(vm);
     lxcDriverUnlock(driver);
 
@@ -1950,7 +1956,7 @@ static int lxcVmStart(virConnectPtr conn,
              priv->monitor,
              VIR_EVENT_HANDLE_ERROR | VIR_EVENT_HANDLE_HANGUP,
              lxcMonitorEvent,
-             vm, NULL)) < 0) {
+             (void*)vm->def->id, NULL)) < 0) {
         goto error;
     }
 
@@ -2513,7 +2519,7 @@ lxcReconnectVM(void *payload, const void *name ATTRIBUTE_UNUSED, void *opaque)
                  priv->monitor,
                  VIR_EVENT_HANDLE_ERROR | VIR_EVENT_HANDLE_HANGUP,
                  lxcMonitorEvent,
-                 vm, NULL)) < 0)
+                 (void*)vm->def->id, NULL)) < 0)
             goto error;
 
         if (virSecurityManagerReserveLabel(driver->securityManager,
-- 
1.7.2.5


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