xfs/{422,517}: kill background jobs on test termination
[xfstests-dev.git] / tests / xfs / 517
index 88c4f43beb1b6214a837f6cf697a511f038f00f1..6877af13bb4e238840e7ee4f6a99b27d74545c35 100755 (executable)
@@ -11,11 +11,29 @@ _begin_fstest auto quick fsmap freeze
 
 _register_cleanup "_cleanup" BUS
 
+# First kill and wait the freeze loop so it won't try to freeze fs again
+# Then make sure fs is not frozen
+# Then kill and wait for the rest of the workers
+# Because if fs is frozen a killed writer will never exit
+kill_loops() {
+       local sig=$1
+
+       [ -n "$freeze_pid" ] && kill $sig $freeze_pid
+       wait $freeze_pid
+       unset freeze_pid
+       $XFS_IO_PROG -x -c 'thaw' $SCRATCH_MNT
+       [ -n "$stress_pid" ] && kill $sig $stress_pid
+       [ -n "$fsmap_pid" ] && kill $sig $fsmap_pid
+       wait
+       unset stress_pid
+       unset fsmap_pid
+}
+
 # Override the default cleanup function.
 _cleanup()
 {
+       kill_loops -9 > /dev/null 2>&1
        cd /
-       $XFS_IO_PROG -x -c 'thaw' $SCRATCH_MNT > /dev/null 2>&1
        rm -rf $tmp.*
 }
 
@@ -29,6 +47,7 @@ _supported_fs xfs
 _require_xfs_scratch_rmapbt
 _require_xfs_io_command "fsmap"
 _require_command "$KILLALL_PROG" killall
+_require_freeze
 
 echo "Format and populate"
 _scratch_mkfs > "$seqres.full" 2>&1
@@ -82,8 +101,11 @@ end=$((start + (30 * TIME_FACTOR) ))
 
 echo "Loop started at $(date --date="@${start}"), ending at $(date --date="@${end}")" >> $seqres.full
 stress_loop $end &
+stress_pid=$!
 freeze_loop $end &
+freeze_pid=$!
 fsmap_loop $end &
+fsmap_pid=$!
 
 # Wait until 2 seconds after the loops should have finished...
 while [ "$(date +%s)" -lt $((end + 2)) ]; do
@@ -91,8 +113,7 @@ while [ "$(date +%s)" -lt $((end + 2)) ]; do
 done
 
 # ...and clean up after the loops in case they didn't do it themselves.
-$KILLALL_PROG -TERM xfs_io fsstress >> $seqres.full 2>&1
-$XFS_IO_PROG -x -c 'thaw' $SCRATCH_MNT >> $seqres.full 2>&1
+kill_loops >> $seqres.full 2>&1
 
 echo "Loop finished at $(date)" >> $seqres.full
 echo "Test done"