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

Reply via email to