]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu_process: Enter QMP command mode when starting QEMU Process
authorChris Venteicher <cventeic@redhat.com>
Thu, 14 Feb 2019 10:25:50 +0000 (11:25 +0100)
committerJiri Denemark <jdenemar@redhat.com>
Tue, 19 Feb 2019 17:44:49 +0000 (18:44 +0100)
qemuProcessQMPStart starts a QEMU process and monitor connection that
can be used by multiple functions possibly for multiple QMP commands.

The QMP exchange to exit capabilities negotiation mode and enter command
mode can only be performed once after the monitor connection is
established.

Move responsibility for entering QMP command mode into the
qemuProcessQMP code so multiple functions can issue QMP commands in
arbitrary orders.

This also simplifies the functions using the connection provided by
qemuProcessQMPStart to issue QMP commands.

Test code now needs to call qemuMonitorSetCapabilities to send the
message to switch to command mode because the test code does not use the
qemuProcessQMP command that internally calls qemuMonitorSetCapabilities.

Signed-off-by: Chris Venteicher <cventeic@redhat.com>
Signed-off-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_processpriv.h
tests/qemucapabilitiestest.c

index a546d9b5a1621c9af7c4a74451f2a4557fc9f436..b48bcbebeecbb44406576dcabffe8fde91d27876 100644 (file)
@@ -4149,12 +4149,6 @@ virQEMUCapsInitQMPMonitor(virQEMUCapsPtr qemuCaps,
 
     /* @mon is supposed to be locked by callee */
 
-    if (qemuMonitorSetCapabilities(mon) < 0) {
-        VIR_DEBUG("Failed to set monitor capabilities %s",
-                  virGetLastErrorMessage());
-        goto cleanup;
-    }
-
     if (qemuMonitorGetVersion(mon,
                               &major, &minor, &micro,
                               &package) < 0) {
@@ -4333,12 +4327,6 @@ virQEMUCapsInitQMPMonitorTCG(virQEMUCapsPtr qemuCaps ATTRIBUTE_UNUSED,
 {
     int ret = -1;
 
-    if (qemuMonitorSetCapabilities(mon) < 0) {
-        VIR_DEBUG("Failed to set monitor capabilities %s",
-                  virGetLastErrorMessage());
-        goto cleanup;
-    }
-
     if (virQEMUCapsProbeQMPCPUDefinitions(qemuCaps, mon, true) < 0)
         goto cleanup;
 
index 820476dbb18d965a65f17f1ffc0e799ad24ec9e5..85952b99756648b546e02e72a2fdf1010b0e0885 100644 (file)
@@ -8544,6 +8544,19 @@ qemuProcessQMPLaunch(qemuProcessQMPPtr proc)
 }
 
 
+int
+qemuProcessQMPInitMonitor(qemuMonitorPtr mon)
+{
+    if (qemuMonitorSetCapabilities(mon) < 0) {
+        VIR_DEBUG("Failed to set monitor capabilities %s",
+                  virGetLastErrorMessage());
+        return -1;
+    }
+
+    return 0;
+}
+
+
 static int
 qemuProcessQMPConnectMonitor(qemuProcessQMPPtr proc)
 {
@@ -8570,6 +8583,9 @@ qemuProcessQMPConnectMonitor(qemuProcessQMPPtr proc)
 
     virObjectLock(proc->mon);
 
+    if (qemuProcessQMPInitMonitor(proc->mon) < 0)
+        goto cleanup;
+
     ret = 0;
 
  cleanup:
index 17f981829bad833f316e5b44935cc30d04672c19..237d7bad58297e87fbea85f044cb5a30a3eef0fa 100644 (file)
@@ -38,4 +38,6 @@ int qemuProcessHandleDeviceDeleted(qemuMonitorPtr mon,
                                    const char *devAlias,
                                    void *opaque);
 
+int qemuProcessQMPInitMonitor(qemuMonitorPtr mon);
+
 #endif /* LIBVIRT_QEMU_PROCESSPRIV_H */
index fab77db7ce03d2aa340b5156439ac362cfb38598..8d47133e6f3a7db6a8931320e368b06323b30bcd 100644 (file)
@@ -26,6 +26,8 @@
 #include "qemu/qemu_capspriv.h"
 #define LIBVIRT_QEMU_MONITOR_PRIV_H_ALLOW
 #include "qemu/qemu_monitor_priv.h"
+#define LIBVIRT_QEMU_PROCESSPRIV_H_ALLOW
+#include "qemu/qemu_processpriv.h"
 
 #define VIR_FROM_THIS VIR_FROM_NONE
 
@@ -60,6 +62,9 @@ testQemuCaps(const void *opaque)
     if (!(mon = qemuMonitorTestNewFromFileFull(repliesFile, &data->driver, NULL)))
         goto cleanup;
 
+    if (qemuProcessQMPInitMonitor(qemuMonitorTestGetMonitor(mon)) < 0)
+        goto cleanup;
+
     if (!(capsActual = virQEMUCapsNew()) ||
         virQEMUCapsInitQMPMonitor(capsActual,
                                   qemuMonitorTestGetMonitor(mon)) < 0)
@@ -67,6 +72,10 @@ testQemuCaps(const void *opaque)
 
     if (virQEMUCapsGet(capsActual, QEMU_CAPS_KVM)) {
         qemuMonitorResetCommandID(qemuMonitorTestGetMonitor(mon));
+
+        if (qemuProcessQMPInitMonitor(qemuMonitorTestGetMonitor(mon)) < 0)
+            goto cleanup;
+
         if (virQEMUCapsInitQMPMonitorTCG(capsActual,
                                          qemuMonitorTestGetMonitor(mon)) < 0)
             goto cleanup;