Skip to content

Commit

Permalink
Merge pull request containers#20400 from baude/issue20361
Browse files Browse the repository at this point in the history
Fix path for omvf vars on Darwin/arm64
  • Loading branch information
openshift-ci[bot] authored Oct 18, 2023
2 parents d4086f5 + cad4d0e commit 9a29eb0
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 15 deletions.
20 changes: 17 additions & 3 deletions pkg/machine/qemu/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ type QEMUVirtualization struct {
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
func findQEMUBinary() (string, error) {
cfg, err := config.Default()
Expand All @@ -41,8 +49,8 @@ func (v *MachineVM) setQMPMonitorSocket() error {

// setNewMachineCMD configure the CLI command that will be run to create the new
// machine
func (v *MachineVM) setNewMachineCMD(qemuBinary string) {
v.CmdLine = NewQemuBuilder(qemuBinary, v.addArchOptions())
func (v *MachineVM) setNewMachineCMD(qemuBinary string, cmdOpts *setNewMachineCMDOpts) {
v.CmdLine = NewQemuBuilder(qemuBinary, v.addArchOptions(cmdOpts))
v.CmdLine.SetMemory(v.Memory)
v.CmdLine.SetCPUs(v.CPUs)
v.CmdLine.SetIgnitionFile(v.IgnitionFile)
Expand All @@ -63,6 +71,11 @@ func (p *QEMUVirtualization) NewMachine(opts machine.InitOptions) (machine.VM, e
vm.Name = opts.Name
}

dataDir, err := machine.GetDataDir(p.VMType())
if err != nil {
return nil, err
}

// set VM ignition file
ignitionFile, err := machine.NewMachineFile(filepath.Join(vmConfigDir, vm.Name+".ign"), nil)
if err != nil {
Expand Down Expand Up @@ -112,7 +125,8 @@ func (p *QEMUVirtualization) NewMachine(opts machine.InitOptions) (machine.VM, e
}

// configure command to run
vm.setNewMachineCMD(execPath)
cmdOpts := setNewMachineCMDOpts{imageDir: dataDir}
vm.setNewMachineCMD(execPath, &cmdOpts)
return vm, nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/machine/qemu/options_darwin_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var (
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"}
return opts
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/machine/qemu/options_darwin_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ var (
QemuCommand = "qemu-system-aarch64"
)

func (v *MachineVM) addArchOptions() []string {
ovmfDir := getOvmfDir(v.ImagePath.GetPath(), v.Name)
func (v *MachineVM) addArchOptions(cmdOpts *setNewMachineCMDOpts) []string {
ovmfDir := getOvmfDir(cmdOpts.imageDir, v.Name)
opts := []string{
"-accel", "hvf",
"-accel", "tcg",
Expand All @@ -25,18 +25,18 @@ func (v *MachineVM) addArchOptions() []string {
}

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}
return exec.Command(cmd[0], cmd[1:]...).Run()
}

func (v *MachineVM) archRemovalFiles() []string {
ovmDir := getOvmfDir(v.ImagePath.GetPath(), v.Name)
ovmDir := getOvmfDir(filepath.Dir(v.ImagePath.GetPath()), v.Name)
return []string{ovmDir}
}

func getOvmfDir(imagePath, vmName string) string {
return filepath.Join(filepath.Dir(imagePath), vmName+"_ovmf_vars.fd")
return filepath.Join(imagePath, vmName+"_ovmf_vars.fd")
}

/*
Expand Down
2 changes: 1 addition & 1 deletion pkg/machine/qemu/options_freebsd_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var (
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"}
return opts
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/machine/qemu/options_freebsd_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var (
QemuCommand = "qemu-system-aarch64"
)

func (v *MachineVM) addArchOptions() []string {
func (v *MachineVM) addArchOptions(_ *setNewMachineCMDOpts) []string {
opts := []string{
"-machine", "virt",
"-accel", "tcg",
Expand Down
2 changes: 1 addition & 1 deletion pkg/machine/qemu/options_linux_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var (
QemuCommand = "qemu-system-x86_64"
)

func (v *MachineVM) addArchOptions() []string {
func (v *MachineVM) addArchOptions(_ *setNewMachineCMDOpts) []string {
opts := []string{
"-accel", "kvm",
"-cpu", "host",
Expand Down
2 changes: 1 addition & 1 deletion pkg/machine/qemu/options_linux_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var (
QemuCommand = "qemu-system-aarch64"
)

func (v *MachineVM) addArchOptions() []string {
func (v *MachineVM) addArchOptions(_ *setNewMachineCMDOpts) []string {
opts := []string{
"-accel", "kvm",
"-cpu", "host",
Expand Down
2 changes: 1 addition & 1 deletion pkg/machine/qemu/options_windows_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var (
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
// "vmx=off" disabled nested virtualization (not needed for podman)
// QEMU issue to track nested virtualization: https://gitlab.com/qemu-project/qemu/-/issues/628
Expand Down
2 changes: 1 addition & 1 deletion pkg/machine/qemu/options_windows_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var (
QemuCommand = "qemu-system-aarch64w"
)

func (v *MachineVM) addArchOptions() []string {
func (v *MachineVM) addArchOptions(_ *setNewMachineCMDOpts) []string {
// stub to fix compilation issues
opts := []string{}
return opts
Expand Down

0 comments on commit 9a29eb0

Please sign in to comment.