qemu: Reorganize the qemu arch patch

This commit is contained in:
Brian C. Lane 2021-01-19 12:00:32 -08:00
parent 31044c2dd5
commit c646e05757

View File

@ -135,23 +135,32 @@ class QEMUInstall(object):
""" """
Run qemu using an iso and a kickstart Run qemu using an iso and a kickstart
""" """
# Mapping of arch to qemu command # Mapping of arch to qemu command and options
QEMU_CMDS = {"x86_64": "qemu-system-x86_64", QEMU = {"x86_64": {
"i386": "qemu-system-i386", "cmd": "qemu-system-x86_64",
"arm": "qemu-system-arm", "arches": ["x86_64", "i386"],
"aarch64": "qemu-system-aarch64", "machine": "q35",
"ppc64le": "qemu-system-ppc64" },
} "i386": {
COMPATIBLE_ARCHS = {"x86_64": [ "x86_64", "i386" ], "cmd": "qemu-system-i386",
"i386": [ "i386" ], "arches": ["i386"],
"arm": [ "arm" ], "machine": "q35",
"aarch64": [ "aarch64", "arm" ], },
"ppc64le": [ "ppc64le" ]} "arm": {
QEMU_DEFAULT_MACHINE = {"x86_64": "q35", "cmd": "qemu-system-arm",
"i386": "q35", "arches": ["arm"],
"arm": "virt", "machine": "virt",
"aarch64": "virt", },
"ppc64le": "pseries" "aarch64": {
"cmd": "qemu-system-aarch64",
"arches": ["aarch64", "arm"],
"machine": "virt",
},
"ppc64le": {
"cmd": "qemu-system-ppc64",
"arches": ["ppc64le"],
"machine": "pseries",
},
} }
def __init__(self, opts, iso, ks_paths, disk_img, img_size=2048, def __init__(self, opts, iso, ks_paths, disk_img, img_size=2048,
@ -181,11 +190,13 @@ class QEMUInstall(object):
:param str ovmf_path: Path to the OVMF firmware :param str ovmf_path: Path to the OVMF firmware
""" """
target_arch = arch or os.uname().machine target_arch = arch or os.uname().machine
has_machine = False
# Lookup qemu-system- for arch if passed, or try to guess using host arch # Lookup qemu-system- for arch if passed, or try to guess using host arch
qemu_cmd = [self.QEMU_CMDS.get(target_arch, "qemu-system-"+os.uname().machine)] if target_arch in self.QEMU:
if not os.path.exists("/usr/bin/"+qemu_cmd[0]): qemu_cmd = [self.QEMU[target_arch]["cmd"]]
raise InstallError("%s does not exist, cannot run qemu" % qemu_cmd[0]) elif os.path.exists("/usr/bin/"+"qemu-system-"+os.uname().machine):
qemu_cmd = ["/usr/bin/qemu-system-"+os.uname().machine]
else:
raise InstallError("/usr/bin/qemu-system-%s does not exist, cannot run qemu" % os.uname().machine)
qemu_cmd += ["-no-user-config"] qemu_cmd += ["-no-user-config"]
qemu_cmd += ["-m", str(memory)] qemu_cmd += ["-m", str(memory)]
@ -193,21 +204,19 @@ class QEMUInstall(object):
qemu_cmd += ["-smp", str(vcpus)] qemu_cmd += ["-smp", str(vcpus)]
if not opts.no_kvm and os.path.exists("/dev/kvm"): if not opts.no_kvm and os.path.exists("/dev/kvm"):
if os.uname().machine not in self.COMPATIBLE_ARCHS[target_arch]: if os.uname().machine not in self.QEMU[target_arch]["arches"]:
raise InstallError("KVM support not available to run %s on %s" % (target_arch, os.uname().machine)) raise InstallError("KVM support not available to run %s on %s" % (target_arch, os.uname().machine))
qemu_cmd += ["-machine", "accel=kvm"] qemu_cmd += ["-machine", "accel=kvm"]
has_machine = True
if boot_uefi: if boot_uefi:
if target_arch == x86_64: if target_arch != "x86_64":
qemu_cmd += ["-machine", "q35,smm=on"]
qemu_cmd += ["-global", "driver=cfi.pflash01,property=secure,value=on"]
has_machine = True
else:
raise InstallError("UEFI support not available for %s (yet?)" % target_arch) raise InstallError("UEFI support not available for %s (yet?)" % target_arch)
if not has_machine: qemu_cmd += ["-machine", "q35,smm=on"]
qemu_cmd += ["-machine", self.QEMU_DEFAULT_MACHINE[target_arch]] qemu_cmd += ["-global", "driver=cfi.pflash01,property=secure,value=on"]
if "-machine" not in qemu_cmd:
qemu_cmd += ["-machine", self.QEMU[target_arch]["machine"]]
# Copy the initrd from the iso, create a cpio archive of the kickstart files # Copy the initrd from the iso, create a cpio archive of the kickstart files
# and append it to the temporary initrd. # and append it to the temporary initrd.