Skip to content

Commit

Permalink
fix(nvmf): move connect logic to initqueue script
Browse files Browse the repository at this point in the history
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.

This retry logic is the same that the iscsi module uses.

The nvme connect-nbft command will do "the right thing" when the connections
specified in the NBFT are already established: Already existing connections
will be skipped. Currently nvme-cli will print an error message and exit
with error status even if all targets are already connected. This should be
handled more gracefully on the nvme-cli side.
  • Loading branch information
mwilck authored and johnmeneghini committed Feb 20, 2023
1 parent 628acaa commit 188160b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 21 deletions.
34 changes: 31 additions & 3 deletions modules.d/95nvmf/nvmf-autoconnect.sh
Original file line number Diff line number Diff line change
@@ -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
23 changes: 5 additions & 18 deletions modules.d/95nvmf/parse-nvmf-boot-connections.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit 188160b

Please sign in to comment.