[libvirt] [PATCH v2 04/23] qemu: replace logCtxt with qemuDomainLogAppendMessage()
Michal Privoznik
mprivozn at redhat.com
Fri Sep 6 11:36:42 UTC 2019
On 8/8/19 4:54 PM, marcandre.lureau at redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau at redhat.com>
>
> Once QEMU is started, the qemuDomainLogContext is owned by it, and can
> no longer be used from libvirt. Instead, use
> qemuDomainLogAppendMessage() which will redirect the log.
>
> This is not strictly necessary for swtpm, but the following patches
> are going to reuse qemuExtDeviceLogCommand().
>
> Signed-off-by: Marc-André Lureau <marcandre.lureau at redhat.com>
> ---
> src/qemu/qemu_extdevice.c | 35 ++++++++++-------------------------
> src/qemu/qemu_extdevice.h | 5 +++--
> src/qemu/qemu_tpm.c | 4 ++--
> 3 files changed, 15 insertions(+), 29 deletions(-)
>
> diff --git a/src/qemu/qemu_extdevice.c b/src/qemu/qemu_extdevice.c
> index af52466421..0aa050cb0a 100644
> --- a/src/qemu/qemu_extdevice.c
> +++ b/src/qemu/qemu_extdevice.c
> @@ -36,39 +36,24 @@
> VIR_LOG_INIT("qemu.qemu_extdevice");
>
> int
> -qemuExtDeviceLogCommand(qemuDomainLogContextPtr logCtxt,
> +qemuExtDeviceLogCommand(virQEMUDriverPtr driver,
> + virDomainObjPtr vm,
> virCommandPtr cmd,
> const char *info)
> {
> - int ret = -1;
> - char *timestamp = NULL;
> - char *logline = NULL;
> - int logFD;
> + VIR_AUTOFREE(char *) timestamp = virTimeStringNow();
> + VIR_AUTOFREE(char *) cmds = virCommandToString(cmd, false);
>
> - logFD = qemuDomainLogContextGetWriteFD(logCtxt);
> -
> - if ((timestamp = virTimeStringNow()) == NULL)
> - goto cleanup;
> -
> - if (virAsprintf(&logline, "%s: Starting external device: %s\n",
> - timestamp, info) < 0)
> - goto cleanup;
> -
> - if (safewrite(logFD, logline, strlen(logline)) < 0)
> - goto cleanup;
> -
> - virCommandWriteArgLog(cmd, logFD);
> -
> - ret = 0;
> -
> - cleanup:
> - VIR_FREE(timestamp);
> - VIR_FREE(logline);
> + if (!timestamp || !cmds)
> + return -1;
>
> - return ret;
> + return qemuDomainLogAppendMessage(driver, vm,
> + _("%s: Starting external device: %s\n%s\n"),
> + timestamp, info, cmds);
> }
>
>
> +
> /*
> * qemuExtDevicesInitPaths:
> *
> diff --git a/src/qemu/qemu_extdevice.h b/src/qemu/qemu_extdevice.h
> index 5a53c79f38..cdd20c28ef 100644
> --- a/src/qemu/qemu_extdevice.h
> +++ b/src/qemu/qemu_extdevice.h
> @@ -23,10 +23,11 @@
> #include "qemu_conf.h"
> #include "qemu_domain.h"
>
> -int qemuExtDeviceLogCommand(qemuDomainLogContextPtr logCtxt,
> +int qemuExtDeviceLogCommand(virQEMUDriverPtr driver,
> + virDomainObjPtr vm,
> virCommandPtr cmd,
> const char *info)
> - ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
> + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4)
> ATTRIBUTE_RETURN_CHECK;
>
> int qemuExtDevicesPrepareHost(virQEMUDriverPtr driver,
> diff --git a/src/qemu/qemu_tpm.c b/src/qemu/qemu_tpm.c
> index 98fe8a38b4..7537091e90 100644
> --- a/src/qemu/qemu_tpm.c
> +++ b/src/qemu/qemu_tpm.c
> @@ -834,7 +834,7 @@ qemuExtTPMCleanupHost(virDomainDefPtr def)
> static int
> qemuExtTPMStartEmulator(virQEMUDriverPtr driver,
> virDomainObjPtr vm,
> - qemuDomainLogContextPtr logCtxt,
> + qemuDomainLogContextPtr logCtxt ATTRIBUTE_UNUSED,
I'd go a step further and remove logCtxt from the rest of the functions.
But that can be done in a separate commit.
Reviewed-by: Michal Privoznik <mprivozn at redhat.com>
Michal
More information about the libvir-list
mailing list