Skip to contentSkip to conversation

common/rc: add _have_kernel_options helper function

PATCH In review Chaitanya Kulkarni 3 participants 5 messages Nov 8, 2025 – Nov 14, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 common/rc: add _have_kernel_options helper function

Add a new helper function _have_kernel_options() that accepts multiple kernel config options as arguments. This allows tests to check for multiple kernel options in a single call, making the requires() function more concise.

Example usage:
requires() {
_have_kernel_options IO_URING BLK_DEV_INTEGRITY
}

Instead of:
requires() {
_have_kernel_option IO_URING
_have_kernel_option BLK_DEV_INTEGRITY
}

The function iterates through all provided options and returns failure if any option is not enabled, maintaining the same error reporting behavior as individual calls.

---
 common/rc | 6 ++++++
 1 file changed, 6 insertions(+)
common/rc +6 -0
index 86bb991..545da61 100644
@@ -226,6 +226,12 @@ _have_kernel_option() {
 	return 0
 }
 
+_have_kernel_options() {
+      for opt in "$@"; do
+          _have_kernel_option "$opt" || return 1
+      done
+}
+
 # Compare the version string in $1 in "a.b.c" format with "$2.$3.$4".
 # If "a.b.c" is smaller than "$2.$3.$4", return true. Otherwise, return
 # false.
Signature · 1 line
2.40.0
#1 lore raw

PATCH 2/2 nvme: convert tests to use _have_kernel_options

Convert multiple _have_kernel_option calls in nvme tests to use the new _have_kernel_options helper function for more concise code.

Modified tests:
nvme/039: FAULT_INJECTION, FAULT_INJECTION_DEBUG_FS nvme/041: NVME_AUTH, NVME_TARGET_AUTH
nvme/042: NVME_AUTH, NVME_TARGET_AUTH
nvme/043: NVME_AUTH, NVME_TARGET_AUTH
nvme/044: NVME_AUTH, NVME_TARGET_AUTH
nvme/045: NVME_AUTH, NVME_TARGET_AUTH
nvme/050: FAIL_IO_TIMEOUT, FAULT_INJECTION_DEBUG_FS nvme/062: NVME_TCP_TLS, NVME_TARGET_TCP_TLS
nvme/063: NVME_AUTH, NVME_TCP_TLS, NVME_TARGET_AUTH, NVME_TARGET_TCP_TLS

---
 tests/nvme/039 | 3 +--
 tests/nvme/041 | 3 +--
 tests/nvme/042 | 3 +--
 tests/nvme/043 | 3 +--
 tests/nvme/044 | 3 +--
 tests/nvme/045 | 3 +--
 tests/nvme/050 | 3 +--
 tests/nvme/062 | 3 +--
 tests/nvme/063 | 6 ++----
 9 files changed, 10 insertions(+), 20 deletions(-)
tests/nvme/039 +1 -2
index ab58f3b..98e5d28 100755
@@ -14,8 +14,7 @@ QUICK=1
 
 requires() {
 	_have_program nvme
-	_have_kernel_option FAULT_INJECTION
-	_have_kernel_option FAULT_INJECTION_DEBUG_FS
+	_have_kernel_options FAULT_INJECTION FAULT_INJECTION_DEBUG_FS
 }
 
 device_requires() {
tests/nvme/041 +1 -2
index 6855a47..8f908c5 100755
@@ -12,8 +12,7 @@ QUICK=1
 requires() {
 	_nvme_requires
 	_have_loop
-	_have_kernel_option NVME_AUTH
-	_have_kernel_option NVME_TARGET_AUTH
+	_have_kernel_options NVME_AUTH NVME_TARGET_AUTH
 	_require_kernel_nvme_fabrics_feature dhchap_ctrl_secret
 	_require_nvme_trtype_is_fabrics
 	_require_nvme_cli_auth
tests/nvme/042 +1 -2
index 17d8a73..34d6684 100755
@@ -12,8 +12,7 @@ QUICK=1
 requires() {
 	_nvme_requires
 	_have_loop
-	_have_kernel_option NVME_AUTH
-	_have_kernel_option NVME_TARGET_AUTH
+	_have_kernel_options NVME_AUTH NVME_TARGET_AUTH
 	_require_kernel_nvme_fabrics_feature dhchap_ctrl_secret
 	_require_nvme_trtype_is_fabrics
 	_require_nvme_cli_auth
tests/nvme/043 +1 -2
index 7f9e67e..616f7e7 100755
@@ -12,8 +12,7 @@ QUICK=1
 requires() {
 	_nvme_requires
 	_have_loop
-	_have_kernel_option NVME_AUTH
-	_have_kernel_option NVME_TARGET_AUTH
+	_have_kernel_options NVME_AUTH NVME_TARGET_AUTH
 	_require_kernel_nvme_fabrics_feature dhchap_ctrl_secret
 	_require_nvme_trtype_is_fabrics
 	_require_nvme_cli_auth
tests/nvme/044 +1 -2
index 1352910..4727dbf 100755
@@ -12,8 +12,7 @@ QUICK=1
 requires() {
 	_nvme_requires
 	_have_loop
-	_have_kernel_option NVME_AUTH
-	_have_kernel_option NVME_TARGET_AUTH
+	_have_kernel_options NVME_AUTH NVME_TARGET_AUTH
 	_require_kernel_nvme_fabrics_feature dhchap_ctrl_secret
 	_require_nvme_trtype_is_fabrics
 	_require_nvme_cli_auth
tests/nvme/045 +1 -2
index 4dd0f94..bf38824 100755
@@ -13,8 +13,7 @@ requires() {
 	_nvme_requires
 	_have_fio
 	_have_loop
-	_have_kernel_option NVME_AUTH
-	_have_kernel_option NVME_TARGET_AUTH
+	_have_kernel_options NVME_AUTH NVME_TARGET_AUTH
 	_require_kernel_nvme_fabrics_feature dhchap_ctrl_secret
 	_require_nvme_trtype_is_fabrics
 	_require_nvme_cli_auth
tests/nvme/050 +1 -2
index ba55c6e..91f3564 100755
@@ -16,8 +16,7 @@ nvme_trtype=pci
 requires() {
 	_have_fio
 	_nvme_requires
-	_have_kernel_option FAIL_IO_TIMEOUT
-	_have_kernel_option FAULT_INJECTION_DEBUG_FS
+	_have_kernel_options FAIL_IO_TIMEOUT FAULT_INJECTION_DEBUG_FS
 }
 
 test_device() {
tests/nvme/062 +1 -2
index 7c88719..19275f8 100755
@@ -12,8 +12,7 @@ QUICK=1
 requires() {
 	_nvme_requires
 	_have_loop
-	_have_kernel_option NVME_TCP_TLS
-	_have_kernel_option NVME_TARGET_TCP_TLS
+	_have_kernel_options NVME_TCP_TLS NVME_TARGET_TCP_TLS
 	_require_kernel_nvme_fabrics_feature tls
 	_require_nvme_trtype tcp
 	_require_nvme_cli_tls
tests/nvme/063 +2 -4
index 5bfe8be..bded9a3 100755
@@ -12,10 +12,8 @@ QUICK=1
 requires() {
 	_nvme_requires
 	_have_loop
-	_have_kernel_option NVME_AUTH
-	_have_kernel_option NVME_TCP_TLS
-	_have_kernel_option NVME_TARGET_AUTH
-	_have_kernel_option NVME_TARGET_TCP_TLS
+	_have_kernel_options NVME_AUTH NVME_TCP_TLS NVME_TARGET_AUTH \
+		NVME_TARGET_TCP_TLS
 	_require_kernel_nvme_fabrics_feature dhchap_ctrl_secret
 	_require_kernel_nvme_fabrics_feature concat
 	_require_nvme_trtype tcp
Signature · 1 line
2.40.0
#2 lore raw
In reply to Chaitanya Kulkarni
Quoted 30 lines · Chaitanya Kulkarni

Add a new helper function _have_kernel_options() that accepts multiple kernel config options as arguments. This allows tests to check for multiple kernel options in a single call, making the requires() function more concise.

Example usage:
requires() {
_have_kernel_options IO_URING BLK_DEV_INTEGRITY
}

Instead of:
requires() {
_have_kernel_option IO_URING
_have_kernel_option BLK_DEV_INTEGRITY
}

The function iterates through all provided options and returns failure if any option is not enabled, maintaining the same error reporting behavior as individual calls.

---
 common/rc | 6 ++++++
 1 file changed, 6 insertions(+)
common/rc +0 -0
index 86bb991..545da61 100644

common/rc _have_kernel_option() { · line 230

Quoted 5 lines
common/rc +2 -0
@@ -226,6 +226,12 @@ _have_kernel_option() {
 	return 0
 }
 
+_have_kernel_options() {
+      for opt in "$@"; do

Nit: spaces are used for indent.

common/rc _have_kernel_option() { · line 231

Quoted 1 line
common/rc +1 -0
+          _have_kernel_option "$opt" || return 1

This early return means that all of the options in $@ may not be checked. This is not good. Let's say there are two kernel options disabled, FOO and BAR. With this implmenetation, only FOO is reported by single blktests run.

"kernel option FOO has not been enabled"

The user will enable FOO, rebuild kernel, run blktests again and see this:

"kernel option BAR has not been enabled"

Now the user needs to rebuild the kernel again. This is troublesome.

I suggest to check all of the options in $@ and report all of disabled options, like,

"kernel option FOO has not been enabled"
"kernel option BAR has not been enabled"

This will report more complete conditions to run test cases, and reduce the risk that users lose their precious time. IOW, I suggest the implementation like:

_have_kenrel_options() {
	local ret=0

	for opt in "$@"; do
		_have_kernel_option "$opt" || ret=1
	done

	return $ret
}

common/rc _have_kernel_option() { · line 233

Quoted 2 lines
common/rc +2 -0
+      done
+}

Other than the comments above, the two patches look good to me. If you are okay with them, I can fold-in the suggested changes when I apply them (assuming there is no other comment on the list). Please let me know your preference.

#3 lore raw
Quoted 3 lines · Shinichiro Kawasaki

Other than the comments above, the two patches look good to me. If you are okay with them, I can fold-in the suggested changes when I apply them (assuming there is no other comment on the list). Please let me know your preference.

Thanks a lot for taking a look at this. I'm absolutely fine to fold-in suggestions. -ck

#4 lore raw
Quoted 8 lines · Chaitanya Kulkarni
Quoted 3 lines · Shinichiro Kawasaki

Other than the comments above, the two patches look good to me. If you are okay with them, I can fold-in the suggested changes when I apply them (assuming there is no other comment on the list). Please let me know your preference.

Thanks a lot for taking a look at this. I'm absolutely fine to fold-in suggestions. -ck

FYI, I applied the patches with the changes. Thanks!