[libvirt] [PATCH 20/20] qemu_process: Enter QMP command mode when starting QEMU Process

Jiri Denemark posted 20 patches 6 years, 11 months ago
[libvirt] [PATCH 20/20] qemu_process: Enter QMP command mode when starting QEMU Process
Posted by Jiri Denemark 6 years, 11 months ago
From: Chris Venteicher <cventeic@redhat.com>

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>
---

Notes:
    Version 7:
    - qemuMonitorSetCapabilities call was moved into a new
      qemuProcessQMPInitMonitor function, which is called from
      qemuProcessQMPConnectMonitor and the tests

 src/qemu/qemu_capabilities.c | 12 ------------
 src/qemu/qemu_process.c      | 16 ++++++++++++++++
 src/qemu/qemu_processpriv.h  |  2 ++
 tests/qemucapabilitiestest.c |  9 +++++++++
 4 files changed, 27 insertions(+), 12 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index a546d9b5a1..b48bcbebee 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -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;
 
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 820476dbb1..85952b9975 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -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:
diff --git a/src/qemu/qemu_processpriv.h b/src/qemu/qemu_processpriv.h
index 17f981829b..237d7bad58 100644
--- a/src/qemu/qemu_processpriv.h
+++ b/src/qemu/qemu_processpriv.h
@@ -38,4 +38,6 @@ int qemuProcessHandleDeviceDeleted(qemuMonitorPtr mon,
                                    const char *devAlias,
                                    void *opaque);
 
+int qemuProcessQMPInitMonitor(qemuMonitorPtr mon);
+
 #endif /* LIBVIRT_QEMU_PROCESSPRIV_H */
diff --git a/tests/qemucapabilitiestest.c b/tests/qemucapabilitiestest.c
index fab77db7ce..8d47133e6f 100644
--- a/tests/qemucapabilitiestest.c
+++ b/tests/qemucapabilitiestest.c
@@ -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;
-- 
2.20.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 20/20] qemu_process: Enter QMP command mode when starting QEMU Process
Posted by Ján Tomko 6 years, 11 months ago
On Tue, Feb 19, 2019 at 10:05:03AM +0100, Jiri Denemark wrote:
>From: Chris Venteicher <cventeic@redhat.com>
>
>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>
>---
>
>Notes:
>    Version 7:
>    - qemuMonitorSetCapabilities call was moved into a new
>      qemuProcessQMPInitMonitor function, which is called from
>      qemuProcessQMPConnectMonitor and the tests
>
> src/qemu/qemu_capabilities.c | 12 ------------
> src/qemu/qemu_process.c      | 16 ++++++++++++++++
> src/qemu/qemu_processpriv.h  |  2 ++
> tests/qemucapabilitiestest.c |  9 +++++++++
> 4 files changed, 27 insertions(+), 12 deletions(-)
>

Reviewed-by: Ján Tomko <jtomko@redhat.com>

Jano
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list