[PATCH blktests 2/3] check: introduce _write_queue_sched() to repeat queue/scheduler writes

Shin'ichiro Kawasaki <[email protected]>
Newsgroups org.kernel.vger.linux-block
Message-ID <[email protected]>
After the kernel commit 4ff58d6bc9dd ("block: serialize elevator changes
for the same queue using a writer lock"), concurrent writes to the sysfs
attribute file queue/scheduler of single block device may fail with
-EBUSY. Such failure is observed when udevd writes to the file while
block/005 is running. The write failure causes blktests test case
failures. To avoid it, check the error of the writes, and if the error
is -EBUSY, retry the write.

Signed-off-by: Shin'ichiro Kawasaki <[email protected]>
---
 check | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/check b/check
index 61524a5..e7eca84 100755
--- a/check
+++ b/check
@@ -385,6 +385,28 @@ _output_test_run() {
 	fi
 }
 
+# Writes to queue/scheduler may fail with -EBUSY when udevd does concurrent
+# write. Retry the writes when -EBUSY is returned.
+_write_queue_sched() {
+	local value="$1"
+	local path="$2"
+	local log
+	local i
+
+	for ((i = 0; i < 5; i++)); do
+		if log=$({ echo "$value" > "$path" ;} 2>&1); then
+			break
+		fi
+		if [[ ! $log =~ "Device or resource busy" ]]; then
+			echo "$log"
+		fi
+	done
+	if ((i > 5)); then
+		echo "echo ${value} > ${path} failed"
+		return 1
+	fi
+}
+
 _register_test_cleanup() {
 	TEST_CLEANUP=$1
 }
@@ -402,7 +424,7 @@ _cleanup() {
 	local key value
 	for key in "${!SYSFS_QUEUE_SAVED[@]}"; do
 		value="${SYSFS_QUEUE_SAVED["$key"]}"
-		echo "$value" >"${key}"
+		_write_queue_sched "$value" "${key}"
 		unset "SYSFS_QUEUE_SAVED[$key]"
 	done
 
-- 
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.