Skip to content

Commit 29e7561

Browse files
tbv 0.2.14: rail addr helper resolves live ifname via XDomain parent (udev rename race)
udev renames u4r<N> -> tbr-<peer> BEFORE running RUN+=, so the passed kernel name is already stale and the helper bailed (rail got no per-link /64, only fe80::). Resolve the XDomain parent device from DEVPATH (stable across rename) and read the current ifname back out of <xdomain>/net. Validated on appmana-018: both rails now carry a routable fd../64 RoCE GID (usb4_rdma5 fd67:..::1, usb4_rdma15 fd72:..::1).
1 parent d561da6 commit 29e7561

2 files changed

Lines changed: 24 additions & 19 deletions

File tree

drivers/thunderbolt_ibverbs/dkms.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PACKAGE_NAME="thunderbolt-ibverbs"
2-
PACKAGE_VERSION="0.2.13"
2+
PACKAGE_VERSION="0.2.14"
33

44
BUILT_MODULE_NAME[0]="thunderbolt_ibverbs"
55
BUILT_MODULE_LOCATION[0]="kernel"

drivers/thunderbolt_ibverbs/packaging/udev/tbv-rdma-addr

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,47 @@
22
# tbv-rdma-addr <ifname> -- assign the deterministic per-link routable /64 to a
33
# usb4_rdma GID-only rail netdev, so both ends of a cabled link share a subnet.
44
# Invoked from udev (RUN+=) after the rail netdev appears, and safe to re-run by
5-
# hand. Pure derivation lives in tbv-rdma-addr-lib.sh; this only does the sysfs
5+
# hand. Pure derivation lives in tbv-rdma-addr-lib.sh; this does the sysfs
66
# lookups and the `ip` assignment.
77
#
88
# The rail netdev is parented (SET_NETDEV_DEV) to its XDomain *device* (e.g.
99
# "0-1"), whose unique_id is the remote peer's host-router UUID. The local
1010
# host-router UUID is "<domain>-0" in the same thunderbolt domain. Both ends
1111
# therefore hold the same unordered UUID pair -> the same /64 (see the lib).
12+
#
13+
# udev renames the netdev (u4r<N> -> tbr-<peer>) BEFORE running RUN+=, so the
14+
# passed kernel name is stale by the time we run. We therefore resolve the live
15+
# interface from the stable XDomain parent device (via DEVPATH), not the name.
1216
set -eu
17+
export PATH=/usr/sbin:/usr/bin:/sbin:/bin:${PATH:-}
1318

1419
LIB="$(dirname "$0")/tbv-rdma-addr-lib.sh"
1520
[ -r "$LIB" ] || LIB=/usr/lib/thunderbolt-ibverbs/tbv-rdma-addr-lib.sh
1621
. "$LIB"
1722

1823
ifc="${1:-}"
19-
[ -n "$ifc" ] || exit 0
20-
21-
# Resolve the netdev's parent device, tolerating a concurrent udev rename: prefer
22-
# the passed name, fall back to udev's DEVPATH for this uevent.
23-
dev="$(readlink -f "/sys/class/net/${ifc}/device" 2>/dev/null || true)"
24-
if [ -z "${dev}" ] && [ -n "${DEVPATH:-}" ]; then
25-
dev="$(readlink -f "/sys${DEVPATH}/device" 2>/dev/null || true)"
24+
xdev=""
25+
# Prefer the passed name if it still resolves; else recover the XDomain parent
26+
# from DEVPATH (stable across the rename) and read the live name back out of it.
27+
if [ -n "$ifc" ] && [ -e "/sys/class/net/${ifc}/device" ]; then
28+
xdev="$(readlink -f "/sys/class/net/${ifc}/device" 2>/dev/null || true)"
29+
elif [ -n "${DEVPATH:-}" ]; then
30+
xdev="$(readlink -f "/sys${DEVPATH%/net/*}" 2>/dev/null || true)"
31+
[ -n "$xdev" ] && ifc="$(ls "${xdev}/net" 2>/dev/null | head -n1)"
2632
fi
27-
[ -n "${dev}" ] || exit 0
33+
[ -n "$xdev" ] && [ -n "$ifc" ] && [ -e "/sys/class/net/${ifc}" ] || exit 0
2834

29-
remote="$(cat "${dev}/unique_id" 2>/dev/null || true)"
30-
[ -n "${remote}" ] || exit 0 # not an XDomain-parented rail
35+
remote="$(cat "${xdev}/unique_id" 2>/dev/null || true)"
36+
[ -n "$remote" ] || exit 0 # not an XDomain-parented rail
3137

32-
xname="$(basename "${dev}")" # e.g. 0-1
33-
domain="${xname%%-*}" # e.g. 0
38+
domain="$(basename "$xdev")"; domain="${domain%%-*}"
3439
local="$(cat "/sys/bus/thunderbolt/devices/${domain}-0/unique_id" 2>/dev/null || true)"
35-
[ -n "${local}" ] || exit 0
40+
[ -n "$local" ] || exit 0
3641

37-
addr="$(tbv_link_addr "${local}" "${remote}")"
42+
addr="$(tbv_link_addr "$local" "$remote")"
3843

3944
# nodad: link-local DAD is pointless on a point-to-point GID-only netdev and only
4045
# adds latency before the GID appears. `replace` keeps the helper idempotent.
41-
ip -6 addr replace "${addr}" dev "${ifc}" nodad 2>/dev/null || \
42-
ip -6 addr replace "${addr}" dev "${ifc}"
43-
ip link set "${ifc}" up
46+
ip -6 addr replace "$addr" dev "$ifc" nodad 2>/dev/null || \
47+
ip -6 addr replace "$addr" dev "$ifc"
48+
ip link set "$ifc" up

0 commit comments

Comments
 (0)