Commit 9b36eebf authored by Michal Berger's avatar Michal Berger Committed by Tomasz Zawadzki
Browse files

test/nvmf: Paranoid handling of net ns deletion



It's been noticed that the backoff of 1s may be not enough for the
net devices to pop up back under the main namespace. Scenario like
this may look similar to:

[2023-11-24T13:25:56.234Z]  14:25:56	-- nvmf/common.sh@398 -- # remove_spdk_ns
...
[2023-11-24T13:26:02.498Z] Found 0000:af:00.0 (0x8086 - 0x159b)
...
[2023-11-24T13:26:02.498Z] Found 0000:af:00.1 (0x8086 - 0x159b)
...
[2023-11-24T13:26:02.498Z] No net devices associated with 0000:af:00.0
...
[2023-11-24T13:26:02.498Z] Found net devices under 0000:af:00.1: eth3
...
[2023-11-24T13:26:02.498Z] ========== Backtrace start: ==========
[2023-11-24T13:26:02.498Z]    230 		# We need two net devs at minimum
[2023-11-24T13:26:02.498Z] => 231 ((${#TCP_INTERFACE_LIST[@]} > 1))
...

After closer inspection the 0000:af:00.0's eth* device normally would
be picked up as $NVMF_TARGET_INTERFACE but since it's still under the
eth*_ns_spdk namespace (from the previous test) it cannot be found
under the main namespace.

To mitigate, wait until all net devices are visible under main
namespace's sysfs.

Change-Id: If190abb6a98b42321bef945979ed1bacbafcf2ce
Signed-off-by: default avatarMichal Berger <michal.berger@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/20737


Reviewed-by: default avatarKarol Latecki <karol.latecki@intel.com>
Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
parent 45fa5534
Loading
Loading
Loading
Loading
+32 −4
Original line number Diff line number Diff line
@@ -576,14 +576,42 @@ function gen_nvmf_target_json() {
	JSON
}

function remove_spdk_ns() {
	local ns
function _remove_spdk_ns() {
	local ns {ns,mn,an}_net_devs
	while read -r ns _; do
		[[ $ns == *_spdk ]] || continue
		# Gather all devs from the target $ns namespace. We want to differentiate
		# between veth and physical links and gather just the latter. To do so,
		# we simply compare ifindex to iflink - as per kernel docs, these should
		# be always equal for the physical links. For veth devices, since they are
		# paired, iflink should point at an actual bridge, hence being different
		# from its own ifindex.
		ns_net_devs=($(
			ip netns exec "$ns" bash <<- 'IN_NS'
				shopt -s extglob
				for dev in /sys/class/net/!(lo|bond*); do
					(($(< "$dev/ifindex") == $(< "$dev/iflink"))) || continue
					echo "${dev##*/}"
				done
			IN_NS
		))
		# Gather all the net devs from the main ns
		mn_net_devs=($(basename -a /sys/class/net/!(lo|bond*)))
		# Merge these two to have a list for comparison
		an_net_devs=($(printf '%s\n' "${ns_net_devs[@]}" "${mn_net_devs[@]}" | sort))

		ip netns delete "$ns"

		# Check if our list matches against the main ns after $ns got deleted
		while [[ ${an_net_devs[*]} != "${mn_net_devs[*]}" ]]; do
			mn_net_devs=($(basename -a /sys/class/net/!(lo|bond*)))
			sleep 1s
		done
	done < <(ip netns list)
	# Let it settle
	sleep 1
}

remove_spdk_ns() {
	xtrace_disable_per_cmd _remove_spdk_ns
}

configure_kernel_target() {