Skip to content

Commit 5b0ba32

Browse files
committed
Implement feature toggle for GA forwarding mode in QEMU
Current code supports 2 modes: - forwarding via SSH forwarding - forwarding by QEMU via serialport In GA they are exclusive modes - it either talks to device or exposes Unix socket inside VM. At some point the GA part was switched to Unix socket only, but QEMU start command line was not updated. SSH forwarder takes care of it by removing Unix socket before starting its own, but there is no point in having it, when it can't be used. This code introduces feature toggle allowing to use either mode. Keeping the "unstable" option could be beneficial for environments, where Unix socket forwarding is tricky (Windows hosts). Signed-off-by: Arthur Sengileyev <[email protected]>
1 parent 0625d0b commit 5b0ba32

File tree

6 files changed

+28
-7
lines changed

6 files changed

+28
-7
lines changed

pkg/hostagent/hostagent.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,9 @@ func New(instName string, stdout io.Writer, signalCh chan os.Signal, opts ...Opt
134134
}
135135
vSockPort = port
136136
} else if *inst.Config.VMType == limayaml.QEMU {
137-
// virtserialport doesn't seem to work reliably: https://github.com/lima-vm/lima/issues/2064
138-
virtioPort = "" // filenames.VirtioPort
137+
if *inst.Config.VMOpts.QEMU.VirtioGA {
138+
virtioPort = filenames.VirtioPort
139+
}
139140
}
140141

141142
if err := cidata.GenerateCloudConfig(inst.Dir, instName, inst.Config); err != nil {

pkg/limayaml/defaults.go

+11
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,17 @@ func FillDefault(y, d, o *LimaYAML, filePath string, warn bool) {
888888
y.CACertificates.Files = unique(slices.Concat(d.CACertificates.Files, y.CACertificates.Files, o.CACertificates.Files))
889889
y.CACertificates.Certs = unique(slices.Concat(d.CACertificates.Certs, y.CACertificates.Certs, o.CACertificates.Certs))
890890

891+
if y.VMOpts.QEMU.VirtioGA == nil {
892+
y.VMOpts.QEMU.VirtioGA = d.VMOpts.QEMU.VirtioGA
893+
}
894+
if o.VMOpts.QEMU.VirtioGA != nil {
895+
y.VMOpts.QEMU.VirtioGA = o.VMOpts.QEMU.VirtioGA
896+
}
897+
if y.VMOpts.QEMU.VirtioGA == nil {
898+
// virtserialport doesn't seem to work reliably, so, default to false: https://github.com/lima-vm/lima/issues/2064
899+
y.VMOpts.QEMU.VirtioGA = ptr.Of(runtime.GOOS == "windows")
900+
}
901+
891902
if runtime.GOOS == "darwin" && IsNativeArch(AARCH64) {
892903
if y.Rosetta.Enabled == nil {
893904
y.Rosetta.Enabled = d.Rosetta.Enabled

pkg/limayaml/limayaml.go

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ type VMOpts struct {
110110

111111
type QEMUOpts struct {
112112
MinimumVersion *string `yaml:"minimumVersion,omitempty" json:"minimumVersion,omitempty" jsonschema:"nullable"`
113+
VirtioGA *bool `yaml:"virtioGA,omitempty" json:"virtioGA,omitempty" jsonschema:"nullable"`
113114
}
114115

115116
type Rosetta struct {

pkg/qemu/qemu.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type Config struct {
4545
LimaYAML *limayaml.LimaYAML
4646
SSHLocalPort int
4747
SSHAddress string
48+
VirtioGA bool
4849
}
4950

5051
// MinimumQemuVersion is the minimum supported QEMU version.
@@ -987,11 +988,13 @@ func Cmdline(ctx context.Context, cfg Config) (exe string, args []string, err er
987988
args = append(args, "-chardev", fmt.Sprintf("socket,id=%s,path=%s,server=on,wait=off", qmpChardev, qmpSock))
988989
args = append(args, "-qmp", "chardev:"+qmpChardev)
989990

990-
// Guest agent via serialport
991-
guestSock := filepath.Join(cfg.InstanceDir, filenames.GuestAgentSock)
992-
args = append(args, "-chardev", fmt.Sprintf("socket,path=%s,server=on,wait=off,id=qga0", guestSock))
993-
args = append(args, "-device", "virtio-serial")
994-
args = append(args, "-device", "virtserialport,chardev=qga0,name="+filenames.VirtioPort)
991+
if cfg.VirtioGA {
992+
// Guest agent via serialport
993+
guestSock := filepath.Join(cfg.InstanceDir, filenames.GuestAgentSock)
994+
args = append(args, "-chardev", fmt.Sprintf("socket,path=%s,server=on,wait=off,id=qga0", guestSock))
995+
args = append(args, "-device", "virtio-serial")
996+
args = append(args, "-device", "virtserialport,chardev=qga0,name="+filenames.VirtioPort)
997+
}
995998

996999
// QEMU process
9971000
args = append(args, "-name", "lima-"+cfg.Name)

pkg/qemu/qemu_driver.go

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ func (l *LimaQemuDriver) Start(ctx context.Context) (chan error, error) {
7777
LimaYAML: l.Instance.Config,
7878
SSHLocalPort: l.SSHLocalPort,
7979
SSHAddress: l.Instance.SSHAddress,
80+
VirtioGA: *l.Instance.Config.VMOpts.QEMU.VirtioGA,
8081
}
8182
qExe, qArgs, err := Cmdline(ctx, qCfg)
8283
if err != nil {

templates/default.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,10 @@ vmOpts:
343343
# Will be ignored if the vmType is not "qemu"
344344
# 🟢 Builtin default: not set
345345
minimumVersion: null
346+
# Enable virtio port for GA. If disabled then will forward GA via SSH.
347+
# Will be ignored if the vmType is not "qemu"
348+
# 🟢 Builtin default: true on Windows and false otherwise
349+
virtioGA: null
346350

347351
# OS: "Linux".
348352
# 🟢 Builtin default: "Linux"

0 commit comments

Comments
 (0)