Skip to content

Commit

Permalink
qemu: refactor QEMU version check
Browse files Browse the repository at this point in the history
Signed-off-by: Akihiro Suda <[email protected]>
  • Loading branch information
AkihiroSuda committed Apr 21, 2022
1 parent ae3e43e commit 04fd06c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pkg/qemu/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ type features struct {
// e.g. "Supported machines are:\nakita...\n...virt-6.2...\n...virt-7.0...\n...\n"
// Not machine-readable, but checking strings.Contains() should be fine.
MachineHelp []byte

// VersionGEQ7 is true when the QEMU version seems v7.0.0 or later
VersionGEQ7 bool
}

func inspectFeatures(exe string) (*features, error) {
Expand Down Expand Up @@ -198,6 +201,7 @@ func inspectFeatures(exe string) (*features, error) {
f.MachineHelp = stderr.Bytes()
}
}
f.VersionGEQ7 = strings.Contains(string(f.MachineHelp), "-7.0")

return &f, nil
}
Expand All @@ -218,8 +222,7 @@ func showDarwinARM64HVFQEMU620Warning(exe, accel string, features *features) {
if accel != "hvf" {
return
}
if strings.Contains(string(features.MachineHelp), "virt-7.0") {
// QEMU 7.0.0 or later
if features.VersionGEQ7 {
return
}
if exeFull, err := exec.LookPath(exe); err == nil {
Expand Down Expand Up @@ -285,7 +288,7 @@ func Cmdline(cfg Config) (string, []string, error) {
// QEMU < 7.0 requires highmem=off to be set, otherwise fails with "VCPU supports less PA bits (36) than requested by the memory map (40)"
// https://github.com/lima-vm/lima/issues/680
// https://github.com/lima-vm/lima/pull/24
if !strings.Contains(string(features.MachineHelp), "virt-7.0") {
if !features.VersionGEQ7 {
machine += ",highmem=off"
}
args = appendArgsIfNoConflict(args, "-machine", machine)
Expand Down

0 comments on commit 04fd06c

Please sign in to comment.