[libvirt] [PATCH 2/4] logging: preserve driver, dom name & uuid against log file

John Ferlan jferlan at redhat.com
Fri Dec 4 19:34:49 UTC 2015



On 12/04/2015 10:53 AM, Daniel P. Berrange wrote:
> 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 at redhat.com>
> ---
>  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;
> +    }
> +

Looks like these error message were cut-n-paste of the existing message,
but the "file " ?adjective? doesn't make sense.

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

Looking at the function call it shows domuuid w/ ATTRIBUTE_UNUSED that
could be removed now

ACK with those adjustments.

John
> +    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"));
> 




More information about the libvir-list mailing list