summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSage Weil <sage@inktank.com>2013-07-11 12:59:56 -0700
committerSage Weil <sage@inktank.com>2013-07-16 15:51:44 -0700
commit2ea8fac441141d64ee0d26c5dd2b441f9782d840 (patch)
treef29ee37c4b7044f004b0c23a61221157feba51d7
parent5b031e100b40f597752b4917cdbeebb366eb98d7 (diff)
downloadceph-2ea8fac441141d64ee0d26c5dd2b441f9782d840.tar.gz
ceph-disk: use /sys/block to determine partition device names
Not all devices are basename + number; some have intervening character(s), like /dev/cciss/c0d1p2. Signed-off-by: Sage Weil <sage@inktank.com>
-rwxr-xr-xsrc/ceph-disk25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/ceph-disk b/src/ceph-disk
index d19c5ae39d9..db988b0d5e3 100755
--- a/src/ceph-disk
+++ b/src/ceph-disk
@@ -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: