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