[PATCH 1/2] Get iscsi going with the new storage code

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

 



This patch gets iscsi going with the new storage code. There are still
a few hicups left (such as NetworkManager downing the interface our / is on),
but I'll address those in separate patches.
---
 backend.py            |    6 ++++--
 isys/isys.py          |    9 ---------
 storage/devices.py    |   33 ++++++++++++---------------------
 storage/devicetree.py |   15 ++++++++++++---
 storage/iscsi.py      |   40 ++++++++++++++--------------------------
 storage/udev.py       |   30 ++++++++++++++++++++++++++++++
 yuminstall.py         |    7 -------
 7 files changed, 72 insertions(+), 68 deletions(-)

diff --git a/backend.py b/backend.py
index 475785b..680f058 100644
--- a/backend.py
+++ b/backend.py
@@ -85,8 +85,10 @@ class AnacondaBackend:
         # the initrd might need iscsi-initiator-utils, and chances are
         # it was not installed yet the first time mkinitrd was run, as
         # mkinitrd does not require it.
-        for disk in anaconda.id.storage.disks:
-            if isys.driveIsIscsi(disk.path):
+        root = anaconda.id.storage.fsset.rootDevice
+        disks = anaconda.id.storage.devicetree.getDevicesByType("iscsi")
+        for disk in disks:
+            if root.dependsOn(disk):
                 has_iscsi_disk = True
                 break
 
diff --git a/isys/isys.py b/isys/isys.py
index 07c69a0..ee18666 100755
--- a/isys/isys.py
+++ b/isys/isys.py
@@ -465,15 +465,6 @@ def driveUsesModule(device, modules):
                     pass
     return rc
 
-def driveIsIscsi(device):
-    # ewww.  just ewww.
-    if not os.path.islink("/sys/block/%s/device" %(device,)):
-        return False
-    target = os.path.realpath("/sys/block/%s/device" %(device,))
-    if re.search("/platform/host[0-9]*/session[0-9]*/target[0-9]*:[0-9]*:[0-9]*/[0-9]*:[0-9]*:[0-9]*:[0-9]*", target) is not None:
-        return True
-    return False
-
 def vtActivate (num):
     if rhpl.getArch() == "s390":
         return
diff --git a/storage/devices.py b/storage/devices.py
index 397a648..2d283fc 100644
--- a/storage/devices.py
+++ b/storage/devices.py
@@ -2657,28 +2657,19 @@ class DirectoryDevice(FileDevice):
 
 
 class iScsiDiskDevice(DiskDevice):
-    """ An iSCSI volume/device/target/???.
-
-        TODO: learn what this is and how we need to use it.
-    """
+    """ An iSCSI disk. """
     _type = "iscsi"
-
-    def __init__(self, ipaddr, port,
-                 user=None, passwd=None,
-                 user_in=None, passwd_in=None,
-                 major=None, minor=None, size=None,
-                 exists=None, parents=None, sysfsPath=''):
-        name = "iscsi://%s:%s" % (ipaddr, port)
-        DiskDevice.__init__(self, name, size=size,
-                            major=major, minor=minor, exists=exists,
-                            parents=parents, sysfsPath=sysfsPath)
-    def __str__(self):
-        return "FIXME: Please add iScsiDiskDevice.__str__"
-
-    def probe(self):
-        """ Probe for any missing information about this device. """
-        raise NotImplementedError("probe method not defined for StorageDevice")
-
+    _packages = ["iscsi-initiator-utils"]
+
+    def __init__(self, device, **kwargs):
+        self.iscsi_name    = kwargs["iscsi_name"]
+        self.iscsi_address = kwargs["iscsi_address"]
+        self.iscsi_port    = int(kwargs["iscsi_port"])
+        del kwargs["iscsi_name"]
+        del kwargs["iscsi_address"]
+        del kwargs["iscsi_port"]
+        DiskDevice.__init__(self, device, **kwargs)
+        log.debug("created new iscsi disk %s %s:%d" % (self.iscsi_name, self.iscsi_address, self.iscsi_port))
 
 class OpticalDevice(StorageDevice):
     """ An optical drive, eg: cdrom, dvd+r, &c.
diff --git a/storage/devicetree.py b/storage/devicetree.py
index b015b55..1ec211a 100644
--- a/storage/devicetree.py
+++ b/storage/devicetree.py
@@ -997,7 +997,16 @@ class DeviceTree(object):
                                 sysfsPath=sysfs_path, exists=True)
                 self._addDevice(device)
         elif udev_device_is_disk(info):
-            log.debug("%s is a disk" % name)
+            kwargs = {}
+            if udev_device_is_iscsi(info):
+                diskType = iScsiDiskDevice
+                kwargs["iscsi_name"]    = udev_device_get_iscsi_name(info)
+                kwargs["iscsi_address"] = udev_device_get_iscsi_address(info)
+                kwargs["iscsi_port"]    = udev_device_get_iscsi_port(info)
+                log.debug("%s is an iscsi disk" % name)
+            else:
+                diskType = DiskDevice
+                log.debug("%s is a disk" % name)
             device = self.getDeviceByName(name)
             if device is None:
                 try:
@@ -1020,11 +1029,11 @@ class DeviceTree(object):
                     else:
                         initlabel = False
 
-                    device = DiskDevice(name,
+                    device = diskType(name,
                                     major=udev_device_get_major(info),
                                     minor=udev_device_get_minor(info),
                                     sysfsPath=sysfs_path,
-                                    initcb=cb, initlabel=initlabel)
+                                    initcb=cb, initlabel=initlabel, **kwargs)
                     self._addDevice(device)
                 except DeviceUserDeniedFormatError: #drive not initialized?
                     self.addIgnoredDisk(name)
diff --git a/storage/iscsi.py b/storage/iscsi.py
index fff6ad1..1add6ee 100644
--- a/storage/iscsi.py
+++ b/storage/iscsi.py
@@ -88,19 +88,6 @@ def iscsi_get_node_record(node_settings, record):
 
     return None
 
-# FIXME replace with libiscsi use
-def iscsi_make_node_autostart(disk):
-    sysfs_path = os.path.realpath("/sys/block/%s/device" %(disk,))
-    argv = [ "-m", "session", "-r", sysfs_path ]
-    log.debug("iscsiadm %s" %(string.join(argv),))
-    node_settings = iutil.execWithCapture(ISCSIADM, argv, stderr="/dev/tty5").splitlines()
-    node_name = iscsi_get_node_record(node_settings, "node.name")
-    argv = [ "-m", "node", "-T", node_name, "-o", "update", "-n",
-             "node.startup", "-v", "automatic" ]
-    log.debug("iscsiadm %s" %(string.join(argv),))
-    iutil.execWithRedirect(ISCSIADM, argv,
-                                stdout = "/dev/tty5", stderr="/dev/tty5")
-
 def randomIname():
     """Generate a random initiator name the same way as iscsi-iname"""
     
@@ -297,20 +284,21 @@ class iscsi(object):
             return
 
         if not flags.test:
-            root_drives = [ ]
             root = anaconda.id.storage.fsset.rootDevice
-            root_deps = anaconda.id.storage.deviceDeps(root)
-            for dev in root_deps:
-                if dev in anaconda.id.storage.disks and \
-                   dev not in root_drives:
-                    root_drives.append(dev.path)
-
-            log.debug("iscsi.write: root_drives: %s" % (string.join(root_drives),))
-
-            # set iscsi nodes not used for root to autostart
-            for disk in anaconda.id.storage.disks:
-                if isys.driveIsIscsi(disk.path) and not disk in root_drives:
-                    iscsi_make_node_autostart(disk.path)
+            disks = anaconda.id.storage.devicetree.getDevicesByType("iscsi")
+
+            # set iscsi nodes to autostart
+            for disk in disks:
+                # devices used for root get started by the initrd
+                if root.dependsOn(disk):
+                    continue
+                # find the iscsi node matching this disk
+                for node in self.nodes:
+                    if node.name    == disk.iscsi_name and \
+                       node.address == disk.iscsi_address and \
+                       node.port    == disk.iscsi_port:
+                        node.setParameter("node.startup", "automatic");
+                        break
 
             if not os.path.isdir(instPath + "/etc/iscsi"):
                 os.makedirs(instPath + "/etc/iscsi", 0755)
diff --git a/storage/udev.py b/storage/udev.py
index 1263823..a6d3190 100644
--- a/storage/udev.py
+++ b/storage/udev.py
@@ -304,3 +304,33 @@ def udev_device_is_dmraid_partition(info, devicetree):
             return True
 
     return False
+
+# iscsi disks have ID_PATH in the form of:
+# ip-${iscsi_address}:${iscsi_port}-iscsi-${iscsi_tgtname}-lun-${lun}
+def udev_device_is_iscsi(info):
+    try:
+        path_components = info["ID_PATH"].split("-")
+
+        if info["ID_BUS"] == "scsi" and len(path_components) >= 6 and \
+           path_components[0] == "ip" and path_components[2] == "iscsi":
+            return True
+    except KeyError:
+        pass
+
+    return False
+
+def udev_device_get_iscsi_name(info):
+    path_components = info["ID_PATH"].split("-")
+
+    # Tricky, the name itself contains atleast 1 - char
+    return "-".join(path_components[3:len(path_components)-2])
+
+def udev_device_get_iscsi_address(info):
+    path_components = info["ID_PATH"].split("-")
+
+    return path_components[1].split(":")[0]
+
+def udev_device_get_iscsi_port(info):
+    path_components = info["ID_PATH"].split("-")
+
+    return path_components[1].split(":")[1]
diff --git a/yuminstall.py b/yuminstall.py
index eff50ba..d842a17 100644
--- a/yuminstall.py
+++ b/yuminstall.py
@@ -1287,13 +1287,6 @@ reposdir=/etc/anaconda.repos.d,/tmp/updates/anaconda.repos.d,/tmp/product/anacon
             # this takes care of device and filesystem packages
             map(self.selectPackage, device.packages)
 
-        for disk in storage.disks:
-            # FIXME: this should get handled by the above
-            if isys.driveIsIscsi(disk.path):
-                log.info("ensuring iscsi is installed")
-                self.selectPackage("iscsi-initiator-utils")
-                break
-
     # anaconda requires several programs on the installed system to complete
     # installation, but we have no guarantees that some of these will be
     # installed (they could have been removed in kickstart).  So we'll force
-- 
1.6.1.3

_______________________________________________
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