Skip to contentSkip to conversation

nvme/{033-037}: timeout while waiting for nvme passthru namespace device

PATCH Superseded Nilay Shroff 2 participants 3 messages Sep 24, 2024 – Sep 25, 2024

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvme/{033-037}: timeout while waiting for nvme passthru namespace device

Avoid waiting indefinitely for nvme passthru namespace block device to appear. Wait for up to 5 seconds and during this time if namespace block device doesn't appear then bail out and FAIL the test.

---
Hi,

You may find more details about this issue here[1].

I found that blktest nvme/033-037 hangs indefinitely when kernel rejects the passthru target namespace due to the duplicate IDs. This patch helps address this issue by ensuring that we bail out and fail the test if for any reason passthru target namspace is not created on the host. The relevant kernel patchv2 to fix the issue with duplicate IDs while using passthru loop target can be found here[2].

[1]: https://lore.kernel.org/all/[email protected]/
[2]: https://lore.kernel.org/all/[email protected]/

Thanks!

---
 tests/nvme/033 |  7 +++++--
 tests/nvme/034 |  7 +++++--
 tests/nvme/035 |  6 +++---
 tests/nvme/036 | 14 ++++++++------
 tests/nvme/037 |  6 +++++-
 tests/nvme/rc  | 12 +++++++++++-
 6 files changed, 37 insertions(+), 15 deletions(-)
tests/nvme/033 +5 -2
index 5e05175..171974e 100755
@@ -62,8 +62,11 @@ test_device() {
 	_nvmet_passthru_target_setup
 
 	nsdev=$(_nvmet_passthru_target_connect)
-
-	compare_dev_info "${nsdev}"
+	if [[ -z "$nsdev" ]]; then
+		echo "FAIL"
+	else
+		compare_dev_info "${nsdev}"
+	fi
 
 	_nvme_disconnect_subsys
 	_nvmet_passthru_target_cleanup
tests/nvme/034 +5 -2
index 154fc91..7625204 100755
@@ -32,8 +32,11 @@ test_device() {
 
 	_nvmet_passthru_target_setup
 	nsdev=$(_nvmet_passthru_target_connect)
-
-	_run_fio_verify_io --size="${NVME_IMG_SIZE}" --filename="${nsdev}"
+	if [[ -z "$nsdev" ]]; then
+		echo "FAIL"
+	else
+		_run_fio_verify_io --size="${NVME_IMG_SIZE}" --filename="${nsdev}"
+	fi
 
 	_nvme_disconnect_subsys
 	_nvmet_passthru_target_cleanup
tests/nvme/035 +3 -3
index ff217d6..6ad9c56 100755
@@ -30,13 +30,13 @@ test_device() {
 
 	_setup_nvmet
 
-	local ctrldev
 	local nsdev
 
 	_nvmet_passthru_target_setup
 	nsdev=$(_nvmet_passthru_target_connect)
-
-	if ! _xfs_run_fio_verify_io "${nsdev}" "${NVME_IMG_SIZE}"; then
+	if [[ -z "$nsdev" ]]; then
+		echo "FAIL"
+	elif ! _xfs_run_fio_verify_io "${nsdev}" "${NVME_IMG_SIZE}"; then
 		echo "FAIL: fio verify failed"
 	fi
 
tests/nvme/036 +8 -6
index 442ffe7..a67ca12 100755
@@ -30,13 +30,15 @@ test_device() {
 
 	_nvmet_passthru_target_setup
 	nsdev=$(_nvmet_passthru_target_connect)
-
-	ctrldev=$(_find_nvme_dev "${def_subsysnqn}")
-
-	if ! nvme reset "/dev/${ctrldev}" >> "$FULL" 2>&1; then
-		echo "ERROR: reset failed"
+	if [[ -z "$nsdev" ]]; then
+		echo "FAIL"
+	else
+		ctrldev=$(_find_nvme_dev "${def_subsysnqn}")
+
+		if ! nvme reset "/dev/${ctrldev}" >> "$FULL" 2>&1; then
+			echo "ERROR: reset failed"
+		fi
 	fi
-
 	_nvme_disconnect_subsys
 	_nvmet_passthru_target_cleanup
 
tests/nvme/037 +5 -1
index f7ddc2d..f0c8a77 100755
@@ -27,7 +27,6 @@ test_device() {
 
 	local subsys="blktests-subsystem-"
 	local iterations=10
-	local ctrldev
 
 	for ((i = 0; i < iterations; i++)); do
 		_nvmet_passthru_target_setup --subsysnqn "${subsys}${i}"
@@ -37,6 +36,11 @@ test_device() {
 		_nvme_disconnect_subsys \
 			--subsysnqn "${subsys}${i}" >>"${FULL}" 2>&1
 		_nvmet_passthru_target_cleanup --subsysnqn "${subsys}${i}"
+
+		if [[ -z "$nsdev" ]]; then
+			echo "FAIL"
+			break
+		fi
 	done
 
 	echo "Test complete"
tests/nvme/rc +11 -1
index a877de3..3def0d0 100644
@@ -394,6 +394,7 @@ _nvmet_passthru_target_setup() {
 
 _nvmet_passthru_target_connect() {
 	local subsysnqn="$def_subsysnqn"
+	local timeout="5"
 
 	while [[ $# -gt 0 ]]; do
 		case $1 in
@@ -414,9 +415,18 @@ _nvmet_passthru_target_connect() {
 	# The following tests can race with the creation
 	# of the device so ensure the block device exists
 	# before continuing
-	while [ ! -b "${nsdev}" ]; do sleep 1; done
+	start_time=$(date +%s)
+	while [ ! -b "${nsdev}" ]; do
+		sleep .1
+		end_time=$(date +%s)
+		if ((end_time - start_time > timeout)); then
+			echo ""
+			return 1
+		fi
+	done
 
 	echo "${nsdev}"
+	return 0
 }
 
 _nvmet_passthru_target_cleanup() {
Signature · 1 line
2.45.2
#1 lore raw
Quoted 19 lines · Nilay Shroff

Avoid waiting indefinitely for nvme passthru namespace block device to appear. Wait for up to 5 seconds and during this time if namespace block device doesn't appear then bail out and FAIL the test.

---
Hi,

You may find more details about this issue here[1].

I found that blktest nvme/033-037 hangs indefinitely when kernel rejects the passthru target namespace due to the duplicate IDs. This patch helps address this issue by ensuring that we bail out and fail the test if for any reason passthru target namspace is not created on the host. The relevant kernel patchv2 to fix the issue with duplicate IDs while using passthru loop target can be found here[2].

Quoted 4 lines

[1]: https://lore.kernel.org/all/[email protected]/
[2]: https://lore.kernel.org/all/[email protected]/

Thanks!

Thanks for the patch :) It's bad that you stumbled into the infinite while loop in _nvmet_passthru_target_connect(). I agree that it should be fixed.

Please find my comments in line.

Quoted 14 lines
---
 tests/nvme/033 |  7 +++++--
 tests/nvme/034 |  7 +++++--
 tests/nvme/035 |  6 +++---
 tests/nvme/036 | 14 ++++++++------
 tests/nvme/037 |  6 +++++-
 tests/nvme/rc  | 12 +++++++++++-
 6 files changed, 37 insertions(+), 15 deletions(-)
tests/nvme/033 +0 -0
index 5e05175..171974e 100755

tests/nvme/033 test_device() { · line 66

Quoted 7 lines
tests/nvme/033 +2 -2
@@ -62,8 +62,11 @@ test_device() {
 	_nvmet_passthru_target_setup
 
 	nsdev=$(_nvmet_passthru_target_connect)
-
-	compare_dev_info "${nsdev}"
+	if [[ -z "$nsdev" ]]; then
+		echo "FAIL"

I think some more specific failure message will be useful. How about "Failed to connect" or so? Same comment for the other test cases 034-037.

Quoted 29 lines
tests/nvme/033 +3 -0
+	else
+		compare_dev_info "${nsdev}"
+	fi
 
 	_nvme_disconnect_subsys
 	_nvmet_passthru_target_cleanup
tests/nvme/034 +5 -2
index 154fc91..7625204 100755
@@ -32,8 +32,11 @@ test_device() {
 
 	_nvmet_passthru_target_setup
 	nsdev=$(_nvmet_passthru_target_connect)
-
-	_run_fio_verify_io --size="${NVME_IMG_SIZE}" --filename="${nsdev}"
+	if [[ -z "$nsdev" ]]; then
+		echo "FAIL"
+	else
+		_run_fio_verify_io --size="${NVME_IMG_SIZE}" --filename="${nsdev}"
+	fi
 
 	_nvme_disconnect_subsys
 	_nvmet_passthru_target_cleanup
tests/nvme/035 +0 -0
index ff217d6..6ad9c56 100755

tests/nvme/035 test_device() { · line 33

Quoted 4 lines
tests/nvme/035 +0 -1
@@ -30,13 +30,13 @@ test_device() {
 
 	_setup_nvmet
 
-	local ctrldev

Good catch :)

tests/nvme/036 test_device() {

Quoted 17 lines
tests/nvme/035 +3 -2
 	local nsdev
 
 	_nvmet_passthru_target_setup
 	nsdev=$(_nvmet_passthru_target_connect)
-
-	if ! _xfs_run_fio_verify_io "${nsdev}" "${NVME_IMG_SIZE}"; then
+	if [[ -z "$nsdev" ]]; then
+		echo "FAIL"
+	elif ! _xfs_run_fio_verify_io "${nsdev}" "${NVME_IMG_SIZE}"; then
 		echo "FAIL: fio verify failed"
 	fi
 
tests/nvme/036 +0 -0
index 442ffe7..a67ca12 100755
@@ -30,13 +30,15 @@ test_device() {

This could be a good chance to add "local nsdev".

Quoted 8 lines
tests/nvme/036 +0 -5
 	_nvmet_passthru_target_setup
 	nsdev=$(_nvmet_passthru_target_connect)
-
-	ctrldev=$(_find_nvme_dev "${def_subsysnqn}")
-
-	if ! nvme reset "/dev/${ctrldev}" >> "$FULL" 2>&1; then
-		echo "ERROR: reset failed"

tests/nvme/036 test_device() { · line 39

Quoted 10 lines
tests/nvme/036 +8 -1
+	if [[ -z "$nsdev" ]]; then
+		echo "FAIL"
+	else
+		ctrldev=$(_find_nvme_dev "${def_subsysnqn}")
+
+		if ! nvme reset "/dev/${ctrldev}" >> "$FULL" 2>&1; then
+			echo "ERROR: reset failed"
+		fi
 	fi
-

Nit: unnecessary change here.

tests/nvme/037 test_device() { · line 30

Quoted 12 lines
tests/nvme/036 +0 -0
 	_nvme_disconnect_subsys
 	_nvmet_passthru_target_cleanup
 
tests/nvme/037 +0 -1
index f7ddc2d..f0c8a77 100755
@@ -27,7 +27,6 @@ test_device() {
 
 	local subsys="blktests-subsystem-"
 	local iterations=10
-	local ctrldev

Good catch. And we can add "local nsdev" here.

Quoted 28 lines
tests/nvme/037 +5 -0
 	for ((i = 0; i < iterations; i++)); do
 		_nvmet_passthru_target_setup --subsysnqn "${subsys}${i}"
@@ -37,6 +36,11 @@ test_device() {
 		_nvme_disconnect_subsys \
 			--subsysnqn "${subsys}${i}" >>"${FULL}" 2>&1
 		_nvmet_passthru_target_cleanup --subsysnqn "${subsys}${i}"
+
+		if [[ -z "$nsdev" ]]; then
+			echo "FAIL"
+			break
+		fi
 	done
 
 	echo "Test complete"
tests/nvme/rc +1 -0
index a877de3..3def0d0 100644
@@ -394,6 +394,7 @@ _nvmet_passthru_target_setup() {
 
 _nvmet_passthru_target_connect() {
 	local subsysnqn="$def_subsysnqn"
+	local timeout="5"
 
 	while [[ $# -gt 0 ]]; do
 		case $1 in

tests/nvme/rc _nvmet_passthru_target_connect() { · line 420

Quoted 7 lines
tests/nvme/rc +3 -1
@@ -414,9 +415,18 @@ _nvmet_passthru_target_connect() {
 	# The following tests can race with the creation
 	# of the device so ensure the block device exists
 	# before continuing
-	while [ ! -b "${nsdev}" ]; do sleep 1; done
+	start_time=$(date +%s)
+	while [ ! -b "${nsdev}" ]; do
+		sleep .1

Is there any reason to have 0.1 second wait duration? When I changed this to "sleep 1", runtime of the test cases did not change on my test system.

tests/nvme/rc _nvmet_passthru_target_connect() { · line 423

Quoted 3 lines
tests/nvme/rc +3 -0
+		end_time=$(date +%s)
+		if ((end_time - start_time > timeout)); then
+			echo ""

This echo doesn't look required.

tests/nvme/rc _nvmet_passthru_target_connect() { · line 425

Quoted 2 lines
tests/nvme/rc +2 -0
+			return 1
+		fi

If 1 second wait is okay instead of 0.1 second wait, the if block above can be a bit simpler, like,

              if ((++count >= timeout)); then
                      return 1
              fi

where, "local count=0" should be declared before.

tests/nvme/rc _nvmet_passthru_target_connect() { · line 429

Quoted 4 lines
tests/nvme/rc +2 -0
+	done
 
 	echo "${nsdev}"
+	return 0

This "return 0" looks redundant. The previous echo succeeds always, then 0 is returned anyway. Also, all of the callers check the failure of this function by referring to the nsdev string echoed. They do not refer to the return code. So, it is not so useful to explicitly show that 0 is returned on success.

Quoted 6 lines
tests/nvme/rc +0 -0
 }
 
 _nvmet_passthru_target_cleanup() {
Signature · 1 line
2.45.2
#2 lore raw
Quoted 23 lines · Shinichiro Kawasaki
Quoted 22 lines · Nilay Shroff

Avoid waiting indefinitely for nvme passthru namespace block device to appear. Wait for up to 5 seconds and during this time if namespace block device doesn't appear then bail out and FAIL the test.

---
Hi,

You may find more details about this issue here[1].

I found that blktest nvme/033-037 hangs indefinitely when kernel rejects the passthru target namespace due to the duplicate IDs. This patch helps address this issue by ensuring that we bail out and fail the test if for any reason passthru target namspace is not created on the host. The relevant kernel patchv2 to fix the issue with duplicate IDs while using passthru loop target can be found here[2].

[1]: https://lore.kernel.org/all/[email protected]/
[2]: https://lore.kernel.org/all/[email protected]/

Quoted 7 lines
Quoted 1 line

Thanks!

Thanks for the patch :) It's bad that you stumbled into the infinite while loop in _nvmet_passthru_target_connect(). I agree that it should be fixed.

Please find my comments in line.

Thank you for your review comments!!

Quoted 16 lines
Quoted 16 lines
---
 tests/nvme/033 |  7 +++++--
 tests/nvme/034 |  7 +++++--
 tests/nvme/035 |  6 +++---
 tests/nvme/036 | 14 ++++++++------
 tests/nvme/037 |  6 +++++-
 tests/nvme/rc  | 12 +++++++++++-
 6 files changed, 37 insertions(+), 15 deletions(-)
tests/nvme/033 +0 -0
index 5e05175..171974e 100755
@@ -62,8 +62,11 @@ test_device() {
 	_nvmet_passthru_target_setup
 
Quoted 8 lines

tests/nvme/033 test_device() { · line 66

Quoted 5 lines
tests/nvme/033 +2 -2
 	nsdev=$(_nvmet_passthru_target_connect)
-
-	compare_dev_info "${nsdev}"
+	if [[ -z "$nsdev" ]]; then
+		echo "FAIL"

I think some more specific failure message will be useful. How about "Failed to connect" or so? Same comment for the other test cases 034-037.

Agreed, I will add a meaningful error message in next patch.

Quoted 49 lines
Quoted 30 lines
tests/nvme/033 +3 -0
+	else
+		compare_dev_info "${nsdev}"
+	fi
 
 	_nvme_disconnect_subsys
 	_nvmet_passthru_target_cleanup
tests/nvme/034 +5 -2
index 154fc91..7625204 100755
@@ -32,8 +32,11 @@ test_device() {
 
 	_nvmet_passthru_target_setup
 	nsdev=$(_nvmet_passthru_target_connect)
-
-	_run_fio_verify_io --size="${NVME_IMG_SIZE}" --filename="${nsdev}"
+	if [[ -z "$nsdev" ]]; then
+		echo "FAIL"
+	else
+		_run_fio_verify_io --size="${NVME_IMG_SIZE}" --filename="${nsdev}"
+	fi
 
 	_nvme_disconnect_subsys
 	_nvmet_passthru_target_cleanup
tests/nvme/035 +0 -0
index ff217d6..6ad9c56 100755

tests/nvme/035 test_device() { · line 33

Quoted 4 lines
tests/nvme/035 +0 -1
@@ -30,13 +30,13 @@ test_device() {
 
 	_setup_nvmet
 
-	local ctrldev

Good catch :)

Quoted 12 lines
tests/nvme/035 +3 -2
 	local nsdev
 
 	_nvmet_passthru_target_setup
 	nsdev=$(_nvmet_passthru_target_connect)
-
-	if ! _xfs_run_fio_verify_io "${nsdev}" "${NVME_IMG_SIZE}"; then
+	if [[ -z "$nsdev" ]]; then
+		echo "FAIL"
+	elif ! _xfs_run_fio_verify_io "${nsdev}" "${NVME_IMG_SIZE}"; then
 		echo "FAIL: fio verify failed"
 	fi
 
Quoted 7 lines

tests/nvme/036 test_device() {

Quoted 5 lines
tests/nvme/036 +0 -0
index 442ffe7..a67ca12 100755
@@ -30,13 +30,15 @@ test_device() {

This could be a good chance to add "local nsdev".

Yeah will do.

Quoted 13 lines
Quoted 13 lines
tests/nvme/036 +4 -5
 	_nvmet_passthru_target_setup
 	nsdev=$(_nvmet_passthru_target_connect)
-
-	ctrldev=$(_find_nvme_dev "${def_subsysnqn}")
-
-	if ! nvme reset "/dev/${ctrldev}" >> "$FULL" 2>&1; then
-		echo "ERROR: reset failed"
+	if [[ -z "$nsdev" ]]; then
+		echo "FAIL"
+	else
+		ctrldev=$(_find_nvme_dev "${def_subsysnqn}")
Quoted 8 lines

tests/nvme/036 test_device() { · line 39

Quoted 6 lines
tests/nvme/036 +4 -1
+
+		if ! nvme reset "/dev/${ctrldev}" >> "$FULL" 2>&1; then
+			echo "ERROR: reset failed"
+		fi
 	fi
-

Nit: unnecessary change here.

Okay, will remove this.

Quoted 10 lines
Quoted 10 lines
tests/nvme/036 +0 -0
 	_nvme_disconnect_subsys
 	_nvmet_passthru_target_cleanup
 
tests/nvme/037 +0 -0
index f7ddc2d..f0c8a77 100755
@@ -27,7 +27,6 @@ test_device() {
 
Quoted 5 lines

tests/nvme/037 test_device() { · line 30

Quoted 3 lines
tests/nvme/037 +0 -1
 	local subsys="blktests-subsystem-"
 	local iterations=10
-	local ctrldev

Good catch. And we can add "local nsdev" here.

yes will do.

Quoted 26 lines
Quoted 26 lines
tests/nvme/037 +5 -0
 	for ((i = 0; i < iterations; i++)); do
 		_nvmet_passthru_target_setup --subsysnqn "${subsys}${i}"
@@ -37,6 +36,11 @@ test_device() {
 		_nvme_disconnect_subsys \
 			--subsysnqn "${subsys}${i}" >>"${FULL}" 2>&1
 		_nvmet_passthru_target_cleanup --subsysnqn "${subsys}${i}"
+
+		if [[ -z "$nsdev" ]]; then
+			echo "FAIL"
+			break
+		fi
 	done
 
 	echo "Test complete"
tests/nvme/rc +1 -0
index a877de3..3def0d0 100644
@@ -394,6 +394,7 @@ _nvmet_passthru_target_setup() {
 
 _nvmet_passthru_target_connect() {
 	local subsysnqn="$def_subsysnqn"
+	local timeout="5"
 
Quoted 14 lines

tests/nvme/rc _nvmet_passthru_target_connect() { · line 420

Quoted 10 lines
tests/nvme/rc +3 -1
 	while [[ $# -gt 0 ]]; do
 		case $1 in
@@ -414,9 +415,18 @@ _nvmet_passthru_target_connect() {
 	# The following tests can race with the creation
 	# of the device so ensure the block device exists
 	# before continuing
-	while [ ! -b "${nsdev}" ]; do sleep 1; done
+	start_time=$(date +%s)
+	while [ ! -b "${nsdev}" ]; do
+		sleep .1

Is there any reason to have 0.1 second wait duration? When I changed this to "sleep 1", runtime of the test cases did not change on my test system.

yes you're right there won't be any noticeable change in the runtime of the test unless we run this test in a loop for multiple number of times. I would say that the gain would be only a fraction of a second in this case. So I will use sleep 1 instead of .1 as you suggested.

Quoted 12 lines

tests/nvme/rc _nvmet_passthru_target_connect() { · line 423

Quoted 3 lines
tests/nvme/rc +3 -0
+		end_time=$(date +%s)
+		if ((end_time - start_time > timeout)); then
+			echo ""

This echo doesn't look required.

tests/nvme/rc _nvmet_passthru_target_connect() { · line 425

Quoted 2 lines
tests/nvme/rc +2 -0
+			return 1
+		fi

If 1 second wait is okay instead of 0.1 second wait, the if block above can be a bit simpler, like,

Quoted 6 lines
              if ((++count >= timeout)); then
                      return 1
              fi

where, "local count=0" should be declared before.

yeah with sleep 1 we can make it simple. I will update this in next patch.

Quoted 10 lines

tests/nvme/rc _nvmet_passthru_target_connect() { · line 429

Quoted 4 lines
tests/nvme/rc +2 -0
+	done
 
 	echo "${nsdev}"
+	return 0

This "return 0" looks redundant. The previous echo succeeds always, then 0 is returned anyway. Also, all of the callers check the failure of this function by referring to the nsdev string echoed. They do not refer to the return code. So, it is not so useful to explicitly show that 0 is returned on success.

yes I will incorporate it in the next patch.

Thanks,
--Nilay