Skip to content

Allow drivers to negotiate transport independent of hostagent #3428

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 6 additions & 20 deletions pkg/hostagent/hostagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,13 @@ func New(instName string, stdout io.Writer, signalCh chan os.Signal, opts ...Opt
}
}

vSockPort := 0
virtioPort := ""
if *inst.Config.VMType == limayaml.VZ {
vSockPort = 2222
} else if *inst.Config.VMType == limayaml.WSL2 {
port, err := freeport.VSock()
if err != nil {
logrus.WithError(err).Error("failed to get free VSock port")
}
vSockPort = port
} else if *inst.Config.VMType == limayaml.QEMU {
// virtserialport doesn't seem to work reliably: https://github.com/lima-vm/lima/issues/2064
virtioPort = "" // filenames.VirtioPort
baseDriver := driver.BaseDriver{
Instance: inst,
SSHLocalPort: sshLocalPort,
}
limaDriver := driverutil.CreateTargetDriverInstance(&baseDriver)
vSockPort := baseDriver.VSockPort
virtioPort := baseDriver.VirtioPort

if err := cidata.GenerateCloudConfig(inst.Dir, instName, inst.Config); err != nil {
return nil, err
Expand Down Expand Up @@ -196,13 +189,6 @@ func New(instName string, stdout io.Writer, signalCh chan os.Signal, opts ...Opt
limayaml.FillPortForwardDefaults(&rule, inst.Dir, inst.Config.User, inst.Param)
rules = append(rules, rule)

limaDriver := driverutil.CreateTargetDriverInstance(&driver.BaseDriver{
Instance: inst,
SSHLocalPort: sshLocalPort,
VSockPort: vSockPort,
VirtioPort: virtioPort,
})

a := &HostAgent{
instConfig: inst.Config,
sshLocalPort: sshLocalPort,
Expand Down
7 changes: 7 additions & 0 deletions pkg/qemu/qemu_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ type LimaQemuDriver struct {
}

func New(driver *driver.BaseDriver) *LimaQemuDriver {
driver.VSockPort = 0
driver.VirtioPort = filenames.VirtioPort
// virtserialport doesn't seem to work reliably: https://github.com/lima-vm/lima/issues/2064
// but on Windows default Unix socket forwarding is not available
if runtime.GOOS != "windows" {
driver.VirtioPort = ""
}
return &LimaQemuDriver{
BaseDriver: driver,
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/vz/vz_driver_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ type LimaVzDriver struct {
}

func New(driver *driver.BaseDriver) *LimaVzDriver {
driver.VSockPort = 2222
driver.VirtioPort = ""
return &LimaVzDriver{
BaseDriver: driver,
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/wsl2/wsl_driver_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/Microsoft/go-winio"
"github.com/Microsoft/go-winio/pkg/guid"
"github.com/lima-vm/lima/pkg/driver"
"github.com/lima-vm/lima/pkg/freeport"
"github.com/lima-vm/lima/pkg/limayaml"
"github.com/lima-vm/lima/pkg/reflectutil"
"github.com/lima-vm/lima/pkg/store"
Expand Down Expand Up @@ -49,6 +50,12 @@ type LimaWslDriver struct {
}

func New(driver *driver.BaseDriver) *LimaWslDriver {
port, err := freeport.VSock()
if err != nil {
logrus.WithError(err).Error("failed to get free VSock port")
}
driver.VSockPort = port
driver.VirtioPort = ""
return &LimaWslDriver{
BaseDriver: driver,
}
Expand Down
Loading