Improve cross platform support in QEMU machine sources

Signed-off-by: Arthur Sengileyev <arthur.sengileyev@gmail.com>
This commit is contained in:
Arthur Sengileyev
2024-02-16 12:49:54 +02:00
parent 5fc351a67a
commit e0a7668547
5 changed files with 9 additions and 24 deletions

View File

@ -149,9 +149,9 @@ func (q *QEMUStubber) StopVM(mc *vmconfigs.MachineConfig, _ bool) error {
// stopLocked stops the machine and expects the caller to hold the machine's lock.
func (q *QEMUStubber) stopLocked(mc *vmconfigs.MachineConfig) error {
// check if the qmp socket is there. if not, qemu instance is gone
if _, err := os.Stat(q.QMPMonitor.Address.GetPath()); errors.Is(err, fs.ErrNotExist) {
if _, err := os.Stat(mc.QEMUHypervisor.QMPMonitor.Address.GetPath()); errors.Is(err, fs.ErrNotExist) {
// Right now it is NOT an error to stop a stopped machine
logrus.Debugf("QMP monitor socket %v does not exist", q.QMPMonitor.Address)
logrus.Debugf("QMP monitor socket %v does not exist", mc.QEMUHypervisor.QMPMonitor.Address)
// Fix incorrect starting state in case of crash during start
if mc.Starting {
mc.Starting = false
@ -162,7 +162,7 @@ func (q *QEMUStubber) stopLocked(mc *vmconfigs.MachineConfig) error {
return nil
}
qmpMonitor, err := qmp.NewSocketMonitor(q.QMPMonitor.Network, q.QMPMonitor.Address.GetPath(), q.QMPMonitor.Timeout)
qmpMonitor, err := qmp.NewSocketMonitor(mc.QEMUHypervisor.QMPMonitor.Network, mc.QEMUHypervisor.QMPMonitor.Address.GetPath(), mc.QEMUHypervisor.QMPMonitor.Timeout)
if err != nil {
return err
}
@ -196,7 +196,7 @@ func (q *QEMUStubber) stopLocked(mc *vmconfigs.MachineConfig) error {
}
// Remove socket
if err := q.QMPMonitor.Address.Delete(); err != nil {
if err := mc.QEMUHypervisor.QMPMonitor.Address.Delete(); err != nil {
return err
}
@ -206,14 +206,14 @@ func (q *QEMUStubber) stopLocked(mc *vmconfigs.MachineConfig) error {
}
disconnected = true
if q.QEMUPidPath.GetPath() == "" {
if mc.QEMUHypervisor.QEMUPidPath.GetPath() == "" {
// no vm pid file path means it's probably a machine created before we
// started using it, so we revert to the old way of waiting for the
// machine to stop
return q.waitForMachineToStop(mc)
}
vmPid, err := q.QEMUPidPath.ReadPIDFrom()
vmPid, err := mc.QEMUHypervisor.QEMUPidPath.ReadPIDFrom()
if err != nil {
return err
}

View File

@ -22,7 +22,7 @@ func checkProcessStatus(processHint string, pid int, stderrBuf *bytes.Buffer) er
var status syscall.WaitStatus
pid, err := syscall.Wait4(pid, &status, syscall.WNOHANG, nil)
if err != nil {
return fmt.Errorf("failed to read qem%su process status: %w", processHint, err)
return fmt.Errorf("failed to read %s process status: %w", processHint, err)
}
if pid > 0 {
// child exited

View File

@ -10,11 +10,3 @@ func (q *QEMUStubber) addArchOptions(_ *setNewMachineCMDOpts) []string {
opts := []string{"-machine", "q35,accel=whpx:tcg", "-cpu", "qemu64"}
return opts
}
func (v *MachineVM) prepare() error {
return nil
}
func (v *MachineVM) archRemovalFiles() []string {
return []string{}
}

View File

@ -9,11 +9,3 @@ func (q *QEMUStubber) addArchOptions(_ *setNewMachineCMDOpts) []string {
opts := []string{}
return opts
}
func (v *MachineVM) prepare() error {
return nil
}
func (v *MachineVM) archRemovalFiles() []string {
return []string{}
}

View File

@ -8,6 +8,7 @@ import (
"net"
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"
"time"
@ -296,7 +297,7 @@ func (q *QEMUStubber) StartNetworking(mc *vmconfigs.MachineConfig, cmd *gvproxy.
if err := gvProxySock.Delete(); err != nil {
logrus.Error(err)
}
cmd.AddQemuSocket(fmt.Sprintf("unix://%s", gvProxySock.GetPath()))
cmd.AddQemuSocket(fmt.Sprintf("unix://%s", filepath.ToSlash(gvProxySock.GetPath())))
return nil
}