From 72a9a91e3bae0148844dd5d01b6bc3c26423b14a Mon Sep 17 00:00:00 2001 From: Praveen K Paladugu Date: Thu, 19 Dec 2024 08:45:59 -0600 Subject: [PATCH] ch: Enable logging for ch domains Use domainLogContext to enable logging for ch domain process during create and restore steps. Signed-off-by: Praveen K Paladugu Reviewed-by: Michal Privoznik --- src/ch/ch_conf.h | 2 ++ src/ch/ch_monitor.c | 5 ++++- src/ch/ch_monitor.h | 3 ++- src/ch/ch_process.c | 34 ++++++++++++++++++++++++++++++---- 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/ch/ch_conf.h b/src/ch/ch_conf.h index bac82a0170..b08573476e 100644 --- a/src/ch/ch_conf.h +++ b/src/ch/ch_conf.h @@ -45,6 +45,8 @@ struct _virCHDriverConfig { uid_t user; gid_t group; + + bool stdioLogD; }; G_DEFINE_AUTOPTR_CLEANUP_FUNC(virCHDriverConfig, virObjectUnref); diff --git a/src/ch/ch_monitor.c b/src/ch/ch_monitor.c index 690aea37c8..c9b08b0f75 100644 --- a/src/ch/ch_monitor.c +++ b/src/ch/ch_monitor.c @@ -536,7 +536,7 @@ chMonitorCreateSocket(const char *socket_path) } virCHMonitor * -virCHMonitorNew(virDomainObj *vm, virCHDriverConfig *cfg) +virCHMonitorNew(virDomainObj *vm, virCHDriverConfig *cfg, int logfile) { g_autoptr(virCHMonitor) mon = NULL; g_autoptr(virCommand) cmd = NULL; @@ -572,6 +572,9 @@ virCHMonitorNew(virDomainObj *vm, virCHDriverConfig *cfg) } cmd = virCommandNew(vm->def->emulator); + virCommandSetOutputFD(cmd, &logfile); + virCommandSetErrorFD(cmd, &logfile); + virCommandNonblockingFDs(cmd); virCommandSetUmask(cmd, 0x002); socket_fd = chMonitorCreateSocket(mon->socketpath); if (socket_fd < 0) { diff --git a/src/ch/ch_monitor.h b/src/ch/ch_monitor.h index 9ec58e5b20..5c02447116 100644 --- a/src/ch/ch_monitor.h +++ b/src/ch/ch_monitor.h @@ -103,7 +103,8 @@ struct _virCHMonitor { virCHMonitorThreadInfo *threads; }; -virCHMonitor *virCHMonitorNew(virDomainObj *vm, virCHDriverConfig *cfg); +virCHMonitor *virCHMonitorNew(virDomainObj *vm, virCHDriverConfig *cfg, + int logfile); void virCHMonitorClose(virCHMonitor *mon); G_DEFINE_AUTOPTR_CLEANUP_FUNC(virCHMonitor, virCHMonitorClose); diff --git a/src/ch/ch_process.c b/src/ch/ch_process.c index 61e263b62b..af44aa81a2 100644 --- a/src/ch/ch_process.c +++ b/src/ch/ch_process.c @@ -29,6 +29,7 @@ #include "ch_process.h" #include "domain_cgroup.h" #include "domain_interface.h" +#include "domain_logcontext.h" #include "viralloc.h" #include "virerror.h" #include "virfile.h" @@ -49,12 +50,13 @@ VIR_LOG_INIT("ch.ch_process"); static virCHMonitor * virCHProcessConnectMonitor(virCHDriver *driver, - virDomainObj *vm) + virDomainObj *vm, + int logfile) { virCHMonitor *monitor = NULL; virCHDriverConfig *cfg = virCHDriverGetConfig(driver); - monitor = virCHMonitorNew(vm, cfg); + monitor = virCHMonitorNew(vm, cfg, logfile); virObjectUnref(cfg); return monitor; @@ -890,6 +892,8 @@ virCHProcessStart(virCHDriver *driver, g_autoptr(virCHDriverConfig) cfg = virCHDriverGetConfig(priv->driver); g_autofree int *nicindexes = NULL; size_t nnicindexes = 0; + g_autoptr(domainLogContext) logCtxt = NULL; + int logfile = -1; if (virDomainObjIsActive(vm)) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", @@ -901,6 +905,16 @@ virCHProcessStart(virCHDriver *driver, return -1; } + VIR_DEBUG("Creating domain log file for %s domain", vm->def->name); + if (!(logCtxt = domainLogContextNew(cfg->stdioLogD, cfg->logDir, + CH_DRIVER_NAME, + vm, driver->privileged, + vm->def->name))) { + virLastErrorPrefixMessage("%s", _("can't connect to virtlogd")); + return -1; + } + logfile = domainLogContextGetWriteFD(logCtxt); + if (virCHProcessPrepareDomain(vm) < 0) { return -1; } @@ -910,7 +924,7 @@ virCHProcessStart(virCHDriver *driver, if (!priv->monitor) { /* And we can get the first monitor connection now too */ - if (!(priv->monitor = virCHProcessConnectMonitor(driver, vm))) { + if (!(priv->monitor = virCHProcessConnectMonitor(driver, vm, logfile))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("failed to create connection to CH socket")); goto cleanup; @@ -1047,10 +1061,22 @@ virCHProcessStartRestore(virCHDriver *driver, virDomainObj *vm, const char *from size_t ntapfds = 0; size_t nnicindexes = 0; int ret = -1; + g_autoptr(domainLogContext) logCtxt = NULL; + int logfile = -1; + + VIR_DEBUG("Creating domain log file for %s domain", vm->def->name); + if (!(logCtxt = domainLogContextNew(cfg->stdioLogD, cfg->logDir, + CH_DRIVER_NAME, + vm, driver->privileged, + vm->def->name))) { + virLastErrorPrefixMessage("%s", _("can't connect to virtlogd")); + return -1; + } + logfile = domainLogContextGetWriteFD(logCtxt); if (!priv->monitor) { /* Get the first monitor connection if not already */ - if (!(priv->monitor = virCHProcessConnectMonitor(driver, vm))) { + if (!(priv->monitor = virCHProcessConnectMonitor(driver, vm, logfile))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("failed to create connection to CH socket")); goto cleanup;