[libvirt PATCH v5 14/32] qemu: move qemuProcessReadLog() to qemuLogContext

Peter Krempa pkrempa at redhat.com
Thu Feb 16 14:56:47 UTC 2023


On Tue, Feb 14, 2023 at 11:08:01 -0600, Jonathon Jongsma wrote:
> This code can be used by the nbdkit implementation for reading back
> filtered log data for error reporting. Move it to qemuLogContext so that
> it can be shared. Renamed to qemuLogContextReadFiltered().
> 
> Signed-off-by: Jonathon Jongsma <jjongsma at redhat.com>
> Reviewed-by: Peter Krempa <pkrempa at redhat.com>
> ---
>  src/qemu/qemu_logcontext.c | 65 ++++++++++++++++++++++++++++++++++++
>  src/qemu/qemu_logcontext.h |  3 ++
>  src/qemu/qemu_process.c    | 67 +-------------------------------------
>  3 files changed, 69 insertions(+), 66 deletions(-)
> 
> diff --git a/src/qemu/qemu_logcontext.c b/src/qemu/qemu_logcontext.c
> index 6ad0beeeae..fed5112e28 100644
> --- a/src/qemu/qemu_logcontext.c
> +++ b/src/qemu/qemu_logcontext.c
> @@ -21,6 +21,7 @@
>  #include "qemu_logcontext.h"
>  #include "viralloc.h"
>  #include "virlog.h"
> +#include "virstring.h"
>  #include "virutil.h"
>  
>  #include <fcntl.h>
> @@ -236,6 +237,70 @@ qemuLogContextRead(qemuLogContext *ctxt,
>  }
>  
>  
> +/**
> + * qemuLogContextFilter: Read and filter log for relevant messages
> + * @ctxt: the domain log context
> + * @msg: pointer to buffer to store the read messages in
> + * @max: maximum length of the message returned in @msg after filtering
> + *
> + * Reads log output from @ctxt and filters it. Skips messages not produced by
> + * the target executable or irrelevant messages. If @max is not zero, @buf will
> + * contain at most @max characters from the end of the log and @buf will start
> + * after a new line if possible.
> + */
> +int
> +qemuLogContextReadFiltered(qemuLogContext *ctxt,
> +                           char **msg,
> +                           size_t max)
> +{
> +    char *buf;
> +    char *eol;
> +    char *filter_next;
> +    size_t skip;
> +    ssize_t got;
> +
> +    if ((got = qemuLogContextRead(ctxt, &buf) < 0))

You've got the quotes wrong here compared to the place where you took it
from

> -    if ((got = qemuLogContextRead(logCtxt, &buf)) < 0)


I wonder how that happened as it looks like code movement.


More information about the libvir-list mailing list