test: keep the NVMe/TCP listener on loopback when the harness listens off loopback

blockvolume refuses a non-loopback frontend listen; the test reaches its
NVMe target only from the same host (user-space client or kernel nvme
connect), so the NVMe address stays 127.0.0.1 (headSzLoopbackAddr) while
data and ctrl use SWBLOCK_TEST_LISTEN_HOST.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
pingqiuandClaude Fable 5.1 committed 2026-11-24 13:29:39 -08:00
1 parent 6f24d3bfbe
commit eb471459de
2 files changed
+30 -2

No files matched your search

@@ -9,6 +9,7 @@ import (
"fmt"
"io"
"math/rand"
"net"
"net/http"
"net/url"
"os"
@@ -217,7 +218,7 @@ func headSzStartCluster(t *testing.T, prefix string, vols []headSzVol) (*handoff
server, replica = v.server, "r1"
}
b := bvHost{id: v.id, server: server, replica: replica, volume: v.id, root: filepath.Join(h.dir, "vol-"+v.id),
data: handoffAddress(t), ctrl: handoffAddress(t), status: handoffAddress(t), nvme: handoffAddress(t)}
data: handoffAddress(t), ctrl: handoffAddress(t), status: handoffAddress(t), nvme: headSzLoopbackAddr(t)}
if v.host != "" {
b.data, b.ctrl = headSzRemoteAddr(t, v.host), headSzRemoteAddr(t, v.host)
}
@@ -244,6 +245,33 @@ func headSzStartCluster(t *testing.T, prefix string, vols []headSzVol) (*handoff
return env, clusterDir
}
// headSzLoopbackAddr picks a free 127.0.0.1 port from the harness's range:
// blockvolume's NVMe/TCP target refuses any non-loopback bind, and the test
// (user-space client or kernel nvme connect) always runs on the same host as
// that blockvolume, also when SWBLOCK_TEST_LISTEN_HOST names a host address.
func headSzLoopbackAddr(t *testing.T) string {
t.Helper()
handoffPorts.Lock()
defer handoffPorts.Unlock()
if handoffPorts.used == nil {
handoffPorts.used = map[int]bool{}
}
for i := 0; i < 500; i++ {
p := 10000 + rand.Intn(10000)
if handoffPorts.used[p] {
continue
}
addr := fmt.Sprintf("127.0.0.1:%d", p)
if ln, err := net.Listen("tcp", addr); err == nil {
ln.Close()
handoffPorts.used[p] = true
return addr
}
}
t.Fatal("no free loopback port")
return ""
}
// headSzRemoteAddr picks host:<port> for a process on another machine from
// the same port range handoffAddress uses, never handing out a port twice.
func headSzRemoteAddr(t *testing.T, host string) string {
@@ -244,7 +244,7 @@ func kzTargetRole(t *testing.T, rep *kzReport, bytes uint64, device bool, run st
rep.ChunkPath = ho.ChunkPath
for _, ht := range ho.Targets {
tb := bvHost{id: ht.Volume, server: ht.Server, replica: "r1", volume: ht.Volume, root: filepath.Join(h.dir, "vol-"+ht.Volume),
data: ht.Data, ctrl: ht.Ctrl, status: handoffAddress(t), nvme: handoffAddress(t)}
data: ht.Data, ctrl: ht.Ctrl, status: handoffAddress(t), nvme: headSzLoopbackAddr(t)}
env.hosts[ht.Volume] = tb
src := kzVolume{Volume: ht.Source, S1Name: ht.S1, Dirty1: ht.Dirty1, Files: ht.Files, Blocks: map[uint64][]byte{}}
for k, v := range ht.Blocks {