diff options
author | Sage Weil <sage@inktank.com> | 2013-03-27 18:43:59 -0700 |
---|---|---|
committer | Sage Weil <sage@inktank.com> | 2013-04-26 13:40:06 -0700 |
commit | 9da81e4e798b8e5593f3a7eda6dfa8586307121f (patch) | |
tree | d572e8388a803bea9796de13f9df2ae5eaa85432 | |
parent | 0c8efc0664f068a1952fe54b8034d005cf3f9ce8 (diff) | |
download | ceph-9da81e4e798b8e5593f3a7eda6dfa8586307121f.tar.gz |
ceph-disk: reimplement is_partition
Previously we were assuming any device that ended in a digit was a
partition, but this is not at all correct (e.g., /dev/sr0, /dev/rbd1).
Instead, look in /dev/disk/by-id and see if there is a symlink that ends in
-partNN that links to our device.
There is probably still a better way...
Signed-off-by: Sage Weil <sage@inktank.com>
(cherry picked from commit 20d594a889d62110ad03b761d8703f79f8eea6ad)
-rwxr-xr-x | src/ceph-disk | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/ceph-disk b/src/ceph-disk index 5c5f82ad007..6b3145131fa 100755 --- a/src/ceph-disk +++ b/src/ceph-disk @@ -180,9 +180,22 @@ def is_partition(dev): if not stat.S_ISBLK(os.lstat(dev).st_mode): raise Error('not a block device', dev) - # if the device ends in a number, it is a partition (e.g., /dev/sda3) - if dev[-1].isdigit(): - return True + # we can't tell just from the name of the device if it is a + # partition or not. look in the by-path dir and see if the + # referring symlink ends in -partNNN. + name = dev.split('/')[-1] + for name in os.listdir('/dev/disk/by-path'): + target = os.readlink(os.path.join('/dev/disk/by-path', name)) + cdev = target.split('/')[-1] + if '/dev/' + cdev != dev: + continue + (baser) = re.search('(.*)-part\d+$', name) + if baser is not None: + return True + else: + return False + + # hrm, don't know... return False |