Currently virtlogd has a hardcoded max file size of 128kb and max of 3 backups. This adds two new config parameters to /etc/libvirt/virtlogd.conf to let these be customized. Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx> --- src/logging/log_daemon.c | 17 +++++++++++++---- src/logging/log_daemon_config.c | 5 +++++ src/logging/log_daemon_config.h | 3 +++ src/logging/log_handler.c | 27 ++++++++++++++++++--------- src/logging/log_handler.h | 4 ++++ src/logging/test_virtlogd.aug.in | 4 ++++ src/logging/virtlogd.aug | 2 ++ src/logging/virtlogd.conf | 8 ++++++++ 8 files changed, 57 insertions(+), 13 deletions(-) diff --git a/src/logging/log_daemon.c b/src/logging/log_daemon.c index 9f71ca9..80e75bf 100644 --- a/src/logging/log_daemon.c +++ b/src/logging/log_daemon.c @@ -165,6 +165,8 @@ virLogDaemonNew(virLogDaemonConfigPtr config, bool privileged) goto error; if (!(logd->handler = virLogHandlerNew(privileged, + config->max_size, + config->max_backups, virLogDaemonInhibitor, logd))) goto error; @@ -185,7 +187,8 @@ virLogDaemonGetHandler(virLogDaemonPtr dmn) static virLogDaemonPtr -virLogDaemonNewPostExecRestart(virJSONValuePtr object, bool privileged) +virLogDaemonNewPostExecRestart(virJSONValuePtr object, bool privileged, + virLogDaemonConfigPtr config) { virLogDaemonPtr logd; virJSONValuePtr child; @@ -226,6 +229,8 @@ virLogDaemonNewPostExecRestart(virJSONValuePtr object, bool privileged) if (!(logd->handler = virLogHandlerNewPostExecRestart(child, privileged, + config->max_size, + config->max_backups, virLogDaemonInhibitor, logd))) goto error; @@ -717,7 +722,8 @@ static int virLogDaemonPostExecRestart(const char *state_file, const char *pid_file, int *pid_file_fd, - bool privileged) + bool privileged, + virLogDaemonConfigPtr config) { const char *gotmagic; char *wantmagic = NULL; @@ -766,7 +772,9 @@ virLogDaemonPostExecRestart(const char *state_file, (*pid_file_fd = virPidFileAcquirePath(pid_file, false, getpid())) < 0) goto cleanup; - if (!(logDaemon = virLogDaemonNewPostExecRestart(object, privileged))) + if (!(logDaemon = virLogDaemonNewPostExecRestart(object, + privileged, + config))) goto cleanup; ret = 1; @@ -1086,7 +1094,8 @@ int main(int argc, char **argv) { if ((rv = virLogDaemonPostExecRestart(state_file, pid_file, &pid_file_fd, - privileged)) < 0) { + privileged, + config)) < 0) { ret = VIR_LOG_DAEMON_ERR_INIT; goto cleanup; } diff --git a/src/logging/log_daemon_config.c b/src/logging/log_daemon_config.c index 9e729fa..b584970 100644 --- a/src/logging/log_daemon_config.c +++ b/src/logging/log_daemon_config.c @@ -128,6 +128,8 @@ virLogDaemonConfigNew(bool privileged ATTRIBUTE_UNUSED) return NULL; data->max_clients = 1024; + data->max_size = 128 * 1024; + data->max_backups = 3; return data; } @@ -154,6 +156,9 @@ virLogDaemonConfigLoadOptions(virLogDaemonConfigPtr data, GET_CONF_STR(conf, filename, log_outputs); GET_CONF_UINT(conf, filename, max_clients); + GET_CONF_UINT(conf, filename, max_size); + GET_CONF_UINT(conf, filename, max_backups); + return 0; error: diff --git a/src/logging/log_daemon_config.h b/src/logging/log_daemon_config.h index 24cc631..0da7b0b 100644 --- a/src/logging/log_daemon_config.h +++ b/src/logging/log_daemon_config.h @@ -34,6 +34,9 @@ struct _virLogDaemonConfig { char *log_filters; char *log_outputs; int max_clients; + + size_t max_backups; + size_t max_size; }; diff --git a/src/logging/log_handler.c b/src/logging/log_handler.c index a8cb6cf..cd0ba6e 100644 --- a/src/logging/log_handler.c +++ b/src/logging/log_handler.c @@ -41,8 +41,6 @@ VIR_LOG_INIT("logging.log_handler"); #define VIR_FROM_THIS VIR_FROM_LOGGING -#define DEFAULT_FILE_SIZE (128 * 1024) -#define DEFAULT_MAX_BACKUP 3 #define DEFAULT_MODE 0600 typedef struct _virLogHandlerLogFile virLogHandlerLogFile; @@ -62,6 +60,9 @@ struct _virLogHandler { virObjectLockable parent; bool privileged; + size_t max_size; + size_t max_backups; + virLogHandlerLogFilePtr *files; size_t nfiles; @@ -184,6 +185,8 @@ virLogHandlerDomainLogFileEvent(int watch, virLogHandlerPtr virLogHandlerNew(bool privileged, + size_t max_size, + size_t max_backups, virLogHandlerShutdownInhibitor inhibitor, void *opaque) { @@ -196,6 +199,8 @@ virLogHandlerNew(bool privileged, goto error; handler->privileged = privileged; + handler->max_size = max_size; + handler->max_backups = max_backups; handler->inhibitor = inhibitor; handler->opaque = opaque; @@ -254,8 +259,8 @@ virLogHandlerLogFilePostExecRestart(virLogHandlerPtr handler, } if ((file->file = virRotatingFileWriterNew(path, - DEFAULT_FILE_SIZE, - DEFAULT_MAX_BACKUP, + handler->max_size, + handler->max_backups, false, DEFAULT_MODE)) == NULL) goto error; @@ -283,6 +288,8 @@ virLogHandlerLogFilePostExecRestart(virLogHandlerPtr handler, virLogHandlerPtr virLogHandlerNewPostExecRestart(virJSONValuePtr object, bool privileged, + size_t max_size, + size_t max_backups, virLogHandlerShutdownInhibitor inhibitor, void *opaque) { @@ -292,6 +299,8 @@ virLogHandlerNewPostExecRestart(virJSONValuePtr object, size_t i; if (!(handler = virLogHandlerNew(privileged, + max_size, + max_backups, inhibitor, opaque))) return NULL; @@ -396,8 +405,8 @@ virLogHandlerDomainOpenLogFile(virLogHandlerPtr handler, goto error; if ((file->file = virRotatingFileWriterNew(path, - DEFAULT_FILE_SIZE, - DEFAULT_MAX_BACKUP, + handler->max_size, + handler->max_backups, trunc, DEFAULT_MODE)) == NULL) goto error; @@ -487,7 +496,7 @@ virLogHandlerDomainReadLogFile(virLogHandlerPtr handler, virObjectLock(handler); - if (!(file = virRotatingFileReaderNew(path, DEFAULT_MAX_BACKUP))) + if (!(file = virRotatingFileReaderNew(path, handler->max_backups))) goto error; if (virRotatingFileReaderSeek(file, inode, offset) < 0) @@ -542,8 +551,8 @@ virLogHandlerDomainAppendLogFile(virLogHandlerPtr handler, if (!writer) { if (!(newwriter = virRotatingFileWriterNew(path, - DEFAULT_FILE_SIZE, - DEFAULT_MAX_BACKUP, + handler->max_size, + handler->max_backups, false, DEFAULT_MODE))) goto cleanup; diff --git a/src/logging/log_handler.h b/src/logging/log_handler.h index 4607e45..70be567 100644 --- a/src/logging/log_handler.h +++ b/src/logging/log_handler.h @@ -34,10 +34,14 @@ typedef void (*virLogHandlerShutdownInhibitor)(bool inhibit, void *opaque); virLogHandlerPtr virLogHandlerNew(bool privileged, + size_t max_size, + size_t max_backups, virLogHandlerShutdownInhibitor inhibitor, void *opaque); virLogHandlerPtr virLogHandlerNewPostExecRestart(virJSONValuePtr child, bool privileged, + size_t max_size, + size_t max_backups, virLogHandlerShutdownInhibitor inhibitor, void *opaque); diff --git a/src/logging/test_virtlogd.aug.in b/src/logging/test_virtlogd.aug.in index b12f676..792a5b8 100644 --- a/src/logging/test_virtlogd.aug.in +++ b/src/logging/test_virtlogd.aug.in @@ -2,9 +2,13 @@ module Test_virtlogd = let conf = "log_level = 3 log_filters=\"3:remote 4:event\" log_outputs=\"3:syslog:virtlogd\" +max_size = 131072 +max_backups = 3 " test Virtlogd.lns get conf = { "log_level" = "3" } { "log_filters" = "3:remote 4:event" } { "log_outputs" = "3:syslog:virtlogd" } + { "max_size" = "131072" } + { "max_backups" = "3" } diff --git a/src/logging/virtlogd.aug b/src/logging/virtlogd.aug index eefba5b..da480fd 100644 --- a/src/logging/virtlogd.aug +++ b/src/logging/virtlogd.aug @@ -29,6 +29,8 @@ module Virtlogd = | str_entry "log_outputs" | int_entry "log_buffer_size" | int_entry "max_clients" + | int_entry "max_size" + | int_entry "max_backups" (* Each enty in the config is one of the following three ... *) let entry = logging_entry diff --git a/src/logging/virtlogd.conf b/src/logging/virtlogd.conf index abb3633..fbd92ff 100644 --- a/src/logging/virtlogd.conf +++ b/src/logging/virtlogd.conf @@ -57,3 +57,11 @@ # The maximum number of concurrent client connections to allow # over all sockets combined. #max_clients = 1024 + + +# Maximum file size before rolling over. Defaults to 128 KB +#max_size = 131072 + +# Maximum number of backup files to keep. Defaults to 3, +# not including the primary active file +#max_backups = 3 -- 2.7.4 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list