xfs/{422,517}: kill background jobs on test termination
[xfstests-dev.git] / tests / xfs / 422
index 175253aa6cdcae5c37b9072c56d19bf32d851549..fdbb8bf14c899ffae4ec6e8a43a32a54d102510b 100755 (executable)
@@ -9,10 +9,36 @@
 # activity, so we can't have userspace wandering in and thawing it.
 #
 . ./common/preamble
-_begin_fstest dangerous_scrub dangerous_online_repair
+_begin_fstest dangerous_scrub dangerous_online_repair 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 "$repair_pid" ] && kill $sig $repair_pid
+       wait
+       unset stress_pid
+       unset repair_pid
+}
+
+# Override the default cleanup function.
+_cleanup()
+{
+       kill_loops -9 > /dev/null 2>&1
+       cd /
+       rm -rf $tmp.*
+}
+
 # Import common functions.
 . ./common/filter
 . ./common/fuzzy
@@ -24,6 +50,7 @@ _require_xfs_scratch_rmapbt
 _require_xfs_io_command "scrub"
 _require_xfs_io_error_injection "force_repair"
 _require_command "$KILLALL_PROG" killall
+_require_freeze
 
 echo "Format and populate"
 _scratch_mkfs > "$seqres.full" 2>&1
@@ -77,8 +104,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=$!
 repair_loop $end &
+repair_pid=$!
 
 # Wait until 2 seconds after the loops should have finished...
 while [ "$(date +%s)" -lt $((end + 2)) ]; do
@@ -86,8 +116,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"