diff options
author | Sage Weil <sage@inktank.com> | 2013-07-03 11:01:58 -0700 |
---|---|---|
committer | Sage Weil <sage@inktank.com> | 2013-07-24 15:46:37 -0700 |
commit | 0a08c8226cb3e461301beade9bab2e264d1b960e (patch) | |
tree | 0f80a5de0a46177904318d0b448f3bd6fe23203a | |
parent | 056000346db09ea7274a22e57cf4b86a7ea4090e (diff) | |
download | ceph-0a08c8226cb3e461301beade9bab2e264d1b960e.tar.gz |
ceph-disk: reimplement is_partition() using /sys/block
Signed-off-by: Sage Weil <sage@inktank.com>
(cherry picked from commit 5b031e100b40f597752b4917cdbeebb366eb98d7)
-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): |