From 221f6631e61dcb56fb3d832632d3268d854d8e84 Mon Sep 17 00:00:00 2001 From: Hannes Reinecke Date: Wed, 2 Oct 2024 16:53:12 +0200 Subject: [PATCH] test/nvme: add test for rapid namespace remapping 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 --- common/nvme | 10 ++++ tests/nvme/055 | 115 +++++++++++++++++++++++++++++++++++++++++++++ tests/nvme/055.out | 14 ++++++ 3 files changed, 139 insertions(+) create mode 100644 tests/nvme/055 create mode 100644 tests/nvme/055.out diff --git a/common/nvme b/common/nvme index 7fc3f08f..a67eb25e 100644 --- a/common/nvme +++ b/common/nvme @@ -555,6 +555,16 @@ _create_nvmet_ns() { echo "${uuid}" } +_get_nvmet_ns_blkdev() { + local nvmet_subsystem="$1" + local nsid="$2" + local subsys_path="${NVMET_CFS}/subsystems/${nvmet_subsystem}" + local ns_path="${subsys_path}/namespaces/${nsid}" + + blkdev=$(cat "${ns_path}/device_path") + echo "${blkdev}" +} + _setup_nvmet_ns_ana() { local nvmet_subsystem="$1" local nsid="$2" diff --git a/tests/nvme/055 b/tests/nvme/055 new file mode 100644 index 00000000..bcf94b9f --- /dev/null +++ b/tests/nvme/055 @@ -0,0 +1,115 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-3.0+ +# Copyright (C) 2024 Hannes Reinecke (SUSE) +# +# Test rapid remapping of namespaces + +. tests/nvme/rc + +DESCRIPTION="test rapid namespace remapping" + +requires() { + _nvme_requires + _have_loop + _have_fio + _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 +} + +_remap_ns() { + local subsysnqn="${def_subsysnqn}" + local grpid="$1" + local nsid="${2:-1}" + local new_uuid + local blkdev + + blkdev=$(_get_nvmet_ns_blkdev "${subsysnqn}" "${nsid}") + _remove_nvmet_ns "${subsysnqn}" "${nsid}" + new_uuid="$(uuidgen)" + _create_nvmet_ns --subsysnqn "${subsysnqn}" --nsid "${nsid}" \ + --blkdev "${blkdev}" --uuid "${new_uuid}" \ + --grpid "${grpid}" > /dev/null +} + +test() { + echo "Running ${TEST_NAME}" + + _setup_nvmet + + local d + local i + local -a ports + local port + + _nvmet_target_setup --ports 6 --blkdev none + + for d in $(seq 1 3); 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 + + read -ra ports < <(_get_nvmet_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 in $(seq 0 10); do + echo "Remap namespace #${i}" + grpid=$(( (i % 3) + 1 )) + for n in $(seq 1 3 | shuf); do + _remap_ns "${grpid}" "${n}" + done + done + + _nvme_disconnect_subsys + _nvmet_target_cleanup + + echo "Test complete" +} diff --git a/tests/nvme/055.out b/tests/nvme/055.out new file mode 100644 index 00000000..c580c830 --- /dev/null +++ b/tests/nvme/055.out @@ -0,0 +1,14 @@ +Running nvme/055 +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