ia64/xen-unstable

changeset 5304:6946d70596e8

bitkeeper revision 1.1662.1.1 (42a07145CPNIh8TprNz04Qg7x-S7Cw)

xend cleanups from Mike Wray.
XendDomain.py:
Add comment for domain_mem_target_set.
SrvDaemon.py:
Use XEND_DAEMONIZE, XEND_DEBUG and XEND_DEBUGLOG.
XendRoot.py:
Use XEND_DEBUG.
netif.py:
Unknown domains are called "Domain-%d" % dom.
params.py:
Add additional parameters and set some parameters from
environment variables.
blkif.py, XendDomain.py:
Cleanup whitespace.
XendRoot.py:
enable_dump default is 'no'.
enable_dump is a bool.
Add 'true' and 'false' to get_config_bool.
XendDomainInfo.py:
Add DOMAIN_CRASH shutdown code.
XendDomain.py:
Simplify.
Add domain_dumpcore.
Move class XendDomainDict outside of class XendDomain.
Import shutdown_reason from XendDomainInfo.
Update comment for xen_domain.
PrettyPrint.py:
Cleanup prettyprintstring.
SrvDir.py:
Cleanup render_GET.
xc.c:
Various cleanups.
Signed-off-by: Mike Wray <mike.wray@hp.com>
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk
date Fri Jun 03 15:03:33 2005 +0000 (2005-06-03)
parents 6b7a4f646fef
children 9672db054b6d
files tools/python/xen/lowlevel/xc/xc.c tools/python/xen/web/SrvDir.py tools/python/xen/xend/PrettyPrint.py tools/python/xen/xend/XendDomain.py tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/XendRoot.py tools/python/xen/xend/server/SrvDaemon.py tools/python/xen/xend/server/blkif.py tools/python/xen/xend/server/netif.py tools/python/xen/xend/server/params.py
line diff
     1.1 --- a/tools/python/xen/lowlevel/xc/xc.c	Fri Jun 03 13:14:54 2005 +0000
     1.2 +++ b/tools/python/xen/lowlevel/xc/xc.c	Fri Jun 03 15:03:33 2005 +0000
     1.3 @@ -14,6 +14,7 @@
     1.4  #include <sys/socket.h>
     1.5  #include <netdb.h>
     1.6  #include <arpa/inet.h>
     1.7 +
     1.8  #include "xc_private.h"
     1.9  #include "linux_boot_params.h"
    1.10  
    1.11 @@ -842,8 +843,8 @@ static PyMethodDef pyxc_methods[] = {
    1.12      { "domain_dumpcore", 
    1.13        (PyCFunction)pyxc_domain_dumpcore, 
    1.14        METH_VARARGS | METH_KEYWORDS, "\n"
    1.15 -      "dump core of a domain.\n"
    1.16 -      " dom [int]: Identifier of domain to be paused.\n\n"
    1.17 +      "Dump core of a domain.\n"
    1.18 +      " dom [int]: Identifier of domain to dump core of.\n\n"
    1.19        " corefile [string]: Name of corefile to be created.\n\n"
    1.20        "Returns: [int] 0 on success; -1 on error.\n" },
    1.21  
     2.1 --- a/tools/python/xen/web/SrvDir.py	Fri Jun 03 13:14:54 2005 +0000
     2.2 +++ b/tools/python/xen/web/SrvDir.py	Fri Jun 03 15:03:33 2005 +0000
     2.3 @@ -77,19 +77,16 @@ class SrvDir(SrvBase):
     2.4          return v
     2.5  
     2.6      def render_GET(self, req):
     2.7 -        try:
     2.8 -            if self.use_sxp(req):
     2.9 -                req.setHeader("Content-type", sxp.mime_type)
    2.10 -                self.ls(req, 1)
    2.11 -            else:
    2.12 -                req.write('<html><head></head><body>')
    2.13 -                self.print_path(req)
    2.14 -                self.ls(req)
    2.15 -                self.form(req)
    2.16 -                req.write('</body></html>')
    2.17 -            return ''
    2.18 -        except Exception, ex:
    2.19 -            self._perform_err(ex, "GET", req)
    2.20 +        if self.use_sxp(req):
    2.21 +            req.setHeader("Content-type", sxp.mime_type)
    2.22 +            self.ls(req, 1)
    2.23 +        else:
    2.24 +            req.write('<html><head></head><body>')
    2.25 +            self.print_path(req)
    2.26 +            self.ls(req)
    2.27 +            self.form(req)
    2.28 +            req.write('</body></html>')
    2.29 +        return ''
    2.30              
    2.31      def ls(self, req, use_sxp=0):
    2.32          url = req.prePathURL()
     3.1 --- a/tools/python/xen/xend/PrettyPrint.py	Fri Jun 03 13:14:54 2005 +0000
     3.2 +++ b/tools/python/xen/xend/PrettyPrint.py	Fri Jun 03 15:03:33 2005 +0000
     3.3 @@ -285,15 +285,18 @@ def prettyprint(sxpr, out=sys.stdout, wi
     3.4          sxp.show(sxpr, out=out)
     3.5      print >> out
     3.6  
     3.7 -def prettyprintstring(sxp):
     3.8 -    class tmpstr:
     3.9 -        def __init__(self):
    3.10 -            self.str = ""
    3.11 -        def write(self, str):
    3.12 -            self.str = self.str + str
    3.13 -    tmp = tmpstr()
    3.14 -    prettyprint(sxp, out=tmp)
    3.15 -    return tmp.str
    3.16 +def prettyprintstring(sxp, width=80):
    3.17 +    """Prettyprint an SXP form to a string.
    3.18 +
    3.19 +    sxpr	s-expression
    3.20 +    width	maximum output width
    3.21 +    """
    3.22 +    io = StringIO.StringIO()
    3.23 +    prettyprint(sxpr, out=io, width=width)
    3.24 +    io.seek(0)
    3.25 +    val = io.getvalue()
    3.26 +    io.close()
    3.27 +    return val
    3.28  
    3.29  def main():
    3.30      pin = sxp.Parser()
     4.1 --- a/tools/python/xen/xend/XendDomain.py	Fri Jun 03 13:14:54 2005 +0000
     4.2 +++ b/tools/python/xen/xend/XendDomain.py	Fri Jun 03 15:03:33 2005 +0000
     4.3 @@ -20,7 +20,7 @@ import sxp
     4.4  import XendRoot; xroot = XendRoot.instance()
     4.5  import XendCheckpoint
     4.6  import XendDB
     4.7 -import XendDomainInfo
     4.8 +from xen.xend.XendDomainInfo import XendDomainInfo, shutdown_reason
     4.9  import EventServer; eserver = EventServer.instance()
    4.10  from XendError import XendError
    4.11  from XendLogging import log
    4.12 @@ -31,6 +31,13 @@ from xen.xend.server import channel
    4.13  
    4.14  SHUTDOWN_TIMEOUT = 30
    4.15  
    4.16 +class XendDomainDict(dict):
    4.17 +    def get_by_name(self, name):
    4.18 +        try:
    4.19 +            return filter(lambda d: d.name == name, self.values())[0]
    4.20 +        except IndexError, err:
    4.21 +            return None
    4.22 +
    4.23  class XendDomain:
    4.24      """Index of all domains. Singleton.
    4.25      """
    4.26 @@ -38,15 +45,8 @@ class XendDomain:
    4.27      """Path to domain database."""
    4.28      dbpath = "domain"
    4.29  
    4.30 -    class XendDomainDict(dict):
    4.31 -        def get_by_name(self, name):
    4.32 -            try:
    4.33 -                return filter(lambda d: d.name == name, self.values())[0]
    4.34 -            except IndexError, err:
    4.35 -                return None
    4.36 -
    4.37      """Dict of domain info indexed by domain id."""
    4.38 -    domains = XendDomainDict()
    4.39 +    domains = None
    4.40      
    4.41      def __init__(self):
    4.42          # Hack alert. Python does not support mutual imports, but XendDomainInfo
    4.43 @@ -54,6 +54,7 @@ class XendDomain:
    4.44          # to import XendDomain from XendDomainInfo causes unbounded recursion.
    4.45          # So we stuff the XendDomain instance (self) into xroot's components.
    4.46          xroot.add_component("xen.xend.XendDomain", self)
    4.47 +        self.domains = XendDomainDict()
    4.48          # Table of domain info indexed by domain id.
    4.49          self.db = XendDB.XendDB(self.dbpath)
    4.50          eserver.subscribe('xend.virq', self.onVirq)
    4.51 @@ -84,6 +85,8 @@ class XendDomain:
    4.52      def xen_domain(self, dom):
    4.53          """Get info about a single domain from xc.
    4.54          Returns None if not found.
    4.55 +
    4.56 +        @param dom domain id
    4.57          """
    4.58          try:
    4.59              dom = int(dom)
    4.60 @@ -189,7 +192,7 @@ class XendDomain:
    4.61                  continue
    4.62              log.debug('XendDomain>reap> domain died name=%s id=%s', name, id)
    4.63              if d['shutdown']:
    4.64 -                reason = XendDomainInfo.shutdown_reason(d['shutdown_reason'])
    4.65 +                reason = shutdown_reason(d['shutdown_reason'])
    4.66                  log.debug('XendDomain>reap> shutdown name=%s id=%s reason=%s', name, id, reason)
    4.67                  if reason in ['suspend']:
    4.68                      if dominfo and dominfo.is_terminated():
    4.69 @@ -203,8 +206,8 @@ class XendDomain:
    4.70                      eserver.inject('xend.domain.exit', [name, id, reason])
    4.71                      self.domain_restart_schedule(id, reason)
    4.72              else:
    4.73 -               if xroot.get_enable_dump() == 'true':
    4.74 -                   xc.domain_dumpcore(dom = int(id), corefile = "/var/xen/dump/%s.%s.core"%(name,id))
    4.75 +               if xroot.get_enable_dump():
    4.76 +                   self.domain_dumpcore(int(id))
    4.77                 eserver.inject('xend.domain.exit', [name, id, 'crash']) 
    4.78              destroyed += 1
    4.79              self.final_domain_destroy(id)
    4.80 @@ -216,7 +219,7 @@ class XendDomain:
    4.81              self.reap()
    4.82          doms = self.xen_domains()
    4.83          # Add entries for any domains we don't know about.
    4.84 -        for (id, d) in doms.items():
    4.85 +        for id in doms.keys():
    4.86              if id not in self.domains:
    4.87                  self.domain_lookup(id)
    4.88          # Remove entries for domains that no longer exist.
    4.89 @@ -326,9 +329,7 @@ class XendDomain:
    4.90  
    4.91          try:
    4.92              fd = os.open(src, os.O_RDONLY)
    4.93 -
    4.94              return XendCheckpoint.restore(self, fd)
    4.95 -
    4.96          except OSError, ex:
    4.97              raise XendError("can't read guest state file %s: %s" %
    4.98                              (src, ex[1]))
    4.99 @@ -343,20 +344,19 @@ class XendDomain:
   4.100          self.refresh_domain(id)
   4.101          return self.domains.get(id)
   4.102  
   4.103 -    def domain_lookup(self, name):
   4.104 -        name = str(name)
   4.105 -        dominfo = self.domains.get_by_name(name) or self.domains.get(name)
   4.106 -        if dominfo:
   4.107 -            return dominfo
   4.108 -        try:
   4.109 -            d = self.xen_domain(name)
   4.110 -            if d:
   4.111 -                log.info("Creating entry for unknown domain: id=%s", name)
   4.112 -                dominfo = XendDomainInfo.vm_recreate(None, d)
   4.113 -                self._add_domain(dominfo)
   4.114 -                return dominfo
   4.115 -        except Exception, ex:
   4.116 -            log.exception("Error creating domain info: id=%s", name)
   4.117 +    def domain_lookup(self, id):
   4.118 +        name = str(id)
   4.119 +        dominfo = self.domains.get_by_name(name) or self.domains.get(id)
   4.120 +        if not dominfo:
   4.121 +            try:
   4.122 +                info = self.xen_domain(id)
   4.123 +                if info:
   4.124 +                    log.info("Creating entry for unknown domain: id=%s", name)
   4.125 +                    dominfo = XendDomainInfo.vm_recreate(None, info)
   4.126 +                    self._add_domain(dominfo)
   4.127 +            except Exception, ex:
   4.128 +                log.exception("Error creating domain info: id=%s", name)
   4.129 +        return dominfo
   4.130  
   4.131      def domain_unpause(self, id):
   4.132          """Unpause domain execution.
   4.133 @@ -595,6 +595,7 @@ class XendDomain:
   4.134              return xc.sedf_domain_get(dominfo.dom)
   4.135          except Exception, ex:
   4.136              raise XendError(str(ex))
   4.137 +
   4.138      def domain_device_create(self, id, devconfig):
   4.139          """Create a new device for a domain.
   4.140  
   4.141 @@ -700,11 +701,28 @@ class XendDomain:
   4.142              raise XendError(str(ex))
   4.143  
   4.144      def domain_mem_target_set(self, id, target):
   4.145 +        """Set the memory target for a domain.
   4.146 +
   4.147 +        @param id: domain
   4.148 +        @param target: memory target (in MB)
   4.149 +        @return: 0 on success, -1 on error
   4.150 +        """
   4.151          dominfo = self.domain_lookup(id)
   4.152          return dominfo.mem_target_set(target)
   4.153 -        
   4.154 +
   4.155 +    def domain_dumpcore(self, id):
   4.156 +        """Save a core dump for a crashed domain.
   4.157  
   4.158 -
   4.159 +        @param id: domain
   4.160 +        """
   4.161 +        dominfo = self.domain_lookup(id)
   4.162 +        corefile = "/var/xen/dump/%s.%s.core"% (dominfo.name, dominfo.id)
   4.163 +        try:
   4.164 +            xc.domain_dumpcore(dom=dominfo.id, corefile=corefile)
   4.165 +        except Exception, ex:
   4.166 +            log.warning("Dumpcore failed, id=%s name=%s: %s",
   4.167 +                        dominfo.id, dominfo.name, ex)
   4.168 +        
   4.169  def instance():
   4.170      """Singleton constructor. Use this instead of the class constructor.
   4.171      """
     5.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Fri Jun 03 13:14:54 2005 +0000
     5.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Fri Jun 03 15:03:33 2005 +0000
     5.3 @@ -45,11 +45,16 @@ DOMAIN_REBOOT   = 1
     5.4  """Shutdown code for suspend."""
     5.5  DOMAIN_SUSPEND  = 2
     5.6  
     5.7 +"""Shutdown code for crash."""
     5.8 +DOMAIN_CRASH    = 3
     5.9 +
    5.10  """Map shutdown codes to strings."""
    5.11  shutdown_reasons = {
    5.12      DOMAIN_POWEROFF: "poweroff",
    5.13      DOMAIN_REBOOT  : "reboot",
    5.14 -    DOMAIN_SUSPEND : "suspend" }
    5.15 +    DOMAIN_SUSPEND : "suspend",
    5.16 +    DOMAIN_CRASH   : "crash",
    5.17 +    }
    5.18  
    5.19  """Map shutdown reasons to the message type to use.
    5.20  """
     6.1 --- a/tools/python/xen/xend/XendRoot.py	Fri Jun 03 13:14:54 2005 +0000
     6.2 +++ b/tools/python/xen/xend/XendRoot.py	Fri Jun 03 15:03:33 2005 +0000
     6.3 @@ -177,7 +177,10 @@ class XendRoot:
     6.4          logfile = self.get_config_value("logfile", self.logfile_default)
     6.5          loglevel = self.get_config_value("loglevel", self.loglevel_default)
     6.6          self.logging = XendLogging(logfile, level=loglevel)
     6.7 -        #self.logging.addLogStderr()
     6.8 +
     6.9 +        from xen.xend.server import params
    6.10 +        if params.XEND_DEBUG:
    6.11 +            self.logging.addLogStderr()
    6.12  
    6.13      def get_logging(self):
    6.14          """Get the XendLogging instance.
    6.15 @@ -241,9 +244,9 @@ class XendRoot:
    6.16  
    6.17      def get_config_bool(self, name, val=None):
    6.18          v = self.get_config_value(name, val)
    6.19 -        if v in ['yes', '1', 'on', 1, True]:
    6.20 +        if v in ['yes', '1', 'on', 'true', 1, True]:
    6.21              return True
    6.22 -        if v in ['no', '0', 'off', 0, False]:
    6.23 +        if v in ['no', '0', 'off', 'false', 0, False]:
    6.24              return False
    6.25          raise XendError("invalid xend config %s: expected bool: %s" % (name, v))
    6.26  
    6.27 @@ -325,7 +328,7 @@ class XendRoot:
    6.28          return self.get_config_value('network-script', 'network')
    6.29  
    6.30      def get_enable_dump(self):
    6.31 -        return self.get_config_value('enable-dump', 'false')
    6.32 +        return self.get_config_bool('enable-dump', 'no')
    6.33  
    6.34      def get_vif_bridge(self):
    6.35          return self.get_config_value('vif-bridge', 'xen-br0')
     7.1 --- a/tools/python/xen/xend/server/SrvDaemon.py	Fri Jun 03 13:14:54 2005 +0000
     7.2 +++ b/tools/python/xen/xend/server/SrvDaemon.py	Fri Jun 03 15:03:33 2005 +0000
     7.3 @@ -167,7 +167,7 @@ class Daemon:
     7.4          return pid
     7.5  
     7.6      def daemonize(self):
     7.7 -        if not DAEMONIZE: return
     7.8 +        if not XEND_DAEMONIZE: return
     7.9          # Detach from TTY.
    7.10          os.setsid()
    7.11  
    7.12 @@ -177,16 +177,16 @@ class Daemon:
    7.13          os.close(0)
    7.14          os.close(1)
    7.15          os.close(2)
    7.16 -        if DEBUG:
    7.17 +        if XEND_DEBUG:
    7.18              os.open('/dev/null', os.O_RDONLY)
    7.19              # XXX KAF: Why doesn't this capture output from C extensions that
    7.20              # fprintf(stdout) or fprintf(stderr) ??
    7.21 -            os.open('/var/log/xend-debug.log', os.O_WRONLY|os.O_CREAT)
    7.22 +            os.open(XEND_DEBUG_LOG, os.O_WRONLY|os.O_CREAT)
    7.23              os.dup(1)
    7.24          else:
    7.25              os.open('/dev/null', os.O_RDWR)
    7.26              os.dup(0)
    7.27 -            os.open('/var/log/xend-debug.log', os.O_WRONLY|os.O_CREAT)
    7.28 +            os.open(XEND_DEBUG_LOG, os.O_WRONLY|os.O_CREAT)
    7.29  
    7.30          
    7.31      def start(self, trace=0):
    7.32 @@ -308,7 +308,7 @@ class Daemon:
    7.33              servers.start()
    7.34          except Exception, ex:
    7.35              print >>sys.stderr, 'Exception starting xend:', ex
    7.36 -            if DEBUG:
    7.37 +            if XEND_DEBUG:
    7.38                  traceback.print_exc()
    7.39              log.exception("Exception starting xend")
    7.40              self.exit(1)
     8.1 --- a/tools/python/xen/xend/server/blkif.py	Fri Jun 03 13:14:54 2005 +0000
     8.2 +++ b/tools/python/xen/xend/server/blkif.py	Fri Jun 03 15:03:33 2005 +0000
     8.3 @@ -56,7 +56,7 @@ class BlkifBackend:
     8.4  
     8.5      def openEvtchn(self):
     8.6          self.evtchn = channel.eventChannel(self.backendDomain, self.frontendDomain)
     8.7 -        
     8.8 +
     8.9      def getEventChannelBackend(self):
    8.10          val = 0
    8.11          if self.evtchn:
     9.1 --- a/tools/python/xen/xend/server/netif.py	Fri Jun 03 13:14:54 2005 +0000
     9.2 +++ b/tools/python/xen/xend/server/netif.py	Fri Jun 03 15:03:33 2005 +0000
     9.3 @@ -230,7 +230,7 @@ class NetDev(Dev):
     9.4                  vm = xd.domain_lookup(dom)
     9.5                  vmname = vm.name
     9.6              except:
     9.7 -                vmname = 'DOM%d' % dom
     9.8 +                vmname = 'Domain-%d' % dom
     9.9          return { 'domain': vmname,
    9.10                   'vif'   : self.get_vifname(), 
    9.11                   'mac'   : self.get_mac(),
    10.1 --- a/tools/python/xen/xend/server/params.py	Fri Jun 03 13:14:54 2005 +0000
    10.2 +++ b/tools/python/xen/xend/server/params.py	Fri Jun 03 15:03:33 2005 +0000
    10.3 @@ -1,6 +1,29 @@
    10.4 +import os
    10.5 +
    10.6 +def getenv(var, val, conv=None):
    10.7 +    """Get a value from the environment, with optional conversion.
    10.8 +
    10.9 +    @param var  name of environment variable
   10.10 +    @param val  default value
   10.11 +    @param conv conversion function to apply to env value
   10.12 +    @return converted value or default
   10.13 +    """
   10.14 +    try:
   10.15 +        v = os.getenv(var)
   10.16 +        if v is None:
   10.17 +            v = val
   10.18 +        else:
   10.19 +            print var, '=', v
   10.20 +        if conv:
   10.21 +            v = conv(v)
   10.22 +    except:
   10.23 +        v = val
   10.24 +    return v
   10.25 +
   10.26  # The following parameters could be placed in a configuration file.
   10.27 -XEND_PID_FILE = '/var/run/xend.pid'
   10.28 -XEND_TRACE_FILE = '/var/log/xend.trace'
   10.29 -
   10.30 -XEND_USER = 'root'
   10.31 -
   10.32 +XEND_PID_FILE     = '/var/run/xend.pid'
   10.33 +XEND_TRACE_FILE   = '/var/log/xend.trace'
   10.34 +XEND_DEBUG_LOG    = '/var/log/xend-debug.log'
   10.35 +XEND_USER         = 'root'
   10.36 +XEND_DEBUG        = getenv("XEND_DEBUG",     0, conv=int)
   10.37 +XEND_DAEMONIZE    = getenv("XEND_DAEMONIZE", not XEND_DEBUG, conv=int)