Count link and syscall failures instead of printing them

This commit is contained in:
flamingcow
2026-07-25 22:54:04 -07:00
parent 1b322bb32b
commit 0f16edfe61
5 changed files with 68 additions and 142 deletions
+6 -31
View File
@@ -6,7 +6,6 @@ import (
"os"
"path/filepath"
"strings"
"time"
"unsafe"
"golang.org/x/sys/unix"
@@ -380,24 +379,6 @@ func checkLinkUp(fd int, ifname string) checkResult {
return res
}
func checkCarrier(ifname string, wait time.Duration) checkResult {
res := checkResult{item: ifname + " carrier"}
deadline := time.Now().Add(wait)
for {
v, ok := readUint("/sys/class/net/" + ifname + "/carrier")
if ok && v == 1 {
res.state = "present"
return res
}
if time.Now().After(deadline) {
res.err = fmt.Errorf("no carrier after %s", wait)
res.fatal = true
return res
}
time.Sleep(100 * time.Millisecond)
}
}
func checkCoalesce(fd int, ifname string, rxUsecs, txUsecs uint32) checkResult {
res := checkResult{item: ifname + " coalesce"}
ec, err := getCoalesce(fd, ifname)
@@ -430,18 +411,18 @@ func checkCoalesce(fd int, ifname string, rxUsecs, txUsecs uint32) checkResult {
return res
}
func checkRings(fd int, ifname string, rxWant, txWant uint32) (checkResult, bool) {
func checkRings(fd int, ifname string, rxWant, txWant uint32) checkResult {
res := checkResult{item: ifname + " rings"}
rp, err := getRings(fd, ifname)
if err != nil {
res.err = err
return res, false
return res
}
rx := min(rxWant, rp.rxMaxPending)
tx := min(txWant, rp.txMaxPending)
if rp.rxPending == rx && rp.txPending == tx {
res.state = fmt.Sprintf("rx=%d tx=%d", rp.rxPending, rp.txPending)
return res, false
return res
}
was := fmt.Sprintf("rx=%d tx=%d", rp.rxPending, rp.txPending)
rp.cmd = unix.ETHTOOL_SRINGPARAM
@@ -450,11 +431,11 @@ func checkRings(fd int, ifname string, rxWant, txWant uint32) (checkResult, bool
if err := ethtoolCall(fd, ifname, unsafe.Pointer(&rp)); err != nil {
res.err = err
res.state = "could not set"
return res, false
return res
}
res.fixed = true
res.state = fmt.Sprintf("was %s, now rx=%d tx=%d (link reset)", was, rx, tx)
return res, true
return res
}
func withIoctlSocket(fn func(fd int) []checkResult) []checkResult {
@@ -475,13 +456,7 @@ func configureSystem(ifnames []string, ethertypes []uint16) []checkResult {
// Ring changes reprogram the queues, so flow rules pointing at those
// queues have to be installed afterwards.
carrierWait := 3 * time.Second
ringRes, ringReset := checkRings(fd, ifname, wantRxRing, wantTxRing)
out = append(out, ringRes)
if ringReset {
carrierWait = 10 * time.Second
}
out = append(out, checkCarrier(ifname, carrierWait))
out = append(out, checkRings(fd, ifname, wantRxRing, wantTxRing))
out = append(out, checkCoalesce(fd, ifname, wantCoalesceUsecs, wantCoalesceUsecs))
out = append(out, checkTimestamping(fd, ifname))
out = append(out, checkFlowRules(fd, ifname, ethertypes))