[PATCH blktests 2/7] nvme: add _setup_nvmet_port_ana()

Shin'ichiro Kawasaki
2024-11-29T13:26:29Z

From: Hannes Reinecke <hare@suse.de>

Add a function to set the ANA state and group id for a port.

Signed-off-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
---
common/nvme | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)

diff --git a/common/nvme b/common/nvme
index fd472fe..e11776b 100644
--- a/common/nvme
+++ b/common/nvme
@@ -8,6 +8,8 @@
def_traddr="127.0.0.1"
def_adrfam="ipv4"
def_trsvcid="4420"
+def_anagrpid="1"
+def_anastate="optimized"
def_remote_wwnn="0x10001100ab000001"
def_remote_wwpn="0x20001100ab000001"
def_local_wwnn="0x10001100aa000001"
@@ -470,6 +472,23 @@ _create_nvmet_port() {
echo "${port}"
}

+_setup_nvmet_port_ana() {
+ local port="$1"
+ local anagrpid="${2:-$def_anagrpid}"
+ local anastate="${3:-$def_anastate}"
+ local cfsport="${NVMET_CFS}/ports/${port}"
+ local anaport="${cfsport}/ana_groups/${anagrpid}"
+
+ if [[ ! -d "${anaport}" ]] ; then
+ if [[ "${anagrpid}" -eq 1 ]]; then
+ echo "FAIL target setup failed, ANA not supported"
+ exit 1
+ fi
+ mkdir "${anaport}"
+ fi
+ echo "${anastate}" > "${anaport}/ana_state"
+}
+
_remove_nvmet_port() {
local port="$1"

--
2.47.0