direct-io.hg

changeset 1825:cf5056d3e5e8

bitkeeper revision 1.1108.1.1 (40fbb559J4VKc_p9h4f2N4LDV9IXfg)

Fix problems with persistence of vm startTime.
author mjw@wray-m-3.hpl.hp.com
date Mon Jul 19 11:49:45 2004 +0000 (2004-07-19)
parents 1a488e40456a
children 1908bce36fa8 bdb9b919d55e
files tools/python/xen/xend/XendDomain.py tools/python/xen/xend/XendDomainInfo.py
line diff
     1.1 --- a/tools/python/xen/xend/XendDomain.py	Sun Jul 18 16:38:30 2004 +0000
     1.2 +++ b/tools/python/xen/xend/XendDomain.py	Mon Jul 19 11:49:45 2004 +0000
     1.3 @@ -179,8 +179,7 @@ class XendDomain:
     1.4          @param info:      domain info from xen
     1.5          @return: deferred
     1.6          """
     1.7 -        config = sxp.child_value(savedinfo, 'config')
     1.8 -        deferred = XendDomainInfo.vm_recreate(config, info)
     1.9 +        deferred = XendDomainInfo.vm_recreate(savedinfo, info)
    1.10          def fn(dominfo):
    1.11              self.domain[dominfo.id] = dominfo
    1.12          deferred.addCallback(fn)
    1.13 @@ -249,20 +248,30 @@ class XendDomain:
    1.14              id = str(d['dom'])
    1.15              doms[id] = d
    1.16              if id not in self.domain:
    1.17 -                config = None
    1.18 -                deferred = XendDomainInfo.vm_recreate(config, d)
    1.19 +                savedinfo = None
    1.20 +                deferred = XendDomainInfo.vm_recreate(savedinfo, d)
    1.21                  def fn(dominfo):
    1.22                      self._add_domain(dominfo.id, dominfo)
    1.23                  deferred.addCallback(fn)
    1.24          # Remove entries for domains that no longer exist.
    1.25          for d in self.domain.values():
    1.26 -            dominfo = doms.get(d.id)
    1.27 -            if dominfo:
    1.28 -                d.update(dominfo)
    1.29 +            info = doms.get(d.id)
    1.30 +            if info:
    1.31 +                d.update(info)
    1.32              else:
    1.33                  self._delete_domain(d.id)
    1.34          self.reap_schedule(1)
    1.35  
    1.36 +    def update_domain(self, id):
    1.37 +        """Update the saved info for a domain.
    1.38 +
    1.39 +        @param id: domain id
    1.40 +        """
    1.41 +        dominfo = self.domain.get(id)
    1.42 +        if dominfo:
    1.43 +            self.domain_db[id] = dominfo.sxpr()
    1.44 +            self.sync_domain(id)
    1.45 +
    1.46      def refresh_domain(self, id):
    1.47          """Refresh information for a single domain.
    1.48  
    1.49 @@ -580,7 +589,9 @@ class XendDomain:
    1.50          if not dominfo:
    1.51              raise XendError("invalid domain:" + str(dom))
    1.52          self.refresh_schedule()
    1.53 -        return dominfo.device_create(devconfig)
    1.54 +        val = dominfo.device_create(devconfig)
    1.55 +        self.update_domain(dominfo.id)
    1.56 +        return val
    1.57  
    1.58      def domain_device_destroy(self, dom, type, idx):
    1.59          """Destroy a device.
    1.60 @@ -594,7 +605,9 @@ class XendDomain:
    1.61          if not dominfo:
    1.62              raise XendError("invalid domain:" + str(dom))
    1.63          self.refresh_schedule()
    1.64 -        return dominfo.device_destroy(type, idx)
    1.65 +        val = dominfo.device_destroy(type, idx)
    1.66 +        self.update_domain(dominfo.id)
    1.67 +        return val
    1.68  
    1.69      def domain_devtype_ls(self, dom, type):
    1.70          """Get list of device indexes for a domain.
     2.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Sun Jul 18 16:38:30 2004 +0000
     2.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Mon Jul 19 11:49:45 2004 +0000
     2.3 @@ -253,14 +253,24 @@ def vm_create(config):
     2.4      vm = XendDomainInfo()
     2.5      return vm.construct(config)
     2.6  
     2.7 -def vm_recreate(config, info):
     2.8 +def vm_recreate(savedinfo, info):
     2.9      """Create the VM object for an existing domain.
    2.10 +
    2.11 +    @param savedinfo: saved info from the domain DB
    2.12 +    @type  savedinfo: sxpr
    2.13 +    @param info:      domain info from xc
    2.14 +    @type  info:      xc domain dict
    2.15 +    @return: deferred
    2.16      """
    2.17      vm = XendDomainInfo()
    2.18      vm.recreate = 1
    2.19      vm.setdom(info['dom'])
    2.20      vm.name = info['name']
    2.21      vm.memory = info['mem_kb']/1024
    2.22 +    start_time = sxp.child_value(savedinfo, 'start_time')
    2.23 +    if start_time is not None:
    2.24 +        vm.startTime = float(start_time)
    2.25 +    config = sxp.child_value(savedinfo, 'config')
    2.26      if config:
    2.27          d = vm.construct(config)
    2.28      else:
    2.29 @@ -382,6 +392,7 @@ class XendDomainInfo:
    2.30                  ['id', self.id],
    2.31                  ['name', self.name],
    2.32                  ['memory', self.memory] ]
    2.33 +
    2.34          if self.info:
    2.35              run   = (self.info['running'] and 'r') or '-'
    2.36              block = (self.info['blocked'] and 'b') or '-'
    2.37 @@ -396,10 +407,10 @@ class XendDomainInfo:
    2.38              sxpr.append(['cpu', self.info['cpu']])
    2.39              sxpr.append(['cpu_time', self.info['cpu_time']/1e9])    
    2.40              
    2.41 -            if self.startTime:
    2.42 -                upTime =  time.time() - self.startTime  
    2.43 -                sxpr.append(['up_time', str( upTime ) ] )
    2.44 -                sxpr.append(['start_time', str( self.startTime ) ] )
    2.45 +        if self.startTime:
    2.46 +            upTime =  time.time() - self.startTime  
    2.47 +            sxpr.append(['up_time', str(upTime) ])
    2.48 +            sxpr.append(['start_time', str(self.startTime) ])
    2.49  
    2.50          if self.console:
    2.51              sxpr.append(self.console.sxpr())
    2.52 @@ -418,9 +429,6 @@ class XendDomainInfo:
    2.53              if self.memory is None:
    2.54                  raise VmError('missing memory size')
    2.55  
    2.56 -            if sxp.child_value( config, 'start_time' ) != None:
    2.57 -                self.startTime = float( sxp.child_value( config, 'start_time' ) )
    2.58 -
    2.59              self.configure_console()
    2.60              self.configure_restart()
    2.61              self.configure_backends()
    2.62 @@ -598,7 +606,7 @@ class XendDomainInfo:
    2.63                            % (name, memory))
    2.64          self.setdom(dom)
    2.65  
    2.66 -        if self.startTime == None:
    2.67 +        if self.startTime is None:
    2.68              self.startTime = time.time()
    2.69  
    2.70      def build_domain(self, ostype, kernel, ramdisk, cmdline, vifs_n):