diff mbox series

[blktests,v2,1/2] common/null_blk: introduce _have_null_blk_feature

Message ID 20240109104453.3764096-2-shinichiro.kawasaki@wdc.com (mailing list archive)
State New, archived
Headers show
Series block/031: allow to run with built-in null_blk driver | expand

Commit Message

Shin'ichiro Kawasaki Jan. 9, 2024, 10:44 a.m. UTC
Introduce a helper function _have_null_blk_feature which checks
/sys/kernel/config/features. It allows test cases to adapt to null_blk
feature support status.

Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
---
 common/null_blk | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

Comments

Chaitanya Kulkarni Jan. 9, 2024, 7:20 p.m. UTC | #1
On 1/9/24 02:44, Shin'ichiro Kawasaki wrote:
> Introduce a helper function _have_null_blk_feature which checks
> /sys/kernel/config/features. It allows test cases to adapt to null_blk
> feature support status.
>
> Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
> ---
>

much needed helper for a driver since features can change
across the release of kernel for validation can also be used
to skip certain tests ...

Looks good.

Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>

-ck
Bart Van Assche Jan. 9, 2024, 8:14 p.m. UTC | #2
On 1/9/24 02:44, Shin'ichiro Kawasaki wrote:
> Introduce a helper function _have_null_blk_feature which checks
> /sys/kernel/config/features. It allows test cases to adapt to null_blk
> feature support status.
> 
> Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
> ---
>   common/null_blk | 15 +++++++++++++++
>   1 file changed, 15 insertions(+)
> 
> diff --git a/common/null_blk b/common/null_blk
> index 91b78d4..164125d 100644
> --- a/common/null_blk
> +++ b/common/null_blk
> @@ -10,6 +10,21 @@ _have_null_blk() {
>   	_have_driver null_blk
>   }
>   
> +_have_null_blk_feature() {
> +	# Ensure that null_blk driver is built-in or loaded
> +	if ! [[ -d /sys/module/null_blk ]]; then
> +		if ! modprobe -q null_blk; then
> +			return 1
> +		fi
> +		if [[ ! "${MODULES_TO_UNLOAD[*]}" =~ null_blk ]]; then
> +			MODULES_TO_UNLOAD+=(null_blk)
> +		fi
> +	fi
> +
> +	# Check that null_blk has the specified feature
> +	grep -qe "$1" /sys/kernel/config/nullb/features
> +}
> +
>   _remove_null_blk_devices() {
>   	if [[ -d /sys/kernel/config/nullb ]]; then
>   		find /sys/kernel/config/nullb -mindepth 1 -maxdepth 1 \

Shouldn't _have_null_blk_feature() unload the null_blk kernel module if it
loads that kernel module? That will allow to simplify the next patch in this
series.

Thanks,

Bart.
diff mbox series

Patch

diff --git a/common/null_blk b/common/null_blk
index 91b78d4..164125d 100644
--- a/common/null_blk
+++ b/common/null_blk
@@ -10,6 +10,21 @@  _have_null_blk() {
 	_have_driver null_blk
 }
 
+_have_null_blk_feature() {
+	# Ensure that null_blk driver is built-in or loaded
+	if ! [[ -d /sys/module/null_blk ]]; then
+		if ! modprobe -q null_blk; then
+			return 1
+		fi
+		if [[ ! "${MODULES_TO_UNLOAD[*]}" =~ null_blk ]]; then
+			MODULES_TO_UNLOAD+=(null_blk)
+		fi
+	fi
+
+	# Check that null_blk has the specified feature
+	grep -qe "$1" /sys/kernel/config/nullb/features
+}
+
 _remove_null_blk_devices() {
 	if [[ -d /sys/kernel/config/nullb ]]; then
 		find /sys/kernel/config/nullb -mindepth 1 -maxdepth 1 \