Merge branch 'firmware-path' into restart-qemu

pull/14183/head
Sharif Elgamal 2022-05-16 17:22:41 -07:00
commit ac8f0b1ede
2 changed files with 41 additions and 19 deletions

View File

@ -38,6 +38,7 @@ import (
"github.com/docker/machine/libmachine/mcnutils"
"github.com/docker/machine/libmachine/ssh"
"github.com/docker/machine/libmachine/state"
"github.com/pkg/errors"
pkgdrivers "k8s.io/minikube/pkg/drivers"
)
@ -79,11 +80,9 @@ type Driver struct {
DiskPath string
CacheMode string
IOMode string
// conn *libvirt.Connect
// VM *libvirt.Domain
UserDataFile string
CloudConfigRoot string
LocalPorts string
UserDataFile string
CloudConfigRoot string
LocalPorts string
}
func (d *Driver) GetMachineName() string {
@ -273,19 +272,19 @@ func parsePortRange(rawPortRange string) (int, int, error) {
minPort, err := strconv.Atoi(portRange[0])
if err != nil {
return 0, 0, fmt.Errorf("invalid port range")
return 0, 0, errors.Wrap(err, "Invalid port range")
}
maxPort, err := strconv.Atoi(portRange[1])
if err != nil {
return 0, 0, fmt.Errorf("invalid port range")
return 0, 0, errors.Wrap(err, "Invalid port range")
}
if maxPort < minPort {
return 0, 0, fmt.Errorf("invalid port range")
return 0, 0, errors.New("Invalid port range")
}
if maxPort-minPort < 2 {
return 0, 0, fmt.Errorf("port range must be minimum 2 ports")
return 0, 0, errors.New("Port range must be minimum 2 ports")
}
return minPort, maxPort, nil
@ -340,7 +339,7 @@ func (d *Driver) Start() error {
machineType := d.MachineType
if runtime.GOOS == "darwin" {
// highmem=off needed, see https://patchwork.kernel.org/project/qemu-devel/patch/20201126215017.41156-9-agraf@csgraf.de/#23800615 for details
machineType += ",accel=hvf,highmem=off"
machineType += ",highmem=off"
}
startCmd = append(startCmd,
"-M", machineType,
@ -380,6 +379,13 @@ func (d *Driver) Start() error {
}
}
// hardware acceleration is important, it increases performance by 10x
// kvm acceleration doesn't currently work for linux, it's incompatible with our chosen CPU
// once that's fixed we should add a branch for linux
if runtime.GOOS == "darwin" {
startCmd = append(startCmd, "-accel", "hvf")
}
startCmd = append(startCmd,
"-m", fmt.Sprintf("%d", d.Memory),
"-smp", fmt.Sprintf("%d", d.CPU),
@ -421,9 +427,10 @@ func (d *Driver) Start() error {
// other options
// "-enable-kvm" if its available
if _, err := os.Stat("/dev/kvm"); err == nil {
// TODO (#14171): re-enable this once kvm acceleration is fixed
/*if _, err := os.Stat("/dev/kvm"); err == nil {
startCmd = append(startCmd, "-enable-kvm")
}
}*/
if d.CloudConfigRoot != "" {
startCmd = append(startCmd,

View File

@ -18,8 +18,10 @@ package qemu2
import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path"
"path/filepath"
"runtime"
@ -64,17 +66,30 @@ func qemuSystemProgram() (string, error) {
func qemuFirmwarePath() (string, error) {
arch := runtime.GOARCH
// For macOS, find the correct brew installation path for qemu firmware
if runtime.GOOS == "darwin" {
p := "/usr/local/Cellar/qemu"
fw := "share/qemu/edk2-x86_64-code.fd"
if arch == "arm64" {
p = "/opt/homebrew/Cellar/qemu"
fw = "share/qemu/edk2-aarch64-code.fd"
}
v, err := ioutil.ReadDir(p)
if err != nil {
return "", fmt.Errorf("lookup qemu: %v", err)
}
for _, version := range v {
if version.IsDir() {
return path.Join(p, version.Name(), fw), nil
}
}
}
switch arch {
case "amd64":
// on macOS, we assume qemu is installed via homebrew for simplicity
if runtime.GOOS == "darwin" {
return "/usr/local/Cellar/qemu/6.2.0_1/share/qemu/edk2-x86_64-code.fd", nil
}
return "/usr/share/OVMF/OVMF_CODE.fd", nil
case "arm64":
if runtime.GOOS == "darwin" {
return "/opt/homebrew/Cellar/qemu/6.2.0_1/share/qemu/edk2-aarch64-code.fd", nil
}
return "/usr/share/AAVMF/AAVMF_CODE.fd", nil
default:
return "", fmt.Errorf("unknown arch: %s", arch)