From 83a5260f685fa135df2e96c3b4157287f05b46f6 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Tue, 18 Apr 2023 18:18:31 +0200 Subject: [PATCH] fix(nvmf): autoconnect logic for nvme-cli 2.5 and newer In nvme-cli 2.5, the "nvme connect-nbft" functionality has been included in the "nvme connect-all" command. "connect-all" will now try connecting to NBFT targets, too, unless the --no-nbft option is used. "connect-all --nbft" will attempt connecting to NBFT targets only. Preserve the previous priority logic for the 2.5+ command line syntax. The "timeout" case is simplified, it just attempts a "connect-all" and an FC autoconnect. For the regular connect attempts, the priorities remain as before: 1 FC autoconnect from kernel commandline ("rd.nvmf.discover=fc,auto") 2 NBFT 3 discovery.conf / config.json / hostonly parameters determined at initramfs build time 4 FC autoconnect without kernel command line Note that NBFT settings take precedence over explicit command line settings. To enforce use of (only) kernel command line settings for NVMe-oF, use this: rd.nvmf.nostatic rd.nvmf.nonbft rd.nvmf.discover=... Because nvme-cli 2.5 is not released yet and older versions will be around for some time, check whether the nbft-related options are supported, and fall back to plain "connect-all" if not (this will not connect to NBFT targets). --- modules.d/95nvmf/nvmf-autoconnect.sh | 34 ++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/modules.d/95nvmf/nvmf-autoconnect.sh b/modules.d/95nvmf/nvmf-autoconnect.sh index ab1a9ffa22..35ee9487de 100755 --- a/modules.d/95nvmf/nvmf-autoconnect.sh +++ b/modules.d/95nvmf/nvmf-autoconnect.sh @@ -6,25 +6,45 @@ [ "$RD_DEBUG" != yes ] || set -x +if [ "$1" = timeout ]; then + [ ! -f /sys/class/fc/fc_udev_device/nvme_discovery ] \ + || echo add > /sys/class/fc/fc_udev_device/nvme_discovery + /usr/sbin/nvme connect-all + exit 0 +fi + NVMF_HOSTNQN_OK= [ ! -f "/etc/nvme/hostnqn" ] || [ ! -f "/etc/nvme/hostid" ] || NVMF_HOSTNQN_OK=1 +# Only nvme-cli 2.5 or newer supports the options --nbft and --no-nbft +# for the connect-all command. +# Make sure we don't use unsupported options with earlier versions. +NBFT_SUPPORTED= +# shellcheck disable=SC2016 +/usr/sbin/nvme connect-all --help 2>&1 | sed -n '/[[:space:]]--nbft[[:space:]]/q1;$q0' \ + || NBFT_SUPPORTED=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 + exit 0 fi -if [ -e /tmp/valid_nbft_entry_found ]; then +if [ "$NBFT_SUPPORTED" ] && [ -e /tmp/valid_nbft_entry_found ]; then # prio 2: NBFT - /usr/sbin/nvme connect-all - [ "$1" = timeout ] || exit 0 + /usr/sbin/nvme connect-all --nbft + exit 0 fi if [ -f /etc/nvme/discovery.conf ] || [ -f /etc/nvme/config.json ] \ && [ "$NVMF_HOSTNQN_OK" ]; then - # prio 3: discovery.conf from initrd - /usr/sbin/nvme connect-all - [ "$1" = timeout ] || exit 0 + # prio 3: configuration from initrd and/or kernel command line + # We can get here even if "rd.nvmf.nonbft" was given, thus use --no-nbft + if [ "$NBFT_SUPPORTED" ]; then + /usr/sbin/nvme connect-all --no-nbft + else + /usr/sbin/nvme connect-all + fi + exit 0 fi if [ "$NVMF_HOSTNQN_OK" ] \ && [ -f /sys/class/fc/fc_udev_device/nvme_discovery ]; then