aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFilipe Manana <fdmanana@suse.com>2024-03-27 17:11:39 +0000
committerAnand Jain <anand.jain@oracle.com>2024-04-03 15:08:24 +0800
commitd6b4a1531fbb15dee7db86272eabe4fd86c49465 (patch)
treefd2b335e0b4d967d885bb8238e5fba4bce567e28
parentb2a3bc018fe0e23c2fbd9df89353ca048b28ad73 (diff)
downloadxfstests-dev-d6b4a1531fbb15dee7db86272eabe4fd86c49465.tar.gz
btrfs: add helper to kill background process running _btrfs_stress_defrag
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. Reviewed-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: Filipe Manana <fdmanana@suse.com> Signed-off-by: Anand Jain <anand.jain@oracle.com>
-rw-r--r--common/btrfs14
-rwxr-xr-xtests/btrfs/0627
-rwxr-xr-xtests/btrfs/0678
-rwxr-xr-xtests/btrfs/07011
-rwxr-xr-xtests/btrfs/0727
-rwxr-xr-xtests/btrfs/07411
6 files changed, 28 insertions, 30 deletions
diff --git a/common/btrfs b/common/btrfs
index cf320190b2..dd7bb6c26c 100644
--- a/common/btrfs
+++ b/common/btrfs
@@ -393,6 +393,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
diff --git a/tests/btrfs/062 b/tests/btrfs/062
index a2639d6ccc..59d581bead 100755
--- a/tests/btrfs/062
+++ b/tests/btrfs/062
@@ -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
diff --git a/tests/btrfs/067 b/tests/btrfs/067
index 709db155d2..2bb00b875a 100755
--- a/tests/btrfs/067
+++ b/tests/btrfs/067
@@ -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
diff --git a/tests/btrfs/070 b/tests/btrfs/070
index 54aa275c7d..cefa572300 100755
--- a/tests/btrfs/070
+++ b/tests/btrfs/070
@@ -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
diff --git a/tests/btrfs/072 b/tests/btrfs/072
index 6c15b51f04..505d0b578c 100755
--- a/tests/btrfs/072
+++ b/tests/btrfs/072
@@ -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
diff --git a/tests/btrfs/074 b/tests/btrfs/074
index 9b22c62029..d51922d08b 100755
--- a/tests/btrfs/074
+++ b/tests/btrfs/074
@@ -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