ia64/xen-unstable

changeset 19298:5997e86988f6

pvscsi: Some fixes for xm scsi-attach

Signed-off-by: Masaki Kanno <kanno.masaki@jp.fujitsu.com>
author Keir Fraser <keir.fraser@citrix.com>
date Mon Mar 09 09:49:50 2009 +0000 (2009-03-09)
parents 12c19447f6ea
children f57ac4af36b4
files tools/python/xen/xend/XendDomainInfo.py
line diff
     1.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Mon Mar 09 09:48:45 2009 +0000
     1.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Mon Mar 09 09:49:50 2009 +0000
     1.3 @@ -855,27 +855,73 @@ class XendDomainInfo:
     1.4          """Configure an existing vscsi device.
     1.5              quoted pci funciton
     1.6          """
     1.7 +        def _is_vscsi_defined(dev_info, p_devs = None, v_devs = None):
     1.8 +            if not dev_info:
     1.9 +                return False
    1.10 +            for dev in sxp.children(dev_info, 'dev'):
    1.11 +                if p_devs is not None:
    1.12 +                    if sxp.child_value(dev, 'p-dev') in p_devs:
    1.13 +                        return True
    1.14 +                if v_devs is not None:
    1.15 +                    if sxp.child_value(dev, 'v-dev') in v_devs:
    1.16 +                        return True
    1.17 +            return False
    1.18 +
    1.19 +        def _vscsi_be(be):
    1.20 +            be_xdi = xen.xend.XendDomain.instance().domain_lookup_nr(be)
    1.21 +            if be_xdi is not None:
    1.22 +                be_domid = be_xdi.getDomid()
    1.23 +                if be_domid is not None:
    1.24 +                    return str(be_domid)
    1.25 +            return str(be)
    1.26 +
    1.27          dev_class = sxp.name(dev_sxp)
    1.28          if dev_class != 'vscsi':
    1.29              return False
    1.30  
    1.31          dev_config = self.info.vscsi_convert_sxp_to_dict(dev_sxp)
    1.32 -        dev = dev_config['devs'][0]
    1.33 -        req_devid = int(dev['devid'])
    1.34 -        existing_dev_info = self._getDeviceInfo_vscsi(req_devid, dev['v-dev'])
    1.35 -        state = dev['state']
    1.36 +        devs = dev_config['devs']
    1.37 +        v_devs = [d['v-dev'] for d in devs]
    1.38 +        state = devs[0]['state']
    1.39 +        req_devid = int(devs[0]['devid'])
    1.40 +        cur_dev_sxp = self._getDeviceInfo_vscsi(req_devid)
    1.41  
    1.42          if state == xenbusState['Initialising']:
    1.43              # new create
    1.44              # If request devid does not exist, create and exit.
    1.45 -            if existing_dev_info is None:
    1.46 +            p_devs = [d['p-dev'] for d in devs]
    1.47 +            for dev_type, dev_info in self.info.all_devices_sxpr():
    1.48 +                if dev_type != 'vscsi':
    1.49 +                    continue
    1.50 +                if _is_vscsi_defined(dev_info, p_devs = p_devs):
    1.51 +                    raise XendError('The physical device "%s" is already defined' % \
    1.52 +                                    p_devs[0])
    1.53 +            if cur_dev_sxp is None:
    1.54                  self.device_create(dev_sxp)
    1.55                  return True
    1.56 -            elif existing_dev_info == "exists":
    1.57 -                raise XendError("The virtual device %s is already defined" % dev['v-dev'])
    1.58 +
    1.59 +            if _is_vscsi_defined(cur_dev_sxp, v_devs = v_devs):
    1.60 +                raise XendError('The virtual device "%s" is already defined' % \
    1.61 +                                v_devs[0])
    1.62 +
    1.63 +            if int(dev_config['feature-host']) != \
    1.64 +               int(sxp.child_value(cur_dev_sxp, 'feature-host')):
    1.65 +                raise XendError('The physical device "%s" cannot define '
    1.66 +                                'because mode is different' % devs[0]['p-dev'])
    1.67 +
    1.68 +            new_be = dev_config.get('backend', None)
    1.69 +            if new_be is not None:
    1.70 +                cur_be = sxp.child_value(cur_dev_sxp, 'backend', None)
    1.71 +                if cur_be is None:
    1.72 +                    cur_be = xen.xend.XendDomain.DOM0_ID
    1.73 +                new_be_dom = _vscsi_be(new_be)
    1.74 +                cur_be_dom = _vscsi_be(cur_be)
    1.75 +                if new_be_dom != cur_be_dom:
    1.76 +                    raise XendError('The physical device "%s" cannot define '
    1.77 +                                    'because backend is different' % devs[0]['p-dev'])
    1.78  
    1.79          elif state == xenbusState['Closing']:
    1.80 -            if existing_dev_info is None:
    1.81 +            if not _is_vscsi_defined(cur_dev_sxp, v_devs = v_devs):
    1.82                  raise XendError("Cannot detach vscsi device does not exist")
    1.83  
    1.84          if self.domid is not None:
    1.85 @@ -896,7 +942,6 @@ class XendDomainInfo:
    1.86                  del self.info['devices'][dev_uuid]
    1.87  
    1.88          else:
    1.89 -            cur_dev_sxp = self._getDeviceInfo_vscsi(req_devid, None)
    1.90              new_dev_sxp = ['vscsi']
    1.91              cur_mode = sxp.children(cur_dev_sxp, 'feature-host')[0]
    1.92              new_dev_sxp.append(cur_mode)
    1.93 @@ -910,8 +955,7 @@ class XendDomainInfo:
    1.94                  if state == xenbusState['Closing']:
    1.95                      if int(cur_mode[1]) == 1:
    1.96                          continue
    1.97 -                    cur_dev_vdev = sxp.child_value(cur_dev, 'v-dev')
    1.98 -                    if cur_dev_vdev == dev['v-dev']:
    1.99 +                    if sxp.child_value(cur_dev, 'v-dev') in v_devs:
   1.100                          continue
   1.101                  new_dev_sxp.append(cur_dev)
   1.102  
   1.103 @@ -1172,23 +1216,14 @@ class XendDomainInfo:
   1.104              return dev_info
   1.105          return None
   1.106  
   1.107 -    def _getDeviceInfo_vscsi(self, devid, vdev):
   1.108 +    def _getDeviceInfo_vscsi(self, devid):
   1.109          devid = int(devid)
   1.110          for dev_type, dev_info in self.info.all_devices_sxpr():
   1.111              if dev_type != 'vscsi':
   1.112                  continue
   1.113 -            existing_dev_uuid = sxp.child_value(dev_info, 'uuid')
   1.114 -            existing_conf = self.info['devices'][existing_dev_uuid][1]
   1.115 -            existing_dev = existing_conf['devs'][0]
   1.116 -            existing_devid = int(existing_dev['devid'])
   1.117 -            existing_vdev = existing_dev['v-dev']
   1.118 -
   1.119 -            if vdev == existing_vdev:
   1.120 -                return "exists"
   1.121 -
   1.122 -            if devid == existing_devid:
   1.123 +            devs = sxp.children(dev_info, 'dev')
   1.124 +            if devid == int(sxp.child_value(devs[0], 'devid')):
   1.125                  return dev_info
   1.126 -
   1.127          return None
   1.128  
   1.129      def setMemoryTarget(self, target):
   1.130 @@ -3639,7 +3674,7 @@ class XendDomainInfo:
   1.131  
   1.132          if self._stateGet() != XEN_API_VM_POWER_STATE_RUNNING:
   1.133  
   1.134 -            cur_vscsi_sxp = self._getDeviceInfo_vscsi(devid, None)
   1.135 +            cur_vscsi_sxp = self._getDeviceInfo_vscsi(devid)
   1.136  
   1.137              if cur_vscsi_sxp is None:
   1.138                  dev_uuid = self.info.device_add('vscsi', cfg_sxp = target_vscsi_sxp)
   1.139 @@ -3737,7 +3772,7 @@ class XendDomainInfo:
   1.140          dscsi = XendAPIStore.get(dev_uuid, 'DSCSI')
   1.141          devid = dscsi.get_virtual_host()
   1.142          vHCTL = dscsi.get_virtual_HCTL()
   1.143 -        cur_vscsi_sxp = self._getDeviceInfo_vscsi(devid, None)
   1.144 +        cur_vscsi_sxp = self._getDeviceInfo_vscsi(devid)
   1.145          dev_uuid = sxp.child_value(cur_vscsi_sxp, 'uuid')
   1.146  
   1.147          target_dev = None