common/rc: don't rely on /proc/partitions for device size
authorJohannes Thumshirn <johannes.thumshirn@wdc.com>
Fri, 26 Mar 2021 15:34:37 +0000 (00:34 +0900)
committerEryu Guan <guaneryu@gmail.com>
Sun, 28 Mar 2021 16:58:45 +0000 (00:58 +0800)
Non-partitionable devices, like zoned block devices, aren't showing
up in in /proc/partitions and therefore we cannot rely on it to get
a device's size.

Use blockdev --getsz to get the block device size.

Cc: Naohiro Aota <naohiro.aota@wdc.com>
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
common/rc

index 8e5282c17566c6c5b3918c7a6a7094520db04d30..23f86ce6f3c167e5b10b38c842d13068ba08256e 100644 (file)
--- a/common/rc
+++ b/common/rc
@@ -3777,7 +3777,7 @@ _get_available_space()
 # return device size in kb
 _get_device_size()
 {
 # return device size in kb
 _get_device_size()
 {
-       grep -w `_short_dev $1` /proc/partitions | awk '{print $3}'
+       echo $(($(blockdev --getsz $1) >> 1))
 }
 
 # Make sure we actually have dmesg checking set up.
 }
 
 # Make sure we actually have dmesg checking set up.