[PATCH blktests 2/8] nvme: move _nvmet_target_setup() to common/nvme
Shin'ichiro Kawasaki
shinichiro.kawasaki at wdc.com
Thu Nov 7 03:13:48 PST 2024
From: Hannes Reinecke <hare at suse.de>
_nvmet_target_setup() is in tests/nvme/rc, but _nvmet_target_cleanup()
is in common/nvme. So move the former into common/nvme to have both
functions in the same place.
Signed-off-by: Hannes Reinecke <hare at suse.de>
[Shin'ichiro: rebased on the commit e3fe06e and resolved conflicts]
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki at wdc.com>
---
common/nvme | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++
tests/nvme/rc | 71 ---------------------------------------------------
2 files changed, 70 insertions(+), 71 deletions(-)
diff --git a/common/nvme b/common/nvme
index 84b6ac3..832e879 100644
--- a/common/nvme
+++ b/common/nvme
@@ -784,6 +784,76 @@ _find_nvme_ns() {
return 1
}
+_nvmet_target_setup() {
+ local blkdev_type="${nvmet_blkdev_type}"
+ local blkdev
+ local ctrlkey=""
+ local hostkey=""
+ local subsysnqn="${def_subsysnqn}"
+ local subsys_uuid
+ local port
+ local -a ARGS
+
+ while [[ $# -gt 0 ]]; do
+ case $1 in
+ --blkdev)
+ blkdev_type="$2"
+ shift 2
+ ;;
+ --ctrlkey)
+ ctrlkey="$2"
+ shift 2
+ ;;
+ --hostkey)
+ hostkey="$2"
+ shift 2
+ ;;
+ --subsysnqn)
+ subsysnqn="$2"
+ shift 2
+ ;;
+ --subsys-uuid)
+ subsys_uuid="$2"
+ shift 2
+ ;;
+ --resv_enable)
+ resv_enable="--resv_enable"
+ shift 1
+ ;;
+ *)
+ echo "WARNING: unknown argument: $1"
+ shift
+ ;;
+ esac
+ done
+
+ if [[ "${blkdev_type}" != "none" ]]; then
+ 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
+ fi
+
+ ARGS=(--subsysnqn "${subsysnqn}")
+ if [[ -n "${blkdev}" ]]; then
+ ARGS+=(--blkdev "${blkdev}")
+ fi
+ if [[ -n "${subsys_uuid}" ]]; then
+ ARGS+=(--uuid "${subsys_uuid}")
+ fi
+ if [[ -n "${resv_enable}" ]]; then
+ ARGS+=("${resv_enable}")
+ fi
+ _create_nvmet_subsystem "${ARGS[@]}"
+
+ port="$(_create_nvmet_port)"
+ _add_nvmet_subsys_to_port "${port}" "${subsysnqn}"
+ _create_nvmet_host "${subsysnqn}" "${def_hostnqn}" \
+ "${hostkey}" "${ctrlkey}"
+}
+
_nvmet_target_cleanup() {
local ports
local port
diff --git a/tests/nvme/rc b/tests/nvme/rc
index 05f9192..d63afd1 100644
--- a/tests/nvme/rc
+++ b/tests/nvme/rc
@@ -317,77 +317,6 @@ _find_nvme_passthru_loop_dev() {
echo "/dev/${dev}n${nsid}"
}
-_nvmet_target_setup() {
- local blkdev_type="${nvmet_blkdev_type}"
- local blkdev
- local ctrlkey=""
- local hostkey=""
- local subsysnqn="${def_subsysnqn}"
- local subsys_uuid
- local port
- local resv_enable=""
- local -a ARGS
-
- while [[ $# -gt 0 ]]; do
- case $1 in
- --blkdev)
- blkdev_type="$2"
- shift 2
- ;;
- --ctrlkey)
- ctrlkey="$2"
- shift 2
- ;;
- --hostkey)
- hostkey="$2"
- shift 2
- ;;
- --subsysnqn)
- subsysnqn="$2"
- shift 2
- ;;
- --subsys-uuid)
- subsys_uuid="$2"
- shift 2
- ;;
- --resv_enable)
- resv_enable="--resv_enable"
- shift 1
- ;;
- *)
- echo "WARNING: unknown argument: $1"
- shift
- ;;
- esac
- done
-
- if [[ "${blkdev_type}" != "none" ]]; then
- 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
- fi
-
- ARGS=(--subsysnqn "${subsysnqn}")
- if [[ -n "${blkdev}" ]]; then
- ARGS+=(--blkdev "${blkdev}")
- fi
- if [[ -n "${subsys_uuid}" ]]; then
- ARGS+=(--uuid "${subsys_uuid}")
- fi
- if [[ -n "${resv_enable}" ]]; then
- ARGS+=("${resv_enable}")
- fi
- _create_nvmet_subsystem "${ARGS[@]}"
-
- port="$(_create_nvmet_port)"
- _add_nvmet_subsys_to_port "${port}" "${subsysnqn}"
- _create_nvmet_host "${subsysnqn}" "${def_hostnqn}" \
- "${hostkey}" "${ctrlkey}"
-}
-
_nvmet_passthru_target_setup() {
local subsysnqn="$def_subsysnqn"
local port
--
2.47.0
More information about the Linux-nvme
mailing list