]> git.ipfire.org Git - thirdparty/dracut.git/blob - modules.d/95nvmf/nvmf-autoconnect.sh
feat(nvmf): add code for parsing the NBFT
[thirdparty/dracut.git] / modules.d / 95nvmf / nvmf-autoconnect.sh
1 #!/bin/sh
2 # Argument $1 is "settled", "online", or "timeout", indicating
3 # the queue from which the script is called.
4 # In the "timeout" case, try everything.
5 # Otherwise, try options according to the priorities below.
6
7 [ "$RD_DEBUG" != yes ] || set -x
8
9 if [ "$1" = timeout ]; then
10 [ ! -f /sys/class/fc/fc_udev_device/nvme_discovery ] \
11 || echo add > /sys/class/fc/fc_udev_device/nvme_discovery
12 /usr/sbin/nvme connect-all
13 exit 0
14 fi
15
16 NVMF_HOSTNQN_OK=
17 [ ! -f "/etc/nvme/hostnqn" ] || [ ! -f "/etc/nvme/hostid" ] || NVMF_HOSTNQN_OK=1
18
19 # Only nvme-cli 2.5 or newer supports the options --nbft and --no-nbft
20 # for the connect-all command.
21 # Make sure we don't use unsupported options with earlier versions.
22 NBFT_SUPPORTED=
23 # shellcheck disable=SC2016
24 /usr/sbin/nvme connect-all --help 2>&1 | sed -n '/[[:space:]]--nbft[[:space:]]/q1;$q0' \
25 || NBFT_SUPPORTED=1
26
27 if [ -e /tmp/nvmf-fc-auto ] && [ "$NVMF_HOSTNQN_OK" ] \
28 && [ -f /sys/class/fc/fc_udev_device/nvme_discovery ]; then
29 # prio 1: cmdline override "rd.nvmf.discovery=fc,auto"
30 echo add > /sys/class/fc/fc_udev_device/nvme_discovery
31 exit 0
32 fi
33 if [ "$NBFT_SUPPORTED" ] && [ -e /tmp/valid_nbft_entry_found ]; then
34 # prio 2: NBFT
35 /usr/sbin/nvme connect-all --nbft
36 exit 0
37 fi
38 if [ -f /etc/nvme/discovery.conf ] || [ -f /etc/nvme/config.json ] \
39 && [ "$NVMF_HOSTNQN_OK" ]; then
40 # prio 3: configuration from initrd and/or kernel command line
41 # We can get here even if "rd.nvmf.nonbft" was given, thus use --no-nbft
42 if [ "$NBFT_SUPPORTED" ]; then
43 /usr/sbin/nvme connect-all --no-nbft
44 else
45 /usr/sbin/nvme connect-all
46 fi
47 exit 0
48 fi
49 if [ "$NVMF_HOSTNQN_OK" ] \
50 && [ -f /sys/class/fc/fc_udev_device/nvme_discovery ]; then
51 # prio 4: no discovery entries, try NVMeoFC autoconnect
52 echo add > /sys/class/fc/fc_udev_device/nvme_discovery
53 fi
54 exit 0