ia64/xen-unstable

changeset 19449:46188402c2d9

xend: Accept udev events about SCSI and update physical SCSI information

Signed-off-by: Masaki Kanno <kanno.masaki@jp.fujitsu.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Mar 31 11:28:49 2009 +0100 (2009-03-31)
parents 2ef77b4bdf58
children b183684130fd
files tools/hotplug/Linux/xend.rules tools/python/xen/util/vscsi_util.py tools/python/xen/xend/XendNode.py tools/python/xen/xend/server/udevevent.py
line diff
     1.1 --- a/tools/hotplug/Linux/xend.rules	Tue Mar 31 11:28:08 2009 +0100
     1.2 +++ b/tools/hotplug/Linux/xend.rules	Tue Mar 31 11:28:49 2009 +0100
     1.3 @@ -1,3 +1,3 @@
     1.4  SUBSYSTEM=="pci", RUN+="socket:/org/xen/xend/udev_event"
     1.5 -#SUBSYSTEM=="scsi", RUN+="socket:/org/xen/xend/udev_event"
     1.6 +SUBSYSTEM=="scsi", RUN+="socket:/org/xen/xend/udev_event"
     1.7  #SUBSYSTEM=="net", KERNEL!="vif[0-9]*.[0-9]*|tap[0-9]*.[0-9]*", RUN+="socket:/org/xen/xend/udev_event"
     2.1 --- a/tools/python/xen/util/vscsi_util.py	Tue Mar 31 11:28:08 2009 +0100
     2.2 +++ b/tools/python/xen/util/vscsi_util.py	Tue Mar 31 11:28:49 2009 +0100
     2.3 @@ -231,40 +231,50 @@ def get_scsi_scsilevel(pHCTL):
     2.4      except:
     2.5          return None
     2.6  
     2.7 -def get_all_scsi_devices():
     2.8 -
     2.9 -    scsi_devs = []
    2.10 +def _make_scsi_record(scsi_info):
    2.11 +    scsi_rec = {
    2.12 +        'physical_HCTL': scsi_info[0],
    2.13 +        'dev_name': None,
    2.14 +        'sg_name': scsi_info[2],
    2.15 +        'scsi_id': None
    2.16 +    }
    2.17 +    if scsi_info[1] is not None:
    2.18 +        scsi_rec['dev_name'] = scsi_info[1] 
    2.19 +    if scsi_info[3] is not None:
    2.20 +        scsi_rec['scsi_id'] = scsi_info[3] 
    2.21  
    2.22 -    for scsi_info in vscsi_get_scsidevices():
    2.23 -        scsi_dev = {
    2.24 -            'physical_HCTL': scsi_info[0],
    2.25 -            'dev_name': None,
    2.26 -            'sg_name': scsi_info[2],
    2.27 -            'scsi_id': None
    2.28 -        }
    2.29 -        if scsi_info[1] is not None:
    2.30 -            scsi_dev['dev_name'] = scsi_info[1] 
    2.31 -        if scsi_info[3] is not None:
    2.32 -            scsi_dev['scsi_id'] = scsi_info[3] 
    2.33 +    scsi_rec['vendor_name'] = \
    2.34 +        get_scsi_vendor(scsi_rec['physical_HCTL'])
    2.35 +    scsi_rec['model'] = \
    2.36 +        get_scsi_model(scsi_rec['physical_HCTL'])
    2.37 +    scsi_rec['type_id'] = \
    2.38 +        get_scsi_typeid(scsi_rec['physical_HCTL'])
    2.39 +    scsi_rec['revision'] = \
    2.40 +        get_scsi_revision(scsi_rec['physical_HCTL'])
    2.41 +    scsi_rec['scsi_level'] = \
    2.42 +        get_scsi_scsilevel(scsi_rec['physical_HCTL'])
    2.43  
    2.44 -        scsi_dev['vendor_name'] = \
    2.45 -            get_scsi_vendor(scsi_dev['physical_HCTL'])
    2.46 -        scsi_dev['model'] = \
    2.47 -            get_scsi_model(scsi_dev['physical_HCTL'])
    2.48 -        scsi_dev['type_id'] = \
    2.49 -            get_scsi_typeid(scsi_dev['physical_HCTL'])
    2.50 -        scsi_dev['revision'] = \
    2.51 -            get_scsi_revision(scsi_dev['physical_HCTL'])
    2.52 -        scsi_dev['scsi_level'] = \
    2.53 -            get_scsi_scsilevel(scsi_dev['physical_HCTL'])
    2.54 +    try:
    2.55 +        lsscsi_info = os.popen('lsscsi %s 2>/dev/null' % scsi_rec['physical_HCTL']).read().split()
    2.56 +        scsi_rec['type'] = lsscsi_info[1]
    2.57 +    except:
    2.58 +        scsi_rec['type'] = None
    2.59 +
    2.60 +    return scsi_rec
    2.61  
    2.62 -        try:
    2.63 -            lsscsi_info = os.popen('lsscsi %s 2>/dev/null' % scsi_dev['physical_HCTL']).read().split()
    2.64 -            scsi_dev['type'] = lsscsi_info[1]
    2.65 -        except:
    2.66 -            scsi_dev['type'] = None
    2.67 +def get_scsi_device(pHCTL):
    2.68 +    scsis_info = _vscsi_get_scsidevices_by_lsscsi(pHCTL)
    2.69 +    if not scsis_info:
    2.70 +        scsis_info = _vscsi_get_scsidevices_by_sysfs()
    2.71 +    for scsi_info in scsis_info:
    2.72 +        if scsi_info[0] == pHCTL:
    2.73 +            return _make_scsi_record(scsi_info)
    2.74 +    return None
    2.75  
    2.76 -        scsi_devs.append(scsi_dev)
    2.77 +def get_all_scsi_devices():
    2.78 +    scsi_records = []
    2.79 +    for scsi_info in vscsi_get_scsidevices():
    2.80 +        scsi_record = _make_scsi_record(scsi_info)
    2.81 +        scsi_records.append(scsi_record)
    2.82 +    return scsi_records
    2.83  
    2.84 -    return scsi_devs
    2.85 -
     3.1 --- a/tools/python/xen/xend/XendNode.py	Tue Mar 31 11:28:08 2009 +0100
     3.2 +++ b/tools/python/xen/xend/XendNode.py	Tue Mar 31 11:28:49 2009 +0100
     3.3 @@ -378,14 +378,38 @@ class XendNode:
     3.4          self.save_PPCIs()
     3.5  
     3.6  
     3.7 -    def add_PSCSI(self):
     3.8 -        # TODO
     3.9 -        log.debug("add_network(): Not implemented.")
    3.10 +    def add_PSCSI(self, add_HCTL):
    3.11 +        saved_pscsis = self.state_store.load_state('pscsi')
    3.12 +        saved_pscsi_table = {}
    3.13 +        if saved_pscsis:
    3.14 +            for saved_uuid, saved_record in saved_pscsis.items():
    3.15 +                try:
    3.16 +                    saved_pscsi_table[saved_record['scsi_id']] = saved_uuid
    3.17 +                except KeyError:
    3.18 +                    pass
    3.19 +
    3.20 +        # Initialise the PSCSI
    3.21 +        pscsi_record = vscsi_util.get_scsi_device(add_HCTL)
    3.22 +        if pscsi_record and pscsi_record['scsi_id']:
    3.23 +            pscsi_uuid = saved_pscsi_table.get(pscsi_record['scsi_id'], None)
    3.24 +            if pscsi_uuid is None:
    3.25 +                pscsi_uuid = uuid.createString()
    3.26 +                XendPSCSI(pscsi_uuid, pscsi_record)
    3.27 +                self.save_PSCSIs()
    3.28  
    3.29  
    3.30 -    def remove_PSCSI(self):
    3.31 -        # TODO
    3.32 -        log.debug("add_network(): Not implemented.")
    3.33 +    def remove_PSCSI(self, rem_HCTL):
    3.34 +        saved_pscsis = self.state_store.load_state('pscsi')
    3.35 +        if not saved_pscsis:
    3.36 +            return
    3.37 +
    3.38 +        # Remove the PSCSI
    3.39 +        for pscsi_record in saved_pscsis.values():
    3.40 +            if rem_HCTL == pscsi_record['physical_HCTL']:
    3.41 +                pscsi_ref = XendPSCSI.get_by_HCTL(rem_HCTL)
    3.42 +                XendAPIStore.get(pscsi_ref, "PSCSI").destroy()
    3.43 +                self.save_PSCSIs()
    3.44 +                return
    3.45  
    3.46  
    3.47  ##    def network_destroy(self, net_uuid):
     4.1 --- a/tools/python/xen/xend/server/udevevent.py	Tue Mar 31 11:28:08 2009 +0100
     4.2 +++ b/tools/python/xen/xend/server/udevevent.py	Tue Mar 31 11:28:49 2009 +0100
     4.3 @@ -40,13 +40,25 @@ class UdevEventProtocol(protocol.Protoco
     4.4                      log.info("Removing pci device %s", pci_name)
     4.5                      XendNode.instance().remove_PPCI(pci_name)
     4.6  
     4.7 -            elif (udev_event.get('SUBSYSTEMS', None) == 'scsi'):
     4.8 +            elif (udev_event.get('SUBSYSTEM', None) == 'scsi'):
     4.9 +                hctl = None
    4.10 +                devpath = udev_event.get('DEVPATH', None)
    4.11 +                if devpath:
    4.12 +                    hctl = devpath.split('/')[-1]
    4.13 +                    if len(hctl.split(':')) != 4:
    4.14 +                        hctl = None
    4.15 +                if hctl is None:
    4.16 +                    # By any possibility, if an HCTL isn't gotten from
    4.17 +                    # the udev event, the udev event is ignored.
    4.18 +                    log.warn("Invalid udev event about scsi received")
    4.19 +                    return
    4.20 +
    4.21                  if (udev_event['ACTION'] == 'add'):
    4.22 -                    log.info("Adding scsi device")
    4.23 -                    XendNode.instance().add_PSCSI()
    4.24 +                    log.info("Adding scsi device %s", hctl)
    4.25 +                    XendNode.instance().add_PSCSI(hctl)
    4.26                  elif (udev_event['ACTION'] == 'remove'):
    4.27 -                    log.info("Removing scci device")
    4.28 -                    XendNode.instance().remove_PSCSI()
    4.29 +                    log.info("Removing scsi device %s", hctl)
    4.30 +                    XendNode.instance().remove_PSCSI(hctl)
    4.31  
    4.32              elif (udev_event.get('SUBSYSTEM', None) == 'net'):
    4.33                  interface = udev_event.get('INTERFACE', None)