ia64/xen-unstable

changeset 15207:853853686147

xend: Fix CPU affinity reset across save/restore.
Fixes bug #936.
Signed-off-by: Masaki Kanno <kanno.masaki@jp.fujitsu.com>
author kfraser@localhost.localdomain
date Thu May 24 14:02:09 2007 +0100 (2007-05-24)
parents 6223d154e55f
children f07c1bb86d6c
files tools/python/xen/xend/XendConfig.py
line diff
     1.1 --- a/tools/python/xen/xend/XendConfig.py	Thu May 24 13:58:01 2007 +0100
     1.2 +++ b/tools/python/xen/xend/XendConfig.py	Thu May 24 14:02:09 2007 +0100
     1.3 @@ -587,30 +587,46 @@ class XendConfig(dict):
     1.4              else:
     1.5                  cfg['cpus'] = str(cfg['cpu'])
     1.6  
     1.7 -        # convert 'cpus' string to list of ints
     1.8 -        # 'cpus' supports a list of ranges (0-3), seperated by
     1.9 -        # commas, and negation, (^1).  
    1.10 -        # Precedence is settled by  order of the string:
    1.11 -        #     "0-3,^1"   -> [0,2,3]
    1.12 -        #     "0-3,^1,1" -> [0,1,2,3]
    1.13 -        try:
    1.14 -            if 'cpus' in cfg and type(cfg['cpus']) != list:
    1.15 -                cpus = []
    1.16 -                for c in cfg['cpus'].split(','):
    1.17 -                    if c.find('-') != -1:             
    1.18 -                        (x, y) = c.split('-')
    1.19 -                        for i in range(int(x), int(y)+1):
    1.20 -                            cpus.append(int(i))
    1.21 -                    else:
    1.22 -                        # remove this element from the list 
    1.23 -                        if c[0] == '^':
    1.24 -                            cpus = [x for x in cpus if x != int(c[1:])]
    1.25 +        # Convert 'cpus' to list of ints
    1.26 +        if 'cpus' in cfg:
    1.27 +            cpus = []
    1.28 +            if type(cfg['cpus']) == list:
    1.29 +                # If sxp_cfg was created from config.sxp,
    1.30 +                # the form of 'cpus' is list of string.
    1.31 +                # Convert 'cpus' to list of ints.
    1.32 +                #    ['1']         -> [1]
    1.33 +                #    ['0','2','3'] -> [0,2,3]
    1.34 +                try:
    1.35 +                    for c in cfg['cpus']:
    1.36 +                        cpus.append(int(c))
    1.37 +                    
    1.38 +                    cfg['cpus'] = cpus
    1.39 +                except ValueError, e:
    1.40 +                    raise XendConfigError('cpus = %s: %s' % (cfg['cpus'], e))
    1.41 +            else:
    1.42 +                # Convert 'cpus' string to list of ints
    1.43 +                # 'cpus' supports a list of ranges (0-3),
    1.44 +                # seperated by commas, and negation, (^1).  
    1.45 +                # Precedence is settled by order of the 
    1.46 +                # string:
    1.47 +                #    "0-3,^1"      -> [0,2,3]
    1.48 +                #    "0-3,^1,1"    -> [0,1,2,3]
    1.49 +                try:
    1.50 +                    for c in cfg['cpus'].split(','):
    1.51 +                        if c.find('-') != -1:             
    1.52 +                            (x, y) = c.split('-')
    1.53 +                            for i in range(int(x), int(y)+1):
    1.54 +                                cpus.append(int(i))
    1.55                          else:
    1.56 -                            cpus.append(int(c))
    1.57 -
    1.58 -                cfg['cpus'] = cpus
    1.59 -        except ValueError, e:
    1.60 -            raise XendConfigError('cpus = %s: %s' % (cfg['cpus'], e))
    1.61 +                            # remove this element from the list 
    1.62 +                            if c[0] == '^':
    1.63 +                                cpus = [x for x in cpus if x != int(c[1:])]
    1.64 +                            else:
    1.65 +                                cpus.append(int(c))
    1.66 +                    
    1.67 +                    cfg['cpus'] = cpus
    1.68 +                except ValueError, e:
    1.69 +                    raise XendConfigError('cpus = %s: %s' % (cfg['cpus'], e))
    1.70  
    1.71          if 'security' in cfg and isinstance(cfg['security'], str):
    1.72              cfg['security'] = sxp.from_string(cfg['security'])
    1.73 @@ -842,6 +858,8 @@ class XendConfig(dict):
    1.74                  if name in self and self[name] not in (None, []):
    1.75                      if typ == dict:
    1.76                          s = self[name].items()
    1.77 +                    elif typ == list:
    1.78 +                        s = self[name]
    1.79                      else:
    1.80                          s = str(self[name])
    1.81                      sxpr.append([name, s])