@@ -120,6 +120,9 @@ 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_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
@@ -167,3 +170,33 @@ if ! findmnt -t configfs /sys/kernel/config > /dev/null; then
mount -t configfs configfs /sys/kernel/config
fi
```
+### NVME_TARGET_CONTROL
+
+When NVME_TARGET_CONTROL is set, blktests will call the script which the
+environment variable points to, to fetch the configuration values to be used for
+the runs, e.g subsysnqn or hostnqn. This allows the blktest to be run against
+external configured/setup targets.
+
+The blktests expects that the script interface implements following
+commands:
+
+config:
+ --show-blkdev-type
+ --show-trtype
+ --show-hostnqn
+ --show-hostid
+ --show-host-traddr
+ --show-traddr
+ --show-trsvid
+ --show-subsys-uuid
+ --show-subsysnqn
+
+setup:
+ --subsysnqn SUBSYSNQN
+ --subsys-uuid SUBSYS_UUID
+ --hostnqn HOSTNQN
+ --ctrlkey CTRLKEY
+ --hostkey HOSTKEY
+
+cleanup:
+ --subsysnqn SUBSYSNQN
@@ -603,6 +603,10 @@ _run_group() {
# shellcheck disable=SC1090
. "tests/${group}/rc"
+ if declare -fF group_setup >/dev/null; then
+ group_setup
+ fi
+
if declare -fF group_requires >/dev/null; then
group_requires
if [[ -v SKIP_REASONS ]]; then
@@ -22,6 +22,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_CFS="/sys/kernel/config/nvmet/"
nvme_trtype=${nvme_trtype:-}
nvme_adrfam=${nvme_adrfam:-}
@@ -157,6 +158,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}"
@@ -208,6 +213,18 @@ _cleanup_nvmet() {
_setup_nvmet() {
_register_test_cleanup _cleanup_nvmet
+
+ if [[ -n "${nvme_target_control}" ]]; then
+ def_hostnqn="$(${nvme_target_control} config --show-hostnqn)"
+ def_hostid="$(${nvme_target_control} config --show-hostid)"
+ def_host_traddr="$(${nvme_target_control} config --show-host-traddr)"
+ def_traddr="$(${nvme_target_control} config --show-traddr)"
+ def_trsvcid="$(${nvme_target_control} config --show-trsvid)"
+ def_subsys_uuid="$(${nvme_target_control} config --show-subsys-uuid)"
+ def_subsysnqn="$(${nvme_target_control} config --show-subsysnqn)"
+ return
+ fi
+
modprobe -q nvmet
if [[ "${nvme_trtype}" != "loop" ]]; then
modprobe -q nvmet-"${nvme_trtype}"
@@ -320,17 +337,23 @@ _nvme_connect_subsys() {
esac
done
- if [[ -z "${port}" ]]; then
- local ports
-
- _get_nvmet_ports "${subsysnqn}" ports
- port="${ports[0]##*/}"
+ if [[ -n "${nvme_target_control}" && -z "${port}" ]]; then
+ ARGS+=(--transport "$(${nvme_target_control} config --show-trtype)")
+ ARGS+=(--traddr "${def_traddr}")
+ ARGS+=(--trsvcid "${def_trsvcid}")
+ else
if [[ -z "${port}" ]]; then
- echo "WARNING: no port found"
- return 1
+ local ports
+
+ _get_nvmet_ports "${subsysnqn}" ports
+ port="${ports[0]##*/}"
+ if [[ -z "${port}" ]]; then
+ echo "WARNING: no port found"
+ return 1
+ fi
fi
+ _get_nvmet_port_params "${port}" ARGS
fi
- _get_nvmet_port_params "${port}" ARGS
ARGS+=(--nqn "${subsysnqn}")
ARGS+=(--hostnqn="${hostnqn}")
ARGS+=(--hostid="${hostid}")
@@ -762,11 +785,13 @@ _find_nvme_ns() {
_nvmet_target_setup() {
local blkdev_type="${nvmet_blkdev_type}"
local blkdev
+ local ARGS=()
local ctrlkey=""
local hostkey=""
local subsysnqn="${def_subsysnqn}"
local subsys_uuid
local port
+ local resv_enable=""
local -a ARGS
while [[ $# -gt 0 ]]; do
@@ -811,6 +836,29 @@ _nvmet_target_setup() {
fi
fi
+ if [[ -n "${hostkey}" ]]; then
+ ARGS+=(--hostkey "${hostkey}")
+ fi
+ 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:-$def_subsys_uuid}" \
+ --hostnqn "${def_hostnqn}" \
+ "${ARGS[@]}" &> /dev/null
+ return
+ fi
+
+ truncate -s "${NVME_IMG_SIZE}" "$(_nvme_def_file_path)"
+ if [[ "${blkdev_type}" == "device" ]]; then
+ blkdev="$(losetup -f --show "$(_nvme_def_file_path)")"
+ else
+ blkdev="$(_nvme_def_file_path)"
+ fi
+
ARGS=(--subsysnqn "${subsysnqn}")
if [[ -n "${blkdev}" ]]; then
ARGS+=(--blkdev "${blkdev}")
@@ -853,6 +901,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
@@ -113,6 +113,13 @@ _nvme_requires() {
return 0
}
+group_setup() {
+ if [[ -n "${nvme_target_control}" ]]; then
+ NVMET_TRTYPES="$(${nvme_target_control} config --show-trtype)"
+ NVMET_BLKDEV_TYPES="$(${nvme_target_control} config --show-blkdev-type)"
+ fi
+}
+
group_requires() {
_have_root
_NVMET_TRTYPES_is_valid
@@ -392,6 +399,13 @@ _nvmet_passthru_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