Skip to content

Commit c21e294

Browse files
yizhanglinuxkawasaki
authored andcommitted
common/nvme: add '--no-wait-ns' argument to _nvme_connect_subsys()
The default behavior of _nvme_connect_subsys is just wait for the controller ready. But sometimes the namespace is not ready after _nvme_connect_subsys especially on RT kernel. This triggers failures as reported in the Link. To avoid the failures, make namespace ready in _nvme_connect_subsys. For that purpose, 1) re-use the the function _nvme_ns_ready to check namespace ready 2) add one new argument `--no-wait-ns` to skip for the cases that don't need wait for namespace ready 3) update to use "return 1" for controller failure check and "return 2" for namespace failure check Link: #193 Signed-off-by: Yi Zhang <[email protected]> Reviewed-by: Daniel Wagner <[email protected]> Reviewed-by: Chaitanya Kulkarni <[email protected]> [Shin'ichiro: simplified the commit message] Signed-off-by: Shin'ichiro Kawasaki <[email protected]>
1 parent f939e6e commit c21e294

1 file changed

Lines changed: 35 additions & 4 deletions

File tree

common/nvme

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,13 +284,15 @@ _nvme_connect_subsys() {
284284
local reconnect_delay=""
285285
local ctrl_loss_tmo=""
286286
local no_wait=false
287+
local no_wait_ns=false
287288
local hdr_digest=false
288289
local data_digest=false
289290
local tls=false
290291
local concat=false
291292
local port
292293
local i
293294
local -a ARGS
295+
local ret=0
294296

295297
while [[ $# -gt 0 ]]; do
296298
case $1 in
@@ -346,6 +348,10 @@ _nvme_connect_subsys() {
346348
no_wait=true
347349
shift 1
348350
;;
351+
--no-wait-ns)
352+
no_wait_ns=true
353+
shift 1
354+
;;
349355
--hdr-digest)
350356
hdr_digest=true
351357
shift 1
@@ -432,14 +438,23 @@ _nvme_connect_subsys() {
432438
if [[ ${no_wait} = false ]]; then
433439
local ctrldev
434440

435-
ctrldev=$(echo "${connect}" | sed -n 's/.*device.:.\(nvme[0-9]*\)./\1/p')
441+
ctrldev=$(echo "${connect}" | sed -n 's/.*device.:.\(nvme[0-9]*\)./\1/p')
436442
udevadm settle
437443
for ((i = 0; i < 10; i++)); do
438-
_nvme_ctrl_ready "${ctrldev}" "${subsysnqn}" && return 0
444+
_nvme_ctrl_ready "${ctrldev}" "${subsysnqn}" && break
439445
sleep .1
440446
done
441-
return 1
447+
[ $i -eq 10 ] && ret=1
448+
if [[ ${no_wait_ns} = false ]]; then
449+
for ((i = 0; i < 10; i++)); do
450+
_nvme_ns_ready "${subsysnqn}" && break
451+
sleep .1
452+
done
453+
[ $i -eq 10 ] && ret=2
454+
fi
455+
442456
fi
457+
return "$ret"
443458
}
444459

445460
_nvme_disconnect_subsys() {
@@ -462,7 +477,6 @@ _nvme_disconnect_subsys() {
462477
grep -o "disconnected.*"
463478
}
464479

465-
466480
_nvme_ctrl_ready() {
467481
local ctrldev="${1}"
468482
local subsysnqn="${2:-$def_subsysnqn}"
@@ -476,6 +490,23 @@ _nvme_ctrl_ready() {
476490
return 1
477491
}
478492

493+
_nvme_ns_ready() {
494+
local subsysnqn="${1}"
495+
local ns_path ns_id dev
496+
local cfs_path="${NVMET_CFS}/subsystems/$subsysnqn"
497+
498+
dev=$(_find_nvme_dev "$subsysnqn")
499+
for ns_path in "${cfs_path}/namespaces/"*; do
500+
ns_id=${ns_path##*/}
501+
if [[ ! -b /dev/${dev}n${ns_id} ||
502+
! -e /sys/block/${dev}n${ns_id}/uuid ||
503+
! -e /sys/block/${dev}n${ns_id}/wwid ]]; then
504+
return 1
505+
fi
506+
done
507+
return 0
508+
}
509+
479510
_remote_wwnn() {
480511
local -i port=${1}
481512

0 commit comments

Comments
 (0)