From nobody Sun Apr 28 00:38:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.37 as permitted sender) client-ip=209.132.183.37; envelope-from=libvir-list-bounces@redhat.com; helo=mx5-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.37 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx5-phx2.redhat.com (mx5-phx2.redhat.com [209.132.183.37]) by mx.zohomail.com with SMTPS id 1489428397853190.0462773906272; Mon, 13 Mar 2017 11:06:37 -0700 (PDT) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx5-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2DI2drF013186; Mon, 13 Mar 2017 14:02:39 -0400 Received: from smtp.corp.redhat.com (int-mx16.intmail.prod.int.phx2.redhat.com [10.5.11.28]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v2DI2cFN028153 for ; Mon, 13 Mar 2017 14:02:38 -0400 Received: by smtp.corp.redhat.com (Postfix) id BEC732D5E7; Mon, 13 Mar 2017 18:02:38 +0000 (UTC) Received: from mx1.redhat.com (ext-mx03.extmail.prod.ext.phx2.redhat.com [10.5.110.27]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B4A672D5C3 for ; Mon, 13 Mar 2017 18:02:38 +0000 (UTC) Received: from mail-lf0-f66.google.com (mail-lf0-f66.google.com [209.85.215.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 96B926B503 for ; Mon, 13 Mar 2017 18:02:30 +0000 (UTC) Received: by mail-lf0-f66.google.com with SMTP id y193so12440593lfd.1 for ; Mon, 13 Mar 2017 11:02:29 -0700 (PDT) Received: from kloomba.my.domain ([31.29.236.169]) by smtp.gmail.com with ESMTPSA id u10sm3190651ljd.40.2017.03.13.11.02.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Mar 2017 11:02:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=yCPMyAi2c5tC2opHMTWHsIEK5QToBB7xi4gjt4fbTFo=; b=tx6i8jLyMA4yox6WM61EX9ONI3NU2XxhCD8kTzeADYY9panqciuayEl/7DdYT8/uM2 UA9s8QttbJn+62JgjcdRC5d0ZAdHBoU+W/HoFoBVmJZNhcF326zMfokWHQ4JQ0S9Lmlm zbT0K1phRt8yGXqkGCC5ta+vJrlPqfPJRlDv3FgfTgz0kc939RlUlVx9N0VBjWh0Nm+O xeY1L1T/pImRXiLZhEa0fF2TnLRW1vQRDsvWdth2+VoG3FfhyEQUBOvZ5Qi/Igu0OD0K 6fdeAzGhVC3yPYxcOmcwhWLD8uFkM0pqCrA1eOyD//T9nKfTGDEtPMl+Eid/zLJv/ILc OGyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=yCPMyAi2c5tC2opHMTWHsIEK5QToBB7xi4gjt4fbTFo=; b=brRc7udAs6qGKR/ziDDHzityNxralGV6PlSPmZm7SY9KscaH10pYnwuv+RB0HyXHv9 H8UI35w5gSOeIlCH8oBxmY3fLu2ykJh0pVqzoM+BLFQm/3bvbDglCbGFSTNntnifMhzO oubTyJh53rg9sUK04Mw25BBNBPGji7sWpVomnfkQPKTti7rNpdPcmUVvT0xT4M5uAPhP nJF/4kYg3lF1wEABdvPPVs5tsE0r1DcbMPAPcUZaKyv3VrQNW0YnzEHqQes3v3xXHSQH 7FlVaKr/ng6RaW8KFRWlROWB2oGmLQ2OFEFoSpAYxED/GZA+ecS3x2E2ha4yFgHSihUj 3LUw== X-Gm-Message-State: AMke39nngJzjLznlNK7h6DplBLOzTwb0ARsoy43RYbUS/qu9zBPZbRBVhVGSyeku//0O0Q== X-Received: by 10.25.145.78 with SMTP id y14mr7959130lfj.18.1489428147748; Mon, 13 Mar 2017 11:02:27 -0700 (PDT) From: Roman Bogorodskiy To: libvir-list@redhat.com Date: Mon, 13 Mar 2017 22:02:20 +0400 Message-Id: <20170313180220.63456-1-bogorodskiy@gmail.com> X-Mailer: git-send-email 2.11.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 13 Mar 2017 18:02:31 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 13 Mar 2017 18:02:31 +0000 (UTC) for IP:'209.85.215.66' DOMAIN:'mail-lf0-f66.google.com' HELO:'mail-lf0-f66.google.com' FROM:'bogorodskiy@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.17 * (BAYES_50, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_SPAM, SPF_PASS) 209.85.215.66 mail-lf0-f66.google.com 209.85.215.66 mail-lf0-f66.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.27 X-Scanned-By: MIMEDefang 2.74 on 10.5.11.28 X-loop: libvir-list@redhat.com Cc: Roman Bogorodskiy Subject: [libvirt] [PATCH] bhyve: add config file support X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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 =3D \ 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 =3D \ $(AM_CFLAGS) libvirt_driver_bhyve_impl_la_LDFLAGS =3D $(AM_LDFLAGS) libvirt_driver_bhyve_impl_la_SOURCES =3D $(BHYVE_DRIVER_SOURCES) + +conf_DATA +=3D bhyve/bhyve.conf +augeas_DATA +=3D bhyve/libvirtd_bhyve.aug +augeastest_DATA +=3D test_libvirtd_bhyve.aug endif WITH_BHYVE +EXTRA_DIST +=3D bhyve/bhyve.conf \ + bhyve/libvirtd_bhyve.aug \ + bhyve/test_libvirtd_bhyve.aug.in =20 if WITH_NETWORK noinst_LTLIBRARIES +=3D 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) =20 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 =20 AUG_GENTEST =3D $(PERL) $(top_srcdir)/build-aux/augeas-gentest.pl EXTRA_DIST +=3D $(top_srcdir)/build-aux/augeas-gentest.pl @@ -2212,6 +2222,19 @@ else ! WITH_LIBXL check-augeas-libxl: endif ! WITH_LIBXL =20 +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 =3D "/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) } =20 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 =3D 0; DIR *dir; struct dirent *entry; - const char *firmware_dir =3D "/usr/local/share/uefi-firmware"; size_t firmwares_alloc =3D 0; + virBhyveDriverConfigPtr cfg =3D virBhyveDriverGetConfig(conn); + const char *firmware_dir =3D cfg->firmwareDir; =20 if (!(caps =3D virDomainCapsNew(emulatorbin, machine, arch, virttype))) goto cleanup; @@ -152,7 +154,10 @@ virBhyveDomainCapsBuild(const char *emulatorbin, =20 caps->os.loader.values.nvalues++; } + } else { + VIR_WARN("Cannot open firmware directory %s", firmware_dir); } + caps->disk.supported =3D 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" =20 +# 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 + * . + * + */ + +#include + +#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 =3D virClassNew(virClassForObject(), + "virBhyveDriverConfig", + sizeof(virBhyveDriverCo= nfig), + virBhyveDriverConfigDis= pose))) + return -1; + + return 0; +} + +VIR_ONCE_GLOBAL_INIT(virBhyveConfig) + +virBhyveDriverConfigPtr +virBhyveDriverConfigNew(void) +{ + virBhyveDriverConfigPtr cfg; + + if (virBhyveConfigInitialize() < 0) + return NULL; + + if (!(cfg =3D 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 =3D -1; + + if (access(filename, R_OK) =3D=3D -1) { + VIR_INFO("Could not read bhyve config file %s", filename); + return 0; + } + + if (!(conf =3D virConfReadFile(filename, 0))) + return -1; + + if (virConfGetValueString(conf, "firmware_dir", + &cfg->firmwareDir) < 0) + goto cleanup; + + ret =3D 0; + cleanup: + virConfFree(conf); + return ret; +} + +virBhyveDriverConfigPtr +virBhyveDriverGetConfig(bhyveConnPtr driver) +{ + virBhyveDriverConfigPtr cfg; + bhyveDriverLock(driver); + cfg =3D virObjectRef(driver->config); + bhyveDriverUnlock(driver); + return cfg; +} + +static void +virBhyveDriverConfigDispose(void *obj) +{ + virBhyveDriverConfigPtr cfg =3D 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 + * . + * + */ + +#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" =20 +#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); =20 virMutexDestroy(&bhyve_driver->lock); VIR_FREE(bhyve_driver); @@ -1276,6 +1278,12 @@ bhyveStateInitialize(bool privileged, =20 bhyve_driver->hostsysinfo =3D virSysinfoRead(); =20 + if (!(bhyve_driver->config =3D virBhyveDriverConfigNew())) + goto cleanup; + + if (virBhyveLoadDriverConfig(bhyve_driver->config, SYSCONFDIR "/libvir= t/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; } =20 - if (!(caps =3D virBhyveDomainCapsBuild(emulatorbin, machine, arch, vir= ttype))) + if (!(caps =3D virBhyveDomainCapsBuild(conn->privateData, emulatorbin, + machine, arch, virttype))) goto cleanup; =20 ret =3D 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" =20 +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 =3D + autoload xfm + + let eol =3D del /[ \t]*\n/ "\n" + let value_sep =3D del /[ \t]*=3D[ \t]*/ " =3D " + let indent =3D del /[ \t]*/ "" + + let array_sep =3D del /,[ \t\n]*/ ", " + let array_start =3D del /\[[ \t\n]*/ "[ " + let array_end =3D del /\]/ "]" + + let str_val =3D del /\"/ "\"" . store /[^\"]*/ . del /\"/ "\"" + let bool_val =3D store /0|1/ + let int_val =3D store /[0-9]+/ + let str_array_element =3D [ seq "el" . str_val ] . del /[ \t\n]*/ "" + let str_array_val =3D counter "el" . array_start . ( str_array_element = . ( array_sep . str_array_element ) * ) ? . array_end + + let str_entry (kw:string) =3D [ key kw . value_sep . str_val ] + let bool_entry (kw:string) =3D [ key kw . value_sep . bool_val ] + let int_entry (kw:string) =3D [ key kw . value_sep . int_val ] + let str_array_entry (kw:string) =3D [ key kw . value_sep . str_array_va= l ] + + let log_entry =3D str_entry "firmware_dir" + + (* Each enty in the config is one of the following three ... *) + let entry =3D log_entry + let comment =3D [ label "#comment" . del /#[ \t]*/ "# " . store /([^ \= t\n][^\n]*)?/ . del /\n/ "\n" ] + let empty =3D [ label "#empty" . eol ] + + let record =3D indent . entry . eol + + let lns =3D ( record | comment | empty ) * + + let filter =3D incl "/etc/libvirt/bhyve.conf" + . Util.stdexcl + + let xfm =3D 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 =3D + ::CONFIG:: + + test Libvirtd_bhyve.lns get conf =3D +{ "firmware_dir" =3D "/usr/local/share/uefi-firmware" } --=20 2.11.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list