diff options
author | Sage Weil <sage@inktank.com> | 2013-07-03 11:01:58 -0700 |
---|---|---|
committer | Sage Weil <sage@inktank.com> | 2013-07-16 15:51:44 -0700 |
commit | 5b031e100b40f597752b4917cdbeebb366eb98d7 (patch) | |
tree | 2f9bf77621dc3b4c1aafbe367ead8e2cb0ff1577 | |
parent | 3359aaedde838c98d1155611e157fd2da9e8b9f5 (diff) | |
download | ceph-5b031e100b40f597752b4917cdbeebb366eb98d7.tar.gz |
ceph-disk: reimplement is_partition() using /sys/block
Signed-off-by: Sage Weil <sage@inktank.com>
-rwxr-xr-x | src/ceph-disk | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/src/ceph-disk b/src/ceph-disk index d088bcc60f4..d19c5ae39d9 100755 --- a/src/ceph-disk +++ b/src/ceph-disk @@ -248,29 +248,22 @@ def list_partitions(basename): def is_partition(dev): """ - Check whether a given device is a partition or a full disk. + Check whether a given device path is a partition or a full disk. """ dev = os.path.realpath(dev) if not stat.S_ISBLK(os.lstat(dev).st_mode): raise Error('not a block device', dev) - # 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: + name = get_dev_name(dev) + if os.path.exists(os.path.join('/sys/block', name)): + return False + + # make sure it is a partition of something else + for basename in os.listdir('/sys/block'): + if os.path.exists(os.path.join('/sys/block', basename, name)): return True - else: - return False - # hrm, don't know... - return False + raise Error('not a disk or partition', dev) def is_mounted(dev): |