Skip to contentSkip to conversation

Grab common lock during domain restore op and security op

PATCH In review Stefan Berger 2 participants 3 messages Mar 10, 2008 – Mar 11, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Grab common lock during domain restore op and security op

I am introducing a lock in the path of the domain restore operation. This lock is acquired when a domain is restored or migrated into a system. The lock is also acquired during policy operation, i.e., setting of a domain's label, which prevents changes to the policy during restore operations.

---
 xen-unstable.hg/tools/python/xen/xend/XendDomain.py     |   27 ++--
 xen-unstable.hg/tools/python/xen/xend/XendDomainInfo.py |  103 ++++++++--------
 2 files changed, 71 insertions(+), 59 deletions(-)
xen-unstable.hg/tools/python/xen/xend/XendDomain.py +17 -10
Index: root/xen-unstable.hg/tools/python/xen/xend/XendDomain.py
===================================================================
@@ -93,6 +93,8 @@ class XendDomain:
         self.managed_domains = {}
         self.domains_lock = threading.RLock()
 
+        self.restore_lock = threading.RLock()
+
         # xen api instance vars
         # TODO: nothing uses this at the moment
         self._allow_new_domains = True
@@ -1133,16 +1135,21 @@ class XendDomain:
         """
 
         try:
-            return XendCheckpoint.restore(self, fd, paused=paused, relocating=relocating)
-        except XendError, e:
-            log.exception("Restore failed")
-            raise
-        except:
-            # I don't really want to log this exception here, but the error
-            # handling in the relocation-socket handling code (relocate.py) is
-            # poor, so we need to log this for debugging.
-            log.exception("Restore failed")
-            raise XendError("Restore failed")
+            self.restore_lock.acquire()
+
+            try:
+                return XendCheckpoint.restore(self, fd, paused=paused, relocating=relocating)
+            except XendError, e:
+                log.exception("Restore failed")
+                raise
+            except:
+                # I don't really want to log this exception here, but the error
+                # handling in the relocation-socket handling code (relocate.py) is
+                # poor, so we need to log this for debugging.
+                log.exception("Restore failed")
+                raise XendError("Restore failed")
+        finally:
+            self.restore_lock.release()
  
     def domain_unpause(self, domid):
         """Unpause domain execution.
xen-unstable.hg/tools/python/xen/xend/XendDomainInfo.py +54 -49

118 lines not on this page · raw message

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw

It seems odd to me that of all update operations that can be performed on a domain by xend, only label-setting needs explicit serialisation against domain restore. What's the underlying problem that this is solving?

-- Keir

Quoted 12 lines · Stefan Berger

I am introducing a lock in the path of the domain restore operation. This lock is acquired when a domain is restored or migrated into a system. The lock is also acquired during policy operation, i.e., setting of a domain's label, which prevents changes to the policy during restore operations.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#2 lore raw

[email protected] wrote on 03/10/2008 06:06:38 PM:

Quoted 1 line

It seems odd to me that of all update operations that can be performed

on a

Quoted 2 lines

domain by xend, only label-setting needs explicit serialisation against domain restore. What's the underlying problem that this is solving?

If it's not serialized, one could otherwise change the policy while a migration is happening. In the worst case this would lead to the new VM running on a system that it otherwise would not be allowed to run (due to the modified policy). I would have grabbed the domains_lock lock otherwise, but then I found this here in the XendCheckpoint.restore() method which is called with the domains_lock() held:

#
# We shouldn't hold the domains_lock over a waitForDevices # As this function sometime gets called holding this lock, # we must release it and re-acquire it appropriately #
from xen.xend import XendDomain

lock = True;
try:
XendDomain.instance().domains_lock.release()
except:
lock = False;

try:
dominfo.waitForDevices() # Wait for backends to set up
except Exception, exn:
log.exception(exn)

if lock:
XendDomain.instance().domains_lock.acquire()

To me it looks like introducing another lock is necessary.

Stefan

Quoted 8 lines

-- Keir

Quoted 3 lines · Stefan Berger

I am introducing a lock in the path of the domain restore operation. This lock is acquired when a domain is restored or migrated into a system. The lock is also acquired during policy operation, i.e.,

setting

Quoted 1 line
Quoted 1 line

of a domain's label, which prevents changes to the policy during

restore

Quoted 11 lines
Quoted 8 lines

operations.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

Quoted 4 lines

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel