diff --git a/lib/ansible/module_utils/facts/hardware/linux.py b/lib/ansible/module_utils/facts/hardware/linux.py index c77c5937f23..cd0f41dcc26 100644 --- a/lib/ansible/module_utils/facts/hardware/linux.py +++ b/lib/ansible/module_utils/facts/hardware/linux.py @@ -794,12 +794,12 @@ class LinuxHardware(Hardware): part['links'][link_type] = link_values.get(partname, []) part['start'] = get_file_content(part_sysdir + "/start", 0) - part['sectors'] = get_file_content(part_sysdir + "/size", 0) - part['sectorsize'] = get_file_content(part_sysdir + "/queue/logical_block_size") if not part['sectorsize']: part['sectorsize'] = get_file_content(part_sysdir + "/queue/hw_sector_size", 512) - part['size'] = bytes_to_human((float(part['sectors']) * 512.0)) + # sysfs sectorcount assumes 512 blocksize. Convert using the correct sectorsize + part['sectors'] = int(get_file_content(part_sysdir + "/size", 0)) * 512 // int(part['sectorsize']) + part['size'] = bytes_to_human(float(part['sectors']) * float(part['sectorsize'])) part['uuid'] = get_partition_uuid(partname) self.get_holders(part, part_sysdir) @@ -813,13 +813,14 @@ class LinuxHardware(Hardware): if m: d['scheduler_mode'] = m.group(2) - d['sectors'] = get_file_content(sysdir + "/size") - if not d['sectors']: - d['sectors'] = 0 d['sectorsize'] = get_file_content(sysdir + "/queue/logical_block_size") if not d['sectorsize']: d['sectorsize'] = get_file_content(sysdir + "/queue/hw_sector_size", 512) - d['size'] = bytes_to_human(float(d['sectors']) * 512.0) + # sysfs sectorcount assumes 512 blocksize. Convert using the correct sectorsize + d['sectors'] = int(get_file_content(sysdir + "/size")) * 512 // int(d['sectorsize']) + if not d['sectors']: + d['sectors'] = 0 + d['size'] = bytes_to_human(float(d['sectors']) * float(d['sectorsize'])) d['host'] = ""