[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH v2 04/23] qemu: replace logCtxt with qemuDomainLogAppendMessage()



From: Marc-André Lureau <marcandre lureau 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 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,
                         bool incomingMigration)
 {
     int ret = -1;
@@ -863,7 +863,7 @@ qemuExtTPMStartEmulator(virQEMUDriverPtr driver,
                                             incomingMigration)))
         goto cleanup;
 
-    if (qemuExtDeviceLogCommand(logCtxt, cmd, "TPM Emulator") < 0)
+    if (qemuExtDeviceLogCommand(driver, vm, cmd, "TPM Emulator") < 0)
         goto cleanup;
 
     virCommandSetErrorBuffer(cmd, &errbuf);
-- 
2.23.0.rc1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]