]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu_process: Use qemuProcessQMP struct for a single process
authorChris Venteicher <cventeic@redhat.com>
Sun, 13 Jan 2019 00:50:06 +0000 (18:50 -0600)
committerJiri Denemark <jdenemar@redhat.com>
Tue, 19 Feb 2019 17:41:28 +0000 (18:41 +0100)
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>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_capabilities.c
src/qemu/qemu_process.c
src/qemu/qemu_process.h

index f578d4a5aeea4e8884bbd0ed4038b2f48ee0f553..6716e62e4a846b1e89f22d2c1b3b579134efb14c 100644 (file)
@@ -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;
 }
 
index 4ae2067782ea5d563619c61b2f5dd45f96218654..6c0f7165c7ec9455ec04071a71752b536c132d3d 100644 (file)
@@ -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";
index c59379facb360196502a13f8282679c60b4e5bfc..46a0bd2475246636d3ecdb703016e4a7fe664bbc 100644 (file)
@@ -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);