ia64/xen-unstable

changeset 6922:8ff691d008f4

Cleanup domain listing on xend start. Fix reaper some more.
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk
date Fri Sep 16 23:55:50 2005 +0000 (2005-09-16)
parents 931526414a64
children 03b58a6f498e
files tools/python/xen/xend/XendDomain.py tools/python/xen/xend/XendDomainInfo.py
line diff
     1.1 --- a/tools/python/xen/xend/XendDomain.py	Fri Sep 16 22:27:04 2005 +0000
     1.2 +++ b/tools/python/xen/xend/XendDomain.py	Fri Sep 16 23:55:50 2005 +0000
     1.3 @@ -39,11 +39,19 @@ from xen.xend import scheduler
     1.4  from xen.xend.server import relocate
     1.5  from xen.xend.uuid import getUuid
     1.6  from xen.xend.xenstore import XenNode, DBMap
     1.7 +from xen.xend.xenstore.xstransact import xstransact
     1.8 +from xen.xend.xenstore.xsutil import GetDomainPath
     1.9  
    1.10  __all__ = [ "XendDomain" ]
    1.11  
    1.12  SHUTDOWN_TIMEOUT = 30
    1.13  
    1.14 +def is_dead(dom):
    1.15 +    return dom['crashed'] or dom['shutdown'] or (
    1.16 +        dom['dying'] and not(dom['running'] or dom['paused'] or
    1.17 +                             dom['blocked']))
    1.18 +
    1.19 +
    1.20  class XendDomainDict(dict):
    1.21      def get_by_name(self, name):
    1.22          try:
    1.23 @@ -65,7 +73,9 @@ class XendDomain:
    1.24          # So we stuff the XendDomain instance (self) into xroot's components.
    1.25          xroot.add_component("xen.xend.XendDomain", self)
    1.26          self.domains = XendDomainDict()
    1.27 -        self.dbmap = DBMap(db=XenNode("/domain"))
    1.28 +        self.domroot = "/domain"
    1.29 +        self.vmroot = "/domain"
    1.30 +        self.dbmap = DBMap(db=XenNode(self.vmroot))
    1.31          self.watchReleaseDomain()
    1.32          self.initial_refresh()
    1.33          self.dom0_setup()
    1.34 @@ -126,57 +136,47 @@ class XendDomain:
    1.35          else:
    1.36              dominfo = dominfo[0]
    1.37          return dominfo
    1.38 -            
    1.39 +
    1.40      def initial_refresh(self):
    1.41          """Refresh initial domain info from db.
    1.42          """
    1.43          doms = self.xen_domains()
    1.44 -        self.dbmap.readDB()
    1.45 -        for domdb in self.dbmap.values():
    1.46 -            if not domdb.has_key("xend"):
    1.47 +        self.dbmap.readDB()             # XXX only needed for "xend"
    1.48 +        for dom in doms.values():
    1.49 +            domid = dom['dom']
    1.50 +            dompath = GetDomainPath(domid)
    1.51 +            if not dompath:
    1.52                  continue
    1.53 -            db = domdb.addChild("xend")
    1.54 +            vmpath = xstransact.Read(dompath, "vm")
    1.55 +            if not vmpath:
    1.56 +                continue
    1.57 +            uuid = xstransact.Read(vmpath, "uuid")
    1.58 +            if not uuid:
    1.59 +                continue
    1.60 +            log.info("recreating domain %d, uuid %s" % (domid, uuid))
    1.61 +            dompath = "/".join(dompath.split("/")[0:-1])
    1.62 +            db = self.dbmap.addChild("%s/xend" % uuid)
    1.63              try:
    1.64 -                domid = int(domdb["domid"].getData())
    1.65 -            except:
    1.66 -                domid = None
    1.67 -            # XXX if domid in self.domains, then something went wrong
    1.68 -            if (domid is None) or (domid in self.domains):
    1.69 -                domdb.delete()
    1.70 -            elif domid in doms:
    1.71 -                try:
    1.72 -                    self._new_domain(domdb["uuid"].getData(), domid, db,
    1.73 -                                     doms[domid]) 
    1.74 -                except Exception, ex:
    1.75 -                    log.exception("Error recreating domain info: id=%d", domid)
    1.76 -                    self._delete_domain(domid)
    1.77 -            else:
    1.78 -                self._delete_domain(domid)
    1.79 +                dominfo = XendDomainInfo.recreate(uuid, dompath, domid, db,
    1.80 +                                                  dom)
    1.81 +            except Exception, ex:
    1.82 +                log.exception("Error recreating domain info: id=%d", domid)
    1.83 +                continue
    1.84 +            self._add_domain(dominfo)
    1.85          self.reap()
    1.86          self.refresh()
    1.87          self.domain_restarts()
    1.88  
    1.89 -    def dom0_setup():
    1.90 +    def dom0_setup(self):
    1.91          dom0 = self.domain_lookup(0)
    1.92          if not dom0:
    1.93 -            dom0 = self.domain_unknown(0)
    1.94 +            dom0 = self.dom0_unknown()
    1.95          dom0.dom0_init_store()    
    1.96          dom0.dom0_enforce_vcpus()
    1.97  
    1.98      def close(self):
    1.99          pass
   1.100  
   1.101 -    def _new_domain(self, uuid, domid, db, info):
   1.102 -        """Create a domain entry from saved info.
   1.103 -
   1.104 -        @param db:   saved info from the db
   1.105 -        @param info: domain info from xen
   1.106 -        @return: domain
   1.107 -        """
   1.108 -        dominfo = XendDomainInfo.recreate(uuid, domid, db, info)
   1.109 -        self.domains[dominfo.domid] = dominfo
   1.110 -        return dominfo
   1.111 -
   1.112      def _add_domain(self, info, notify=True):
   1.113          """Add a domain entry to the tables.
   1.114  
   1.115 @@ -196,11 +196,6 @@ class XendDomain:
   1.116          @param id:     domain id
   1.117          @param notify: send a domain died event if true
   1.118          """
   1.119 -        try:
   1.120 -            if self.xen_domain(id):
   1.121 -                return
   1.122 -        except:
   1.123 -            pass
   1.124          info = self.domains.get(id)
   1.125          if info:
   1.126              del self.domains[id]
   1.127 @@ -226,10 +221,7 @@ class XendDomain:
   1.128          """
   1.129          doms = self.xen_domains()
   1.130          for d in doms.values():
   1.131 -            dead = d['crashed'] or d['shutdown'] or (
   1.132 -                d['dying'] and not(d['running'] or d['paused'] or
   1.133 -                                   d['blocked']))
   1.134 -            if not dead:
   1.135 +            if not is_dead(d):
   1.136                  continue
   1.137              domid = d['dom']
   1.138              dominfo = self.domains.get(domid)
   1.139 @@ -240,8 +232,8 @@ class XendDomain:
   1.140                  self.domain_dumpcore(domid)
   1.141              if d['shutdown']:
   1.142                  reason = shutdown_reason(d['shutdown_reason'])
   1.143 -                log.debug('shutdown name=%s id=%d reason=%s', name, domid,
   1.144 -                          reason)
   1.145 +                log.debug('shutdown name=%s id=%d reason=%s', dominfo.name,
   1.146 +                          domid, reason)
   1.147                  if reason == 'suspend':
   1.148                      dominfo.state_set("suspended")
   1.149                      continue
   1.150 @@ -338,22 +330,32 @@ class XendDomain:
   1.151          self.update_domain(id)
   1.152          return self.domains.get(id)
   1.153  
   1.154 -    def domain_unknown(self, id):
   1.155 +    def dom0_unknown(self):
   1.156 +        dom0 = 0
   1.157 +        uuid = None
   1.158 +        info = self.xen_domain(dom0)
   1.159 +        dompath = GetDomainPath(dom0)
   1.160 +        if dompath:
   1.161 +            vmpath = xstransact.Read(dompath, "vm")
   1.162 +            if vmpath:
   1.163 +                uuid = xstransact.Read(vmpath, "uuid")
   1.164 +            if not uuid:
   1.165 +                uuid = dompath.split("/")[-1]
   1.166 +            dompath = "/".join(dompath.split("/")[0:-1])
   1.167 +        if not uuid:
   1.168 +            uuid = getUuid()
   1.169 +            dompath = self.domroot
   1.170 +        log.info("Creating entry for unknown xend domain: id=%d uuid=%s",
   1.171 +                 dom0, uuid)
   1.172 +        db = self.dbmap.addChild("%s/xend" % uuid)
   1.173          try:
   1.174 -            info = self.xen_domain(id)
   1.175 -            if info:
   1.176 -                uuid = getUuid()
   1.177 -                log.info(
   1.178 -                    "Creating entry for unknown domain: id=%d uuid=%s",
   1.179 -                    id, uuid)
   1.180 -                db = self.dbmap.addChild("%s/xend" % uuid)
   1.181 -                dominfo = XendDomainInfo.recreate(uuid, id, db, info)
   1.182 -                self._add_domain(dominfo)
   1.183 -                return dominfo
   1.184 -        except Exception, ex:
   1.185 -            raise
   1.186 -            log.exception("Error creating domain info: id=%d", id)
   1.187 -        return None
   1.188 +            dominfo = XendDomainInfo.recreate(uuid, dompath, dom0,
   1.189 +                                              db, info)
   1.190 +        except:
   1.191 +            raise XendError("Error recreating xend domain info: id=%d" %
   1.192 +                            dom0)
   1.193 +        self._add_domain(dominfo)
   1.194 +        return dominfo
   1.195          
   1.196      def domain_lookup(self, id):
   1.197          return self.domains.get(id)
     2.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Fri Sep 16 22:27:04 2005 +0000
     2.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Fri Sep 16 23:55:50 2005 +0000
     2.3 @@ -153,13 +153,12 @@ class XendDomainInfo:
     2.4  
     2.5      create = classmethod(create)
     2.6  
     2.7 -    def recreate(cls, uuid, domid, db, info):
     2.8 +    def recreate(cls, uuid, path, domid, db, info):
     2.9          """Create the VM object for an existing domain.
    2.10  
    2.11          @param db:        domain db
    2.12          @param info:      domain info from xc
    2.13          """
    2.14 -        path = "/".join(db.getPath().split("/")[0:-2])
    2.15          vm = cls(uuid, path, db)
    2.16          vm.setDomid(domid)
    2.17          vm.name, vm.start_time = vm.gatherVm(("name", str),
    2.18 @@ -726,8 +725,6 @@ class XendDomainInfo:
    2.19      def delete(self):
    2.20          """Delete the vm's db.
    2.21          """
    2.22 -        if dom_get(self.domid):
    2.23 -            return
    2.24          self.domid = None
    2.25          self.saveToDB(sync=True)
    2.26          try:
    2.27 @@ -759,7 +756,7 @@ class XendDomainInfo:
    2.28          if self.store_channel:
    2.29              self.setStoreChannel(None)
    2.30          if self.console_channel:
    2.31 -            # notify processes using this cosole?
    2.32 +            # notify processes using this console?
    2.33              try:
    2.34                  self.console_channel.close()
    2.35                  self.console_channel = None