]> www.infradead.org Git - users/hch/xfstests-dev.git/commitdiff
btrfs: add helper to kill background process running _btrfs_stress_remount_compress
authorFilipe Manana <fdmanana@suse.com>
Wed, 27 Mar 2024 17:11:40 +0000 (17:11 +0000)
committerAnand Jain <anand.jain@oracle.com>
Wed, 3 Apr 2024 07:08:30 +0000 (15:08 +0800)
Killing a background process running _btrfs_stress_remount_compress() 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 "mount.*$SCRATCH_MNT" | 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>
[ Restore 'wait $fsstress_pid' before 'kill $replace_pid' ]

common/btrfs
tests/btrfs/063
tests/btrfs/068
tests/btrfs/071
tests/btrfs/073
tests/btrfs/074

index dd7bb6c26c23fb0660380c371f258f10f2c50128..e7df825ed45491f9918b22b128a6eb912c3fa0f7 100644 (file)
@@ -421,6 +421,21 @@ _btrfs_stress_remount_compress()
        done
 }
 
+# Kill a background process running _btrfs_stress_remount_compress()
+_btrfs_kill_stress_remount_compress_pid()
+{
+       local remount_pid=$1
+       local btrfs_mnt=$2
+
+       # Ignore if process already died.
+       kill $remount_pid &> /dev/null
+       wait $remount_pid &> /dev/null
+       # Wait for the remount loop to finish.
+       while ps aux | grep "mount.*${btrfs_mnt}" | grep -qv grep; do
+               sleep 1
+       done
+}
+
 # stress btrfs by replacing devices in a loop
 # Note that at least 3 devices are needed in SCRATCH_DEV_POOL and the last
 # device should be free(not used by btrfs)
index baf0c35649a5aa4068aad5ec1168f10477e92eb9..5ee2837f891d66908387153281ca46edae785010 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 $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
+       _btrfs_kill_stress_remount_compress_pid $remount_pid $SCRATCH_MNT
 
        echo "Scrub the filesystem" >>$seqres.full
        $BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
index 15fd41db97b40d97914e1047f70ad0094cc2976e..db53254a150d9bb3d1f7db3a0a8940fd778998d1 100755 (executable)
@@ -58,12 +58,8 @@ run_test()
        wait $fsstress_pid
 
        touch $stop_file
-       kill $remount_pid
-       wait
-       # wait for the remount loop process to finish
-       while ps aux | grep "mount.*$SCRATCH_MNT" | grep -qv grep; do
-               sleep 1
-       done
+       wait $subvol_pid
+       _btrfs_kill_stress_remount_compress_pid $remount_pid $SCRATCH_MNT
 
        echo "Scrub the filesystem" >>$seqres.full
        $BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
index 6ebbd8cc3c54fcca66e2f69e83f06dbc3a47b5c0..d9aaf3d56148a57286ef9fcef19ee6d96b469143 100755 (executable)
@@ -59,16 +59,15 @@ run_test()
 
        echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
        wait $fsstress_pid
-       kill $replace_pid $remount_pid
-       wait
+       kill $replace_pid
+       wait $replace_pid
 
-       # wait for the remount and replace operations to finish
+       # wait for the replace operationss to finish
        while ps aux | grep "replace start" | grep -qv grep; do
                sleep 1
        done
-       while ps aux | grep "mount.*$SCRATCH_MNT" | grep -qv grep; do
-               sleep 1
-       done
+
+       _btrfs_kill_stress_remount_compress_pid $remount_pid $SCRATCH_MNT
 
        echo "Scrub the filesystem" >>$seqres.full
        $BTRFS_UTIL_PROG scrub start -B $SCRATCH_MNT >>$seqres.full 2>&1
index 49a4abd11369d3b0af9a5cbae8ef7b5efcb28c33..503582862f6de34cc49105acdb175ca95fad4959 100755 (executable)
@@ -51,13 +51,7 @@ run_test()
 
        echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
        wait $fsstress_pid
-       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_remount_compress_pid $remount_pid $SCRATCH_MNT
        _btrfs_kill_stress_scrub_pid $scrub_pid
 
        echo "Scrub the filesystem" >>$seqres.full
index d51922d08b8b8278cbd35f3b37443fccadcfac08..6e93b36a9702432c99497cbe3f9afbc604e21899 100755 (executable)
@@ -52,13 +52,7 @@ run_test()
 
        echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full
        wait $fsstress_pid
-       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_remount_compress_pid $remount_pid $SCRATCH_MNT
        _btrfs_kill_stress_defrag_pid $defrag_pid
 
        echo "Scrub the filesystem" >>$seqres.full