]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
bhyve: add config file support
authorRoman Bogorodskiy <bogorodskiy@gmail.com>
Sat, 11 Mar 2017 16:19:03 +0000 (20:19 +0400)
committerRoman Bogorodskiy <bogorodskiy@gmail.com>
Tue, 14 Mar 2017 16:46:05 +0000 (20:46 +0400)
Introduce config file support for the bhyve driver. The only available
setting at present is 'firmware_dir' for specifying a directory with
UEFI firmware files.

src/Makefile.am
src/bhyve/bhyve.conf [new file with mode: 0644]
src/bhyve/bhyve_capabilities.c
src/bhyve/bhyve_capabilities.h
src/bhyve/bhyve_conf.c [new file with mode: 0644]
src/bhyve/bhyve_conf.h [new file with mode: 0644]
src/bhyve/bhyve_driver.c
src/bhyve/bhyve_utils.h
src/bhyve/libvirtd_bhyve.aug [new file with mode: 0644]
src/bhyve/test_libvirtd_bhyve.aug.in [new file with mode: 0644]

index 02579659abe1f559c6098730aa4956bba9e738d5..f0d8efe5074115642751efe21814a8deb62b1df6 100644 (file)
@@ -930,6 +930,8 @@ BHYVE_DRIVER_SOURCES =                                              \
                bhyve/bhyve_capabilities.h                      \
                bhyve/bhyve_command.c                           \
                bhyve/bhyve_command.h                           \
+               bhyve/bhyve_conf.c                              \
+               bhyve/bhyve_conf.h                              \
                bhyve/bhyve_parse_command.c                     \
                bhyve/bhyve_parse_command.h                     \
                bhyve/bhyve_device.c                            \
@@ -1575,7 +1577,14 @@ libvirt_driver_bhyve_impl_la_CFLAGS = \
        $(AM_CFLAGS)
 libvirt_driver_bhyve_impl_la_LDFLAGS = $(AM_LDFLAGS)
 libvirt_driver_bhyve_impl_la_SOURCES = $(BHYVE_DRIVER_SOURCES)
+
+conf_DATA += bhyve/bhyve.conf
+augeas_DATA += bhyve/libvirtd_bhyve.aug
+augeastest_DATA += test_libvirtd_bhyve.aug
 endif WITH_BHYVE
+EXTRA_DIST += bhyve/bhyve.conf \
+       bhyve/libvirtd_bhyve.aug \
+       bhyve/test_libvirtd_bhyve.aug.in
 
 if WITH_NETWORK
 noinst_LTLIBRARIES += libvirt_driver_network_impl.la
@@ -2125,11 +2134,12 @@ check-local: check-augeas
        check-augeas-sanlock \
        check-augeas-lockd \
        check-augeas-libxl \
+       check-augeas-bhyve \
        $(NULL)
 
 check-augeas: check-augeas-qemu check-augeas-lxc check-augeas-sanlock \
        check-augeas-lockd check-augeas-virtlockd check-augeas-libxl \
-       check-augeas-virtlogd
+       check-augeas-bhyve check-augeas-virtlogd
 
 AUG_GENTEST = $(PERL) $(top_srcdir)/build-aux/augeas-gentest.pl
 EXTRA_DIST += $(top_srcdir)/build-aux/augeas-gentest.pl
@@ -2212,6 +2222,19 @@ else ! WITH_LIBXL
 check-augeas-libxl:
 endif ! WITH_LIBXL
 
+if WITH_BHYVE
+test_libvirtd_bhyve.aug: bhyve/test_libvirtd_bhyve.aug.in \
+               $(srcdir)/bhyve/bhyve.conf $(AUG_GENTEST)
+       $(AM_V_GEN)$(AUG_GENTEST) $(srcdir)/bhyve/bhyve.conf $< $@
+
+check-augeas-bhyve: test_libvirtd_bhyve.aug
+       $(AM_V_GEN)if test -x '$(AUGPARSE)'; then \
+           '$(AUGPARSE)' -I $(srcdir)/bhyve test_libvirtd_bhyve.aug; \
+       fi
+else ! WITH_BHYVE
+check-augeas-bhyve:
+endif ! WITH_BHYVE
+
 test_virtlogd.aug: logging/test_virtlogd.aug.in \
                logging/virtlogd.conf $(AUG_GENTEST)
        $(AM_V_GEN)$(AUG_GENTEST) $(srcdir)/logging/virtlogd.conf $< $@
diff --git a/src/bhyve/bhyve.conf b/src/bhyve/bhyve.conf
new file mode 100644 (file)
index 0000000..2a8baac
--- /dev/null
@@ -0,0 +1,7 @@
+# Master configuration file for the bhyve driver.
+# All settings described here are optional - if omitted, sensible
+# defaults are used.
+
+# Path to a directory with firmware files. By default it's pointing
+# to the directory that sysutils/bhyve-firmware installs files into.
+#firmware_dir = "/usr/local/share/uefi-firmware"
index cfcbde9d181eb288a4aa39652a6388f1e4436d33..4bf1d84fafc5fd5a37025173d5e6d20214933d48 100644 (file)
 #include "virstring.h"
 #include "cpu/cpu.h"
 #include "nodeinfo.h"
-#include "bhyve_utils.h"
 #include "domain_conf.h"
 #include "vircommand.h"
 #include "bhyve_capabilities.h"
+#include "bhyve_conf.h"
 
 #define VIR_FROM_THIS   VIR_FROM_BHYVE
 
@@ -88,7 +88,8 @@ virBhyveCapsBuild(void)
 }
 
 virDomainCapsPtr
-virBhyveDomainCapsBuild(const char *emulatorbin,
+virBhyveDomainCapsBuild(bhyveConnPtr conn,
+                        const char *emulatorbin,
                         const char *machine,
                         virArch arch,
                         virDomainVirtType virttype)
@@ -97,8 +98,9 @@ virBhyveDomainCapsBuild(const char *emulatorbin,
     unsigned int bhyve_caps = 0;
     DIR *dir;
     struct dirent *entry;
-    const char *firmware_dir = "/usr/local/share/uefi-firmware";
     size_t firmwares_alloc = 0;
+    virBhyveDriverConfigPtr cfg = virBhyveDriverGetConfig(conn);
+    const char *firmware_dir = cfg->firmwareDir;
 
     if (!(caps = virDomainCapsNew(emulatorbin, machine, arch, virttype)))
         goto cleanup;
@@ -129,7 +131,10 @@ virBhyveDomainCapsBuild(const char *emulatorbin,
 
            caps->os.loader.values.nvalues++;
         }
+    } else {
+        VIR_WARN("Cannot open firmware directory %s", firmware_dir);
     }
+
     caps->disk.supported = true;
     VIR_DOMAIN_CAPS_ENUM_SET(caps->disk.diskDevice,
                              VIR_DOMAIN_DISK_DEVICE_DISK,
@@ -147,6 +152,7 @@ virBhyveDomainCapsBuild(const char *emulatorbin,
     }
  cleanup:
     VIR_DIR_CLOSE(dir);
+    virObjectUnref(cfg);
     return caps;
 }
 
index 8fb97d73019a97ebc6f642f71693e3bac56b030e..3db4f1b88898b87999c15a9184cf731b6be690a7 100644 (file)
 # include "capabilities.h"
 # include "conf/domain_capabilities.h"
 
+# include "bhyve_utils.h"
+
 virCapsPtr virBhyveCapsBuild(void);
-virDomainCapsPtr virBhyveDomainCapsBuild(const char *emulatorbin,
+virDomainCapsPtr virBhyveDomainCapsBuild(bhyveConnPtr,
+                                         const char *emulatorbin,
                                          const char *machine,
                                          virArch arch,
                                          virDomainVirtType virttype);
diff --git a/src/bhyve/bhyve_conf.c b/src/bhyve/bhyve_conf.c
new file mode 100644 (file)
index 0000000..b0b40c5
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+ * bhyve_conf.c: bhyve config file
+ *
+ * Copyright (C) 2017 Roman Bogorodskiy
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <config.h>
+
+#include "viralloc.h"
+#include "virlog.h"
+#include "virstring.h"
+#include "bhyve_conf.h"
+#include "configmake.h"
+
+#define VIR_FROM_THIS VIR_FROM_BHYVE
+
+VIR_LOG_INIT("bhyve.bhyve_conf");
+
+static virClassPtr virBhyveDriverConfigClass;
+static void virBhyveDriverConfigDispose(void *obj);
+
+static int virBhyveConfigOnceInit(void)
+{
+     if (!(virBhyveDriverConfigClass = virClassNew(virClassForObject(),
+                                                   "virBhyveDriverConfig",
+                                                   sizeof(virBhyveDriverConfig),
+                                                   virBhyveDriverConfigDispose)))
+         return -1;
+
+     return 0;
+}
+
+VIR_ONCE_GLOBAL_INIT(virBhyveConfig)
+
+virBhyveDriverConfigPtr
+virBhyveDriverConfigNew(void)
+{
+    virBhyveDriverConfigPtr cfg;
+
+    if (virBhyveConfigInitialize() < 0)
+        return NULL;
+
+    if (!(cfg = virObjectNew(virBhyveDriverConfigClass)))
+        return NULL;
+
+    if (VIR_STRDUP(cfg->firmwareDir, DATADIR "/uefi-firmware") < 0)
+        goto error;
+
+    return cfg;
+
+ error:
+    virObjectUnref(cfg);
+    return NULL;
+}
+
+int
+virBhyveLoadDriverConfig(virBhyveDriverConfigPtr cfg,
+                         const char *filename)
+{
+    virConfPtr conf;
+    int ret = -1;
+
+    if (access(filename, R_OK) == -1) {
+        VIR_INFO("Could not read bhyve config file %s", filename);
+        return 0;
+    }
+
+    if (!(conf = virConfReadFile(filename, 0)))
+        return -1;
+
+    if (virConfGetValueString(conf, "firmware_dir",
+                              &cfg->firmwareDir) < 0)
+        goto cleanup;
+
+    ret = 0;
+ cleanup:
+    virConfFree(conf);
+    return ret;
+}
+
+virBhyveDriverConfigPtr
+virBhyveDriverGetConfig(bhyveConnPtr driver)
+{
+    virBhyveDriverConfigPtr cfg;
+    bhyveDriverLock(driver);
+    cfg = virObjectRef(driver->config);
+    bhyveDriverUnlock(driver);
+    return cfg;
+}
+
+static void
+virBhyveDriverConfigDispose(void *obj)
+{
+    virBhyveDriverConfigPtr cfg = obj;
+
+    VIR_FREE(cfg->firmwareDir);
+}
diff --git a/src/bhyve/bhyve_conf.h b/src/bhyve/bhyve_conf.h
new file mode 100644 (file)
index 0000000..3f105ac
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * bhyve_conf.h: bhyve config file
+ *
+ * Copyright (C) 2017 Roman Bogorodskiy
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef BHYVE_CONF_H
+# define BHYVE_CONF_H
+
+# include "bhyve_utils.h"
+
+virBhyveDriverConfigPtr virBhyveDriverConfigNew(void);
+virBhyveDriverConfigPtr virBhyveDriverGetConfig(bhyveConnPtr driver);
+int virBhyveLoadDriverConfig(virBhyveDriverConfigPtr cfg,
+                             const char *filename);
+
+#endif /* BHYVE_CONF_H */
index 759825c28b67d8f2b2c9f1ed3ac051ae323f8dff..3258c272085d0840cf18310fb6631c7963868d68 100644 (file)
@@ -55,6 +55,7 @@
 #include "virhostmem.h"
 #include "conf/domain_capabilities.h"
 
+#include "bhyve_conf.h"
 #include "bhyve_device.h"
 #include "bhyve_driver.h"
 #include "bhyve_command.h"
@@ -1228,6 +1229,7 @@ bhyveStateCleanup(void)
     virSysinfoDefFree(bhyve_driver->hostsysinfo);
     virObjectUnref(bhyve_driver->closeCallbacks);
     virObjectUnref(bhyve_driver->domainEventState);
+    virObjectUnref(bhyve_driver->config);
 
     virMutexDestroy(&bhyve_driver->lock);
     VIR_FREE(bhyve_driver);
@@ -1276,6 +1278,12 @@ bhyveStateInitialize(bool privileged,
 
     bhyve_driver->hostsysinfo = virSysinfoRead();
 
+    if (!(bhyve_driver->config = virBhyveDriverConfigNew()))
+        goto cleanup;
+
+    if (virBhyveLoadDriverConfig(bhyve_driver->config, SYSCONFDIR "/libvirt/bhyve.conf") < 0)
+        goto cleanup;
+
     if (virFileMakePath(BHYVE_LOG_DIR) < 0) {
         virReportSystemError(errno,
                              _("Failed to mkdir %s"),
@@ -1657,7 +1665,8 @@ bhyveConnectGetDomainCapabilities(virConnectPtr conn,
         goto cleanup;
     }
 
-    if (!(caps = virBhyveDomainCapsBuild(emulatorbin, machine, arch, virttype)))
+    if (!(caps = virBhyveDomainCapsBuild(conn->privateData, emulatorbin,
+                                         machine, arch, virttype)))
         goto cleanup;
 
     ret = virDomainCapsFormat(caps);
index 9a911608ccb42c9bf57e704e156d32b5e6be74f2..db50e012ac385aac0f8caf99250126e3b391850e 100644 (file)
 # define BHYVE_STATE_DIR        LOCALSTATEDIR "/run/libvirt/bhyve"
 # define BHYVE_LOG_DIR          LOCALSTATEDIR "/log/libvirt/bhyve"
 
+typedef struct _virBhyveDriverConfig virBhyveDriverConfig;
+typedef struct _virBhyveDriverConfig *virBhyveDriverConfigPtr;
+
+struct _virBhyveDriverConfig {
+    virObject parent;
+
+    char *firmwareDir;
+};
+
 struct _bhyveConn {
     virMutex lock;
+
+    virBhyveDriverConfigPtr config;
+
     virDomainObjListPtr domains;
     virCapsPtr caps;
     virDomainXMLOptionPtr xmlopt;
diff --git a/src/bhyve/libvirtd_bhyve.aug b/src/bhyve/libvirtd_bhyve.aug
new file mode 100644 (file)
index 0000000..6607937
--- /dev/null
@@ -0,0 +1,39 @@
+(* /etc/libvirt/bhyve.conf *)
+
+module Libvirtd_bhyve =
+   autoload xfm
+
+   let eol   = del /[ \t]*\n/ "\n"
+   let value_sep   = del /[ \t]*=[ \t]*/  " = "
+   let indent = del /[ \t]*/ ""
+
+   let array_sep  = del /,[ \t\n]*/ ", "
+   let array_start = del /\[[ \t\n]*/ "[ "
+   let array_end = del /\]/ "]"
+
+   let str_val = del /\"/ "\"" . store /[^\"]*/ . del /\"/ "\""
+   let bool_val = store /0|1/
+   let int_val = store /[0-9]+/
+   let str_array_element = [ seq "el" . str_val ] . del /[ \t\n]*/ ""
+   let str_array_val = counter "el" . array_start . ( str_array_element . ( array_sep . str_array_element ) * ) ? . array_end
+
+   let str_entry       (kw:string) = [ key kw . value_sep . str_val ]
+   let bool_entry      (kw:string) = [ key kw . value_sep . bool_val ]
+   let int_entry       (kw:string) = [ key kw . value_sep . int_val ]
+   let str_array_entry (kw:string) = [ key kw . value_sep . str_array_val ]
+
+   let log_entry = str_entry "firmware_dir"
+
+   (* Each enty in the config is one of the following three ... *)
+   let entry = log_entry
+   let comment = [ label "#comment" . del /#[ \t]*/ "# " .  store /([^ \t\n][^\n]*)?/ . del /\n/ "\n" ]
+   let empty = [ label "#empty" . eol ]
+
+   let record = indent . entry . eol
+
+   let lns = ( record | comment | empty ) *
+
+   let filter = incl "/etc/libvirt/bhyve.conf"
+              . Util.stdexcl
+
+   let xfm = transform lns filter
diff --git a/src/bhyve/test_libvirtd_bhyve.aug.in b/src/bhyve/test_libvirtd_bhyve.aug.in
new file mode 100644 (file)
index 0000000..f28e586
--- /dev/null
@@ -0,0 +1,5 @@
+module Test_libvirtd_bhyve =
+  ::CONFIG::
+
+  test Libvirtd_bhyve.lns get conf =
+{ "firmware_dir" = "/usr/local/share/uefi-firmware" }