Skip to contentSkip to conversation

fstests/btrfs: fixes for tests btrfs/06[0-9] and btrfs/07[0-4]

PATCH In review [email protected] 2 participants 27 messages Mar 27, 2024 – Mar 28, 2024 Btrfs file system

lore
Share & tools
lore
#0 lore raw

cover fstests/btrfs: fixes for tests btrfs/06[0-9] and btrfs/07[0-4]

From: Filipe Manana <[email protected]>

Killing any of the tests cases btrfs/06[0-9] and btrfs/07[0-4] often leaves some background processes running around that prevent unmounting the scratch filesystems or running fstests again. When that happens it requires manually finding which processes are still using the scratch filesystem and then kill them. These patches address that issue. Details in the change logs.

Filipe Manana (10):
btrfs: add helper to kill background process running _btrfs_stress_balance btrfs/028: use the helper _btrfs_kill_stress_balance_pid
btrfs/028: removed redundant sync and scratch filesystem unmount
btrfs: add helper to kill background process running _btrfs_stress_scrub
btrfs: add helper to kill background process running _btrfs_stress_defrag
btrfs: add helper to kill background process running _btrfs_stress_remount_compress
btrfs: add helper to kill background process running _btrfs_stress_replace
btrfs: add helper to stop background process running _btrfs_stress_subvolume
btrfs: remove stop file early at _btrfs_stress_subvolume btrfs/06[0-9]..07[0-4]: kill all background tasks when test is killed/interrupted

 common/btrfs    | 84 +++++++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/028 | 16 +++-------
 tests/btrfs/060 | 33 +++++++++++++------
 tests/btrfs/061 | 30 ++++++++++++------
 tests/btrfs/062 | 30 ++++++++++++------
 tests/btrfs/063 | 30 ++++++++++++------
 tests/btrfs/064 | 30 ++++++++++++------
 tests/btrfs/065 | 33 +++++++++++++------
 tests/btrfs/066 | 33 +++++++++++++------
 tests/btrfs/067 | 33 +++++++++++++------
 tests/btrfs/068 | 33 +++++++++++++------
 tests/btrfs/069 | 31 ++++++++++++------
 tests/btrfs/070 | 31 ++++++++++++------
 tests/btrfs/071 | 31 ++++++++++++------
 tests/btrfs/072 | 31 ++++++++++++------
 tests/btrfs/073 | 30 ++++++++++++------
 tests/btrfs/074 | 30 ++++++++++++------
 tests/btrfs/255 |  8 ++---
 18 files changed, 417 insertions(+), 160 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/10 btrfs: add helper to kill background process running _btrfs_stress_balance

From: Filipe Manana <[email protected]>

Killing a background process running _btrfs_stress_balance() is not as simple as sending a signal to the process and waiting for it to die. Therefore we have the following logic to terminate such process:

kill $pid
wait $pid
# Wait for the balance operation to finish. while ps aux | grep "balance start" | grep -qv grep; do
sleep 1
done

Since this is repeated in several test cases, move this logic to a common helper and use it in all affected test cases. This will help to avoid repeating the same code again several times in upcoming changes.

---
 common/btrfs    | 14 ++++++++++++++
 tests/btrfs/060 |  8 ++------
 tests/btrfs/061 | 10 ++++------
 tests/btrfs/062 | 10 ++++------
 tests/btrfs/063 | 10 ++++------
 tests/btrfs/064 | 10 ++++------
 tests/btrfs/255 |  8 ++------
 7 files changed, 34 insertions(+), 36 deletions(-)
common/btrfs +14 -0
index aa344706..e95cff7f 100644
@@ -308,6 +308,20 @@ _btrfs_stress_balance()
 	done
 }
 
+# Kill a background process running _btrfs_stress_balance()
+_btrfs_kill_stress_balance_pid()
+{
+	local balance_pid=$1
+
+	# Ignore if process already died.
+	kill $balance_pid &> /dev/null
+	wait $balance_pid &> /dev/null
+	# Wait for the balance operation to finish.
+	while ps aux | grep "balance start" | grep -qv grep; do
+		sleep 1
+	done
+}
+
 # stress btrfs by creating/mounting/umounting/deleting subvolume in a loop
 _btrfs_stress_subvolume()
 {
tests/btrfs/060 +2 -6
index a0184891..58167cc6 100755
@@ -57,12 +57,8 @@ run_test()
 	wait $fsstress_pid
 
 	touch $stop_file
-	kill $balance_pid
-	wait
-	# wait for the balance operation to finish
-	while ps aux | grep "balance start" | grep -qv grep; do
-		sleep 1
-	done
+	wait $subvol_pid
+	_btrfs_kill_stress_balance_pid $balance_pid
 
 	echo "Scrub the filesystem" >>$seqres.full
 	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/061 +4 -6
index c1010413..d0b55e48 100755
@@ -51,12 +51,10 @@ run_test()
 
 	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
 	wait $fsstress_pid
-	kill $balance_pid $scrub_pid
-	wait
-	# wait for the balance and scrub operations to finish
-	while ps aux | grep "balance start" | grep -qv grep; do
-		sleep 1
-	done
+	_btrfs_kill_stress_balance_pid $balance_pid
+	kill $scrub_pid
+	wait $scrub_pid
+	# wait for the crub operation to finish
 	while ps aux | grep "scrub start" | grep -qv grep; do
 		sleep 1
 	done
tests/btrfs/062 +4 -6
index 818a0156..a2639d6c 100755
@@ -52,12 +52,10 @@ run_test()
 
 	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
 	wait $fsstress_pid
-	kill $balance_pid $defrag_pid
-	wait
-	# wait for the balance and defrag operations to finish
-	while ps aux | grep "balance start" | grep -qv grep; do
-		sleep 1
-	done
+	_btrfs_kill_stress_balance_pid $balance_pid
+	kill $defrag_pid
+	wait $defrag_pid
+	# wait for the defrag operation to finish
 	while ps aux | grep "btrfs filesystem defrag" | grep -qv grep; do
 		sleep 1
 	done
tests/btrfs/063 +4 -6
index 2f771baf..baf0c356 100755
@@ -51,12 +51,10 @@ run_test()
 
 	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
 	wait $fsstress_pid
-	kill $balance_pid $remount_pid
-	wait
-	# wait for the balance and remount loop to finish
-	while ps aux | grep "balance start" | grep -qv grep; do
-		sleep 1
-	done
+	_btrfs_kill_stress_balance_pid $balance_pid
+	kill $remount_pid
+	wait $remount_pid
+	# wait for the remount loop to finish
 	while ps aux | grep "mount.*$SCRATCH_MNT" | grep -qv grep; do
 		sleep 1
 	done
tests/btrfs/064 +4 -6
index e9b46ce6..58b53afe 100755
@@ -63,12 +63,10 @@ run_test()
 
 	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
 	wait $fsstress_pid
-	kill $balance_pid $replace_pid
-	wait
-	# wait for the balance and replace operations to finish
-	while ps aux | grep "balance start" | grep -qv grep; do
-		sleep 1
-	done
+	_btrfs_kill_stress_balance_pid $balance_pid
+	kill $replace_pid
+	wait $replace_pid
+	# wait for the replace operation to finish
 	while ps aux | grep "replace start" | grep -qv grep; do
 		sleep 1
 	done
tests/btrfs/255 +2 -6
index 7e70944a..aa250467 100755
@@ -41,12 +41,8 @@ for ((i = 0; i < 20; i++)); do
 	$BTRFS_UTIL_PROG quota enable $SCRATCH_MNT
 	$BTRFS_UTIL_PROG quota disable $SCRATCH_MNT
 done
-kill $balance_pid &> /dev/null
-wait
-# wait for the balance operation to finish
-while ps aux | grep "balance start" | grep -qv grep; do
-	sleep 1
-done
+
+_btrfs_kill_stress_balance_pid $balance_pid
 
 echo "Silence is golden"
 status=0
Signature · 1 line
2.43.0
#4 lore raw

PATCH 2/10 btrfs/028: use the helper _btrfs_kill_stress_balance_pid

In reply to [email protected]

From: Filipe Manana <[email protected]>

Now that there's a helper to kill a background process that is running _btrfs_stress_balance(), use it in btrfs/028. It's equivalent to the existing code in btrfs/028.

---
 tests/btrfs/028 | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
tests/btrfs/028 +3 -6
index d860974e..8fbe8887 100755
@@ -44,12 +44,9 @@ balance_pid=$!
 
 # 30s is enough to trigger bug
 sleep $((30*$TIME_FACTOR))
-kill $fsstress_pid $balance_pid &> /dev/null
-wait
-
-# kill _btrfs_stress_balance can't end balance, so call btrfs balance cancel
-# to cancel running or paused balance.
-$BTRFS_UTIL_PROG balance cancel $SCRATCH_MNT &> /dev/null
+kill $fsstress_pid &> /dev/null
+wait $fsstress_pid &> /dev/null
+_btrfs_kill_stress_balance_pid $balance_pid
 
 _run_btrfs_util_prog filesystem sync $SCRATCH_MNT
 
Signature · 1 line
2.43.0
#7 lore raw

PATCH 3/10 btrfs/028: removed redundant sync and scratch filesystem unmount

In reply to [email protected]

From: Filipe Manana <[email protected]>

There's no need to have an explicit scratch filesystem sync and unmount at the of the test, as the fstests framework automatically unmounts the filesystem and the unmount naturally syncs any data and metadata.

So remove them and update the comment to be more clear.

---
 tests/btrfs/028 | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
tests/btrfs/028 +2 -5
index 8fbe8887..0c96b2fe 100755
@@ -48,11 +48,8 @@ kill $fsstress_pid &> /dev/null
 wait $fsstress_pid &> /dev/null
 _btrfs_kill_stress_balance_pid $balance_pid
 
-_run_btrfs_util_prog filesystem sync $SCRATCH_MNT
-
-_scratch_unmount
-
-# qgroup will be checked at _check_scratch_fs() by fstest.
+# The qgroups accounting will be checked by 'btrfs check' (fsck) after the
+# fstests framework unmounts the filesystem.
 echo "Silence is golden"
 status=0
 
Signature · 1 line
2.43.0
#8 lore raw

PATCH 4/10 btrfs: add helper to kill background process running _btrfs_stress_scrub

In reply to [email protected]

From: Filipe Manana <[email protected]>

Killing a background process running _btrfs_stress_scrub() is not as simple as sending a signal to the process and waiting for it to die. Therefore we have the following logic to terminate such process:

kill $pid
wait $pid
while ps aux | grep "scrub start" | grep -qv grep; do
sleep 1
done

Since this is repeated in several test cases, move this logic to a common helper and use it in all affected test cases. This will help to avoid repeating the same code again several times in upcoming changes.

---
 common/btrfs    | 14 ++++++++++++++
 tests/btrfs/061 |  7 +------
 tests/btrfs/066 |  8 ++------
 tests/btrfs/069 | 11 +++++------
 tests/btrfs/072 | 11 +++++------
 tests/btrfs/073 | 11 +++++------
 6 files changed, 32 insertions(+), 30 deletions(-)
common/btrfs +14 -0
index e95cff7f..d0adeea1 100644
@@ -349,6 +349,20 @@ _btrfs_stress_scrub()
 	done
 }
 
+# Kill a background process running _btrfs_stress_scrub()
+_btrfs_kill_stress_scrub_pid()
+{
+       local scrub_pid=$1
+
+       # Ignore if process already died.
+       kill $scrub_pid &> /dev/null
+       wait $scrub_pid &> /dev/null
+       # Wait for the scrub operation to finish.
+       while ps aux | grep "scrub start" | grep -qv grep; do
+               sleep 1
+       done
+}
+
 # stress btrfs by defragmenting every file/dir in a loop and compress file
 # contents while defragmenting if second argument is not "nocompress"
 _btrfs_stress_defrag()
tests/btrfs/061 +1 -6
index d0b55e48..b8b2706c 100755
@@ -52,12 +52,7 @@ run_test()
 	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
 	wait $fsstress_pid
 	_btrfs_kill_stress_balance_pid $balance_pid
-	kill $scrub_pid
-	wait $scrub_pid
-	# wait for the crub operation to finish
-	while ps aux | grep "scrub start" | grep -qv grep; do
-		sleep 1
-	done
+	_btrfs_kill_stress_scrub_pid $scrub_pid
 
 	echo "Scrub the filesystem" >>$seqres.full
 	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/066 +2 -6
index a29034bb..29821fdd 100755
@@ -57,12 +57,8 @@ run_test()
 	wait $fsstress_pid
 
 	touch $stop_file
-	kill $scrub_pid
-	wait
-	# wait for the scrub operation to finish
-	while ps aux | grep "scrub start" | grep -qv grep; do
-		sleep 1
-	done
+	wait $subvol_pid
+	_btrfs_kill_stress_scrub_pid $scrub_pid
 
 	echo "Scrub the filesystem" >>$seqres.full
 	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/069 +5 -6
index 139dde48..20f44b39 100755
@@ -59,17 +59,16 @@ run_test()
 
 	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
 	wait $fsstress_pid
-	kill $replace_pid $scrub_pid
-	wait
+	kill $replace_pid
+	wait $replace_pid
 
-	# wait for the scrub and replace operations to finish
-	while ps aux | grep "scrub start" | grep -qv grep; do
-		sleep 1
-	done
+	# wait for the replace operation to finish
 	while ps aux | grep "replace start" | grep -qv grep; do
 		sleep 1
 	done
 
+	_btrfs_kill_stress_scrub_pid $scrub_pid
+
 	echo "Scrub the filesystem" >>$seqres.full
 	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
 	if [ $? -ne 0 ]; then
tests/btrfs/072 +5 -6
index 4b6b6fb5..6c15b51f 100755
@@ -52,16 +52,15 @@ run_test()
 
 	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
 	wait $fsstress_pid
-	kill $scrub_pid $defrag_pid
-	wait
-	# wait for the scrub and defrag operations to finish
-	while ps aux | grep "scrub start" | grep -qv grep; do
-		sleep 1
-	done
+	kill $defrag_pid
+	wait $defrag_pid
+	# wait for the defrag operation to finish
 	while ps aux | grep "btrfs filesystem defrag" | grep -qv grep; do
 		sleep 1
 	done
 
+	_btrfs_kill_stress_scrub_pid $scrub_pid
+
 	echo "Scrub the filesystem" >>$seqres.full
 	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
 	if [ $? -ne 0 ]; then
tests/btrfs/073 +5 -6
index b1604f94..49a4abd1 100755
@@ -51,16 +51,15 @@ run_test()
 
 	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
 	wait $fsstress_pid
-	kill $scrub_pid $remount_pid
-	wait
-	# wait for the scrub and remount operations to finish
-	while ps aux | grep "scrub start" | grep -qv grep; do
-		sleep 1
-	done
+	kill $remount_pid
+	wait $remount_pid
+	# wait for the remount operation to finish
 	while ps aux | grep "mount.*$SCRATCH_MNT" | grep -qv grep; do
 		sleep 1
 	done
 
+	_btrfs_kill_stress_scrub_pid $scrub_pid
+
 	echo "Scrub the filesystem" >>$seqres.full
 	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
 	if [ $? -ne 0 ]; then
Signature · 1 line
2.43.0
#11 lore raw

PATCH 5/10 btrfs: add helper to kill background process running _btrfs_stress_defrag

In reply to [email protected]

From: Filipe Manana <[email protected]>

Killing a background process running _btrfs_stress_defrag() is not as simple as sending a signal to the process and waiting for it to die. Therefore we have the following logic to terminate such process:

kill $pid
wait $pid
while ps aux | grep "btrfs filesystem defrag" | grep -qv grep; do
sleep 1
done

Since this is repeated in several test cases, move this logic to a common helper and use it in all affected test cases. This will help to avoid repeating the same code again several times in upcoming changes.

---
 common/btrfs    | 14 ++++++++++++++
 tests/btrfs/062 |  7 +------
 tests/btrfs/067 |  8 ++------
 tests/btrfs/070 | 11 +++++------
 tests/btrfs/072 |  7 +------
 tests/btrfs/074 | 11 +++++------
 6 files changed, 28 insertions(+), 30 deletions(-)
common/btrfs +14 -0
index d0adeea1..46056d4a 100644
@@ -383,6 +383,20 @@ _btrfs_stress_defrag()
 	done
 }
 
+# Kill a background process running _btrfs_stress_defrag()
+_btrfs_kill_stress_defrag_pid()
+{
+       local defrag_pid=$1
+
+       # Ignore if process already died.
+       kill $defrag_pid &> /dev/null
+       wait $defrag_pid &> /dev/null
+       # Wait for the defrag operation to finish.
+       while ps aux | grep "btrfs filesystem defrag" | grep -qv grep; do
+               sleep 1
+       done
+}
+
 # stress btrfs by remounting it with different compression algorithms in a loop
 # run this with fsstress running at background could exercise the compression
 # code path and ensure no race when switching compression algorithm with constant
tests/btrfs/062 +1 -6
index a2639d6c..59d581be 100755
@@ -53,12 +53,7 @@ run_test()
 	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
 	wait $fsstress_pid
 	_btrfs_kill_stress_balance_pid $balance_pid
-	kill $defrag_pid
-	wait $defrag_pid
-	# wait for the defrag operation to finish
-	while ps aux | grep "btrfs filesystem defrag" | grep -qv grep; do
-		sleep 1
-	done
+	_btrfs_kill_stress_defrag_pid $defrag_pid
 
 	echo "Scrub the filesystem" >>$seqres.full
 	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/067 +2 -6
index 709db155..2bb00b87 100755
@@ -58,12 +58,8 @@ run_test()
 	wait $fsstress_pid
 
 	touch $stop_file
-	kill $defrag_pid
-	wait
-	# wait for btrfs defrag process to exit, otherwise it will block umount
-	while ps aux | grep "btrfs filesystem defrag" | grep -qv grep; do
-		sleep 1
-	done
+	wait $subvol_pid
+	_btrfs_kill_stress_defrag_pid $defrag_pid
 
 	echo "Scrub the filesystem" >>$seqres.full
 	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/070 +5 -6
index 54aa275c..cefa5723 100755
@@ -60,17 +60,16 @@ run_test()
 
 	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
 	wait $fsstress_pid
-	kill $replace_pid $defrag_pid
-	wait
+	kill $replace_pid
+	wait $replace_pid
 
-	# wait for the defrag and replace operations to finish
-	while ps aux | grep "btrfs filesystem defrag" | grep -qv grep; do
-		sleep 1
-	done
+	# wait for the replace operation to finish
 	while ps aux | grep "replace start" | grep -qv grep; do
 		sleep 1
 	done
 
+	_btrfs_kill_stress_defrag_pid $defrag_pid
+
 	echo "Scrub the filesystem" >>$seqres.full
 	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
 	if [ $? -ne 0 ]; then
tests/btrfs/072 +1 -6
index 6c15b51f..505d0b57 100755
@@ -52,13 +52,8 @@ run_test()
 
 	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
 	wait $fsstress_pid
-	kill $defrag_pid
-	wait $defrag_pid
-	# wait for the defrag operation to finish
-	while ps aux | grep "btrfs filesystem defrag" | grep -qv grep; do
-		sleep 1
-	done
 
+	_btrfs_kill_stress_defrag_pid $defrag_pid
 	_btrfs_kill_stress_scrub_pid $scrub_pid
 
 	echo "Scrub the filesystem" >>$seqres.full
tests/btrfs/074 +5 -6
index 9b22c620..d51922d0 100755
@@ -52,16 +52,15 @@ run_test()
 
 	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
 	wait $fsstress_pid
-	kill $defrag_pid $remount_pid
-	wait
-	# wait for the defrag and remount operations to finish
-	while ps aux | grep "btrfs filesystem defrag" | grep -qv grep; do
-		sleep 1
-	done
+	kill $remount_pid
+	wait $remount_pid
+	# wait for the remount operation to finish
 	while ps aux | grep "mount.*$SCRATCH_MNT" | grep -qv grep; do
 		sleep 1
 	done
 
+	_btrfs_kill_stress_defrag_pid $defrag_pid
+
 	echo "Scrub the filesystem" >>$seqres.full
 	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
 	if [ $? -ne 0 ]; then
Signature · 1 line
2.43.0
#14 lore raw

PATCH 6/10 btrfs: add helper to kill background process running _btrfs_stress_remount_compress

In reply to [email protected]

From: Filipe Manana <[email protected]>

Killing a background process running _btrfs_stress_remount_compress() is not as simple as sending a signal to the process and waiting for it to die. Therefore we have the following logic to terminate such process:

kill $pid
wait $pid
while ps aux | grep "mount.*$SCRATCH_MNT" | grep -qv grep; do
sleep 1
done

Since this is repeated in several test cases, move this logic to a common helper and use it in all affected test cases. This will help to avoid repeating the same code again several times in upcoming changes.

---
 common/btrfs    | 15 +++++++++++++++
 tests/btrfs/063 |  7 +------
 tests/btrfs/068 |  8 ++------
 tests/btrfs/071 | 12 +++++-------
 tests/btrfs/073 |  8 +-------
 tests/btrfs/074 |  8 +-------
 6 files changed, 25 insertions(+), 33 deletions(-)
common/btrfs +15 -0
index 46056d4a..66a3a347 100644
@@ -411,6 +411,21 @@ _btrfs_stress_remount_compress()
 	done
 }
 
+# Kill a background process running _btrfs_stress_remount_compress()
+_btrfs_kill_stress_remount_compress_pid()
+{
+	local remount_pid=$1
+	local btrfs_mnt=$2
+
+	# Ignore if process already died.
+	kill $remount_pid &> /dev/null
+	wait $remount_pid &> /dev/null
+	# Wait for the remount loop to finish.
+	while ps aux | grep "mount.*${btrfs_mnt}" | grep -qv grep; do
+		sleep 1
+	done
+}
+
 # stress btrfs by replacing devices in a loop
 # Note that at least 3 devices are needed in SCRATCH_DEV_POOL and the last
 # device should be free(not used by btrfs)
tests/btrfs/063 +1 -6
index baf0c356..5ee2837f 100755
@@ -52,12 +52,7 @@ run_test()
 	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
 	wait $fsstress_pid
 	_btrfs_kill_stress_balance_pid $balance_pid
-	kill $remount_pid
-	wait $remount_pid
-	# wait for the remount loop to finish
-	while ps aux | grep "mount.*$SCRATCH_MNT" | grep -qv grep; do
-		sleep 1
-	done
+	_btrfs_kill_stress_remount_compress_pid $remount_pid $SCRATCH_MNT
 
 	echo "Scrub the filesystem" >>$seqres.full
 	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/068 +2 -6
index 15fd41db..db53254a 100755
@@ -58,12 +58,8 @@ run_test()
 	wait $fsstress_pid
 
 	touch $stop_file
-	kill $remount_pid
-	wait
-	# wait for the remount loop process to finish
-	while ps aux | grep "mount.*$SCRATCH_MNT" | grep -qv grep; do
-		sleep 1
-	done
+	wait $subvol_pid
+	_btrfs_kill_stress_remount_compress_pid $remount_pid $SCRATCH_MNT
 
 	echo "Scrub the filesystem" >>$seqres.full
 	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/071 +5 -7
index 6ebbd8cc..7ba15390 100755
@@ -58,17 +58,15 @@ run_test()
 	echo "$remount_pid" >>$seqres.full
 
 	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
-	wait $fsstress_pid
-	kill $replace_pid $remount_pid
-	wait
+	kill $replace_pid
+	wait $fsstress_pid $replace_pid
 
-	# wait for the remount and replace operations to finish
+	# wait for the replace operationss to finish
 	while ps aux | grep "replace start" | grep -qv grep; do
 		sleep 1
 	done
-	while ps aux | grep "mount.*$SCRATCH_MNT" | grep -qv grep; do
-		sleep 1
-	done
+
+	_btrfs_kill_stress_remount_compress_pid $remount_pid $SCRATCH_MNT
 
 	echo "Scrub the filesystem" >>$seqres.full
 	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/073 +1 -7
index 49a4abd1..50358286 100755
@@ -51,13 +51,7 @@ run_test()
 
 	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
 	wait $fsstress_pid
-	kill $remount_pid
-	wait $remount_pid
-	# wait for the remount operation to finish
-	while ps aux | grep "mount.*$SCRATCH_MNT" | grep -qv grep; do
-		sleep 1
-	done
-
+	_btrfs_kill_stress_remount_compress_pid $remount_pid $SCRATCH_MNT
 	_btrfs_kill_stress_scrub_pid $scrub_pid
 
 	echo "Scrub the filesystem" >>$seqres.full
tests/btrfs/074 +1 -7
index d51922d0..6e93b36a 100755
@@ -52,13 +52,7 @@ run_test()
 
 	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
 	wait $fsstress_pid
-	kill $remount_pid
-	wait $remount_pid
-	# wait for the remount operation to finish
-	while ps aux | grep "mount.*$SCRATCH_MNT" | grep -qv grep; do
-		sleep 1
-	done
-
+	_btrfs_kill_stress_remount_compress_pid $remount_pid $SCRATCH_MNT
 	_btrfs_kill_stress_defrag_pid $defrag_pid
 
 	echo "Scrub the filesystem" >>$seqres.full
Signature · 1 line
2.43.0
#19 lore raw

PATCH 7/10 btrfs: add helper to kill background process running _btrfs_stress_replace

In reply to [email protected]

From: Filipe Manana <[email protected]>

Killing a background process running _btrfs_stress_replace() is not as simple as sending a signal to the process and waiting for it to die. Therefore we have the following logic to terminate such process:

kill $pid
wait $pid
while ps aux | grep "replace start" | grep -qv grep; do
sleep 1
done

Since this is repeated in several test cases, move this logic to a common helper and use it in all affected test cases. This will help to avoid repeating the same code again several times in upcoming changes.

---
 common/btrfs    | 14 ++++++++++++++
 tests/btrfs/064 |  7 +------
 tests/btrfs/065 |  8 ++------
 tests/btrfs/069 |  9 +--------
 tests/btrfs/070 |  9 +--------
 tests/btrfs/071 | 10 ++--------
 6 files changed, 21 insertions(+), 36 deletions(-)
common/btrfs +14 -0
index 66a3a347..6d7e7a68 100644
@@ -475,6 +475,20 @@ _btrfs_stress_replace()
 	done
 }
 
+# Kill a background process running _btrfs_stress_replace()
+_btrfs_kill_stress_replace_pid()
+{
+       local replace_pid=$1
+
+       # Ignore if process already died.
+       kill $replace_pid &> /dev/null
+       wait $replace_pid &> /dev/null
+       # Wait for the replace operation to finish.
+       while ps aux | grep "replace start" | grep -qv grep; do
+               sleep 1
+       done
+}
+
 # find the right option to force output in bytes, older versions of btrfs-progs
 # print that by default, newer print human readable numbers with unit suffix
 _btrfs_qgroup_units()
tests/btrfs/064 +1 -6
index 58b53afe..9e0b3b30 100755
@@ -64,12 +64,7 @@ run_test()
 	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
 	wait $fsstress_pid
 	_btrfs_kill_stress_balance_pid $balance_pid
-	kill $replace_pid
-	wait $replace_pid
-	# wait for the replace operation to finish
-	while ps aux | grep "replace start" | grep -qv grep; do
-		sleep 1
-	done
+	_btrfs_kill_stress_replace_pid $replace_pid
 
 	echo "Scrub the filesystem" >>$seqres.full
 	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/065 +2 -6
index c4b6aafe..d2b04178 100755
@@ -65,12 +65,8 @@ run_test()
 	wait $fsstress_pid
 
 	touch $stop_file
-	kill $replace_pid
-	wait
-	# wait for the replace operation to finish
-	while ps aux | grep "replace start" | grep -qv grep; do
-		sleep 1
-	done
+	wait $subvol_pid
+	_btrfs_kill_stress_replace_pid $replace_pid
 
 	echo "Scrub the filesystem" >>$seqres.full
 	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/069 +1 -8
index 20f44b39..ad1609d4 100755
@@ -59,15 +59,8 @@ run_test()
 
 	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
 	wait $fsstress_pid
-	kill $replace_pid
-	wait $replace_pid
-
-	# wait for the replace operation to finish
-	while ps aux | grep "replace start" | grep -qv grep; do
-		sleep 1
-	done
-
 	_btrfs_kill_stress_scrub_pid $scrub_pid
+	_btrfs_kill_stress_replace_pid $replace_pid
 
 	echo "Scrub the filesystem" >>$seqres.full
 	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/070 +1 -8
index cefa5723..3054c270 100755
@@ -60,14 +60,7 @@ run_test()
 
 	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
 	wait $fsstress_pid
-	kill $replace_pid
-	wait $replace_pid
-
-	# wait for the replace operation to finish
-	while ps aux | grep "replace start" | grep -qv grep; do
-		sleep 1
-	done
-
+	_btrfs_kill_stress_replace_pid $replace_pid
 	_btrfs_kill_stress_defrag_pid $defrag_pid
 
 	echo "Scrub the filesystem" >>$seqres.full
tests/btrfs/071 +2 -8
index 7ba15390..36b39341 100755
@@ -58,14 +58,8 @@ run_test()
 	echo "$remount_pid" >>$seqres.full
 
 	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
-	kill $replace_pid
-	wait $fsstress_pid $replace_pid
-
-	# wait for the replace operationss to finish
-	while ps aux | grep "replace start" | grep -qv grep; do
-		sleep 1
-	done
-
+	wait $fsstress_pid
+	_btrfs_kill_stress_replace_pid $replace_pid
 	_btrfs_kill_stress_remount_compress_pid $remount_pid $SCRATCH_MNT
 
 	echo "Scrub the filesystem" >>$seqres.full
Signature · 1 line
2.43.0
#21 lore raw

PATCH 8/10 btrfs: add helper to stop background process running _btrfs_stress_subvolume

In reply to [email protected]

From: Filipe Manana <[email protected]>

We have this logic to stop a process running _btrfs_stress_subvolume() spread in several test cases:

touch $stop_file
wait $subvol_pid

Add a helper to encapsulate that logic and also remove the stop file after the process terminated as there's no point having it around anymore.

This will help to avoid repeating the same code again several times in upcoming changes.

---
 common/btrfs    | 12 ++++++++++++
 tests/btrfs/060 |  3 +--
 tests/btrfs/065 |  3 +--
 tests/btrfs/066 |  3 +--
 tests/btrfs/067 |  3 +--
 tests/btrfs/068 |  3 +--
 6 files changed, 17 insertions(+), 10 deletions(-)
common/btrfs +12 -0
index 6d7e7a68..e19a6ad1 100644
@@ -340,6 +340,18 @@ _btrfs_stress_subvolume()
 	done
 }
 
+# Kill a background process running _btrfs_stress_subvolume()
+_btrfs_kill_stress_subvolume_pid()
+{
+	local subvol_pid=$1
+	local stop_file=$2
+
+	touch $stop_file
+	# Ignore if process already died.
+	wait $subvol_pid &> /dev/null
+	rm -f $stop_file
+}
+
 # stress btrfs by running scrub in a loop
 _btrfs_stress_scrub()
 {
tests/btrfs/060 +1 -2
index 58167cc6..87823aba 100755
@@ -56,8 +56,7 @@ run_test()
 	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
 	wait $fsstress_pid
 
-	touch $stop_file
-	wait $subvol_pid
+	_btrfs_kill_stress_subvolume_pid $subvol_pid $stop_file
 	_btrfs_kill_stress_balance_pid $balance_pid
 
 	echo "Scrub the filesystem" >>$seqres.full
tests/btrfs/065 +1 -2
index d2b04178..ddc28616 100755
@@ -64,8 +64,7 @@ run_test()
 	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
 	wait $fsstress_pid
 
-	touch $stop_file
-	wait $subvol_pid
+	_btrfs_kill_stress_subvolume_pid $subvol_pid $stop_file
 	_btrfs_kill_stress_replace_pid $replace_pid
 
 	echo "Scrub the filesystem" >>$seqres.full
tests/btrfs/066 +1 -2
index 29821fdd..c7488602 100755
@@ -56,8 +56,7 @@ run_test()
 	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
 	wait $fsstress_pid
 
-	touch $stop_file
-	wait $subvol_pid
+	_btrfs_kill_stress_subvolume_pid $subvol_pid $stop_file
 	_btrfs_kill_stress_scrub_pid $scrub_pid
 
 	echo "Scrub the filesystem" >>$seqres.full
tests/btrfs/067 +1 -2
index 2bb00b87..ebbec1be 100755
@@ -57,8 +57,7 @@ run_test()
 	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
 	wait $fsstress_pid
 
-	touch $stop_file
-	wait $subvol_pid
+	_btrfs_kill_stress_subvolume_pid $subvol_pid $stop_file
 	_btrfs_kill_stress_defrag_pid $defrag_pid
 
 	echo "Scrub the filesystem" >>$seqres.full
tests/btrfs/068 +1 -2
index db53254a..5f41fb74 100755
@@ -57,8 +57,7 @@ run_test()
 	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
 	wait $fsstress_pid
 
-	touch $stop_file
-	wait $subvol_pid
+	_btrfs_kill_stress_subvolume_pid $subvol_pid $stop_file
 	_btrfs_kill_stress_remount_compress_pid $remount_pid $SCRATCH_MNT
 
 	echo "Scrub the filesystem" >>$seqres.full
Signature · 1 line
2.43.0
#23 lore raw

PATCH 9/10 btrfs: remove stop file early at _btrfs_stress_subvolume

In reply to [email protected]

From: Filipe Manana <[email protected]>

Instead of having every test case that uses _btrfs_stress_subvolume() removing the stop file before calling that function, do the file remove at _btrfs_stress_subvolume(). There's no point in doing it in every single test case.

---
 common/btrfs    | 1 +
 tests/btrfs/060 | 2 --
 tests/btrfs/065 | 2 --
 tests/btrfs/066 | 2 --
 tests/btrfs/067 | 2 --
 tests/btrfs/068 | 2 --
 6 files changed, 1 insertion(+), 10 deletions(-)
common/btrfs +1 -0
index e19a6ad1..29061c23 100644
@@ -331,6 +331,7 @@ _btrfs_stress_subvolume()
 	local subvol_mnt=$4
 	local stop_file=$5
 
+	rm -f $stop_file
 	mkdir -p $subvol_mnt
 	while [ ! -e $stop_file ]; do
 		$BTRFS_UTIL_PROG subvolume create $btrfs_mnt/$subvol_name
tests/btrfs/060 +0 -2
index 87823aba..53cbd3a0 100755
@@ -46,8 +46,6 @@ run_test()
 	balance_pid=$!
 	echo "$balance_pid" >>$seqres.full
 
-	# make sure the stop sign is not there
-	rm -f $stop_file
 	echo -n "Start subvolume worker: " >>$seqres.full
 	_btrfs_stress_subvolume $SCRATCH_DEV $SCRATCH_MNT subvol_$$ $subvol_mnt $stop_file >/dev/null 2>&1 &
 	subvol_pid=$!
tests/btrfs/065 +0 -2
index ddc28616..f9e43cdc 100755
@@ -49,8 +49,6 @@ run_test()
 	$FSSTRESS_PROG $args >>$seqres.full &
 	fsstress_pid=$!
 
-	# make sure the stop sign is not there
-	rm -f $stop_file
 	echo -n "Start subvolume worker: " >>$seqres.full
 	_btrfs_stress_subvolume $SCRATCH_DEV $SCRATCH_MNT subvol_$$ $subvol_mnt $stop_file >/dev/null 2>&1 &
 	subvol_pid=$!
tests/btrfs/066 +0 -2
index c7488602..b6f904ac 100755
@@ -41,8 +41,6 @@ run_test()
 	$FSSTRESS_PROG $args >>$seqres.full &
 	fsstress_pid=$!
 
-	# make sure the stop sign is not there
-	rm -f $stop_file
 	echo -n "Start subvolume worker: " >>$seqres.full
 	_btrfs_stress_subvolume $SCRATCH_DEV $SCRATCH_MNT subvol_$$ $subvol_mnt $stop_file >/dev/null 2>&1 &
 	subvol_pid=$!
tests/btrfs/067 +0 -2
index ebbec1be..7be09d52 100755
@@ -42,8 +42,6 @@ run_test()
 	$FSSTRESS_PROG $args >>$seqres.full &
 	fsstress_pid=$!
 
-	# make sure the stop sign is not there
-	rm -f $stop_file
 	echo -n "Start subvolume worker: " >>$seqres.full
 	_btrfs_stress_subvolume $SCRATCH_DEV $SCRATCH_MNT subvol_$$ $subvol_mnt $stop_file >/dev/null 2>&1 &
 	subvol_pid=$!
tests/btrfs/068 +0 -2
index 5f41fb74..19e37010 100755
@@ -42,8 +42,6 @@ run_test()
 	$FSSTRESS_PROG $args >>$seqres.full &
 	fsstress_pid=$!
 
-	# make sure the stop sign is not there
-	rm -f $stop_file
 	echo -n "Start subvolume worker: " >>$seqres.full
 	_btrfs_stress_subvolume $SCRATCH_DEV $SCRATCH_MNT subvol_$$ $subvol_mnt $stop_file >/dev/null 2>&1 &
 	subvol_pid=$!
Signature · 1 line
2.43.0
#25 lore raw

PATCH 10/10 btrfs/06[0-9]..07[0-4]: kill all background tasks when test is killed/interrupted

In reply to [email protected]

From: Filipe Manana <[email protected]>

Test cases btrfs/06[0-9] and btrfs/07[0-4] exercise multiple concurrent operations while fsstress is running in parallel, and all these are left as child processes running in the background, which are correctly stopped if the tests are not interrupted/killed. However if any of these tests is interrupted/killed, it often leaves child processes still running in the background, which prevent further running fstests again. For example:

  $ /check -g auto
  (...)
  btrfs/060 394s ...  264s
  btrfs/061 83s ...  69s
  btrfs/062 109s ...  105s
  btrfs/063 52s ...  67s
  btrfs/064 53s ...  51s
  btrfs/065 88s ...  271s
  btrfs/066 127s ...  241s
  btrfs/067 435s ...  248s
  btrfs/068 161s ... ^C^C
  ^C
  $ ./check btrfs/068
  FSTYP         -- btrfs
  PLATFORM      -- Linux/x86_64 debian0 6.8.0-rc7-btrfs-next-153+ #1 SMP PREEMPT_DYNAMIC Mon Mar  4 17:19:19 WET 2024
  MKFS_OPTIONS  -- /dev/sdb
  MOUNT_OPTIONS -- /dev/sdb /home/fdmanana/btrfs-tests/scratch_1

our local _scratch_mkfs routine ... btrfs-progs v6.6.2
See https://btrfs.readthedocs.io for more information.

ERROR: unable to open /dev/sdb: Device or resource busy
check: failed to mkfs $SCRATCH_DEV using specified options Interrupted!
Passed all 0 tests

In this case there was still a process running _btrfs_stress_subvolume() from common/btrfs.

This is a bit annoying because it requires manually finding out which process is preventing unmounting the scratch device and then properly stop/kill it.

So fix this by adding a _cleanup() function to all these tests and then making sure it stops all the child processes it spawned and are running in the background.

All these tests have the same structure as they were part of the same patchset and from the same author.

---
 tests/btrfs/060 | 22 +++++++++++++++++++++-
 tests/btrfs/061 | 19 +++++++++++++++++++
 tests/btrfs/062 | 19 +++++++++++++++++++
 tests/btrfs/063 | 19 +++++++++++++++++++
 tests/btrfs/064 | 19 +++++++++++++++++++
 tests/btrfs/065 | 22 +++++++++++++++++++++-
 tests/btrfs/066 | 22 +++++++++++++++++++++-
 tests/btrfs/067 | 22 +++++++++++++++++++++-
 tests/btrfs/068 | 22 +++++++++++++++++++++-
 tests/btrfs/069 | 19 +++++++++++++++++++
 tests/btrfs/070 | 19 +++++++++++++++++++
 tests/btrfs/071 | 19 +++++++++++++++++++
 tests/btrfs/072 | 19 +++++++++++++++++++
 tests/btrfs/073 | 19 +++++++++++++++++++
 tests/btrfs/074 | 19 +++++++++++++++++++
 15 files changed, 295 insertions(+), 5 deletions(-)
tests/btrfs/060 +21 -1
index 53cbd3a0..f74d9593 100755
@@ -10,6 +10,22 @@
 . ./common/preamble
 _begin_fstest auto balance subvol scrub
 
+_cleanup()
+{
+	cd /
+	rm -rf $tmp.*
+	if [ ! -z "$stop_file" ] && [ ! -z "$subvol_pid" ]; then
+		_btrfs_kill_stress_subvolume_pid $subvol_pid $stop_file
+	fi
+	if [ ! -z "$balance_pid" ]; then
+		_btrfs_kill_stress_balance_pid $balance_pid
+	fi
+	if [ ! -z "$fsstress_pid" ]; then
+		kill $fsstress_pid &> /dev/null
+		wait $fsstress_pid &> /dev/null
+	fi
+}
+
 # Import common functions.
 . ./common/filter
 
@@ -20,11 +36,12 @@ _require_scratch_nocheck
 _require_scratch_dev_pool 4
 _btrfs_get_profile_configs
 
+stop_file=$TEST_DIR/$seq.stop.$$
+
 run_test()
 {
 	local mkfs_opts=$1
 	local subvol_mnt=$TEST_DIR/$seq.mnt
-	local stop_file=$TEST_DIR/$seq.stop.$$
 
 	echo "Test $mkfs_opts" >>$seqres.full
 
@@ -53,9 +70,12 @@ run_test()
 
 	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
 	wait $fsstress_pid
+	unset fsstress_pid
 
 	_btrfs_kill_stress_subvolume_pid $subvol_pid $stop_file
+	unset subvol_pid
 	_btrfs_kill_stress_balance_pid $balance_pid
+	unset balance_pid
 
 	echo "Scrub the filesystem" >>$seqres.full
 	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/061 +19 -0
index b8b2706c..fec90882 100755
@@ -10,6 +10,22 @@
 . ./common/preamble
 _begin_fstest auto balance scrub
 
+_cleanup()
+{
+	cd /
+	rm -rf $tmp.*
+	if [ ! -z "$balance_pid" ]; then
+		_btrfs_kill_stress_balance_pid $balance_pid
+	fi
+	if [ ! -z "$scrub_pid" ]; then
+		_btrfs_kill_stress_scrub_pid $scrub_pid
+	fi
+	if [ ! -z "$fsstress_pid" ]; then
+		kill $fsstress_pid &> /dev/null
+		wait $fsstress_pid &> /dev/null
+	fi
+}
+
 # Import common functions.
 . ./common/filter
 
@@ -51,8 +67,11 @@ run_test()
 
 	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
 	wait $fsstress_pid
+	unset fsstress_pid
 	_btrfs_kill_stress_balance_pid $balance_pid
+	unset balance_pid
 	_btrfs_kill_stress_scrub_pid $scrub_pid
+	unset scrub_pid
 
 	echo "Scrub the filesystem" >>$seqres.full
 	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/062 +19 -0
index 59d581be..0b57681f 100755
@@ -10,6 +10,22 @@
 . ./common/preamble
 _begin_fstest auto balance defrag compress scrub
 
+_cleanup()
+{
+	cd /
+	rm -rf $tmp.*
+	if [ ! -z "$balance_pid" ]; then
+		_btrfs_kill_stress_balance_pid $balance_pid
+	fi
+	if [ ! -z "$defrag_pid" ]; then
+		_btrfs_kill_stress_defrag_pid $defrag_pid
+	fi
+	if [ ! -z "$fsstress_pid" ]; then
+		kill $fsstress_pid &> /dev/null
+		wait $fsstress_pid &> /dev/null
+	fi
+}
+
 # Import common functions.
 . ./common/filter
 
@@ -52,8 +68,11 @@ run_test()
 
 	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
 	wait $fsstress_pid
+	unset fsstress_pid
 	_btrfs_kill_stress_balance_pid $balance_pid
+	unset balance_pid
 	_btrfs_kill_stress_defrag_pid $defrag_pid
+	unset defrag_pid
 
 	echo "Scrub the filesystem" >>$seqres.full
 	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/063 +19 -0
index 5ee2837f..99d9d2c1 100755
@@ -10,6 +10,22 @@
 . ./common/preamble
 _begin_fstest auto balance remount compress scrub
 
+_cleanup()
+{
+	cd /
+	rm -rf $tmp.*
+	if [ ! -z "$balance_pid" ]; then
+		_btrfs_kill_stress_balance_pid $balance_pid
+	fi
+	if [ ! -z "$remount_pid" ]; then
+		_btrfs_kill_stress_remount_compress_pid $remount_pid $SCRATCH_MNT
+	fi
+	if [ ! -z "$fsstress_pid" ]; then
+		kill $fsstress_pid &> /dev/null
+		wait $fsstress_pid &> /dev/null
+	fi
+}
+
 # Import common functions.
 . ./common/filter
 
@@ -51,8 +67,11 @@ run_test()
 
 	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
 	wait $fsstress_pid
+	unset fsstress_pid
 	_btrfs_kill_stress_balance_pid $balance_pid
+	unset balance_pid
 	_btrfs_kill_stress_remount_compress_pid $remount_pid $SCRATCH_MNT
+	unset remount_pid
 
 	echo "Scrub the filesystem" >>$seqres.full
 	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/064 +19 -0
index 9e0b3b30..663442c6 100755
@@ -12,6 +12,22 @@
 . ./common/preamble
 _begin_fstest auto balance replace volume scrub
 
+_cleanup()
+{
+	cd /
+	rm -rf $tmp.*
+	if [ ! -z "$balance_pid" ]; then
+		_btrfs_kill_stress_balance_pid $balance_pid
+	fi
+	if [ ! -z "$replace_pid" ]; then
+		_btrfs_kill_stress_replace_pid $replace_pid
+	fi
+	if [ ! -z "$fsstress_pid" ]; then
+		kill $fsstress_pid &> /dev/null
+		wait $fsstress_pid &> /dev/null
+	fi
+}
+
 # Import common functions.
 . ./common/filter
 
@@ -63,8 +79,11 @@ run_test()
 
 	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
 	wait $fsstress_pid
+	unset fsstress_pid
 	_btrfs_kill_stress_balance_pid $balance_pid
+	unset balance_pid
 	_btrfs_kill_stress_replace_pid $replace_pid
+	unset replace_pid
 
 	echo "Scrub the filesystem" >>$seqres.full
 	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/065 +21 -1
index f9e43cdc..b1e54fc8 100755
@@ -10,6 +10,22 @@
 . ./common/preamble
 _begin_fstest auto subvol replace volume scrub
 
+_cleanup()
+{
+	cd /
+	rm -rf $tmp.*
+	if [ ! -z "$stop_file" ] && [ ! -z "$subvol_pid" ]; then
+		_btrfs_kill_stress_subvolume_pid $subvol_pid $stop_file
+	fi
+	if [ ! -z "$replace_pid" ]; then
+		_btrfs_kill_stress_replace_pid $replace_pid
+	fi
+	if [ ! -z "$fsstress_pid" ]; then
+		kill $fsstress_pid &> /dev/null
+		wait $fsstress_pid &> /dev/null
+	fi
+}
+
 # Import common functions.
 . ./common/filter
 
@@ -21,12 +37,13 @@ _require_scratch_dev_pool 5
 _require_scratch_dev_pool_equal_size
 _btrfs_get_profile_configs replace
 
+stop_file=$TEST_DIR/$seq.stop.$$
+
 run_test()
 {
 	local mkfs_opts=$1
 	local saved_scratch_dev_pool=$SCRATCH_DEV_POOL
 	local subvol_mnt=$TEST_DIR/$seq.mnt
-	local stop_file=$TEST_DIR/$seq.stop.$$
 
 	echo "Test $mkfs_opts" >>$seqres.full
 
@@ -61,9 +78,12 @@ run_test()
 
 	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
 	wait $fsstress_pid
+	unset fsstress_pid
 
 	_btrfs_kill_stress_subvolume_pid $subvol_pid $stop_file
+	unset subvol_pid
 	_btrfs_kill_stress_replace_pid $replace_pid
+	unset replace_pid
 
 	echo "Scrub the filesystem" >>$seqres.full
 	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/066 +21 -1
index b6f904ac..feb6062e 100755
@@ -10,6 +10,22 @@
 . ./common/preamble
 _begin_fstest auto subvol scrub
 
+_cleanup()
+{
+	cd /
+	rm -rf $tmp.*
+	if [ ! -z "$stop_file" ] && [ ! -z "$subvol_pid" ]; then
+		_btrfs_kill_stress_subvolume_pid $subvol_pid $stop_file
+	fi
+	if [ ! -z "$scrub_pid" ]; then
+		_btrfs_kill_stress_scrub_pid $scrub_pid
+	fi
+	if [ ! -z "$fsstress_pid" ]; then
+		kill $fsstress_pid &> /dev/null
+		wait $fsstress_pid &> /dev/null
+	fi
+}
+
 # Import common functions.
 . ./common/filter
 
@@ -20,11 +36,12 @@ _require_scratch_nocheck
 _require_scratch_dev_pool 4
 _btrfs_get_profile_configs
 
+stop_file=$TEST_DIR/$seq.stop.$$
+
 run_test()
 {
 	local mkfs_opts=$1
 	local subvol_mnt=$TEST_DIR/$seq.mnt
-	local stop_file=$TEST_DIR/$seq.stop.$$
 
 	echo "Test $mkfs_opts" >>$seqres.full
 
@@ -53,9 +70,12 @@ run_test()
 
 	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
 	wait $fsstress_pid
+	unset fsstress_pid
 
 	_btrfs_kill_stress_subvolume_pid $subvol_pid $stop_file
+	unset subvol_pid
 	_btrfs_kill_stress_scrub_pid $scrub_pid
+	unset scrub_pid
 
 	echo "Scrub the filesystem" >>$seqres.full
 	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/067 +21 -1
index 7be09d52..0bbfe83f 100755
@@ -10,6 +10,22 @@
 . ./common/preamble
 _begin_fstest auto subvol defrag compress scrub
 
+_cleanup()
+{
+	cd /
+	rm -rf $tmp.*
+	if [ ! -z "$stop_file" ] && [ ! -z "$subvol_pid" ]; then
+		_btrfs_kill_stress_subvolume_pid $subvol_pid $stop_file
+	fi
+	if [ ! -z "$defrag_pid" ]; then
+		_btrfs_kill_stress_defrag_pid $defrag_pid
+	fi
+	if [ ! -z "$fsstress_pid" ]; then
+		kill $fsstress_pid &> /dev/null
+		wait $fsstress_pid &> /dev/null
+	fi
+}
+
 # Import common functions.
 . ./common/filter
 
@@ -20,12 +36,13 @@ _require_scratch_nocheck
 _require_scratch_dev_pool 4
 _btrfs_get_profile_configs
 
+stop_file=$TEST_DIR/$seq.stop.$$
+
 run_test()
 {
 	local mkfs_opts=$1
 	local with_compress=$2
 	local subvol_mnt=$TEST_DIR/$seq.mnt
-	local stop_file=$TEST_DIR/$seq.stop.$$
 
 	echo "Test $mkfs_opts with $with_compress" >>$seqres.full
 
@@ -54,9 +71,12 @@ run_test()
 
 	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
 	wait $fsstress_pid
+	unset fsstress_pid
 
 	_btrfs_kill_stress_subvolume_pid $subvol_pid $stop_file
+	unset subvol_pid
 	_btrfs_kill_stress_defrag_pid $defrag_pid
+	unset defrag_pid
 
 	echo "Scrub the filesystem" >>$seqres.full
 	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/068 +21 -1
index 19e37010..7ab6feca 100755
@@ -11,6 +11,22 @@
 . ./common/preamble
 _begin_fstest auto subvol remount compress scrub
 
+_cleanup()
+{
+	cd /
+	rm -rf $tmp.*
+	if [ ! -z "$stop_file" ] && [ ! -z "$subvol_pid" ]; then
+		_btrfs_kill_stress_subvolume_pid $subvol_pid $stop_file
+	fi
+	if [ ! -z "$remount_pid" ]; then
+		_btrfs_kill_stress_remount_compress_pid $remount_pid $SCRATCH_MNT
+	fi
+	if [ ! -z "$fsstress_pid" ]; then
+		kill $fsstress_pid &> /dev/null
+		wait $fsstress_pid &> /dev/null
+	fi
+}
+
 # Import common functions.
 . ./common/filter
 
@@ -21,11 +37,12 @@ _require_scratch_nocheck
 _require_scratch_dev_pool 4
 _btrfs_get_profile_configs
 
+stop_file=$TEST_DIR/$seq.stop.$$
+
 run_test()
 {
 	local mkfs_opts=$1
 	local subvol_mnt=$TEST_DIR/$seq.mnt
-	local stop_file=$TEST_DIR/$seq.stop.$$
 
 	echo "Test $mkfs_opts with $with_compress" >>$seqres.full
 
@@ -54,9 +71,12 @@ run_test()
 
 	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
 	wait $fsstress_pid
+	unset fsstress_pid
 
 	_btrfs_kill_stress_subvolume_pid $subvol_pid $stop_file
+	unset subvol_pid
 	_btrfs_kill_stress_remount_compress_pid $remount_pid $SCRATCH_MNT
+	unset remount_pid
 
 	echo "Scrub the filesystem" >>$seqres.full
 	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/069 +19 -0
index ad1609d4..3fbfecdb 100755
@@ -10,6 +10,22 @@
 . ./common/preamble
 _begin_fstest auto replace scrub volume
 
+_cleanup()
+{
+	cd /
+	rm -rf $tmp.*
+	if [ ! -z "$replace_pid" ]; then
+		_btrfs_kill_stress_replace_pid $replace_pid
+	fi
+	if [ ! -z "$scrub_pid" ]; then
+		_btrfs_kill_stress_scrub_pid $scrub_pid
+	fi
+	if [ ! -z "$fsstress_pid" ]; then
+		kill $fsstress_pid &> /dev/null
+		wait $fsstress_pid &> /dev/null
+	fi
+}
+
 # Import common functions.
 . ./common/filter
 
@@ -59,8 +75,11 @@ run_test()
 
 	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
 	wait $fsstress_pid
+	unset fsstress_pid
 	_btrfs_kill_stress_scrub_pid $scrub_pid
+	unset scrub_pid
 	_btrfs_kill_stress_replace_pid $replace_pid
+	unset replace_pid
 
 	echo "Scrub the filesystem" >>$seqres.full
 	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/070 +19 -0
index 3054c270..11fddc86 100755
@@ -10,6 +10,22 @@
 . ./common/preamble
 _begin_fstest auto replace defrag compress volume scrub
 
+_cleanup()
+{
+	cd /
+	rm -rf $tmp.*
+	if [ ! -z "$replace_pid" ]; then
+		_btrfs_kill_stress_replace_pid $replace_pid
+	fi
+	if [ ! -z "$defrag_pid" ]; then
+		_btrfs_kill_stress_defrag_pid $defrag_pid
+	fi
+	if [ ! -z "$fsstress_pid" ]; then
+		kill $fsstress_pid &> /dev/null
+		wait $fsstress_pid &> /dev/null
+	fi
+}
+
 # Import common functions.
 . ./common/filter
 
@@ -60,8 +76,11 @@ run_test()
 
 	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
 	wait $fsstress_pid
+	unset fsstress_pid
 	_btrfs_kill_stress_replace_pid $replace_pid
+	unset replace_pid
 	_btrfs_kill_stress_defrag_pid $defrag_pid
+	unset defrag_pid
 
 	echo "Scrub the filesystem" >>$seqres.full
 	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/071 +19 -0
index 36b39341..1a91ec45 100755
@@ -10,6 +10,22 @@
 . ./common/preamble
 _begin_fstest auto replace remount compress volume scrub
 
+_cleanup()
+{
+	cd /
+	rm -rf $tmp.*
+	if [ ! -z "$replace_pid" ]; then
+		_btrfs_kill_stress_replace_pid $replace_pid
+	fi
+	if [ ! -z "$remount_pid" ]; then
+		_btrfs_kill_stress_remount_compress_pid $remount_pid $SCRATCH_MNT
+	fi
+	if [ ! -z "$fsstress_pid" ]; then
+		kill $fsstress_pid &> /dev/null
+		wait $fsstress_pid &> /dev/null
+	fi
+}
+
 # Import common functions.
 . ./common/filter
 
@@ -59,8 +75,11 @@ run_test()
 
 	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
 	wait $fsstress_pid
+	unset fsstress_pid
 	_btrfs_kill_stress_replace_pid $replace_pid
+	unset replace_pid
 	_btrfs_kill_stress_remount_compress_pid $remount_pid $SCRATCH_MNT
+	unset remount_pid
 
 	echo "Scrub the filesystem" >>$seqres.full
 	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/072 +19 -0
index 505d0b57..e66e49c9 100755
@@ -10,6 +10,22 @@
 . ./common/preamble
 _begin_fstest auto scrub defrag compress
 
+_cleanup()
+{
+	cd /
+	rm -rf $tmp.*
+	if [ ! -z "$defrag_pid" ]; then
+		_btrfs_kill_stress_defrag_pid $defrag_pid
+	fi
+	if [ ! -z "$scrub_pid" ]; then
+		_btrfs_kill_stress_scrub_pid $scrub_pid
+	fi
+	if [ ! -z "$fsstress_pid" ]; then
+		kill $fsstress_pid &> /dev/null
+		wait $fsstress_pid &> /dev/null
+	fi
+}
+
 # Import common functions.
 . ./common/filter
 
@@ -52,9 +68,12 @@ run_test()
 
 	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
 	wait $fsstress_pid
+	unset fsstress_pid
 
 	_btrfs_kill_stress_defrag_pid $defrag_pid
+	unset defrag_pid
 	_btrfs_kill_stress_scrub_pid $scrub_pid
+	unset scrub_pid
 
 	echo "Scrub the filesystem" >>$seqres.full
 	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/073 +19 -0
index 50358286..e6cfd92a 100755
@@ -10,6 +10,22 @@
 . ./common/preamble
 _begin_fstest auto scrub remount compress
 
+_cleanup()
+{
+	cd /
+	rm -rf $tmp.*
+	if [ ! -z "$remount_pid" ]; then
+		_btrfs_kill_stress_remount_compress_pid $remount_pid $SCRATCH_MNT
+	fi
+	if [ ! -z "$scrub_pid" ]; then
+		_btrfs_kill_stress_scrub_pid $scrub_pid
+	fi
+	if [ ! -z "$fsstress_pid" ]; then
+		kill $fsstress_pid &> /dev/null
+		wait $fsstress_pid &> /dev/null
+	fi
+}
+
 # Import common functions.
 . ./common/filter
 
@@ -51,8 +67,11 @@ run_test()
 
 	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
 	wait $fsstress_pid
+	unset fsstress_pid
 	_btrfs_kill_stress_remount_compress_pid $remount_pid $SCRATCH_MNT
+	unset remount_pid
 	_btrfs_kill_stress_scrub_pid $scrub_pid
+	unset scrub_pid
 
 	echo "Scrub the filesystem" >>$seqres.full
 	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/074 +19 -0
index 6e93b36a..1dd88bcd 100755
@@ -10,6 +10,22 @@
 . ./common/preamble
 _begin_fstest auto defrag remount compress scrub
 
+_cleanup()
+{
+	cd /
+	rm -rf $tmp.*
+	if [ ! -z "$remount_pid" ]; then
+		_btrfs_kill_stress_remount_compress_pid $remount_pid $SCRATCH_MNT
+	fi
+	if [ ! -z "$defrag_pid" ]; then
+		_btrfs_kill_stress_defrag_pid $defrag_pid
+	fi
+	if [ ! -z "$fsstress_pid" ]; then
+		kill $fsstress_pid &> /dev/null
+		wait $fsstress_pid &> /dev/null
+	fi
+}
+
 # Import common functions.
 . ./common/filter
 
@@ -52,8 +68,11 @@ run_test()
 
 	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
 	wait $fsstress_pid
+	unset fsstress_pid
 	_btrfs_kill_stress_remount_compress_pid $remount_pid $SCRATCH_MNT
+	unset remount_pid
 	_btrfs_kill_stress_defrag_pid $defrag_pid
+	unset defrag_pid
 
 	echo "Scrub the filesystem" >>$seqres.full
 	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
Signature · 1 line
2.43.0
Reviewed-by on v1 1/10
#2 lore raw

Re: [PATCH 01/10] btrfs: add helper to kill background process running _btrfs_stress_balance

In reply to [email protected]
Quoted 12 lines · On 3/28/24 01:11, [email protected] wrote:

From: Filipe Manana <[email protected]>

Killing a background process running _btrfs_stress_balance() is not as simple as sending a signal to the process and waiting for it to die. Therefore we have the following logic to terminate such process:

kill $pid
wait $pid
# Wait for the balance operation to finish. while ps aux | grep "balance start" | grep -qv grep; do

Quoted 8 lines

sleep 1
done

Since this is repeated in several test cases, move this logic to a common helper and use it in all affected test cases. This will help to avoid repeating the same code again several times in upcoming changes.

A few minor things below.

Quoted 18 lines
---
  common/btrfs    | 14 ++++++++++++++
  tests/btrfs/060 |  8 ++------
  tests/btrfs/061 | 10 ++++------
  tests/btrfs/062 | 10 ++++------
  tests/btrfs/063 | 10 ++++------
  tests/btrfs/064 | 10 ++++------
  tests/btrfs/255 |  8 ++------
  7 files changed, 34 insertions(+), 36 deletions(-)
common/btrfs +0 -0
index aa344706..e95cff7f 100644
@@ -308,6 +308,20 @@ _btrfs_stress_balance()
  	done
  }
 

common/btrfs _btrfs_stress_balance() · line 320

Quoted 10 lines
common/btrfs +10 -0
+# Kill a background process running _btrfs_stress_balance()
+_btrfs_kill_stress_balance_pid()
+{
+	local balance_pid=$1
+
+	# Ignore if process already died.
+	kill $balance_pid &> /dev/null
+	wait $balance_pid &> /dev/null
+	# Wait for the balance operation to finish.
+	while ps aux | grep "balance start" | grep -qv grep; do

We can use pgrep instead. I will make the following changes before merging if you are okay with it.

- while ps aux | grep "balance start" | grep -qv grep; do
+ while pgrep -f "btrfs balance start" > /dev/null; do

Quoted 34 lines
common/btrfs +4 -0
+		sleep 1
+	done
+}
+
  # stress btrfs by creating/mounting/umounting/deleting subvolume in a loop
  _btrfs_stress_subvolume()
  {
tests/btrfs/060 +2 -6
index a0184891..58167cc6 100755
@@ -57,12 +57,8 @@ run_test()
  	wait $fsstress_pid
 
  	touch $stop_file
-	kill $balance_pid
-	wait
-	# wait for the balance operation to finish
-	while ps aux | grep "balance start" | grep -qv grep; do
-		sleep 1
-	done
+	wait $subvol_pid
+	_btrfs_kill_stress_balance_pid $balance_pid
 
  	echo "Scrub the filesystem" >>$seqres.full
  	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/061 +0 -0
index c1010413..d0b55e48 100755
@@ -51,12 +51,10 @@ run_test()
 
  	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
  	wait $fsstress_pid

tests/btrfs/061 run_test() · line 57

Quoted 10 lines
tests/btrfs/061 +4 -6
-	kill $balance_pid $scrub_pid
-	wait
-	# wait for the balance and scrub operations to finish
-	while ps aux | grep "balance start" | grep -qv grep; do
-		sleep 1
-	done
+	_btrfs_kill_stress_balance_pid $balance_pid
+	kill $scrub_pid
+	wait $scrub_pid
+	# wait for the crub operation to finish

s/crub/scrub/

Thanks, Anand

Quoted 85 lines
tests/btrfs/061 +0 -0
  	while ps aux | grep "scrub start" | grep -qv grep; do
  		sleep 1
  	done
tests/btrfs/062 +4 -6
index 818a0156..a2639d6c 100755
@@ -52,12 +52,10 @@ run_test()
 
  	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
  	wait $fsstress_pid
-	kill $balance_pid $defrag_pid
-	wait
-	# wait for the balance and defrag operations to finish
-	while ps aux | grep "balance start" | grep -qv grep; do
-		sleep 1
-	done
+	_btrfs_kill_stress_balance_pid $balance_pid
+	kill $defrag_pid
+	wait $defrag_pid
+	# wait for the defrag operation to finish
  	while ps aux | grep "btrfs filesystem defrag" | grep -qv grep; do
  		sleep 1
  	done
tests/btrfs/063 +4 -6
index 2f771baf..baf0c356 100755
@@ -51,12 +51,10 @@ run_test()
 
  	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
  	wait $fsstress_pid
-	kill $balance_pid $remount_pid
-	wait
-	# wait for the balance and remount loop to finish
-	while ps aux | grep "balance start" | grep -qv grep; do
-		sleep 1
-	done
+	_btrfs_kill_stress_balance_pid $balance_pid
+	kill $remount_pid
+	wait $remount_pid
+	# wait for the remount loop to finish
  	while ps aux | grep "mount.*$SCRATCH_MNT" | grep -qv grep; do
  		sleep 1
  	done
tests/btrfs/064 +4 -6
index e9b46ce6..58b53afe 100755
@@ -63,12 +63,10 @@ run_test()
 
  	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
  	wait $fsstress_pid
-	kill $balance_pid $replace_pid
-	wait
-	# wait for the balance and replace operations to finish
-	while ps aux | grep "balance start" | grep -qv grep; do
-		sleep 1
-	done
+	_btrfs_kill_stress_balance_pid $balance_pid
+	kill $replace_pid
+	wait $replace_pid
+	# wait for the replace operation to finish
  	while ps aux | grep "replace start" | grep -qv grep; do
  		sleep 1
  	done
tests/btrfs/255 +2 -6
index 7e70944a..aa250467 100755
@@ -41,12 +41,8 @@ for ((i = 0; i < 20; i++)); do
  	$BTRFS_UTIL_PROG quota enable $SCRATCH_MNT
  	$BTRFS_UTIL_PROG quota disable $SCRATCH_MNT
  done
-kill $balance_pid &> /dev/null
-wait
-# wait for the balance operation to finish
-while ps aux | grep "balance start" | grep -qv grep; do
-	sleep 1
-done
+
+_btrfs_kill_stress_balance_pid $balance_pid
 
  echo "Silence is golden"
  status=0
#9 lore raw

Re: [PATCH 04/10] btrfs: add helper to kill background process running _btrfs_stress_scrub

In reply to [email protected]
Quoted 36 lines · On 3/28/24 01:11, [email protected] wrote:

From: Filipe Manana <[email protected]>

Killing a background process running _btrfs_stress_scrub() is not as simple as sending a signal to the process and waiting for it to die. Therefore we have the following logic to terminate such process:

kill $pid
wait $pid
while ps aux | grep "scrub start" | grep -qv grep; do
sleep 1
done

Since this is repeated in several test cases, move this logic to a common helper and use it in all affected test cases. This will help to avoid repeating the same code again several times in upcoming changes.

---
  common/btrfs    | 14 ++++++++++++++
  tests/btrfs/061 |  7 +------
  tests/btrfs/066 |  8 ++------
  tests/btrfs/069 | 11 +++++------
  tests/btrfs/072 | 11 +++++------
  tests/btrfs/073 | 11 +++++------
  6 files changed, 32 insertions(+), 30 deletions(-)
common/btrfs +2 -0
index e95cff7f..d0adeea1 100644
@@ -349,6 +349,20 @@ _btrfs_stress_scrub()
  	done
  }
 
+# Kill a background process running _btrfs_stress_scrub()
+_btrfs_kill_stress_scrub_pid()

common/btrfs _btrfs_stress_scrub() · line 363

Quoted 10 lines
common/btrfs +8 -0
+{
+       local scrub_pid=$1
+
+       # Ignore if process already died.
+       kill $scrub_pid &> /dev/null
+       wait $scrub_pid &> /dev/null
+       # Wait for the scrub operation to finish.
 
 
+       while ps aux | grep "scrub start" | grep -qv grep; do

This can be replaced by pgrep. I'll make the change if there are no objections.

while pgrep -f "btrfs scrub start" > /dev/null; do

Thanks, Anand

Quoted 123 lines
common/btrfs +4 -0
+               sleep 1
+       done
+}
+
  # stress btrfs by defragmenting every file/dir in a loop and compress file
  # contents while defragmenting if second argument is not "nocompress"
  _btrfs_stress_defrag()
tests/btrfs/061 +1 -6
index d0b55e48..b8b2706c 100755
@@ -52,12 +52,7 @@ run_test()
  	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
  	wait $fsstress_pid
  	_btrfs_kill_stress_balance_pid $balance_pid
-	kill $scrub_pid
-	wait $scrub_pid
-	# wait for the crub operation to finish
-	while ps aux | grep "scrub start" | grep -qv grep; do
-		sleep 1
-	done
+	_btrfs_kill_stress_scrub_pid $scrub_pid
 
  	echo "Scrub the filesystem" >>$seqres.full
  	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/066 +2 -6
index a29034bb..29821fdd 100755
@@ -57,12 +57,8 @@ run_test()
  	wait $fsstress_pid
 
  	touch $stop_file
-	kill $scrub_pid
-	wait
-	# wait for the scrub operation to finish
-	while ps aux | grep "scrub start" | grep -qv grep; do
-		sleep 1
-	done
+	wait $subvol_pid
+	_btrfs_kill_stress_scrub_pid $scrub_pid
 
  	echo "Scrub the filesystem" >>$seqres.full
  	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/069 +5 -6
index 139dde48..20f44b39 100755
@@ -59,17 +59,16 @@ run_test()
 
  	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
  	wait $fsstress_pid
-	kill $replace_pid $scrub_pid
-	wait
+	kill $replace_pid
+	wait $replace_pid
 
-	# wait for the scrub and replace operations to finish
-	while ps aux | grep "scrub start" | grep -qv grep; do
-		sleep 1
-	done
+	# wait for the replace operation to finish
  	while ps aux | grep "replace start" | grep -qv grep; do
  		sleep 1
  	done
 
+	_btrfs_kill_stress_scrub_pid $scrub_pid
+
  	echo "Scrub the filesystem" >>$seqres.full
  	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
  	if [ $? -ne 0 ]; then
tests/btrfs/072 +5 -6
index 4b6b6fb5..6c15b51f 100755
@@ -52,16 +52,15 @@ run_test()
 
  	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
  	wait $fsstress_pid
-	kill $scrub_pid $defrag_pid
-	wait
-	# wait for the scrub and defrag operations to finish
-	while ps aux | grep "scrub start" | grep -qv grep; do
-		sleep 1
-	done
+	kill $defrag_pid
+	wait $defrag_pid
+	# wait for the defrag operation to finish
  	while ps aux | grep "btrfs filesystem defrag" | grep -qv grep; do
  		sleep 1
  	done
 
+	_btrfs_kill_stress_scrub_pid $scrub_pid
+
  	echo "Scrub the filesystem" >>$seqres.full
  	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
  	if [ $? -ne 0 ]; then
tests/btrfs/073 +5 -6
index b1604f94..49a4abd1 100755
@@ -51,16 +51,15 @@ run_test()
 
  	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
  	wait $fsstress_pid
-	kill $scrub_pid $remount_pid
-	wait
-	# wait for the scrub and remount operations to finish
-	while ps aux | grep "scrub start" | grep -qv grep; do
-		sleep 1
-	done
+	kill $remount_pid
+	wait $remount_pid
+	# wait for the remount operation to finish
  	while ps aux | grep "mount.*$SCRATCH_MNT" | grep -qv grep; do
  		sleep 1
  	done
 
+	_btrfs_kill_stress_scrub_pid $scrub_pid
+
  	echo "Scrub the filesystem" >>$seqres.full
  	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
  	if [ $? -ne 0 ]; then
#5 lore raw

Re: [PATCH 02/10] btrfs/028: use the helper _btrfs_kill_stress_balance_pid

In reply to [email protected]
Quoted 17 lines · On 3/28/24 01:11, [email protected] wrote:

From: Filipe Manana <[email protected]>

Now that there's a helper to kill a background process that is running _btrfs_stress_balance(), use it in btrfs/028. It's equivalent to the existing code in btrfs/028.

---
  tests/btrfs/028 | 9 +++------
  1 file changed, 3 insertions(+), 6 deletions(-)
tests/btrfs/028 +0 -0
index d860974e..8fbe8887 100755
@@ -44,12 +44,9 @@ balance_pid=$!
 

tests/btrfs/028 balance_pid=$! · line 49

Quoted 10 lines
tests/btrfs/028 +3 -5
  # 30s is enough to trigger bug
  sleep $((30*$TIME_FACTOR))
-kill $fsstress_pid $balance_pid &> /dev/null
-wait
-
-# kill _btrfs_stress_balance can't end balance, so call btrfs balance cancel
-# to cancel running or paused balance. > -$BTRFS_UTIL_PROG balance cancel $SCRATCH_MNT &> /dev/null
+kill $fsstress_pid &> /dev/null
+wait $fsstress_pid &> /dev/null
+_btrfs_kill_stress_balance_pid $balance_pid

I didn't understand the point of replacing 'balance cancel' with 'kill'. The Git change log also doesn't say anything about it. The old code also tested BTRFS_IOC_BALANCE_CTL ioctl.

Thanks, Anand

Quoted 2 lines
tests/btrfs/028 +0 -0
  _run_btrfs_util_prog filesystem sync $SCRATCH_MNT
 
Reviewed-by on v1 5/10
#12 lore raw

Re: [PATCH 05/10] btrfs: add helper to kill background process running _btrfs_stress_defrag

In reply to [email protected]
Quoted 34 lines · On 3/28/24 01:11, [email protected] wrote:

From: Filipe Manana <[email protected]>

Killing a background process running _btrfs_stress_defrag() is not as simple as sending a signal to the process and waiting for it to die. Therefore we have the following logic to terminate such process:

kill $pid
wait $pid
while ps aux | grep "btrfs filesystem defrag" | grep -qv grep; do
sleep 1
done

Since this is repeated in several test cases, move this logic to a common helper and use it in all affected test cases. This will help to avoid repeating the same code again several times in upcoming changes.

---
  common/btrfs    | 14 ++++++++++++++
  tests/btrfs/062 |  7 +------
  tests/btrfs/067 |  8 ++------
  tests/btrfs/070 | 11 +++++------
  tests/btrfs/072 |  7 +------
  tests/btrfs/074 | 11 +++++------
  6 files changed, 28 insertions(+), 30 deletions(-)
common/btrfs +0 -0
index d0adeea1..46056d4a 100644
@@ -383,6 +383,20 @@ _btrfs_stress_defrag()
  	done
  }
 

common/btrfs _btrfs_stress_defrag() · line 395

Quoted 10 lines
common/btrfs +10 -0
+# Kill a background process running _btrfs_stress_defrag()
+_btrfs_kill_stress_defrag_pid()
+{
+       local defrag_pid=$1
+
+       # Ignore if process already died.
+       kill $defrag_pid &> /dev/null
+       wait $defrag_pid &> /dev/null
+       # Wait for the defrag operation to finish.
+       while ps aux | grep "btrfs filesystem defrag" | grep -qv grep; do

The same comments apply here regarding the use of pgrep.

Looks good.

Thanks, Anand

Quoted 116 lines
common/btrfs +4 -0
+               sleep 1
+       done
+}
+
  # stress btrfs by remounting it with different compression algorithms in a loop
  # run this with fsstress running at background could exercise the compression
  # code path and ensure no race when switching compression algorithm with constant
tests/btrfs/062 +1 -6
index a2639d6c..59d581be 100755
@@ -53,12 +53,7 @@ run_test()
  	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
  	wait $fsstress_pid
  	_btrfs_kill_stress_balance_pid $balance_pid
-	kill $defrag_pid
-	wait $defrag_pid
-	# wait for the defrag operation to finish
-	while ps aux | grep "btrfs filesystem defrag" | grep -qv grep; do
-		sleep 1
-	done
+	_btrfs_kill_stress_defrag_pid $defrag_pid
 
  	echo "Scrub the filesystem" >>$seqres.full
  	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/067 +2 -6
index 709db155..2bb00b87 100755
@@ -58,12 +58,8 @@ run_test()
  	wait $fsstress_pid
 
  	touch $stop_file
-	kill $defrag_pid
-	wait
-	# wait for btrfs defrag process to exit, otherwise it will block umount
-	while ps aux | grep "btrfs filesystem defrag" | grep -qv grep; do
-		sleep 1
-	done
+	wait $subvol_pid
+	_btrfs_kill_stress_defrag_pid $defrag_pid
 
  	echo "Scrub the filesystem" >>$seqres.full
  	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/070 +5 -6
index 54aa275c..cefa5723 100755
@@ -60,17 +60,16 @@ run_test()
 
  	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
  	wait $fsstress_pid
-	kill $replace_pid $defrag_pid
-	wait
+	kill $replace_pid
+	wait $replace_pid
 
-	# wait for the defrag and replace operations to finish
-	while ps aux | grep "btrfs filesystem defrag" | grep -qv grep; do
-		sleep 1
-	done
+	# wait for the replace operation to finish
  	while ps aux | grep "replace start" | grep -qv grep; do
  		sleep 1
  	done
 
+	_btrfs_kill_stress_defrag_pid $defrag_pid
+
  	echo "Scrub the filesystem" >>$seqres.full
  	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
  	if [ $? -ne 0 ]; then
tests/btrfs/072 +1 -6
index 6c15b51f..505d0b57 100755
@@ -52,13 +52,8 @@ run_test()
 
  	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
  	wait $fsstress_pid
-	kill $defrag_pid
-	wait $defrag_pid
-	# wait for the defrag operation to finish
-	while ps aux | grep "btrfs filesystem defrag" | grep -qv grep; do
-		sleep 1
-	done
 
+	_btrfs_kill_stress_defrag_pid $defrag_pid
  	_btrfs_kill_stress_scrub_pid $scrub_pid
 
  	echo "Scrub the filesystem" >>$seqres.full
tests/btrfs/074 +5 -6
index 9b22c620..d51922d0 100755
@@ -52,16 +52,15 @@ run_test()
 
  	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
  	wait $fsstress_pid
-	kill $defrag_pid $remount_pid
-	wait
-	# wait for the defrag and remount operations to finish
-	while ps aux | grep "btrfs filesystem defrag" | grep -qv grep; do
-		sleep 1
-	done
+	kill $remount_pid
+	wait $remount_pid
+	# wait for the remount operation to finish
  	while ps aux | grep "mount.*$SCRATCH_MNT" | grep -qv grep; do
  		sleep 1
  	done
 
+	_btrfs_kill_stress_defrag_pid $defrag_pid
+
  	echo "Scrub the filesystem" >>$seqres.full
  	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
  	if [ $? -ne 0 ]; then
#3 lore raw

Re: [PATCH 01/10] btrfs: add helper to kill background process running _btrfs_stress_balance

In reply to Anand Jain
Quoted 45 lines · Anand Jain
Quoted 12 lines · On 3/28/24 01:11, [email protected] wrote:

From: Filipe Manana <[email protected]>

Killing a background process running _btrfs_stress_balance() is not as simple as sending a signal to the process and waiting for it to die. Therefore we have the following logic to terminate such process:

kill $pid
wait $pid
# Wait for the balance operation to finish. while ps aux | grep "balance start" | grep -qv grep; do

Quoted 8 lines

sleep 1
done

Since this is repeated in several test cases, move this logic to a common helper and use it in all affected test cases. This will help to avoid repeating the same code again several times in upcoming changes.

A few minor things below.

Quoted 18 lines
---
  common/btrfs    | 14 ++++++++++++++
  tests/btrfs/060 |  8 ++------
  tests/btrfs/061 | 10 ++++------
  tests/btrfs/062 | 10 ++++------
  tests/btrfs/063 | 10 ++++------
  tests/btrfs/064 | 10 ++++------
  tests/btrfs/255 |  8 ++------
  7 files changed, 34 insertions(+), 36 deletions(-)
common/btrfs +0 -0
index aa344706..e95cff7f 100644
@@ -308,6 +308,20 @@ _btrfs_stress_balance()
      done
  }
 
Quoted 14 lines

common/btrfs _btrfs_stress_balance() · line 320

Quoted 10 lines
common/btrfs +10 -0
+# Kill a background process running _btrfs_stress_balance()
+_btrfs_kill_stress_balance_pid()
+{
+     local balance_pid=$1
+
+     # Ignore if process already died.
+     kill $balance_pid &> /dev/null
+     wait $balance_pid &> /dev/null
+     # Wait for the balance operation to finish.
+     while ps aux | grep "balance start" | grep -qv grep; do

We can use pgrep instead. I will make the following changes before merging if you are okay with it.

Not doing such a change was intentional, as the goal is just to move repeated code into a helper.
I would prefer for such change to be done separately in its own patch.

Quoted 38 lines
(quoted diff) +1 -1
-       while ps aux | grep "balance start" | grep -qv grep; do
+       while pgrep -f "btrfs balance start" > /dev/null; do
Quoted 35 lines
common/btrfs +4 -0
+             sleep 1
+     done
+}
+
  # stress btrfs by creating/mounting/umounting/deleting subvolume in a loop
  _btrfs_stress_subvolume()
  {
tests/btrfs/060 +2 -6
index a0184891..58167cc6 100755
@@ -57,12 +57,8 @@ run_test()
      wait $fsstress_pid
 
      touch $stop_file
-     kill $balance_pid
-     wait
-     # wait for the balance operation to finish
-     while ps aux | grep "balance start" | grep -qv grep; do
-             sleep 1
-     done
+     wait $subvol_pid
+     _btrfs_kill_stress_balance_pid $balance_pid
 
      echo "Scrub the filesystem" >>$seqres.full
      $BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/061 +0 -0
index c1010413..d0b55e48 100755
@@ -51,12 +51,10 @@ run_test()
 
Quoted 14 lines

tests/btrfs/061 run_test() · line 57

Quoted 12 lines
tests/btrfs/061 +4 -6
      echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
      wait $fsstress_pid
-     kill $balance_pid $scrub_pid
-     wait
-     # wait for the balance and scrub operations to finish
-     while ps aux | grep "balance start" | grep -qv grep; do
-             sleep 1
-     done
+     _btrfs_kill_stress_balance_pid $balance_pid
+     kill $scrub_pid
+     wait $scrub_pid
+     # wait for the crub operation to finish

s/crub/scrub/

Yeah, but the comment is going away in the patch that adds the helper to kill scrub.

Thanks.

Quoted 89 lines

Thanks, Anand

Quoted 85 lines
tests/btrfs/061 +0 -0
      while ps aux | grep "scrub start" | grep -qv grep; do
              sleep 1
      done
tests/btrfs/062 +4 -6
index 818a0156..a2639d6c 100755
@@ -52,12 +52,10 @@ run_test()
 
      echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
      wait $fsstress_pid
-     kill $balance_pid $defrag_pid
-     wait
-     # wait for the balance and defrag operations to finish
-     while ps aux | grep "balance start" | grep -qv grep; do
-             sleep 1
-     done
+     _btrfs_kill_stress_balance_pid $balance_pid
+     kill $defrag_pid
+     wait $defrag_pid
+     # wait for the defrag operation to finish
      while ps aux | grep "btrfs filesystem defrag" | grep -qv grep; do
              sleep 1
      done
tests/btrfs/063 +4 -6
index 2f771baf..baf0c356 100755
@@ -51,12 +51,10 @@ run_test()
 
      echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
      wait $fsstress_pid
-     kill $balance_pid $remount_pid
-     wait
-     # wait for the balance and remount loop to finish
-     while ps aux | grep "balance start" | grep -qv grep; do
-             sleep 1
-     done
+     _btrfs_kill_stress_balance_pid $balance_pid
+     kill $remount_pid
+     wait $remount_pid
+     # wait for the remount loop to finish
      while ps aux | grep "mount.*$SCRATCH_MNT" | grep -qv grep; do
              sleep 1
      done
tests/btrfs/064 +4 -6
index e9b46ce6..58b53afe 100755
@@ -63,12 +63,10 @@ run_test()
 
      echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
      wait $fsstress_pid
-     kill $balance_pid $replace_pid
-     wait
-     # wait for the balance and replace operations to finish
-     while ps aux | grep "balance start" | grep -qv grep; do
-             sleep 1
-     done
+     _btrfs_kill_stress_balance_pid $balance_pid
+     kill $replace_pid
+     wait $replace_pid
+     # wait for the replace operation to finish
      while ps aux | grep "replace start" | grep -qv grep; do
              sleep 1
      done
tests/btrfs/255 +2 -6
index 7e70944a..aa250467 100755
@@ -41,12 +41,8 @@ for ((i = 0; i < 20; i++)); do
      $BTRFS_UTIL_PROG quota enable $SCRATCH_MNT
      $BTRFS_UTIL_PROG quota disable $SCRATCH_MNT
  done
-kill $balance_pid &> /dev/null
-wait
-# wait for the balance operation to finish
-while ps aux | grep "balance start" | grep -qv grep; do
-     sleep 1
-done
+
+_btrfs_kill_stress_balance_pid $balance_pid
 
  echo "Silence is golden"
  status=0
Reviewed-by on v1 6/10
#15 lore raw

Re: [PATCH 06/10] btrfs: add helper to kill background process running _btrfs_stress_remount_compress

In reply to [email protected]
Quoted 12 lines · On 3/28/24 01:11, [email protected] wrote:

From: Filipe Manana <[email protected]>

Killing a background process running _btrfs_stress_remount_compress() is not as simple as sending a signal to the process and waiting for it to die. Therefore we have the following logic to terminate such process:

kill $pid
wait $pid
while ps aux | grep "mount.*$SCRATCH_MNT" | grep -qv grep; do
sleep 1
done

Quoted 5 lines

Since this is repeated in several test cases, move this logic to a common helper and use it in all affected test cases. This will help to avoid repeating the same code again several times in upcoming changes.

Thanks, Anand

Quoted 137 lines
---
  common/btrfs    | 15 +++++++++++++++
  tests/btrfs/063 |  7 +------
  tests/btrfs/068 |  8 ++------
  tests/btrfs/071 | 12 +++++-------
  tests/btrfs/073 |  8 +-------
  tests/btrfs/074 |  8 +-------
  6 files changed, 25 insertions(+), 33 deletions(-)
common/btrfs +15 -0
index 46056d4a..66a3a347 100644
@@ -411,6 +411,21 @@ _btrfs_stress_remount_compress()
  	done
  }
 
+# Kill a background process running _btrfs_stress_remount_compress()
+_btrfs_kill_stress_remount_compress_pid()
+{
+	local remount_pid=$1
+	local btrfs_mnt=$2
+
+	# Ignore if process already died.
+	kill $remount_pid &> /dev/null
+	wait $remount_pid &> /dev/null
+	# Wait for the remount loop to finish.
+	while ps aux | grep "mount.*${btrfs_mnt}" | grep -qv grep; do
+		sleep 1
+	done
+}
+
  # stress btrfs by replacing devices in a loop
  # Note that at least 3 devices are needed in SCRATCH_DEV_POOL and the last
  # device should be free(not used by btrfs)
tests/btrfs/063 +1 -6
index baf0c356..5ee2837f 100755
@@ -52,12 +52,7 @@ run_test()
  	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
  	wait $fsstress_pid
  	_btrfs_kill_stress_balance_pid $balance_pid
-	kill $remount_pid
-	wait $remount_pid
-	# wait for the remount loop to finish
-	while ps aux | grep "mount.*$SCRATCH_MNT" | grep -qv grep; do
-		sleep 1
-	done
+	_btrfs_kill_stress_remount_compress_pid $remount_pid $SCRATCH_MNT
 
  	echo "Scrub the filesystem" >>$seqres.full
  	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/068 +2 -6
index 15fd41db..db53254a 100755
@@ -58,12 +58,8 @@ run_test()
  	wait $fsstress_pid
 
  	touch $stop_file
-	kill $remount_pid
-	wait
-	# wait for the remount loop process to finish
-	while ps aux | grep "mount.*$SCRATCH_MNT" | grep -qv grep; do
-		sleep 1
-	done
+	wait $subvol_pid
+	_btrfs_kill_stress_remount_compress_pid $remount_pid $SCRATCH_MNT
 
  	echo "Scrub the filesystem" >>$seqres.full
  	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/071 +5 -7
index 6ebbd8cc..7ba15390 100755
@@ -58,17 +58,15 @@ run_test()
  	echo "$remount_pid" >>$seqres.full
 
  	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
-	wait $fsstress_pid
-	kill $replace_pid $remount_pid
-	wait
+	kill $replace_pid
+	wait $fsstress_pid $replace_pid
 
-	# wait for the remount and replace operations to finish
+	# wait for the replace operationss to finish
  	while ps aux | grep "replace start" | grep -qv grep; do
  		sleep 1
  	done
-	while ps aux | grep "mount.*$SCRATCH_MNT" | grep -qv grep; do
-		sleep 1
-	done
+
+	_btrfs_kill_stress_remount_compress_pid $remount_pid $SCRATCH_MNT
 
  	echo "Scrub the filesystem" >>$seqres.full
  	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/073 +1 -7
index 49a4abd1..50358286 100755
@@ -51,13 +51,7 @@ run_test()
 
  	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
  	wait $fsstress_pid
-	kill $remount_pid
-	wait $remount_pid
-	# wait for the remount operation to finish
-	while ps aux | grep "mount.*$SCRATCH_MNT" | grep -qv grep; do
-		sleep 1
-	done
-
+	_btrfs_kill_stress_remount_compress_pid $remount_pid $SCRATCH_MNT
  	_btrfs_kill_stress_scrub_pid $scrub_pid
 
  	echo "Scrub the filesystem" >>$seqres.full
tests/btrfs/074 +1 -7
index d51922d0..6e93b36a 100755
@@ -52,13 +52,7 @@ run_test()
 
  	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
  	wait $fsstress_pid
-	kill $remount_pid
-	wait $remount_pid
-	# wait for the remount operation to finish
-	while ps aux | grep "mount.*$SCRATCH_MNT" | grep -qv grep; do
-		sleep 1
-	done
-
+	_btrfs_kill_stress_remount_compress_pid $remount_pid $SCRATCH_MNT
  	_btrfs_kill_stress_defrag_pid $defrag_pid
 
  	echo "Scrub the filesystem" >>$seqres.full
#6 lore raw

Re: [PATCH 02/10] btrfs/028: use the helper _btrfs_kill_stress_balance_pid

In reply to Anand Jain
Quoted 19 lines · Anand Jain
Quoted 17 lines · On 3/28/24 01:11, [email protected] wrote:

From: Filipe Manana <[email protected]>

Now that there's a helper to kill a background process that is running _btrfs_stress_balance(), use it in btrfs/028. It's equivalent to the existing code in btrfs/028.

---
  tests/btrfs/028 | 9 +++------
  1 file changed, 3 insertions(+), 6 deletions(-)
tests/btrfs/028 +0 -0
index d860974e..8fbe8887 100755
@@ -44,12 +44,9 @@ balance_pid=$!
 
Quoted 14 lines

tests/btrfs/028 balance_pid=$! · line 49

Quoted 10 lines
tests/btrfs/028 +3 -5
  # 30s is enough to trigger bug
  sleep $((30*$TIME_FACTOR))
-kill $fsstress_pid $balance_pid &> /dev/null
-wait
-
-# kill _btrfs_stress_balance can't end balance, so call btrfs balance cancel
-# to cancel running or paused balance. > -$BTRFS_UTIL_PROG balance cancel $SCRATCH_MNT &> /dev/null
+kill $fsstress_pid &> /dev/null
+wait $fsstress_pid &> /dev/null
+_btrfs_kill_stress_balance_pid $balance_pid

I didn't understand the point of replacing 'balance cancel' with 'kill'. The Git change log also doesn't say anything about it. The old code also tested BTRFS_IOC_BALANCE_CTL ioctl.

The point is to use the helper to kill the background task running balance in a loop, so for every _btrfs_stress_balance() call we have a matching _btrfs_kill_stress_balance_pid().

Doing the kill + cancel is equivalent to what the helper does, and the goal of the test is not to exercise the balance cancel.

Thanks.

Quoted 7 lines

Thanks, Anand

Quoted 2 lines
tests/btrfs/028 +0 -0
  _run_btrfs_util_prog filesystem sync $SCRATCH_MNT
 
#10 lore raw

Re: [PATCH 04/10] btrfs: add helper to kill background process running _btrfs_stress_scrub

In reply to Anand Jain
Quoted 47 lines · Anand Jain
Quoted 43 lines · On 3/28/24 01:11, [email protected] wrote:

From: Filipe Manana <[email protected]>

Killing a background process running _btrfs_stress_scrub() is not as simple as sending a signal to the process and waiting for it to die. Therefore we have the following logic to terminate such process:

kill $pid
wait $pid
while ps aux | grep "scrub start" | grep -qv grep; do
sleep 1
done

Since this is repeated in several test cases, move this logic to a common helper and use it in all affected test cases. This will help to avoid repeating the same code again several times in upcoming changes.

---
  common/btrfs    | 14 ++++++++++++++
  tests/btrfs/061 |  7 +------
  tests/btrfs/066 |  8 ++------
  tests/btrfs/069 | 11 +++++------
  tests/btrfs/072 | 11 +++++------
  tests/btrfs/073 | 11 +++++------
  6 files changed, 32 insertions(+), 30 deletions(-)
common/btrfs +9 -0
index e95cff7f..d0adeea1 100644
@@ -349,6 +349,20 @@ _btrfs_stress_scrub()
      done
  }
 
+# Kill a background process running _btrfs_stress_scrub()
+_btrfs_kill_stress_scrub_pid()
+{
+       local scrub_pid=$1
+
+       # Ignore if process already died.
+       kill $scrub_pid &> /dev/null
+       wait $scrub_pid &> /dev/null
+       # Wait for the scrub operation to finish.
Quoted 4 lines

common/btrfs _btrfs_stress_scrub() · line 361

Quoted 1 line
common/btrfs +1 -0
+       while ps aux | grep "scrub start" | grep -qv grep; do

This can be replaced by pgrep. I'll make the change if there are no objections.

Yes, but as previously pointed out, the goal of the patch is just to move repeated code into a helper function.
I would prefer such a change to be done separately.

Thanks.

Quoted 129 lines

while pgrep -f "btrfs scrub start" > /dev/null; do

Thanks, Anand

Quoted 123 lines
common/btrfs +4 -0
+               sleep 1
+       done
+}
+
  # stress btrfs by defragmenting every file/dir in a loop and compress file
  # contents while defragmenting if second argument is not "nocompress"
  _btrfs_stress_defrag()
tests/btrfs/061 +1 -6
index d0b55e48..b8b2706c 100755
@@ -52,12 +52,7 @@ run_test()
      echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
      wait $fsstress_pid
      _btrfs_kill_stress_balance_pid $balance_pid
-     kill $scrub_pid
-     wait $scrub_pid
-     # wait for the crub operation to finish
-     while ps aux | grep "scrub start" | grep -qv grep; do
-             sleep 1
-     done
+     _btrfs_kill_stress_scrub_pid $scrub_pid
 
      echo "Scrub the filesystem" >>$seqres.full
      $BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/066 +2 -6
index a29034bb..29821fdd 100755
@@ -57,12 +57,8 @@ run_test()
      wait $fsstress_pid
 
      touch $stop_file
-     kill $scrub_pid
-     wait
-     # wait for the scrub operation to finish
-     while ps aux | grep "scrub start" | grep -qv grep; do
-             sleep 1
-     done
+     wait $subvol_pid
+     _btrfs_kill_stress_scrub_pid $scrub_pid
 
      echo "Scrub the filesystem" >>$seqres.full
      $BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/069 +5 -6
index 139dde48..20f44b39 100755
@@ -59,17 +59,16 @@ run_test()
 
      echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
      wait $fsstress_pid
-     kill $replace_pid $scrub_pid
-     wait
+     kill $replace_pid
+     wait $replace_pid
 
-     # wait for the scrub and replace operations to finish
-     while ps aux | grep "scrub start" | grep -qv grep; do
-             sleep 1
-     done
+     # wait for the replace operation to finish
      while ps aux | grep "replace start" | grep -qv grep; do
              sleep 1
      done
 
+     _btrfs_kill_stress_scrub_pid $scrub_pid
+
      echo "Scrub the filesystem" >>$seqres.full
      $BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
      if [ $? -ne 0 ]; then
tests/btrfs/072 +5 -6
index 4b6b6fb5..6c15b51f 100755
@@ -52,16 +52,15 @@ run_test()
 
      echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
      wait $fsstress_pid
-     kill $scrub_pid $defrag_pid
-     wait
-     # wait for the scrub and defrag operations to finish
-     while ps aux | grep "scrub start" | grep -qv grep; do
-             sleep 1
-     done
+     kill $defrag_pid
+     wait $defrag_pid
+     # wait for the defrag operation to finish
      while ps aux | grep "btrfs filesystem defrag" | grep -qv grep; do
              sleep 1
      done
 
+     _btrfs_kill_stress_scrub_pid $scrub_pid
+
      echo "Scrub the filesystem" >>$seqres.full
      $BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
      if [ $? -ne 0 ]; then
tests/btrfs/073 +5 -6
index b1604f94..49a4abd1 100755
@@ -51,16 +51,15 @@ run_test()
 
      echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
      wait $fsstress_pid
-     kill $scrub_pid $remount_pid
-     wait
-     # wait for the scrub and remount operations to finish
-     while ps aux | grep "scrub start" | grep -qv grep; do
-             sleep 1
-     done
+     kill $remount_pid
+     wait $remount_pid
+     # wait for the remount operation to finish
      while ps aux | grep "mount.*$SCRATCH_MNT" | grep -qv grep; do
              sleep 1
      done
 
+     _btrfs_kill_stress_scrub_pid $scrub_pid
+
      echo "Scrub the filesystem" >>$seqres.full
      $BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
      if [ $? -ne 0 ]; then
#13 lore raw

Re: [PATCH 05/10] btrfs: add helper to kill background process running _btrfs_stress_defrag

In reply to Anand Jain
Quoted 36 lines · Anand Jain
Quoted 34 lines · On 3/28/24 01:11, [email protected] wrote:

From: Filipe Manana <[email protected]>

Killing a background process running _btrfs_stress_defrag() is not as simple as sending a signal to the process and waiting for it to die. Therefore we have the following logic to terminate such process:

kill $pid
wait $pid
while ps aux | grep "btrfs filesystem defrag" | grep -qv grep; do
sleep 1
done

Since this is repeated in several test cases, move this logic to a common helper and use it in all affected test cases. This will help to avoid repeating the same code again several times in upcoming changes.

---
  common/btrfs    | 14 ++++++++++++++
  tests/btrfs/062 |  7 +------
  tests/btrfs/067 |  8 ++------
  tests/btrfs/070 | 11 +++++------
  tests/btrfs/072 |  7 +------
  tests/btrfs/074 | 11 +++++------
  6 files changed, 28 insertions(+), 30 deletions(-)
common/btrfs +0 -0
index d0adeea1..46056d4a 100644
@@ -383,6 +383,20 @@ _btrfs_stress_defrag()
      done
  }
 
Quoted 12 lines

common/btrfs _btrfs_stress_defrag() · line 395

Quoted 10 lines
common/btrfs +10 -0
+# Kill a background process running _btrfs_stress_defrag()
+_btrfs_kill_stress_defrag_pid()
+{
+       local defrag_pid=$1
+
+       # Ignore if process already died.
+       kill $defrag_pid &> /dev/null
+       wait $defrag_pid &> /dev/null
+       # Wait for the defrag operation to finish.
+       while ps aux | grep "btrfs filesystem defrag" | grep -qv grep; do

The same comments apply here regarding the use of pgrep.

Yes, but as previously pointed out, the goal of the patch is just to move repeated code into a helper function.
I would prefer such a change to be done separately.

Thanks.

Quoted 123 lines

Looks good.

Thanks, Anand

Quoted 116 lines
common/btrfs +4 -0
+               sleep 1
+       done
+}
+
  # stress btrfs by remounting it with different compression algorithms in a loop
  # run this with fsstress running at background could exercise the compression
  # code path and ensure no race when switching compression algorithm with constant
tests/btrfs/062 +1 -6
index a2639d6c..59d581be 100755
@@ -53,12 +53,7 @@ run_test()
      echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
      wait $fsstress_pid
      _btrfs_kill_stress_balance_pid $balance_pid
-     kill $defrag_pid
-     wait $defrag_pid
-     # wait for the defrag operation to finish
-     while ps aux | grep "btrfs filesystem defrag" | grep -qv grep; do
-             sleep 1
-     done
+     _btrfs_kill_stress_defrag_pid $defrag_pid
 
      echo "Scrub the filesystem" >>$seqres.full
      $BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/067 +2 -6
index 709db155..2bb00b87 100755
@@ -58,12 +58,8 @@ run_test()
      wait $fsstress_pid
 
      touch $stop_file
-     kill $defrag_pid
-     wait
-     # wait for btrfs defrag process to exit, otherwise it will block umount
-     while ps aux | grep "btrfs filesystem defrag" | grep -qv grep; do
-             sleep 1
-     done
+     wait $subvol_pid
+     _btrfs_kill_stress_defrag_pid $defrag_pid
 
      echo "Scrub the filesystem" >>$seqres.full
      $BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/070 +5 -6
index 54aa275c..cefa5723 100755
@@ -60,17 +60,16 @@ run_test()
 
      echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
      wait $fsstress_pid
-     kill $replace_pid $defrag_pid
-     wait
+     kill $replace_pid
+     wait $replace_pid
 
-     # wait for the defrag and replace operations to finish
-     while ps aux | grep "btrfs filesystem defrag" | grep -qv grep; do
-             sleep 1
-     done
+     # wait for the replace operation to finish
      while ps aux | grep "replace start" | grep -qv grep; do
              sleep 1
      done
 
+     _btrfs_kill_stress_defrag_pid $defrag_pid
+
      echo "Scrub the filesystem" >>$seqres.full
      $BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
      if [ $? -ne 0 ]; then
tests/btrfs/072 +1 -6
index 6c15b51f..505d0b57 100755
@@ -52,13 +52,8 @@ run_test()
 
      echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
      wait $fsstress_pid
-     kill $defrag_pid
-     wait $defrag_pid
-     # wait for the defrag operation to finish
-     while ps aux | grep "btrfs filesystem defrag" | grep -qv grep; do
-             sleep 1
-     done
 
+     _btrfs_kill_stress_defrag_pid $defrag_pid
      _btrfs_kill_stress_scrub_pid $scrub_pid
 
      echo "Scrub the filesystem" >>$seqres.full
tests/btrfs/074 +5 -6
index 9b22c620..d51922d0 100755
@@ -52,16 +52,15 @@ run_test()
 
      echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
      wait $fsstress_pid
-     kill $defrag_pid $remount_pid
-     wait
-     # wait for the defrag and remount operations to finish
-     while ps aux | grep "btrfs filesystem defrag" | grep -qv grep; do
-             sleep 1
-     done
+     kill $remount_pid
+     wait $remount_pid
+     # wait for the remount operation to finish
      while ps aux | grep "mount.*$SCRATCH_MNT" | grep -qv grep; do
              sleep 1
      done
 
+     _btrfs_kill_stress_defrag_pid $defrag_pid
+
      echo "Scrub the filesystem" >>$seqres.full
      $BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
      if [ $? -ne 0 ]; then
Reviewed-by on v1 7/10
#20 lore raw

Re: [PATCH 07/10] btrfs: add helper to kill background process running _btrfs_stress_replace

In reply to [email protected]
Quoted 12 lines · On 3/28/24 01:11, [email protected] wrote:

From: Filipe Manana <[email protected]>

Killing a background process running _btrfs_stress_replace() is not as simple as sending a signal to the process and waiting for it to die. Therefore we have the following logic to terminate such process:

kill $pid
wait $pid
while ps aux | grep "replace start" | grep -qv grep; do
sleep 1
done

Quoted 5 lines

Since this is repeated in several test cases, move this logic to a common helper and use it in all affected test cases. This will help to avoid repeating the same code again several times in upcoming changes.

Thanks, Anand

Quoted 133 lines
---
  common/btrfs    | 14 ++++++++++++++
  tests/btrfs/064 |  7 +------
  tests/btrfs/065 |  8 ++------
  tests/btrfs/069 |  9 +--------
  tests/btrfs/070 |  9 +--------
  tests/btrfs/071 | 10 ++--------
  6 files changed, 21 insertions(+), 36 deletions(-)
common/btrfs +14 -0
index 66a3a347..6d7e7a68 100644
@@ -475,6 +475,20 @@ _btrfs_stress_replace()
  	done
  }
 
+# Kill a background process running _btrfs_stress_replace()
+_btrfs_kill_stress_replace_pid()
+{
+       local replace_pid=$1
+
+       # Ignore if process already died.
+       kill $replace_pid &> /dev/null
+       wait $replace_pid &> /dev/null
+       # Wait for the replace operation to finish.
+       while ps aux | grep "replace start" | grep -qv grep; do
+               sleep 1
+       done
+}
+
  # find the right option to force output in bytes, older versions of btrfs-progs
  # print that by default, newer print human readable numbers with unit suffix
  _btrfs_qgroup_units()
tests/btrfs/064 +1 -6
index 58b53afe..9e0b3b30 100755
@@ -64,12 +64,7 @@ run_test()
  	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
  	wait $fsstress_pid
  	_btrfs_kill_stress_balance_pid $balance_pid
-	kill $replace_pid
-	wait $replace_pid
-	# wait for the replace operation to finish
-	while ps aux | grep "replace start" | grep -qv grep; do
-		sleep 1
-	done
+	_btrfs_kill_stress_replace_pid $replace_pid
 
  	echo "Scrub the filesystem" >>$seqres.full
  	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/065 +2 -6
index c4b6aafe..d2b04178 100755
@@ -65,12 +65,8 @@ run_test()
  	wait $fsstress_pid
 
  	touch $stop_file
-	kill $replace_pid
-	wait
-	# wait for the replace operation to finish
-	while ps aux | grep "replace start" | grep -qv grep; do
-		sleep 1
-	done
+	wait $subvol_pid
+	_btrfs_kill_stress_replace_pid $replace_pid
 
  	echo "Scrub the filesystem" >>$seqres.full
  	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/069 +1 -8
index 20f44b39..ad1609d4 100755
@@ -59,15 +59,8 @@ run_test()
 
  	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
  	wait $fsstress_pid
-	kill $replace_pid
-	wait $replace_pid
-
-	# wait for the replace operation to finish
-	while ps aux | grep "replace start" | grep -qv grep; do
-		sleep 1
-	done
-
  	_btrfs_kill_stress_scrub_pid $scrub_pid
+	_btrfs_kill_stress_replace_pid $replace_pid
 
  	echo "Scrub the filesystem" >>$seqres.full
  	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/070 +1 -8
index cefa5723..3054c270 100755
@@ -60,14 +60,7 @@ run_test()
 
  	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
  	wait $fsstress_pid
-	kill $replace_pid
-	wait $replace_pid
-
-	# wait for the replace operation to finish
-	while ps aux | grep "replace start" | grep -qv grep; do
-		sleep 1
-	done
-
+	_btrfs_kill_stress_replace_pid $replace_pid
  	_btrfs_kill_stress_defrag_pid $defrag_pid
 
  	echo "Scrub the filesystem" >>$seqres.full
tests/btrfs/071 +2 -8
index 7ba15390..36b39341 100755
@@ -58,14 +58,8 @@ run_test()
  	echo "$remount_pid" >>$seqres.full
 
  	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
-	kill $replace_pid
-	wait $fsstress_pid $replace_pid
-
-	# wait for the replace operationss to finish
-	while ps aux | grep "replace start" | grep -qv grep; do
-		sleep 1
-	done
-
+	wait $fsstress_pid
+	_btrfs_kill_stress_replace_pid $replace_pid
  	_btrfs_kill_stress_remount_compress_pid $remount_pid $SCRATCH_MNT
 
  	echo "Scrub the filesystem" >>$seqres.full
Reviewed-by on v1 8/10
#22 lore raw

Re: [PATCH 08/10] btrfs: add helper to stop background process running _btrfs_stress_subvolume

In reply to [email protected]
Quoted 8 lines · On 3/28/24 01:11, [email protected] wrote:

From: Filipe Manana <[email protected]>

We have this logic to stop a process running _btrfs_stress_subvolume() spread in several test cases:

touch $stop_file
wait $subvol_pid

Quoted 7 lines

Add a helper to encapsulate that logic and also remove the stop file after the process terminated as there's no point having it around anymore.

This will help to avoid repeating the same code again several times in upcoming changes.

Thanks, Anand

Quoted 102 lines
---
  common/btrfs    | 12 ++++++++++++
  tests/btrfs/060 |  3 +--
  tests/btrfs/065 |  3 +--
  tests/btrfs/066 |  3 +--
  tests/btrfs/067 |  3 +--
  tests/btrfs/068 |  3 +--
  6 files changed, 17 insertions(+), 10 deletions(-)
common/btrfs +12 -0
index 6d7e7a68..e19a6ad1 100644
@@ -340,6 +340,18 @@ _btrfs_stress_subvolume()
  	done
  }
 
+# Kill a background process running _btrfs_stress_subvolume()
+_btrfs_kill_stress_subvolume_pid()
+{
+	local subvol_pid=$1
+	local stop_file=$2
+
+	touch $stop_file
+	# Ignore if process already died.
+	wait $subvol_pid &> /dev/null
+	rm -f $stop_file
+}
+
  # stress btrfs by running scrub in a loop
  _btrfs_stress_scrub()
  {
tests/btrfs/060 +1 -2
index 58167cc6..87823aba 100755
@@ -56,8 +56,7 @@ run_test()
  	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
  	wait $fsstress_pid
 
-	touch $stop_file
-	wait $subvol_pid
+	_btrfs_kill_stress_subvolume_pid $subvol_pid $stop_file
  	_btrfs_kill_stress_balance_pid $balance_pid
 
  	echo "Scrub the filesystem" >>$seqres.full
tests/btrfs/065 +1 -2
index d2b04178..ddc28616 100755
@@ -64,8 +64,7 @@ run_test()
  	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
  	wait $fsstress_pid
 
-	touch $stop_file
-	wait $subvol_pid
+	_btrfs_kill_stress_subvolume_pid $subvol_pid $stop_file
  	_btrfs_kill_stress_replace_pid $replace_pid
 
  	echo "Scrub the filesystem" >>$seqres.full
tests/btrfs/066 +1 -2
index 29821fdd..c7488602 100755
@@ -56,8 +56,7 @@ run_test()
  	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
  	wait $fsstress_pid
 
-	touch $stop_file
-	wait $subvol_pid
+	_btrfs_kill_stress_subvolume_pid $subvol_pid $stop_file
  	_btrfs_kill_stress_scrub_pid $scrub_pid
 
  	echo "Scrub the filesystem" >>$seqres.full
tests/btrfs/067 +1 -2
index 2bb00b87..ebbec1be 100755
@@ -57,8 +57,7 @@ run_test()
  	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
  	wait $fsstress_pid
 
-	touch $stop_file
-	wait $subvol_pid
+	_btrfs_kill_stress_subvolume_pid $subvol_pid $stop_file
  	_btrfs_kill_stress_defrag_pid $defrag_pid
 
  	echo "Scrub the filesystem" >>$seqres.full
tests/btrfs/068 +1 -2
index db53254a..5f41fb74 100755
@@ -57,8 +57,7 @@ run_test()
  	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
  	wait $fsstress_pid
 
-	touch $stop_file
-	wait $subvol_pid
+	_btrfs_kill_stress_subvolume_pid $subvol_pid $stop_file
  	_btrfs_kill_stress_remount_compress_pid $remount_pid $SCRATCH_MNT
 
  	echo "Scrub the filesystem" >>$seqres.full
Reviewed-by on v1 9/10
#24 lore raw

Re: [PATCH 09/10] btrfs: remove stop file early at _btrfs_stress_subvolume

In reply to [email protected]
Quoted 8 lines · On 3/28/24 01:11, [email protected] wrote:

From: Filipe Manana <[email protected]>

Instead of having every test case that uses _btrfs_stress_subvolume() removing the stop file before calling that function, do the file remove at _btrfs_stress_subvolume(). There's no point in doing it in every single test case.

Thanks Anand

Quoted 86 lines
---
  common/btrfs    | 1 +
  tests/btrfs/060 | 2 --
  tests/btrfs/065 | 2 --
  tests/btrfs/066 | 2 --
  tests/btrfs/067 | 2 --
  tests/btrfs/068 | 2 --
  6 files changed, 1 insertion(+), 10 deletions(-)
common/btrfs +1 -0
index e19a6ad1..29061c23 100644
@@ -331,6 +331,7 @@ _btrfs_stress_subvolume()
  	local subvol_mnt=$4
  	local stop_file=$5
 
+	rm -f $stop_file
  	mkdir -p $subvol_mnt
  	while [ ! -e $stop_file ]; do
  		$BTRFS_UTIL_PROG subvolume create $btrfs_mnt/$subvol_name
tests/btrfs/060 +0 -2
index 87823aba..53cbd3a0 100755
@@ -46,8 +46,6 @@ run_test()
  	balance_pid=$!
  	echo "$balance_pid" >>$seqres.full
 
-	# make sure the stop sign is not there
-	rm -f $stop_file
  	echo -n "Start subvolume worker: " >>$seqres.full
  	_btrfs_stress_subvolume $SCRATCH_DEV $SCRATCH_MNT subvol_$$ $subvol_mnt $stop_file >/dev/null 2>&1 &
  	subvol_pid=$!
tests/btrfs/065 +0 -2
index ddc28616..f9e43cdc 100755
@@ -49,8 +49,6 @@ run_test()
  	$FSSTRESS_PROG $args >>$seqres.full &
  	fsstress_pid=$!
 
-	# make sure the stop sign is not there
-	rm -f $stop_file
  	echo -n "Start subvolume worker: " >>$seqres.full
  	_btrfs_stress_subvolume $SCRATCH_DEV $SCRATCH_MNT subvol_$$ $subvol_mnt $stop_file >/dev/null 2>&1 &
  	subvol_pid=$!
tests/btrfs/066 +0 -2
index c7488602..b6f904ac 100755
@@ -41,8 +41,6 @@ run_test()
  	$FSSTRESS_PROG $args >>$seqres.full &
  	fsstress_pid=$!
 
-	# make sure the stop sign is not there
-	rm -f $stop_file
  	echo -n "Start subvolume worker: " >>$seqres.full
  	_btrfs_stress_subvolume $SCRATCH_DEV $SCRATCH_MNT subvol_$$ $subvol_mnt $stop_file >/dev/null 2>&1 &
  	subvol_pid=$!
tests/btrfs/067 +0 -2
index ebbec1be..7be09d52 100755
@@ -42,8 +42,6 @@ run_test()
  	$FSSTRESS_PROG $args >>$seqres.full &
  	fsstress_pid=$!
 
-	# make sure the stop sign is not there
-	rm -f $stop_file
  	echo -n "Start subvolume worker: " >>$seqres.full
  	_btrfs_stress_subvolume $SCRATCH_DEV $SCRATCH_MNT subvol_$$ $subvol_mnt $stop_file >/dev/null 2>&1 &
  	subvol_pid=$!
tests/btrfs/068 +0 -2
index 5f41fb74..19e37010 100755
@@ -42,8 +42,6 @@ run_test()
  	$FSSTRESS_PROG $args >>$seqres.full &
  	fsstress_pid=$!
 
-	# make sure the stop sign is not there
-	rm -f $stop_file
  	echo -n "Start subvolume worker: " >>$seqres.full
  	_btrfs_stress_subvolume $SCRATCH_DEV $SCRATCH_MNT subvol_$$ $subvol_mnt $stop_file >/dev/null 2>&1 &
  	subvol_pid=$!
Reviewed-by on v1 10/10
#26 lore raw

Re: [PATCH 10/10] btrfs/06[0-9]..07[0-4]: kill all background tasks when test is killed/interrupted

In reply to [email protected]
Quoted 44 lines · On 3/28/24 01:11, [email protected] wrote:

From: Filipe Manana <[email protected]>

Test cases btrfs/06[0-9] and btrfs/07[0-4] exercise multiple concurrent operations while fsstress is running in parallel, and all these are left as child processes running in the background, which are correctly stopped if the tests are not interrupted/killed. However if any of these tests is interrupted/killed, it often leaves child processes still running in the background, which prevent further running fstests again. For example:

   $ /check -g auto
   (...)
   btrfs/060 394s ...  264s
   btrfs/061 83s ...  69s
   btrfs/062 109s ...  105s
   btrfs/063 52s ...  67s
   btrfs/064 53s ...  51s
   btrfs/065 88s ...  271s
   btrfs/066 127s ...  241s
   btrfs/067 435s ...  248s
   btrfs/068 161s ... ^C^C
   ^C
   $ ./check btrfs/068
   FSTYP         -- btrfs
   PLATFORM      -- Linux/x86_64 debian0 6.8.0-rc7-btrfs-next-153+ #1 SMP PREEMPT_DYNAMIC Mon Mar  4 17:19:19 WET 2024
   MKFS_OPTIONS  -- /dev/sdb
   MOUNT_OPTIONS -- /dev/sdb /home/fdmanana/btrfs-tests/scratch_1

our local _scratch_mkfs routine ... btrfs-progs v6.6.2
See https://btrfs.readthedocs.io for more information.

ERROR: unable to open /dev/sdb: Device or resource busy
check: failed to mkfs $SCRATCH_DEV using specified options Interrupted!
Passed all 0 tests

In this case there was still a process running _btrfs_stress_subvolume() from common/btrfs.

This is a bit annoying because it requires manually finding out which process is preventing unmounting the scratch device and then properly stop/kill it.

Quoted 8 lines

So fix this by adding a _cleanup() function to all these tests and then making sure it stops all the child processes it spawned and are running in the background.

All these tests have the same structure as they were part of the same patchset and from the same author.

Thanks, Anand

Quoted 681 lines
---
  tests/btrfs/060 | 22 +++++++++++++++++++++-
  tests/btrfs/061 | 19 +++++++++++++++++++
  tests/btrfs/062 | 19 +++++++++++++++++++
  tests/btrfs/063 | 19 +++++++++++++++++++
  tests/btrfs/064 | 19 +++++++++++++++++++
  tests/btrfs/065 | 22 +++++++++++++++++++++-
  tests/btrfs/066 | 22 +++++++++++++++++++++-
  tests/btrfs/067 | 22 +++++++++++++++++++++-
  tests/btrfs/068 | 22 +++++++++++++++++++++-
  tests/btrfs/069 | 19 +++++++++++++++++++
  tests/btrfs/070 | 19 +++++++++++++++++++
  tests/btrfs/071 | 19 +++++++++++++++++++
  tests/btrfs/072 | 19 +++++++++++++++++++
  tests/btrfs/073 | 19 +++++++++++++++++++
  tests/btrfs/074 | 19 +++++++++++++++++++
  15 files changed, 295 insertions(+), 5 deletions(-)
tests/btrfs/060 +21 -1
index 53cbd3a0..f74d9593 100755
@@ -10,6 +10,22 @@
  . ./common/preamble
  _begin_fstest auto balance subvol scrub
 
+_cleanup()
+{
+	cd /
+	rm -rf $tmp.*
+	if [ ! -z "$stop_file" ] && [ ! -z "$subvol_pid" ]; then
+		_btrfs_kill_stress_subvolume_pid $subvol_pid $stop_file
+	fi
+	if [ ! -z "$balance_pid" ]; then
+		_btrfs_kill_stress_balance_pid $balance_pid
+	fi
+	if [ ! -z "$fsstress_pid" ]; then
+		kill $fsstress_pid &> /dev/null
+		wait $fsstress_pid &> /dev/null
+	fi
+}
+
  # Import common functions.
  . ./common/filter
 
@@ -20,11 +36,12 @@ _require_scratch_nocheck
  _require_scratch_dev_pool 4
  _btrfs_get_profile_configs
 
+stop_file=$TEST_DIR/$seq.stop.$$
+
  run_test()
  {
  	local mkfs_opts=$1
  	local subvol_mnt=$TEST_DIR/$seq.mnt
-	local stop_file=$TEST_DIR/$seq.stop.$$
 
  	echo "Test $mkfs_opts" >>$seqres.full
 
@@ -53,9 +70,12 @@ run_test()
 
  	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
  	wait $fsstress_pid
+	unset fsstress_pid
 
  	_btrfs_kill_stress_subvolume_pid $subvol_pid $stop_file
+	unset subvol_pid
  	_btrfs_kill_stress_balance_pid $balance_pid
+	unset balance_pid
 
  	echo "Scrub the filesystem" >>$seqres.full
  	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/061 +19 -0
index b8b2706c..fec90882 100755
@@ -10,6 +10,22 @@
  . ./common/preamble
  _begin_fstest auto balance scrub
 
+_cleanup()
+{
+	cd /
+	rm -rf $tmp.*
+	if [ ! -z "$balance_pid" ]; then
+		_btrfs_kill_stress_balance_pid $balance_pid
+	fi
+	if [ ! -z "$scrub_pid" ]; then
+		_btrfs_kill_stress_scrub_pid $scrub_pid
+	fi
+	if [ ! -z "$fsstress_pid" ]; then
+		kill $fsstress_pid &> /dev/null
+		wait $fsstress_pid &> /dev/null
+	fi
+}
+
  # Import common functions.
  . ./common/filter
 
@@ -51,8 +67,11 @@ run_test()
 
  	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
  	wait $fsstress_pid
+	unset fsstress_pid
  	_btrfs_kill_stress_balance_pid $balance_pid
+	unset balance_pid
  	_btrfs_kill_stress_scrub_pid $scrub_pid
+	unset scrub_pid
 
  	echo "Scrub the filesystem" >>$seqres.full
  	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/062 +19 -0
index 59d581be..0b57681f 100755
@@ -10,6 +10,22 @@
  . ./common/preamble
  _begin_fstest auto balance defrag compress scrub
 
+_cleanup()
+{
+	cd /
+	rm -rf $tmp.*
+	if [ ! -z "$balance_pid" ]; then
+		_btrfs_kill_stress_balance_pid $balance_pid
+	fi
+	if [ ! -z "$defrag_pid" ]; then
+		_btrfs_kill_stress_defrag_pid $defrag_pid
+	fi
+	if [ ! -z "$fsstress_pid" ]; then
+		kill $fsstress_pid &> /dev/null
+		wait $fsstress_pid &> /dev/null
+	fi
+}
+
  # Import common functions.
  . ./common/filter
 
@@ -52,8 +68,11 @@ run_test()
 
  	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
  	wait $fsstress_pid
+	unset fsstress_pid
  	_btrfs_kill_stress_balance_pid $balance_pid
+	unset balance_pid
  	_btrfs_kill_stress_defrag_pid $defrag_pid
+	unset defrag_pid
 
  	echo "Scrub the filesystem" >>$seqres.full
  	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/063 +19 -0
index 5ee2837f..99d9d2c1 100755
@@ -10,6 +10,22 @@
  . ./common/preamble
  _begin_fstest auto balance remount compress scrub
 
+_cleanup()
+{
+	cd /
+	rm -rf $tmp.*
+	if [ ! -z "$balance_pid" ]; then
+		_btrfs_kill_stress_balance_pid $balance_pid
+	fi
+	if [ ! -z "$remount_pid" ]; then
+		_btrfs_kill_stress_remount_compress_pid $remount_pid $SCRATCH_MNT
+	fi
+	if [ ! -z "$fsstress_pid" ]; then
+		kill $fsstress_pid &> /dev/null
+		wait $fsstress_pid &> /dev/null
+	fi
+}
+
  # Import common functions.
  . ./common/filter
 
@@ -51,8 +67,11 @@ run_test()
 
  	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
  	wait $fsstress_pid
+	unset fsstress_pid
  	_btrfs_kill_stress_balance_pid $balance_pid
+	unset balance_pid
  	_btrfs_kill_stress_remount_compress_pid $remount_pid $SCRATCH_MNT
+	unset remount_pid
 
  	echo "Scrub the filesystem" >>$seqres.full
  	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/064 +19 -0
index 9e0b3b30..663442c6 100755
@@ -12,6 +12,22 @@
  . ./common/preamble
  _begin_fstest auto balance replace volume scrub
 
+_cleanup()
+{
+	cd /
+	rm -rf $tmp.*
+	if [ ! -z "$balance_pid" ]; then
+		_btrfs_kill_stress_balance_pid $balance_pid
+	fi
+	if [ ! -z "$replace_pid" ]; then
+		_btrfs_kill_stress_replace_pid $replace_pid
+	fi
+	if [ ! -z "$fsstress_pid" ]; then
+		kill $fsstress_pid &> /dev/null
+		wait $fsstress_pid &> /dev/null
+	fi
+}
+
  # Import common functions.
  . ./common/filter
 
@@ -63,8 +79,11 @@ run_test()
 
  	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
  	wait $fsstress_pid
+	unset fsstress_pid
  	_btrfs_kill_stress_balance_pid $balance_pid
+	unset balance_pid
  	_btrfs_kill_stress_replace_pid $replace_pid
+	unset replace_pid
 
  	echo "Scrub the filesystem" >>$seqres.full
  	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/065 +21 -1
index f9e43cdc..b1e54fc8 100755
@@ -10,6 +10,22 @@
  . ./common/preamble
  _begin_fstest auto subvol replace volume scrub
 
+_cleanup()
+{
+	cd /
+	rm -rf $tmp.*
+	if [ ! -z "$stop_file" ] && [ ! -z "$subvol_pid" ]; then
+		_btrfs_kill_stress_subvolume_pid $subvol_pid $stop_file
+	fi
+	if [ ! -z "$replace_pid" ]; then
+		_btrfs_kill_stress_replace_pid $replace_pid
+	fi
+	if [ ! -z "$fsstress_pid" ]; then
+		kill $fsstress_pid &> /dev/null
+		wait $fsstress_pid &> /dev/null
+	fi
+}
+
  # Import common functions.
  . ./common/filter
 
@@ -21,12 +37,13 @@ _require_scratch_dev_pool 5
  _require_scratch_dev_pool_equal_size
  _btrfs_get_profile_configs replace
 
+stop_file=$TEST_DIR/$seq.stop.$$
+
  run_test()
  {
  	local mkfs_opts=$1
  	local saved_scratch_dev_pool=$SCRATCH_DEV_POOL
  	local subvol_mnt=$TEST_DIR/$seq.mnt
-	local stop_file=$TEST_DIR/$seq.stop.$$
 
  	echo "Test $mkfs_opts" >>$seqres.full
 
@@ -61,9 +78,12 @@ run_test()
 
  	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
  	wait $fsstress_pid
+	unset fsstress_pid
 
  	_btrfs_kill_stress_subvolume_pid $subvol_pid $stop_file
+	unset subvol_pid
  	_btrfs_kill_stress_replace_pid $replace_pid
+	unset replace_pid
 
  	echo "Scrub the filesystem" >>$seqres.full
  	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/066 +21 -1
index b6f904ac..feb6062e 100755
@@ -10,6 +10,22 @@
  . ./common/preamble
  _begin_fstest auto subvol scrub
 
+_cleanup()
+{
+	cd /
+	rm -rf $tmp.*
+	if [ ! -z "$stop_file" ] && [ ! -z "$subvol_pid" ]; then
+		_btrfs_kill_stress_subvolume_pid $subvol_pid $stop_file
+	fi
+	if [ ! -z "$scrub_pid" ]; then
+		_btrfs_kill_stress_scrub_pid $scrub_pid
+	fi
+	if [ ! -z "$fsstress_pid" ]; then
+		kill $fsstress_pid &> /dev/null
+		wait $fsstress_pid &> /dev/null
+	fi
+}
+
  # Import common functions.
  . ./common/filter
 
@@ -20,11 +36,12 @@ _require_scratch_nocheck
  _require_scratch_dev_pool 4
  _btrfs_get_profile_configs
 
+stop_file=$TEST_DIR/$seq.stop.$$
+
  run_test()
  {
  	local mkfs_opts=$1
  	local subvol_mnt=$TEST_DIR/$seq.mnt
-	local stop_file=$TEST_DIR/$seq.stop.$$
 
  	echo "Test $mkfs_opts" >>$seqres.full
 
@@ -53,9 +70,12 @@ run_test()
 
  	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
  	wait $fsstress_pid
+	unset fsstress_pid
 
  	_btrfs_kill_stress_subvolume_pid $subvol_pid $stop_file
+	unset subvol_pid
  	_btrfs_kill_stress_scrub_pid $scrub_pid
+	unset scrub_pid
 
  	echo "Scrub the filesystem" >>$seqres.full
  	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/067 +21 -1
index 7be09d52..0bbfe83f 100755
@@ -10,6 +10,22 @@
  . ./common/preamble
  _begin_fstest auto subvol defrag compress scrub
 
+_cleanup()
+{
+	cd /
+	rm -rf $tmp.*
+	if [ ! -z "$stop_file" ] && [ ! -z "$subvol_pid" ]; then
+		_btrfs_kill_stress_subvolume_pid $subvol_pid $stop_file
+	fi
+	if [ ! -z "$defrag_pid" ]; then
+		_btrfs_kill_stress_defrag_pid $defrag_pid
+	fi
+	if [ ! -z "$fsstress_pid" ]; then
+		kill $fsstress_pid &> /dev/null
+		wait $fsstress_pid &> /dev/null
+	fi
+}
+
  # Import common functions.
  . ./common/filter
 
@@ -20,12 +36,13 @@ _require_scratch_nocheck
  _require_scratch_dev_pool 4
  _btrfs_get_profile_configs
 
+stop_file=$TEST_DIR/$seq.stop.$$
+
  run_test()
  {
  	local mkfs_opts=$1
  	local with_compress=$2
  	local subvol_mnt=$TEST_DIR/$seq.mnt
-	local stop_file=$TEST_DIR/$seq.stop.$$
 
  	echo "Test $mkfs_opts with $with_compress" >>$seqres.full
 
@@ -54,9 +71,12 @@ run_test()
 
  	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
  	wait $fsstress_pid
+	unset fsstress_pid
 
  	_btrfs_kill_stress_subvolume_pid $subvol_pid $stop_file
+	unset subvol_pid
  	_btrfs_kill_stress_defrag_pid $defrag_pid
+	unset defrag_pid
 
  	echo "Scrub the filesystem" >>$seqres.full
  	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/068 +21 -1
index 19e37010..7ab6feca 100755
@@ -11,6 +11,22 @@
  . ./common/preamble
  _begin_fstest auto subvol remount compress scrub
 
+_cleanup()
+{
+	cd /
+	rm -rf $tmp.*
+	if [ ! -z "$stop_file" ] && [ ! -z "$subvol_pid" ]; then
+		_btrfs_kill_stress_subvolume_pid $subvol_pid $stop_file
+	fi
+	if [ ! -z "$remount_pid" ]; then
+		_btrfs_kill_stress_remount_compress_pid $remount_pid $SCRATCH_MNT
+	fi
+	if [ ! -z "$fsstress_pid" ]; then
+		kill $fsstress_pid &> /dev/null
+		wait $fsstress_pid &> /dev/null
+	fi
+}
+
  # Import common functions.
  . ./common/filter
 
@@ -21,11 +37,12 @@ _require_scratch_nocheck
  _require_scratch_dev_pool 4
  _btrfs_get_profile_configs
 
+stop_file=$TEST_DIR/$seq.stop.$$
+
  run_test()
  {
  	local mkfs_opts=$1
  	local subvol_mnt=$TEST_DIR/$seq.mnt
-	local stop_file=$TEST_DIR/$seq.stop.$$
 
  	echo "Test $mkfs_opts with $with_compress" >>$seqres.full
 
@@ -54,9 +71,12 @@ run_test()
 
  	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
  	wait $fsstress_pid
+	unset fsstress_pid
 
  	_btrfs_kill_stress_subvolume_pid $subvol_pid $stop_file
+	unset subvol_pid
  	_btrfs_kill_stress_remount_compress_pid $remount_pid $SCRATCH_MNT
+	unset remount_pid
 
  	echo "Scrub the filesystem" >>$seqres.full
  	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/069 +19 -0
index ad1609d4..3fbfecdb 100755
@@ -10,6 +10,22 @@
  . ./common/preamble
  _begin_fstest auto replace scrub volume
 
+_cleanup()
+{
+	cd /
+	rm -rf $tmp.*
+	if [ ! -z "$replace_pid" ]; then
+		_btrfs_kill_stress_replace_pid $replace_pid
+	fi
+	if [ ! -z "$scrub_pid" ]; then
+		_btrfs_kill_stress_scrub_pid $scrub_pid
+	fi
+	if [ ! -z "$fsstress_pid" ]; then
+		kill $fsstress_pid &> /dev/null
+		wait $fsstress_pid &> /dev/null
+	fi
+}
+
  # Import common functions.
  . ./common/filter
 
@@ -59,8 +75,11 @@ run_test()
 
  	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
  	wait $fsstress_pid
+	unset fsstress_pid
  	_btrfs_kill_stress_scrub_pid $scrub_pid
+	unset scrub_pid
  	_btrfs_kill_stress_replace_pid $replace_pid
+	unset replace_pid
 
  	echo "Scrub the filesystem" >>$seqres.full
  	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/070 +19 -0
index 3054c270..11fddc86 100755
@@ -10,6 +10,22 @@
  . ./common/preamble
  _begin_fstest auto replace defrag compress volume scrub
 
+_cleanup()
+{
+	cd /
+	rm -rf $tmp.*
+	if [ ! -z "$replace_pid" ]; then
+		_btrfs_kill_stress_replace_pid $replace_pid
+	fi
+	if [ ! -z "$defrag_pid" ]; then
+		_btrfs_kill_stress_defrag_pid $defrag_pid
+	fi
+	if [ ! -z "$fsstress_pid" ]; then
+		kill $fsstress_pid &> /dev/null
+		wait $fsstress_pid &> /dev/null
+	fi
+}
+
  # Import common functions.
  . ./common/filter
 
@@ -60,8 +76,11 @@ run_test()
 
  	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
  	wait $fsstress_pid
+	unset fsstress_pid
  	_btrfs_kill_stress_replace_pid $replace_pid
+	unset replace_pid
  	_btrfs_kill_stress_defrag_pid $defrag_pid
+	unset defrag_pid
 
  	echo "Scrub the filesystem" >>$seqres.full
  	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/071 +19 -0
index 36b39341..1a91ec45 100755
@@ -10,6 +10,22 @@
  . ./common/preamble
  _begin_fstest auto replace remount compress volume scrub
 
+_cleanup()
+{
+	cd /
+	rm -rf $tmp.*
+	if [ ! -z "$replace_pid" ]; then
+		_btrfs_kill_stress_replace_pid $replace_pid
+	fi
+	if [ ! -z "$remount_pid" ]; then
+		_btrfs_kill_stress_remount_compress_pid $remount_pid $SCRATCH_MNT
+	fi
+	if [ ! -z "$fsstress_pid" ]; then
+		kill $fsstress_pid &> /dev/null
+		wait $fsstress_pid &> /dev/null
+	fi
+}
+
  # Import common functions.
  . ./common/filter
 
@@ -59,8 +75,11 @@ run_test()
 
  	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
  	wait $fsstress_pid
+	unset fsstress_pid
  	_btrfs_kill_stress_replace_pid $replace_pid
+	unset replace_pid
  	_btrfs_kill_stress_remount_compress_pid $remount_pid $SCRATCH_MNT
+	unset remount_pid
 
  	echo "Scrub the filesystem" >>$seqres.full
  	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/072 +19 -0
index 505d0b57..e66e49c9 100755
@@ -10,6 +10,22 @@
  . ./common/preamble
  _begin_fstest auto scrub defrag compress
 
+_cleanup()
+{
+	cd /
+	rm -rf $tmp.*
+	if [ ! -z "$defrag_pid" ]; then
+		_btrfs_kill_stress_defrag_pid $defrag_pid
+	fi
+	if [ ! -z "$scrub_pid" ]; then
+		_btrfs_kill_stress_scrub_pid $scrub_pid
+	fi
+	if [ ! -z "$fsstress_pid" ]; then
+		kill $fsstress_pid &> /dev/null
+		wait $fsstress_pid &> /dev/null
+	fi
+}
+
  # Import common functions.
  . ./common/filter
 
@@ -52,9 +68,12 @@ run_test()
 
  	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
  	wait $fsstress_pid
+	unset fsstress_pid
 
  	_btrfs_kill_stress_defrag_pid $defrag_pid
+	unset defrag_pid
  	_btrfs_kill_stress_scrub_pid $scrub_pid
+	unset scrub_pid
 
  	echo "Scrub the filesystem" >>$seqres.full
  	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/073 +19 -0
index 50358286..e6cfd92a 100755
@@ -10,6 +10,22 @@
  . ./common/preamble
  _begin_fstest auto scrub remount compress
 
+_cleanup()
+{
+	cd /
+	rm -rf $tmp.*
+	if [ ! -z "$remount_pid" ]; then
+		_btrfs_kill_stress_remount_compress_pid $remount_pid $SCRATCH_MNT
+	fi
+	if [ ! -z "$scrub_pid" ]; then
+		_btrfs_kill_stress_scrub_pid $scrub_pid
+	fi
+	if [ ! -z "$fsstress_pid" ]; then
+		kill $fsstress_pid &> /dev/null
+		wait $fsstress_pid &> /dev/null
+	fi
+}
+
  # Import common functions.
  . ./common/filter
 
@@ -51,8 +67,11 @@ run_test()
 
  	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
  	wait $fsstress_pid
+	unset fsstress_pid
  	_btrfs_kill_stress_remount_compress_pid $remount_pid $SCRATCH_MNT
+	unset remount_pid
  	_btrfs_kill_stress_scrub_pid $scrub_pid
+	unset scrub_pid
 
  	echo "Scrub the filesystem" >>$seqres.full
  	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
tests/btrfs/074 +19 -0
index 6e93b36a..1dd88bcd 100755
@@ -10,6 +10,22 @@
  . ./common/preamble
  _begin_fstest auto defrag remount compress scrub
 
+_cleanup()
+{
+	cd /
+	rm -rf $tmp.*
+	if [ ! -z "$remount_pid" ]; then
+		_btrfs_kill_stress_remount_compress_pid $remount_pid $SCRATCH_MNT
+	fi
+	if [ ! -z "$defrag_pid" ]; then
+		_btrfs_kill_stress_defrag_pid $defrag_pid
+	fi
+	if [ ! -z "$fsstress_pid" ]; then
+		kill $fsstress_pid &> /dev/null
+		wait $fsstress_pid &> /dev/null
+	fi
+}
+
  # Import common functions.
  . ./common/filter
 
@@ -52,8 +68,11 @@ run_test()
 
  	echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
  	wait $fsstress_pid
+	unset fsstress_pid
  	_btrfs_kill_stress_remount_compress_pid $remount_pid $SCRATCH_MNT
+	unset remount_pid
  	_btrfs_kill_stress_defrag_pid $defrag_pid
+	unset defrag_pid
 
  	echo "Scrub the filesystem" >>$seqres.full
  	$BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
#16 lore raw

Re: [PATCH 06/10] btrfs: add helper to kill background process running _btrfs_stress_remount_compress

In reply to Anand Jain
Quoted 10 lines
Quoted 7 lines
tests/btrfs/071 +0 -0
index 6ebbd8cc..7ba15390 100755
@@ -58,17 +58,15 @@ run_test()

      echo "$remount_pid" >>$seqres.full

Quoted 7 lines
Quoted 7 lines

      echo "Wait for fsstress to exit and kill all background workers"

Quoted 1 line
Quoted 1 line

$seqres.full

-    wait $fsstress_pid
-    kill $replace_pid $remount_pid
-    wait
+    kill $replace_pid
+    wait $fsstress_pid $replace_pid

The change first kills the replace and then wait for fsstress. Was this intentional?

This patch is causing a regression. The replace never gets killed, as the echo-comment specifically states to wait for fsstress and then kill the replace. Following it fixes the issue.

Which the patch 7/10 reversed the order to fix. But why?

Thanks, Anand

Quoted 16 lines
Quoted 16 lines

-    # wait for the remount and replace operations to finish +    # wait for the replace operationss to finish

      while ps aux | grep "replace start" | grep -qv grep; do sleep 1
      done
-    while ps aux | grep "mount.*$SCRATCH_MNT" | grep -qv grep; do -        sleep 1
-    done
+
+    _btrfs_kill_stress_remount_compress_pid $remount_pid $SCRATCH_MNT echo "Scrub the filesystem" >>$seqres.full $BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1

#17 lore raw

Re: [PATCH 06/10] btrfs: add helper to kill background process running _btrfs_stress_remount_compress

Quoted 13 lines · Anand Jain
Quoted 13 lines
Quoted 13 lines
tests/btrfs/071 +0 -0
index 6ebbd8cc..7ba15390 100755
@@ -58,17 +58,15 @@ run_test()
      echo "$remount_pid" >>$seqres.full
 
 
 
      echo "Wait for fsstress to exit and kill all background workers"
Quoted 1 line
Quoted 1 line

$seqres.full

Quoted 8 lines
Quoted 5 lines

tests/btrfs/071 run_test() · line 62

Quoted 5 lines
tests/btrfs/071 +2 -3
-    wait $fsstress_pid
-    kill $replace_pid $remount_pid
-    wait
+    kill $replace_pid
+    wait $fsstress_pid $replace_pid

The change first kills the replace and then wait for fsstress. Was this intentional?

It wasn't. But after all patches applied, everything's correct, we wait for fsstress to finish and then kill replace.
Do you want me to fix that?

The sequence will have to be:

wait $fsstress_pid
kill $replace_pid
wait $replace_pid

Thanks.

Quoted 26 lines

This patch is causing a regression. The replace never gets killed, as the echo-comment specifically states to wait for fsstress and then kill the replace. Following it fixes the issue.

Which the patch 7/10 reversed the order to fix. But why?

Thanks, Anand

Quoted 16 lines
Quoted 16 lines
tests/btrfs/071 +3 -4
-    # wait for the remount and replace operations to finish
+    # wait for the replace operationss to finish
 
 
 
 
      while ps aux | grep "replace start" | grep -qv grep; do
          sleep 1
      done
-    while ps aux | grep "mount.*$SCRATCH_MNT" | grep -qv grep; do
-        sleep 1
-    done
+
+    _btrfs_kill_stress_remount_compress_pid $remount_pid $SCRATCH_MNT
      echo "Scrub the filesystem" >>$seqres.full
      $BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
#18 lore raw

Re: [PATCH 06/10] btrfs: add helper to kill background process running _btrfs_stress_remount_compress

Quoted 21 lines · Filipe Manana
Quoted 19 lines · Anand Jain
Quoted 18 lines
Quoted 18 lines
tests/btrfs/071 +0 -0
index 6ebbd8cc..7ba15390 100755
@@ -58,17 +58,15 @@ run_test()
       echo "$remount_pid" >>$seqres.full
 
 
 
       echo "Wait for fsstress to exit and kill all background workers"
Quoted 1 line
Quoted 1 line

$seqres.full

tests/btrfs/071 +2 -3
-    wait $fsstress_pid
-    kill $replace_pid $remount_pid
-    wait
+    kill $replace_pid
+    wait $fsstress_pid $replace_pid
Quoted 5 lines
Quoted 2 lines

The change first kills the replace and then wait for fsstress. Was this intentional?

It wasn't.

Ok. Thanks for confirming. I will fix it.

-Anand

Quoted 38 lines

But after all patches applied, everything's correct, we wait for fsstress to finish and then kill replace. Do you want me to fix that?

The sequence will have to be:

wait $fsstress_pid
kill $replace_pid
wait $replace_pid

Thanks.

Quoted 26 lines

This patch is causing a regression. The replace never gets killed, as the echo-comment specifically states to wait for fsstress and then kill the replace. Following it fixes the issue.

Which the patch 7/10 reversed the order to fix. But why?

Thanks, Anand

Quoted 16 lines
Quoted 16 lines
tests/btrfs/071 +3 -4
-    # wait for the remount and replace operations to finish
+    # wait for the replace operationss to finish
 
 
 
 
       while ps aux | grep "replace start" | grep -qv grep; do
           sleep 1
       done
-    while ps aux | grep "mount.*$SCRATCH_MNT" | grep -qv grep; do
-        sleep 1
-    done
+
+    _btrfs_kill_stress_remount_compress_pid $remount_pid $SCRATCH_MNT
       echo "Scrub the filesystem" >>$seqres.full
       $BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1