public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH] tools/counter: Add checking directory exists for make clean
       [not found] <362e127d-6018-5fc6-247b-3c729b99d946@gmail.com>
@ 2023-07-10  1:07 ` William Breathitt Gray
  2023-07-14 13:57   ` Anh Tuan Phan
  0 siblings, 1 reply; 3+ messages in thread
From: William Breathitt Gray @ 2023-07-10  1:07 UTC (permalink / raw)
  To: Anh Tuan Phan
  Cc: linux-kernel-mentees, rongtao, ricardo, linux-iio, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2106 bytes --]

On Fri, Jul 07, 2023 at 09:08:35PM +0700, Anh Tuan Phan wrote:
> rmdir requires the directory exist so it causes "make -C tools clean"
> failed if someone only builds other tools but not counter. This commit
> adds checking the directory exist before doing rmdir.
> 
> Signed-off-by: Anh Tuan Phan <tuananhlfc@gmail.com>
> ---
>  tools/counter/Makefile | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/counter/Makefile b/tools/counter/Makefile
> index a0f4cab71fe5..2907f3b3094b 100644
> --- a/tools/counter/Makefile
> +++ b/tools/counter/Makefile
> @@ -40,7 +40,9 @@ $(OUTPUT)counter_example: $(COUNTER_EXAMPLE)
>  clean:
>  	rm -f $(ALL_PROGRAMS)
>  	rm -rf $(OUTPUT)include/linux/counter.h
> -	rmdir -p $(OUTPUT)include/linux
> +	@if [ -d $(OUTPUT)include/linux ]; then \
> +		rmdir -p $(OUTPUT)include/linux; \
> +	fi
>  	find $(or $(OUTPUT),.) -name '*.o' -delete -o -name '\.*.d' -delete
> 
>  install: $(ALL_PROGRAMS)
> -- 
> 2.34.1

Hi Anh,

Please CC <linux-iio@vger.kernel.org> and <linux-kernel@vger.kernel.org>
as well in the future so Counter users and developers can become aware
of relevant patches.

One worry I have with this approach is the possible race condition where
the check for existence succeeds but the directory is deleted by another
agent before our rmdir executes. However, I'm not sure how we could
achieve such behavior atomically to prevent the issue.

One alternative I've considered is perhaps a single find command to
search for and delete empty directories:

    find $(or $(OUTPUT),.) -type d -empty -delete

But this will delete directories not created by the makefile which I
consider an unexpected behavior for the user (or at least very rude of
the script to do).

Perhaps we should delete the directory tree explicitly:

    rm -df $(OUTPUT)include/linux
    rm -df $(OUTPUT)include

Although we lose the symmetry of rmdir to our previous mkdir, this
should prevent the race condition issue and succeed whether the
directories still exist or not.

William Breathitt Gray

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

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

* Re: [PATCH] tools/counter: Add checking directory exists for make clean
  2023-07-14 13:57   ` Anh Tuan Phan
@ 2023-07-14 11:34     ` William Breathitt Gray
  0 siblings, 0 replies; 3+ messages in thread
From: William Breathitt Gray @ 2023-07-14 11:34 UTC (permalink / raw)
  To: Anh Tuan Phan
  Cc: linux-kernel-mentees, rongtao, ricardo, linux-iio, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 422 bytes --]

On Fri, Jul 14, 2023 at 08:57:21PM +0700, Anh Tuan Phan wrote:
> Hi William, the race condition possibility is a good point. Thanks for
> suggesting me. Will send a new version with using `rm -df` instead and
> add the appropriate CC lists. Thank you!

Hi Anh,

Because this will fix a failure, please include a Fixes tag as well that
references the commit that introduces the rmdir line.

Thanks,

William Breathitt Gray

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

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

* Re: [PATCH] tools/counter: Add checking directory exists for make clean
  2023-07-10  1:07 ` [PATCH] tools/counter: Add checking directory exists for make clean William Breathitt Gray
@ 2023-07-14 13:57   ` Anh Tuan Phan
  2023-07-14 11:34     ` William Breathitt Gray
  0 siblings, 1 reply; 3+ messages in thread
From: Anh Tuan Phan @ 2023-07-14 13:57 UTC (permalink / raw)
  To: William Breathitt Gray
  Cc: linux-kernel-mentees, rongtao, ricardo, linux-iio, linux-kernel

Hi William, the race condition possibility is a good point. Thanks for
suggesting me. Will send a new version with using `rm -df` instead and
add the appropriate CC lists. Thank you!

On 7/10/23 08:07, William Breathitt Gray wrote:
> On Fri, Jul 07, 2023 at 09:08:35PM +0700, Anh Tuan Phan wrote:
>> rmdir requires the directory exist so it causes "make -C tools clean"
>> failed if someone only builds other tools but not counter. This commit
>> adds checking the directory exist before doing rmdir.
>>
>> Signed-off-by: Anh Tuan Phan <tuananhlfc@gmail.com>
>> ---
>>  tools/counter/Makefile | 4 +++-
>>  1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/tools/counter/Makefile b/tools/counter/Makefile
>> index a0f4cab71fe5..2907f3b3094b 100644
>> --- a/tools/counter/Makefile
>> +++ b/tools/counter/Makefile
>> @@ -40,7 +40,9 @@ $(OUTPUT)counter_example: $(COUNTER_EXAMPLE)
>>  clean:
>>  	rm -f $(ALL_PROGRAMS)
>>  	rm -rf $(OUTPUT)include/linux/counter.h
>> -	rmdir -p $(OUTPUT)include/linux
>> +	@if [ -d $(OUTPUT)include/linux ]; then \
>> +		rmdir -p $(OUTPUT)include/linux; \
>> +	fi
>>  	find $(or $(OUTPUT),.) -name '*.o' -delete -o -name '\.*.d' -delete
>>
>>  install: $(ALL_PROGRAMS)
>> -- 
>> 2.34.1
> 
> Hi Anh,
> 
> Please CC <linux-iio@vger.kernel.org> and <linux-kernel@vger.kernel.org>
> as well in the future so Counter users and developers can become aware
> of relevant patches.
> 
> One worry I have with this approach is the possible race condition where
> the check for existence succeeds but the directory is deleted by another
> agent before our rmdir executes. However, I'm not sure how we could
> achieve such behavior atomically to prevent the issue.
> 
> One alternative I've considered is perhaps a single find command to
> search for and delete empty directories:
> 
>     find $(or $(OUTPUT),.) -type d -empty -delete
> 
> But this will delete directories not created by the makefile which I
> consider an unexpected behavior for the user (or at least very rude of
> the script to do).
> 
> Perhaps we should delete the directory tree explicitly:
> 
>     rm -df $(OUTPUT)include/linux
>     rm -df $(OUTPUT)include
> 
> Although we lose the symmetry of rmdir to our previous mkdir, this
> should prevent the race condition issue and succeed whether the
> directories still exist or not.
> 
> William Breathitt Gray

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

end of thread, other threads:[~2023-07-14 22:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <362e127d-6018-5fc6-247b-3c729b99d946@gmail.com>
2023-07-10  1:07 ` [PATCH] tools/counter: Add checking directory exists for make clean William Breathitt Gray
2023-07-14 13:57   ` Anh Tuan Phan
2023-07-14 11:34     ` William Breathitt Gray

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox