From 3f68f33c36232132db3a6f4c8925fd09690688dc Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Mon, 29 Feb 2016 12:26:02 +0000 Subject: [PATCH] logging: support truncation of logfiles when opening The virtlogd daemon currently opens all files for append, but in some cases the user may wish to discard existing data. Define a new flag to indicate that logfiles should be truncated when opening. --- src/logging/log_daemon_dispatch.c | 3 ++- src/logging/log_handler.c | 6 ++---- src/logging/log_handler.h | 2 +- src/logging/log_manager.h | 2 ++ src/logging/log_protocol.x | 4 ++++ 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/logging/log_daemon_dispatch.c b/src/logging/log_daemon_dispatch.c index a5fa7f0c76..b00cee2b81 100644 --- a/src/logging/log_daemon_dispatch.c +++ b/src/logging/log_daemon_dispatch.c @@ -50,13 +50,14 @@ virLogManagerProtocolDispatchDomainOpenLogFile(virNetServerPtr server ATTRIBUTE_ int rv = -1; off_t offset; ino_t inode; + bool trunc = args->flags & VIR_LOG_MANAGER_PROTOCOL_DOMAIN_OPEN_LOG_FILE_TRUNCATE; if ((fd = virLogHandlerDomainOpenLogFile(virLogDaemonGetHandler(logDaemon), args->driver, (unsigned char *)args->dom.uuid, args->dom.name, args->path, - args->flags, + trunc, &inode, &offset)) < 0) goto cleanup; diff --git a/src/logging/log_handler.c b/src/logging/log_handler.c index 92cff503c4..4c08223820 100644 --- a/src/logging/log_handler.c +++ b/src/logging/log_handler.c @@ -357,7 +357,7 @@ virLogHandlerDomainOpenLogFile(virLogHandlerPtr handler, const unsigned char *domuuid, const char *domname, const char *path, - unsigned int flags, + bool trunc, ino_t *inode, off_t *offset) { @@ -365,8 +365,6 @@ virLogHandlerDomainOpenLogFile(virLogHandlerPtr handler, virLogHandlerLogFilePtr file = NULL; int pipefd[2] = { -1, -1 }; - virCheckFlags(0, -1); - virObjectLock(handler); handler->inhibitor(true, handler->opaque); @@ -400,7 +398,7 @@ virLogHandlerDomainOpenLogFile(virLogHandlerPtr handler, if ((file->file = virRotatingFileWriterNew(path, DEFAULT_FILE_SIZE, DEFAULT_MAX_BACKUP, - false, + trunc, DEFAULT_MODE)) == NULL) goto error; diff --git a/src/logging/log_handler.h b/src/logging/log_handler.h index e61f32d4d4..54a9cd9288 100644 --- a/src/logging/log_handler.h +++ b/src/logging/log_handler.h @@ -48,7 +48,7 @@ int virLogHandlerDomainOpenLogFile(virLogHandlerPtr handler, const unsigned char *domuuid, const char *domname, const char *path, - unsigned int flags, + bool trunc, ino_t *inode, off_t *offset); diff --git a/src/logging/log_manager.h b/src/logging/log_manager.h index d3b9d29e10..7deaba77f2 100644 --- a/src/logging/log_manager.h +++ b/src/logging/log_manager.h @@ -26,6 +26,8 @@ # include "internal.h" +# include "logging/log_protocol.h" + typedef struct _virLogManager virLogManager; typedef virLogManager *virLogManagerPtr; diff --git a/src/logging/log_protocol.x b/src/logging/log_protocol.x index b0ac31bce4..0363c756c8 100644 --- a/src/logging/log_protocol.x +++ b/src/logging/log_protocol.x @@ -30,6 +30,10 @@ struct virLogManagerProtocolLogFilePosition { }; typedef struct virLogManagerProtocolLogFilePosition virLogManagerProtocolLogFilePosition; +enum virLogManagerProtocolDomainOpenLogFileFlags { + VIR_LOG_MANAGER_PROTOCOL_DOMAIN_OPEN_LOG_FILE_TRUNCATE = 1 +}; + /* Obtain a file handle suitable for writing to a * log file for a domain */ -- 2.39.5