Fix path for omvf vars on Darwin/arm64

On darwin arm64, we need to set the location of the ovmf vars. It should be put into the imageDir (also known as as dataDir).  But because qemu determines the image path late in Init(), the image path is set something like a stream marker.

Fixes #20361

[NO NEW TESTS NEEDED]

Signed-off-by: Brent Baude <bbaude@redhat.com>
This commit is contained in:
Brent Baude
2023-10-18 10:40:08 -05:00
parent 02757ab20d
commit cad4d0ee9f
9 changed files with 29 additions and 15 deletions

View File

@ -20,6 +20,14 @@ type QEMUVirtualization struct {
machine.Virtualization machine.Virtualization
} }
// setNewMachineCMDOpts are options needed to pass
// into setting up the qemu command line. long term, this need
// should be eliminated
// TODO Podman5
type setNewMachineCMDOpts struct {
imageDir string
}
// findQEMUBinary locates and returns the QEMU binary // findQEMUBinary locates and returns the QEMU binary
func findQEMUBinary() (string, error) { func findQEMUBinary() (string, error) {
cfg, err := config.Default() cfg, err := config.Default()
@ -41,8 +49,8 @@ func (v *MachineVM) setQMPMonitorSocket() error {
// setNewMachineCMD configure the CLI command that will be run to create the new // setNewMachineCMD configure the CLI command that will be run to create the new
// machine // machine
func (v *MachineVM) setNewMachineCMD(qemuBinary string) { func (v *MachineVM) setNewMachineCMD(qemuBinary string, cmdOpts *setNewMachineCMDOpts) {
v.CmdLine = NewQemuBuilder(qemuBinary, v.addArchOptions()) v.CmdLine = NewQemuBuilder(qemuBinary, v.addArchOptions(cmdOpts))
v.CmdLine.SetMemory(v.Memory) v.CmdLine.SetMemory(v.Memory)
v.CmdLine.SetCPUs(v.CPUs) v.CmdLine.SetCPUs(v.CPUs)
v.CmdLine.SetIgnitionFile(v.IgnitionFile) v.CmdLine.SetIgnitionFile(v.IgnitionFile)
@ -63,6 +71,11 @@ func (p *QEMUVirtualization) NewMachine(opts machine.InitOptions) (machine.VM, e
vm.Name = opts.Name vm.Name = opts.Name
} }
dataDir, err := machine.GetDataDir(p.VMType())
if err != nil {
return nil, err
}
// set VM ignition file // set VM ignition file
ignitionFile, err := machine.NewMachineFile(filepath.Join(vmConfigDir, vm.Name+".ign"), nil) ignitionFile, err := machine.NewMachineFile(filepath.Join(vmConfigDir, vm.Name+".ign"), nil)
if err != nil { if err != nil {
@ -112,7 +125,8 @@ func (p *QEMUVirtualization) NewMachine(opts machine.InitOptions) (machine.VM, e
} }
// configure command to run // configure command to run
vm.setNewMachineCMD(execPath) cmdOpts := setNewMachineCMDOpts{imageDir: dataDir}
vm.setNewMachineCMD(execPath, &cmdOpts)
return vm, nil return vm, nil
} }

View File

@ -4,7 +4,7 @@ var (
QemuCommand = "qemu-system-x86_64" QemuCommand = "qemu-system-x86_64"
) )
func (v *MachineVM) addArchOptions() []string { func (v *MachineVM) addArchOptions(_ *setNewMachineCMDOpts) []string {
opts := []string{"-machine", "q35,accel=hvf:tcg", "-cpu", "host"} opts := []string{"-machine", "q35,accel=hvf:tcg", "-cpu", "host"}
return opts return opts
} }

View File

@ -12,8 +12,8 @@ var (
QemuCommand = "qemu-system-aarch64" QemuCommand = "qemu-system-aarch64"
) )
func (v *MachineVM) addArchOptions() []string { func (v *MachineVM) addArchOptions(cmdOpts *setNewMachineCMDOpts) []string {
ovmfDir := getOvmfDir(v.ImagePath.GetPath(), v.Name) ovmfDir := getOvmfDir(cmdOpts.imageDir, v.Name)
opts := []string{ opts := []string{
"-accel", "hvf", "-accel", "hvf",
"-accel", "tcg", "-accel", "tcg",
@ -25,18 +25,18 @@ func (v *MachineVM) addArchOptions() []string {
} }
func (v *MachineVM) prepare() error { func (v *MachineVM) prepare() error {
ovmfDir := getOvmfDir(v.ImagePath.GetPath(), v.Name) ovmfDir := getOvmfDir(filepath.Dir(v.ImagePath.GetPath()), v.Name)
cmd := []string{"/bin/dd", "if=/dev/zero", "conv=sync", "bs=1m", "count=64", "of=" + ovmfDir} cmd := []string{"/bin/dd", "if=/dev/zero", "conv=sync", "bs=1m", "count=64", "of=" + ovmfDir}
return exec.Command(cmd[0], cmd[1:]...).Run() return exec.Command(cmd[0], cmd[1:]...).Run()
} }
func (v *MachineVM) archRemovalFiles() []string { func (v *MachineVM) archRemovalFiles() []string {
ovmDir := getOvmfDir(v.ImagePath.GetPath(), v.Name) ovmDir := getOvmfDir(filepath.Dir(v.ImagePath.GetPath()), v.Name)
return []string{ovmDir} return []string{ovmDir}
} }
func getOvmfDir(imagePath, vmName string) string { func getOvmfDir(imagePath, vmName string) string {
return filepath.Join(filepath.Dir(imagePath), vmName+"_ovmf_vars.fd") return filepath.Join(imagePath, vmName+"_ovmf_vars.fd")
} }
/* /*

View File

@ -4,7 +4,7 @@ var (
QemuCommand = "qemu-system-x86_64" QemuCommand = "qemu-system-x86_64"
) )
func (v *MachineVM) addArchOptions() []string { func (v *MachineVM) addArchOptions(_ *setNewMachineCMDOpts) []string {
opts := []string{"-machine", "q35,accel=hvf:tcg", "-cpu", "host"} opts := []string{"-machine", "q35,accel=hvf:tcg", "-cpu", "host"}
return opts return opts
} }

View File

@ -4,7 +4,7 @@ var (
QemuCommand = "qemu-system-aarch64" QemuCommand = "qemu-system-aarch64"
) )
func (v *MachineVM) addArchOptions() []string { func (v *MachineVM) addArchOptions(_ *setNewMachineCMDOpts) []string {
opts := []string{ opts := []string{
"-machine", "virt", "-machine", "virt",
"-accel", "tcg", "-accel", "tcg",

View File

@ -4,7 +4,7 @@ var (
QemuCommand = "qemu-system-x86_64" QemuCommand = "qemu-system-x86_64"
) )
func (v *MachineVM) addArchOptions() []string { func (v *MachineVM) addArchOptions(_ *setNewMachineCMDOpts) []string {
opts := []string{ opts := []string{
"-accel", "kvm", "-accel", "kvm",
"-cpu", "host", "-cpu", "host",

View File

@ -9,7 +9,7 @@ var (
QemuCommand = "qemu-system-aarch64" QemuCommand = "qemu-system-aarch64"
) )
func (v *MachineVM) addArchOptions() []string { func (v *MachineVM) addArchOptions(_ *setNewMachineCMDOpts) []string {
opts := []string{ opts := []string{
"-accel", "kvm", "-accel", "kvm",
"-cpu", "host", "-cpu", "host",

View File

@ -4,7 +4,7 @@ var (
QemuCommand = "qemu-system-x86_64w" QemuCommand = "qemu-system-x86_64w"
) )
func (v *MachineVM) addArchOptions() []string { func (v *MachineVM) addArchOptions(_ *setNewMachineCMDOpts) []string {
// "max" level is used, because "host" is not supported with "whpx" acceleration // "max" level is used, because "host" is not supported with "whpx" acceleration
// "vmx=off" disabled nested virtualization (not needed for podman) // "vmx=off" disabled nested virtualization (not needed for podman)
// QEMU issue to track nested virtualization: https://gitlab.com/qemu-project/qemu/-/issues/628 // QEMU issue to track nested virtualization: https://gitlab.com/qemu-project/qemu/-/issues/628

View File

@ -4,7 +4,7 @@ var (
QemuCommand = "qemu-system-aarch64w" QemuCommand = "qemu-system-aarch64w"
) )
func (v *MachineVM) addArchOptions() []string { func (v *MachineVM) addArchOptions(_ *setNewMachineCMDOpts) []string {
// stub to fix compilation issues // stub to fix compilation issues
opts := []string{} opts := []string{}
return opts return opts