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

[libvirt] [PATCH v6 07/33] qemu_process: Use qemuProcessQMP struct for a single process



In new process code, move from model where qemuProcessQMP struct can be
used to activate a series of Qemu processes to model where one
qemuProcessQMP struct is used for one and only one Qemu process.

By allowing only one process activation per qemuProcessQMP struct, the
struct can safely store process outputs like status and stderr, without
being overwritten, until qemuProcessQMPFree is called.

By doing this, process outputs like status and stderr can remain stored
in the qemuProcessQMP struct without being overwritten by subsequent
process activations.

The forceTCG parameter (use / don't use KVM) will be passed when the
qemuProcessQMP struct is initialized since the qemuProcessQMP struct
won't be reused.

Signed-off-by: Chris Venteicher <cventeic redhat com>
---
 src/qemu/qemu_capabilities.c | 19 +++++++++++++++----
 src/qemu/qemu_process.c      |  9 +++++----
 src/qemu/qemu_process.h      |  7 ++++---
 3 files changed, 24 insertions(+), 11 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 73380fdc2b..35aac798d9 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -4360,14 +4360,15 @@ virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps,
                    char **qmperr)
 {
     qemuProcessQMPPtr proc = NULL;
+    qemuProcessQMPPtr procTCG = NULL;
     int ret = -1;
     int rc;
 
     if (!(proc = qemuProcessQMPNew(qemuCaps->binary, libDir,
-                                   runUid, runGid, qmperr)))
+                                   runUid, runGid, qmperr, false)))
         goto cleanup;
 
-    if ((rc = qemuProcessQMPRun(proc, false)) != 0) {
+    if ((rc = qemuProcessQMPRun(proc)) != 0) {
         if (rc == 1)
             ret = 0;
         goto cleanup;
@@ -4377,14 +4378,22 @@ virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps,
         goto cleanup;
 
     if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM)) {
+        /* The second QEMU process probes for TCG capabilities
+         * in case the first process reported KVM as enabled
+         * (otherwise the first one already reported TCG capabilities). */
+
         qemuProcessQMPStop(proc);
-        if ((rc = qemuProcessQMPRun(proc, true)) != 0) {
+
+        procTCG = qemuProcessQMPNew(qemuCaps->binary, libDir,
+                                    runUid, runGid, NULL, true);
+
+        if ((rc = qemuProcessQMPRun(procTCG)) != 0) {
             if (rc == 1)
                 ret = 0;
             goto cleanup;
         }
 
-        if (virQEMUCapsInitQMPMonitorTCG(qemuCaps, proc->mon) < 0)
+        if (virQEMUCapsInitQMPMonitorTCG(qemuCaps, procTCG->mon) < 0)
             goto cleanup;
     }
 
@@ -4392,7 +4401,9 @@ virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps,
 
  cleanup:
     qemuProcessQMPStop(proc);
+    qemuProcessQMPStop(procTCG);
     qemuProcessQMPFree(proc);
+    qemuProcessQMPFree(procTCG);
     return ret;
 }
 
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 2208ff72b2..297a542e3d 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -8223,7 +8223,8 @@ qemuProcessQMPNew(const char *binary,
                   const char *libDir,
                   uid_t runUid,
                   gid_t runGid,
-                  char **qmperr)
+                  char **qmperr,
+                  bool forceTCG)
 {
     qemuProcessQMPPtr proc = NULL;
 
@@ -8236,6 +8237,7 @@ qemuProcessQMPNew(const char *binary,
     proc->runUid = runUid;
     proc->runGid = runGid;
     proc->qmperr = qmperr;
+    proc->forceTCG = forceTCG;
 
     /* the ".sock" sufix is important to avoid a possible clash with a qemu
      * domain called "capabilities"
@@ -8274,15 +8276,14 @@ qemuProcessQMPNew(const char *binary,
  *          1 when probing QEMU failed
  */
 int
-qemuProcessQMPRun(qemuProcessQMPPtr proc,
-                  bool forceTCG)
+qemuProcessQMPRun(qemuProcessQMPPtr proc)
 {
     virDomainXMLOptionPtr xmlopt = NULL;
     const char *machine;
     int status = 0;
     int ret = -1;
 
-    if (forceTCG)
+    if (proc->forceTCG)
         machine = "none,accel=tcg";
     else
         machine = "none,accel=kvm:tcg";
diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h
index 28186a256f..ccbdb33679 100644
--- a/src/qemu/qemu_process.h
+++ b/src/qemu/qemu_process.h
@@ -229,18 +229,19 @@ struct _qemuProcessQMP {
     virDomainChrSourceDef config;
     pid_t pid;
     virDomainObjPtr vm;
+    bool forceTCG;
 };
 
 qemuProcessQMPPtr qemuProcessQMPNew(const char *binary,
                                     const char *libDir,
                                     uid_t runUid,
                                     gid_t runGid,
-                                    char **qmperr);
+                                    char **qmperr,
+                                    bool forceTCG);
 
 void qemuProcessQMPFree(qemuProcessQMPPtr proc);
 
-int qemuProcessQMPRun(qemuProcessQMPPtr cmd,
-                      bool forceTCG);
+int qemuProcessQMPRun(qemuProcessQMPPtr cmd);
 
 void qemuProcessQMPStop(qemuProcessQMPPtr proc);
 
-- 
2.17.1


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