]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-disk: make is_held() smarter about full disks
authorSage Weil <sage@inktank.com>
Tue, 18 Jun 2013 03:54:15 +0000 (20:54 -0700)
committerSage Weil <sage@inktank.com>
Tue, 2 Jul 2013 21:00:15 +0000 (14:00 -0700)
Handle the case where the device is a full disk.  Make the partition
check a bit more robust (don't make assumptions about naming aside from
the device being a prefix of the partition).

Signed-off-by: Sage Weil <sage@inktank.com>
src/ceph-disk

index e77a8560ec20d17f7e7149f696e19ef1524f1cb8..13f434882c8d7d300dd044d952a9904e2464f421 100755 (executable)
@@ -289,13 +289,20 @@ def is_held(dev):
     assert os.path.exists(dev)
     dev = os.path.realpath(dev)
     base = dev[5:]
-    disk = base
-    while disk[-1].isdigit():
-        disk = disk[:-1]
-    directory = '/sys/block/{disk}/{base}/holders'.format(disk=disk, base=base)
-    if not os.path.exists(directory):
-        return []
-    return os.listdir(directory)
+
+    # full disk?
+    directory = '/sys/block/{base}/holders'.format(base=base)
+    if os.path.exists(directory):
+        return os.listdir(directory)
+
+    # partition?
+    part = base
+    while len(base):
+        directory = '/sys/block/{base}/{part}/holders'.format(part=part, base=base)
+        if os.path.exists(directory):
+            return os.listdir(directory)
+        base = base[:-1]
+    return []
 
 
 def verify_not_in_use(dev):