From: Matthieu Baerts <matttbe@kernel.org>
To: Geliang Tang <geliang@kernel.org>, mptcp@lists.linux.dev
Subject: Re: [PATCH mptcp-next v6 5/9] selftests: net: lib: remove ns from list after clean-up
Date: Tue, 28 May 2024 17:26:19 +0200 [thread overview]
Message-ID: <be0b8ab8-bff8-4a11-a6bd-fdba6ed36ff5@kernel.org> (raw)
In-Reply-To: <60d8e4dd2e8bb8671200bf009c7f49d9ec545cec.camel@kernel.org>
Hi Geliang,
On 28/05/2024 15:18, Geliang Tang wrote:
> On Tue, 2024-05-28 at 12:38 +0200, Matthieu Baerts wrote:
>> Hi Geliang,
>>
>> Thank you for your review!
>>
>> On 28/05/2024 05:47, Geliang Tang wrote:
>>> On Mon, 2024-05-27 at 12:58 +0200, Matthieu Baerts (NGI0) wrote:
>>>> Instead of only appending items to the list, remove them when the
>>>> netns
>>>> has been deleted.
>>>>
>>>> By doing that, we can make sure 'cleanup_all_ns()' is not trying
>>>> to
>>>> remove already deleted netns.
>>>>
>>>> Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
>>>> ---
>>>> tools/testing/selftests/net/lib.sh | 21 +++++++++++++++++----
>>>> 1 file changed, 17 insertions(+), 4 deletions(-)
>>>>
>>>> diff --git a/tools/testing/selftests/net/lib.sh
>>>> b/tools/testing/selftests/net/lib.sh
>>>> index b2572aff6286..c7a8cfb477cc 100644
>>>> --- a/tools/testing/selftests/net/lib.sh
>>>> +++ b/tools/testing/selftests/net/lib.sh
>>>> @@ -125,6 +125,20 @@ slowwait_for_counter()
>>>> slowwait "$timeout" until_counter_is ">= $((base +
>>>> delta))"
>>>> "$@"
>>>> }
>>>>
>>>> +remove_ns_list()
>>>> +{
>>>> + local item=$1
>>>> + local ns
>>>> + local ns_list=("${NS_LIST[@]}")
>>>> + NS_LIST=()
>>>> +
>>>> + for ns in "${ns_list[@]}"; do
>>>> + if [ "${ns}" != "${item}" ]; then
>>>> + NS_LIST+=("${ns}")
>>>> + fi
>>>> + done
>>>> +}
>>>> +
>>>> cleanup_ns()
>>>> {
>>>> local ns=""
>>>> @@ -136,6 +150,8 @@ cleanup_ns()
>>>> if ! busywait $BUSYWAIT_TIMEOUT ip netns list \|
>>>> grep -vq "^$ns$" &> /dev/null; then
>>>> echo "Warn: Failed to remove namespace
>>>> $ns"
>>>> ret=1
>>>> + else
>>>
>>> nit: Should we also remove ns_list when "ip netns list" is busy? Or
>>> should we not delete ns when "ip netns list" is busy?
>>>
>>> I think we should do these two commands together:
>>>
>>> ip netns delete "${ns}" &> /dev/null || true
>>> remove_ns_list "${ns}"
>>>
>>> I'm not sure. WDYT?
>>
>> Good point, I'm not sure either. I kept it in the list because in
>> case
>> of errors, the caller could still get the list of NS that have been
>> created, but not deleted yet.
>>
>> To be honest, I don't think any actions should be done on the NS
>> after
>> having called cleanup: it would probably better to kill all attached
>> processes before that, and not retry later after errors and a kill.
>> But
>> I didn't want to change this logic as there might be other impacts.
>> So
>> at least here, we let the responsibility to the caller, and it can
>> call
>> cleanup_all_ns() again in case of errors. WDYT?
>
> If so, I think this is better:
>
> for ns in "$@"; do
> [ -z "${ns}" ] && continue
> ip netns delete "${ns}" &> /dev/null || true
> remove_ns_list "${ns}"
> if ! busywait $BUSYWAIT_TIMEOUT ip netns list \| grep -
> vq "^$ns$" &> /dev/null; then
> echo "Warn: Failed to remove namespace $ns"
> ret=1
> fi
> done
Sorry, I was not clear enough: I wanted to say that I think it is better
to keep "remove_ns_list" in the "else", only to remove the netns from
the list if it has been deleted. By doing that, the caller can call
cleanup_all_ns() again, after having stopped everything.
(That's a detail, I guess the removal should not fail, and if it does,
the caller should adapt the code to make sure the clean doesn't fail.)
> If you agree, please update this when merging it. No need to send a v7.
Thanks! I will wait for your feedback on what is above before applying
this series (even if we can always have squash-to patches later).
Cheers,
Matt
--
Sponsored by the NGI0 Core fund.
next prev parent reply other threads:[~2024-05-28 15:26 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-27 10:58 [PATCH mptcp-next v6 0/9] use helpers in lib.sh and net_helpers.sh Matthieu Baerts (NGI0)
2024-05-27 10:58 ` [PATCH mptcp-next v6 1/9] selftests: net: lib: set 'i' as local Matthieu Baerts (NGI0)
2024-05-27 10:58 ` [PATCH mptcp-next v6 2/9] selftests: net: lib: support errexit with busywait Matthieu Baerts (NGI0)
2024-05-27 10:58 ` [PATCH mptcp-next v6 3/9] selftests: net: lib: avoid error removing empty netns name Matthieu Baerts (NGI0)
2024-05-27 10:58 ` [PATCH mptcp-next v6 4/9] selftests: net: lib: ignore possible error Matthieu Baerts (NGI0)
2024-05-27 10:58 ` [PATCH mptcp-next v6 5/9] selftests: net: lib: remove ns from list after clean-up Matthieu Baerts (NGI0)
2024-05-28 3:47 ` Geliang Tang
2024-05-28 10:38 ` Matthieu Baerts
2024-05-28 13:18 ` Geliang Tang
2024-05-28 15:26 ` Matthieu Baerts [this message]
2024-05-29 1:31 ` Geliang Tang
2024-05-27 10:58 ` [PATCH mptcp-next v6 6/9] selftests: net: lib: do not set ns var as readonly Matthieu Baerts (NGI0)
2024-05-27 10:58 ` [PATCH mptcp-next v6 7/9] selftests: net: lib: remove 'ns' var in setup_ns Matthieu Baerts (NGI0)
2024-05-27 10:58 ` [PATCH mptcp-next v6 8/9] selftests: mptcp: lib: use setup/cleanup_ns helpers Matthieu Baerts (NGI0)
2024-05-27 10:58 ` [PATCH mptcp-next v6 9/9] selftests: mptcp: lib: use wait_local_port_listen helper Matthieu Baerts (NGI0)
2024-05-27 11:47 ` [PATCH mptcp-next v6 0/9] use helpers in lib.sh and net_helpers.sh MPTCP CI
2024-05-28 13:19 ` Geliang Tang
2024-06-03 16:01 ` Matthieu Baerts
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=be0b8ab8-bff8-4a11-a6bd-fdba6ed36ff5@kernel.org \
--to=matttbe@kernel.org \
--cc=geliang@kernel.org \
--cc=mptcp@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox