Skip to content

Commit 04fd06c

Browse files
committed
qemu: refactor QEMU version check
Signed-off-by: Akihiro Suda <[email protected]>
1 parent ae3e43e commit 04fd06c

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

pkg/qemu/qemu.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ type features struct {
155155
// e.g. "Supported machines are:\nakita...\n...virt-6.2...\n...virt-7.0...\n...\n"
156156
// Not machine-readable, but checking strings.Contains() should be fine.
157157
MachineHelp []byte
158+
159+
// VersionGEQ7 is true when the QEMU version seems v7.0.0 or later
160+
VersionGEQ7 bool
158161
}
159162

160163
func inspectFeatures(exe string) (*features, error) {
@@ -198,6 +201,7 @@ func inspectFeatures(exe string) (*features, error) {
198201
f.MachineHelp = stderr.Bytes()
199202
}
200203
}
204+
f.VersionGEQ7 = strings.Contains(string(f.MachineHelp), "-7.0")
201205

202206
return &f, nil
203207
}
@@ -218,8 +222,7 @@ func showDarwinARM64HVFQEMU620Warning(exe, accel string, features *features) {
218222
if accel != "hvf" {
219223
return
220224
}
221-
if strings.Contains(string(features.MachineHelp), "virt-7.0") {
222-
// QEMU 7.0.0 or later
225+
if features.VersionGEQ7 {
223226
return
224227
}
225228
if exeFull, err := exec.LookPath(exe); err == nil {
@@ -285,7 +288,7 @@ func Cmdline(cfg Config) (string, []string, error) {
285288
// 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)"
286289
// https://github.com/lima-vm/lima/issues/680
287290
// https://github.com/lima-vm/lima/pull/24
288-
if !strings.Contains(string(features.MachineHelp), "virt-7.0") {
291+
if !features.VersionGEQ7 {
289292
machine += ",highmem=off"
290293
}
291294
args = appendArgsIfNoConflict(args, "-machine", machine)

0 commit comments

Comments
 (0)