bhyve: add config file support

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.
This commit is contained in:
Roman Bogorodskiy 2017-03-11 20:19:03 +04:00
parent 0765c3e3f7
commit 32b675456e
10 changed files with 254 additions and 6 deletions

View 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 $< $@

7
src/bhyve/bhyve.conf Normal file
View File

@ -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"

View File

@ -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
@ -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;
}

View File

@ -25,8 +25,11 @@
# 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);

112
src/bhyve/bhyve_conf.c Normal file
View File

@ -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);
}

32
src/bhyve/bhyve_conf.h Normal file
View File

@ -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 */

View 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);

View File

@ -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;

View File

@ -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

View File

@ -0,0 +1,5 @@
module Test_libvirtd_bhyve =
::CONFIG::
test Libvirtd_bhyve.lns get conf =
{ "firmware_dir" = "/usr/local/share/uefi-firmware" }