Up until now there are just two ways how to specify UEFI paths to
libvirt. The first one is editing qemu.conf, the other is editing
qemu_conf.c and recompile which is not that fancy. So, new
configure option is introduced: --with-loader-nvram which takes a
list of pairs of UEFI firmware and NVRAM store. This way, the
compiled in defaults can be passed during compile time without
need to change the code itself.

Signed-off-by: Michal Privoznik <mpriv...@redhat.com>
---
 configure.ac           | 17 +++++++++++++++++
 src/qemu/qemu_conf.c   | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 tests/domaincapstest.c | 15 ++++++++-------
 3 files changed, 74 insertions(+), 7 deletions(-)

diff --git a/configure.ac b/configure.ac
index f370475..b121777 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2789,6 +2789,23 @@ AC_ARG_WITH([default-editor],
   [DEFAULT_EDITOR=vi])
 AC_DEFINE_UNQUOTED([DEFAULT_EDITOR], ["$DEFAULT_EDITOR"], [Default editor to 
use])
 
+AC_ARG_WITH([loader-nvram],
+  [AS_HELP_STRING([--with-loader-nvram],
+    [Pass list of pairs of <loader>:<nvram> paths. Both
+     pairs and list items are separated by a colon.
+     @<:default=paths to OVMF and its clones@:>@])],
+     [if test "$withval" = "no"; then
+        withval=""
+      else
+        l=`echo $withval | tr ':' '\n' | wc -l`
+        if test "$((l % 2))" -ne 0; then
+            AC_MSG_ERROR([Malformed --with-loader-nvram argument])
+        fi
+      fi
+      AC_DEFINE_UNQUOTED([DEFAULT_LOADER_NVRAM],
+                          ["$withval"],
+                          [List of laoder:nvram pairs])])
+
 # Some GNULIB base64 symbols clash with a kerberos library
 AC_DEFINE_UNQUOTED([isbase64],[libvirt_gl_isbase64],[Hack to avoid symbol 
clash])
 AC_DEFINE_UNQUOTED([base64_encode],[libvirt_gl_base64_encode],[Hack to avoid 
symbol clash])
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index a24c5c5..a6183b9 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -107,6 +107,48 @@ void qemuDomainCmdlineDefFree(qemuDomainCmdlineDefPtr def)
     VIR_FREE(def);
 }
 
+
+static int ATTRIBUTE_UNUSED
+virQEMUDriverConfigLoaderNVRAMParse(virQEMUDriverConfigPtr cfg,
+                                    const char *list)
+{
+    int ret = -1;
+    char **token;
+    size_t i, j;
+
+    if (!(token = virStringSplit(list, ":", 0)))
+        goto cleanup;
+
+    for (i = 0; token[i]; i += 2) {
+        if (!token[i] || !token[i + 1] ||
+            STREQ(token[i], "") || STREQ(token[i + 1], "")) {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("Invalid --with-loader-nvram list: %s"),
+                           list);
+            goto cleanup;
+        }
+    }
+
+    if (i) {
+        if (VIR_ALLOC_N(cfg->loader, i / 2) < 0 ||
+            VIR_ALLOC_N(cfg->nvram, i / 2) < 0)
+            goto cleanup;
+        cfg->nloader = i / 2;
+
+        for (j = 0; j < i / 2; j++) {
+            if (VIR_STRDUP(cfg->loader[j], token[2 * j]) < 0 ||
+                VIR_STRDUP(cfg->nvram[j], token[2 * j + 1]) < 0)
+                goto cleanup;
+        }
+    }
+
+    ret = 0;
+ cleanup:
+    virStringFreeList(token);
+    return ret;
+}
+
+
 #define VIR_QEMU_LOADER_FILE_PATH "/usr/share/OVMF/OVMF_CODE.fd"
 #define VIR_QEMU_NVRAM_FILE_PATH "/usr/share/OVMF/OVMF_VARS.fd"
 
@@ -258,6 +300,12 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool 
privileged)
 
     cfg->logTimestamp = true;
 
+#ifdef DEFAULT_LOADER_NVRAM
+    if (virQEMUDriverConfigLoaderNVRAMParse(cfg, DEFAULT_LOADER_NVRAM) < 0)
+        goto error;
+
+#else
+
     if (VIR_ALLOC_N(cfg->loader, 1) < 0 ||
         VIR_ALLOC_N(cfg->nvram, 1) < 0)
         goto error;
@@ -266,6 +314,7 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool 
privileged)
     if (VIR_STRDUP(cfg->loader[0], VIR_QEMU_LOADER_FILE_PATH) < 0 ||
         VIR_STRDUP(cfg->nvram[0], VIR_QEMU_NVRAM_FILE_PATH) < 0)
         goto error;
+#endif
 
     return cfg;
 
diff --git a/tests/domaincapstest.c b/tests/domaincapstest.c
index 70d2ef3..5ec03a4 100644
--- a/tests/domaincapstest.c
+++ b/tests/domaincapstest.c
@@ -105,6 +105,7 @@ fillQemuCaps(virDomainCapsPtr domCaps,
     struct fillQemuCapsData *data = (struct fillQemuCapsData *) opaque;
     virQEMUCapsPtr qemuCaps = data->qemuCaps;
     virQEMUDriverConfigPtr cfg = data->cfg;
+    virDomainCapsLoaderPtr loader = &domCaps->os.loader;
 
     if (virQEMUCapsFillDomainCaps(domCaps, qemuCaps,
                                   cfg->loader, cfg->nloader) < 0)
@@ -122,14 +123,14 @@ fillQemuCaps(virDomainCapsPtr domCaps,
 
     /* Moreover, as of f05b6a918e28 we are expecting to see
      * OVMF_CODE.fd file which may not exists everywhere. */
-    if (!domCaps->os.loader.values.nvalues) {
-        virDomainCapsLoaderPtr loader = &domCaps->os.loader;
+    while (loader->values.nvalues)
+        VIR_FREE(loader->values.values[--loader->values.nvalues]);
+
+    if (fillStringValues(&loader->values,
+                         "/usr/share/OVMF/OVMF_CODE.fd",
+                         NULL) < 0)
+        return -1;
 
-        if (fillStringValues(&loader->values,
-                             "/usr/share/OVMF/OVMF_CODE.fd",
-                             NULL) < 0)
-            return -1;
-    }
     return 0;
 }
 #endif /* WITH_QEMU */
-- 
2.0.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to