Merged
perf(orchestrator): use a single NBD connection per device on Linux 4.19 #240
perf(orchestrator): use a single NBD connection per device on Linux 4.19 #240
Merged
xhmljaAdd on Oct 26
Total: 5 files changed+118-2
Apackages/orchestrator/internal/sandbox/nbd/connections_test.go+31-0File content is under review, please try again later
Mpackages/orchestrator/internal/sandbox/nbd/path_direct.go+19-1File content is under review, please try again later
@@ -57,6 +57,7 @@ require (
57 golang.org/x/mod v0.31.057 golang.org/x/mod v0.31.0
58 golang.org/x/oauth2 v0.34.058 golang.org/x/oauth2 v0.34.0
59 golang.org/x/sync v0.19.059 golang.org/x/sync v0.19.0
60+ golang.org/x/sys v0.40.0
60 google.golang.org/api v0.257.061 google.golang.org/api v0.257.0
61 google.golang.org/grpc v1.78.062 google.golang.org/grpc v1.78.0
62 google.golang.org/protobuf v1.36.1163 google.golang.org/protobuf v1.36.11
@@ -381,7 +382,6 @@ require (
381 golang.org/x/crypto v0.47.0 // indirect382 golang.org/x/crypto v0.47.0 // indirect
382 golang.org/x/exp v0.0.0-20250808145144-a408d31f581a // indirect383 golang.org/x/exp v0.0.0-20250808145144-a408d31f581a // indirect
383 golang.org/x/net v0.49.0 // indirect384 golang.org/x/net v0.49.0 // indirect
384- golang.org/x/sys v0.40.0 // indirect
385 golang.org/x/term v0.39.0 // indirect385 golang.org/x/term v0.39.0 // indirect
386 golang.org/x/text v0.33.0 // indirect386 golang.org/x/text v0.33.0 // indirect
387 golang.org/x/time v0.14.0 // indirect387 golang.org/x/time v0.14.0 // indirect
@@ -0,0 +1,32 @@
1+// Package hostkernel reports facts about the kernel the current process
2+// runs on. Linux 4.19 specific workarounds check IsLinux419 so that other
3+// kernels keep the upstream behavior.
4+package hostkernel
5+ 
6+import (
7+ "strings"
8+ "sync"
9+ 
10+ "golang.org/x/sys/unix"
11+)
12+ 
13+// IsLinux419 reports whether the host kernel is Linux 4.19 (e.g. openEuler
14+// 20.03 LTS). The result is computed once and cached.
15+func IsLinux419() bool {
16+ return isLinux419()
17+}
18+ 
19+var isLinux419 = sync.OnceValue(func() bool {
20+ var uts unix.Utsname
21+ if err := unix.Uname(&uts); err != nil {
22+ return false
23+ }
24+ 
25+ return isLinux419Release(unix.ByteSliceToString(uts.Release[:]))
26+})
27+ 
28+// isLinux419Release reports whether a kernel release string, as printed by
29+// `uname -r`, belongs to Linux 4.19.
30+func isLinux419Release(release string) bool {
31+ return release == "4.19" || strings.HasPrefix(release, "4.19.")
32+}
@@ -0,0 +1,35 @@
1+package hostkernel
2+ 
3+import (
4+ "testing"
5+ 
6+ "github.com/stretchr/testify/assert"
7+)
8+ 
9+func TestIsLinux419Release(t *testing.T) {
10+ t.Parallel()
11+ 
12+ tests := []struct {
13+ release string
14+ want bool
15+ }{
16+ {"4.19", true},
17+ {"4.19.0", true},
18+ {"4.19.90-2112.8.0.0131.oe1.aarch64", true},
19+ {"4.19.90-89.11.v2401.ky10.aarch64", true},
20+ {"4.190", false},
21+ {"4.1", false},
22+ {"14.19.1", false},
23+ {"5.10.0-60.18.0.50.oe2203.aarch64", false},
24+ {"6.6.0-145.0.13.139.oe2403.aarch64", false},
25+ {"", false},
26+ }
27+ 
28+ for _, tt := range tests {
29+ t.Run(tt.release, func(t *testing.T) {
30+ t.Parallel()
31+ 
32+ assert.Equal(t, tt.want, isLinux419Release(tt.release))
33+ })
34+ }
35+}