[PATCH v2 blktests] don't require modular null_blk for fault-injection

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This blktests change changes null_blk fault-injection settings to be
configured via configfs instead of module parameters.
This allows null_blk fault-injection tests to run even if the null_blk is
built-in the kernel and not built as a module.

If the null_blk does not yet support configuring fault-injection via
configfs, fall back to set up with module parameter.

Signed-off-by: Akinobu Mita <akinobu.mita@xxxxxxxxx>
---
* v2
- don't skip the tests on older kernels without fault-injection via configfs

 tests/block/014 | 30 +++++++++++++++++++++++-------
 tests/block/015 | 30 +++++++++++++++++++++++-------
 tests/block/030 | 44 ++++++++++++++++++++++++++++++++------------
 3 files changed, 78 insertions(+), 26 deletions(-)

diff --git a/tests/block/014 b/tests/block/014
index facd4bc..cac779b 100755
--- a/tests/block/014
+++ b/tests/block/014
@@ -16,20 +16,36 @@ requires() {
 test() {
 	echo "Running ${TEST_NAME}"
 
-	# The format is "<interval>,<probability>,<space>,<times>". Here, we
-	# fail 50% of I/Os.
-	if ! _init_null_blk timeout='1,50,0,-1'; then
-		return 1
+	local faultb=faultb0
+
+	# Here, we fail 50% of I/Os.
+	if ! _configure_null_blk "$faultb" timeout_inject/probability=50 \
+	     timeout_inject/times=-1 timeout_inject/verbose=0 power=1 \
+	     > /dev/null 2>&1; then
+		rmdir /sys/kernel/config/nullb/"$faultb"
+		if _module_file_exists null_blk; then
+			faultb=nullb0
+
+			# Fall back to set up with module parameter. The format
+			# is "<interval>,<probability>,<space>,<times>"
+			if ! _init_null_blk timeout='1,50,0,-1'; then
+				echo "Configuring null_blk failed"
+				return 1
+			fi
+		else
+			SKIP_REASONS+=("requires fault injection via configfs or modular null_blk")
+			return 1
+		fi
 	fi
 
-	for sched in $(_io_schedulers nullb0); do
+	for sched in $(_io_schedulers "$faultb"); do
 		echo "Testing $sched" >> "$FULL"
-		echo "$sched" > /sys/block/nullb0/queue/scheduler
+		echo "$sched" > /sys/block/"$faultb"/queue/scheduler
 		# Do a bunch of I/Os which will timeout and then complete. The
 		# only thing we're really testing here is that this doesn't
 		# crash or hang.
 		for ((i = 0; i < 100; i++)); do
-			dd if=/dev/nullb0 of=/dev/null bs=4K count=4 \
+			dd if=/dev/"$faultb" of=/dev/null bs=4K count=4 \
 				iflag=direct status=none > /dev/null 2>&1 &
 		done
 		wait
diff --git a/tests/block/015 b/tests/block/015
index 389c67f..afb4b82 100755
--- a/tests/block/015
+++ b/tests/block/015
@@ -18,16 +18,32 @@ requires() {
 test() {
 	echo "Running ${TEST_NAME}"
 
-	# The format is "<interval>,<probability>,<space>,<times>". Here, we
-	# requeue 10% of the time.
-	if ! _init_null_blk requeue='1,10,0,-1'; then
-		return 1
+	local faultb=faultb0
+
+	# Here, we requeue 10% of the time.
+	if ! _configure_null_blk "$faultb" requeue_inject/probability=10 \
+	     requeue_inject/times=-1 requeue_inject/verbose=0 power=1 \
+	     > /dev/null 2>&1; then
+		rmdir /sys/kernel/config/nullb/"$faultb"
+		if _module_file_exists null_blk; then
+			faultb=nullb0
+
+			# Fall back to set up with module parameter. The format
+			# is "<interval>,<probability>,<space>,<times>"
+			if ! _init_null_blk requeue='1,10,0,-1'; then
+				echo "Configuring null_blk failed"
+				return 1
+			fi
+		else
+			SKIP_REASONS+=("requires fault injection via configfs or modular null_blk")
+			return 1
+		fi
 	fi
 
-	for sched in $(_io_schedulers nullb0); do
+	for sched in $(_io_schedulers "$faultb"); do
 		echo "Testing $sched" >> "$FULL"
-		echo "$sched" > /sys/block/nullb0/queue/scheduler
-		dd if=/dev/nullb0 of=/dev/null bs=4K count=$((512 * 1024)) \
+		echo "$sched" > /sys/block/"$faultb"/queue/scheduler
+		dd if=/dev/"$faultb" of=/dev/null bs=4K count=$((512 * 1024)) \
 			iflag=direct status=none
 	done
 
diff --git a/tests/block/030 b/tests/block/030
index 7a0712b..82330c2 100755
--- a/tests/block/030
+++ b/tests/block/030
@@ -17,20 +17,39 @@ requires() {
 }
 
 test() {
-	local i sq=/sys/kernel/config/nullb/nullb0/submit_queues
+	local faultb=faultb0
+	local i sq
 
 	: "${TIMEOUT:=30}"
-	# Legend: init_hctx=<interval>,<probability>,<space>,<times>
 	# Set <space> to $(nproc) + 1 to make loading of null_blk succeed.
-	if ! _init_null_blk nr_devices=0 \
-	     "init_hctx=$(nproc),100,$(($(nproc) + 1)),-1"; then
-		echo "Loading null_blk failed"
-		return 1
-	fi
-	if ! _configure_null_blk nullb0 completion_nsec=0 blocksize=512 size=16\
-	     submit_queues="$(nproc)" memory_backed=1 power=1; then
-		echo "Configuring null_blk failed"
-		return 1
+	if ! _configure_null_blk "$faultb" completion_nsec=0 blocksize=512 size=16\
+	     submit_queues="$(nproc)" memory_backed=1 \
+	     init_hctx_fault_inject/interval="$(nproc)" \
+	     init_hctx_fault_inject/probability=100 \
+	     init_hctx_fault_inject/space="$(($(nproc) + 1))" \
+	     init_hctx_fault_inject/times=-1 \
+	     init_hctx_fault_inject/verbose=0 power=1 \
+	     > /dev/null 2>&1; then
+		rmdir /sys/kernel/config/nullb/"$faultb"
+		if _module_file_exists null_blk; then
+			faultb=nullb0
+
+			# Fall back to set up with module parameter. The format
+			# is "<interval>,<probability>,<space>,<times>"
+			if ! _init_null_blk nr_devices=0 \
+			    "init_hctx=$(nproc),100,$(($(nproc) + 1)),-1"; then
+				echo "Loading null_blk failed"
+				return 1
+			fi
+			if ! _configure_null_blk "$faultb" completion_nsec=0 blocksize=512 size=16\
+			    submit_queues="$(nproc)" memory_backed=1 power=1; then
+				echo "Configuring null_blk failed"
+				return 1
+			fi
+		else
+			SKIP_REASONS+=("requires fault injection via configfs or modular null_blk")
+			return 1
+		fi
 	fi
 	# Since older null_blk versions do not allow "submit_queues" to be
 	# modified, check first whether that configs attribute is writeable.
@@ -39,6 +58,7 @@ test() {
 	# blk_mq_realloc_hw_ctxs() error paths will be triggered. Whether or
 	# not this test succeeds depends on whether or not _check_dmesg()
 	# detects a kernel warning.
+	sq=/sys/kernel/config/nullb/"$faultb"/submit_queues
 	if { echo "$(<"$sq")" >$sq; } 2>/dev/null; then
 		for ((i = 0; i < 100; i++)); do
 			echo 1 > $sq
@@ -47,7 +67,7 @@ test() {
 	else
 		SKIP_REASONS+=("Skipping test because $sq cannot be modified")
 	fi
-	rmdir /sys/kernel/config/nullb/nullb0
+	rmdir /sys/kernel/config/nullb/"$faultb"
 	_exit_null_blk
 	echo Passed
 }
-- 
2.34.1




[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux