ia64/xen-unstable

changeset 19232:2a8ba98a5cff

xm: Some fixes for pvSCSI

For xm create and xm new, an error may not occur even if wrong
vscsi configuration is given.

e.g.
vscsi = [ '0:0:0:0,0:0:0:0', '0:0:0:0,1:0:0:0' ]

# xm create vm1
Using config file "/etc/xen/vm1".
Started domain vm1 (id=8)
# xm scsi-list vm1
Idx BE state host phy-hctl phy vir-hctl devstate
0 0 1 0 0:0:0:0 sda 0:0:0:0 None
1 0 1 0 0:0:0:0 sda 1:0:0:0 None

This patch fixes some problems such as the above.

Signed-off-by: Masaki Kanno <kanno.masaki@jp.fujitsu.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Feb 19 11:01:15 2009 +0000 (2009-02-19)
parents bd991b0431aa
children 84af3ded5b02
files tools/python/xen/xm/create.py
line diff
     1.1 --- a/tools/python/xen/xm/create.py	Thu Feb 19 10:59:43 2009 +0000
     1.2 +++ b/tools/python/xen/xm/create.py	Thu Feb 19 11:01:15 2009 +0000
     1.3 @@ -703,25 +703,6 @@ def configure_pci(config_devs, vals):
     1.4          config_pci.insert(0, 'pci')
     1.5          config_devs.append(['device', config_pci])
     1.6  
     1.7 -def vscsi_convert_sxp_to_dict(dev_sxp):
     1.8 -    dev_dict = {}
     1.9 -    for opt_val in dev_sxp[1:]:
    1.10 -        try:
    1.11 -            opt, val = opt_val
    1.12 -            dev_dict[opt] = val
    1.13 -        except TypeError:
    1.14 -            pass
    1.15 -    return dev_dict
    1.16 -
    1.17 -def vscsi_lookup_devid(devlist, req_devid):
    1.18 -    if len(devlist) == 0:
    1.19 -        return 0
    1.20 -    else:
    1.21 -        for (devid, _, _) in devlist:
    1.22 -            if devid == req_devid:
    1.23 -                return 1
    1.24 -        return 0
    1.25 -
    1.26  def configure_vscsis(config_devs, vals):
    1.27      """Create the config for vscsis (virtual scsi devices).
    1.28      """
    1.29 @@ -729,11 +710,13 @@ def configure_vscsis(config_devs, vals):
    1.30      def get_devid(hctl):
    1.31          return int(hctl.split(':')[0])
    1.32  
    1.33 -    devidlist = []
    1.34 -    config_scsi = []
    1.35      if len(vals.vscsi) == 0:
    1.36          return 0
    1.37  
    1.38 +    config_scsi = {}
    1.39 +    pHCTL_list = []
    1.40 +    vHCTL_list = []
    1.41 +
    1.42      scsi_devices = vscsi_util.vscsi_get_scsidevices()
    1.43      for (p_dev, v_dev, backend) in vals.vscsi:
    1.44          (p_hctl, devname) = \
    1.45 @@ -742,9 +725,9 @@ def configure_vscsis(config_devs, vals):
    1.46          if p_hctl == None:
    1.47              raise ValueError('Cannot find device "%s"' % p_dev)
    1.48  
    1.49 -        host_mode = 0
    1.50 +        feature_host = 0
    1.51          if v_dev == 'host':
    1.52 -            host_mode = 1
    1.53 +            feature_host = 1
    1.54              scsi_info = []
    1.55              devid = get_devid(p_hctl)
    1.56              for (pHCTL, devname, _, _) in scsi_devices:
    1.57 @@ -753,32 +736,44 @@ def configure_vscsis(config_devs, vals):
    1.58          else:
    1.59              scsi_info = [[get_devid(v_dev), p_hctl, devname, v_dev]]
    1.60  
    1.61 -        for config in config_scsi:
    1.62 -            dev = vscsi_convert_sxp_to_dict(config)
    1.63 -            if dev['v-dev'] in [scsi_info[x][3] for x in range(len(scsi_info))]:
    1.64 -                raise ValueError('The virtual device "%s" is already defined' % v_dev)
    1.65 -
    1.66 -        for (devid, pHCTL, devname, vHCTL) in scsi_info:
    1.67 -            config_scsi.append(['dev', \
    1.68 -                                ['state', xenbusState['Initialising']], \
    1.69 -                                ['devid', devid], \
    1.70 -                                ['p-dev', pHCTL], \
    1.71 -                                ['p-devname', devname], \
    1.72 -                                ['v-dev', vHCTL] ])
    1.73 +        devid_key = scsi_info[0][0]
    1.74 +        try:
    1.75 +            config = config_scsi[devid_key]
    1.76 +        except KeyError:
    1.77 +            config = {'feature-host': feature_host, 'backend': backend, 'devs': []}
    1.78  
    1.79 -        if vscsi_lookup_devid(devidlist, devid) == 0:
    1.80 -            devidlist.append([devid, backend, host_mode])
    1.81 +        devs = config['devs']
    1.82 +        for (devid, pHCTL, devname, vHCTL) in scsi_info:
    1.83 +            if pHCTL in pHCTL_list:
    1.84 +                raise ValueError('The physical device "%s" is already defined' % pHCTL)
    1.85 +            if vHCTL in vHCTL_list:
    1.86 +                raise ValueError('The virtual device "%s" is already defined' % vHCTL)
    1.87 +            pHCTL_list.append(pHCTL)
    1.88 +            vHCTL_list.append(vHCTL)
    1.89 +            devs.append(['dev', \
    1.90 +                         ['state', xenbusState['Initialising']], \
    1.91 +                         ['devid', devid], \
    1.92 +                         ['p-dev', pHCTL], \
    1.93 +                         ['p-devname', devname], \
    1.94 +                         ['v-dev', vHCTL] ])
    1.95  
    1.96 -    for (devid, backend, host_mode) in devidlist:
    1.97 -        tmp = ['vscsi', ['feature-host', host_mode]]
    1.98 -        for config in config_scsi:
    1.99 -            dev = vscsi_convert_sxp_to_dict(config)
   1.100 -            if dev['devid'] == devid:
   1.101 -                tmp.append(config)
   1.102 +        if config['feature-host'] != feature_host:
   1.103 +            raise ValueError('The physical device "%s" cannot define '
   1.104 +                             'because mode is different' % scsi_info[0][1])
   1.105 +        if config['backend'] != backend:
   1.106 +            raise ValueError('The physical device "%s" cannot define '
   1.107 +                             'because backend is different' % scsi_info[0][1])
   1.108  
   1.109 -        if backend:
   1.110 -            tmp.append(['backend', backend])
   1.111 -        config_devs.append(['device', tmp])
   1.112 +        config['devs'] = devs
   1.113 +        config_scsi[devid_key] = config
   1.114 +
   1.115 +    for config in config_scsi.values():
   1.116 +        device = ['vscsi', ['feature-host', config['feature-host']]]
   1.117 +        for dev in config['devs']:
   1.118 +            device.append(dev)
   1.119 +        if config['backend']:
   1.120 +            device.append(['backend', config['backend']])
   1.121 +        config_devs.append(['device', device])
   1.122  
   1.123  def configure_ioports(config_devs, vals):
   1.124      """Create the config for legacy i/o ranges.