[libvirt] [PATCH RFC 15/22] qemu_process: Don't open monitor if process failed

Chris Venteicher posted 22 patches 6 years ago
[libvirt] [PATCH RFC 15/22] qemu_process: Don't open monitor if process failed
Posted by Chris Venteicher 6 years ago
Gracefully handle case when proc activation failed prior to calling.

Consistent with the existing code for qemuConnectMonitor (for domains)
    in qemu_process.c...

- Handle qemMonitorOpen failure with INFO message and NULL ptr
- Identify parameters passed to qemuMonitorOpen

Monitor callbacks will be removed in future patch so we prep for passing
NULL for the callback pointer.

Set proc->mon to NULL then use VIR_STEAL_PTR if successful to be
consistent with other functions.

Signed-off-by: Chris Venteicher <cventeic@redhat.com>
---
 src/qemu/qemu_process.c | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index d4ed2d6353..55a092ecbb 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -8236,25 +8236,48 @@ static int
 qemuConnectMonitorQmp(qemuProcessPtr proc)
 {
     int ret = -1;
+    qemuMonitorPtr mon = NULL;
+    unsigned long long timeout = 0;
+    bool retry = true;
+    bool enableJson = true;
+    virQEMUDriverPtr driver = NULL;
+    qemuMonitorCallbacksPtr monCallbacks = &callbacks;
     virDomainXMLOptionPtr xmlopt = NULL;
     virDomainChrSourceDef monConfig;
 
     VIR_DEBUG("proc=%p, emulator=%s, proc->pid=%lld",
               proc, NULLSTR(proc->binary), (long long) proc->pid);
 
+    if (!proc || !proc->pid)
+        goto ignore;
+
+    proc->mon = NULL;
+
     monConfig.type = VIR_DOMAIN_CHR_TYPE_UNIX;
     monConfig.data.nix.path = proc->monpath;
     monConfig.data.nix.listen = false;
 
+    /* Create a NULL Domain object for qemuMonitor */
     if (!(xmlopt = virDomainXMLOptionNew(NULL, NULL, NULL, NULL, NULL)) ||
         !(proc->vm = virDomainObjNew(xmlopt)))
         goto cleanup;
 
     proc->vm->pid = proc->pid;
 
-    if (!(proc->mon = qemuMonitorOpen(proc->vm, &monConfig, true, true,
-                                      0, &callbacks, NULL)))
+    mon = qemuMonitorOpen(proc->vm,
+                          &monConfig,
+                          enableJson,
+                          retry,
+                          timeout,
+                          monCallbacks,
+                          driver);
+
+    if (!mon) {
+        VIR_INFO("Failed to connect monitor to emulator %s", proc->binary);
         goto ignore;
+    }
+
+    VIR_STEAL_PTR(proc->mon, mon);
 
     virObjectLock(proc->mon);
 
-- 
2.17.1

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