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-24 15:46:37 -0700
commit1f8e4b15eeb132fd7f389318009b19f8f13adbf5 (patch)
tree7385cbdadcd666295c9ee9f2d1a1dd35f6d4a1ed
parent0a08c8226cb3e461301beade9bab2e264d1b960e (diff)
downloadceph-1f8e4b15eeb132fd7f389318009b19f8f13adbf5.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> (cherry picked from commit 2ea8fac441141d64ee0d26c5dd2b441f9782d840)
-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: