Skip to content

Commit 8fc8eb1

Browse files
committed
nvme/rc: fix nvme device readiness check after _nvme_connect_subsys
The helper function _nvme_connect_subsys() creates a nvme device. It may take some time after the function call until the device gets ready for I/O. So it is expected that the test cases call _find_nvme_dev() after _nvme_connect_subsys() before I/O. _find_nvme_dev() returns the path of the created device, and it also waits for uuid and wwid sysfs attributes of the created device get ready. This wait works as the wait for the device I/O readiness. However, this wait by _find_nvme_dev() has two problems. The first problem is missing call of _find_nvme_dev(). The test case nvme/047 calls _nvme_connect_subsys() twice, but _find_nvme_dev() is called only for the first _nvme_connect_subsys() call. This causes too early I/O to the device with tcp transport [1]. Fix this by moving the wait for the device readiness from _find_nvme_dev() to _nvme_connect_subsys(). Also add --no-wait option to _nvme_connect_subsys(). It allows to skip the wait in _nvmet_passthru_target_connect() which has its own wait for device readiness. The second problem is wrong paths for the sysfs attributes. The paths do not include namespace index, so the check for the attributes always fail. Still _find_nvme_dev() does 1 second wait and allows the device get ready for I/O in most cases, but this is not intended behavior. Fix this by checking sysfs paths with the namespace index. Get list of namespace indices for the sub-system and do the check for all indices. On top of the checks for sysfs attributes, add 'udevadm settle' and a check for the created device file. These ensures that the create device is ready for I/O. [1] https://lore.kernel.org/linux-block/CAHj4cs9GNohGUjohNw93jrr8JGNcRYC-ienAZz+sa7az1RK77w@mail.gmail.com/ Fixes: c766fcc ("Make the NVMe tests more reliable") Reviewed-by: Daniel Wagner <[email protected]> Signed-off-by: Shin'ichiro Kawasaki <[email protected]>
1 parent 2866494 commit 8fc8eb1

1 file changed

Lines changed: 34 additions & 8 deletions

File tree

  • tests/nvme

tests/nvme/rc

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,8 @@ _nvme_connect_subsys() {
428428
local keep_alive_tmo=""
429429
local reconnect_delay=""
430430
local ctrl_loss_tmo=""
431+
local no_wait=false
432+
local i
431433

432434
while [[ $# -gt 0 ]]; do
433435
case $1 in
@@ -483,6 +485,10 @@ _nvme_connect_subsys() {
483485
ctrl_loss_tmo="$2"
484486
shift 2
485487
;;
488+
--no-wait)
489+
no_wait=true
490+
shift 1
491+
;;
486492
*)
487493
positional_args+=("$1")
488494
shift
@@ -532,6 +538,33 @@ _nvme_connect_subsys() {
532538
fi
533539

534540
nvme connect "${ARGS[@]}" 2> /dev/null
541+
542+
# Wait until device file and uuid/wwid sysfs attributes get ready for
543+
# all namespaces.
544+
if [[ ${no_wait} = false ]]; then
545+
udevadm settle
546+
for ((i = 0; i < 10; i++)); do
547+
_nvme_ns_ready "${subsysnqn}" && return
548+
sleep .1
549+
done
550+
fi
551+
}
552+
553+
_nvme_ns_ready() {
554+
local subsysnqn="${1}"
555+
local ns_path ns_id dev
556+
local cfs_path="${NVMET_CFS}/subsystems/$subsysnqn"
557+
558+
dev=$(_find_nvme_dev "$subsysnqn")
559+
for ns_path in "${cfs_path}/namespaces/"*; do
560+
ns_id=${ns_path##*/}
561+
if [[ ! -b /dev/${dev}n${ns_id} ||
562+
! -e /sys/block/${dev}n${ns_id}/uuid ||
563+
! -e /sys/block/${dev}n${ns_id}/wwid ]]; then
564+
return 1
565+
fi
566+
done
567+
return 0
535568
}
536569

537570
_nvme_discover() {
@@ -758,13 +791,6 @@ _find_nvme_dev() {
758791
subsysnqn="$(cat "/sys/class/nvme/${dev}/subsysnqn")"
759792
if [[ "$subsysnqn" == "$subsys" ]]; then
760793
echo "$dev"
761-
for ((i = 0; i < 10; i++)); do
762-
if [[ -e /sys/block/$dev/uuid &&
763-
-e /sys/block/$dev/wwid ]]; then
764-
return
765-
fi
766-
sleep .1
767-
done
768794
fi
769795
done
770796
}
@@ -794,7 +820,7 @@ _nvmet_passthru_target_connect() {
794820
local trtype=$1
795821
local subsys_name=$2
796822

797-
_nvme_connect_subsys "${trtype}" "${subsys_name}" || return
823+
_nvme_connect_subsys "${trtype}" "${subsys_name}" --no-wait || return
798824
nsdev=$(_find_nvme_passthru_loop_dev "${subsys_name}")
799825

800826
# The following tests can race with the creation

0 commit comments

Comments
 (0)