]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
libxl: Support firmware autoselection
authorJim Fehlig <jfehlig@suse.com>
Thu, 3 Jun 2021 20:04:30 +0000 (14:04 -0600)
committerJim Fehlig <jfehlig@suse.com>
Tue, 8 Jun 2021 17:44:19 +0000 (11:44 -0600)
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>
src/libxl/libxl_conf.c
src/libxl/libxl_domain.c

index fc4268db018097ccfd52f29ee4e90d67509cce74..aef93fae53c8cc9f229211aed608bf74d2b38eb4 100644 (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)) {
index 14d000511a60909f91360e675cb78322b6bff9ce..59d26d5e2be6f91e2f3e3f443787f39bcb88137b 100644 (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,
 };