From 4dcbbc934dfa0097ca0039756231bbb4713811e0 Mon Sep 17 00:00:00 2001 From: dawn Date: Fri, 19 Jun 2026 23:10:36 +0300 Subject: [PATCH] spindle/microvm: use consistent qmp sock paths to avoid the AF_UNIX path limit Signed-off-by: dawn --- docker-compose.yml | 4 ++++ spindle/engines/microvm/qemu.go | 24 +++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index ad99a93c..1a0572c3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -151,6 +151,10 @@ services: SPINDLE_MICROVM_PIPELINES_OVERLAY_DIR: /var/lib/spindle/overlays SPINDLE_MICROVM_PIPELINES_AGENT_PORT: "11240" SPINDLE_S3_LOG_BUCKET: "" + SPINDLE_MICROVM_PIPELINES_ENABLE_CGROUPS: "false" + # these two are required for cgroups, uncomment if testing + # privileged: true + # cgroup: host devices: - /dev/vsock:/dev/vsock - /dev/kvm:/dev/kvm diff --git a/spindle/engines/microvm/qemu.go b/spindle/engines/microvm/qemu.go index 0d1fe255..b8502506 100644 --- a/spindle/engines/microvm/qemu.go +++ b/spindle/engines/microvm/qemu.go @@ -2,7 +2,9 @@ package microvm import ( "context" + "crypto/sha256" _ "embed" + "encoding/hex" "encoding/json" "errors" "fmt" @@ -54,6 +56,8 @@ type QEMUVMHandle struct { serialLogPath string workDir string + qmpSocketPath string + cmd *exec.Cmd done chan struct{} qemuLogFile *os.File @@ -108,6 +112,17 @@ func (qemuRunner) Start(ctx context.Context, cfg VMConfig, volumePaths map[strin }, logger) } +// we hash the workDir to get a deterministic qmpSock path +// since they are AF_UNIX sockets, they are bound by a 108 char long path limit... +func qmpSocketPath(workDir string) string { + base := filepath.Dir(workDir) + if workDir == "" { + base = os.TempDir() + } + sum := sha256.Sum256([]byte(workDir)) + return filepath.Join(base, hex.EncodeToString(sum[:8])+".qmp.sock") +} + func StartQEMU(ctx context.Context, cfg QEMUConfig, logger *slog.Logger) (VMHandle, error) { if logger == nil { logger = slog.Default() @@ -163,7 +178,8 @@ func StartQEMU(ctx context.Context, cfg QEMUConfig, logger *slog.Logger) (VMHand qmpPath := cfg.QMPPath if qmpPath == "" { - qmpPath = filepath.Join(workDir, "qmp.sock") + qmpPath = qmpSocketPath(workDir) + handle.qmpSocketPath = qmpPath } handle.QMPPath = qmpPath @@ -335,6 +351,12 @@ func (h *QEMUVMHandle) Close() error { closeErr = errors.Join(closeErr, h.cgroup.Close()) h.cgroup = nil } + if h.qmpSocketPath != "" { + if err := os.Remove(h.qmpSocketPath); err != nil && !os.IsNotExist(err) { + closeErr = errors.Join(closeErr, err) + } + h.qmpSocketPath = "" + } return closeErr } -- 2.51.2