From: Sage Weil Date: Thu, 28 Mar 2013 01:44:32 +0000 (-0700) Subject: ceph-disk: reimplement list_all_partitions X-Git-Tag: v0.62~137^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=d3e49047ff405573aa41f45864cf315be23f5c50;p=ceph.git ceph-disk: reimplement list_all_partitions Use /dev/disk/by-id to list disks and their partitions. This is more accurate and correct than the previous (as-yet unused) implementation. Signed-off-by: Sage Weil --- diff --git a/src/ceph-disk b/src/ceph-disk index bce09e0ccd9d..750ec2400cbf 100755 --- a/src/ceph-disk +++ b/src/ceph-disk @@ -131,24 +131,21 @@ def list_all_partitions(): Return a list of devices and partitions """ dev_part_list = {} - with file('/proc/partitions', 'rb') as proc_partitions: - for line in proc_partitions.read().split('\n')[2:]: - fields = re.split('\s+', line) - if len(fields) < 5: - continue - name = fields[4] - name = '/dev/' + name - if "dm-" in name: - if "/dev/dm" not in dev_part_list: - dev_part_list["/dev/dm"] = [] - dev_part_list["/dev/dm"].append(name) - if name[-1].isdigit(): - base = name - while base[-1].isdigit(): - base = base[:-1] - dev_part_list[base].append(name) - else: - dev_part_list[name] = [] + for name in os.listdir('/dev/disk/by-path'): + target = os.readlink(os.path.join('/dev/disk/by-path', name)) + dev = target.split('/')[-1] + #print "name %s target %s dev %s" % (name, target, dev) + (baser) = re.search('(.*)-part\d+$', name) + if baser is not None: + basename = baser.group(1) + #print 'basename %s' % basename + base = os.readlink(os.path.join('/dev/disk/by-path', basename)).split('/')[-1] + if base not in dev_part_list: + dev_part_list[base] = [] + dev_part_list[base].append(dev) + else: + if dev not in dev_part_list: + dev_part_list[dev] = [] return dev_part_list