mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-09-08 16:54:49 +00:00
logging: preserve driver, dom name & uuid against log file
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@redhat.com>
This commit is contained in:
parent
0eafe9955b
commit
d4abb09d80
@ -30,6 +30,7 @@
|
|||||||
#include "virstring.h"
|
#include "virstring.h"
|
||||||
#include "virlog.h"
|
#include "virlog.h"
|
||||||
#include "virrotatingfile.h"
|
#include "virrotatingfile.h"
|
||||||
|
#include "viruuid.h"
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
@ -51,6 +52,10 @@ struct _virLogHandlerLogFile {
|
|||||||
virRotatingFileWriterPtr file;
|
virRotatingFileWriterPtr file;
|
||||||
int watch;
|
int watch;
|
||||||
int pipefd; /* Read from QEMU via this */
|
int pipefd; /* Read from QEMU via this */
|
||||||
|
|
||||||
|
char *driver;
|
||||||
|
unsigned char domuuid[VIR_UUID_BUFLEN];
|
||||||
|
char *domname;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _virLogHandler {
|
struct _virLogHandler {
|
||||||
@ -93,6 +98,9 @@ virLogHandlerLogFileFree(virLogHandlerLogFilePtr file)
|
|||||||
|
|
||||||
if (file->watch != -1)
|
if (file->watch != -1)
|
||||||
virEventRemoveHandle(file->watch);
|
virEventRemoveHandle(file->watch);
|
||||||
|
|
||||||
|
VIR_FREE(file->driver);
|
||||||
|
VIR_FREE(file->domname);
|
||||||
VIR_FREE(file);
|
VIR_FREE(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,6 +212,8 @@ virLogHandlerLogFilePostExecRestart(virLogHandlerPtr handler,
|
|||||||
{
|
{
|
||||||
virLogHandlerLogFilePtr file;
|
virLogHandlerLogFilePtr file;
|
||||||
const char *path;
|
const char *path;
|
||||||
|
const char *domuuid;
|
||||||
|
const char *tmp;
|
||||||
|
|
||||||
if (VIR_ALLOC(file) < 0)
|
if (VIR_ALLOC(file) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -212,7 +222,34 @@ virLogHandlerLogFilePostExecRestart(virLogHandlerPtr handler,
|
|||||||
|
|
||||||
if ((path = virJSONValueObjectGetString(object, "path")) == NULL) {
|
if ((path = virJSONValueObjectGetString(object, "path")) == NULL) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("Missing file path in JSON document"));
|
_("Missing 'path' field in JSON document"));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((tmp = virJSONValueObjectGetString(object, "driver")) == NULL) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
|
_("Missing '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 '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 'domuuid' in JSON document"));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
if (virUUIDParse(domuuid, file->domuuid) < 0) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
|
_("Malformed 'domuuid' in JSON document"));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,7 +262,7 @@ virLogHandlerLogFilePostExecRestart(virLogHandlerPtr handler,
|
|||||||
|
|
||||||
if (virJSONValueObjectGetNumberInt(object, "pipefd", &file->pipefd) < 0) {
|
if (virJSONValueObjectGetNumberInt(object, "pipefd", &file->pipefd) < 0) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("Missing file pipefd in JSON document"));
|
_("Missing 'pipefd' in JSON document"));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (virSetInherit(file->pipefd, false) < 0) {
|
if (virSetInherit(file->pipefd, false) < 0) {
|
||||||
@ -347,7 +384,7 @@ virLogHandlerGetLogFilePathForDomain(virLogHandlerPtr handler,
|
|||||||
int
|
int
|
||||||
virLogHandlerDomainOpenLogFile(virLogHandlerPtr handler,
|
virLogHandlerDomainOpenLogFile(virLogHandlerPtr handler,
|
||||||
const char *driver,
|
const char *driver,
|
||||||
const unsigned char *domuuid ATTRIBUTE_UNUSED,
|
const unsigned char *domuuid,
|
||||||
const char *domname,
|
const char *domname,
|
||||||
ino_t *inode,
|
ino_t *inode,
|
||||||
off_t *offset)
|
off_t *offset)
|
||||||
@ -388,6 +425,10 @@ virLogHandlerDomainOpenLogFile(virLogHandlerPtr handler,
|
|||||||
file->watch = -1;
|
file->watch = -1;
|
||||||
file->pipefd = pipefd[0];
|
file->pipefd = pipefd[0];
|
||||||
pipefd[0] = -1;
|
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,
|
if ((file->file = virRotatingFileWriterNew(path,
|
||||||
DEFAULT_FILE_SIZE,
|
DEFAULT_FILE_SIZE,
|
||||||
@ -531,6 +572,7 @@ virLogHandlerPreExecRestart(virLogHandlerPtr handler)
|
|||||||
virJSONValuePtr ret = virJSONValueNewObject();
|
virJSONValuePtr ret = virJSONValueNewObject();
|
||||||
virJSONValuePtr files;
|
virJSONValuePtr files;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
char domuuid[VIR_UUID_STRING_BUFLEN];
|
||||||
|
|
||||||
if (!ret)
|
if (!ret)
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -561,6 +603,18 @@ virLogHandlerPreExecRestart(virLogHandlerPtr handler)
|
|||||||
virRotatingFileWriterGetPath(handler->files[i]->file)) < 0)
|
virRotatingFileWriterGetPath(handler->files[i]->file)) < 0)
|
||||||
goto error;
|
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) {
|
if (virSetInherit(handler->files[i]->pipefd, true) < 0) {
|
||||||
virReportSystemError(errno, "%s",
|
virReportSystemError(errno, "%s",
|
||||||
_("Cannot disable close-on-exec flag"));
|
_("Cannot disable close-on-exec flag"));
|
||||||
|
Loading…
Reference in New Issue
Block a user