diff --git a/src/runtime/config/configuration-qemu.toml.in b/src/runtime/config/configuration-qemu.toml.in index 0394d01246..4aced59752 100644 --- a/src/runtime/config/configuration-qemu.toml.in +++ b/src/runtime/config/configuration-qemu.toml.in @@ -311,7 +311,7 @@ valid_file_mem_backends = @DEFVALIDFILEMEMBACKENDS@ pflashes = [] # This option changes the default hypervisor and kernel parameters -# to enable debug output where available. +# to enable debug output where available. And Debug also enable the hmp socket. # # Default false #enable_debug = true diff --git a/src/runtime/pkg/govmm/qemu/qemu.go b/src/runtime/pkg/govmm/qemu/qemu.go index 4a071019b9..148212f511 100644 --- a/src/runtime/pkg/govmm/qemu/qemu.go +++ b/src/runtime/pkg/govmm/qemu/qemu.go @@ -2336,10 +2336,14 @@ const ( ) // QMPSocket represents a qemu QMP socket configuration. +// nolint: govet type QMPSocket struct { // Type is the socket type (e.g. "unix"). Type QMPSocketType + // Human Monitor Interface (HMP) (true for HMP, false for QMP, default false) + IsHmp bool + // QMP listener file descriptor to be passed to qemu FD *os.File @@ -2710,7 +2714,12 @@ func (config *Config) appendQMPSockets() { } } - config.qemuParams = append(config.qemuParams, "-qmp") + if q.IsHmp { + config.qemuParams = append(config.qemuParams, "-monitor") + } else { + config.qemuParams = append(config.qemuParams, "-qmp") + } + config.qemuParams = append(config.qemuParams, strings.Join(qmpParams, ",")) } } diff --git a/src/runtime/virtcontainers/hypervisor.go b/src/runtime/virtcontainers/hypervisor.go index bb1b8e90e7..3ea7a83a47 100644 --- a/src/runtime/virtcontainers/hypervisor.go +++ b/src/runtime/virtcontainers/hypervisor.go @@ -505,7 +505,7 @@ type HypervisorConfig struct { EnableIOThreads bool // Debug changes the default hypervisor and kernel parameters to - // enable debug output where available. + // enable debug output where available. And Debug also enable the hmp socket. Debug bool // MemPrealloc specifies if the memory should be pre-allocated diff --git a/src/runtime/virtcontainers/qemu.go b/src/runtime/virtcontainers/qemu.go index 54846b40e1..d59d67d801 100644 --- a/src/runtime/virtcontainers/qemu.go +++ b/src/runtime/virtcontainers/qemu.go @@ -121,6 +121,7 @@ type qemu struct { const ( consoleSocket = "console.sock" qmpSocket = "qmp.sock" + hmpSocket = "hmp.sock" vhostFSSocket = "vhost-fs.sock" nydusdAPISock = "nydusd-api.sock" @@ -328,6 +329,10 @@ func (q *qemu) qmpSocketPath(id string) (string, error) { return utils.BuildSocketPath(q.config.VMStorePath, id, qmpSocket) } +func (q *qemu) hmpSocketPath(id string) (string, error) { + return utils.BuildSocketPath(q.config.VMStorePath, id, hmpSocket) +} + func (q *qemu) getQemuMachine() (govmmQemu.Machine, error) { machine := q.arch.machine() @@ -369,13 +374,30 @@ func (q *qemu) createQmpSocket() ([]govmmQemu.QMPSocket, error) { path: monitorSockPath, } - return []govmmQemu.QMPSocket{ - { + var sockets []govmmQemu.QMPSocket + + sockets = append(sockets, govmmQemu.QMPSocket{ + Type: "unix", + Server: true, + NoWait: true, + }) + + if q.HypervisorConfig().Debug { + humanMonitorSockPath, err := q.hmpSocketPath(q.id) + if err != nil { + return nil, err + } + + sockets = append(sockets, govmmQemu.QMPSocket{ Type: "unix", + IsHmp: true, + Name: humanMonitorSockPath, Server: true, NoWait: true, - }, - }, nil + }) + } + + return sockets, nil } func (q *qemu) buildDevices(ctx context.Context, initrdPath string) ([]govmmQemu.Device, *govmmQemu.IOThread, error) {