From: Marc-André Lureau <marcandre.lureau@xxxxxxxxxx> 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. Signed-off-by: Marc-André Lureau <marcandre.lureau@xxxxxxxxxx> --- src/qemu/qemu_extdevice.c | 40 ++++++++++++--------------------------- src/qemu/qemu_extdevice.h | 10 +++++----- src/qemu/qemu_process.c | 2 +- src/qemu/qemu_tpm.c | 10 ++++------ src/qemu/qemu_tpm.h | 5 ++--- 5 files changed, 24 insertions(+), 43 deletions(-) diff --git a/src/qemu/qemu_extdevice.c b/src/qemu/qemu_extdevice.c index a21caefaba..79d5d64951 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: * @@ -127,8 +112,7 @@ qemuExtDevicesCleanupHost(virQEMUDriverPtr driver, int qemuExtDevicesStart(virQEMUDriverPtr driver, - virDomainObjPtr vm, - qemuDomainLogContextPtr logCtxt) + virDomainObjPtr vm) { int ret = 0; @@ -136,7 +120,7 @@ qemuExtDevicesStart(virQEMUDriverPtr driver, return -1; if (vm->def->tpm) - ret = qemuExtTPMStart(driver, vm, logCtxt); + ret = qemuExtTPMStart(driver, vm); return ret; } diff --git a/src/qemu/qemu_extdevice.h b/src/qemu/qemu_extdevice.h index a72e05ce63..c9a3109fb6 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, @@ -39,9 +40,8 @@ void qemuExtDevicesCleanupHost(virQEMUDriverPtr driver, ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); int qemuExtDevicesStart(virQEMUDriverPtr driver, - virDomainObjPtr vm, - qemuDomainLogContextPtr logCtxt) - ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) + virDomainObjPtr vm) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK; void qemuExtDevicesStop(virQEMUDriverPtr driver, diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index aa09ef175a..411ecf17ad 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -6705,7 +6705,7 @@ qemuProcessLaunch(virConnectPtr conn, if (qemuProcessGenID(vm, flags) < 0) goto cleanup; - if (qemuExtDevicesStart(driver, vm, logCtxt) < 0) + if (qemuExtDevicesStart(driver, vm) < 0) goto cleanup; VIR_DEBUG("Building emulator command line"); diff --git a/src/qemu/qemu_tpm.c b/src/qemu/qemu_tpm.c index cc8c69433b..200a3d3391 100644 --- a/src/qemu/qemu_tpm.c +++ b/src/qemu/qemu_tpm.c @@ -754,8 +754,7 @@ qemuExtTPMCleanupHost(virDomainDefPtr def) */ static int qemuExtTPMStartEmulator(virQEMUDriverPtr driver, - virDomainObjPtr vm, - qemuDomainLogContextPtr logCtxt) + virDomainObjPtr vm) { int ret = -1; virCommandPtr cmd = NULL; @@ -782,7 +781,7 @@ qemuExtTPMStartEmulator(virQEMUDriverPtr driver, cfg->swtpmStateDir, shortName))) goto cleanup; - if (qemuExtDeviceLogCommand(logCtxt, cmd, "TPM Emulator") < 0) + if (qemuExtDeviceLogCommand(driver, vm, cmd, "TPM Emulator") < 0) goto cleanup; virCommandSetErrorBuffer(cmd, &errbuf); @@ -835,15 +834,14 @@ qemuExtTPMStartEmulator(virQEMUDriverPtr driver, int qemuExtTPMStart(virQEMUDriverPtr driver, - virDomainObjPtr vm, - qemuDomainLogContextPtr logCtxt) + virDomainObjPtr vm) { int ret = 0; virDomainTPMDefPtr tpm = vm->def->tpm; switch (tpm->type) { case VIR_DOMAIN_TPM_TYPE_EMULATOR: - ret = qemuExtTPMStartEmulator(driver, vm, logCtxt); + ret = qemuExtTPMStartEmulator(driver, vm); break; case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH: case VIR_DOMAIN_TPM_TYPE_LAST: diff --git a/src/qemu/qemu_tpm.h b/src/qemu/qemu_tpm.h index 74c9924d68..0be94bac3f 100644 --- a/src/qemu/qemu_tpm.h +++ b/src/qemu/qemu_tpm.h @@ -36,9 +36,8 @@ void qemuExtTPMCleanupHost(virDomainDefPtr def) ATTRIBUTE_NONNULL(1); int qemuExtTPMStart(virQEMUDriverPtr driver, - virDomainObjPtr vm, - qemuDomainLogContextPtr logCtxt) - ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) + virDomainObjPtr vm) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK; void qemuExtTPMStop(virQEMUDriverPtr driver, -- 2.22.0.214.g8dca754b1e -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list