WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] xend: Accept udev events about SCSI and u

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] xend: Accept udev events about SCSI and update physical SCSI information
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Tue, 07 Apr 2009 23:00:34 -0700
Delivery-date: Tue, 07 Apr 2009 23:02:03 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1238495329 -3600
# Node ID 46188402c2d9381c4aeb713e775ddc1e9b58c591
# Parent  2ef77b4bdf589642aab55c24bbc0b2ced0d2752c
xend: Accept udev events about SCSI and update physical SCSI information

Signed-off-by: Masaki Kanno <kanno.masaki@xxxxxxxxxxxxxx>
---
 tools/hotplug/Linux/xend.rules            |    2 
 tools/python/xen/util/vscsi_util.py       |   80 ++++++++++++++++--------------
 tools/python/xen/xend/XendNode.py         |   40 ++++++++++++---
 tools/python/xen/xend/server/udevevent.py |   22 ++++++--
 4 files changed, 95 insertions(+), 49 deletions(-)

diff -r 2ef77b4bdf58 -r 46188402c2d9 tools/hotplug/Linux/xend.rules
--- a/tools/hotplug/Linux/xend.rules    Tue Mar 31 11:28:08 2009 +0100
+++ b/tools/hotplug/Linux/xend.rules    Tue Mar 31 11:28:49 2009 +0100
@@ -1,3 +1,3 @@ SUBSYSTEM=="pci", RUN+="socket:/org/xen/
 SUBSYSTEM=="pci", RUN+="socket:/org/xen/xend/udev_event"
-#SUBSYSTEM=="scsi", RUN+="socket:/org/xen/xend/udev_event"
+SUBSYSTEM=="scsi", RUN+="socket:/org/xen/xend/udev_event"
 #SUBSYSTEM=="net", KERNEL!="vif[0-9]*.[0-9]*|tap[0-9]*.[0-9]*", 
RUN+="socket:/org/xen/xend/udev_event"
diff -r 2ef77b4bdf58 -r 46188402c2d9 tools/python/xen/util/vscsi_util.py
--- a/tools/python/xen/util/vscsi_util.py       Tue Mar 31 11:28:08 2009 +0100
+++ b/tools/python/xen/util/vscsi_util.py       Tue Mar 31 11:28:49 2009 +0100
@@ -231,40 +231,50 @@ def get_scsi_scsilevel(pHCTL):
     except:
         return None
 
+def _make_scsi_record(scsi_info):
+    scsi_rec = {
+        'physical_HCTL': scsi_info[0],
+        'dev_name': None,
+        'sg_name': scsi_info[2],
+        'scsi_id': None
+    }
+    if scsi_info[1] is not None:
+        scsi_rec['dev_name'] = scsi_info[1] 
+    if scsi_info[3] is not None:
+        scsi_rec['scsi_id'] = scsi_info[3] 
+
+    scsi_rec['vendor_name'] = \
+        get_scsi_vendor(scsi_rec['physical_HCTL'])
+    scsi_rec['model'] = \
+        get_scsi_model(scsi_rec['physical_HCTL'])
+    scsi_rec['type_id'] = \
+        get_scsi_typeid(scsi_rec['physical_HCTL'])
+    scsi_rec['revision'] = \
+        get_scsi_revision(scsi_rec['physical_HCTL'])
+    scsi_rec['scsi_level'] = \
+        get_scsi_scsilevel(scsi_rec['physical_HCTL'])
+
+    try:
+        lsscsi_info = os.popen('lsscsi %s 2>/dev/null' % 
scsi_rec['physical_HCTL']).read().split()
+        scsi_rec['type'] = lsscsi_info[1]
+    except:
+        scsi_rec['type'] = None
+
+    return scsi_rec
+
+def get_scsi_device(pHCTL):
+    scsis_info = _vscsi_get_scsidevices_by_lsscsi(pHCTL)
+    if not scsis_info:
+        scsis_info = _vscsi_get_scsidevices_by_sysfs()
+    for scsi_info in scsis_info:
+        if scsi_info[0] == pHCTL:
+            return _make_scsi_record(scsi_info)
+    return None
+
 def get_all_scsi_devices():
-
-    scsi_devs = []
-
+    scsi_records = []
     for scsi_info in vscsi_get_scsidevices():
-        scsi_dev = {
-            'physical_HCTL': scsi_info[0],
-            'dev_name': None,
-            'sg_name': scsi_info[2],
-            'scsi_id': None
-        }
-        if scsi_info[1] is not None:
-            scsi_dev['dev_name'] = scsi_info[1] 
-        if scsi_info[3] is not None:
-            scsi_dev['scsi_id'] = scsi_info[3] 
-
-        scsi_dev['vendor_name'] = \
-            get_scsi_vendor(scsi_dev['physical_HCTL'])
-        scsi_dev['model'] = \
-            get_scsi_model(scsi_dev['physical_HCTL'])
-        scsi_dev['type_id'] = \
-            get_scsi_typeid(scsi_dev['physical_HCTL'])
-        scsi_dev['revision'] = \
-            get_scsi_revision(scsi_dev['physical_HCTL'])
-        scsi_dev['scsi_level'] = \
-            get_scsi_scsilevel(scsi_dev['physical_HCTL'])
-
-        try:
-            lsscsi_info = os.popen('lsscsi %s 2>/dev/null' % 
scsi_dev['physical_HCTL']).read().split()
-            scsi_dev['type'] = lsscsi_info[1]
-        except:
-            scsi_dev['type'] = None
-
-        scsi_devs.append(scsi_dev)
-
-    return scsi_devs
-
+        scsi_record = _make_scsi_record(scsi_info)
+        scsi_records.append(scsi_record)
+    return scsi_records
+
diff -r 2ef77b4bdf58 -r 46188402c2d9 tools/python/xen/xend/XendNode.py
--- a/tools/python/xen/xend/XendNode.py Tue Mar 31 11:28:08 2009 +0100
+++ b/tools/python/xen/xend/XendNode.py Tue Mar 31 11:28:49 2009 +0100
@@ -378,14 +378,38 @@ class XendNode:
         self.save_PPCIs()
 
 
-    def add_PSCSI(self):
-        # TODO
-        log.debug("add_network(): Not implemented.")
-
-
-    def remove_PSCSI(self):
-        # TODO
-        log.debug("add_network(): Not implemented.")
+    def add_PSCSI(self, add_HCTL):
+        saved_pscsis = self.state_store.load_state('pscsi')
+        saved_pscsi_table = {}
+        if saved_pscsis:
+            for saved_uuid, saved_record in saved_pscsis.items():
+                try:
+                    saved_pscsi_table[saved_record['scsi_id']] = saved_uuid
+                except KeyError:
+                    pass
+
+        # Initialise the PSCSI
+        pscsi_record = vscsi_util.get_scsi_device(add_HCTL)
+        if pscsi_record and pscsi_record['scsi_id']:
+            pscsi_uuid = saved_pscsi_table.get(pscsi_record['scsi_id'], None)
+            if pscsi_uuid is None:
+                pscsi_uuid = uuid.createString()
+                XendPSCSI(pscsi_uuid, pscsi_record)
+                self.save_PSCSIs()
+
+
+    def remove_PSCSI(self, rem_HCTL):
+        saved_pscsis = self.state_store.load_state('pscsi')
+        if not saved_pscsis:
+            return
+
+        # Remove the PSCSI
+        for pscsi_record in saved_pscsis.values():
+            if rem_HCTL == pscsi_record['physical_HCTL']:
+                pscsi_ref = XendPSCSI.get_by_HCTL(rem_HCTL)
+                XendAPIStore.get(pscsi_ref, "PSCSI").destroy()
+                self.save_PSCSIs()
+                return
 
 
 ##    def network_destroy(self, net_uuid):
diff -r 2ef77b4bdf58 -r 46188402c2d9 tools/python/xen/xend/server/udevevent.py
--- a/tools/python/xen/xend/server/udevevent.py Tue Mar 31 11:28:08 2009 +0100
+++ b/tools/python/xen/xend/server/udevevent.py Tue Mar 31 11:28:49 2009 +0100
@@ -40,13 +40,25 @@ class UdevEventProtocol(protocol.Protoco
                     log.info("Removing pci device %s", pci_name)
                     XendNode.instance().remove_PPCI(pci_name)
 
-            elif (udev_event.get('SUBSYSTEMS', None) == 'scsi'):
+            elif (udev_event.get('SUBSYSTEM', None) == 'scsi'):
+                hctl = None
+                devpath = udev_event.get('DEVPATH', None)
+                if devpath:
+                    hctl = devpath.split('/')[-1]
+                    if len(hctl.split(':')) != 4:
+                        hctl = None
+                if hctl is None:
+                    # By any possibility, if an HCTL isn't gotten from
+                    # the udev event, the udev event is ignored.
+                    log.warn("Invalid udev event about scsi received")
+                    return
+
                 if (udev_event['ACTION'] == 'add'):
-                    log.info("Adding scsi device")
-                    XendNode.instance().add_PSCSI()
+                    log.info("Adding scsi device %s", hctl)
+                    XendNode.instance().add_PSCSI(hctl)
                 elif (udev_event['ACTION'] == 'remove'):
-                    log.info("Removing scci device")
-                    XendNode.instance().remove_PSCSI()
+                    log.info("Removing scsi device %s", hctl)
+                    XendNode.instance().remove_PSCSI(hctl)
 
             elif (udev_event.get('SUBSYSTEM', None) == 'net'):
                 interface = udev_event.get('INTERFACE', None)

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] xend: Accept udev events about SCSI and update physical SCSI information, Xen patchbot-unstable <=