提交 5e6143fb 编写于 作者: P Peter Krempa

log: handler: Add new API to append to logging files

For logging one-shot entries to the VM log file it's quite a waste to
hold open the file descriptor for logging that is provided by the
current API.

This new API will be ideal for logging one-shot entries to the file
e.g. at the point when we shut the VM down rather than having to add the
whole file-descriptor infrastructure.

Additionally this will allow to add the messages even after restart of
libvirtd since virtlogd doesn't allow to obtain a regular context with
filedescriptors while the VM is still active.
上级 456ccc14
......@@ -513,6 +513,56 @@ virLogHandlerDomainReadLogFile(virLogHandlerPtr handler,
}
int
virLogHandlerDomainAppendLogFile(virLogHandlerPtr handler,
const char *driver ATTRIBUTE_UNUSED,
const unsigned char *domuuid ATTRIBUTE_UNUSED,
const char *domname ATTRIBUTE_UNUSED,
const char *path,
const char *message,
unsigned int flags)
{
size_t i;
virRotatingFileWriterPtr writer = NULL;
virRotatingFileWriterPtr newwriter = NULL;
int ret = -1;
virCheckFlags(0, -1);
VIR_DEBUG("Appending to log '%s' message: '%s'", path, message);
virObjectLock(handler);
for (i = 0; i < handler->nfiles; i++) {
if (STREQ(virRotatingFileWriterGetPath(handler->files[i]->file), path)) {
writer = handler->files[i]->file;
break;
}
}
if (!writer) {
if (!(newwriter = virRotatingFileWriterNew(path,
DEFAULT_FILE_SIZE,
DEFAULT_MAX_BACKUP,
false,
DEFAULT_MODE)))
goto cleanup;
writer = newwriter;
}
if (virRotatingFileWriterAppend(writer, message, strlen(message)) < 0)
goto cleanup;
ret = 0;
cleanup:
virRotatingFileWriterFree(newwriter);
virObjectUnlock(handler);
return ret;
}
virJSONValuePtr
virLogHandlerPreExecRestart(virLogHandlerPtr handler)
{
......
......@@ -65,6 +65,14 @@ char *virLogHandlerDomainReadLogFile(virLogHandlerPtr handler,
size_t maxlen,
unsigned int flags);
int virLogHandlerDomainAppendLogFile(virLogHandlerPtr handler,
const char *driver,
const unsigned char *domuuid,
const char *domname,
const char *path,
const char *message,
unsigned int flags);
virJSONValuePtr virLogHandlerPreExecRestart(virLogHandlerPtr handler);
#endif /** __VIR_LOG_HANDLER_H__ */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册