diff --git a/virtcontainers/qemu.go b/virtcontainers/qemu.go index efb1699b72..882294ad39 100644 --- a/virtcontainers/qemu.go +++ b/virtcontainers/qemu.go @@ -7,7 +7,6 @@ package virtcontainers import ( "context" - "errors" "fmt" "os" "path/filepath" @@ -49,7 +48,6 @@ type qemu struct { config HypervisorConfig qmpMonitorCh qmpChannel - qmpControlCh qmpChannel qemuConfig govmmQemu.Config @@ -62,6 +60,8 @@ type qemu struct { const qmpCapErrMsg = "Failed to negoatiate QMP capabilities" +const qmpSocket = "qmp.sock" + const defaultConsole = "console.sock" // agnostic list of kernel parameters @@ -223,50 +223,8 @@ func (q *qemu) memoryTopology(sandboxConfig SandboxConfig) (govmmQemu.Memory, er return q.arch.memoryTopology(memMb, hostMemMb), nil } -func (q *qemu) qmpSocketPath(socketName string) (string, error) { - if socketName == "" { - return "", errors.New("need socket name") - } - - parentDirPath := filepath.Join(runStoragePath, q.sandbox.id) - - dir, err := utils.BuildSocketPath(parentDirPath) - if err != nil { - return "", err - } - - name := fmt.Sprintf("%s-%s", socketName, q.state.UUID) - - path, err := utils.BuildSocketPath(dir, name) - if err == nil { - return path, nil - } - - // The socket path is too long so truncate up to a minimum length. - - // The minimum path length we're prepared to use (based on current - // values) - const minNameLen = 12 - - dirLen := len(dir) - - // '-1' is for the addition of a path separator - availableNameLen := utils.MaxSocketPathLen - dirLen - 1 - - if availableNameLen < minNameLen { - return "", fmt.Errorf("QMP socket name cannot be shortened: %v", name) - } - - new := name[:availableNameLen] - - q.Logger().WithFields(logrus.Fields{ - "original-name": name, - "new-name": new, - }).Warnf("shortening QMP socket name") - - name = new - - return utils.BuildSocketPath(dir, name) +func (q *qemu) qmpSocketPath(sandboxID string) (string, error) { + return utils.BuildSocketPath(runStoragePath, sandboxID, qmpSocket) } func (q *qemu) getQemuMachine(sandboxConfig SandboxConfig) (govmmQemu.Machine, error) { @@ -354,7 +312,7 @@ func (q *qemu) createSandbox(sandboxConfig SandboxConfig) error { return fmt.Errorf("UUID should not be empty") } - monitorSockPath, err := q.qmpSocketPath(monitorSocket) + monitorSockPath, err := q.qmpSocketPath(sandboxConfig.ID) if err != nil { return err } @@ -364,16 +322,11 @@ func (q *qemu) createSandbox(sandboxConfig SandboxConfig) error { path: monitorSockPath, } - controlSockPath, err := q.qmpSocketPath(controlSocket) + err = os.MkdirAll(filepath.Dir(monitorSockPath), dirMode) if err != nil { return err } - q.qmpControlCh = qmpChannel{ - ctx: context.Background(), - path: controlSockPath, - } - qmpSockets := []govmmQemu.QMPSocket{ { Type: "unix", @@ -381,12 +334,6 @@ func (q *qemu) createSandbox(sandboxConfig SandboxConfig) error { Server: true, NoWait: true, }, - { - Type: "unix", - Name: q.qmpControlCh.path, - Server: true, - NoWait: true, - }, } // Add bridges before any other devices. This way we make sure that @@ -531,7 +478,7 @@ func (q *qemu) stopSandbox() error { disconnectCh := make(chan struct{}) q.Logger().Info("Stopping Sandbox") - qmp, _, err := govmmQemu.QMPStart(q.qmpControlCh.ctx, q.qmpControlCh.path, cfg, disconnectCh) + qmp, _, err := govmmQemu.QMPStart(q.qmpMonitorCh.ctx, q.qmpMonitorCh.path, cfg, disconnectCh) if err != nil { q.Logger().WithError(err).Error("Failed to connect to QEMU instance") return err @@ -558,7 +505,7 @@ func (q *qemu) togglePauseSandbox(pause bool) error { // Auto-closed by QMPStart(). disconnectCh := make(chan struct{}) - qmp, _, err := govmmQemu.QMPStart(q.qmpControlCh.ctx, q.qmpControlCh.path, cfg, disconnectCh) + qmp, _, err := govmmQemu.QMPStart(q.qmpMonitorCh.ctx, q.qmpMonitorCh.path, cfg, disconnectCh) if err != nil { q.Logger().WithError(err).Error("Failed to connect to QEMU instance") return err @@ -591,7 +538,7 @@ func (q *qemu) qmpSetup() (*govmmQemu.QMP, error) { // Auto-closed by QMPStart(). disconnectCh := make(chan struct{}) - qmp, _, err := govmmQemu.QMPStart(q.qmpControlCh.ctx, q.qmpControlCh.path, cfg, disconnectCh) + qmp, _, err := govmmQemu.QMPStart(q.qmpMonitorCh.ctx, q.qmpMonitorCh.path, cfg, disconnectCh) if err != nil { q.Logger().WithError(err).Error("Failed to connect to QEMU instance") return nil, err diff --git a/virtcontainers/sandbox.go b/virtcontainers/sandbox.go index 2d0abbfff9..f803a63f56 100644 --- a/virtcontainers/sandbox.go +++ b/virtcontainers/sandbox.go @@ -23,17 +23,6 @@ import ( deviceManager "github.com/kata-containers/runtime/virtcontainers/device/manager" ) -// controlSocket is the sandbox control socket. -// It is an hypervisor resource, and for example qemu's control -// socket is the QMP one. -const controlSocket = "ctl" - -// monitorSocket is the sandbox monitoring socket. -// It is an hypervisor resource, and is a qmp socket in the qemu case. -// This is a socket that any monitoring entity will listen to in order -// to understand if the VM is still alive or not. -const monitorSocket = "mon" - // vmStartTimeout represents the time in seconds a sandbox can wait before // to consider the VM starting operation failed. const vmStartTimeout = 10