ia64/xen-unstable

changeset 14972:2c90965d0810

Sanity check changes to memory dynamic/static min/max and ensure we cannot
get ourselves into an inconsistent state.

Signed-off-by: Steven Hand <steven@xensource.com>
author Steven Hand <steven@xensource.com>
date Fri Apr 27 14:16:22 2007 +0100 (2007-04-27)
parents 3c352bbc894d
children 53b9883bbcc3
files tools/python/xen/xend/XendDomainInfo.py
line diff
     1.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Fri Apr 27 13:31:09 2007 +0100
     1.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Fri Apr 27 14:16:22 2007 +0100
     1.3 @@ -580,12 +580,9 @@ class XendDomainInfo:
     1.4          log.debug("Setting memory target of domain %s (%s) to %d MiB.",
     1.5                    self.info['name_label'], str(self.domid), target)
     1.6          
     1.7 -        if target <= 0:
     1.8 -            raise XendError('Invalid memory size')
     1.9 -        
    1.10          MiB = 1024 * 1024
    1.11 -        self.info['memory_dynamic_min'] = target * MiB
    1.12 -        self.info['memory_dynamic_max'] = target * MiB
    1.13 +        self._safe_set_memory('memory_dynamic_min', target * MiB)
    1.14 +        self._safe_set_memory('memory_dynamic_max', target * MiB)
    1.15  
    1.16          if self.domid >= 0:
    1.17              self.storeVm("memory", target)
    1.18 @@ -2134,14 +2131,24 @@ class XendDomainInfo:
    1.19      def get_memory_dynamic_min(self):
    1.20          return self.info.get('memory_dynamic_min', 0)
    1.21  
    1.22 +    # only update memory-related config values if they maintain sanity 
    1.23 +    def _safe_set_memory(self, key, newval):
    1.24 +        oldval = self.info.get(key, 0)
    1.25 +        try:
    1.26 +            self.info[key] = newval
    1.27 +            self.info._memory_sanity_check()
    1.28 +        except Exception, ex:
    1.29 +            self.info[key] = oldval
    1.30 +            raise 
    1.31 +    
    1.32      def set_memory_static_max(self, val):
    1.33 -        self.info['memory_static_max'] = val
    1.34 +        self._safe_set_memory('memory_static_max', val)
    1.35      def set_memory_static_min(self, val):
    1.36 -        self.info['memory_static_min'] = val
    1.37 +        self._safe_set_memory('memory_static_min', val)
    1.38      def set_memory_dynamic_max(self, val):
    1.39 -        self.info['memory_dynamic_max'] = val
    1.40 +        self._safe_set_memory('memory_dynamic_max', val)
    1.41      def set_memory_dynamic_min(self, val):
    1.42 -        self.info['memory_dynamic_min'] = val
    1.43 +        self._safe_set_memory('memory_dynamic_min', val)
    1.44      
    1.45      def get_vcpus_params(self):
    1.46          if self.getDomid() is None: