diff mbox series

[v3] fstests: don't rely on /proc/partitions for device size

Message ID 20210326153437.27840-1-johannes.thumshirn@wdc.com (mailing list archive)
State New
Headers show
Series [v3] fstests: don't rely on /proc/partitions for device size | expand

Commit Message

Johannes Thumshirn March 26, 2021, 3:34 p.m. UTC
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>

---
Changes to v2:
- Don't forget the sectors to kb conversion (Damien)

Changes to v1:
- Use blockdev --getsz instead of sysfs (Nikolay/Damien)
---
 common/rc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Damien Le Moal March 28, 2021, 9:31 p.m. UTC | #1
On 2021/03/27 0:34, Johannes Thumshirn wrote:
> 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>
> 
> ---
> Changes to v2:
> - Don't forget the sectors to kb conversion (Damien)
> 
> Changes to v1:
> - Use blockdev --getsz instead of sysfs (Nikolay/Damien)
> ---
>  common/rc | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/common/rc b/common/rc
> index 1c814b9aabf1..2f295fa05484 100644
> --- a/common/rc
> +++ b/common/rc
> @@ -3778,7 +3778,7 @@ _get_available_space()
>  # 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.
> 

Looks good to me.

Reviewed-by: Damien Le Moal <damien.lemoal@wdc.com>
diff mbox series

Patch

diff --git a/common/rc b/common/rc
index 1c814b9aabf1..2f295fa05484 100644
--- a/common/rc
+++ b/common/rc
@@ -3778,7 +3778,7 @@  _get_available_space()
 # 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.