]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-disk: reimplement is_partition() using /sys/block
authorSage Weil <sage@inktank.com>
Wed, 3 Jul 2013 18:01:58 +0000 (11:01 -0700)
committerSage Weil <sage@inktank.com>
Tue, 16 Jul 2013 22:51:44 +0000 (15:51 -0700)
Signed-off-by: Sage Weil <sage@inktank.com>
src/ceph-disk

index d088bcc60f4e6e11f4a1729ff15728035dca7e4c..d19c5ae39d9d428b61cbcc88260309d0f7bb8d64 100755 (executable)
@@ -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):