From: Alexandre Maragone Date: Tue, 18 Jun 2013 23:18:01 +0000 (-0700) Subject: ceph-disk: make list_partition behave with unusual device names X-Git-Tag: v0.65~30 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8c0daafe003935881c5192e0b6b59b949269e5ae;p=ceph.git ceph-disk: make list_partition behave with unusual device names When you get device names like sdaa you do not want to mistakenly conclude that sdaa is a partition of sda. Use /sys/block/$device/$partition existence instead. Fixes: #5211 Backport: cuttlefish Signed-off-by: Alexandre Maragone Reviewed-by: Sage Weil --- diff --git a/src/ceph-disk b/src/ceph-disk index bd7e6206ae82..93864c1c0085 100755 --- a/src/ceph-disk +++ b/src/ceph-disk @@ -206,16 +206,11 @@ def list_partitions(disk): disk = os.path.realpath(disk) assert not is_partition(disk) assert disk.startswith('/dev/') - base = disk[5:] + base = disk.split('/')[-1] partitions = [] - 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] - if name != base and name.startswith(base): - partitions.append('/dev/' + name) + for name in os.listdir(os.path.join('/sys/block', base)): + if name.startswith(base): + partitions.append('/dev/' + name) return partitions