]> www.infradead.org Git - users/hch/xfstests-dev.git/commitdiff
btrfs: add helper to kill background process running _btrfs_stress_replace
authorFilipe Manana <fdmanana@suse.com>
Wed, 27 Mar 2024 17:11:41 +0000 (17:11 +0000)
committerAnand Jain <anand.jain@oracle.com>
Wed, 3 Apr 2024 07:08:37 +0000 (15:08 +0800)
Killing a background process running _btrfs_stress_replace() 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 "replace 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/064
tests/btrfs/065
tests/btrfs/069
tests/btrfs/070
tests/btrfs/071

index e7df825ed45491f9918b22b128a6eb912c3fa0f7..217373f54fd3f9ffe211ba08f63f02a882e6ab93 100644 (file)
@@ -485,6 +485,20 @@ _btrfs_stress_replace()
        done
 }
 
+# Kill a background process running _btrfs_stress_replace()
+_btrfs_kill_stress_replace_pid()
+{
+       local replace_pid=$1
+
+       # Ignore if process already died.
+       kill $replace_pid &> /dev/null
+       wait $replace_pid &> /dev/null
+       # Wait for the replace operation to finish.
+       while ps aux | grep "replace start" | grep -qv grep; do
+               sleep 1
+       done
+}
+
 # find the right option to force output in bytes, older versions of btrfs-progs
 # print that by default, newer print human readable numbers with unit suffix
 _btrfs_qgroup_units()
index 58b53afe3fdfdf479ab9d1793b5dbc074090720a..9e0b3b30236caa2972867cb38f5cb993cb716b1a 100755 (executable)
@@ -64,12 +64,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 $replace_pid
-       wait $replace_pid
-       # wait for the replace operation to finish
-       while ps aux | grep "replace start" | grep -qv grep; do
-               sleep 1
-       done
+       _btrfs_kill_stress_replace_pid $replace_pid
 
        echo "Scrub the filesystem" >>$seqres.full
        $BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
index c4b6aafe7d263e9b85b7ec521cc28ede2995db2f..d2b04178d69e48353b328529f9569a48dab7e498 100755 (executable)
@@ -65,12 +65,8 @@ run_test()
        wait $fsstress_pid
 
        touch $stop_file
-       kill $replace_pid
-       wait
-       # wait for the replace operation to finish
-       while ps aux | grep "replace start" | grep -qv grep; do
-               sleep 1
-       done
+       wait $subvol_pid
+       _btrfs_kill_stress_replace_pid $replace_pid
 
        echo "Scrub the filesystem" >>$seqres.full
        $BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
index 20f44b396e9cba8400dd01ab2bcf12673eb91792..ad1609d401620eb163c515e1f410bccbac51e2fa 100755 (executable)
@@ -59,15 +59,8 @@ run_test()
 
        echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
        wait $fsstress_pid
-       kill $replace_pid
-       wait $replace_pid
-
-       # 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
+       _btrfs_kill_stress_replace_pid $replace_pid
 
        echo "Scrub the filesystem" >>$seqres.full
        $BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
index cefa572300a7a81e7af97c54fd7ae45c7790fa9d..3054c270bcf592f47417d5ab14ae5f29dfa66710 100755 (executable)
@@ -60,14 +60,7 @@ run_test()
 
        echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
        wait $fsstress_pid
-       kill $replace_pid
-       wait $replace_pid
-
-       # wait for the replace operation to finish
-       while ps aux | grep "replace start" | grep -qv grep; do
-               sleep 1
-       done
-
+       _btrfs_kill_stress_replace_pid $replace_pid
        _btrfs_kill_stress_defrag_pid $defrag_pid
 
        echo "Scrub the filesystem" >>$seqres.full
index d9aaf3d56148a57286ef9fcef19ee6d96b469143..36b393412a738b66acd6feaa4a0438fa6bf42c6b 100755 (executable)
@@ -59,14 +59,7 @@ run_test()
 
        echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
        wait $fsstress_pid
-       kill $replace_pid
-       wait $replace_pid
-
-       # wait for the replace operationss to finish
-       while ps aux | grep "replace start" | grep -qv grep; do
-               sleep 1
-       done
-
+       _btrfs_kill_stress_replace_pid $replace_pid
        _btrfs_kill_stress_remount_compress_pid $remount_pid $SCRATCH_MNT
 
        echo "Scrub the filesystem" >>$seqres.full