Skip to contentSkip to conversation

Lifecycle Patches 7/7

RFC New Ewan Mellor 1 participant 1 message Jul 14, 2006

lore
Share & tools
lore
#0 lore raw

RFC 1/1 Lifecycle Patches 7/7

Xend lifecycle xm suspend / xm resume functionality.

 xend/XendCheckpoint.py |    9 +++--
 xend/XendDomain.py     |   88 +++++++++++++++++++++++++++++++++++++++++--------
 xend/XendDomainInfo.py |   69 +++++++++++++++++++++++++++-----------
 xm/main.py             |   26 ++++++++++++--
 4 files changed, 153 insertions(+), 39 deletions(-)
tools/python/xen/xend/XendDomain.py +74 -14
Index: xen/tools/python/xen/xend/XendDomain.py
===================================================================
@@ -150,18 +150,12 @@
     def persistent_check_point_path(self, domname):
         dom_path = xroot.get_xend_domains_path()
         path = os.path.join(dom_path, domname, CHECK_POINT_FILE)
-        if os.path.exists(path):
-            return path
-        else:
-            return None        
+        return path
 
     def persistent_config_path(self, domname):
         dom_path = xroot.get_xend_domains_path()
         path = os.path.join(dom_path, domname, CACHED_CONFIG_FILE)
-        if os.path.exists(path):
-            return path
-        else:
-            return None
+        return path
 
     def persistent_config_delete(self, domname):
         try:
@@ -258,7 +252,7 @@
             domname = info.getName()
             
             cached_config = self.persistent_config_path(domname)
-            if cached_config:
+            if os.path.exists(cached_config):
                 self.persistent_config_delete(domname)
             del self.domains[domname]
 
@@ -381,11 +375,16 @@
         """
         self.domains_lock.acquire()
         try:
-            xeninfo = XendDomainInfo.parseConfig(config)
-            dominfo = XendDomainInfo.createDormant(xeninfo)
-            self._add_domain(dominfo)
-            self.persistent_config_save(dominfo)
-            # no return value because it isn't meaningful for client
+            try:
+                xeninfo = XendDomainInfo.parseConfig(config)
+                dominfo = XendDomainInfo.createDormant(xeninfo)
+                self._add_domain(dominfo)
+                self.persistent_config_save(dominfo)
+                # no return value because it isn't meaningful for client
+            except XendError, e:
+                raise e
+            except Exception, e:
+                raise XendError(str(e))
         finally:
             self.domains_lock.release()
 
@@ -471,6 +470,67 @@
         finally:
             self.domains_lock.release()
 
+    def domain_suspend(self, domname):
+        """
+        Suspends a domain that is persistently managed by Xend
+
+        @param domname: Domain Name
+        """
+
+        try:
+            dominfo = self.domain_lookup_by_name_nr(domname)
+            if not dominfo:
+                raise XendInvalidDomain(domname)
+
+            if dominfo.getDomid() == PRIV_DOMAIN:
+                raise XendError("Cannot save privileged domain %s" % domname)
+
+            if dominfo.state != XendDomainInfo.DOM_STATE_RUNNING:
+                raise XendError("Cannot suspend domain that is not running.")
+
+            if not os.path.exists(self.persistent_config_path(domname)):
+                raise XendError("Domain is not managed by Xend lifecycle " +
+                                "support.")
+            
+            path = self.persistent_check_point_path(domname)
+            fd = os.open(path, os.O_WRONLY | os.O_CREAT | os.O_TRUNC)
+            try:
+                # For now we don't support 'live checkpoint' 
+                return XendCheckpoint.save(fd, dominfo, False, False, path)
+            finally:
+                os.close(fd)
+        except OSError, ex:
+            raise XendError("can't write guest state file %s: %s" %
+                            (path, ex[1]))
+
+    def domain_resume(self, domname):
+        try:
+            dominfo = self.domain_lookup_by_name_nr(domname)
+            
+            if not dominfo:
+                raise XendInvalidDomain(domname)
+
+            if dominfo.getDomid() == PRIV_DOMAIN:
+                raise XendError("Cannot save privileged domain %s" % domname)
+
+            if dominfo.state != XendDomainInfo.DOM_STATE_HALTED:
+                raise XendError("Cannot suspend domain that is not running.")
+
+            chkpath = self.persistent_check_point_path(domname)
+            if not os.path.exists(chkpath):
+                raise XendError("Domain was not suspended by Xend")
+
+            # Restore that replaces the existing XendDomainInfo
+            try:
+                log.debug('Current DomainInfo state: %d' % dominfo.state)
+                XendCheckpoint.restore(self,
+                                       os.open(chkpath, os.O_RDONLY),
+                                       dominfo)
+            except OSError, ex:
+                raise XendError("Failed to read stored checkpoint file")
+        except Exception, ex:
+            log.exception("Exception occurred when resuming")
+            raise XendError("Error occurred when resuming: %s" % str(ex))
 
     def domain_lookup(self, domid):
         self.domains_lock.acquire()
tools/python/xen/xm/main.py +23 -3
Index: xen/tools/python/xen/xm/main.py
===================================================================
@@ -56,9 +56,7 @@
 create_help =  """create [-c] <ConfigFile>
           [Name=Value]..            Create and start a domain based on
                                     ConfigFile"""
-new_help =     """new [-c] <ConfigFile>
-          [Name=Value]..            Create a domain based on ConfigFile"""
-delete_help =  """delete <DomName>      Remove a persistent domain"""
+delete_help =  "delete <DomName>                 Remove a persistent domain"
 destroy_help = "destroy <DomId>                  Terminate a domain immediately"
 help_help =    "help                             Display this message"
 list_help =    "list [--long] [DomId, ...]       List information about domains"
@@ -67,12 +65,16 @@
 mem_max_help = "mem-max <DomId> <Mem>            Set maximum memory reservation for a domain"
 mem_set_help = "mem-set <DomId> <Mem>            Adjust the current memory usage for a domain"
 migrate_help = "migrate <DomId> <Host>           Migrate a domain to another machine"
+new_help =     """new [-c] <ConfigFile>
+          [Name=Value]..            Create a domain based on ConfigFile"""
 pause_help =   "pause <DomId>                    Pause execution of a domain"
 reboot_help =  "reboot <DomId> [-w][-a]          Reboot a domain"
 restore_help = "restore <File>                   Create a domain from a saved state file"
+resume_help =  "resume <DomName>                 Resume a suspended domain"
 save_help =    "save <DomId> <File>              Save domain state (and config) to file"
 shutdown_help ="shutdown <DomId> [-w][-a][-R|-H] Shutdown a domain"
 start_help    ="start <DomId>                    Start a halted domain."
+suspend_help = "suspend <DomName>                Suspend a domain."
 top_help =     "top                              Monitor system and domains in real-time"
 unpause_help = "unpause <DomId>                  Unpause a paused domain"
 
@@ -150,9 +152,11 @@
     "pause",
     "reboot",
     "restore",
+    "resume",
     "save",
     "shutdown",
     "start",
+    "suspend",
     "top",
     "unpause",
     "vcpu-set",
@@ -175,9 +179,11 @@
     "reboot",
     "rename",
     "restore",
+    "resume",
     "save",
     "shutdown",
     "start",
+    "suspend",
     "sysrq",
     "top",
     "unpause",
@@ -583,6 +589,16 @@
     arg_check(args, "delete", 1)
     dom = args[0]
     server.xend.domain.delete(dom)
+
+def xm_suspend(args):
+    arg_check(args, "suspend", 1)
+    dom = args[0]
+    server.xend.domain.suspend(dom)
+
+def xm_resume(args):
+    arg_check(args, "resume", 1)
+    dom = args[0]
+    server.xend.domain.resume(dom)
     
 def xm_reboot(args):
     arg_check(args, "reboot", 1, 3)
@@ -829,6 +845,8 @@
     dom = args[0]
     info = server.xend.domain(dom)
     domid = int(sxp.child_value(info, 'domid', '-1'))
+    if domid == -1:
+        raise Exception("Domain is not started")
     console.execConsole(domid)
 
 
@@ -1129,7 +1147,9 @@
     "domname": xm_domname,
     "rename": xm_rename,
     "restore": xm_restore,
+    "resume": xm_resume,
     "save": xm_save,
+    "suspend": xm_suspend,
     "reboot": xm_reboot,
     "list": xm_list,
     # memory commands
tools/python/xen/xend/XendDomainInfo.py +49 -20

132 lines not on this page · raw message

tools/python/xen/xend/XendCheckpoint.py +7 -2
Index: xen/tools/python/xen/xend/XendCheckpoint.py
===================================================================
@@ -23,6 +23,7 @@
 from XendLogging import log
 from XendDomainInfo import DEV_MIGRATE_STEP1, DEV_MIGRATE_STEP2
 from XendDomainInfo import DEV_MIGRATE_STEP3
+from XendDomainInfo import parseConfig
 
 SIGNATURE = "LinuxGuestRecord"
 XC_SAVE = "xc_save"
@@ -111,7 +112,7 @@
         raise Exception, exn
 
 
-def restore(xd, fd):
+def restore(xd, fd, dominfo = None):
     signature = read_exact(fd, len(SIGNATURE),
         "not a valid guest state file: signature read")
     if signature != SIGNATURE:
@@ -131,7 +132,11 @@
 
     vmconfig = p.get_val()
 
-    dominfo = xd.restore_(vmconfig)
+    if dominfo:
+        dominfo.update(parseConfig(vmconfig), refresh = False)
+        dominfo.resume()
+    else:
+        dominfo = xd.restore_(vmconfig)
 
     store_port   = dominfo.getStorePort()
     console_port = dominfo.getConsolePort()

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