Skip to contentSkip to conversation

nvme/{common/nvme, 051, 052}: introduce def_nsid

PATCH Superseded Guixin Liu 2 participants 3 messages Oct 31, 2024 NVMe

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Guixin Liu

author
#0 lore raw

PATCH v2 1/1 nvme/{common/nvme, 051, 052}: introduce def_nsid

Use def_nsid instead of hard code, the default of def_nsid is 1.

---
Changes from v1 to v2:
- change the hard code in _remove_nvmet_subsystem() to fix the nvme/004 fail if change def_nsid to 2.

 common/nvme    | 5 +++--
 tests/nvme/051 | 2 +-
 tests/nvme/052 | 6 +++---
 3 files changed, 7 insertions(+), 6 deletions(-)
common/nvme +3 -2
index c1aa8d6..99c2911 100644
@@ -16,6 +16,7 @@ def_hostid="0f01fb42-9f7f-4856-b0b3-51e60b8de349"
 def_hostnqn="nqn.2014-08.org.nvmexpress:uuid:${def_hostid}"
 export def_subsysnqn="blktests-subsystem-1"
 export def_subsys_uuid="91fdba0d-f87b-4c25-b80f-db7be1418b9e"
+export def_nsid="1"
 _check_conflict_and_set_default NVMET_TRTYPES nvme_trtype "loop"
 _check_conflict_and_set_default NVME_IMG_SIZE nvme_img_size 1G
 _check_conflict_and_set_default NVME_NUM_ITER nvme_num_iter 1000
@@ -537,7 +538,7 @@ _create_nvmet_subsystem() {
 	mkdir -p "${cfs_path}"
 	echo 0 > "${cfs_path}/attr_allow_any_host"
 	_create_nvmet_ns --subsysnqn "${nvmet_subsystem}" \
-			 --nsid "1" \
+			 --nsid "${def_nsid}" \
 			 --blkdev "${blkdev}" \
 			 --uuid "${uuid}" \
 			 ${resv_enable}
@@ -588,7 +589,7 @@ _remove_nvmet_subsystem() {
 	local nvmet_subsystem="$1"
 	local subsys_path="${NVMET_CFS}/subsystems/${nvmet_subsystem}"
 
-	_remove_nvmet_ns "${nvmet_subsystem}" "1"
+	_remove_nvmet_ns "${nvmet_subsystem}" "${def_nsid}"
 	rm -f "${subsys_path}"/allowed_hosts/*
 	rmdir "${subsys_path}"
 }
tests/nvme/051 +1 -1
index 624b42f..4757b80 100755
@@ -33,7 +33,7 @@ test() {
 	_setup_nvmet
 
 	_nvmet_target_setup
-	ns="${NVMET_CFS}subsystems/${def_subsysnqn}/namespaces/1"
+	ns="${NVMET_CFS}subsystems/${def_subsysnqn}/namespaces/${def_nsid}"
 
 	# fire off two enable/disable loops concurrently and wait
 	# for them to complete...
tests/nvme/052 +3 -3
index 1dcda23..781a9f0 100755
@@ -57,10 +57,10 @@ test() {
 
 	_nvme_connect_subsys
 
-	# start iteration from ns-id 2 because ns-id 1 is created
-	# by default when nvme target is setup. Also ns-id 1 is
+	# start iteration from def_nsid+1 because def_nsid is created
+	# by default when nvme target is setup. Also def_nsid is
 	# deleted when nvme target is cleaned up.
-	for ((i = 2; i <= iterations; i++)); do {
+	for ((i = $((${def_nsid})) + 1; i <= iterations; i++)); do {
 		truncate -s "${NVME_IMG_SIZE}" "$(_nvme_def_file_path).$i"
 		uuid="$(uuidgen -r)"
 
Signature · 1 line
2.43.0
#1 lore raw
Quoted 9 lines · Guixin Liu

Use def_nsid instead of hard code, the default of def_nsid is 1.

---
Changes from v1 to v2:
- change the hard code in _remove_nvmet_subsystem() to fix the nvme/004 fail if change def_nsid to 2.

Thanks for the update. I think you overlooked my other comments for v1, which were at the end of my e-mail [1].

[1] https://lore.kernel.org/linux-nvme/33susvhlxjt2uf3gqldcb2n43pgrvt5m2wj6b27nbgeoxamfkn@az45ko2fsydt/

Here I quote my comments:

------------------------------------------------------------------------------
After this change, when def_nsid is larger than iteration=20, nvme/052 will do nothing. I think the change should be like this:

    for ((i = 2; i <= iterations; i++)); do {
        nsid=$((def_nsid + i - 1))
	truncate -s "${NVME_IMG_SIZE}" "$(_nvme_def_file_path).${nsid}"
        uuid=$(_create_nvmet_ns --blkdev "$(_nvme_def_file_path).${nsid}" \
                                   --nsid "${nsid}")
        ....

Also, same change will be required in nvme/016 and nvme/017. They also use the --nsid option.

$ git grep -e "--nsid"
common/nvme:                    --nsid)
tests/nvme/016:         _create_nvmet_ns --nsid "${i}" \
tests/nvme/017:         _create_nvmet_ns --nsid "${i}" \
tests/nvme/052:                                 --nsid "${i}")
------------------------------------------------------------------------------

And I have one more comment below.

[...]

Quoted 7 lines
tests/nvme/052 +0 -0
index 1dcda23..781a9f0 100755
@@ -57,10 +57,10 @@ test() {
 
 	_nvme_connect_subsys

tests/nvme/052 test() { · line 65

Quoted 10 lines
tests/nvme/052 +3 -3
 
-	# start iteration from ns-id 2 because ns-id 1 is created
-	# by default when nvme target is setup. Also ns-id 1 is
+	# start iteration from def_nsid+1 because def_nsid is created
+	# by default when nvme target is setup. Also def_nsid is
 	# deleted when nvme target is cleaned up.
-	for ((i = 2; i <= iterations; i++)); do {
+	for ((i = $((${def_nsid})) + 1; i <= iterations; i++)); do {
 		truncate -s "${NVME_IMG_SIZE}" "$(_nvme_def_file_path).$i"
 		uuid="$(uuidgen -r)"

The change above causes the shellcheck error below. Do you see the error in your environment?

------------------------------------------------------------------------------

$ make check
shellcheck -x -e SC2119 -f gcc check common/* \
        tests/*/rc tests/*/[0-9]*[0-9] src/*.sh
tests/nvme/052:63:15: note: $/${} is unnecessary on arithmetic variables. [SC2004]
make: *** [Makefile:21: check] Error 1
------------------------------------------------------------------------------
author
#2 lore raw
Quoted 15 lines · Shinichiro Kawasaki
Quoted 9 lines · Guixin Liu

Use def_nsid instead of hard code, the default of def_nsid is 1.

---
Changes from v1 to v2:
- change the hard code in _remove_nvmet_subsystem() to fix the nvme/004 fail if change def_nsid to 2.

Thanks for the update. I think you overlooked my other comments for v1, which were at the end of my e-mail [1].

[1] https://lore.kernel.org/linux-nvme/33susvhlxjt2uf3gqldcb2n43pgrvt5m2wj6b27nbgeoxamfkn@az45ko2fsydt/

Quoted 8 lines

Here I quote my comments:

------------------------------------------------------------------------------
After this change, when def_nsid is larger than iteration=20, nvme/052 will do nothing. I think the change should be like this:

     for ((i = 2; i <= iterations; i++)); do {
         nsid=$((def_nsid + i - 1))

Sorry I miss this, I think here "i" can be start with 1, and nsid=$((def_nsid + i)).

Changed in v3.

Quoted 5 lines
	truncate -s "${NVME_IMG_SIZE}" "$(_nvme_def_file_path).${nsid}"
         uuid=$(_create_nvmet_ns --blkdev "$(_nvme_def_file_path).${nsid}" \
                                    --nsid "${nsid}")
         ....
Quoted 8 lines

Also, same change will be required in nvme/016 and nvme/017. They also use the --nsid option.

$ git grep -e "--nsid"
common/nvme:                    --nsid)
tests/nvme/016:         _create_nvmet_ns --nsid "${i}" \
tests/nvme/017:         _create_nvmet_ns --nsid "${i}" \
tests/nvme/052:                                 --nsid "${i}")

Also changed in v3, thanks.

Quoted 25 lines

------------------------------------------------------------------------------

And I have one more comment below.

[...]

Quoted 7 lines
tests/nvme/052 +0 -0
index 1dcda23..781a9f0 100755
@@ -57,10 +57,10 @@ test() {
 
  	_nvme_connect_subsys

tests/nvme/052 test() { · line 65

Quoted 10 lines
tests/nvme/052 +3 -3
 
-	# start iteration from ns-id 2 because ns-id 1 is created
-	# by default when nvme target is setup. Also ns-id 1 is
+	# start iteration from def_nsid+1 because def_nsid is created
+	# by default when nvme target is setup. Also def_nsid is
  	# deleted when nvme target is cleaned up.
-	for ((i = 2; i <= iterations; i++)); do {
+	for ((i = $((${def_nsid})) + 1; i <= iterations; i++)); do {
  		truncate -s "${NVME_IMG_SIZE}" "$(_nvme_def_file_path).$i"
  		uuid="$(uuidgen -r)"

The change above causes the shellcheck error below. Do you see the error in your environment?

Quoted 7 lines

------------------------------------------------------------------------------

$ make check
shellcheck -x -e SC2119 -f gcc check common/* \
         tests/*/rc tests/*/[0-9]*[0-9] src/*.sh
tests/nvme/052:63:15: note: $/${} is unnecessary on arithmetic variables. [SC2004]
make: *** [Makefile:21: check] Error 1
------------------------------------------------------------------------------

If change to nsid=$((def_nsid + i)), no error report now.

Thanks, I will remember to run "make check" before I send the patch.

Best Regards,

Guixin Liu