Skip to contentSkip to conversation

Add support to run against real target

RFC Superseded Daniel Wagner 2 participants 8 messages Jun 12, 2024 – Jun 14, 2024

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Add support to run against real target

I've updated this series and added a simple example how to use it. I didn't really know where to put it, so I added this part to new directorty called 'contrib'.

Don't know if we want to keep adding environment variables for this or if it would be simpler to pass in a configuration file. The environemnt variable are fairly simple to handle and it works. Adding a configuraiton file adds more code to blktests.

changes:
v2:
- many of the preperation patches have been merged, drop them
- added a python script which implements the blktests API
- add some documentation how to use it
- changed the casing of the environment variables to upper case

v1:
- initial version
- https://lore.kernel.org/linux-nvme/[email protected]/

Daniel Wagner (3):
nvme/rc: introduce remote target support
nvme/030: only run against kernel soft target
contrib: add remote target setup/cleanup script

 Documentation/running-tests.md |   9 +++
 contrib/nvme_target_control.py | 110 +++++++++++++++++++++++++++++++++
 contrib/nvmet-subsys.jinja2    |  71 +++++++++++++++++++++
 tests/nvme/030                 |   1 +
 tests/nvme/rc                  |  56 +++++++++++++++--
 5 files changed, 243 insertions(+), 4 deletions(-)
 create mode 100755 contrib/nvme_target_control.py
 create mode 100644 contrib/nvmet-subsys.jinja2
Signature · 1 line
2.45.2
#1 lore raw

RFC v2 1/3 nvme/rc: introduce remote target support

Most of the NVMEeoF tests are exercising the host code of the nvme subsystem. There is no real reason not to run these against a real target. We just have to skip the soft target setup and make it possible to setup a remote target.

Because all tests use now the common setup/cleanup helpers we just need to intercept this call and forward it to an external component.

As we already have various nvme variables to setup the target which we should allow to overwrite. Also introduce a NVME_TARGET_CONTROL variable which points to a script which gets executed whenever a targets needs to be created/destroyed.

---
 Documentation/running-tests.md |  9 +++++++
 tests/nvme/rc                  | 48 +++++++++++++++++++++++++++++++---
 2 files changed, 53 insertions(+), 4 deletions(-)
Documentation/running-tests.md +9 -0
index 968702e76bb5..99dedaebfab0 100644
@@ -120,6 +120,15 @@ The NVMe tests can be additionally parameterized via environment variables.
 - NVME_NUM_ITER: 1000 (default)
   The number of iterations a test should do. This parameter had an old name
   'nvme_num_iter'. The old name is still usable, but not recommended.
+- NVME_TRADDR: transport address. Overwrites the default
+  transport address. See also NVME_TARGET_CONTROL.
+- NVME_HOST_TRADDR: host address. Overwrites the default
+  host address. See also NVME_TARGET_CONTROL.
+- NVME_TRSVID: transport service id. Overwrite the default
+  transport service ide. See also NVME_TARGET_CONTROL.
+- NVME_TARGET_CONTROL: When defined, the generic target setup/cleanup code will
+  be skipped and this script gets called. This makes it possible to run
+  the fabric nvme tests against a real target.
 
 ### Running nvme-rdma and SRP tests
 
tests/nvme/rc +44 -4

105 lines not on this page · raw message

Signature · 1 line
2.45.2
#2 lore raw

Re: [RFC blktests v2 1/3] nvme/rc: introduce remote target support

Quoted 26 lines · Daniel Wagner

Most of the NVMEeoF tests are exercising the host code of the nvme subsystem. There is no real reason not to run these against a real target. We just have to skip the soft target setup and make it possible to setup a remote target.

Because all tests use now the common setup/cleanup helpers we just need to intercept this call and forward it to an external component.

As we already have various nvme variables to setup the target which we should allow to overwrite. Also introduce a NVME_TARGET_CONTROL variable which points to a script which gets executed whenever a targets needs to be created/destroyed.

---
 Documentation/running-tests.md |  9 +++++++
 tests/nvme/rc                  | 48 +++++++++++++++++++++++++++++++---
 2 files changed, 53 insertions(+), 4 deletions(-)
Documentation/running-tests.md +0 -0
index 968702e76bb5..99dedaebfab0 100644
@@ -120,6 +120,15 @@ The NVMe tests can be additionally parameterized via environment variables.
 - NVME_NUM_ITER: 1000 (default)
   The number of iterations a test should do. This parameter had an old name

Documentation/running-tests.md The NVMe tests can be additionally parameterized via environment variables. · line 131

Quoted 10 lines
Documentation/running-tests.md +9 -0
   'nvme_num_iter'. The old name is still usable, but not recommended.
+- NVME_TRADDR: transport address. Overwrites the default
+  transport address. See also NVME_TARGET_CONTROL.
+- NVME_HOST_TRADDR: host address. Overwrites the default
+  host address. See also NVME_TARGET_CONTROL.
+- NVME_TRSVID: transport service id. Overwrite the default
+  transport service ide. See also NVME_TARGET_CONTROL.
+- NVME_TARGET_CONTROL: When defined, the generic target setup/cleanup code will
+  be skipped and this script gets called. This makes it possible to run
+  the fabric nvme tests against a real target.

It might be helpful to add the lines below:

Refer _nvmet_target_setup() and _nvmet_target_cleanup() for the options provided to NVME_TARGET_CONTROL.

Quoted 90 lines
Documentation/running-tests.md +0 -0
 ### Running nvme-rdma and SRP tests
 
tests/nvme/rc +24 -4
index c1ddf412033b..aaa64453fe16 100644
@@ -7,9 +7,10 @@
 . common/rc
 . common/multipath-over-rdma
 
-def_traddr="127.0.0.1"
+def_traddr="${NVME_TRADDR:-127.0.0.1}"
+def_host_traddr="${NVME_HOST_TRADDDR:-}"
 def_adrfam="ipv4"
-def_trsvcid="4420"
+def_trsvcid="${NVME_TRSVID:-4420}"
 def_remote_wwnn="0x10001100aa000001"
 def_remote_wwpn="0x20001100aa000001"
 def_local_wwnn="0x10001100aa000002"
@@ -23,6 +24,7 @@ _check_conflict_and_set_default NVME_IMG_SIZE nvme_img_size 1G
 _check_conflict_and_set_default NVME_NUM_ITER nvme_num_iter 1000
 nvmet_blkdev_type=${nvmet_blkdev_type:-"device"}
 NVMET_BLKDEV_TYPES=${NVMET_BLKDEV_TYPES:-"device file"}
+nvme_target_control="${NVME_TARGET_CONTROL:-}"
 
 _NVMET_TRTYPES_is_valid() {
 	local type
@@ -359,6 +361,10 @@ _cleanup_nvmet() {
 		fi
 	done
 
+	if [[ -n "${nvme_target_control}" ]]; then
+		return
+	fi
+
 	for port in "${NVMET_CFS}"/ports/*; do
 		name=$(basename "${port}")
 		echo "WARNING: Test did not clean up port: ${name}"
@@ -403,11 +409,19 @@ _cleanup_nvmet() {
 
 _setup_nvmet() {
 	_register_test_cleanup _cleanup_nvmet
+
+	if [[ -n "${nvme_target_control}" ]]; then
+		return
+	fi
+
 	modprobe -q nvmet
+
 	if [[ "${nvme_trtype}" != "loop" ]]; then
 		modprobe -q nvmet-"${nvme_trtype}"
 	fi
+
 	modprobe -q nvme-"${nvme_trtype}"
+
 	if [[ "${nvme_trtype}" == "rdma" ]]; then
 		start_soft_rdma
 		for i in $(rdma_network_interfaces)
@@ -425,6 +439,7 @@ _setup_nvmet() {
 			fi
 		done
 	fi
+
 	if [[ "${nvme_trtype}" = "fc" ]]; then
 		modprobe -q nvme-fcloop
 		_setup_fcloop "${def_local_wwnn}" "${def_local_wwpn}" \
@@ -873,11 +888,13 @@ _find_nvme_passthru_loop_dev() {
 
 _nvmet_target_setup() {
 	local blkdev_type="${nvmet_blkdev_type}"
+	local subsys_uuid="${def_subsys_uuid}"
+	local subsysnqn="${def_subsysnqn}"
 	local blkdev
+	local ARGS=()
 	local ctrlkey=""
 	local hostkey=""
-	local subsysnqn="${def_subsysnqn}"
-	local subsys_uuid="${def_subsys_uuid}"
+	local blkdev
 	local port
 
 	while [[ $# -gt 0 ]]; do
@@ -909,6 +926,22 @@ _nvmet_target_setup() {
 		esac
 	done
 
+	if [[ -n "${hostkey}" ]]; then
+		ARGS+=(--hostkey "${hostkey}")
+	fi

tests/nvme/rc _nvmet_target_setup() { · line 941

Quoted 10 lines
tests/nvme/rc +10 -0
+	if [[ -n "${ctrlkey}" ]]; then
+		ARGS+=(--ctrkey "${ctrlkey}")
+	fi
+
+	if [[ -n "${nvme_target_control}" ]]; then
+		eval "${nvme_target_control}" setup \
+			--subsysnqn "${subsysnqn}" \
+			--subsys-uuid "${subsys_uuid}" \
+			--hostnqn "${def_hostnqn}" \
+			"${ARGS[@]}" > /dev/null 2>&1

Nit: the line above can be a bit simpler: "${ARGS[@]}" &> /dev/null

Quoted 23 lines
tests/nvme/rc +10 -0
+		return
+	fi
+
 	truncate -s "${NVME_IMG_SIZE}" "$(_nvme_def_file_path)"
 	if [[ "${blkdev_type}" == "device" ]]; then
 		blkdev="$(losetup -f --show "$(_nvme_def_file_path)")"
@@ -948,6 +981,13 @@ _nvmet_target_cleanup() {
 		esac
 	done
 
+	if [[ -n "${nvme_target_control}" ]]; then
+		eval "${nvme_target_control}" cleanup \
+			--subsysnqn "${subsysnqn}" \
+			> /dev/null
+		return
+	fi
+
 	_get_nvmet_ports "${subsysnqn}" ports
 
 	for port in "${ports[@]}"; do
Signature · 1 line
2.45.2
#3 lore raw

RFC v2 2/3 nvme/030: only run against kernel soft target

In reply to Daniel Wagner

This tests is exercising the target code and not so much the host side. The problem with nvme/030 is that it depends on interface to interact with the target which is not covered by the standard. Thus we can't run it against a real target. Just skip it when we run against a real target.

---
 tests/nvme/030 | 1 +
 tests/nvme/rc  | 8 ++++++++
 2 files changed, 9 insertions(+)
tests/nvme/030 +1 -0
index b1ed8bc20908..672487734332 100755
@@ -13,6 +13,7 @@ requires() {
 	_nvme_requires
 	_have_loop
 	_require_nvme_trtype_is_fabrics
+	_require_kernel_target
 }
 
 set_conditions() {
tests/nvme/rc +8 -0
index aaa64453fe16..4a2d107bd532 100644
@@ -219,6 +219,14 @@ _require_kernel_nvme_fabrics_feature() {
 	return 0
 }
 
+_require_kernel_target() {
+	if [[ -n "${nvme_target_control}" ]]; then
+		SKIP_REASONS+=("Linux kernel soft target not available")
+		return 1;
+	fi
+	return 0
+}
+
 _test_dev_nvme_ctrl() {
 	echo "/dev/char/$(cat "${TEST_DEV_SYSFS}/device/dev")"
 }
Signature · 1 line
2.45.2
#4 lore raw

Re: [RFC blktests v2 2/3] nvme/030: only run against kernel soft target

Quoted 1 line · Daniel Wagner

This tests is exercising the target code and not so much the host side.

s/tests/test/

Quoted 16 lines

The problem with nvme/030 is that it depends on interface to interact with the target which is not covered by the standard. Thus we can't run it against a real target. Just skip it when we run against a real target.

---
 tests/nvme/030 | 1 +
 tests/nvme/rc  | 8 ++++++++
 2 files changed, 9 insertions(+)
tests/nvme/030 +0 -0
index b1ed8bc20908..672487734332 100755

tests/nvme/030 requires() { · line 16

Quoted 4 lines
tests/nvme/030 +1 -0
@@ -13,6 +13,7 @@ requires() {
 	_nvme_requires
 	_have_loop
 	_require_nvme_trtype_is_fabrics
+	_require_kernel_target

The function name sounds generic too much for me. How about _require_kernel_nvme_target? (The current name reminds me SCSI target).

Quoted 25 lines
tests/nvme/030 +0 -0
 }
 
 set_conditions() {
tests/nvme/rc +8 -0
index aaa64453fe16..4a2d107bd532 100644
@@ -219,6 +219,14 @@ _require_kernel_nvme_fabrics_feature() {
 	return 0
 }
 
+_require_kernel_target() {
+	if [[ -n "${nvme_target_control}" ]]; then
+		SKIP_REASONS+=("Linux kernel soft target not available")
+		return 1;
+	fi
+	return 0
+}
+
 _test_dev_nvme_ctrl() {
 	echo "/dev/char/$(cat "${TEST_DEV_SYSFS}/device/dev")"
 }
Signature · 1 line
2.45.2
#5 lore raw

RFC v2 3/3 contrib: add remote target setup/cleanup script

In reply to Daniel Wagner

Use nvmetcli to setup/cleanup a remote soft target.

---
 contrib/nvme_target_control.py | 110 +++++++++++++++++++++++++++++++++
 contrib/nvmet-subsys.jinja2    |  71 +++++++++++++++++++++
 2 files changed, 181 insertions(+)
 create mode 100755 contrib/nvme_target_control.py
 create mode 100644 contrib/nvmet-subsys.jinja2
contrib/nvme_target_control.py new file +110 -0
new file mode 100755
index 000000000000..97ed1c600dd2
@@ -0,0 +1,110 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-3.0+
+
+# blktests calls this script to setup/teardown remote targets. blktests passes
+# all relevant information via the command line, e.g. --hostnqn. The interface
+# between blktests and this script is 'documentent' here in build_parser
+# function.
+#
+# This script uses nvmetcli to setup the remote target (it depends on the REST
+# API feature [1]). There is not technical need for nvmetcli to use but it makes
+# it simple to setup a remote Linux box. If you want to setup someting else
+# you should to replace this part.
+#
+# There are couple of global configuration options which need to be set.
+# Add ~/.config/blktests/nvme_target_control.toml file with something like:
+#
+# [main]
+# nvmetcli='/usr/bin/nvmetcli'
+# remote='http://nvmet.local:5000'
+#
+# And then start the nvmetcli server on the remote host.
+#
+# nvmetcli uses JSON configuration, thus this script creates a JSON configuration
+# using a jinja2 template. After this step we simple have to set the blktests
+# variable correctly and start blktests.
+#
+# $ host_ip4=$(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1)
+# $ NVME_TRTYPE=tcp NVME_NVMET=nvmet.local NVME_HOST_TRADDR=${host_ip4} \
+#   NVME_TARGET_CONTROL=~/blktests/contrib/nvme_target_control.py ./check nvme
+#
+# [1] https://github.com/hreinecke/nvmetcli/tree/restapi
+
+import os
+import tomllib
+import argparse
+import subprocess
+from jinja2 import Environment, FileSystemLoader
+
+
+XDG_CONFIG_HOME = os.environ.get("XDG_CONFIG_HOME")
+if not XDG_CONFIG_HOME:
+    XDG_CONFIG_HOME = os.environ.get('HOME') + '/.config'
+
+
+with open(f'{XDG_CONFIG_HOME}/blktests/nvme_target_control.toml', 'rb') as f:
+    config = tomllib.load(f)
+    nvmetcli = config['main']['nvmetcli']
+    remote = config['main']['remote']
+
+
+def gen_conf(conf):
+    environment = Environment(loader=FileSystemLoader('.'))
+    template = environment.get_template('nvmet-subsys.jinja2')
+    filename = f'{conf["subsysnqn"]}.json'
+    content = template.render(conf)
+    with open(filename, mode='w', encoding='utf-8') as outfile:
+        outfile.write(content)
+
+
+def target_setup(args):
+    conf = {
+        'subsysnqn': args.subsysnqn,
+        'subsys_uuid': args.subsys_uuid,
+        'hostnqn': args.hostnqn,
+        'allowed_hosts': args.hostnqn,
+        'ctrlkey': args.ctrlkey,
+        'hostkey': args.hostkey,
+        'blkdev': '/dev/vdc'
+    }
+
+    gen_conf(conf)
+
+    subprocess.call(['python3', nvmetcli, '--remote=' + remote,
+                     'restore', args.subsysnqn + '.json'])
+
+
+def target_cleanup(args):
+    subprocess.call(['python3', nvmetcli, '--remote=' + remote,
+                     'clear', args.subsysnqn + '.json'])
+
+
+def build_parser():
+    parser = argparse.ArgumentParser()
+    sub = parser.add_subparsers(required=True)
+
+    setup = sub.add_parser('setup')
+    setup.add_argument('--subsysnqn', required=True)
+    setup.add_argument('--subsys-uuid', required=True)
+    setup.add_argument('--hostnqn', required=True)
+    setup.add_argument('--ctrlkey', default='')
+    setup.add_argument('--hostkey', default='')
+    setup.set_defaults(func=target_setup)
+
+    cleanup = sub.add_parser('cleanup')
+    cleanup.add_argument('--subsysnqn', required=True)
+    cleanup.set_defaults(func=target_cleanup)
+
+    return parser
+
+
+def main():
+    import sys
+
+    parser = build_parser()
+    args = parser.parse_args()
+    args.func(args)
+
+
+if __name__ == '__main__':
+    main()
contrib/nvmet-subsys.jinja2 new file +71 -0

71 lines not on this page · raw message

Signature · 1 line
2.45.2
#6 lore raw

Re: [RFC blktests v2 3/3] contrib: add remote target setup/cleanup script

contrib/nvme_target_control.py line 7

Quoted 4 lines · Daniel Wagner
contrib/nvme_target_control.py new file +4 -0
+# blktests calls this script to setup/teardown remote targets. blktests passes
+# all relevant information via the command line, e.g. --hostnqn. The interface
+# between blktests and this script is 'documentent' here in build_parser
+# function.

I just had an offline discussion with Hannes. This script is setting up/tearing down the targets on demand. This is fine for a remote Linux box the soft target running use case.

Hannes' idea/requirement that it should also support static setups. E.g. the admin setups the real remote target and provides the ns uuids, which test should run against (this is very similar to TESTS_DEVS). Thus the tests should only operate on ns uuids and through this script blktests can ask for the ns uuids.

#7 lore raw
In reply to Daniel Wagner

Hi Daniel,

Quoted 3 lines · Daniel Wagner

I've updated this series and added a simple example how to use it. I didn't really know where to put it, so I added this part to new directorty called 'contrib'.

I'm fine with this. Some other helper scripts maybe go into the contrib directory in the future.

Quoted 5 lines

Don't know if we want to keep adding environment variables for this or if it would be simpler to pass in a configuration file. The environemnt variable are fairly simple to handle and it works. Adding a configuraiton file adds more code to blktests.

The first patch added 4 new environemnt variables. Unless you plan to add more, I think it's fine with the environemnt variable approach.

Overall, the changes do not affect core part of blktests. This looks good to me.

I'm not sure if the NVME_TARGET_CONTROL script command line interface will be stable or not (setup/cleanup, --subsysnqn, --subsys-uuid and --hostnqn options). I wonder the disucssion with Hannes may affect it.