1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
#!/bin/bash
# called by dracut
check() {
local -A nvmf_trtypes
require_binaries nvme jq || return 1
require_kernel_modules nvme_fabrics || return 1
# shellcheck disable=SC2317,SC2329 # called later by for_each_host_dev_and_slaves
is_nvmf() {
local _dev=$1
local trtype
[[ -L "/sys/dev/block/$_dev" ]] || return 0
cd -P "/sys/dev/block/$_dev" || return 0
if [ -f partition ]; then
cd ..
fi
for d in device/nvme*; do
[ -L "$d" ] || continue
if readlink "$d" | grep -q nvme-fabrics; then
read -r trtype < "$d"/transport
break
fi
done
if [[ $trtype == "fc" ]] || [[ $trtype == "tcp" ]] || [[ $trtype == "rdma" ]]; then
nvmf_trtypes["nvme_${trtype}"]=1
return 0
else
return 1
fi
}
has_nbft() {
local f found=
for f in /sys/firmware/acpi/tables/NBFT*; do
[ -f "$f" ] || continue
found=1
break
done
[[ $found ]]
}
[[ $hostonly_mode == "strict" ]] || [[ $mount_needs ]] && {
[ -f /etc/nvme/hostnqn ] || return 255
[ -f /etc/nvme/hostid ] || return 255
pushd . > /dev/null
for_each_host_dev_and_slaves is_nvmf
local _is_nvmf=$?
popd > /dev/null || exit
[[ $_is_nvmf == 0 ]] || return 255
require_kernel_modules "${!nvmf_trtypes[@]}" || return 1
if [ ! -f /sys/class/fc/fc_udev_device/nvme_discovery ] \
&& [ ! -f /etc/nvme/discovery.conf ] \
&& [ ! -f /etc/nvme/config.json ] && ! has_nbft; then
echo "No discovery arguments present"
return 255
fi
}
return 0
}
# called by dracut
depends() {
echo rootfs-block network initqueue
return 0
}
# called by dracut
installkernel() {
hostonly=$(optional_hostonly) instmods nvme_fc nvme_tcp nvme_rdma lpfc qla2xxx
# 802.1q VLAN may be set up in Firmware later. Include the module always.
hostonly="" instmods 8021q
}
# called by dracut
cmdline() {
local _hostnqn
local _hostid
# shellcheck disable=SC2317,SC2329 # called later by for_each_host_dev_and_slaves
gen_nvmf_cmdline() {
local _dev=$1
local trtype
local traddr
local host_traddr
local trsvcid
local _address
local -a _address_parts
[[ -L "/sys/dev/block/$_dev" ]] || return 0
cd -P "/sys/dev/block/$_dev" || return 0
if [ -f partition ]; then
cd ..
fi
for d in device/nvme*; do
[ -L "$d" ] || continue
if readlink "$d" | grep -q nvme-fabrics; then
read -r trtype < "$d"/transport
break
fi
done
[ -z "$trtype" ] && return 0
nvme list-subsys "${PWD##*/}" | while read -r _ _ trtype _address _; do
[[ -z $trtype || $trtype != "${trtype#NQN}" ]] && continue
unset traddr
unset host_traddr
unset trsvcid
mapfile -t -d ',' _address_parts < <(printf "%s" "$_address")
for i in "${_address_parts[@]}"; do
[[ $i =~ ^traddr= ]] && traddr="${i#traddr=}"
[[ $i =~ ^host_traddr= ]] && host_traddr="${i#host_traddr=}"
[[ $i =~ ^trsvcid= ]] && trsvcid="${i#trsvcid=}"
done
[[ -z $traddr && -z $host_traddr && -z $trsvcid ]] && continue
echo -n " rd.nvmf.discover=$trtype,$traddr,$host_traddr,$trsvcid"
done
}
if [ -f /etc/nvme/hostnqn ]; then
read -r _hostnqn < /etc/nvme/hostnqn
echo -n " rd.nvmf.hostnqn=${_hostnqn}"
fi
if [ -f /etc/nvme/hostid ]; then
read -r _hostid < /etc/nvme/hostid
echo -n " rd.nvmf.hostid=${_hostid}"
fi
[[ ${hostonly-} ]] || [[ $mount_needs ]] && {
pushd . > /dev/null
for_each_host_dev_and_slaves gen_nvmf_cmdline
popd > /dev/null || exit
}
}
# called by dracut
install() {
if [[ $hostonly_cmdline == "yes" ]]; then
local _nvmf_args
_nvmf_args=$(cmdline)
[[ "$_nvmf_args" ]] && printf "%s" "$_nvmf_args" >> "${initdir}/etc/cmdline.d/95nvmf-args.conf"
fi
inst_simple -H "/etc/nvme/hostnqn"
inst_simple -H "/etc/nvme/hostid"
inst_multiple ip sed
inst_script "${moddir}/nvmf-autoconnect.sh" /sbin/nvmf-autoconnect.sh
inst_script "${moddir}/nbftroot.sh" /sbin/nbftroot
inst_multiple nvme jq
inst_hook cmdline 92 "$moddir/parse-nvmf-boot-connections.sh"
inst_simple "/etc/nvme/discovery.conf"
inst_simple "/etc/nvme/config.json"
inst_rules /usr/lib/udev/rules.d/71-nvmf-iopolicy-netapp.rules
inst_rules "$moddir/95-nvmf-initqueue.rules"
}
|