Skip to contentSkip to conversation

Test multipath and marginal ports

PATCH In review Jesse Taube 2 participants 4 messages Aug 28 – Oct 14

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v3 cover Test multipath and marginal ports

Tests for the upcoming nvme-fc: FPIN link integrity handling set. It tests for various multipath and marginal port
scenarios, while confirming the port usage and state. The test is intended to emulate receiving an FPIN event in a multipath environment.

In V3 various generic link checking code was move to common/nvme. This is so that it can be used by other tests to check if multipath working correctly, even on kernels that dont support marginal paths.

V1 -> V2:
- Fix timeout issue
- Skip test if /sys/class/fcloop/ctl/set_marginal_rport does not exist
- Wrap lines at 80col
- Add John's tags
- Fix various change requests from mailing list
V2 -> V3:
- Add tests for inaccessable paths
- Fix fio not exiting
- Move generic code to common/nvme

Jesse Taube (2):
nvme: Add _setup_nvmet_port_marginal
nvme/070: Test multipath and marginal ports

 common/nvme        | 278 +++++++++++++++++++++++++++
 tests/nvme/070     | 454 +++++++++++++++++++++++++++++++++++++++++++++
 tests/nvme/070.out |  49 +++++
 3 files changed, 781 insertions(+)
 create mode 100755 tests/nvme/070
 create mode 100644 tests/nvme/070.out
Signature · 1 line
2.54.0
#1 lore raw

PATCH v3 1/2 nvme: Add _setup_nvmet_port_marginal

Adds functionality to set up a NVME port in marginal state. This is useful for testing the behavior of the NVME driver when a port is in a marginal state.

---
V1 -> V2:
- Added john's review and test-by tags
- Use != instead of ! ==
- Wrap lines over 80col
V2 -> V3:
- No change

---
 common/nvme | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
common/nvme +31 -0
index f399937..a6d6b28 100644
@@ -153,6 +153,16 @@ _nvme_fcloop_add_tport() {
 	echo "wwnn=${wwnn},wwpn=${wwpn}" > ${loopctl}/add_target_port
 }
 
+_nvme_fcloop_set_rport_marginal() {
+	local wwnn="$1"
+	local wwpn="$2"
+	local marginal="$3"
+	local loopctl=/sys/class/fcloop/ctl
+
+	echo "wwnn=${wwnn},wwpn=${wwpn},marginal=${marginal}" \
+	     > ${loopctl}/set_marginal_rport
+}
+
 _nvme_fcloop_del_rport() {
 	local local_wwnn="$1"
 	local local_wwpn="$2"
@@ -763,6 +773,27 @@ _create_nvmet_port() {
 	echo "${port}"
 }
 
+_setup_nvmet_port_marginal() {
+	local -i port="$1"
+	local state="${2}"
+
+	if [[ "${nvme_trtype}" != "fc" ]]; then
+		echo "FAIL _setup_nvmet_port_marginal() only supports fc transport"
+		exit 1
+	fi
+
+	if [[ "${state}" == "live" ]]; then
+		_nvme_fcloop_set_rport_marginal "$(_remote_wwnn $port)" \
+					"$(_remote_wwpn $port)" 0
+	elif [[ "${state}" == "marginal" ]]; then
+		_nvme_fcloop_set_rport_marginal "$(_remote_wwnn $port)" \
+					"$(_remote_wwpn $port)" 1
+	else
+		echo "FAIL _setup_nvmet_port_marginal() invalid state: ${state}"
+		exit 1
+	fi
+}
+
 _setup_nvmet_port_ana() {
 	local port="$1"
 	local anagrpid="${2:-$def_anagrpid}"
Signature · 1 line
2.54.0
#2 lore raw

PATCH v3 2/2 nvme/070: Test multipath and marginal ports

In reply to Jesse Taube

Add tests/nvme/070 to test various multipath and marginal port scenarios, while confirming the port useage and state. This test is intended to emulate receiving an FPIN event in a multipath environment.

---
V1 -> V2:
- Add John's tags
- Add _rport_check_use_opt
- Add _rport_is_not_in_use to allow for checking with a timeout
- Add _rport_num_in_use - Wrap lines over 80col
- Add timeout functionality to _rport_is_marginal, is_online,

     in_use.

- Fix path state setup to have one optimized and one non-optimized port for each host
- Fix test_set_all_marginal to correctly check non-numa iopolicy
- Remove _rport_check_opt as it was redundant
- Rename _rport_optimized to _rport_is_optimized
- Skip test if /sys/class/fcloop/ctl/set_marginal_rport does not exist
- Use grep --quiet instead of grep -q
- Use local -a for arrays
V2 -> V3:
- Add tests for inaccessable paths
- Fix fio not exiting
- Move generic code to common/nvme

---
 common/nvme        | 247 ++++++++++++++++++++++++
 tests/nvme/070     | 454 +++++++++++++++++++++++++++++++++++++++++++++
 tests/nvme/070.out |  49 +++++
 3 files changed, 750 insertions(+)
 create mode 100755 tests/nvme/070
 create mode 100644 tests/nvme/070.out
common/nvme +247 -0
index a6d6b28..da1124a 100644
@@ -16,6 +16,7 @@ def_local_wwnn="0x10001100aa000001"
 def_local_wwpn="0x20001100aa000001"
 def_hostid="0f01fb42-9f7f-4856-b0b3-51e60b8de349"
 def_hostnqn="nqn.2014-08.org.nvmexpress:uuid:${def_hostid}"
+export def_check_timeout=10
 export def_subsysnqn="blktests-subsystem-1"
 export def_subsys_uuid="91fdba0d-f87b-4c25-b80f-db7be1418b9e"
 export def_nsid="1"
@@ -209,6 +210,252 @@ _cleanup_blkdev() {
 	rm -f "$(_nvme_def_file_path)"
 }
 
+_subsys_rport_addr() {
+	local RPORT=$1 # /sys/devices/virtual/nvme-subsystem/nvme-subsys3/nvme9
+
+	cat "$RPORT"/address
+	# traddr=nn-0x2047d039ea98949e:pn-0x2048d039ea98949e,host_traddr=nn-0x200000109b9b7e4e:pn-0x100000109b9b7e4e
+}
+
+_subsys_get_port() {
+	local RPORT=$1 # /sys/devices/virtual/nvme-subsystem/nvme-subsys3/nvme9
+	local port
+	local address
+
+	address=$(_subsys_rport_addr "$RPORT")
+	port=$(echo "$address" | sed -n 's/.*pn-\(.*\),.*/\1/p')
+	echo $(( port - $(_remote_wwpn 0) ))
+	# a number representing the port number, e.g. 0, 1, 2, 3
+}
+
+_rport_set_iopolicy() {
+	local RPORT=$1 # /sys/devices/virtual/nvme-subsystem/nvme-subsys3/nvme9
+	local POLICY=$2 # numa queue-depth round-robin
+
+	echo "$POLICY" | sudo tee "$RPORT"/iopolicy > /dev/null
+	# Returns none
+}
+
+_rport_set_marginal() {
+	local RPORT=$1 # /sys/devices/virtual/nvme-subsystem/nvme-subsys3/nvme9
+
+	_setup_nvmet_port_marginal "$(_subsys_get_port "$RPORT")" "marginal"
+}
+
+_rport_set_online() {
+	local RPORT=$1 # /sys/devices/virtual/nvme-subsystem/nvme-subsys3/nvme9
+
+	_setup_nvmet_port_marginal "$(_subsys_get_port "$RPORT")" "live"
+}
+
+_rport_is_online_raw() {
+	local RPORT=$1 # /sys/devices/virtual/nvme-subsystem/nvme-subsys3/nvme9
+
+	[[ "$(cat "$RPORT"/state)" == "live" ]]
+	# Returns Success or Fail
+}
+
+_rport_is_marginal_raw() {
+	local RPORT=$1 # /sys/devices/virtual/nvme-subsystem/nvme-subsys3/nvme9
+
+	[[ "$(cat "$RPORT"/state)" == "marginal" ]]
+	# Returns Success or Fail
+}
+
+_rport_in_use_raw() {
+	local SUBSYS_PATH=$1 # /sys/devices/virtual/nvme-subsystem/nvme-subsys3/nvme9
+
+	# there should only be one "nvme3c9n1"
+	[[ "$(cat "$SUBSYS_PATH"/nvme*/stat | awk '{print $9}')" != "0" ]]
+	# Returns exit code 0 if in use, 1 if not in use
+}
+
+_rport_is_optimized() {
+	local SUBSYS_PATH=$1 # /sys/devices/virtual/nvme-subsystem/nvme-subsys3/nvme9
+
+	# there should only be one "nvme3c9n1"
+	[[ "$(cat "$SUBSYS_PATH"/nvme*/ana_state)" == "optimized" ]]
+	# Returns exit code 0 if optimized, 1 if not optimized
+}
+
+_rport_is_non_optimized() {
+	local SUBSYS_PATH=$1 # /sys/devices/virtual/nvme-subsystem/nvme-subsys3/nvme9
+
+	# there should only be one "nvme3c9n1"
+	[[ "$(cat "$SUBSYS_PATH"/nvme*/ana_state)" == "non-optimized" ]]
+	# Returns exit code 0 if non-optimized, 1 if not non-optimized
+}
+
+_rport_is_inaccessible() {
+	local SUBSYS_PATH=$1 # /sys/devices/virtual/nvme-subsystem/nvme-subsys3/nvme9
+
+	# there should only be one "nvme3c9n1"
+	[[ "$(cat "$SUBSYS_PATH"/nvme*/ana_state)" == "inaccessible" ]]
+	# Returns exit code 0 if inaccessible, 1 if not inaccessible
+}
+
+_rport_is_online() {
+	local RPORT=$1 # /sys/devices/virtual/nvme-subsystem/nvme-subsys3/nvme9
+	local -i TIMEOUT="${2:-$def_check_timeout}"
+	local -i time_passed=0
+
+	for (( time_passed=0; time_passed < TIMEOUT; time_passed++ )); do
+		_rport_is_online_raw "$RPORT" && return 0 || true
+		sleep 1
+	done
+	return 1
+	# Returns Success or Fail
+}
+
+_rport_is_marginal() {
+	local RPORT=$1 # /sys/devices/virtual/nvme-subsystem/nvme-subsys3/nvme9
+	local -i TIMEOUT="${2:-$def_check_timeout}"
+	local -i time_passed=0
+
+	for (( time_passed=0; time_passed < TIMEOUT; time_passed++ )); do
+		_rport_is_marginal_raw "$RPORT" && return 0 || true
+		sleep 1
+	done
+	return 1
+	# Returns Success or Fail
+}
+
+_rport_in_use() {
+	local RPORT=$1 # /sys/devices/virtual/nvme-subsystem/nvme-subsys3/nvme9
+	local -i TIMEOUT="${2:-$def_check_timeout}"
+	local -i time_passed=0
+
+	for (( time_passed=0; time_passed < TIMEOUT; time_passed++ )); do
+		_rport_in_use_raw "$RPORT" && return 0 || true
+		sleep 1
+	done
+	return 1
+	# Returns exit code 0 if in use, 1 if not in use
+}
+
+_rport_not_in_use() {
+	local RPORT=$1 # /sys/devices/virtual/nvme-subsystem/nvme-subsys3/nvme9
+	local -i TIMEOUT="${2:-$def_check_timeout}"
+	local -i time_passed=0
+
+	for (( time_passed=0; time_passed < TIMEOUT; time_passed++ )); do
+		_rport_in_use_raw "$RPORT" || return 0
+		sleep 1
+	done
+	return 1
+	# Returns exit code 0 if in not use, 1 if in use
+}
+
+_rport_num_in_use() {
+	local -a RPORTS_PATHS=("$@") # /sys/devices/virtual/nvme-subsystem/nvme-subsys3/nvme9
+	local -i num_in_use=0
+
+	# Check if one of the marginal paths is in use
+	for subsys_path in "${RPORTS_PATHS[@]}"; do
+		_rport_in_use_raw "$subsys_path" || continue
+		num_in_use=$((num_in_use + 1))
+	done
+
+	echo "$num_in_use"
+	# Returns number of links in use
+}
+
+# check if link is marginal or not
+_rport_check_online() {
+	local RPORT=$1 # /sys/devices/virtual/nvme-subsystem/nvme-subsys3/nvme9
+	local STATE=$2 # "Online"
+	local -i TIMEOUT="${3:-$def_check_timeout}"
+
+	if [[ "$STATE" == "Online" ]]; then
+		if ! _rport_is_online "$RPORT" "$TIMEOUT"; then
+			echo  FC port \("$RPORT"\) is not online, expteced online.
+			return 1
+		fi
+	else
+		if ! _rport_is_marginal "$RPORT" "$TIMEOUT"; then
+			echo FC port \("$RPORT"\) is not marginal, expteced marginal.
+			return 1
+		fi
+	fi
+	# Returns Success or Fail
+}
+
+# check if link is in use
+_rport_check_use() {
+	local RPORT=$1 # /sys/devices/virtual/nvme-subsystem/nvme-subsys3/nvme9
+	local STATE=$2 # "Online"
+	local -i TIMEOUT="${3:-$def_check_timeout}"
+
+	if [[ "$STATE" == "Online" ]]; then
+		if ! _rport_in_use "$RPORT" "$TIMEOUT"; then
+			echo FC port on \("$RPORT"\) is not being used, expected use.
+			return 1
+		fi
+	else
+		if ! _rport_not_in_use "$RPORT" "$TIMEOUT"; then
+			echo FC port on \("$RPORT"\) is being used, expected no use.
+			return 1
+		fi
+	fi
+	# Returns Success or Fail
+}
+
+# check if all links are in the expected use state based on ana state
+_rport_check_use_opt() {
+	local RPORT=$1 # /sys/devices/virtual/nvme-subsystem/nvme-subsys3/nvme9
+	local -i TIMEOUT="${2:-$def_check_timeout}"
+
+	# Only optimized paths will be in use
+	if _rport_is_optimized "$RPORT"; then
+		_rport_check_use "$RPORT" Online "$TIMEOUT" || return 1
+	else
+		_rport_check_use "$RPORT" Marginal "$TIMEOUT" || return 1
+	fi
+	# Returns Success or Fail
+}
+
+# check if all links are in state and use state
+_rport_check() {
+	local RPORT=$1 # /sys/devices/virtual/nvme-subsystem/nvme-subsys3/nvme9
+	local STATE=$2 # "Online"
+	local -i TIMEOUT="${3:-$def_check_timeout}"
+
+	_rport_check_online "$RPORT" "$STATE" "$TIMEOUT" || return 1
+	_rport_check_use "$RPORT" "$STATE" "$TIMEOUT"
+	# Returns Success or Fail
+}
+
+# Check if one of the paths is in use
+_rport_check_one_use() {
+	local STATE=$1
+	local -i TIMEOUT=$2
+	shift
+	shift
+	local -a RPORTS_PATHS=("$@") #  /sys/devices/virtual/nvme-subsystem/nvme-subsys3/nvme9
+	local -i time_passed=0
+	local -i count_in_use=0
+
+	for (( time_passed=0; time_passed < TIMEOUT; time_passed++ )); do
+		# Check if one of the online paths is in use
+		count_in_use=$(_rport_num_in_use "${RPORTS_PATHS[@]}")
+		if [ $count_in_use -eq 1 ]; then
+			return 0
+		fi
+		sleep 1
+	done
+
+	if [ $count_in_use -gt 1 ]; then
+		echo More than one FC port is being used, expected only one in use when all are "$STATE" in numa mode.
+		return 1
+	fi
+
+	echo No FC ports are being used, expected atleast one in use when all are "$STATE" in numa mode.
+	# None of the online paths were in use
+	return 1
+
+	# Returns Success or Fail
+}
+
 _cleanup_nvmet() {
 	local dev
 	local port
tests/nvme/070 new file +454 -0

454 lines not on this page · raw message

tests/nvme/070.out new file +49 -0

49 lines not on this page · raw message

Signature · 1 line
2.54.0
#3 lore raw
In reply to Jesse Taube
Quoted 8 lines · Jesse Taube

Tests for the upcoming nvme-fc: FPIN link integrity handling set. It tests for various multipath and marginal port
scenarios, while confirming the port usage and state. The test is intended to emulate receiving an FPIN event in a multipath environment.

In V3 various generic link checking code was move to common/nvme. This is so that it can be used by other tests to check if multipath working correctly, even on kernels that dont support marginal paths.

Thanks for the v3 patch. I applied it. Please note that I renumbered the test case from 070 to 071.