From e0a76685475855823dbcf9504057b92b58d69941 Mon Sep 17 00:00:00 2001 From: Arthur Sengileyev Date: Fri, 16 Feb 2024 12:49:54 +0200 Subject: [PATCH] Improve cross platform support in QEMU machine sources Signed-off-by: Arthur Sengileyev --- pkg/machine/qemu/machine.go | 12 ++++++------ pkg/machine/qemu/machine_unix.go | 2 +- pkg/machine/qemu/options_windows_amd64.go | 8 -------- pkg/machine/qemu/options_windows_arm64.go | 8 -------- pkg/machine/qemu/stubber.go | 3 ++- 5 files changed, 9 insertions(+), 24 deletions(-) diff --git a/pkg/machine/qemu/machine.go b/pkg/machine/qemu/machine.go index eb610f890d..2be390d3c6 100644 --- a/pkg/machine/qemu/machine.go +++ b/pkg/machine/qemu/machine.go @@ -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 } diff --git a/pkg/machine/qemu/machine_unix.go b/pkg/machine/qemu/machine_unix.go index baea1f9e67..fe0bb74954 100644 --- a/pkg/machine/qemu/machine_unix.go +++ b/pkg/machine/qemu/machine_unix.go @@ -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 diff --git a/pkg/machine/qemu/options_windows_amd64.go b/pkg/machine/qemu/options_windows_amd64.go index 945b7bf851..8ab50e8191 100644 --- a/pkg/machine/qemu/options_windows_amd64.go +++ b/pkg/machine/qemu/options_windows_amd64.go @@ -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{} -} diff --git a/pkg/machine/qemu/options_windows_arm64.go b/pkg/machine/qemu/options_windows_arm64.go index 09d63a1c67..3371b41c7a 100644 --- a/pkg/machine/qemu/options_windows_arm64.go +++ b/pkg/machine/qemu/options_windows_arm64.go @@ -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{} -} diff --git a/pkg/machine/qemu/stubber.go b/pkg/machine/qemu/stubber.go index 8015b633bc..7497c46b19 100644 --- a/pkg/machine/qemu/stubber.go +++ b/pkg/machine/qemu/stubber.go @@ -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 }