[PATCH blktests 7/7] test/nvme: add test for rapid namespace remapping

Shin'ichiro Kawasaki shinichiro.kawasaki at wdc.com
Fri Nov 29 05:26:17 PST 2024


From: Hannes Reinecke <hare at suse.de>

Add a test for rapid namespace remapping to simulate short-lived
namespaces being created and deleted in rapid succession with a
cluster.

Signed-off-by: Hannes Reinecke <hare at suse.de>
[Shin'ichiro: renumbered the test case from 055 to 056]
[Shin'ichiro: use for loop instead of seq per style guideline]
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki at wdc.com>
---
 tests/nvme/056     | 105 +++++++++++++++++++++++++++++++++++++++++++++
 tests/nvme/056.out |  14 ++++++
 tests/nvme/rc      |  31 +++++++++++++
 3 files changed, 150 insertions(+)
 create mode 100755 tests/nvme/056
 create mode 100644 tests/nvme/056.out

diff --git a/tests/nvme/056 b/tests/nvme/056
new file mode 100755
index 0000000..d230a21
--- /dev/null
+++ b/tests/nvme/056
@@ -0,0 +1,105 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright (C) 2024 Hannes Reinecke (SUSE) <hare at suse.de>
+#
+# Test rapid remapping of namespaces
+
+. tests/nvme/rc
+
+DESCRIPTION="test rapid namespace remapping"
+
+requires() {
+	_nvme_requires
+	_have_loop
+	_require_nvme_trtype_is_fabrics
+}
+
+set_conditions() {
+	_set_nvme_trtype "$@"
+}
+
+_setup_ana() {
+	local portno=0
+
+	for port in "$@"; do
+		if (( portno == 0 )); then
+			_setup_nvmet_port_ana "${port}" 1 "optimized"
+			_setup_nvmet_port_ana "${port}" 2 "inaccessible"
+			_setup_nvmet_port_ana "${port}" 3 "inaccessible"
+		elif (( portno == 1 )); then
+			_setup_nvmet_port_ana "${port}" 1 "non-optimized"
+			_setup_nvmet_port_ana "${port}" 2 "inaccessible"
+			_setup_nvmet_port_ana "${port}" 3 "inaccessible"
+		elif (( portno == 2 )); then
+			_setup_nvmet_port_ana "${port}" 1 "inaccessible"
+			_setup_nvmet_port_ana "${port}" 2 "optimized"
+			_setup_nvmet_port_ana "${port}" 3 "inaccessible"
+		elif (( portno == 3 )); then
+			_setup_nvmet_port_ana "${port}" 1 "inaccessible"
+			_setup_nvmet_port_ana "${port}" 2 "non-optimized"
+			_setup_nvmet_port_ana "${port}" 3 "inaccessible"
+		elif (( portno == 4 )); then
+			_setup_nvmet_port_ana "${port}" 1 "inaccessible"
+			_setup_nvmet_port_ana "${port}" 2 "inaccessible"
+			_setup_nvmet_port_ana "${port}" 3 "optimized"
+		else
+			_setup_nvmet_port_ana "${port}" 1 "inaccessible"
+			_setup_nvmet_port_ana "${port}" 2 "inaccessible"
+			_setup_nvmet_port_ana "${port}" 3 "non-optimized"
+		fi
+		portno=$(( portno + 1 ))
+	done
+}
+
+test() {
+	echo "Running ${TEST_NAME}"
+
+	_setup_nvmet
+
+	local d i n port
+	local -a ports
+	local num_namespaces=3
+
+	_nvmet_target_setup --ports 6 --blkdev none
+
+	for ((d = 1; d <= num_namespaces; d++)); do
+		local file_path
+		local blkdev
+		local uuid
+
+		file_path="${TMPDIR}/img${d}"
+		truncate -s "${NVME_IMG_SIZE}" "${file_path}"
+		blkdev="$(losetup -f --show "${file_path}")"
+		uuid="$(uuidgen)"
+		_create_nvmet_ns --nsid "${d}" --blkdev "${blkdev}" \
+				 --uuid "${uuid}" --grpid "${d}" > /dev/null
+	done
+
+	_get_nvmet_ports "${def_subsysnqn}" ports
+	_setup_ana "${ports[@]}"
+
+	for port in "${ports[@]}"; do
+		_nvme_connect_subsys --port "${port}"
+	done
+
+	# Simulate unmap on one cluster node and remap to anther one
+	for ((i = 0; i <= 10; i++)); do
+		echo "Remap namespace #${i}"
+		grpid=$(( (i % 3) + 1 ))
+		for n in $(seq 1 "${num_namespaces}" | shuf); do
+			_disable_nvmet_ns "${n}"
+		done
+		for n in $(seq 1 "${num_namespaces}" | shuf); do
+			local uuid
+
+			uuid=$(uuidgen)
+			_set_nvmet_ns_uuid "${n}" "${uuid}"
+			_enable_nvmet_ns "${n}"
+		done
+	done
+
+	_nvme_disconnect_subsys
+	_nvmet_target_cleanup
+
+	echo "Test complete"
+}
diff --git a/tests/nvme/056.out b/tests/nvme/056.out
new file mode 100644
index 0000000..cdc3e55
--- /dev/null
+++ b/tests/nvme/056.out
@@ -0,0 +1,14 @@
+Running nvme/056
+Remap namespace #0
+Remap namespace #1
+Remap namespace #2
+Remap namespace #3
+Remap namespace #4
+Remap namespace #5
+Remap namespace #6
+Remap namespace #7
+Remap namespace #8
+Remap namespace #9
+Remap namespace #10
+disconnected 6 controller(s)
+Test complete
diff --git a/tests/nvme/rc b/tests/nvme/rc
index d63afd1..2ddc6bc 100644
--- a/tests/nvme/rc
+++ b/tests/nvme/rc
@@ -307,6 +307,37 @@ _set_nvmet_dhgroup() {
 	     "${cfs_path}/dhchap_dhgroup"
 }
 
+_enable_nvmet_ns() {
+	local subsysnqn="${def_subsysnqn}"
+	local nsid="${1:-1}"
+
+	cfs_path="${NVMET_CFS}/subsystems/${subsysnqn}"
+	ns_path="${cfs_path}/namespaces/${nsid}"
+
+	echo 1 > "${ns_path}/enable"
+}
+
+_disable_nvmet_ns() {
+	local subsysnqn="${def_subsysnqn}"
+	local nsid="${1:-1}"
+
+	cfs_path="${NVMET_CFS}/subsystems/${subsysnqn}"
+	ns_path="${cfs_path}/namespaces/${nsid}"
+
+	echo 0 > "${ns_path}/enable"
+}
+
+_set_nvmet_ns_uuid() {
+	local subsysnqn="${def_subsysnqn}"
+	local nsid="${1:-1}"
+	local uuid="${2:-$(uuidgen)}"
+
+	cfs_path="${NVMET_CFS}/subsystems/${subsysnqn}"
+	ns_path="${cfs_path}/namespaces/${nsid}"
+
+	printf "%s" "${uuid}" > "${ns_path}/device_uuid"
+}
+
 _find_nvme_passthru_loop_dev() {
 	local subsys=$1
 	local nsid
-- 
2.47.0




More information about the Linux-nvme mailing list