Fix hard drive size miscalculation

On Linux ohai gets the block device size from /sys/block/$device/size.
That size is always measured in units of 512 bytes even if the "physical"
block size of the device in question is different [1][2]. On the other hand
/sys/block/$device/queue/logical_block_size is the smallest unit which
the device can address, and /sys/block/$device/queue/physical_block_size
is the smallest unit the physical storage device can write atomically.
Typically SATA/SAS drives having the size >= 2 TB have 4 KB physical
sectors and expose 512 "logical" block size to the operating system.
However some hard drives (for instance, HGST Ultrastar 7K6000 SAS drive)
expose the actual physical sector size (that is, 4 KB) for the efficiency
reasons. As a result nailgun-agent miscomputes the size of the hard drive
(it's 8x off!)

[1] http://lxr.free-electrons.com/source/include/linux/types.h?v=4.4#L124
[2] http://lxr.free-electrons.com/source/drivers/scsi/sd.c?v=4.4#L2340

Change-Id: Iae36b11dce8e6f43d7ee4bddac5098c633883ed6
Cherry-pick from: 76f48ff6c6
Closes-Bug: #1544816
This commit is contained in:
Alexey Sheplyakov 2016-02-11 12:30:26 +03:00 committed by Denis Puchkin
parent 71361290d2
commit 748971cc94
1 changed files with 6 additions and 4 deletions

10
agent
View File

@ -383,11 +383,13 @@ class NodeAgent
end
dname = bname.gsub(/!/, '/')
# 512 bytes is the size of one sector by default
# ohai reports the disk size according to /sys/block/#{bname}
# which is always measured in 512 bytes blocks, no matter what
# the physical (minimal unit which can be atomically written)
# or logical (minimal # unit which can be addressed) block sizes are, see
# http://lxr.free-electrons.com/source/include/linux/types.h?v=4.4#L124
# http://lxr.free-electrons.com/source/drivers/scsi/sd.c?v=4.4#L2340
block_size = 512
fn = "/sys/block/#{bname}/queue/logical_block_size"
block_size = File.read(fn).to_i if File.exist? fn
block_size = 512 if block_size == 0
detailed_meta[:disks] << {
:name => dname,
:model => binfo[:model],