[libvirt] [PATCH] bhyve: add config file support

Roman Bogorodskiy posted 1 patch 7 years ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20170313180220.63456-1-bogorodskiy@gmail.com
src/Makefile.am                      |  25 +++++++-
src/bhyve/bhyve.conf                 |   7 +++
src/bhyve/bhyve_capabilities.c       |   9 ++-
src/bhyve/bhyve_capabilities.h       |   5 +-
src/bhyve/bhyve_conf.c               | 112 +++++++++++++++++++++++++++++++++++
src/bhyve/bhyve_conf.h               |  32 ++++++++++
src/bhyve/bhyve_driver.c             |  11 +++-
src/bhyve/bhyve_utils.h              |  12 ++++
src/bhyve/libvirtd_bhyve.aug         |  39 ++++++++++++
src/bhyve/test_libvirtd_bhyve.aug.in |   5 ++
10 files changed, 252 insertions(+), 5 deletions(-)
create mode 100644 src/bhyve/bhyve.conf
create mode 100644 src/bhyve/bhyve_conf.c
create mode 100644 src/bhyve/bhyve_conf.h
create mode 100644 src/bhyve/libvirtd_bhyve.aug
create mode 100644 src/bhyve/test_libvirtd_bhyve.aug.in
[libvirt] [PATCH] bhyve: add config file support
Posted by Roman Bogorodskiy 7 years ago
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                      |  25 +++++++-
 src/bhyve/bhyve.conf                 |   7 +++
 src/bhyve/bhyve_capabilities.c       |   9 ++-
 src/bhyve/bhyve_capabilities.h       |   5 +-
 src/bhyve/bhyve_conf.c               | 112 +++++++++++++++++++++++++++++++++++
 src/bhyve/bhyve_conf.h               |  32 ++++++++++
 src/bhyve/bhyve_driver.c             |  11 +++-
 src/bhyve/bhyve_utils.h              |  12 ++++
 src/bhyve/libvirtd_bhyve.aug         |  39 ++++++++++++
 src/bhyve/test_libvirtd_bhyve.aug.in |   5 ++
 10 files changed, 252 insertions(+), 5 deletions(-)
 create mode 100644 src/bhyve/bhyve.conf
 create mode 100644 src/bhyve/bhyve_conf.c
 create mode 100644 src/bhyve/bhyve_conf.h
 create mode 100644 src/bhyve/libvirtd_bhyve.aug
 create mode 100644 src/bhyve/test_libvirtd_bhyve.aug.in

diff --git a/src/Makefile.am b/src/Makefile.am
index 02579659a..f0d8efe50 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -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
index 000000000..2a8baacff
--- /dev/null
+++ b/src/bhyve/bhyve.conf
@@ -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"
diff --git a/src/bhyve/bhyve_capabilities.c b/src/bhyve/bhyve_capabilities.c
index 5e6094e3c..da06ba711 100644
--- a/src/bhyve/bhyve_capabilities.c
+++ b/src/bhyve/bhyve_capabilities.c
@@ -111,7 +111,8 @@ virBhyveCapsBuild(void)
 }
 
 virDomainCapsPtr
-virBhyveDomainCapsBuild(const char *emulatorbin,
+virBhyveDomainCapsBuild(bhyveConnPtr conn,
+                        const char *emulatorbin,
                         const char *machine,
                         virArch arch,
                         virDomainVirtType virttype)
@@ -120,8 +121,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;
@@ -152,7 +154,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,
diff --git a/src/bhyve/bhyve_capabilities.h b/src/bhyve/bhyve_capabilities.h
index 8fb97d730..3d8edb490 100644
--- a/src/bhyve/bhyve_capabilities.h
+++ b/src/bhyve/bhyve_capabilities.h
@@ -25,8 +25,11 @@
 # include "capabilities.h"
 # include "conf/domain_capabilities.h"
 
+# include "bhyve_conf.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
index 000000000..b0b40c575
--- /dev/null
+++ b/src/bhyve/bhyve_conf.c
@@ -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
index 000000000..3f105ace1
--- /dev/null
+++ b/src/bhyve/bhyve_conf.h
@@ -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 */
diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c
index 759825c28..3258c2720 100644
--- a/src/bhyve/bhyve_driver.c
+++ b/src/bhyve/bhyve_driver.c
@@ -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);
diff --git a/src/bhyve/bhyve_utils.h b/src/bhyve/bhyve_utils.h
index 9a911608c..db50e012a 100644
--- a/src/bhyve/bhyve_utils.h
+++ b/src/bhyve/bhyve_utils.h
@@ -34,8 +34,20 @@
 # 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
index 000000000..66079376c
--- /dev/null
+++ b/src/bhyve/libvirtd_bhyve.aug
@@ -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
index 000000000..f28e58614
--- /dev/null
+++ b/src/bhyve/test_libvirtd_bhyve.aug.in
@@ -0,0 +1,5 @@
+module Test_libvirtd_bhyve =
+  ::CONFIG::
+
+  test Libvirtd_bhyve.lns get conf =
+{ "firmware_dir" = "/usr/local/share/uefi-firmware" }
-- 
2.11.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] bhyve: add config file support
Posted by Michal Privoznik 7 years ago
On 03/13/2017 07:02 PM, Roman Bogorodskiy wrote:
> 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                      |  25 +++++++-
>  src/bhyve/bhyve.conf                 |   7 +++
>  src/bhyve/bhyve_capabilities.c       |   9 ++-
>  src/bhyve/bhyve_capabilities.h       |   5 +-
>  src/bhyve/bhyve_conf.c               | 112 +++++++++++++++++++++++++++++++++++
>  src/bhyve/bhyve_conf.h               |  32 ++++++++++
>  src/bhyve/bhyve_driver.c             |  11 +++-
>  src/bhyve/bhyve_utils.h              |  12 ++++
>  src/bhyve/libvirtd_bhyve.aug         |  39 ++++++++++++
>  src/bhyve/test_libvirtd_bhyve.aug.in |   5 ++
>  10 files changed, 252 insertions(+), 5 deletions(-)
>  create mode 100644 src/bhyve/bhyve.conf
>  create mode 100644 src/bhyve/bhyve_conf.c
>  create mode 100644 src/bhyve/bhyve_conf.h
>  create mode 100644 src/bhyve/libvirtd_bhyve.aug
>  create mode 100644 src/bhyve/test_libvirtd_bhyve.aug.in
> 
> diff --git a/src/Makefile.am b/src/Makefile.am
> index 02579659a..f0d8efe50 100644
> --- a/src/Makefile.am
> +++ b/src/Makefile.am
> @@ -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
> index 000000000..2a8baacff
> --- /dev/null
> +++ b/src/bhyve/bhyve.conf
> @@ -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"
> diff --git a/src/bhyve/bhyve_capabilities.c b/src/bhyve/bhyve_capabilities.c
> index 5e6094e3c..da06ba711 100644
> --- a/src/bhyve/bhyve_capabilities.c
> +++ b/src/bhyve/bhyve_capabilities.c
> @@ -111,7 +111,8 @@ virBhyveCapsBuild(void)
>  }
>  
>  virDomainCapsPtr
> -virBhyveDomainCapsBuild(const char *emulatorbin,
> +virBhyveDomainCapsBuild(bhyveConnPtr conn,
> +                        const char *emulatorbin,
>                          const char *machine,
>                          virArch arch,
>                          virDomainVirtType virttype)
> @@ -120,8 +121,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);

You need to unref @cfg.

> +    const char *firmware_dir = cfg->firmwareDir;
>  
>      if (!(caps = virDomainCapsNew(emulatorbin, machine, arch, virttype)))
>          goto cleanup;
> @@ -152,7 +154,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,
> diff --git a/src/bhyve/bhyve_capabilities.h b/src/bhyve/bhyve_capabilities.h
> index 8fb97d730..3d8edb490 100644
> --- a/src/bhyve/bhyve_capabilities.h
> +++ b/src/bhyve/bhyve_capabilities.h
> @@ -25,8 +25,11 @@
>  # include "capabilities.h"
>  # include "conf/domain_capabilities.h"
>  
> +# include "bhyve_conf.h"
> +

This include is because of bhyveConnPtr type I assume. Well, that one is defined in bhyve_utils.h which is the file you should be including.
After you've done that you'll find that bhyve_capabilities needs to include bhyve_conf.h" because of virBhyveDriverGetConfig call. But that's okay - you can replace include of bhyve_utils.h there with bhyve_conf.h:

diff --git a/src/bhyve/bhyve_capabilities.c b/src/bhyve/bhyve_capabilities.c
index 0b7881d60..4672170b3 100644
--- a/src/bhyve/bhyve_capabilities.c
+++ b/src/bhyve/bhyve_capabilities.c
@@ -32,10 +32,10 @@
 #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
 
diff --git a/src/bhyve/bhyve_capabilities.h b/src/bhyve/bhyve_capabilities.h
index 3d8edb490..e6d934bc2 100644
--- a/src/bhyve/bhyve_capabilities.h
+++ b/src/bhyve/bhyve_capabilities.h
@@ -24,8 +24,7 @@
 
 # include "capabilities.h"
 # include "conf/domain_capabilities.h"
-
-# include "bhyve_conf.h"
+# include "bhyve_utils.h"
 
 virCapsPtr virBhyveCapsBuild(void);
 virDomainCapsPtr virBhyveDomainCapsBuild(bhyveConnPtr,


>  virCapsPtr virBhyveCapsBuild(void);
> -virDomainCapsPtr virBhyveDomainCapsBuild(const char *emulatorbin,
> +virDomainCapsPtr virBhyveDomainCapsBuild(bhyveConnPtr,
> +                                         const char *emulatorbin,
>                                           const char *machine,
>                                           virArch arch,
>                                           virDomainVirtType virttype);

With that squashed in, and unrefing @cfg you have my ACK.

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] bhyve: add config file support
Posted by Roman Bogorodskiy 7 years ago
  Michal Privoznik wrote:

> On 03/13/2017 07:02 PM, Roman Bogorodskiy wrote:
> > 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                      |  25 +++++++-
> >  src/bhyve/bhyve.conf                 |   7 +++
> >  src/bhyve/bhyve_capabilities.c       |   9 ++-
> >  src/bhyve/bhyve_capabilities.h       |   5 +-
> >  src/bhyve/bhyve_conf.c               | 112 +++++++++++++++++++++++++++++++++++
> >  src/bhyve/bhyve_conf.h               |  32 ++++++++++
> >  src/bhyve/bhyve_driver.c             |  11 +++-
> >  src/bhyve/bhyve_utils.h              |  12 ++++
> >  src/bhyve/libvirtd_bhyve.aug         |  39 ++++++++++++
> >  src/bhyve/test_libvirtd_bhyve.aug.in |   5 ++
> >  10 files changed, 252 insertions(+), 5 deletions(-)
> >  create mode 100644 src/bhyve/bhyve.conf
> >  create mode 100644 src/bhyve/bhyve_conf.c
> >  create mode 100644 src/bhyve/bhyve_conf.h
> >  create mode 100644 src/bhyve/libvirtd_bhyve.aug
> >  create mode 100644 src/bhyve/test_libvirtd_bhyve.aug.in
> > 
> > diff --git a/src/bhyve/bhyve_capabilities.c b/src/bhyve/bhyve_capabilities.c
> > index 5e6094e3c..da06ba711 100644
> > --- a/src/bhyve/bhyve_capabilities.c
> > +++ b/src/bhyve/bhyve_capabilities.c
> > @@ -111,7 +111,8 @@ virBhyveCapsBuild(void)
> >  }
> >  
> >  virDomainCapsPtr
> > -virBhyveDomainCapsBuild(const char *emulatorbin,
> > +virBhyveDomainCapsBuild(bhyveConnPtr conn,
> > +                        const char *emulatorbin,
> >                          const char *machine,
> >                          virArch arch,
> >                          virDomainVirtType virttype)
> > @@ -120,8 +121,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);
> 
> You need to unref @cfg.

Fixed.

> > +    const char *firmware_dir = cfg->firmwareDir;
> >  
> >      if (!(caps = virDomainCapsNew(emulatorbin, machine, arch, virttype)))
> >          goto cleanup;
> > @@ -152,7 +154,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,
> > diff --git a/src/bhyve/bhyve_capabilities.h b/src/bhyve/bhyve_capabilities.h
> > index 8fb97d730..3d8edb490 100644
> > --- a/src/bhyve/bhyve_capabilities.h
> > +++ b/src/bhyve/bhyve_capabilities.h
> > @@ -25,8 +25,11 @@
> >  # include "capabilities.h"
> >  # include "conf/domain_capabilities.h"
> >  
> > +# include "bhyve_conf.h"
> > +
> 
> This include is because of bhyveConnPtr type I assume. Well, that one is defined in bhyve_utils.h which is the file you should be including.

Actually it's simpler: initially I planned to pass
virBhyveDriverConfigPtr instead of bhyveConnPtr to virBhyveDomainCapsBuild(),
but then decided to call virBhyveDriverGetConfig() in the place where it's
actually used and made a last minute change forgetting to change
includes (which unfortunately didn't trigger a warning).

> After you've done that you'll find that bhyve_capabilities needs to include bhyve_conf.h" because of virBhyveDriverGetConfig call. But that's okay - you can replace include of bhyve_utils.h there with bhyve_conf.h:
> 
> >  virCapsPtr virBhyveCapsBuild(void);
> > -virDomainCapsPtr virBhyveDomainCapsBuild(const char *emulatorbin,
> > +virDomainCapsPtr virBhyveDomainCapsBuild(bhyveConnPtr,
> > +                                         const char *emulatorbin,
> >                                           const char *machine,
> >                                           virArch arch,
> >                                           virDomainVirtType virttype);
> 
> With that squashed in, and unrefing @cfg you have my ACK.
> 
> Michal

Pushed with the fixes applied, thanks!

Roman Bogorodskiy
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] bhyve: add config file support
Posted by Andrea Bolognani 7 years ago
On Tue, 2017-03-14 at 20:58 +0400, Roman Bogorodskiy wrote:
> Pushed with the fixes applied, thanks!

Don't forget to document this new feature in the
release notes! ;)

-- 
Andrea Bolognani / Red Hat / Virtualization

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