summaryrefslogtreecommitdiff
path: root/rtslib/utils.py
diff options
context:
space:
mode:
authorAndy Grover <agrover@redhat.com>2013-10-11 10:52:31 -0700
committerAndy Grover <agrover@redhat.com>2013-10-11 10:53:36 -0700
commitcc7642baa47341635e264b4e370afe0b254c5caa (patch)
tree6732ec6a1acb4e0b8447c1790b10ed03606e6818 /rtslib/utils.py
parent3c640e55a9d1611360074b7cf230077c6c2c5676 (diff)
downloadrtslib-fb-cc7642baa47341635e264b4e370afe0b254c5caa.tar.gz
Fix get_blockdev_size for non-512 logical block sizes
/sys/block/x/size returns sectors, not logical blocks. We need to scale this result to return the right answer. Signed-off-by: Andy Grover <agrover@redhat.com>
Diffstat (limited to 'rtslib/utils.py')
-rw-r--r--rtslib/utils.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/rtslib/utils.py b/rtslib/utils.py
index b6b4162..b8f6e05 100644
--- a/rtslib/utils.py
+++ b/rtslib/utils.py
@@ -111,12 +111,18 @@ def is_dev_in_use(path):
def get_blockdev_size(path):
'''
- Returns the size in blocks of a disk-type block device.
+ Returns the size in logical blocks of a disk-type block device.
'''
name = os.path.basename(os.path.realpath(path))
+ # size is in 512-byte sectors, we want to return number of logical blocks
+ def get_size(path):
+ sect_size = int(fread("%s/size" % path))
+ logical_block_size = int(fread("%s/queue/logical_block_size" % path))
+ return sect_size / (logical_block_size / 512)
+
try:
- return int(fread("/sys/block/%s/size" % name))
+ return get_size("/sys/block/%s" % name)
except IOError:
# Maybe it's a partition?
m = re.search(r'^([a-z0-9_-]+)(\d+)$', name)
@@ -126,7 +132,7 @@ def get_blockdev_size(path):
disk = m.groups()[0]
if disk[-1] == 'p' and disk[-2].isdigit():
disk = disk[:-1]
- return int(fread("/sys/block/%s/%s/size" % (disk, m.group())))
+ return get_size("/sys/block/%s/%s" % (disk, m.group()))
else:
raise