]> www.infradead.org Git - users/sagi/blktests.git/commitdiff
nvme/rc: Avoid triggering host nvme-cli autoconnect
authorDaniel Wagner <dwagner@suse.de>
Mon, 3 Jul 2023 09:16:46 +0000 (11:16 +0200)
committerShin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Mon, 10 Jul 2023 02:07:58 +0000 (11:07 +0900)
When the host has enabled the udev/systemd autoconnect services for the
fc transport it interacts with blktests and make tests break.

nvme-cli learned to ignore connects attemps when using the --context
command line option paired with a volatile configuration. Thus we can
mark all the resources created by blktests and avoid any interaction
with the systemd autoconnect scripts.

Only enabled this for the fc transport.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
tests/nvme/rc

index 1c2c2fab62c192be68aeec11d2ecae663e823fe2..9b5442b2c07ba75a5ef811db4b9341586d36c21c 100644 (file)
@@ -176,6 +176,57 @@ _nvme_calc_rand_io_size() {
        echo "${io_size_kb}k"
 }
 
+_have_nvme_cli_context() {
+       # ignore all non-fc transports for now
+       if [[ "${nvme_trtype}" != "fc" ]] ||
+          ! nvme connect --help 2>&1 | grep -q -- '--context=<STR>' > /dev/null; then
+               return 1
+       fi
+       return 0
+}
+
+_setup_nvme_cli() {
+       local local_wwnn="${1}"
+       local local_wwpn="${2}"
+       local remote_wwnn="${3}"
+       local remote_wwpn="${4}"
+
+       if ! _have_nvme_cli_context; then
+               return
+       fi
+
+       mkdir -p /run/nvme
+       cat >> /run/nvme/blktests.json <<-EOF
+       [
+         {
+           "hostnqn": "${def_hostnqn}",
+           "hostid": "${def_hostid}",
+           "subsystems": [
+             {
+               "application": "blktests",
+               "nqn": "blktests-subsystem-1",
+               "ports": [
+                 {
+                   "transport": "fc",
+                   "traddr": "nn-${remote_wwnn}:pn-${remote_wwpn}",
+                   "host_traddr": "nn-${local_wwnn}:pn-${local_wwpn}"
+                 }
+               ]
+             }
+           ]
+         }
+       ]
+       EOF
+}
+
+_cleanup_nvme_cli() {
+       if ! _have_nvme_cli_context; then
+               return
+       fi
+
+       rm -f /run/nvme/blktests.json
+}
+
 _nvme_fcloop_add_rport() {
        local local_wwnn="$1"
        local local_wwpn="$2"
@@ -208,6 +259,9 @@ _setup_fcloop() {
        local remote_wwnn="${3:-$def_remote_wwnn}"
        local remote_wwpn="${4:-$def_remote_wwpn}"
 
+       _setup_nvme_cli "${local_wwnn}" "${local_wwpn}" \
+                       "${remote_wwnn}" "${remote_wwpn}"
+
        _nvme_fcloop_add_tport "${remote_wwnn}" "${remote_wwpn}"
        _nvme_fcloop_add_lport "${local_wwnn}" "${local_wwpn}"
        _nvme_fcloop_add_rport "${local_wwnn}" "${local_wwpn}" \
@@ -250,6 +304,8 @@ _cleanup_fcloop() {
        _nvme_fcloop_del_lport "${local_wwnn}" "${local_wwpn}"
        _nvme_fcloop_del_rport "${local_wwnn}" "${local_wwpn}" \
                               "${remote_wwnn}" "${remote_wwpn}"
+
+       _cleanup_nvme_cli
 }
 
 _cleanup_nvmet() {
@@ -452,6 +508,9 @@ _nvme_connect_subsys() {
        subsysnqn="$2"
 
        ARGS=(-t "${trtype}" -n "${subsysnqn}")
+       if _have_nvme_cli_context; then
+               ARGS+=(--context="blktests")
+       fi
        if [[ "${trtype}" == "fc" ]] ; then
                ARGS+=(-a "${traddr}" -w "${host_traddr}")
        elif [[ "${trtype}" != "loop" ]]; then
@@ -496,6 +555,9 @@ _nvme_discover() {
        ARGS=(-t "${trtype}")
        ARGS+=(--hostnqn="${def_hostnqn}")
        ARGS+=(--hostid="${def_hostid}")
+       if _have_nvme_cli_context; then
+               ARGS+=(--context="blktests")
+       fi
        if [[ "${trtype}" = "fc" ]]; then
                ARGS+=(-a "${traddr}" -w "${host_traddr}")
        elif [[ "${trtype}" != "loop" ]]; then