From: Sage Weil Date: Wed, 3 Jul 2013 18:01:58 +0000 (-0700) Subject: ceph-disk: reimplement is_partition() using /sys/block X-Git-Tag: v0.67-rc1~53^2~1 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=5b031e100b40f597752b4917cdbeebb366eb98d7;p=ceph.git ceph-disk: reimplement is_partition() using /sys/block Signed-off-by: Sage Weil --- diff --git a/src/ceph-disk b/src/ceph-disk index d088bcc60f4e6..d19c5ae39d9d4 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):