]> www.infradead.org Git - users/hch/xfstests-dev.git/commitdiff
btrfs: add helper to kill background process running _btrfs_stress_balance
authorFilipe Manana <fdmanana@suse.com>
Wed, 27 Mar 2024 17:11:35 +0000 (17:11 +0000)
committerAnand Jain <anand.jain@oracle.com>
Wed, 3 Apr 2024 07:06:31 +0000 (15:06 +0800)
Killing a background process running _btrfs_stress_balance() 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
   # Wait for the balance operation to finish.
   while ps aux | grep "balance 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/060
tests/btrfs/061
tests/btrfs/062
tests/btrfs/063
tests/btrfs/064
tests/btrfs/255

index 99bd5ace674fbee94769322b3d23576d49e0ad7c..f9a888e39ceee052d1d60e6ec7b53e6961e4f1a1 100644 (file)
@@ -318,6 +318,20 @@ _btrfs_stress_balance()
        done
 }
 
+# Kill a background process running _btrfs_stress_balance()
+_btrfs_kill_stress_balance_pid()
+{
+       local balance_pid=$1
+
+       # Ignore if process already died.
+       kill $balance_pid &> /dev/null
+       wait $balance_pid &> /dev/null
+       # Wait for the balance operation to finish.
+       while ps aux | grep "balance start" | grep -qv grep; do
+               sleep 1
+       done
+}
+
 # stress btrfs by creating/mounting/umounting/deleting subvolume in a loop
 _btrfs_stress_subvolume()
 {
index a018489160273d5bba6bb4658e1c74e5f9284d93..58167cc6ba7f35d93fdc0fb2b82be93c50e7dbc0 100755 (executable)
@@ -57,12 +57,8 @@ run_test()
        wait $fsstress_pid
 
        touch $stop_file
-       kill $balance_pid
-       wait
-       # wait for the balance operation to finish
-       while ps aux | grep "balance start" | grep -qv grep; do
-               sleep 1
-       done
+       wait $subvol_pid
+       _btrfs_kill_stress_balance_pid $balance_pid
 
        echo "Scrub the filesystem" >>$seqres.full
        $BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
index c101041360cebb4d6a0e278ac0d0a063b2a9a98b..d0b55e48c0e881a23d82f59d1178582c4729d5ae 100755 (executable)
@@ -51,12 +51,10 @@ run_test()
 
        echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
        wait $fsstress_pid
-       kill $balance_pid $scrub_pid
-       wait
-       # wait for the balance and scrub operations to finish
-       while ps aux | grep "balance start" | grep -qv grep; do
-               sleep 1
-       done
+       _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
index 818a0156668d8c89aa1148de26683b488610191d..a2639d6ccc1631d57af29a5c91ae7ed86d4f263e 100755 (executable)
@@ -52,12 +52,10 @@ run_test()
 
        echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
        wait $fsstress_pid
-       kill $balance_pid $defrag_pid
-       wait
-       # wait for the balance and defrag operations to finish
-       while ps aux | grep "balance start" | grep -qv grep; do
-               sleep 1
-       done
+       _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
index 2f771baf7cea2b0e4b59f57421a698c0e0dee043..baf0c35649a5aa4068aad5ec1168f10477e92eb9 100755 (executable)
@@ -51,12 +51,10 @@ run_test()
 
        echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
        wait $fsstress_pid
-       kill $balance_pid $remount_pid
-       wait
-       # wait for the balance and remount loop to finish
-       while ps aux | grep "balance start" | grep -qv grep; do
-               sleep 1
-       done
+       _btrfs_kill_stress_balance_pid $balance_pid
+       kill $remount_pid
+       wait $remount_pid
+       # wait for the remount loop to finish
        while ps aux | grep "mount.*$SCRATCH_MNT" | grep -qv grep; do
                sleep 1
        done
index e9b46ce665775de5f64dad77698b07f30dd496e3..58b53afe3fdfdf479ab9d1793b5dbc074090720a 100755 (executable)
@@ -63,12 +63,10 @@ run_test()
 
        echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
        wait $fsstress_pid
-       kill $balance_pid $replace_pid
-       wait
-       # wait for the balance and replace operations to finish
-       while ps aux | grep "balance start" | grep -qv grep; do
-               sleep 1
-       done
+       _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
index 7e70944afa44496259e789f3d2d91f165a2d9804..aa250467e465da4b5c75b55f55f8139b4ac0c309 100755 (executable)
@@ -41,12 +41,8 @@ for ((i = 0; i < 20; i++)); do
        $BTRFS_UTIL_PROG quota enable $SCRATCH_MNT
        $BTRFS_UTIL_PROG quota disable $SCRATCH_MNT
 done
-kill $balance_pid &> /dev/null
-wait
-# wait for the balance operation to finish
-while ps aux | grep "balance start" | grep -qv grep; do
-       sleep 1
-done
+
+_btrfs_kill_stress_balance_pid $balance_pid
 
 echo "Silence is golden"
 status=0