From: Geliang Tang <geliang@kernel.org>
To: "Matthieu Baerts (NGI0)" <matttbe@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 11:47:51 +0800 [thread overview]
Message-ID: <312d5bb28672c8bd0eff47fcaf1ea7707bec8d60.camel@kernel.org> (raw)
In-Reply-To: <20240527-selftests-net-lib-fixes-v6-5-72411ff2460e@kernel.org>
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?
Thanks,
-Geliang
> + remove_ns_list "${ns}"
> fi
> done
>
> @@ -154,17 +170,14 @@ setup_ns()
> local ns=""
> local ns_name=""
> local ns_list=()
> - local ns_exist=
> for ns_name in "$@"; do
> # Some test may setup/remove same netns multi times
> if unset ${ns_name} 2> /dev/null; then
> ns="${ns_name,,}-$(mktemp -u XXXXXX)"
> eval readonly ${ns_name}="$ns"
> - ns_exist=false
> else
> eval ns='$'${ns_name}
> cleanup_ns "$ns"
> - ns_exist=true
> fi
>
> if ! ip netns add "$ns"; then
> @@ -173,7 +186,7 @@ setup_ns()
> return $ksft_skip
> fi
> ip -n "$ns" link set lo up
> - ! $ns_exist && ns_list+=("$ns")
> + ns_list+=("$ns")
> done
> NS_LIST+=("${ns_list[@]}")
> }
>
next prev parent reply other threads:[~2024-05-28 3:47 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 [this message]
2024-05-28 10:38 ` Matthieu Baerts
2024-05-28 13:18 ` Geliang Tang
2024-05-28 15:26 ` Matthieu Baerts
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=312d5bb28672c8bd0eff47fcaf1ea7707bec8d60.camel@kernel.org \
--to=geliang@kernel.org \
--cc=matttbe@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.