Subversion Repositories xen

Rev

Rev 1 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

--- /root/xen_lock_patch/XendDomainInfo.py      2011-03-14 11:03:21.000000000 +0100
+++ /usr/lib/xen-4.1/lib/python/xen/xend/XendDomainInfo.py      2011-03-14 15:50:52.000000000 +0100
@@ -365,6 +365,8 @@
     @type state_updated: threading.Condition
     @ivar refresh_shutdown_lock: lock for polling shutdown state
     @type refresh_shutdown_lock: threading.Condition
+    @ivar running_lock: lock for running VM
+    @type running_lock: bool or None
     @ivar _deviceControllers: device controller cache for this domain
     @type _deviceControllers: dict 'string' to DevControllers
     """
@@ -444,6 +446,8 @@
         self.refresh_shutdown_lock = threading.Condition()
         self._stateSet(DOM_STATE_HALTED)
 
+        self.running_lock = None
+
         self._deviceControllers = {}
 
         for state in DOM_STATES_OLD:
@@ -470,6 +474,7 @@
 
         if self._stateGet() in (XEN_API_VM_POWER_STATE_HALTED, XEN_API_VM_POWER_STATE_SUSPENDED, XEN_API_VM_POWER_STATE_CRASHED):
             try:
+                self.acquire_running_lock();
                 XendTask.log_progress(0, 30, self._constructDomain)
                 XendTask.log_progress(31, 60, self._initDomain)
                 
@@ -496,6 +501,7 @@
         state = self._stateGet()
         if state in (DOM_STATE_SUSPENDED, DOM_STATE_HALTED):
             try:
+                self.acquire_running_lock();
                 self._constructDomain()
 
                 try:
@@ -2950,6 +2956,11 @@
 
             self._stateSet(DOM_STATE_HALTED)
             self.domid = None  # Do not push into _stateSet()!
+
+            try:
+                self.release_running_lock()
+            except:
+                log.exception("Release running lock failed: %s" % status)
         finally:
             self.refresh_shutdown_lock.release()
 
@@ -4438,6 +4449,32 @@
     def has_device(self, dev_class, dev_uuid):
         return (dev_uuid in self.info['%s_refs' % dev_class.lower()])
 
+    def acquire_running_lock(self):   
+        if not self.running_lock:
+            lock_path = xoptions.get_xend_domains_lock_path()
+           if lock_path:
+               doms_lock_path = xoptions.get_xend_domains_path()
+               if doms_lock_path:
+                       status = os.system('%s --lock --name %s --uuid %s --path %s' % \
+                                          (lock_path, self.info['name_label'], self.info['uuid'], doms_lock_path))
+                       if status == 0:
+                           self.running_lock = True
+                       else:
+                           raise XendError('Acquire running lock failed: %s' % status)
+
+    def release_running_lock(self):
+        if self.running_lock:
+            lock_path = xoptions.get_xend_domains_lock_path()
+            if lock_path:
+               doms_lock_path = xoptions.get_xend_domains_path()
+               if doms_lock_path:
+                       status = os.system('%s --unlock --name %s --uuid %s --path %s' % \
+                                          (lock_path, self.info['name_label'], self.info['uuid'], doms_lock_path))
+                       if status == 0:
+                           self.running_lock = False
+                       else:
+                           raise XendError('Release running lock failed: %s' % status)
+
     def __str__(self):
         return '<domain id=%s name=%s memory=%s state=%s>' % \
                (str(self.domid), self.info['name_label'],
--- /root/xen_lock_patch/XendDomain.py  2011-03-14 11:04:13.000000000 +0100
+++ /usr/lib/xen-4.1/lib/python/xen/xend/XendDomain.py  2011-03-14 11:26:44.000000000 +0100
@@ -1368,6 +1368,7 @@
             raise XendError("Domain is not a managed domain")
 
         """ The following call may raise a XendError exception """
+        dominfo.release_running_lock();
         dominfo.testMigrateDevices(True, dst)
 
         if live:
--- /root/xen_lock_patch/XendOptions.py 2011-03-14 11:02:52.000000000 +0100
+++ /usr/lib/xen-4.1/lib/python/xen/xend/XendOptions.py 2011-03-14 11:27:33.000000000 +0100
@@ -321,6 +321,11 @@
         """
         return self.get_config_string("xend-domains-path", self.xend_domains_path_default)
 
+    def get_xend_domains_lock_path(self):
+        """ Get the path of the lock utility for running domains.
+        """
+        return self.get_config_string("xend-domains-lock-path")
+
     def get_xend_state_path(self):
         """ Get the path for persistent domain configuration storage
         """