[libvirt] [PATCH 19/20] qemu_process: Use unique directories for QMP processes

Jiri Denemark posted 20 patches 6 years, 11 months ago
[libvirt] [PATCH 19/20] qemu_process: Use unique directories for QMP processes
Posted by Jiri Denemark 6 years, 11 months ago
From: Chris Venteicher <cventeic@redhat.com>

Multiple QEMU processes for QMP commands can operate concurrently.

Use a unique directory under libDir for each QEMU process to avoid
pidfile and unix socket collision between processes.

The pid file name is changed from "capabilities.pidfile" to "qmp.pid"
because we no longer need to avoid a possible clash with a qemu domain
called "capabilities" now that the processes artifacts are stored in
their own unique temporary directories.

"Capabilities" was changed to "qmp" in the pid file name because these
processes are no longer specific to the capabilities usecase and are
more generic in terms of being used for any general purpose QMP message
exchanges with a QEMU process that is not associated with a domain.

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

Notes:
    Version 7:
    - report error if mkdtemp fails

 src/qemu/qemu_process.c | 30 ++++++++++++++++++++----------
 src/qemu/qemu_process.h |  1 +
 2 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index ca5911bacd..820476dbb1 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -8358,6 +8358,9 @@ qemuProcessQMPStop(qemuProcessQMPPtr proc)
 
     if (proc->pidfile)
         unlink(proc->pidfile);
+
+    if (proc->uniqDir)
+        rmdir(proc->uniqDir);
 }
 
 
@@ -8376,6 +8379,7 @@ qemuProcessQMPFree(qemuProcessQMPPtr proc)
     qemuProcessQMPStop(proc);
     VIR_FREE(proc->binary);
     VIR_FREE(proc->libDir);
+    VIR_FREE(proc->uniqDir);
     VIR_FREE(proc->monpath);
     VIR_FREE(proc->monarg);
     VIR_FREE(proc->pidfile);
@@ -8430,31 +8434,37 @@ qemuProcessQMPNew(const char *binary,
 static int
 qemuProcessQMPInit(qemuProcessQMPPtr proc)
 {
+    char *template = NULL;
     int ret = -1;
 
     VIR_DEBUG("proc=%p, emulator=%s", proc, proc->binary);
 
-    /* the ".sock" sufix is important to avoid a possible clash with a qemu
-     * domain called "capabilities"
-     */
-    if (virAsprintf(&proc->monpath, "%s/%s", proc->libDir,
-                    "capabilities.monitor.sock") < 0)
+    if (virAsprintf(&template, "%s/qmp-XXXXXX", proc->libDir) < 0)
+        goto cleanup;
+
+    if (!(proc->uniqDir = mkdtemp(template))) {
+        virReportSystemError(errno,
+                             _("Failed to create unique directory with "
+                               "template '%s' for probing QEMU"),
+                             template);
+        goto cleanup;
+    }
+
+    if (virAsprintf(&proc->monpath, "%s/%s", proc->uniqDir,
+                    "qmp.monitor") < 0)
         goto cleanup;
 
     if (virAsprintf(&proc->monarg, "unix:%s,server,nowait", proc->monpath) < 0)
         goto cleanup;
 
-    /* ".pidfile" suffix is used rather than ".pid" to avoid a possible clash
-     * with a qemu domain called "capabilities"
+    /*
      * Normally we'd use runDir for pid files, but because we're using
      * -daemonize we need QEMU to be allowed to create them, rather
      * than libvirtd. So we're using libDir which QEMU can write to
      */
-    if (virAsprintf(&proc->pidfile, "%s/%s", proc->libDir, "capabilities.pidfile") < 0)
+    if (virAsprintf(&proc->pidfile, "%s/%s", proc->uniqDir, "qmp.pid") < 0)
         goto cleanup;
 
-    virPidFileForceCleanupPath(proc->pidfile);
-
     ret = 0;
 
  cleanup:
diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h
index c435a19726..3367cd3fe5 100644
--- a/src/qemu/qemu_process.h
+++ b/src/qemu/qemu_process.h
@@ -225,6 +225,7 @@ struct _qemuProcessQMP {
     char *monarg;
     char *monpath;
     char *pidfile;
+    char *uniqDir;
     virCommandPtr cmd;
     qemuMonitorPtr mon;
     pid_t pid;
-- 
2.20.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 19/20] qemu_process: Use unique directories for QMP processes
Posted by Ján Tomko 6 years, 11 months ago
On Tue, Feb 19, 2019 at 10:05:02AM +0100, Jiri Denemark wrote:
>From: Chris Venteicher <cventeic@redhat.com>
>
>Multiple QEMU processes for QMP commands can operate concurrently.
>
>Use a unique directory under libDir for each QEMU process to avoid
>pidfile and unix socket collision between processes.
>
>The pid file name is changed from "capabilities.pidfile" to "qmp.pid"
>because we no longer need to avoid a possible clash with a qemu domain
>called "capabilities" now that the processes artifacts are stored in
>their own unique temporary directories.
>
>"Capabilities" was changed to "qmp" in the pid file name because these
>processes are no longer specific to the capabilities usecase and are
>more generic in terms of being used for any general purpose QMP message
>exchanges with a QEMU process that is not associated with a domain.
>
>Signed-off-by: Chris Venteicher <cventeic@redhat.com>
>Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
>---
>
>Notes:
>    Version 7:
>    - report error if mkdtemp fails
>
> src/qemu/qemu_process.c | 30 ++++++++++++++++++++----------
> src/qemu/qemu_process.h |  1 +
> 2 files changed, 21 insertions(+), 10 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