libxl: Support firmware autoselection

Xen only supports one firmware, making autoselection easy to implement.
In fact, <os firmware='efi'> is probably preferable in the Xen driver,
where libxl supports a firmware setting with accepted values such as
bios, ovmf, uefi (currently same semantics as ovmf), seabios, etc.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Jim Fehlig 2021-06-03 14:04:30 -06:00
parent 7c5507df10
commit 07dc1ac9d2
2 changed files with 31 additions and 8 deletions

View File

@ -627,15 +627,28 @@ libxlMakeDomBuildInfo(virDomainDef *def,
/*
* Currently libxl only allows specifying the type of BIOS.
* If the type is PFLASH, we assume OVMF and set libxl_bios_type
* If automatic firmware selection is enabled or the loader
* type is PFLASH, we assume OVMF and set libxl_bios_type
* to LIBXL_BIOS_TYPE_OVMF. The path to the OVMF firmware is
* configured when building Xen using '--with-system-ovmf='. If
* not specified, LIBXL_FIRMWARE_DIR/ovmf.bin is used. In the
* future, Xen will support a user-specified firmware path. See
* https://lists.xenproject.org/archives/html/xen-devel/2016-03/msg01628.html
*/
if (virDomainDefHasOldStyleUEFI(def))
if (def->os.firmware == VIR_DOMAIN_OS_DEF_FIRMWARE_EFI) {
if (def->os.loader == NULL)
def->os.loader = g_new0(virDomainLoaderDef, 1);
if (def->os.loader->path == NULL)
def->os.loader->path = g_strdup(cfg->firmwares[0]->name);
if (def->os.loader->type == VIR_DOMAIN_LOADER_TYPE_NONE)
def->os.loader->type = VIR_DOMAIN_LOADER_TYPE_PFLASH;
if (def->os.loader->readonly == VIR_TRISTATE_BOOL_ABSENT)
def->os.loader->readonly = VIR_TRISTATE_BOOL_YES;
b_info->u.hvm.bios = LIBXL_BIOS_TYPE_OVMF;
def->os.firmware = VIR_DOMAIN_OS_DEF_FIRMWARE_NONE;
} else if (virDomainDefHasOldStyleUEFI(def)) {
b_info->u.hvm.bios = LIBXL_BIOS_TYPE_OVMF;
}
if (def->emulator) {
if (!virFileExists(def->emulator)) {

View File

@ -440,6 +440,7 @@ libxlDomainDefValidate(const virDomainDef *def,
{
libxlDriverPrivate *driver = opaque;
g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
bool reqSecureBoot = false;
if (!virCapabilitiesDomainSupported(cfg->caps, def->os.type,
def->os.arch,
@ -447,13 +448,20 @@ libxlDomainDefValidate(const virDomainDef *def,
return -1;
/* Xen+ovmf does not support secure boot */
if (def->os.firmware == VIR_DOMAIN_OS_DEF_FIRMWARE_EFI) {
if (def->os.firmwareFeatures &&
def->os.firmwareFeatures[VIR_DOMAIN_OS_DEF_FIRMWARE_FEATURE_SECURE_BOOT])
reqSecureBoot = true;
}
if (virDomainDefHasOldStyleUEFI(def)) {
if (def->os.loader &&
def->os.loader->secure == VIR_TRISTATE_BOOL_YES) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Secure boot is not supported on Xen"));
return -1;
}
def->os.loader->secure == VIR_TRISTATE_BOOL_YES)
reqSecureBoot = true;
}
if (reqSecureBoot) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Secure boot is not supported on Xen"));
return -1;
}
return 0;
@ -465,7 +473,9 @@ virDomainDefParserConfig libxlDomainDefParserConfig = {
.devicesPostParseCallback = libxlDomainDeviceDefPostParse,
.domainPostParseCallback = libxlDomainDefPostParse,
.domainValidateCallback = libxlDomainDefValidate,
.features = VIR_DOMAIN_DEF_FEATURE_NET_MODEL_STRING,
.features = VIR_DOMAIN_DEF_FEATURE_FW_AUTOSELECT |
VIR_DOMAIN_DEF_FEATURE_NET_MODEL_STRING,
};