ia64/xen-unstable

changeset 7213:22449386d38d

Explicitly close files on save and restore. Rename all local variables named id or slice so as not to clash with the builtins.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@ewan
date Wed Oct 05 00:00:42 2005 +0100 (2005-10-05)
parents 2c9e66555ff4
children 33cd9a7a903b
files tools/python/xen/xend/XendDomain.py
line diff
     1.1 --- a/tools/python/xen/xend/XendDomain.py	Tue Oct 04 23:56:42 2005 +0100
     1.2 +++ b/tools/python/xen/xend/XendDomain.py	Wed Oct 05 00:00:42 2005 +0100
     1.3 @@ -216,7 +216,11 @@ class XendDomain:
     1.4          """
     1.5  
     1.6          try:
     1.7 -            return self.domain_restore_fd(os.open(src, os.O_RDONLY))
     1.8 +            fd = os.open(src, os.O_RDONLY)
     1.9 +            try:
    1.10 +                return self.domain_restore_fd(fd)
    1.11 +            finally:
    1.12 +                os.close(fd)
    1.13          except OSError, ex:
    1.14              raise XendError("can't read guest state file %s: %s" %
    1.15                              (src, ex[1]))
    1.16 @@ -256,19 +260,19 @@ class XendDomain:
    1.17              self.domains_lock.release()
    1.18  
    1.19  
    1.20 -    def domain_lookup(self, id):
    1.21 +    def domain_lookup(self, domid):
    1.22          self.domains_lock.acquire()
    1.23          try:
    1.24              self.refresh()
    1.25 -            return self.domains.get(id)
    1.26 +            return self.domains.get(domid)
    1.27          finally:
    1.28              self.domains_lock.release()
    1.29  
    1.30  
    1.31 -    def domain_lookup_nr(self, id):
    1.32 +    def domain_lookup_nr(self, domid):
    1.33          self.domains_lock.acquire()
    1.34          try:
    1.35 -            return self.domains.get(id)
    1.36 +            return self.domains.get(domid)
    1.37          finally:
    1.38              self.domains_lock.release()
    1.39  
    1.40 @@ -323,12 +327,9 @@ class XendDomain:
    1.41              self.domains_lock.release()
    1.42  
    1.43   
    1.44 -    def domain_unpause(self, id):
    1.45 -        """Unpause domain execution.
    1.46 -
    1.47 -        @param id: domain id
    1.48 -        """
    1.49 -        dominfo = self.domain_lookup(id)
    1.50 +    def domain_unpause(self, domid):
    1.51 +        """Unpause domain execution."""
    1.52 +        dominfo = self.domain_lookup(domid)
    1.53          eserver.inject('xend.domain.unpause', [dominfo.getName(),
    1.54                                                 dominfo.getDomid()])
    1.55          try:
    1.56 @@ -336,12 +337,9 @@ class XendDomain:
    1.57          except Exception, ex:
    1.58              raise XendError(str(ex))
    1.59      
    1.60 -    def domain_pause(self, id):
    1.61 -        """Pause domain execution.
    1.62 -
    1.63 -        @param id: domain id
    1.64 -        """
    1.65 -        dominfo = self.domain_lookup(id)
    1.66 +    def domain_pause(self, domid):
    1.67 +        """Pause domain execution."""
    1.68 +        dominfo = self.domain_lookup(domid)
    1.69          eserver.inject('xend.domain.pause', [dominfo.getName(),
    1.70                                               dominfo.getDomid()])
    1.71          try:
    1.72 @@ -380,14 +378,10 @@ class XendDomain:
    1.73                  raise XendError(str(ex))
    1.74          return val       
    1.75  
    1.76 -    def domain_migrate(self, id, dst, live=False, resource=0):
    1.77 -        """Start domain migration.
    1.78 +    def domain_migrate(self, domid, dst, live=False, resource=0):
    1.79 +        """Start domain migration."""
    1.80  
    1.81 -        @param id: domain id
    1.82 -        """
    1.83 -        # Need a cancel too?
    1.84 -        # Don't forget to cancel restart for it.
    1.85 -        dominfo = self.domain_lookup(id)
    1.86 +        dominfo = self.domain_lookup(domid)
    1.87  
    1.88          port = xroot.get_xend_relocation_port()
    1.89          sock = relocate.setupRelocation(dst, port)
    1.90 @@ -395,42 +389,41 @@ class XendDomain:
    1.91          XendCheckpoint.save(sock.fileno(), dominfo, live)
    1.92          
    1.93  
    1.94 -    def domain_save(self, id, dst):
    1.95 +    def domain_save(self, domid, dst):
    1.96          """Start saving a domain to file.
    1.97  
    1.98 -        @param id:       domain id
    1.99          @param dst:      destination file
   1.100          """
   1.101  
   1.102          try:
   1.103 -            dominfo = self.domain_lookup(id)
   1.104 +            dominfo = self.domain_lookup(domid)
   1.105  
   1.106              fd = os.open(dst, os.O_WRONLY | os.O_CREAT | os.O_TRUNC)
   1.107 -
   1.108 -            # For now we don't support 'live checkpoint' 
   1.109 -            return XendCheckpoint.save(fd, dominfo, False)
   1.110 -
   1.111 +            try:
   1.112 +                # For now we don't support 'live checkpoint' 
   1.113 +                return XendCheckpoint.save(fd, dominfo, False)
   1.114 +            finally:
   1.115 +                os.close(fd)
   1.116          except OSError, ex:
   1.117              raise XendError("can't write guest state file %s: %s" %
   1.118                              (dst, ex[1]))
   1.119  
   1.120 -    def domain_pincpu(self, id, vcpu, cpumap):
   1.121 +    def domain_pincpu(self, domid, vcpu, cpumap):
   1.122          """Set which cpus vcpu can use
   1.123  
   1.124 -        @param id:   domain
   1.125 -        @param vcpu: vcpu number
   1.126 -        @param cpumap:  bitmap of usbale cpus
   1.127 +        @param cpumap:  bitmap of usable cpus
   1.128          """
   1.129 -        dominfo = self.domain_lookup(id)
   1.130 +        dominfo = self.domain_lookup(domid)
   1.131          try:
   1.132              return xc.domain_pincpu(dominfo.getDomid(), vcpu, cpumap)
   1.133          except Exception, ex:
   1.134              raise XendError(str(ex))
   1.135  
   1.136 -    def domain_cpu_bvt_set(self, id, mcuadv, warpback, warpvalue, warpl, warpu):
   1.137 +    def domain_cpu_bvt_set(self, domid, mcuadv, warpback, warpvalue, warpl,
   1.138 +                           warpu):
   1.139          """Set BVT (Borrowed Virtual Time) scheduler parameters for a domain.
   1.140          """
   1.141 -        dominfo = self.domain_lookup(id)
   1.142 +        dominfo = self.domain_lookup(domid)
   1.143          try:
   1.144              return xc.bvtsched_domain_set(dom=dominfo.getDomid(),
   1.145                                            mcuadv=mcuadv,
   1.146 @@ -440,30 +433,31 @@ class XendDomain:
   1.147          except Exception, ex:
   1.148              raise XendError(str(ex))
   1.149  
   1.150 -    def domain_cpu_bvt_get(self, id):
   1.151 +    def domain_cpu_bvt_get(self, domid):
   1.152          """Get BVT (Borrowed Virtual Time) scheduler parameters for a domain.
   1.153          """
   1.154 -        dominfo = self.domain_lookup(id)
   1.155 +        dominfo = self.domain_lookup(domid)
   1.156          try:
   1.157              return xc.bvtsched_domain_get(dominfo.getDomid())
   1.158          except Exception, ex:
   1.159              raise XendError(str(ex))
   1.160      
   1.161      
   1.162 -    def domain_cpu_sedf_set(self, id, period, slice, latency, extratime, weight):
   1.163 +    def domain_cpu_sedf_set(self, domid, period, slice_, latency, extratime,
   1.164 +                            weight):
   1.165          """Set Simple EDF scheduler parameters for a domain.
   1.166          """
   1.167 -        dominfo = self.domain_lookup(id)
   1.168 +        dominfo = self.domain_lookup(domid)
   1.169          try:
   1.170 -            return xc.sedf_domain_set(dominfo.getDomid(), period, slice,
   1.171 +            return xc.sedf_domain_set(dominfo.getDomid(), period, slice_,
   1.172                                        latency, extratime, weight)
   1.173          except Exception, ex:
   1.174              raise XendError(str(ex))
   1.175  
   1.176 -    def domain_cpu_sedf_get(self, id):
   1.177 +    def domain_cpu_sedf_get(self, domid):
   1.178          """Get Simple EDF scheduler parameters for a domain.
   1.179          """
   1.180 -        dominfo = self.domain_lookup(id)
   1.181 +        dominfo = self.domain_lookup(domid)
   1.182          try:
   1.183              return xc.sedf_domain_get(dominfo.getDomid())
   1.184          except Exception, ex:
   1.185 @@ -508,35 +502,30 @@ class XendDomain:
   1.186                               devtype)
   1.187  
   1.188  
   1.189 -    def domain_vif_limit_set(self, id, vif, credit, period):
   1.190 +    def domain_vif_limit_set(self, domid, vif, credit, period):
   1.191          """Limit the vif's transmission rate
   1.192          """
   1.193 -        dominfo = self.domain_lookup(id)
   1.194 +        dominfo = self.domain_lookup(domid)
   1.195          dev = dominfo.getDevice('vif', vif)
   1.196          if not dev:
   1.197              raise XendError("invalid vif")
   1.198          return dev.setCreditLimit(credit, period)
   1.199          
   1.200 -    def domain_shadow_control(self, id, op):
   1.201 -        """Shadow page control.
   1.202 -
   1.203 -        @param id: domain
   1.204 -        @param op:  operation
   1.205 -        """
   1.206 -        dominfo = self.domain_lookup(id)
   1.207 +    def domain_shadow_control(self, domid, op):
   1.208 +        """Shadow page control."""
   1.209 +        dominfo = self.domain_lookup(domid)
   1.210          try:
   1.211              return xc.shadow_control(dominfo.getDomid(), op)
   1.212          except Exception, ex:
   1.213              raise XendError(str(ex))
   1.214  
   1.215 -    def domain_maxmem_set(self, id, mem):
   1.216 +    def domain_maxmem_set(self, domid, mem):
   1.217          """Set the memory limit for a domain.
   1.218  
   1.219 -        @param id: domain
   1.220          @param mem: memory limit (in MiB)
   1.221          @return: 0 on success, -1 on error
   1.222          """
   1.223 -        dominfo = self.domain_lookup(id)
   1.224 +        dominfo = self.domain_lookup(domid)
   1.225          maxmem = int(mem) * 1024
   1.226          try:
   1.227              return xc.domain_setmaxmem(dominfo.getDomid(),