ia64/xen-unstable

changeset 14171:0ba4f202d504

Add xm save -c/--checkpoint option

xm save --checkpoint leaves the domain running after creating the
snapshot.

Signed-off-by: Brendan Cully <brendan@cs.ubc.ca>
author kfraser@localhost.localdomain
date Wed Feb 28 09:39:23 2007 +0000 (2007-02-28)
parents 270a5e2ead43
children 9149ef0e61ce
files tools/python/xen/xend/XendCheckpoint.py tools/python/xen/xend/XendDomain.py tools/python/xen/xm/main.py
line diff
     1.1 --- a/tools/python/xen/xend/XendCheckpoint.py	Wed Feb 28 09:39:03 2007 +0000
     1.2 +++ b/tools/python/xen/xend/XendCheckpoint.py	Wed Feb 28 09:39:23 2007 +0000
     1.3 @@ -54,7 +54,7 @@ def read_exact(fd, size, errmsg):
     1.4      return buf
     1.5  
     1.6  
     1.7 -def save(fd, dominfo, network, live, dst):
     1.8 +def save(fd, dominfo, network, live, dst, checkpoint=False):
     1.9      write_exact(fd, SIGNATURE, "could not write guest state file: signature")
    1.10  
    1.11      config = sxp.to_string(dominfo.sxpr())
    1.12 @@ -121,9 +121,11 @@ def save(fd, dominfo, network, live, dst
    1.13              os.close(qemu_fd)
    1.14              os.remove("/tmp/xen.qemu-dm.%d" % dominfo.getDomid())
    1.15  
    1.16 -        dominfo.destroyDomain()
    1.17 -        dominfo.testDeviceComplete()
    1.18 -
    1.19 +        if checkpoint:
    1.20 +            dominfo.resumeDomain()
    1.21 +        else:
    1.22 +            dominfo.destroyDomain()
    1.23 +            dominfo.testDeviceComplete()
    1.24          try:
    1.25              dominfo.setName(domain_name)
    1.26          except VmError:
     2.1 --- a/tools/python/xen/xend/XendDomain.py	Wed Feb 28 09:39:03 2007 +0000
     2.2 +++ b/tools/python/xen/xend/XendDomain.py	Wed Feb 28 09:39:23 2007 +0000
     2.3 @@ -1172,7 +1172,7 @@ class XendDomain:
     2.4          XendCheckpoint.save(sock.fileno(), dominfo, True, live, dst)
     2.5          sock.close()
     2.6  
     2.7 -    def domain_save(self, domid, dst):
     2.8 +    def domain_save(self, domid, dst, checkpoint):
     2.9          """Start saving a domain to file.
    2.10  
    2.11          @param domid: Domain ID or Name
    2.12 @@ -1196,8 +1196,8 @@ class XendDomain:
    2.13                  oflags |= os.O_LARGEFILE
    2.14              fd = os.open(dst, oflags)
    2.15              try:
    2.16 -                # For now we don't support 'live checkpoint' 
    2.17 -                XendCheckpoint.save(fd, dominfo, False, False, dst)
    2.18 +                XendCheckpoint.save(fd, dominfo, False, False, dst,
    2.19 +                                    checkpoint=checkpoint)
    2.20              finally:
    2.21                  os.close(fd)
    2.22          except OSError, ex:
     3.1 --- a/tools/python/xen/xm/main.py	Wed Feb 28 09:39:03 2007 +0000
     3.2 +++ b/tools/python/xen/xm/main.py	Wed Feb 28 09:39:23 2007 +0000
     3.3 @@ -102,7 +102,7 @@ SUBCOMMAND_HELP = {
     3.4      'reboot'      : ('<Domain> [-wa]', 'Reboot a domain.'),
     3.5      'restore'     : ('<CheckpointFile> [-p]',
     3.6                       'Restore a domain from a saved state.'),
     3.7 -    'save'        : ('<Domain> <CheckpointFile>',
     3.8 +    'save'        : ('[-c] <Domain> <CheckpointFile>',
     3.9                       'Save a domain state to restore later.'),
    3.10      'shutdown'    : ('<Domain> [-waRH]', 'Shutdown a domain.'),
    3.11      'top'         : ('', 'Monitor a host and the domains in real time.'),
    3.12 @@ -232,6 +232,9 @@ SUBCOMMAND_OPTIONS = {
    3.13      'resume': (
    3.14        ('-p', '--paused', 'Do not unpause domain after resuming it'),
    3.15      ),
    3.16 +    'save': (
    3.17 +      ('-c', '--checkpoint', 'Leave domain running after creating snapshot'),
    3.18 +    ),
    3.19     'restore': (
    3.20        ('-p', '--paused', 'Do not unpause domain after restoring it'),
    3.21      ),
    3.22 @@ -604,21 +607,37 @@ def xm_shell(args):
    3.23  #########################################################################
    3.24  
    3.25  def xm_save(args):
    3.26 -    arg_check(args, "save", 2)
    3.27 +    arg_check(args, "save", 2, 3)
    3.28  
    3.29      try:
    3.30 -        dominfo = parse_doms_info(server.xend.domain(args[0]))
    3.31 +        (options, params) = getopt.gnu_getopt(args, 'c', ['checkpoint'])
    3.32 +    except getopt.GetoptError, opterr:
    3.33 +        err(opterr)
    3.34 +        sys.exit(1)
    3.35 +
    3.36 +    checkpoint = False
    3.37 +    for (k, v) in options:
    3.38 +        if k in ['-c', '--checkpoint']:
    3.39 +            checkpoint = True
    3.40 +
    3.41 +    if len(params) != 2:
    3.42 +        err("Wrong number of parameters")
    3.43 +        usage('save')
    3.44 +        sys.exit(1)
    3.45 +
    3.46 +    try:
    3.47 +        dominfo = parse_doms_info(server.xend.domain(params[0]))
    3.48      except xmlrpclib.Fault, ex:
    3.49          raise ex
    3.50      
    3.51      domid = dominfo['domid']
    3.52 -    savefile = os.path.abspath(args[1])
    3.53 +    savefile = os.path.abspath(params[1])
    3.54  
    3.55      if not os.access(os.path.dirname(savefile), os.W_OK):
    3.56          err("xm save: Unable to create file %s" % savefile)
    3.57          sys.exit(1)
    3.58      
    3.59 -    server.xend.domain.save(domid, savefile)
    3.60 +    server.xend.domain.save(domid, savefile, checkpoint)
    3.61      
    3.62  def xm_restore(args):
    3.63      arg_check(args, "restore", 1, 2)