Skip to content

Commit 24eaf3b

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 d2fce41 commit 24eaf3b

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
@@ -131,8 +131,9 @@ func New(instName string, stdout io.Writer, signalCh chan os.Signal, opts ...Opt
131131
}
132132
vSockPort = port
133133
} else if *inst.Config.VMType == limayaml.QEMU {
134-
// virtserialport doesn't seem to work reliably: https://github.com/lima-vm/lima/issues/2064
135-
virtioPort = "" // filenames.VirtioPort
134+
if *inst.Config.VMOpts.QEMU.VirtioGA {
135+
virtioPort = filenames.VirtioPort
136+
}
136137
}
137138

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

pkg/limayaml/defaults.go

+11
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,17 @@ func FillDefault(y, d, o *LimaYAML, filePath string, warn bool) {
835835
caCerts := unique(append(append(d.CACertificates.Certs, y.CACertificates.Certs...), o.CACertificates.Certs...))
836836
y.CACertificates.Certs = caCerts
837837

838+
if y.VMOpts.QEMU.VirtioGA == nil {
839+
y.VMOpts.QEMU.VirtioGA = d.VMOpts.QEMU.VirtioGA
840+
}
841+
if o.VMOpts.QEMU.VirtioGA != nil {
842+
y.VMOpts.QEMU.VirtioGA = o.VMOpts.QEMU.VirtioGA
843+
}
844+
if y.VMOpts.QEMU.VirtioGA == nil {
845+
// virtserialport doesn't seem to work reliably, so, default to false: https://github.com/lima-vm/lima/issues/2064
846+
y.VMOpts.QEMU.VirtioGA = ptr.Of(false)
847+
}
848+
838849
if runtime.GOOS == "darwin" && IsNativeArch(AARCH64) {
839850
if y.Rosetta.Enabled == nil {
840851
y.Rosetta.Enabled = d.Rosetta.Enabled

pkg/limayaml/limayaml.go

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

9999
type QEMUOpts struct {
100100
MinimumVersion *string `yaml:"minimumVersion,omitempty" json:"minimumVersion,omitempty" jsonschema:"nullable"`
101+
VirtioGA *bool `yaml:"virtioGA,omitempty" json:"virtioGA,omitempty" jsonschema:"nullable"`
101102
}
102103

103104
type Rosetta struct {

pkg/qemu/qemu.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ type Config struct {
4141
InstanceDir string
4242
LimaYAML *limayaml.LimaYAML
4343
SSHLocalPort int
44+
VirtioGA bool
4445
}
4546

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

923-
// Guest agent via serialport
924-
guestSock := filepath.Join(cfg.InstanceDir, filenames.GuestAgentSock)
925-
args = append(args, "-chardev", fmt.Sprintf("socket,path=%s,server=on,wait=off,id=qga0", guestSock))
926-
args = append(args, "-device", "virtio-serial")
927-
args = append(args, "-device", "virtserialport,chardev=qga0,name="+filenames.VirtioPort)
924+
if cfg.VirtioGA {
925+
// Guest agent via serialport
926+
guestSock := filepath.Join(cfg.InstanceDir, filenames.GuestAgentSock)
927+
args = append(args, "-chardev", fmt.Sprintf("socket,path=%s,server=on,wait=off,id=qga0", guestSock))
928+
args = append(args, "-device", "virtio-serial")
929+
args = append(args, "-device", "virtserialport,chardev=qga0,name="+filenames.VirtioPort)
930+
}
928931

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

pkg/qemu/qemu_driver.go

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ func (l *LimaQemuDriver) Start(ctx context.Context) (chan error, error) {
7272
InstanceDir: l.Instance.Dir,
7373
LimaYAML: l.Instance.Config,
7474
SSHLocalPort: l.SSHLocalPort,
75+
VirtioGA: *l.Instance.Config.VMOpts.QEMU.VirtioGA,
7576
}
7677
qExe, qArgs, err := Cmdline(ctx, qCfg)
7778
if err != nil {

templates/default.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,10 @@ vmOpts:
304304
# Will be ignored if the vmType is not "qemu"
305305
# 🟢 Builtin default: not set
306306
minimumVersion: null
307+
# Enable virtio port for GA. If disabled then will forward GA via SSH.
308+
# Will be ignored if the vmType is not "qemu"
309+
# 🟢 Builtin default: false
310+
virtioGA : null
307311

308312
# OS: "Linux".
309313
# 🟢 Builtin default: "Linux"

0 commit comments

Comments
 (0)