The virt driver, dom name and uuid associated with a log file are important pieces of metadata to keep around for sake of future enhancements to virtlogd. Currently we discard them after opening the log file, but we should preserve them, even across restarts. Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx> --- src/logging/log_handler.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/src/logging/log_handler.c b/src/logging/log_handler.c index a4f0395..23c33da 100644 --- a/src/logging/log_handler.c +++ b/src/logging/log_handler.c @@ -30,6 +30,7 @@ #include "virstring.h" #include "virlog.h" #include "virrotatingfile.h" +#include "viruuid.h" #include <unistd.h> #include <fcntl.h> @@ -51,6 +52,10 @@ struct _virLogHandlerLogFile { virRotatingFileWriterPtr file; int watch; int pipefd; /* Read from QEMU via this */ + + char *driver; + unsigned char domuuid[VIR_UUID_BUFLEN]; + char *domname; }; struct _virLogHandler { @@ -93,6 +98,9 @@ virLogHandlerLogFileFree(virLogHandlerLogFilePtr file) if (file->watch != -1) virEventRemoveHandle(file->watch); + + VIR_FREE(file->driver); + VIR_FREE(file->domname); VIR_FREE(file); } @@ -204,6 +212,8 @@ virLogHandlerLogFilePostExecRestart(virLogHandlerPtr handler, { virLogHandlerLogFilePtr file; const char *path; + const char *domuuid; + const char *tmp; if (VIR_ALLOC(file) < 0) return NULL; @@ -216,6 +226,33 @@ virLogHandlerLogFilePostExecRestart(virLogHandlerPtr handler, goto error; } + if ((tmp = virJSONValueObjectGetString(object, "driver")) == NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Missing file driver in JSON document")); + goto error; + } + if (VIR_STRDUP(file->driver, tmp) < 0) + goto error; + + if ((tmp = virJSONValueObjectGetString(object, "domname")) == NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Missing file domname in JSON document")); + goto error; + } + if (VIR_STRDUP(file->domname, tmp) < 0) + goto error; + + if ((domuuid = virJSONValueObjectGetString(object, "domuuid")) == NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Missing file domuuid in JSON document")); + goto error; + } + if (virUUIDParse(domuuid, file->domuuid) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Malformed file domuuid in JSON document")); + goto error; + } + if ((file->file = virRotatingFileWriterNew(path, DEFAULT_FILE_SIZE, DEFAULT_MAX_BACKUP, @@ -388,6 +425,10 @@ virLogHandlerDomainOpenLogFile(virLogHandlerPtr handler, file->watch = -1; file->pipefd = pipefd[0]; pipefd[0] = -1; + memcpy(file->domuuid, domuuid, VIR_UUID_BUFLEN); + if (VIR_STRDUP(file->driver, driver) < 0 || + VIR_STRDUP(file->domname, domname) < 0) + goto error; if ((file->file = virRotatingFileWriterNew(path, DEFAULT_FILE_SIZE, @@ -531,6 +572,7 @@ virLogHandlerPreExecRestart(virLogHandlerPtr handler) virJSONValuePtr ret = virJSONValueNewObject(); virJSONValuePtr files; size_t i; + char domuuid[VIR_UUID_STRING_BUFLEN]; if (!ret) return NULL; @@ -561,6 +603,18 @@ virLogHandlerPreExecRestart(virLogHandlerPtr handler) virRotatingFileWriterGetPath(handler->files[i]->file)) < 0) goto error; + if (virJSONValueObjectAppendString(file, "driver", + handler->files[i]->driver) < 0) + goto error; + + if (virJSONValueObjectAppendString(file, "domname", + handler->files[i]->domname) < 0) + goto error; + + virUUIDFormat(handler->files[i]->domuuid, domuuid); + if (virJSONValueObjectAppendString(file, "domuuid", domuuid) < 0) + goto error; + if (virSetInherit(handler->files[i]->pipefd, true) < 0) { virReportSystemError(errno, "%s", _("Cannot disable close-on-exec flag")); -- 2.5.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list