aboutsummaryrefslogtreecommitdiffstats
path: root/recipes-extended/libvirt/libvirt/libvirt-1.0.3-fix-thread-safety-in-lxc-callback-handling.patch
blob: 558d5ef65c332c4fa22c5429be99081b8f394477 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
From ad5d9cee87357f9f38f62583119606ef95ba10df Mon Sep 17 00:00:00 2001
From: Bogdan Purcareata <bogdan.purcareata@freescale.com>
Date: Fri, 24 May 2013 16:46:00 +0300
Subject: [PATCH] Fix thread safety in LXC callback handling

Signed-off-by: Bogdan Purcareata <bogdan.purcareata@freescale.com>
---
 src/lxc/lxc_process.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c
index aaa81a7..0eadc67 100644
--- a/src/lxc/lxc_process.c
+++ b/src/lxc/lxc_process.c
@@ -609,8 +609,13 @@ static void virLXCProcessMonitorExitNotify(virLXCMonitorPtr mon ATTRIBUTE_UNUSED
                                            virLXCProtocolExitStatus status,
                                            virDomainObjPtr vm)
 {
+    virLXCDriverPtr driver = lxc_driver;
     virLXCDomainObjPrivatePtr priv = vm->privateData;
 
+    lxcDriverLock(driver);
+    virObjectLock(vm);
+    lxcDriverUnlock(driver);
+
     switch (status) {
     case VIR_LXC_PROTOCOL_EXIT_STATUS_SHUTDOWN:
         priv->stopReason = VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN;
@@ -628,6 +633,8 @@ static void virLXCProcessMonitorExitNotify(virLXCMonitorPtr mon ATTRIBUTE_UNUSED
     }
     VIR_DEBUG("Domain shutoff reason %d (from status %d)",
               priv->stopReason, status);
+
+    virObjectUnlock(vm);
 }
 
 /* XXX a little evil */
@@ -636,12 +643,21 @@ static void virLXCProcessMonitorInitNotify(virLXCMonitorPtr mon ATTRIBUTE_UNUSED
                                            pid_t initpid,
                                            virDomainObjPtr vm)
 {
-    virLXCDomainObjPrivatePtr priv = vm->privateData;
+    virLXCDriverPtr driver = lxc_driver;
+    virLXCDomainObjPrivatePtr priv;
+
+    lxcDriverLock(driver);
+    virObjectLock(vm);
+    lxcDriverUnlock(driver);
+
+    priv = vm->privateData;
     priv->initpid = initpid;
     virDomainAuditInit(vm, initpid);
 
     if (virDomainSaveStatus(lxc_driver->caps, 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