43 lines
1.8 KiB
Bash
43 lines
1.8 KiB
Bash
#!/bin/bash
|
|
# nvmf-connect.sh — initqueue/online hook (fires when a NIC comes online).
|
|
#
|
|
# TEST MODE ONLY (rd.dot1x=0): drive the NVMe-oF root connect here.
|
|
# This distro's dracut `nvmf` module parses rd.nvmf.discover into
|
|
# /etc/nvme/discovery.conf but registers NO autoconnect hook (initqueue/online/
|
|
# ships empty), and a job placed on the MAIN initqueue is not re-executed once
|
|
# the loop blocks waiting on udev events — so `nvme connect-all` otherwise never
|
|
# runs, the root namespace never appears, and boot spins on /dev/mapper/root
|
|
# forever. initqueue/online is the correct, event-driven place: network-legacy
|
|
# sources these hooks once DHCP is bound, so the link is guaranteed up here.
|
|
# Idempotent via a stamp; connect-all is itself safe to re-run, and on failure
|
|
# we leave the stamp unset so the next online event retries.
|
|
#
|
|
# The secure path (rd.dot1x unset/!=0) connects over macsec0 from its own flow
|
|
# in dot1x-macsec-up.sh and must NOT connect over the physical link here.
|
|
|
|
type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
|
|
|
|
[ "$(getarg rd.dot1x=)" = "0" ] || exit 0
|
|
[ -e /run/dot1x/.nvmf-connected ] && exit 0
|
|
|
|
_disc=$(getarg rd.nvmf.discover=) # e.g. tcp,192.168.50.10,4420
|
|
[ -n "$_disc" ] || { warn "nvmf-connect: rd.nvmf.discover not set"; exit 0; }
|
|
_trtype=${_disc%%,*}
|
|
_rest=${_disc#*,}
|
|
_traddr=${_rest%%,*}
|
|
_trsvcid=${_rest##*,}
|
|
|
|
# nvme_tcp is usually auto-loaded, but ensure it so connect-all can't fail on a
|
|
# missing /dev/nvme-fabrics.
|
|
modprobe nvme_tcp 2>/dev/null
|
|
|
|
info "nvmf-connect: nvme connect-all ${_trtype}/${_traddr}/${_trsvcid}"
|
|
if nvme connect-all -t "$_trtype" -a "$_traddr" -s "$_trsvcid"; then
|
|
mkdir -p /run/dot1x
|
|
: > /run/dot1x/.nvmf-connected
|
|
info "nvmf-connect: connected — namespace + by-id link should appear shortly"
|
|
else
|
|
warn "nvmf-connect: connect-all failed; will retry on next online event"
|
|
fi
|
|
exit 0
|