]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-disk: add get_partition_base() helper
authorSage Weil <sage@redhat.com>
Wed, 13 Aug 2014 18:39:47 +0000 (11:39 -0700)
committerSage Weil <sage@redhat.com>
Sat, 16 Aug 2014 00:15:37 +0000 (17:15 -0700)
Return the base devices/disk for a partition device.

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

src/ceph-disk

index 398e5c89a1bb7637d7682843fca047e2a2e20421..7297da3773febbf05bf12087d9e2fdc0dc983fd8 100755 (executable)
@@ -437,6 +437,23 @@ def list_partitions(basename):
             partitions.append(name)
     return partitions
 
+def get_partition_base(dev):
+    """
+    Get the base device for a partition
+    """
+    dev = os.path.realpath(dev)
+    if not stat.S_ISBLK(os.lstat(dev).st_mode):
+        raise Error('not a block device', dev)
+
+    name = get_dev_name(dev)
+    if os.path.exists(os.path.join('/sys/block', name)):
+        raise Error('not a partition', dev)
+
+    # find the base
+    for basename in os.listdir('/sys/block'):
+        if os.path.exists(os.path.join('/sys/block', basename, name)):
+            return '/dev/' + basename
+    raise Error('no parent device for partition', dev)
 
 def is_partition(dev):
     """