On 3/28/24 01:11, fdmanana@xxxxxxxxxx wrote:
From: Filipe Manana <fdmanana@xxxxxxxx>
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.
Signed-off-by: Filipe Manana <fdmanana@xxxxxxxx>
Reviewed-by: Anand Jain <anand.jain@xxxxxxxxxx>
Thanks, Anand
---
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(-)
diff --git a/common/btrfs b/common/btrfs
index 6d7e7a68..e19a6ad1 100644
--- a/common/btrfs
+++ b/common/btrfs
@@ -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()
{
diff --git a/tests/btrfs/060 b/tests/btrfs/060
index 58167cc6..87823aba 100755
--- a/tests/btrfs/060
+++ b/tests/btrfs/060
@@ -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
diff --git a/tests/btrfs/065 b/tests/btrfs/065
index d2b04178..ddc28616 100755
--- a/tests/btrfs/065
+++ b/tests/btrfs/065
@@ -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
diff --git a/tests/btrfs/066 b/tests/btrfs/066
index 29821fdd..c7488602 100755
--- a/tests/btrfs/066
+++ b/tests/btrfs/066
@@ -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
diff --git a/tests/btrfs/067 b/tests/btrfs/067
index 2bb00b87..ebbec1be 100755
--- a/tests/btrfs/067
+++ b/tests/btrfs/067
@@ -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
diff --git a/tests/btrfs/068 b/tests/btrfs/068
index db53254a..5f41fb74 100755
--- a/tests/btrfs/068
+++ b/tests/btrfs/068
@@ -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