From a6f10ebd572cbf95c94614a94f981ca3550fca25 Mon Sep 17 00:00:00 2001 From: Paul Cuzner Date: Tue, 30 Aug 2022 11:54:00 +1200 Subject: [PATCH] cephadm: Fix disk size calculation With native 4k sectors, the logical blocksize is set to 4096, which yields a disk size 8x the size of the actual device. According to kernel source, device size only uses 512 byte sectors, so the use of logical blocksize is unnecessary. Fixes: https://tracker.ceph.com/issues/57335 Signed-off-by: Paul Cuzner --- src/cephadm/cephadm | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm index 049048f346f..4601f7abbba 100755 --- a/src/cephadm/cephadm +++ b/src/cephadm/cephadm @@ -8437,12 +8437,15 @@ class HostFacts(): def _get_capacity(self, dev): # type: (str) -> int - """Determine the size of a given device""" + """Determine the size of a given device + + The kernel always bases device size calculations based on a 512 byte + sector. For more information see + https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/include/linux/types.h?h=v5.15.63#n120 + """ size_path = os.path.join('/sys/block', dev, 'size') size_blocks = int(read_file([size_path])) - blk_path = os.path.join('/sys/block', dev, 'queue', 'logical_block_size') - blk_count = int(read_file([blk_path])) - return size_blocks * blk_count + return size_blocks * 512 def _get_capacity_by_type(self, disk_type='hdd'): # type: (str) -> int -- 2.39.5