OpenVZ / Virtuozzo kernel development (devel@openvz.org)
 help / color / mirror / Atom feed
* [Devel] [PATCH hci-8.1] selftests/zram: use the device ids that hot_add returns
@ 2026-11-03 11:03 Eva Kurchatova
  2026-11-03 11:07 ` no-reply
  2026-11-03 17:40 ` Konstantin Khorenko
  0 siblings, 2 replies; 3+ messages in thread
From: Eva Kurchatova @ 2026-11-03 11:03 UTC (permalink / raw)
  To: khorenko; +Cc: devel

zram_load() numbers the devices it creates by counting the nodes in
/dev and discards the ids hot_add returns. hot_add takes the lowest
free id, so once the ids have a gap the test works on a device it did
not create: with zram0 and zram2 present it creates zram1, then
configures, formats and mounts zram2, and finally resets and removes
zram2 and leaves zram1 behind.

Keep the ids hot_add returns and use them in every step and in the
cleanup. A hot_add that fails now fails the test.

Fixes: 01dabed20573 ("selftests/zram: Adapt the situation that /dev/zram0 is being used")
https://virtuozzo.atlassian.net/browse/VSTOR-152656
Feature: fix selftests

Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
---
 tools/testing/selftests/zram/zram01.sh   |  2 +-
 tools/testing/selftests/zram/zram_lib.sh | 85 +++++++++++++-----------
 2 files changed, 49 insertions(+), 38 deletions(-)

diff --git a/tools/testing/selftests/zram/zram01.sh b/tools/testing/selftests/zram/zram01.sh
index 8f337e6adf8b..582f7987437b 100755
--- a/tools/testing/selftests/zram/zram01.sh
+++ b/tools/testing/selftests/zram/zram01.sh
@@ -37,7 +37,7 @@ zram_fill_fs()
 	# An earlier step failed, and after a failed mount the directory
 	# would be filled on the host's filesystem
 	[ $ERR_CODE -ne 0 ] && return
-	for i in $(seq $dev_start $dev_end); do
+	for i in $dev_ids; do
 		echo "fill zram$i..."
 		local b=0
 		while [ true ]; do
diff --git a/tools/testing/selftests/zram/zram_lib.sh b/tools/testing/selftests/zram/zram_lib.sh
index f32c86c876d3..59b7f91a0c9e 100755
--- a/tools/testing/selftests/zram/zram_lib.sh
+++ b/tools/testing/selftests/zram/zram_lib.sh
@@ -5,10 +5,9 @@
 # Author: Alexey Kodanev <alexey.kodanev@oracle.com>
 # Modified: Naresh Kamboju <naresh.kamboju@linaro.org>
 
-dev_makeswap=-1
-dev_mounted=-1
-dev_start=0
-dev_end=-1
+dev_ids=
+dev_makeswap=
+dev_mounted=
 module_load=-1
 sys_control=-1
 # Kselftest framework requirement - SKIP code is 4.
@@ -55,21 +54,21 @@ zram_cleanup()
 {
 	echo "zram cleanup"
 	local i=
-	for i in $(seq $dev_start $dev_makeswap); do
+	for i in $dev_makeswap; do
 		swapoff /dev/zram$i
 	done
 
-	for i in $(seq $dev_start $dev_mounted); do
+	for i in $dev_mounted; do
 		umount /dev/zram$i
 	done
 
-	for i in $(seq $dev_start $dev_end); do
+	for i in $dev_ids; do
 		echo 1 > /sys/block/zram${i}/reset
 		rm -rf zram$i
 	done
 
 	if [ $sys_control -eq 1 ]; then
-		for i in $(seq $dev_start $dev_end); do
+		for i in $dev_ids; do
 			echo $i > /sys/class/zram-control/hot_remove
 		done
 	fi
@@ -87,16 +86,19 @@ zram_load()
 	if [ -d "/sys/class/zram-control" ]; then
 		echo "zram modules already loaded, kernel supports" \
 			"zram-control interface"
-		dev_start=$(ls /dev/zram* | wc -w)
-		dev_end=$(($dev_start + $dev_num - 1))
 		sys_control=1
 
-		for i in $(seq $dev_start $dev_end); do
-			cat /sys/class/zram-control/hot_add > /dev/null
+		local id
+		for i in $(seq $dev_num); do
+			id=$(cat /sys/class/zram-control/hot_add) || {
+				echo "FAIL can't add a zram device"
+				zram_cleanup
+				exit 1
+			}
+			dev_ids="$dev_ids $id"
 		done
 
-		echo "all zram devices (/dev/zram$dev_start~$dev_end" \
-			"successfully created"
+		echo "zram devices created:$dev_ids"
 		return 0
 	fi
 
@@ -119,8 +121,8 @@ zram_load()
 	fi
 
 	module_load=1
-	dev_end=$(($dev_num - 1))
-	echo "all zram devices (/dev/zram0~$dev_end) successfully created"
+	dev_ids=$(seq 0 $(($dev_num - 1)))
+	echo "all zram devices (/dev/zram0~$(($dev_num - 1))) successfully created"
 }
 
 zram_max_streams()
@@ -134,8 +136,11 @@ zram_max_streams()
 		return 0
 	fi
 
-	local i=$dev_start
+	local i
+	set -- $dev_ids
 	for max_s in $zram_max_streams; do
+		i=$1
+		shift
 		local sys_path="/sys/block/zram${i}/max_comp_streams"
 		echo $max_s > $sys_path || \
 			{ echo "FAIL failed to set '$max_s' to $sys_path"; ERR_CODE=-1; }
@@ -147,7 +152,6 @@ zram_max_streams()
 			ERR_CODE=-1
 		fi
 
-		i=$(($i + 1))
 		echo "$sys_path = '$max_streams'"
 	done
 
@@ -158,16 +162,19 @@ zram_compress_alg()
 {
 	echo "test that we can set compression algorithm"
 
-	local i=$dev_start
-	local algs=$(cat /sys/block/zram${i}/comp_algorithm)
+	local i
+	set -- $dev_ids
+	local algs=$(cat /sys/block/zram$1/comp_algorithm)
 	echo "supported algs: $algs"
 	if [ -z "$algs" ]; then
-		echo "FAIL can't read /sys/block/zram${i}/comp_algorithm"
+		echo "FAIL can't read /sys/block/zram$1/comp_algorithm"
 		ERR_CODE=-1
 		return
 	fi
 
 	for alg in $zram_algs; do
+		i=$1
+		shift
 		local sys_path="/sys/block/zram${i}/comp_algorithm"
 		# A kernel built without the algorithm is not a zram failure
 		case " $(echo "$algs" | tr -d '[]') " in
@@ -175,13 +182,11 @@ zram_compress_alg()
 		*)
 			echo "SKIP '$alg' is not supported by this kernel"
 			SKIP_CODE=$ksft_skip
-			i=$(($i + 1))
 			continue
 			;;
 		esac
 		echo "$alg" >	$sys_path || \
 			{ echo "FAIL can't set '$alg' to $sys_path"; ERR_CODE=-1; }
-		i=$(($i + 1))
 		echo "$sys_path = '$alg'"
 	done
 
@@ -191,13 +196,15 @@ zram_compress_alg()
 zram_set_disksizes()
 {
 	echo "set disk size to zram device(s)"
-	local i=$dev_start
+	local i
+	set -- $dev_ids
 	for ds in $zram_sizes; do
+		i=$1
+		shift
 		local sys_path="/sys/block/zram${i}/disksize"
 		echo "$ds" >	$sys_path || \
 			{ echo "FAIL can't set '$ds' to $sys_path"; ERR_CODE=-1; }
 
-		i=$(($i + 1))
 		echo "$sys_path = '$ds'"
 	done
 
@@ -208,13 +215,15 @@ zram_set_memlimit()
 {
 	echo "set memory limit to zram device(s)"
 
-	local i=$dev_start
+	local i
+	set -- $dev_ids
 	for ds in $zram_mem_limits; do
+		i=$1
+		shift
 		local sys_path="/sys/block/zram${i}/mem_limit"
 		echo "$ds" >	$sys_path || \
 			{ echo "FAIL can't set '$ds' to $sys_path"; ERR_CODE=-1; }
 
-		i=$(($i + 1))
 		echo "$sys_path = '$ds'"
 	done
 
@@ -224,8 +233,8 @@ zram_set_memlimit()
 zram_makeswap()
 {
 	echo "make swap with zram device(s)"
-	local i=$dev_start
-	for i in $(seq $dev_start $dev_end); do
+	local i=
+	for i in $dev_ids; do
 		mkswap /dev/zram$i > err.log 2>&1
 		if [ $? -ne 0 ]; then
 			cat err.log
@@ -241,7 +250,7 @@ zram_makeswap()
 		fi
 
 		echo "done with /dev/zram$i"
-		dev_makeswap=$i
+		dev_makeswap="$dev_makeswap $i"
 	done
 
 	echo "zram making zram mkswap and swapon: OK"
@@ -250,7 +259,7 @@ zram_makeswap()
 zram_swapoff()
 {
 	local i=
-	for i in $(seq $dev_start $dev_end); do
+	for i in $dev_ids; do
 		swapoff /dev/zram$i > err.log 2>&1
 		if [ $? -ne 0 ]; then
 			cat err.log
@@ -258,15 +267,18 @@ zram_swapoff()
 			ERR_CODE=-1
 		fi
 	done
-	dev_makeswap=-1
+	dev_makeswap=
 
 	echo "zram swapoff: OK"
 }
 
 zram_makefs()
 {
-	local i=$dev_start
+	local i
+	set -- $dev_ids
 	for fs in $zram_filesystems; do
+		i=$1
+		shift
 		# if requested fs not supported default it to ext2
 		which mkfs.$fs > /dev/null 2>&1 || fs=ext2
 
@@ -277,20 +289,19 @@ zram_makefs()
 			echo "FAIL failed to make $fs on /dev/zram$i"
 			ERR_CODE=-1
 		fi
-		i=$(($i + 1))
 		echo "zram mkfs.$fs: OK"
 	done
 }
 
 zram_mount()
 {
-	local i=0
-	for i in $(seq $dev_start $dev_end); do
+	local i=
+	for i in $dev_ids; do
 		echo "mount /dev/zram$i"
 		mkdir zram$i
 		mount /dev/zram$i zram$i > /dev/null || \
 			{ echo "FAIL mount /dev/zram$i failed"; ERR_CODE=-1; }
-		dev_mounted=$i
+		dev_mounted="$dev_mounted $i"
 	done
 
 	echo "zram mount of zram device(s): OK"
-- 
2.56.0

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-03 17:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-03 11:03 [Devel] [PATCH hci-8.1] selftests/zram: use the device ids that hot_add returns Eva Kurchatova
2026-11-03 11:07 ` no-reply
2026-11-03 17:40 ` Konstantin Khorenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox