From eaf31bf9f90ba9709a57a6870dbafa21142dae2c Mon Sep 17 00:00:00 2001 From: Danny Al-Gaaf Date: Tue, 2 Apr 2013 17:33:08 +0200 Subject: [PATCH] ceph-disk: merge twice defined function is_mounted(dev) Signed-off-by: Danny Al-Gaaf --- src/ceph-disk | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/src/ceph-disk b/src/ceph-disk index d714500b0033..16a0bb1e4513 100755 --- a/src/ceph-disk +++ b/src/ceph-disk @@ -201,14 +201,18 @@ def is_mounted(dev): Check if the given device is mounted. """ dev = os.path.realpath(dev) - with file('/proc/mounts') as f: - for line in f.read().split('\n'): - d = line.split(' ')[0] - if os.path.exists(d): + with file('/proc/mounts', 'rb') as proc_mounts: + for line in proc_mounts: + fields = line.split() + if len(fields) < 3: + continue + d = fields[0] + path = fields[1] + if d.startswith('/') and os.path.exists(d): d = os.path.realpath(d) - if dev == d: - return True - return False + if d == dev: + return path + return None def is_held(dev): @@ -1645,20 +1649,6 @@ def get_partition_uuid(dev): return m.group(1).lower() return None -def is_mounted(dev): - with file('/proc/mounts', 'rb') as proc_mounts: - for line in proc_mounts: - fields = line.split() - if len(fields) < 3: - continue - d = fields[0] - path = fields[1] - if d.startswith('/') and os.path.exists(d): - d = os.path.realpath(d) - if d == dev: - return path - return None - def more_osd_info(path, uuid_map): desc = [] ceph_fsid = get_oneliner(path, 'ceph_fsid') -- 2.47.3