From e082f1247fb6ddfb36c4223cbfdf500d6b45c978 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 17 Jun 2013 20:54:15 -0700 Subject: [PATCH] ceph-disk: make is_held() smarter about full disks 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 --- src/ceph-disk | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/ceph-disk b/src/ceph-disk index e77a8560ec20d..13f434882c8d7 100755 --- a/src/ceph-disk +++ b/src/ceph-disk @@ -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): -- 2.39.5