]> git.apps.os.sepia.ceph.com Git - xfstests-dev.git/commitdiff
common/btrfs: lookup running processes using pgrep
authorAnand Jain <anand.jain@oracle.com>
Mon, 1 Apr 2024 05:56:03 +0000 (13:56 +0800)
committerAnand Jain <anand.jain@oracle.com>
Wed, 3 Apr 2024 07:09:01 +0000 (15:09 +0800)
Certain helper functions and the testcase btrfs/132 use the following
script to find running processes:

while ps aux | grep "balance start" | grep -qv grep; do
<>
done

Instead, using pgrep is more efficient.

while pgrep -f "btrfs balance start" > /dev/null; do
<>
done

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
common/btrfs
tests/btrfs/132

index 2c086227d8e0a2c1cf534c84e318bef9bb718934..a320b0e41d0d7a6ad40e8fdad065d1d5c35cae70 100644 (file)
@@ -327,7 +327,7 @@ _btrfs_kill_stress_balance_pid()
        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
+       while pgrep -f "btrfs balance start" > /dev/null; do
                sleep 1
        done
 }
@@ -381,7 +381,7 @@ _btrfs_kill_stress_scrub_pid()
        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
+       while pgrep -f "btrfs scrub start" > /dev/null; do
                sleep 1
        done
 }
@@ -415,7 +415,7 @@ _btrfs_kill_stress_defrag_pid()
        kill $defrag_pid &> /dev/null
        wait $defrag_pid &> /dev/null
        # Wait for the defrag operation to finish.
-       while ps aux | grep "btrfs filesystem defrag" | grep -qv grep; do
+       while pgrep -f "btrfs filesystem defrag" > /dev/null; do
                sleep 1
        done
 }
@@ -444,7 +444,7 @@ _btrfs_kill_stress_remount_compress_pid()
        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
+       while pgrep -f "mount.*${btrfs_mnt}" > /dev/null; do
                sleep 1
        done
 }
@@ -507,7 +507,7 @@ _btrfs_kill_stress_replace_pid()
        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
+       while pgrep -f "btrfs replace start" > /dev/null; do
                sleep 1
        done
 }
index f50420f5118139aea9f912f9a16a3aaf81884f42..b48395c1884fb0cb350babfc30d21361c03f4e1d 100755 (executable)
@@ -70,7 +70,7 @@ kill $pids
 wait
 
 # Wait all writers really exits
-while ps aux | grep "$SCRATCH_MNT" | grep -qv grep; do
+while pgrep -f "$SCRATCH_MNT" > /dev/null; do
        sleep 1
 done