From c6d4d1d667a7b00808a1624e425ab1223d4a56b4 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Wed, 8 Feb 2023 11:56:36 +0100 Subject: [PATCH] fix(nvmf): move connect logic to initqueue script Rather than trying to connect immediately from parse-nvmf-boot-connections.sh, move the connect logic to an initqueue script which is called at various stages (settle, online, and timeout). In the timeout case, just try every possible connection. Otherwise, use the existing priority logic. Also, make sure that the initqueue script doesn't call exit(). --- modules.d/95nvmf/nvmf-autoconnect.sh | 34 +++++++++++++++++-- .../95nvmf/parse-nvmf-boot-connections.sh | 23 +++---------- 2 files changed, 36 insertions(+), 21 deletions(-) diff --git a/modules.d/95nvmf/nvmf-autoconnect.sh b/modules.d/95nvmf/nvmf-autoconnect.sh index c8f676a74b..afaa569b22 100755 --- a/modules.d/95nvmf/nvmf-autoconnect.sh +++ b/modules.d/95nvmf/nvmf-autoconnect.sh @@ -1,5 +1,33 @@ -#!/bin/bash +#!/bin/sh +# Argument $1 is "settled", "online", or "timeout", indicating +# the queue from which the script is called. +# In the "timeout" case, try everything. +# Otherwise, try options according to the priorities below. -[ -f /sys/class/fc/fc_udev_device/nvme_discovery ] || exit 1 -echo add > /sys/class/fc/fc_udev_device/nvme_discovery +[ "$RD_DEBUG" != yes ] || set -x + +NVMF_HOSTNQN_OK= +[ ! -f "/etc/nvme/hostnqn" ] || [ ! -f "/etc/nvme/hostid" ] || NVMF_HOSTNQN_OK=1 + +if [ -e /tmp/nvmf-fc-auto ] && [ "$NVMF_HOSTNQN_OK" ] && + [ -f /sys/class/fc/fc_udev_device/nvme_discovery ]; then + # prio 1: cmdline override "rd.nvmf.discovery=fc,auto" + echo add >/sys/class/fc/fc_udev_device/nvme_discovery + [ "$1" = timeout ] || exit 0 +fi +if [ -e /tmp/valid_nbft_entry_found ]; then + # prio 2: NBFT + /usr/sbin/nvme connect-nbft + [ "$1" = timeout ] || exit 0 +fi +if [ -f /etc/nvme/discovery.conf ] && [ $NVMF_HOSTNQN_OK ]; then + # prio 3: discovery.conf from initrd + /usr/sbin/nvme connect-all + [ "$1" = timeout ] || exit 0 +fi +if [ "$NVMF_HOSTNQN_OK" ] && + [ -f /sys/class/fc/fc_udev_device/nvme_discovery ]; then + # prio 4: no discovery entries, try NVMeoFC autoconnect + echo add >/sys/class/fc/fc_udev_device/nvme_discovery +fi exit 0 diff --git a/modules.d/95nvmf/parse-nvmf-boot-connections.sh b/modules.d/95nvmf/parse-nvmf-boot-connections.sh index da45437002..85e2c7cd5d 100755 --- a/modules.d/95nvmf/parse-nvmf-boot-connections.sh +++ b/modules.d/95nvmf/parse-nvmf-boot-connections.sh @@ -301,10 +301,10 @@ if [ -n "$nvmf_hostid" ]; then echo "$nvmf_hostid" > /etc/nvme/hostid fi -NVMF_FC_AUTO= +rm -f /tmp/nvmf-fc-auto for d in $(getargs rd.nvmf.discover -d nvmf.discover=); do parse_nvmf_discover "$d" || { - NVMF_FC_AUTO=1 + : > /tmp/nvmf-fc-auto break } done @@ -314,19 +314,6 @@ if [ -e /tmp/nvmf_needs_network ] || [ -e /tmp/valid_nbft_entry_found ]; then rm -f /tmp/nvmf_needs_network fi -NVMF_HOSTNQN_OK= -[ ! -f "/etc/nvme/hostnqn" ] || [ ! -f "/etc/nvme/hostid" ] || NVMF_HOSTNQN_OK=1 - -if [ $NVMF_FC_AUTO ] && [ $NVMF_HOSTNQN_OK ]; then - # prio 1: cmdline override "rd.nvmf.discovery=fc,auto" - /sbin/initqueue --settled --onetime --unique --name nvme-fc-autoconnect /sbin/nvmf-autoconnect.sh -elif [ -e /tmp/valid_nbft_entry_found ]; then - # prio 2: NBFT - /sbin/initqueue --settled --onetime --unique --name nvme-connect-nbft /usr/sbin/nvme connect-nbft -elif [ -f /etc/nvme/discovery.conf ] && [ $NVMF_HOSTNQN_OK ]; then - # prio 3: discovery.conf from initrd - /sbin/initqueue --settled --onetime --unique --name nvme-discover /usr/sbin/nvme connect-all -elif [ $NVMF_HOSTNQN_OK ]; then - # prio 4: no discovery entries, try NVMeoFC autoconnect - /sbin/initqueue --settled --onetime --unique --name nvme-fc-autoconnect /sbin/nvmf-autoconnect.sh -fi +/sbin/initqueue --online --name nvmf-connect-online /sbin/nvmf-autoconnect.sh online +/sbin/initqueue --settled --onetime --name nvmf-connect-settled /sbin/nvmf-autoconnect.sh settled +/sbin/initqueue --timeout --onetime --name nvmf-connect-timeout /sbin/nvmf-autoconnect.sh timeout