virtlogd: make max file size & number of backups configurable

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@redhat.com>
This commit is contained in:
Daniel P. Berrange 2016-07-01 17:40:55 +01:00
parent e114b09157
commit 24aacfa8e8
8 changed files with 57 additions and 13 deletions

View File

@ -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;
}

View File

@ -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:

View File

@ -34,6 +34,9 @@ struct _virLogDaemonConfig {
char *log_filters;
char *log_outputs;
int max_clients;
size_t max_backups;
size_t max_size;
};

View File

@ -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;

View File

@ -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);

View File

@ -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" }

View File

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

View File

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