[PATCH blktests v2 12/13] common/nvme, nvme/{016,017,052}: improve _create_nvmet_ns()
Shin'ichiro Kawasaki
shinichiro.kawasaki at wdc.com
Tue Oct 29 23:51:48 PDT 2024
From: Hannes Reinecke <hare at suse.de>
Add --grpid option to pass ANA group id. If no UUID is passed the kernel
will generate a UUID, so return the UUID to allow the caller to identify
the generated namespace. Allow to call _create_nvmet_ns() without
--subsysnqn option by using def_subsysnqn as its default value.
Signed-off-by: Hannes Reinecke <hare at suse.de>
[Shin'ichiro: rebased on the commit e3fe06e and resolved conflicts]
Reviewed-by: Daniel Wagner <dwagner at suse.de>
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki at wdc.com>
---
common/nvme | 47 ++++++++++++++++++++++++++++++++---------------
tests/nvme/016 | 5 ++---
tests/nvme/017 | 5 ++---
tests/nvme/052 | 8 +++-----
4 files changed, 39 insertions(+), 26 deletions(-)
diff --git a/common/nvme b/common/nvme
index 3a2bb35..bc5019a 100644
--- a/common/nvme
+++ b/common/nvme
@@ -511,18 +511,19 @@ _remove_nvmet_port() {
}
_create_nvmet_ns() {
- local nvmet_subsystem=""
- local nsid=""
- local blkdev=""
- local uuid="00000000-0000-0000-0000-000000000000"
- local subsys_path=""
- local ns_path=""
+ local subsysnqn="${def_subsysnqn}"
+ local nsid="1"
+ local grpid="1"
+ local blkdev
+ local uuid
+ local subsys_path
+ local ns_path
local resv_enable=false
while [[ $# -gt 0 ]]; do
case $1 in
--subsysnqn)
- nvmet_subsystem="$2"
+ subsysnqn="$2"
shift 2
;;
--nsid)
@@ -541,6 +542,10 @@ _create_nvmet_ns() {
resv_enable=true
shift 1
;;
+ --grpid)
+ grpid="$2"
+ shift 2
+ ;;
*)
echo "WARNING: unknown argument: $1"
shift
@@ -548,16 +553,23 @@ _create_nvmet_ns() {
esac
done
- subsys_path="${NVMET_CFS}/subsystems/${nvmet_subsystem}"
+ subsys_path="${NVMET_CFS}/subsystems/${subsysnqn}"
ns_path="${subsys_path}/namespaces/${nsid}"
-
mkdir "${ns_path}"
printf "%s" "${blkdev}" > "${ns_path}/device_path"
- printf "%s" "${uuid}" > "${ns_path}/device_uuid"
if [[ -f "${ns_path}/resv_enable" && "${resv_enable}" = true ]] ; then
printf 1 > "${ns_path}/resv_enable"
fi
+ if [[ -n "${uuid}" ]]; then
+ printf "%s" "${uuid}" > "${ns_path}/device_uuid"
+ else
+ uuid=$(cat "${ns_path}/device_uuid")
+ fi
+ if (( grpid != 1 )); then
+ printf "%d" "${grpid}" > "${ns_path}/ana_grpid"
+ fi
printf 1 > "${ns_path}/enable"
+ echo "${uuid}"
}
_create_nvmet_subsystem() {
@@ -566,6 +578,7 @@ _create_nvmet_subsystem() {
local uuid="00000000-0000-0000-0000-000000000000"
local resv_enable=""
local cfs_path=""
+ local -a ARGS
while [[ $# -gt 0 ]]; do
case $1 in
@@ -595,11 +608,15 @@ _create_nvmet_subsystem() {
cfs_path="${NVMET_CFS}/subsystems/${nvmet_subsystem}"
mkdir -p "${cfs_path}"
echo 0 > "${cfs_path}/attr_allow_any_host"
- _create_nvmet_ns --subsysnqn "${nvmet_subsystem}" \
- --nsid "1" \
- --blkdev "${blkdev}" \
- --uuid "${uuid}" \
- ${resv_enable}
+ ARGS+=(--subsysnqn "${nvmet_subsystem}")
+ ARGS+=(--blkdev "${blkdev}")
+ if [[ -n "$uuid" ]]; then
+ ARGS+=(--uuid "${uuid}")
+ fi
+ if [[ -n "$resv_enable" ]]; then
+ ARGS+=("${resv_enable}")
+ fi
+ _create_nvmet_ns "${ARGS[@]}" > /dev/null
}
_add_nvmet_allow_hosts() {
diff --git a/tests/nvme/016 b/tests/nvme/016
index 13d2c46..56f1477 100755
--- a/tests/nvme/016
+++ b/tests/nvme/016
@@ -33,9 +33,8 @@ test() {
--blkdev "${loop_dev}"
for ((i = 2; i <= iterations; i++)); do
- _create_nvmet_ns --subsysnqn "${def_subsysnqn}" \
- --nsid "${i}" \
- --blkdev "${loop_dev}"
+ _create_nvmet_ns --nsid "${i}" \
+ --blkdev "${loop_dev}" > /dev/null
done
port="$(_create_nvmet_port)"
diff --git a/tests/nvme/017 b/tests/nvme/017
index 10ee38c..edd70ca 100755
--- a/tests/nvme/017
+++ b/tests/nvme/017
@@ -34,9 +34,8 @@ test() {
--uuid "${def_subsys_uuid}"
for ((i = 2; i <= iterations; i++)); do
- _create_nvmet_ns --subsysnqn "${def_subsysnqn}" \
- --nsid "${i}" \
- --blkdev "$(_nvme_def_file_path)"
+ _create_nvmet_ns --nsid "${i}" \
+ --blkdev "$(_nvme_def_file_path)" > /dev/null
done
port="$(_create_nvmet_port)"
diff --git a/tests/nvme/052 b/tests/nvme/052
index 1dcda23..5cdabb1 100755
--- a/tests/nvme/052
+++ b/tests/nvme/052
@@ -52,6 +52,7 @@ test() {
_setup_nvmet
local iterations=20
+ local uuid
_nvmet_target_setup
@@ -62,12 +63,9 @@ test() {
# deleted when nvme target is cleaned up.
for ((i = 2; i <= iterations; i++)); do {
truncate -s "${NVME_IMG_SIZE}" "$(_nvme_def_file_path).$i"
- uuid="$(uuidgen -r)"
- _create_nvmet_ns --subsysnqn "${def_subsysnqn}" \
- --nsid "${i}" \
- --blkdev "$(_nvme_def_file_path).$i" \
- --uuid "${uuid}"
+ uuid=$(_create_nvmet_ns --blkdev "$(_nvme_def_file_path).$i" \
+ --nsid "${i}")
# wait until async request is processed and ns is created
if ! nvmf_wait_for_ns "${uuid}" created; then
--
2.45.2
More information about the Linux-nvme
mailing list