[libvirt] [PATCH 06/20] qemu_capabilities: Stop QEMU process before freeing

Jiri Denemark posted 20 patches 6 years, 11 months ago
[libvirt] [PATCH 06/20] qemu_capabilities: Stop QEMU process before freeing
Posted by Jiri Denemark 6 years, 11 months ago
From: Chris Venteicher <cventeic@redhat.com>

virQEMUCapsInitQMP now stops QEMU process in all execution paths,
before freeing the process structure.

The qemuProcessQMPStop function can be called multiple times without
problems... Won't attempt to stop processes and free resources multiple
times.

Follow the convention established in qemu_process of
1) alloc process structure
2) start process
3) use process
4) stop process
5) free process data structure

The process data structure persists after the process activation fails
or the process dies or is killed so stderr strings can be retrieved
until the process data structure is freed.

Signed-off-by: Chris Venteicher <cventeic@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---

Notes:
    Version 7:
    - no change

 src/qemu/qemu_capabilities.c |  1 +
 src/qemu/qemu_process.c      | 24 ++++++++++++++++--------
 2 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index d187e35a38..f578d4a5ae 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -4393,6 +4393,7 @@ virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps,
     ret = 0;
 
  cleanup:
+    qemuProcessQMPStop(proc);
     qemuProcessQMPFree(proc);
     return ret;
 }
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index d463a41ca0..4ae2067782 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -8488,14 +8488,20 @@ qemuProcessQMPRun(qemuProcessQMPPtr proc,
 void
 qemuProcessQMPStop(qemuProcessQMPPtr proc)
 {
-    if (proc->mon)
-        virObjectUnlock(proc->mon);
-    qemuMonitorClose(proc->mon);
-    proc->mon = NULL;
+    if (!proc)
+        return;
 
-    virCommandAbort(proc->cmd);
-    virCommandFree(proc->cmd);
-    proc->cmd = NULL;
+    if (proc->mon) {
+        virObjectUnlock(proc->mon);
+        qemuMonitorClose(proc->mon);
+        proc->mon = NULL;
+    }
+
+    if (proc->cmd) {
+        virCommandAbort(proc->cmd);
+        virCommandFree(proc->cmd);
+        proc->cmd = NULL;
+    }
 
     if (proc->monpath)
         unlink(proc->monpath);
@@ -8512,8 +8518,10 @@ qemuProcessQMPStop(qemuProcessQMPPtr proc)
                       virStrerror(errno, ebuf, sizeof(ebuf)));
 
         VIR_FREE(*proc->qmperr);
+
+        proc->pid = 0;
     }
+
     if (proc->pidfile)
         unlink(proc->pidfile);
-    proc->pid = 0;
 }
-- 
2.20.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 06/20] qemu_capabilities: Stop QEMU process before freeing
Posted by Ján Tomko 6 years, 11 months ago
On Tue, Feb 19, 2019 at 10:04:49AM +0100, Jiri Denemark wrote:
>From: Chris Venteicher <cventeic@redhat.com>
>
>virQEMUCapsInitQMP now stops QEMU process in all execution paths,
>before freeing the process structure.
>
>The qemuProcessQMPStop function can be called multiple times without
>problems... Won't attempt to stop processes and free resources multiple
>times.
>
>Follow the convention established in qemu_process of
>1) alloc process structure
>2) start process
>3) use process
>4) stop process
>5) free process data structure
>
>The process data structure persists after the process activation fails
>or the process dies or is killed so stderr strings can be retrieved
>until the process data structure is freed.
>
>Signed-off-by: Chris Venteicher <cventeic@redhat.com>
>Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
>Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
>---
>
>Notes:
>    Version 7:
>    - no change
>
> src/qemu/qemu_capabilities.c |  1 +
> src/qemu/qemu_process.c      | 24 ++++++++++++++++--------
> 2 files changed, 17 insertions(+), 8 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