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

Jiri Denemark jdenemar at redhat.com
Tue Feb 19 09:04:50 UTC 2019


From: Chris Venteicher <cventeic at redhat.com>

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 at redhat.com>
Reviewed-by: Jiri Denemark <jdenemar at redhat.com>
Signed-off-by: Jiri Denemark <jdenemar at redhat.com>
---

Notes:
    Version 7:
    - no change

 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 f578d4a5ae..6716e62e4a 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -4362,14 +4362,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;
@@ -4379,14 +4380,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;
     }
 
@@ -4394,7 +4403,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 4ae2067782..6c0f7165c7 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -8344,7 +8344,8 @@ qemuProcessQMPNew(const char *binary,
                   const char *libDir,
                   uid_t runUid,
                   gid_t runGid,
-                  char **qmperr)
+                  char **qmperr,
+                  bool forceTCG)
 {
     qemuProcessQMPPtr proc = NULL;
 
@@ -8357,6 +8358,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"
@@ -8395,15 +8397,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 c59379facb..46a0bd2475 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 proc,
-                      bool forceTCG);
+int qemuProcessQMPRun(qemuProcessQMPPtr proc);
 
 void qemuProcessQMPStop(qemuProcessQMPPtr proc);
 
-- 
2.20.1




More information about the libvir-list mailing list