[PATCH] bhyve: add <os firmware='efi'> support

Pavel Hrdina phrdina at redhat.com
Mon Mar 15 11:05:12 UTC 2021


On Sat, Feb 27, 2021 at 08:34:08AM +0400, Roman Bogorodskiy wrote:
> Implement "<os firmware='efi'>" support for bhyve driver.
> As there are not really lot of options, try to find
> "BHYVE_UEFI.fd" firmware which is installed by the
> sysutils/uefi-edk2-bhyve FreeBSD port.
> 
> If not found, just use the first found firmware
> in the firmwares directory (which is configurable via
> config file).
> 
> Signed-off-by: Roman Bogorodskiy <bogorodskiy at gmail.com>
> ---
> Not extremely happy about the LIBVIRT_BHYVE_FIRMWARE_DIR_OVERRIDE knob,
> but not sure how to test this otherwise.

Agreed, that should not be part of the production code.

You can use tests/bhyvexml2argvmock.c which is already used for that
test where you would provide your custom implementation of opendir()
system call. The implementation should check if it tries to access the
default firmware dir and change it to location in our tests and all
other paths simply pass to the real opendir().

Look into tests/virpcimock.c, but the addition for your use-case should
look something like this:


diff --git a/tests/bhyvexml2argvmock.c b/tests/bhyvexml2argvmock.c
index 25b97f5e04..1c2b1f8876 100644
--- a/tests/bhyvexml2argvmock.c
+++ b/tests/bhyvexml2argvmock.c
@@ -4,10 +4,34 @@
 #include "virstring.h"
 #include "virnetdev.h"
 #include "virnetdevtap.h"
+#include "virmock.h"
 #include "internal.h"

 #define VIR_FROM_THIS VIR_FROM_BHYVE

+#define DEFAULT_FIRMWARE_DIR_TEMPLATE DATADIR "/uefi-firmware"
+#define FAKE_FIRMWARE_DIR_TEMPLATE abs_builddir "/bhyvefakefirmwaredir-XXXXXX"
+
+static int (*real_opendir)(const char *name);
+
+static void
+init_syms(void)
+{
+    VIR_MOCK_REAL_INIT(opendir);
+}
+
+DIR *
+opendir(const char *path)
+{
+    init_syms();
+
+    if (STRPREFIX(path, DEFAULT_FIRMWARE_DIR_TEMPLATE)) {
+        return real_opendir(FAKE_FIRMWARE_DIR_TEMPLATE);
+    } else {
+        return real_opendir(path);
+    }
+}
+
 void virMacAddrGenerate(const unsigned char prefix[VIR_MAC_PREFIX_BUFLEN],
                         virMacAddrPtr addr)
 {


I did not test it :)

Pavel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20210315/301cbd68/attachment-0001.sig>


More information about the libvir-list mailing list