Skip to content

Commit

Permalink
machine/qemu: use extra gvproxy socket
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Luap99 committed Feb 15, 2024
1 parent bbd4476 commit 9ee17d4
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions pkg/machine/qemu/stubber.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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()
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 9ee17d4

Please sign in to comment.