From 748971cc947c6ea5d5848ce1915c5e4d8e0ebfda Mon Sep 17 00:00:00 2001 From: Alexey Sheplyakov Date: Thu, 11 Feb 2016 12:30:26 +0300 Subject: [PATCH] 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: 76f48ff6c6a3996a7800a34cd97c5bfd4539107f Closes-Bug: #1544816 --- agent | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/agent b/agent index b5ae4e2..658a8af 100755 --- a/agent +++ b/agent @@ -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],