mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-28 16:27:50 +00:00
qemu: clean up qmp channel
We only need one qmp channel and it is qemu internal detail thus sandbox.go does not need to be aware of it. Fixes: #428 Signed-off-by: Peng Tao <bergwolf@gmail.com>
This commit is contained in:
parent
c324b55255
commit
8f329dbf48
@ -7,7 +7,6 @@ package virtcontainers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -49,7 +48,6 @@ type qemu struct {
|
|||||||
config HypervisorConfig
|
config HypervisorConfig
|
||||||
|
|
||||||
qmpMonitorCh qmpChannel
|
qmpMonitorCh qmpChannel
|
||||||
qmpControlCh qmpChannel
|
|
||||||
|
|
||||||
qemuConfig govmmQemu.Config
|
qemuConfig govmmQemu.Config
|
||||||
|
|
||||||
@ -62,6 +60,8 @@ type qemu struct {
|
|||||||
|
|
||||||
const qmpCapErrMsg = "Failed to negoatiate QMP capabilities"
|
const qmpCapErrMsg = "Failed to negoatiate QMP capabilities"
|
||||||
|
|
||||||
|
const qmpSocket = "qmp.sock"
|
||||||
|
|
||||||
const defaultConsole = "console.sock"
|
const defaultConsole = "console.sock"
|
||||||
|
|
||||||
// agnostic list of kernel parameters
|
// 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
|
return q.arch.memoryTopology(memMb, hostMemMb), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *qemu) qmpSocketPath(socketName string) (string, error) {
|
func (q *qemu) qmpSocketPath(sandboxID string) (string, error) {
|
||||||
if socketName == "" {
|
return utils.BuildSocketPath(runStoragePath, sandboxID, qmpSocket)
|
||||||
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) getQemuMachine(sandboxConfig SandboxConfig) (govmmQemu.Machine, error) {
|
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")
|
return fmt.Errorf("UUID should not be empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
monitorSockPath, err := q.qmpSocketPath(monitorSocket)
|
monitorSockPath, err := q.qmpSocketPath(sandboxConfig.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -364,16 +322,11 @@ func (q *qemu) createSandbox(sandboxConfig SandboxConfig) error {
|
|||||||
path: monitorSockPath,
|
path: monitorSockPath,
|
||||||
}
|
}
|
||||||
|
|
||||||
controlSockPath, err := q.qmpSocketPath(controlSocket)
|
err = os.MkdirAll(filepath.Dir(monitorSockPath), dirMode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
q.qmpControlCh = qmpChannel{
|
|
||||||
ctx: context.Background(),
|
|
||||||
path: controlSockPath,
|
|
||||||
}
|
|
||||||
|
|
||||||
qmpSockets := []govmmQemu.QMPSocket{
|
qmpSockets := []govmmQemu.QMPSocket{
|
||||||
{
|
{
|
||||||
Type: "unix",
|
Type: "unix",
|
||||||
@ -381,12 +334,6 @@ func (q *qemu) createSandbox(sandboxConfig SandboxConfig) error {
|
|||||||
Server: true,
|
Server: true,
|
||||||
NoWait: 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
|
// 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{})
|
disconnectCh := make(chan struct{})
|
||||||
|
|
||||||
q.Logger().Info("Stopping Sandbox")
|
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 {
|
if err != nil {
|
||||||
q.Logger().WithError(err).Error("Failed to connect to QEMU instance")
|
q.Logger().WithError(err).Error("Failed to connect to QEMU instance")
|
||||||
return err
|
return err
|
||||||
@ -558,7 +505,7 @@ func (q *qemu) togglePauseSandbox(pause bool) error {
|
|||||||
// Auto-closed by QMPStart().
|
// Auto-closed by QMPStart().
|
||||||
disconnectCh := make(chan struct{})
|
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 {
|
if err != nil {
|
||||||
q.Logger().WithError(err).Error("Failed to connect to QEMU instance")
|
q.Logger().WithError(err).Error("Failed to connect to QEMU instance")
|
||||||
return err
|
return err
|
||||||
@ -591,7 +538,7 @@ func (q *qemu) qmpSetup() (*govmmQemu.QMP, error) {
|
|||||||
// Auto-closed by QMPStart().
|
// Auto-closed by QMPStart().
|
||||||
disconnectCh := make(chan struct{})
|
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 {
|
if err != nil {
|
||||||
q.Logger().WithError(err).Error("Failed to connect to QEMU instance")
|
q.Logger().WithError(err).Error("Failed to connect to QEMU instance")
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -23,17 +23,6 @@ import (
|
|||||||
deviceManager "github.com/kata-containers/runtime/virtcontainers/device/manager"
|
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
|
// vmStartTimeout represents the time in seconds a sandbox can wait before
|
||||||
// to consider the VM starting operation failed.
|
// to consider the VM starting operation failed.
|
||||||
const vmStartTimeout = 10
|
const vmStartTimeout = 10
|
||||||
|
Loading…
Reference in New Issue
Block a user