[PATCH v3 0/3] CH: Add support for a configuration file and log level configuration

Similar to the qemu.conf file that allows QEMU specific configurations we add the possibility to specify a ch.conf file for Cloud Hypervisor configuration. The initial single config option is the log level, which sets the verbosity of the Cloud Hypervisor process. This allows for simpler debugging when using Cloud Hypervisor via libvirt. Stefan Kober (3): ch: Add config file support ch: add log level configuration option NEWS: ch: announce log_level config option NEWS.rst | 5 +++++ src/ch/ch.conf | 11 ++++++++++ src/ch/ch_conf.c | 31 ++++++++++++++++++++++++++ src/ch/ch_conf.h | 18 +++++++++++++++ src/ch/ch_driver.c | 6 +++++ src/ch/ch_monitor.c | 6 +++++ src/ch/libvirtd_ch.aug | 40 ++++++++++++++++++++++++++++++++++ src/ch/meson.build | 12 ++++++++++ src/ch/test_libvirtd_ch.aug.in | 5 +++++ 9 files changed, 134 insertions(+) create mode 100644 src/ch/ch.conf create mode 100644 src/ch/libvirtd_ch.aug create mode 100644 src/ch/test_libvirtd_ch.aug.in -- 2.49.0

Similar to the QEMU driver, the ch driver receives support for configuration files that allows doing certain configuration on the virtchd daemon. The initial use case will be setting the verbosity of the cloud hypervisor instances started by virtchd, but the implementation allows for adding further options. Signed-off-by: Stefan Kober <stefan.kober@cyberus-technology.de> --- src/ch/ch.conf | 3 +++ src/ch/ch_conf.c | 22 ++++++++++++++++++++++ src/ch/ch_conf.h | 3 +++ src/ch/ch_driver.c | 6 ++++++ src/ch/libvirtd_ch.aug | 40 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 74 insertions(+) create mode 100644 src/ch/ch.conf create mode 100644 src/ch/libvirtd_ch.aug diff --git a/src/ch/ch.conf b/src/ch/ch.conf new file mode 100644 index 0000000000..8ce987f675 --- /dev/null +++ b/src/ch/ch.conf @@ -0,0 +1,3 @@ +# Master configuration file for the QEMU driver. +# All settings described here are optional - if omitted, sensible +# defaults are used. diff --git a/src/ch/ch_conf.c b/src/ch/ch_conf.c index cab97639c4..7d3f600707 100644 --- a/src/ch/ch_conf.c +++ b/src/ch/ch_conf.c @@ -22,6 +22,7 @@ #include "configmake.h" #include "vircommand.h" +#include "virconf.h" #include "virfile.h" #include "virlog.h" #include "virobject.h" @@ -81,6 +82,25 @@ virCaps *virCHDriverCapsInit(void) return g_steal_pointer(&caps); } +int virCHDriverConfigLoadFile(virCHDriverConfig *cfg, + const char *filename) +{ + g_autoptr(virConf) conf = NULL; + + /* Just check the file is readable before opening it, otherwise + * libvirt emits an error. + */ + if (access(filename, R_OK) == -1) { + VIR_INFO("Could not read ch config file %s", filename); + return 0; + } + + if (!(conf = virConfReadFile(filename, 0))) + return -1; + + return 0; +} + /** * virCHDriverGetCapabilities: * @@ -149,6 +169,7 @@ virCHDriverConfigNew(bool privileged) cfg->logDir = g_strdup_printf("%s/log/libvirt/ch", LOCALSTATEDIR); cfg->stateDir = g_strdup_printf("%s/libvirt/ch", RUNSTATEDIR); cfg->saveDir = g_strdup_printf("%s/lib/libvirt/ch/save", LOCALSTATEDIR); + cfg->configDir = g_strdup_printf("%s/lib/libvirt/ch", LOCALSTATEDIR); } else { g_autofree char *rundir = NULL; @@ -164,6 +185,7 @@ virCHDriverConfigNew(bool privileged) configbasedir = virGetUserConfigDirectory(); cfg->saveDir = g_strdup_printf("%s/ch/save", configbasedir); + cfg->configDir = g_strdup_printf("%s/ch", configbasedir); } return cfg; diff --git a/src/ch/ch_conf.h b/src/ch/ch_conf.h index b08573476e..2f0d090d35 100644 --- a/src/ch/ch_conf.h +++ b/src/ch/ch_conf.h @@ -38,6 +38,7 @@ struct _virCHDriverConfig { GObject parent; char *stateDir; + char *configDir; char *logDir; char *saveDir; @@ -103,6 +104,8 @@ struct _CHSaveXMLHeader { uint32_t unused[11]; }; +int virCHDriverConfigLoadFile(virCHDriverConfig *cfg, + const char *filename); virCaps *virCHDriverCapsInit(void); virCaps *virCHDriverGetCapabilities(virCHDriver *driver, bool refresh); diff --git a/src/ch/ch_driver.c b/src/ch/ch_driver.c index 3bdcf66ebd..cf6874f22e 100644 --- a/src/ch/ch_driver.c +++ b/src/ch/ch_driver.c @@ -1411,6 +1411,7 @@ chStateInitialize(bool privileged, virStateInhibitCallback callback G_GNUC_UNUSED, void *opaque G_GNUC_UNUSED) { + g_autofree char *driverConf = NULL; int ret = VIR_DRV_STATE_INIT_ERROR; int rv; @@ -1447,6 +1448,11 @@ chStateInitialize(bool privileged, if (!(ch_driver->config = virCHDriverConfigNew(privileged))) goto cleanup; + driverConf = g_strdup_printf("%s/ch.conf", ch_driver->config->configDir); + + if (virCHDriverConfigLoadFile(ch_driver->config, driverConf) < 0) + goto cleanup; + if (!(ch_driver->hostdevMgr = virHostdevManagerGetDefault())) goto cleanup; diff --git a/src/ch/libvirtd_ch.aug b/src/ch/libvirtd_ch.aug new file mode 100644 index 0000000000..d0b0964987 --- /dev/null +++ b/src/ch/libvirtd_ch.aug @@ -0,0 +1,40 @@ +(* /etc/libvirt/ch.conf *) + +module Libvirtd_ch = + 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 ] + + (* Config entry grouped by function - same order as example config *) + let config_entry = bool_entry "placeholder" + + (* Each entry in the config is one of the following three ... *) + let entry = config_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/ch.conf" + . Util.stdexcl + + let xfm = transform lns filter -- 2.49.0

Allow a user to set the verbosity of the cloud hypervisor instances by specifying it in the ch.conf configuration file. Signed-off-by: Stefan Kober <stefan.kober@cyberus-technology.de> --- src/ch/ch.conf | 8 ++++++++ src/ch/ch_conf.c | 9 +++++++++ src/ch/ch_conf.h | 15 +++++++++++++++ src/ch/ch_monitor.c | 6 ++++++ src/ch/libvirtd_ch.aug | 2 +- src/ch/meson.build | 12 ++++++++++++ src/ch/test_libvirtd_ch.aug.in | 5 +++++ 7 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 src/ch/test_libvirtd_ch.aug.in diff --git a/src/ch/ch.conf b/src/ch/ch.conf index 8ce987f675..5e3cf8f92f 100644 --- a/src/ch/ch.conf +++ b/src/ch/ch.conf @@ -1,3 +1,11 @@ # Master configuration file for the QEMU driver. # All settings described here are optional - if omitted, sensible # defaults are used. + +# By default, Cloud Hypervisor only emits warning and error messages. By using +# the log_level configuration option, the logging verbosity can be increased. +# +# Using log_level = 1 configures Cloud Hypervisor to also show info messages. +# Using log_level = 2 configures Cloud Hypervisor to also show debug messages. +# +#log_level = 0 diff --git a/src/ch/ch_conf.c b/src/ch/ch_conf.c index 7d3f600707..b9432e2a42 100644 --- a/src/ch/ch_conf.c +++ b/src/ch/ch_conf.c @@ -98,6 +98,15 @@ int virCHDriverConfigLoadFile(virCHDriverConfig *cfg, if (!(conf = virConfReadFile(filename, 0))) return -1; + if (virConfGetValueUInt(conf, "log_level", &cfg->logLevel) < 0) + return -1; + + if (!(cfg->logLevel < VIR_CH_LOGLEVEL_LAST)) { + virReportError(VIR_ERR_INTERNAL_ERROR, _("Invalid log_level %1$u"), + cfg->logLevel); + return -1; + } + return 0; } diff --git a/src/ch/ch_conf.h b/src/ch/ch_conf.h index 2f0d090d35..1660762f2b 100644 --- a/src/ch/ch_conf.h +++ b/src/ch/ch_conf.h @@ -34,6 +34,19 @@ typedef struct _virCHDriver virCHDriver; typedef struct _virCHDriverConfig virCHDriverConfig; +typedef enum { + /* Standard log level only showing warning and error messages. */ + VIR_CH_LOGLEVEL_DEFAULT = 0, + + /* Additional info messages are shown. Will not spam the log. */ + VIR_CH_LOGLEVEL_INFO, + + /* Additional debug messages are shown. Will be very verbose. */ + VIR_CH_LOGLEVEL_DEBUG, + + VIR_CH_LOGLEVEL_LAST +} virCHLogLevel; + struct _virCHDriverConfig { GObject parent; @@ -48,6 +61,8 @@ struct _virCHDriverConfig { gid_t group; bool stdioLogD; + + virCHLogLevel logLevel; }; G_DEFINE_AUTOPTR_CLEANUP_FUNC(virCHDriverConfig, virObjectUnref); diff --git a/src/ch/ch_monitor.c b/src/ch/ch_monitor.c index 3d3b4cb87d..6bf877fef3 100644 --- a/src/ch/ch_monitor.c +++ b/src/ch/ch_monitor.c @@ -698,6 +698,12 @@ virCHMonitorNew(virDomainObj *vm, virCHDriverConfig *cfg, int logfile) return NULL; } + if (cfg->logLevel == VIR_CH_LOGLEVEL_INFO) { + virCommandAddArg(cmd, "-v"); + } else if (cfg->logLevel == VIR_CH_LOGLEVEL_DEBUG) { + virCommandAddArg(cmd, "-vv"); + } + virCommandAddArg(cmd, "--api-socket"); virCommandAddArgFormat(cmd, "fd=%d", socket_fd); virCommandPassFD(cmd, socket_fd, VIR_COMMAND_PASS_FD_CLOSE_PARENT); diff --git a/src/ch/libvirtd_ch.aug b/src/ch/libvirtd_ch.aug index d0b0964987..fa97d2a44a 100644 --- a/src/ch/libvirtd_ch.aug +++ b/src/ch/libvirtd_ch.aug @@ -23,7 +23,7 @@ module Libvirtd_ch = let str_array_entry (kw:string) = [ key kw . value_sep . str_array_val ] (* Config entry grouped by function - same order as example config *) - let config_entry = bool_entry "placeholder" + let config_entry = int_entry "log_level" (* Each entry in the config is one of the following three ... *) let entry = config_entry diff --git a/src/ch/meson.build b/src/ch/meson.build index 0b4a5aeb49..cd20c3d065 100644 --- a/src/ch/meson.build +++ b/src/ch/meson.build @@ -77,6 +77,18 @@ if conf.has('WITH_CH') ], } + ch_conf = files('ch.conf') + virt_conf_files += ch_conf + virt_aug_files += files('libvirtd_ch.aug') + virt_test_aug_files += { + 'name': 'test_libvirtd_ch.aug', + 'aug': files('test_libvirtd_ch.aug.in'), + 'conf': ch_conf, + 'test_name': 'libvirtd_ch', + 'test_srcdir': meson.current_source_dir(), + 'test_builddir': meson.current_build_dir(), + } + virt_install_dirs += [ localstatedir / 'lib' / 'libvirt' / 'ch', localstatedir / 'log' / 'libvirt' / 'ch', diff --git a/src/ch/test_libvirtd_ch.aug.in b/src/ch/test_libvirtd_ch.aug.in new file mode 100644 index 0000000000..bddec24b88 --- /dev/null +++ b/src/ch/test_libvirtd_ch.aug.in @@ -0,0 +1,5 @@ +module Test_libvirtd_ch = + @CONFIG@ + + test Libvirtd_ch.lns get conf = +{ "log_level" = "0" } -- 2.49.0

Signed-off-by: Stefan Kober <stefan.kober@cyberus-technology.de> --- NEWS.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/NEWS.rst b/NEWS.rst index 636fcbd573..cfeddd10df 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -17,6 +17,11 @@ v11.4.0 (unreleased) * **New features** + * Allow setting the log level of Cloud Hypervisor + + Users can now configure the verbosity of Cloud Hypervisor by setting + the "log_level" option in ch.conf + * **Improvements** * virsh: Add option ``--no-pkttyagent`` -- 2.49.0

bump :)
participants (2)
-
Stefan Kober
-
stefan.kober@cyberus-technology.de