From 702eb8bf57b076e15e074f6a0c6fd04fb62546d9 Mon Sep 17 00:00:00 2001
From: Daniel Baumann <daniel.baumann@progress-linux.org>
Date: Thu, 12 Dec 2024 18:22:06 +0100
Subject: Adding upstream version 4.3+20241202.

Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
---
 tests/04update-uuid            | 34 ------------------------------
 tests/05r1-re-add-nosuper      | 32 ++++++----------------------
 tests/07reshape5intr           | 16 +++++++++++++-
 tests/func.sh                  | 47 +++++++++++++++++++++++++++++++++++-------
 tests/imsm-grow-template       |  2 --
 tests/templates/names_template |  6 ++++--
 6 files changed, 64 insertions(+), 73 deletions(-)

(limited to 'tests')

diff --git a/tests/04update-uuid b/tests/04update-uuid
index 25314ab..ce5a958 100644
--- a/tests/04update-uuid
+++ b/tests/04update-uuid
@@ -22,40 +22,6 @@ mdadm -D /dev/md0 | grep -s > /dev/null 01234567:89abcdef:fedcba98:76543210 || {
 }
 mdadm -S /dev/md0
 
-
-# now if we have a bitmap, that needs updating too.
-rm -f $targetdir/bitmap
-yes | mdadm -CR --assume-clean -b $targetdir/bitmap $md0 -l5 -n3 $dev0 $dev1 $dev2
-mdadm -S /dev/md0
-mdadm -A /dev/md0 -b $targetdir/bitmap --update=uuid --uuid=0123456789abcdef:fedcba9876543210 $dev0 $dev1 $dev2
-no_errors
-mdadm -D /dev/md0 | grep -s > /dev/null 01234567:89abcdef:fedcba98:76543210 || {
-   echo Wrong uuid; mdadm -D /dev/md0 ; exit 2;
-}
-if mdadm -X $targetdir/bitmap | grep -s > /dev/null 01234567:89abcdef:fedcba98:76543210 ||
-   mdadm -X $targetdir/bitmap | grep -s > /dev/null 67452301:efcdab89:98badcfe:10325476
-then : ; else
-   echo Wrong uuid; mdadm -X $targetdir/bitmap ; exit 2;
-fi
-mdadm -S /dev/md0
-
-# and bitmap for version1
-rm -f $targetdir/bitmap
-yes | mdadm -CR --assume-clean -e1.1 -b $targetdir/bitmap $md0 -l5 -n3 $dev0 $dev1 $dev2
-mdadm -S /dev/md0
-mdadm -A /dev/md0 -b $targetdir/bitmap --update=uuid --uuid=0123456789abcdef:fedcba9876543210 $dev0 $dev1 $dev2
-no_errors
-mdadm -D /dev/md0 | grep -s > /dev/null 01234567:89abcdef:fedcba98:76543210 || {
-   echo Wrong uuid; mdadm -D /dev/md0 ; exit 2;
-}
-# -X cannot tell which byteorder to use for the UUID, so allow both.
-if mdadm -X $targetdir/bitmap | grep -s > /dev/null 01234567:89abcdef:fedcba98:76543210 ||
-   mdadm -X $targetdir/bitmap | grep -s > /dev/null 67452301:efcdab89:98badcfe:10325476
-then : ; else
-   echo Wrong uuid; mdadm -X $targetdir/bitmap ; exit 2;
-fi
-mdadm -S /dev/md0
-
 # Internal bitmaps too.
 mdadm -CR --assume-clean  -b internal --bitmap-chunk 4 $md0 -l5 -n3 $dev0 $dev1 $dev2
 mdadm -S /dev/md0
diff --git a/tests/05r1-re-add-nosuper b/tests/05r1-re-add-nosuper
index 7d41fd7..750d7c1 100644
--- a/tests/05r1-re-add-nosuper
+++ b/tests/05r1-re-add-nosuper
@@ -1,12 +1,8 @@
-
 #
-# create a raid1, remove a drive, and readd it.
-# resync should be instant.
-# Then do some IO first.  Resync should still be very fast
+# create a raid1 without superblock, remove a drive, and readd it.
+# readd should fail.
 #
-bmf=$targetdir/bitmap2
-rm -f $bmf
-yes | mdadm -B $md0 -l1 -n2 -b$bmf -d1 $dev1 $dev2
+mdadm -B $md0 -l1 -n2 -d1 $dev1 $dev2
 check resync
 check wait
 testdev $md0 1 $size 1
@@ -15,24 +11,8 @@ sleep 4
 mdadm $md0 -f $dev2
 sleep 1
 mdadm $md0 -r $dev2
-mdadm $md0 --re-add $dev2
-check nosync
+if mdadm $md0 --re-add $dev2; then
+	err "re-add should fail"
+fi
 
-mdadm $md0 -f $dev2
-sleep 1
-mdadm $md0 -r $dev2
-testdev $md0 1 $size 1
-mdadm $md0 --re-add $dev2
-check wait
-cmp --bytes=$[$mdsize0*1024] $dev1 $dev2
-
-mdadm $md0 -f $dev2; sleep 1
-mdadm $md0 -r $dev2
-if dd if=/dev/zero of=$md0 ; then : ; fi
-blockdev --flushbufs $md0 # make sure writes have been sent
-mdadm $md0 --re-add $dev2
-check recovery
-check wait
-# should BLKFLSBUF and then read $dev1/$dev2...
-cmp --bytes=$[$mdsize0*1024] $file1 $file2
 mdadm -S $md0
diff --git a/tests/07reshape5intr b/tests/07reshape5intr
index 0f4803a..2af2910 100644
--- a/tests/07reshape5intr
+++ b/tests/07reshape5intr
@@ -31,7 +31,21 @@ do
   echo 1000 > /proc/sys/dev/raid/speed_limit_min
   echo 2000 > /proc/sys/dev/raid/speed_limit_max
   check wait
-  while ! echo check > /sys/block/md0/md/sync_action; do sleep 0.1; done
+
+  max=5
+
+  for ((i = 0 ; i < max ; i++ )); do
+    if [[ $(echo check > /sys/block/md0/md/sync_action) != 0 ]]; then
+        break;
+    fi
+    sleep 1
+  done
+
+  if [[ i == max ]]; then
+     echo >&2 "Timeout waiting for check to succeed"
+     exit 1
+  fi
+
   check wait
   mm=`cat /sys/block/md0/md/mismatch_cnt`
   if [ $mm -gt 0 ]
diff --git a/tests/func.sh b/tests/func.sh
index 567d91d..4b4d374 100644
--- a/tests/func.sh
+++ b/tests/func.sh
@@ -186,7 +186,7 @@ is_raid_foreign() {
 	# to decide if an array is foreign or local. It adds homehost if
 	# one array is local
 	hostname=$(hostname)
-	if [ `expr length "$(hostname)$name"` -lt 31 ]; then
+	if [ `expr length "$(hostname):$name"` -lt 31 ]; then
 		is_foreign="no"
 	else
 		is_foreign="yes"
@@ -202,6 +202,24 @@ restore_selinux() {
 	setenforce $sys_selinux
 }
 
+wait_for_reshape_end() {
+	# wait for grow-continue to finish but break if sync_action does not
+	# contain any reshape value
+	while true
+	do
+		sync_action=$(grep -Ec '(resync|recovery|reshape|check|repair) *=' /proc/mdstat)
+		if (( "$sync_action" != 0 )); then
+			sleep 1
+			continue
+		elif [[ $(pgrep -f "mdadm --grow --continue" > /dev/null) != "" ]]; then
+			echo "Grow continue did not finish but reshape is done" >&2
+			exit 1
+		else
+			break
+		fi
+	done
+}
+
 setup_systemd_env() {
 	warn "Warning! Test suite will set up systemd environment!\n"
 	echo "Use \"systemctl show-environment\" to show systemd environment variables"
@@ -357,15 +375,28 @@ check() {
 		max=`cat /proc/sys/dev/raid/speed_limit_max`
 		echo 200000 > /proc/sys/dev/raid/speed_limit_max
 		sleep 0.1
-		while grep -Eq '(resync|recovery|reshape|check|repair) *=' /proc/mdstat ||
-			grep -v idle > /dev/null /sys/block/md*/md/sync_action
+		iterations=0
+		# Wait 10 seconds for one of the actions appears in sync_action.
+		while [ $iterations -le 10 ]
 		do
-			sleep 0.5
-		done
-		while ps auxf | grep "mdadm --grow --continue" | grep -v grep
-		do
-			sleep 1
+			sync_action=$(grep -Ec '(resync|recovery|reshape|check|repair) *=' /proc/mdstat)
+			if (( "$sync_action" == 0 )); then
+				sleep 1
+				iterations=$(( $iterations + 1 ))
+				continue
+			else
+				break
+			fi
 		done
+		echo "Reshape has not started after 10 seconds"
+
+		# Now let's wait for reshape to finish.
+		echo "Waiting for grow-continue to finish"
+		wait_for_reshape_end
+		# If we have matrix-raid there's a second process ongoing
+		sleep 5
+		wait_for_reshape_end
+
 		echo $min > /proc/sys/dev/raid/speed_limit_min
 		echo $max > /proc/sys/dev/raid/speed_limit_max
 	;;
diff --git a/tests/imsm-grow-template b/tests/imsm-grow-template
index f69e025..c3279fc 100644
--- a/tests/imsm-grow-template
+++ b/tests/imsm-grow-template
@@ -103,9 +103,7 @@ else
 			exit 1
 		fi
 	else
-		sleep 5
 		check wait
-		sleep 5
 		check wait
 		imsm_check member $member0 $num_disks $vol0_level $vol0_comp_size $((vol0_comp_size * vol0_new_num_comps)) $vol0_offset $vol0_chunk
 		testdev $member0 $vol0_new_num_comps $vol0_comp_size $vol0_chunk
diff --git a/tests/templates/names_template b/tests/templates/names_template
index c94245e..8060794 100644
--- a/tests/templates/names_template
+++ b/tests/templates/names_template
@@ -4,8 +4,6 @@ function names_create() {
 	local NAME=$2
 	local NEG_TEST=$3
 
-	is_raid_foreign $DEVNAME
-
 	if [[ -z "$NAME" ]]; then
 		mdadm -CR "$DEVNAME" -l0 -n 1 $dev0 --force
 	else
@@ -34,6 +32,10 @@ function names_verify() {
 	local WANTED_NAME="$3"
 	local EXPECTED=""
 
+	# We don't know what is saved in metadata, but we know what to expect. Therfore check if
+	# expecation would be foreign (no hostname information).
+	is_raid_foreign $WANTED_NAME
+
 	local RES="$(mdadm -D --export $DEVNODE_NAME | grep MD_DEVNAME)"
 	if [[ "$?" != "0" ]]; then
 		echo "Cannot get details for $DEVNODE_NAME - unexpected devnode."
-- 
cgit v1.2.3