]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-disk: use /sys/block to determine partition device names
authorSage Weil <sage@inktank.com>
Thu, 11 Jul 2013 19:59:56 +0000 (12:59 -0700)
committerSage Weil <sage@inktank.com>
Tue, 16 Jul 2013 22:51:44 +0000 (15:51 -0700)
Not all devices are basename + number; some have intervening character(s),
like /dev/cciss/c0d1p2.

Signed-off-by: Sage Weil <sage@inktank.com>
src/ceph-disk

index d19c5ae39d9d428b61cbcc88260309d0f7bb8d64..db988b0d5e346092d259fc094abeeb660ca2829b 100755 (executable)
@@ -224,6 +224,29 @@ def get_dev_relpath(name):
     """
     return name.replace('!', '/')
 
+
+def get_partition_dev(dev, pnum):
+    """
+    get the device name for a partition
+
+    assume that partitions are named like the base dev, with a number, and optionally
+    some intervening characters (like 'p').  e.g.,
+
+       sda 1 -> sda1
+       cciss/c0d1 1 -> cciss!c0d1p1
+    """
+    name = get_dev_name(os.path.realpath(dev))
+    partname = None
+    for f in os.listdir(os.path.join('/sys/block', name)):
+        if f.startswith(name) and f.endswith(str(pnum)):
+            # we want the shortest name that starts with the base name and ends with the partition number
+            if not partname or len(f) < len(partname):
+                partname = f
+    if partname:
+        return get_dev_path(partname)
+    else:
+        raise Error('partition %d for %s does not appear to exist' % (pnum, dev))
+
 def list_all_partitions():
     """
     Return a list of devices and partitions
@@ -1016,7 +1039,7 @@ def prepare_dev(
         except subprocess.CalledProcessError as e:
             raise Error(e)
 
-        rawdev = '{data}1'.format(data=data)
+        rawdev = get_partition_dev(data, 1)
 
     dev = None
     if osd_dm_keypath: