diff options
author | Sage Weil <sage@inktank.com> | 2013-03-27 18:44:32 -0700 |
---|---|---|
committer | Sage Weil <sage@inktank.com> | 2013-04-26 13:40:06 -0700 |
commit | bf3f8702c580c6b9647878837355688a2a4f954c (patch) | |
tree | cc57567df051b850d48e90409c6e9c1b9aafe73f | |
parent | 9da81e4e798b8e5593f3a7eda6dfa8586307121f (diff) | |
download | ceph-bf3f8702c580c6b9647878837355688a2a4f954c.tar.gz |
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 <sage@inktank.com>
(cherry picked from commit d3e49047ff405573aa41f45864cf315be23f5c50)
-rwxr-xr-x | src/ceph-disk | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/src/ceph-disk b/src/ceph-disk index 6b3145131fa..f48686dc88d 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 |