[PATCH] Add dracutSetupString() method to ZFCPDiskDevice (#526354).

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Collect CCW bus ID, WWPN, and FCP LUN values for zFCP devices when
building the device tree.  Store these in the ZFCPDiskDevice object and
use them to generate the rd_ZFCP= string for dracut.

Expand storage/udev.py with functions to determine if a device is zFCP,
get a zFCP device's bus ID, and get arbitrary attribute values.
---
 storage/devices.py    |   23 +++++++++++------------
 storage/devicetree.py |    8 ++++++++
 storage/udev.py       |   35 +++++++++++++++++++++++++++++++++++
 3 files changed, 54 insertions(+), 12 deletions(-)

diff --git a/storage/devices.py b/storage/devices.py
index b76402c..19b4c3c 100644
--- a/storage/devices.py
+++ b/storage/devices.py
@@ -3135,23 +3135,22 @@ class ZFCPDiskDevice(DiskDevice):
     """ A mainframe ZFCP disk. """
     _type = "zfcp"
 
-    def __init__(self, name, size=None, major=None, minor=None,
-                 devnum=None, wwpn=None, fcplun=None,
-                 parents=None, sysfsPath=''):
-        self.devnum = devnum
-        self.wwpn = wwpn
-        self.fcplun = fcplun
-        name = "zfcp://%s/%s/%s" % (self.devnum, self.wwpn, self.fcplun)
-        DiskDevice.__init__(self, name, size=size,
-                            major=major, minor=minor,
-                            parents=parents, sysfsPath=sysfsPath)
+    def __init__(self, name, **kwargs):
+        self.busid = kwargs.get("busid")
+        self.wwpn = kwargs.get("wwpn")
+        self.fcp_lun = kwargs.get("fcp_lun")
+        name = "zfcp://%s/%s/%s" % (self.busid, self.wwpn, self.fcplun,)
+        DiskDevice.__init__(self, name, **kwargs)
 
     def __str__(self):
         s = DiskDevice.__str__(self)
-        s += ("  devnum = %(devnum)s  wwpn = %(wwpn)s  fcplun = %(fcplun)s" %
-              {"devnum": self.devnum, "wwpn": self.wwpn, "fcplun": self.fcplun})
+        s += ("  busid = %(busid)s  wwpn = %(wwpn)s  fcp_lun = %(fcp_lun)s" %
+              {"busid": self.busid, "wwpn": self.wwpn, "fcp_lun": self.fcp_lun})
         return s
 
+    def dracutSetupString(self):
+        return "rd_ZFCP=%s,%s,%s" % (self.busid, self.wwpn, self.fcp_lun,)
+
 
 class DASDDevice(DiskDevice):
     """ A mainframe DASD. """
diff --git a/storage/devicetree.py b/storage/devicetree.py
index 1aae2a9..1b5358a 100644
--- a/storage/devicetree.py
+++ b/storage/devicetree.py
@@ -1199,6 +1199,14 @@ class DeviceTree(object):
                 kwargs["opts"][attr] = udev_device_get_dasd_flag(info, attr)
 
             log.debug("%s is a dasd device" % name)
+        elif udev_device_is_zfcp(info):
+            diskType = ZFCPDiskDevice
+            kwargs["busid"] = udev_device_get_zfcp_bus_id(info)
+
+            for attr in ['wwpn', 'fcp_lun']:
+                kwargs[attr] = udev_device_get_zfcp_attribute(info, attr=attr)
+
+            log.debug("%s is a zfcp device" % name)
         else:
             diskType = DiskDevice
             log.debug("%s is a disk" % name)
diff --git a/storage/udev.py b/storage/udev.py
index 1af2289..3318602 100644
--- a/storage/udev.py
+++ b/storage/udev.py
@@ -180,6 +180,41 @@ def udev_device_get_dasd_flag(info, flag=None):
 
     return open(path, 'r').read().strip()
 
+def udev_device_is_zfcp(info):
+    """ Return True if the device is a zfcp device. """
+    bypath = False
+    devdir = os.path.realpath("/sys" + info.get("sysfs_path") + "/device")
+    wwpn = os.path.realpath(devdir + "/wwpn")
+    fcplun = os.path.realpath(devdir + "/fcp_lun")
+
+    for symlink in info.get("symlinks"):
+        if symlink.startswith("disk/by-path") and symlink.find("zfcp") != -1:
+            bypath = True
+            break
+
+    if bypath and os.path.isdir(devdir) and \
+       os.path.isfile(wwpn) and os.path.isfile(fcplun):
+        return True
+
+    return False
+
+def udev_device_get_zfcp_bus_id(info):
+    """ Return the CCW bus ID of the zfcp device. """
+    return info.get("sysfs_path").split("/")[4]
+
+def udev_device_get_zfcp_attribute(info, attr=None):
+    """ Return the value of the specified attribute of the zfcp device. """
+    if not attr:
+        return None
+
+    attribute = "/sys%s/devices/%s" % (info.get("sysfs_path"), attr,)
+    attribute = os.path.realpath(attribute)
+
+    if not os.path.isfile(attribute):
+        return None
+
+    return open(attribute, "r").read().strip()
+
 def udev_device_is_cdrom(info):
     """ Return True if the device is an optical drive. """
     # FIXME: how can we differentiate USB drives from CD-ROM drives?
-- 
1.6.2.5

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux