fstests.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] common/btrfs: lookup running processes using pgrep
@ 2024-04-01  6:16 Anand Jain
  2024-04-01  6:21 ` Qu Wenruo
  0 siblings, 1 reply; 5+ messages in thread
From: Anand Jain @ 2024-04-01  6:16 UTC (permalink / raw)
  To: fstests; +Cc: linux-btrfs

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

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 common/btrfs    | 10 +++++-----
 tests/btrfs/132 |  2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/common/btrfs b/common/btrfs
index 2c086227d8e0..a320b0e41d0d 100644
--- a/common/btrfs
+++ b/common/btrfs
@@ -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
 }
diff --git a/tests/btrfs/132 b/tests/btrfs/132
index f50420f51181..b48395c1884f 100755
--- a/tests/btrfs/132
+++ b/tests/btrfs/132
@@ -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
 
-- 
2.39.3


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] common/btrfs: lookup running processes using pgrep
  2024-04-01  6:16 [PATCH] common/btrfs: lookup running processes using pgrep Anand Jain
@ 2024-04-01  6:21 ` Qu Wenruo
  2024-04-01  7:40   ` Anand Jain
  0 siblings, 1 reply; 5+ messages in thread
From: Qu Wenruo @ 2024-04-01  6:21 UTC (permalink / raw)
  To: Anand Jain, fstests; +Cc: linux-btrfs



在 2024/4/1 16:46, Anand Jain 写道:
> 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
>
> Signed-off-by: Anand Jain <anand.jain@oracle.com>

Looks good to me.

Although there are already several test cases utilizing pgrep, I'm not
100% sure if pgrep would exist for all systems.

Shouldn't there be some checks first?

Thanks,
Qu
> ---
>   common/btrfs    | 10 +++++-----
>   tests/btrfs/132 |  2 +-
>   2 files changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/common/btrfs b/common/btrfs
> index 2c086227d8e0..a320b0e41d0d 100644
> --- a/common/btrfs
> +++ b/common/btrfs
> @@ -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
>   }
> diff --git a/tests/btrfs/132 b/tests/btrfs/132
> index f50420f51181..b48395c1884f 100755
> --- a/tests/btrfs/132
> +++ b/tests/btrfs/132
> @@ -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
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] common/btrfs: lookup running processes using pgrep
  2024-04-01  6:21 ` Qu Wenruo
@ 2024-04-01  7:40   ` Anand Jain
  2024-04-01  7:51     ` Qu Wenruo
  0 siblings, 1 reply; 5+ messages in thread
From: Anand Jain @ 2024-04-01  7:40 UTC (permalink / raw)
  To: Qu Wenruo, fstests; +Cc: linux-btrfs



On 4/1/24 14:21, Qu Wenruo wrote:
> 
> 
> 在 2024/4/1 16:46, Anand Jain 写道:
>> 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
>>
>> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> 
> Looks good to me.
> 
> Although there are already several test cases utilizing pgrep, I'm not
> 100% sure if pgrep would exist for all systems.
> 
> Shouldn't there be some checks first?
> 


Actually, I checked on that and noticed that pgrep comes from
the same package as ps. So we are fine.

  $ rpm -ql procps-ng | grep -E "bin/pgrep|bin/ps"
  /usr/bin/pgrep
  /usr/bin/ps

Thanks, Anand


> Thanks,
> Qu
>> ---
>>   common/btrfs    | 10 +++++-----
>>   tests/btrfs/132 |  2 +-
>>   2 files changed, 6 insertions(+), 6 deletions(-)
>>
>> diff --git a/common/btrfs b/common/btrfs
>> index 2c086227d8e0..a320b0e41d0d 100644
>> --- a/common/btrfs
>> +++ b/common/btrfs
>> @@ -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
>>   }
>> diff --git a/tests/btrfs/132 b/tests/btrfs/132
>> index f50420f51181..b48395c1884f 100755
>> --- a/tests/btrfs/132
>> +++ b/tests/btrfs/132
>> @@ -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
>>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] common/btrfs: lookup running processes using pgrep
  2024-04-01  7:40   ` Anand Jain
@ 2024-04-01  7:51     ` Qu Wenruo
  2024-04-01  8:17       ` Anand Jain
  0 siblings, 1 reply; 5+ messages in thread
From: Qu Wenruo @ 2024-04-01  7:51 UTC (permalink / raw)
  To: Anand Jain, fstests; +Cc: linux-btrfs



在 2024/4/1 18:10, Anand Jain 写道:
>
>
> On 4/1/24 14:21, Qu Wenruo wrote:
>>
>>
>> 在 2024/4/1 16:46, Anand Jain 写道:
>>> 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
>>>
>>> Signed-off-by: Anand Jain <anand.jain@oracle.com>
>>
>> Looks good to me.
>>
>> Although there are already several test cases utilizing pgrep, I'm not
>> 100% sure if pgrep would exist for all systems.
>>
>> Shouldn't there be some checks first?
>>
>
>
> Actually, I checked on that and noticed that pgrep comes from
> the same package as ps. So we are fine.
>
>   $ rpm -ql procps-ng | grep -E "bin/pgrep|bin/ps"
>   /usr/bin/pgrep
>   /usr/bin/ps
>
> Thanks, Anand

So I guess busybox based system won't be supported anyway for fstests?

In that case it looks fine to me.

Reviewed-by: Qu Wenruo <wqu@suse.com>

Thanks,
Qu
>
>
>> Thanks,
>> Qu
>>> ---
>>>   common/btrfs    | 10 +++++-----
>>>   tests/btrfs/132 |  2 +-
>>>   2 files changed, 6 insertions(+), 6 deletions(-)
>>>
>>> diff --git a/common/btrfs b/common/btrfs
>>> index 2c086227d8e0..a320b0e41d0d 100644
>>> --- a/common/btrfs
>>> +++ b/common/btrfs
>>> @@ -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
>>>   }
>>> diff --git a/tests/btrfs/132 b/tests/btrfs/132
>>> index f50420f51181..b48395c1884f 100755
>>> --- a/tests/btrfs/132
>>> +++ b/tests/btrfs/132
>>> @@ -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
>>>
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] common/btrfs: lookup running processes using pgrep
  2024-04-01  7:51     ` Qu Wenruo
@ 2024-04-01  8:17       ` Anand Jain
  0 siblings, 0 replies; 5+ messages in thread
From: Anand Jain @ 2024-04-01  8:17 UTC (permalink / raw)
  To: Qu Wenruo, fstests; +Cc: linux-btrfs



On 4/1/24 15:51, Qu Wenruo wrote:
> 
> 
> 在 2024/4/1 18:10, Anand Jain 写道:
>>
>>
>> On 4/1/24 14:21, Qu Wenruo wrote:
>>>
>>>
>>> 在 2024/4/1 16:46, Anand Jain 写道:
>>>> 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
>>>>
>>>> Signed-off-by: Anand Jain <anand.jain@oracle.com>
>>>
>>> Looks good to me.
>>>
>>> Although there are already several test cases utilizing pgrep, I'm not
>>> 100% sure if pgrep would exist for all systems.
>>>
>>> Shouldn't there be some checks first?
>>>
>>
>>
>> Actually, I checked on that and noticed that pgrep comes from
>> the same package as ps. So we are fine.
>>
>>   $ rpm -ql procps-ng | grep -E "bin/pgrep|bin/ps"
>>   /usr/bin/pgrep
>>   /usr/bin/ps
>>
>> Thanks, Anand
> 
> So I guess busybox based system won't be supported anyway for fstests?
> 

  There aren't quite a lot of tools required for fstests in BusyBox.
  pgrep is not new in fstests, as you noticed, so not introducing
  a new failures, so for now, it should be okay.

Thanks, Anand

> In that case it looks fine to me.
> 
> Reviewed-by: Qu Wenruo <wqu@suse.com>
> 
> Thanks,
> Qu
>>
>>
>>> Thanks,
>>> Qu
>>>> ---
>>>>   common/btrfs    | 10 +++++-----
>>>>   tests/btrfs/132 |  2 +-
>>>>   2 files changed, 6 insertions(+), 6 deletions(-)
>>>>
>>>> diff --git a/common/btrfs b/common/btrfs
>>>> index 2c086227d8e0..a320b0e41d0d 100644
>>>> --- a/common/btrfs
>>>> +++ b/common/btrfs
>>>> @@ -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
>>>>   }
>>>> diff --git a/tests/btrfs/132 b/tests/btrfs/132
>>>> index f50420f51181..b48395c1884f 100755
>>>> --- a/tests/btrfs/132
>>>> +++ b/tests/btrfs/132
>>>> @@ -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
>>>>
>>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-04-01  8:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-01  6:16 [PATCH] common/btrfs: lookup running processes using pgrep Anand Jain
2024-04-01  6:21 ` Qu Wenruo
2024-04-01  7:40   ` Anand Jain
2024-04-01  7:51     ` Qu Wenruo
2024-04-01  8:17       ` Anand Jain

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).