]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-disk: reimplement list_all_partitions
authorSage Weil <sage@inktank.com>
Thu, 28 Mar 2013 01:44:32 +0000 (18:44 -0700)
committerSage Weil <sage@inktank.com>
Fri, 26 Apr 2013 20:40:06 +0000 (13:40 -0700)
Use /dev/disk/by-id to list disks and their partitions.  This is more
accurate and correct than the previous (as-yet unused) implementation.

Signed-off-by: Sage Weil <sage@inktank.com>
(cherry picked from commit d3e49047ff405573aa41f45864cf315be23f5c50)

src/ceph-disk

index 6b3145131fa721ceb9b3298ff8d37eded82f2cd1..f48686dc88d8fe243d39f445421a4111e0c947e5 100755 (executable)
@@ -131,24 +131,21 @@ def list_all_partitions():
     Return a list of devices and partitions
     """
     dev_part_list = {}
-    with file('/proc/partitions', 'rb') as proc_partitions:
-        for line in proc_partitions.read().split('\n')[2:]:
-            fields = re.split('\s+', line)
-            if len(fields) < 5:
-                continue
-            name = fields[4]
-            name = '/dev/' + name
-            if "dm-" in name:
-                if "/dev/dm" not in dev_part_list:
-                    dev_part_list["/dev/dm"] = []
-                dev_part_list["/dev/dm"].append(name)
-            if name[-1].isdigit():
-                base = name
-                while base[-1].isdigit():
-                    base = base[:-1]
-                    dev_part_list[base].append(name)
-            else:
-                dev_part_list[name] = []
+    for name in os.listdir('/dev/disk/by-path'):
+        target = os.readlink(os.path.join('/dev/disk/by-path', name))
+        dev = target.split('/')[-1]
+        #print "name %s target %s dev %s" % (name, target, dev)
+        (baser) = re.search('(.*)-part\d+$', name)
+        if baser is not None:
+            basename = baser.group(1)
+            #print 'basename %s' % basename
+            base = os.readlink(os.path.join('/dev/disk/by-path', basename)).split('/')[-1]
+            if base not in dev_part_list:
+                dev_part_list[base] = []
+            dev_part_list[base].append(dev)
+        else:
+            if dev not in dev_part_list:
+                dev_part_list[dev] = []
     return dev_part_list