[PATCH v2 06/11] qemu: Modify qemu driver to use domainLogContext

Praveen K Paladugu posted 11 patches 2 days, 8 hours ago
[PATCH v2 06/11] qemu: Modify qemu driver to use domainLogContext
Posted by Praveen K Paladugu 2 days, 8 hours ago
Modify qemu driver to use domainLogcontext instead of qemuLogContext.

Signed-off-by: Praveen K Paladugu <praveenkpaladugu@gmail.com>
---
 src/qemu/qemu_domain.c  | 28 ++++++++++++-------------
 src/qemu/qemu_domain.h  | 12 +++++------
 src/qemu/qemu_nbdkit.c  | 12 +++++++----
 src/qemu/qemu_process.c | 45 ++++++++++++++++++++++-------------------
 4 files changed, 52 insertions(+), 45 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index f15ba58179..c7d7ac26ce 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -5399,7 +5399,7 @@ static void G_GNUC_PRINTF(5, 6)
 qemuDomainObjTaintMsg(virQEMUDriver *driver,
                       virDomainObj *obj,
                       virDomainTaintFlags taint,
-                      qemuLogContext *logCtxt,
+                      domainLogContext *logCtxt,
                       const char *fmt, ...)
 {
     virErrorPtr orig_err = NULL;
@@ -5452,12 +5452,12 @@ qemuDomainObjTaintMsg(virQEMUDriver *driver,
         goto cleanup;
 
     if (logCtxt) {
-        rc = qemuLogContextWrite(logCtxt,
-                                 "%s: Domain id=%d is tainted: %s%s%s%s\n",
-                                 timestamp,
-                                 obj->def->id,
-                                 virDomainTaintTypeToString(taint),
-                                 extraprefix, extramsg, extrasuffix);
+        rc = domainLogContextWrite(logCtxt,
+                                   "%s: Domain id=%d is tainted: %s%s%s%s\n",
+                                   timestamp,
+                                   obj->def->id,
+                                   virDomainTaintTypeToString(taint),
+                                   extraprefix, extramsg, extrasuffix);
     } else {
         rc = qemuDomainLogAppendMessage(driver, obj,
                                         "%s: Domain id=%d is tainted: %s%s%s%s\n",
@@ -5478,7 +5478,7 @@ qemuDomainObjTaintMsg(virQEMUDriver *driver,
 void qemuDomainObjTaint(virQEMUDriver *driver,
                         virDomainObj *obj,
                         virDomainTaintFlags taint,
-                        qemuLogContext *logCtxt)
+                        domainLogContext *logCtxt)
 {
     qemuDomainObjTaintMsg(driver, obj, taint, logCtxt, NULL);
     qemuDomainSaveStatus(obj);
@@ -5487,7 +5487,7 @@ void qemuDomainObjTaint(virQEMUDriver *driver,
 static void
 qemuDomainObjCheckMachineTaint(virQEMUDriver *driver,
                                virDomainObj *obj,
-                               qemuLogContext *logCtxt)
+                               domainLogContext *logCtxt)
 {
     qemuDomainObjPrivate *priv = obj->privateData;
     virQEMUCaps *qemuCaps = priv->qemuCaps;
@@ -5505,7 +5505,7 @@ qemuDomainObjCheckMachineTaint(virQEMUDriver *driver,
 static void
 qemuDomainObjCheckCPUTaint(virQEMUDriver *driver,
                            virDomainObj *obj,
-                           qemuLogContext *logCtxt,
+                           domainLogContext *logCtxt,
                            bool incomingMigration)
 {
     qemuDomainObjPrivate *priv = obj->privateData;
@@ -5537,7 +5537,7 @@ qemuDomainObjCheckCPUTaint(virQEMUDriver *driver,
 
 void qemuDomainObjCheckTaint(virQEMUDriver *driver,
                              virDomainObj *obj,
-                             qemuLogContext *logCtxt,
+                             domainLogContext *logCtxt,
                              bool incomingMigration)
 {
     size_t i;
@@ -5593,7 +5593,7 @@ void qemuDomainObjCheckTaint(virQEMUDriver *driver,
 void qemuDomainObjCheckDiskTaint(virQEMUDriver *driver,
                                  virDomainObj *obj,
                                  virDomainDiskDef *disk,
-                                 qemuLogContext *logCtxt)
+                                 domainLogContext *logCtxt)
 {
     if (disk->rawio == VIR_TRISTATE_BOOL_YES)
         qemuDomainObjTaint(driver, obj, VIR_DOMAIN_TAINT_HIGH_PRIVILEGES,
@@ -5610,7 +5610,7 @@ void qemuDomainObjCheckDiskTaint(virQEMUDriver *driver,
 void qemuDomainObjCheckHostdevTaint(virQEMUDriver *driver,
                                     virDomainObj *obj,
                                     virDomainHostdevDef *hostdev,
-                                    qemuLogContext *logCtxt)
+                                    domainLogContext *logCtxt)
 {
     if (!virHostdevIsSCSIDevice(hostdev))
         return;
@@ -5623,7 +5623,7 @@ void qemuDomainObjCheckHostdevTaint(virQEMUDriver *driver,
 void qemuDomainObjCheckNetTaint(virQEMUDriver *driver,
                                 virDomainObj *obj,
                                 virDomainNetDef *net,
-                                qemuLogContext *logCtxt)
+                                domainLogContext *logCtxt)
 {
     /* script is only useful for NET_TYPE_ETHERNET (qemu) and
      * NET_TYPE_BRIDGE (xen), but could be (incorrectly) specified for
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 86e24ad54b..04577f1297 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -26,13 +26,13 @@
 #include "virperf.h"
 #include "domain_addr.h"
 #include "domain_conf.h"
+#include "domain_logcontext.h"
 #include "qemu_monitor.h"
 #include "qemu_agent.h"
 #include "qemu_blockjob.h"
 #include "qemu_domainjob.h"
 #include "qemu_conf.h"
 #include "qemu_capabilities.h"
-#include "qemu_logcontext.h"
 #include "qemu_migration_params.h"
 #include "qemu_nbdkit.h"
 #include "qemu_slirp.h"
@@ -641,24 +641,24 @@ char *qemuDomainDefFormatLive(virQEMUDriver *driver,
 void qemuDomainObjTaint(virQEMUDriver *driver,
                         virDomainObj *obj,
                         virDomainTaintFlags taint,
-                        qemuLogContext *logCtxt);
+                        domainLogContext *logCtxt);
 
 void qemuDomainObjCheckTaint(virQEMUDriver *driver,
                              virDomainObj *obj,
-                             qemuLogContext *logCtxt,
+                             domainLogContext *logCtxt,
                              bool incomingMigration);
 void qemuDomainObjCheckDiskTaint(virQEMUDriver *driver,
                                  virDomainObj *obj,
                                  virDomainDiskDef *disk,
-                                 qemuLogContext *logCtxt);
+                                 domainLogContext *logCtxt);
 void qemuDomainObjCheckHostdevTaint(virQEMUDriver *driver,
                                     virDomainObj *obj,
                                     virDomainHostdevDef *disk,
-                                    qemuLogContext *logCtxt);
+                                    domainLogContext *logCtxt);
 void qemuDomainObjCheckNetTaint(virQEMUDriver *driver,
                                 virDomainObj *obj,
                                 virDomainNetDef *net,
-                                qemuLogContext *logCtxt);
+                                domainLogContext *logCtxt);
 
 int qemuDomainLogAppendMessage(virQEMUDriver *driver,
                                virDomainObj *vm,
diff --git a/src/qemu/qemu_nbdkit.c b/src/qemu/qemu_nbdkit.c
index f099f35e1e..65c98de017 100644
--- a/src/qemu/qemu_nbdkit.c
+++ b/src/qemu/qemu_nbdkit.c
@@ -1177,6 +1177,7 @@ qemuNbdkitProcessStart(qemuNbdkitProcess *proc,
                        virQEMUDriver *driver)
 {
     g_autoptr(virCommand) cmd = NULL;
+    g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
     int rc;
     int exitstatus = 0;
     g_autofree char *errbuf = NULL;
@@ -1185,7 +1186,7 @@ qemuNbdkitProcessStart(qemuNbdkitProcess *proc,
     g_autofree char *uristring = NULL;
     g_autofree char *basename = g_strdup_printf("%s-nbdkit-%i", vm->def->name, proc->source->id);
     int logfd = -1;
-    g_autoptr(qemuLogContext) logContext = NULL;
+    g_autoptr(domainLogContext) logContext = NULL;
 #if WITH_NBDKIT
     struct nbd_handle *nbd = NULL;
 #endif
@@ -1200,12 +1201,15 @@ qemuNbdkitProcessStart(qemuNbdkitProcess *proc,
     if (!(cmd = qemuNbdkitProcessBuildCommand(proc)))
         return -1;
 
-    if (!(logContext = qemuLogContextNew(driver, vm, basename))) {
+    if (!(logContext = domainLogContextNew(cfg->stdioLogD, cfg->logDir,
+                                           QEMU_DRIVER_NAME,
+                                           vm, driver->privileged,
+                                           basename))) {
         virLastErrorPrefixMessage("%s", _("can't connect to virtlogd"));
         return -1;
     }
 
-    logfd = qemuLogContextGetWriteFD(logContext);
+    logfd = domainLogContextGetWriteFD(logContext);
 
     VIR_DEBUG("starting nbdkit process for %s", qemuBlockStorageSourceGetStorageNodename(proc->source));
     virCommandSetErrorFD(cmd, &logfd);
@@ -1283,7 +1287,7 @@ qemuNbdkitProcessStart(qemuNbdkitProcess *proc,
     if ((uri = qemuBlockStorageSourceGetURI(proc->source)))
         uristring = virURIFormat(uri);
 
-    if (qemuLogContextReadFiltered(logContext, &errbuf, 1024) < 0)
+    if (domainLogContextReadFiltered(logContext, &errbuf, 1024) < 0)
         VIR_WARN("Unable to read from nbdkit log");
 
     virReportError(VIR_ERR_OPERATION_FAILED,
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 5f2e278156..c7240f3ae4 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -1840,7 +1840,7 @@ qemuProcessMonitorReportLogError(qemuMonitor *mon,
 static void
 qemuProcessMonitorLogFree(void *opaque)
 {
-    qemuLogContext *logCtxt = opaque;
+    domainLogContext *logCtxt = opaque;
     g_clear_object(&logCtxt);
 }
 
@@ -1866,7 +1866,7 @@ static int
 qemuConnectMonitor(virQEMUDriver *driver,
                    virDomainObj *vm,
                    int asyncJob,
-                   qemuLogContext *logCtxt,
+                   domainLogContext *logCtxt,
                    bool reconnect)
 {
     qemuDomainObjPrivate *priv = vm->privateData;
@@ -1918,13 +1918,13 @@ qemuConnectMonitor(virQEMUDriver *driver,
 
 
 static int
-qemuProcessReportLogError(qemuLogContext *logCtxt,
+qemuProcessReportLogError(domainLogContext *logCtxt,
                           const char *msgprefix)
 {
     g_autofree char *logmsg = NULL;
 
     /* assume that 1024 chars of qemu log is the right balance */
-    if (qemuLogContextReadFiltered(logCtxt, &logmsg, 1024) < 0)
+    if (domainLogContextReadFiltered(logCtxt, &logmsg, 1024) < 0)
         return -1;
 
     virResetLastError();
@@ -1943,7 +1943,7 @@ qemuProcessMonitorReportLogError(qemuMonitor *mon G_GNUC_UNUSED,
                                  const char *msg,
                                  void *opaque)
 {
-    qemuLogContext *logCtxt = opaque;
+    domainLogContext *logCtxt = opaque;
     qemuProcessReportLogError(logCtxt, msg);
 }
 
@@ -2244,7 +2244,7 @@ static int
 qemuProcessWaitForMonitor(virQEMUDriver *driver,
                           virDomainObj *vm,
                           int asyncJob,
-                          qemuLogContext *logCtxt)
+                          domainLogContext *logCtxt)
 {
     int ret = -1;
     g_autoptr(GHashTable) info = NULL;
@@ -4740,7 +4740,7 @@ static void
 qemuLogOperation(virDomainObj *vm,
                  const char *msg,
                  virCommand *cmd,
-                 qemuLogContext *logCtxt)
+                 domainLogContext *logCtxt)
 {
     g_autofree char *timestamp = NULL;
     qemuDomainObjPrivate *priv = vm->privateData;
@@ -4754,20 +4754,20 @@ qemuLogOperation(virDomainObj *vm,
     if ((timestamp = virTimeStringNow()) == NULL)
         return;
 
-    if (qemuLogContextWrite(logCtxt,
-                            "%s: %s %s, qemu version: %d.%d.%d%s, kernel: %s, hostname: %s\n",
-                            timestamp, msg, VIR_LOG_VERSION_STRING,
-                            (qemuVersion / 1000000) % 1000,
-                            (qemuVersion / 1000) % 1000,
-                            qemuVersion % 1000,
-                            NULLSTR_EMPTY(package),
-                            uts.release,
-                            NULLSTR_EMPTY(hostname)) < 0)
+    if (domainLogContextWrite(logCtxt,
+                              "%s: %s %s, qemu version: %d.%d.%d%s, kernel: %s, hostname: %s\n",
+                              timestamp, msg, VIR_LOG_VERSION_STRING,
+                              (qemuVersion / 1000000) % 1000,
+                              (qemuVersion / 1000) % 1000,
+                              qemuVersion % 1000,
+                              NULLSTR_EMPTY(package),
+                              uts.release,
+                              NULLSTR_EMPTY(hostname)) < 0)
         return;
 
     if (cmd) {
         g_autofree char *args = virCommandToString(cmd, true);
-        qemuLogContextWrite(logCtxt, "%s\n", args);
+        domainLogContextWrite(logCtxt, "%s\n", args);
     }
 }
 
@@ -7776,7 +7776,7 @@ qemuProcessLaunch(virConnectPtr conn,
     int ret = -1;
     int rv;
     int logfile = -1;
-    g_autoptr(qemuLogContext) logCtxt = NULL;
+    g_autoptr(domainLogContext) logCtxt = NULL;
     qemuDomainObjPrivate *priv = vm->privateData;
     g_autoptr(virCommand) cmd = NULL;
     struct qemuProcessHookData hookData;
@@ -7826,11 +7826,14 @@ qemuProcessLaunch(virConnectPtr conn,
     hookData.cfg = cfg;
 
     VIR_DEBUG("Creating domain log file");
-    if (!(logCtxt = qemuLogContextNew(driver, vm, vm->def->name))) {
+    if (!(logCtxt = domainLogContextNew(cfg->stdioLogD, cfg->logDir,
+                                        QEMU_DRIVER_NAME,
+                                        vm, driver->privileged,
+                                        vm->def->name))) {
         virLastErrorPrefixMessage("%s", _("can't connect to virtlogd"));
         goto cleanup;
     }
-    logfile = qemuLogContextGetWriteFD(logCtxt);
+    logfile = domainLogContextGetWriteFD(logCtxt);
 
     if (qemuProcessGenID(vm, flags) < 0)
         goto cleanup;
@@ -7866,7 +7869,7 @@ qemuProcessLaunch(virConnectPtr conn,
 
     qemuDomainObjCheckTaint(driver, vm, logCtxt, incoming != NULL);
 
-    qemuLogContextMarkPosition(logCtxt);
+    domainLogContextMarkPosition(logCtxt);
 
     if (qemuProcessEnableDomainNamespaces(driver, vm) < 0)
         goto cleanup;
-- 
2.47.0