diff mbox series

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

Message ID 20240103114940.3000366-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. 3, 2024, 11:49 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 | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Bart Van Assche Jan. 3, 2024, 3:55 p.m. UTC | #1
On 1/3/24 03:49, Shin'ichiro Kawasaki wrote:
> +_have_null_blk_feature() {
> +	grep -qe "$1" /sys/kernel/config/nullb/features
> +}

The above test can only work if the null_blk driver is already
loaded. Is it guaranteed that the null_blk driver is loaded when
this function is called? Wouldn't it be better to examine the
output of modprobe null_blk?

Thanks,

Bart.
Shin'ichiro Kawasaki Jan. 5, 2024, 8:51 a.m. UTC | #2
On Jan 03, 2024 / 07:55, Bart Van Assche wrote:
> On 1/3/24 03:49, Shin'ichiro Kawasaki wrote:
> > +_have_null_blk_feature() {
> > +	grep -qe "$1" /sys/kernel/config/nullb/features
> > +}
> 
> The above test can only work if the null_blk driver is already
> loaded. Is it guaranteed that the null_blk driver is loaded when
> this function is called? Wouldn't it be better to examine the
> output of modprobe null_blk?

Thanks for the comment. I agree that it's better to check the null_blk driver
availability in the function. Will improve it in v2.
diff mbox series

Patch

diff --git a/common/null_blk b/common/null_blk
index 91b78d4..d2f9e88 100644
--- a/common/null_blk
+++ b/common/null_blk
@@ -10,6 +10,10 @@  _have_null_blk() {
 	_have_driver null_blk
 }
 
+_have_null_blk_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 \