[rhel6-branch] Support cciss devices in get_sysfs_path_by_name().

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

 



The method assumed sysfs paths of cciss partitions are
e.g. "/sys/class/block/c0d1p1" when in fact they are
e.g. "/sys/class/block/cciss!c0d0p1" (in a manner very inconsistent with
other devices).

Resolves: rhbz#677689
---
 iutil.py                    |   15 +++++++++++++--
 storage/formats/__init__.py |    4 ++--
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/iutil.py b/iutil.py
index 3a2f7de..ae62c7c 100644
--- a/iutil.py
+++ b/iutil.py
@@ -780,12 +780,23 @@ def notify_kernel(path, action="change"):
     f.write("%s\n" % action)
     f.close()
 
-def get_sysfs_path_by_name(dev_name, class_name="block"):
-    dev_name = os.path.basename(dev_name)
+def get_sysfs_path_by_name(dev_node, class_name="block"):
+    """ Return sysfs path for a given device.
+
+        For a device node (e.g. /dev/vda2) get the respective sysfs path
+        (e.g. /sys/class/block/vda2). This also has to work for device nodes
+        that are in a subdirectory of /dev like '/dev/cciss/c0d0p1'.
+     """
+    dev_name = os.path.basename(dev_node)
+    if dev_node.startswith("/dev/"):
+        dev_name = dev_node[5:].replace("/", "!")
     sysfs_class_dir = "/sys/class/%s" % class_name
     dev_path = os.path.join(sysfs_class_dir, dev_name)
     if os.path.exists(dev_path):
         return dev_path
+    else:
+        raise RuntimeError("get_sysfs_path_by_name: Could not find sysfs path "
+                           "for '%s' (it is not at '%s')" % (dev_node, dev_path))
 
 def numeric_type(num):
     """ Verify that a value is given as a numeric data type.
diff --git a/storage/formats/__init__.py b/storage/formats/__init__.py
index 9094785..f4eee3a 100644
--- a/storage/formats/__init__.py
+++ b/storage/formats/__init__.py
@@ -246,8 +246,8 @@ class DeviceFormat(object):
             except Exception, e:
                 log.warning("failed to get dm node for %s" % self.device)
                 return
-        elif self.device:
-            name = os.path.basename(self.device)
+        else:
+            name = self.device
 
         path = get_sysfs_path_by_name(name)
         try:
-- 
1.7.3.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