]> www.infradead.org Git - users/hch/xfstests-dev.git/commitdiff
btrfs: add helper to kill background process running _btrfs_stress_scrub
authorFilipe Manana <fdmanana@suse.com>
Wed, 27 Mar 2024 17:11:38 +0000 (17:11 +0000)
committerAnand Jain <anand.jain@oracle.com>
Wed, 3 Apr 2024 07:08:15 +0000 (15:08 +0800)
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.

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>
common/btrfs
tests/btrfs/061
tests/btrfs/066
tests/btrfs/069
tests/btrfs/072
tests/btrfs/073

index f9a888e39ceee052d1d60e6ec7b53e6961e4f1a1..cf320190b22f86a97ce76cdf0325038a99559839 100644 (file)
@@ -359,6 +359,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()
index d0b55e48c0e881a23d82f59d1178582c4729d5ae..b8b2706c666fe3a6f60fcf625f575db937b232d0 100755 (executable)
@@ -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
index a29034bb3a7eecbbf9d93af0db782833a8c90b44..29821fddc05fa657501116c70dc0033248af5089 100755 (executable)
@@ -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
index 139dde48a5f44c7c218c824fdd6c42f2bcce69f4..20f44b396e9cba8400dd01ab2bcf12673eb91792 100755 (executable)
@@ -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
index 4b6b6fb57231729713a09d03b686ee02a7fed64d..6c15b51f046578fb2985aa7b1fc323ea70c07869 100755 (executable)
@@ -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
index b1604f94989aafdc503074bb4243c1ca3de839d6..49a4abd11369d3b0af9a5cbae8ef7b5efcb28c33 100755 (executable)
@@ -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