]> 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>
Wed, 24 Jul 2013 22:46:36 +0000 (15:46 -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>
(cherry picked from commit e082f1247fb6ddfb36c4223cbfdf500d6b45c978)

src/ceph-disk

index 36c75b5d598111597a7ab933acca5fb3f7e9841a..643eb588a4083d99b1c88d6ecf04ea97d9853cdd 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):