diff mbox series

fstests: don't relay on /proc/partitions for device size

Message ID 20210325112337.35102-1-johannes.thumshirn@wdc.com (mailing list archive)
State New, archived
Headers show
Series fstests: don't relay on /proc/partitions for device size | expand

Commit Message

Johannes Thumshirn March 25, 2021, 11:23 a.m. UTC
Non-partitionable devices, like zoned block devices, aren't showing up in in
/proc/partitions and therefore we cannot relay on it to get a device's
size.

Use sysfs' size attribute to get the block device size.

Cc: Naohiro Aota <naohiro.aota@wdc.com>
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 common/rc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Nikolay Borisov March 25, 2021, 12:13 p.m. UTC | #1
On 25.03.21 г. 13:23, Johannes Thumshirn wrote:
> Non-partitionable devices, like zoned block devices, aren't showing up in in
> /proc/partitions and therefore we cannot relay on it to get a device's
> size.
> 
> Use sysfs' size attribute to get the block device size.
> 
> Cc: Naohiro Aota <naohiro.aota@wdc.com>
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
> ---
>  common/rc | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/common/rc b/common/rc
> index 1c814b9aabf1..c99fff824087 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 $(($(cat /sys/block/`_short_dev $1`/size) >> 1))
>  }

How about simply using 'blockdev --getsz'

>  
>  # Make sure we actually have dmesg checking set up.
>
Damien Le Moal March 25, 2021, 9:39 p.m. UTC | #2
On 2021/03/25 20:25, Johannes Thumshirn wrote:
> Non-partitionable devices, like zoned block devices, aren't showing up in in
> /proc/partitions and therefore we cannot relay on it to get a device's

s/relay/rely

Same in the patch title.

> size.
> 
> Use sysfs' size attribute to get the block device size.
> 
> Cc: Naohiro Aota <naohiro.aota@wdc.com>
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
> ---
>  common/rc | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/common/rc b/common/rc
> index 1c814b9aabf1..c99fff824087 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 $(($(cat /sys/block/`_short_dev $1`/size) >> 1))

This will not work if the device is a partition, no ? Why not simply use
"blockdev --getsz" ? That will work in all cases: zoned or not, partition and
whole drive.

>  }
>  
>  # Make sure we actually have dmesg checking set up.
>
diff mbox series

Patch

diff --git a/common/rc b/common/rc
index 1c814b9aabf1..c99fff824087 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 $(($(cat /sys/block/`_short_dev $1`/size) >> 1))
 }
 
 # Make sure we actually have dmesg checking set up.