[PATCH blktests 1/3] block: add test for concurrent IO scheduler switching

Shin'ichiro Kawasaki <[email protected]>
Newsgroups org.kernel.vger.linux-block
Message-ID <[email protected]>
Add test to confirm that multiple processes can write to queue/scheduler
sysfs attribute of single block device concurrently. This is the fix
confirmation test for the recent bug in the kernel fixed by the kernel
commit 4ff58d6bc9dd ("block: serialize elevator changes for the same
queue using a writer lock").

Signed-off-by: Shin'ichiro Kawasaki <[email protected]>
---
 tests/block/045     | 49 +++++++++++++++++++++++++++++++++++++++++++++
 tests/block/045.out |  2 ++
 2 files changed, 51 insertions(+)
 create mode 100755 tests/block/045
 create mode 100644 tests/block/045.out

diff --git a/tests/block/045 b/tests/block/045
new file mode 100755
index 0000000..ef84bc4
--- /dev/null
+++ b/tests/block/045
@@ -0,0 +1,49 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright (C) 2026 Western Digital Corporation or its affiliates.
+#
+# Switch IO schedulers concurrently to exercise the scheduler change path under
+# contention. This is the regression test for the kernel fix commit 4ff58d6bc9dd
+# ("block: serialize elevator changes for the same queue using a writer lock").
+
+. tests/block/rc
+. common/null_blk
+
+DESCRIPTION="switch schedulers concurrently"
+TIMED=1
+
+switch_schedulers() {
+	local start_time idx
+
+	start_time=$(date +%s)
+	while (( $(date +%s) - start_time <= timeout )); do
+		idx=$((RANDOM % ${#scheds[@]}))
+		{ echo "${scheds[$idx]}" > \
+                       /sys/block/nullb1/queue/scheduler ;} 2> /dev/null
+	done
+}
+
+test() {
+	echo "Running ${TEST_NAME}"
+
+	local timeout pid1 pid2
+	local -a scheds
+
+	if ! _configure_null_blk nullb1 power=1; then
+		return 1
+	fi
+
+	timeout=${TIMEOUT:=30}
+	read -r -a scheds < <(_io_schedulers nullb1)
+
+	switch_schedulers &
+	pid1=$!
+	switch_schedulers &
+	pid2=$!
+
+	wait $pid1 $pid2
+
+	_exit_null_blk
+
+	echo "Test complete"
+}
diff --git a/tests/block/045.out b/tests/block/045.out
new file mode 100644
index 0000000..2301a37
--- /dev/null
+++ b/tests/block/045.out
@@ -0,0 +1,2 @@
+Running block/045
+Test complete
-- 
2.54.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.