From 9ee17d42220a55b3dd340ef50dc3794b6343cf27 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Thu, 15 Feb 2024 15:45:54 +0100 Subject: [PATCH] machine/qemu: use extra gvproxy socket Right now the code used the same socket for gvproxy and the qemu qmp socket, this was racy and no correct as the later overwrote the former. The correct thing is to use to separate socket paths, just use the GVProxySocket() helper like applehv does. [NO NEW TESTS NEEDED] Signed-off-by: Paul Holzinger --- pkg/machine/qemu/stubber.go | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/pkg/machine/qemu/stubber.go b/pkg/machine/qemu/stubber.go index 19b9758244..b394a6ed63 100644 --- a/pkg/machine/qemu/stubber.go +++ b/pkg/machine/qemu/stubber.go @@ -141,19 +141,18 @@ func (q *QEMUStubber) StartVM(mc *vmconfigs.MachineConfig) (func() error, func() return nil, nil, err } - // If the qemusocketpath exists and the vm is off/down, we should rm - // it before the dial as to avoid a segv - - if err := mc.QEMUHypervisor.QMPMonitor.Address.Delete(); err != nil { + gvProxySock, err := mc.GVProxySocket() + if err != nil { return nil, nil, err } - qemuSocketConn, err := sockets.DialSocketWithBackoffs(maxBackoffs, defaultBackoff, mc.QEMUHypervisor.QMPMonitor.Address.GetPath()) + + qemuNetdevSockConn, err := sockets.DialSocketWithBackoffs(maxBackoffs, defaultBackoff, gvProxySock.GetPath()) if err != nil { - return nil, nil, fmt.Errorf("failed to connect to qemu monitor socket: %w", err) + return nil, nil, fmt.Errorf("failed to connect to gvproxy socket: %w", err) } - defer qemuSocketConn.Close() + defer qemuNetdevSockConn.Close() - fd, err := qemuSocketConn.(*net.UnixConn).File() + fd, err := qemuNetdevSockConn.(*net.UnixConn).File() if err != nil { return nil, nil, err } @@ -166,9 +165,6 @@ func (q *QEMUStubber) StartVM(mc *vmconfigs.MachineConfig) (func() error, func() defer dnr.Close() defer dnw.Close() - attr := new(os.ProcAttr) - files := []*os.File{dnr, dnw, dnw, fd} - attr.Files = files cmdLine := q.Command cmdLine.SetPropagatedHostEnvs() @@ -292,7 +288,15 @@ func (q *QEMUStubber) SetProviderAttrs(mc *vmconfigs.MachineConfig, opts define. } func (q *QEMUStubber) StartNetworking(mc *vmconfigs.MachineConfig, cmd *gvproxy.GvproxyCommand) error { - cmd.AddQemuSocket(fmt.Sprintf("unix://%s", mc.QEMUHypervisor.QMPMonitor.Address.GetPath())) + gvProxySock, err := mc.GVProxySocket() + if err != nil { + return err + } + // make sure it does not exist before gvproxy is called + if err := gvProxySock.Delete(); err != nil { + logrus.Error(err) + } + cmd.AddQemuSocket(fmt.Sprintf("unix://%s", gvProxySock.GetPath())) return nil }