[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH v5 04/36] qemu_process: Refer to proc not cmd in process code



s/cmd/proc/ in process code imported from qemu_capabilities.

No functionality is changed.  Just variable renaming.

Process code imported from qemu_capabilities was oriented around
starting a process to issue a single QMP command.

Future usecases (ex. baseline, compare) expect to use a single process
to issue multiple different QMP commands.

This patch changes the variable naming from cmd to proc to put focus
on the process being maintained to issue commands.

Signed-off-by: Chris Venteicher <cventeic redhat com>
---
 src/qemu/qemu_capabilities.c |  18 ++---
 src/qemu/qemu_process.c      | 138 +++++++++++++++++------------------
 src/qemu/qemu_process.h      |   4 +-
 3 files changed, 80 insertions(+), 80 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 2f78fe27fe..41a0dfa844 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -4241,39 +4241,39 @@ virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps,
                    gid_t runGid,
                    char **qmperr)
 {
-    qemuProcessQmpPtr cmd = NULL;
+    qemuProcessQmpPtr proc = NULL;
     int ret = -1;
     int rc;
 
-    if (!(cmd = qemuProcessQmpNew(qemuCaps->binary, libDir,
-                                  runUid, runGid, qmperr)))
+    if (!(proc = qemuProcessQmpNew(qemuCaps->binary, libDir,
+                                   runUid, runGid, qmperr)))
         goto cleanup;
 
-    if ((rc = qemuProcessQmpRun(cmd, false)) != 0) {
+    if ((rc = qemuProcessQmpRun(proc, false)) != 0) {
         if (rc == 1)
             ret = 0;
         goto cleanup;
     }
 
-    if (virQEMUCapsInitQMPMonitor(qemuCaps, cmd->mon) < 0)
+    if (virQEMUCapsInitQMPMonitor(qemuCaps, proc->mon) < 0)
         goto cleanup;
 
     if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM)) {
-        qemuProcessQmpAbort(cmd);
-        if ((rc = qemuProcessQmpRun(cmd, true)) != 0) {
+        qemuProcessQmpAbort(proc);
+        if ((rc = qemuProcessQmpRun(proc, true)) != 0) {
             if (rc == 1)
                 ret = 0;
             goto cleanup;
         }
 
-        if (virQEMUCapsInitQMPMonitorTCG(qemuCaps, cmd->mon) < 0)
+        if (virQEMUCapsInitQMPMonitorTCG(qemuCaps, proc->mon) < 0)
             goto cleanup;
     }
 
     ret = 0;
 
  cleanup:
-    qemuProcessQmpFree(cmd);
+    qemuProcessQmpFree(proc);
     return ret;
 }
 
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 46aed4fc9c..5f4853e0c4 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -8108,17 +8108,17 @@ static qemuMonitorCallbacks callbacks = {
 
 
 void
-qemuProcessQmpFree(qemuProcessQmpPtr cmd)
+qemuProcessQmpFree(qemuProcessQmpPtr proc)
 {
-    if (!cmd)
+    if (!proc)
         return;
 
-    qemuProcessQmpAbort(cmd);
-    VIR_FREE(cmd->binary);
-    VIR_FREE(cmd->monpath);
-    VIR_FREE(cmd->monarg);
-    VIR_FREE(cmd->pidfile);
-    VIR_FREE(cmd);
+    qemuProcessQmpAbort(proc);
+    VIR_FREE(proc->binary);
+    VIR_FREE(proc->monpath);
+    VIR_FREE(proc->monarg);
+    VIR_FREE(proc->pidfile);
+    VIR_FREE(proc);
 }
 
 
@@ -8129,25 +8129,25 @@ qemuProcessQmpNew(const char *binary,
                   gid_t runGid,
                   char **qmperr)
 {
-    qemuProcessQmpPtr cmd = NULL;
+    qemuProcessQmpPtr proc = NULL;
 
-    if (VIR_ALLOC(cmd) < 0)
+    if (VIR_ALLOC(proc) < 0)
         goto error;
 
-    if (VIR_STRDUP(cmd->binary, binary) < 0)
+    if (VIR_STRDUP(proc->binary, binary) < 0)
         goto error;
 
-    cmd->runUid = runUid;
-    cmd->runGid = runGid;
-    cmd->qmperr = qmperr;
+    proc->runUid = runUid;
+    proc->runGid = runGid;
+    proc->qmperr = qmperr;
 
     /* the ".sock" sufix is important to avoid a possible clash with a qemu
      * domain called "capabilities"
      */
-    if (virAsprintf(&cmd->monpath, "%s/%s", libDir,
+    if (virAsprintf(&proc->monpath, "%s/%s", libDir,
                     "capabilities.monitor.sock") < 0)
         goto error;
-    if (virAsprintf(&cmd->monarg, "unix:%s,server,nowait", cmd->monpath) < 0)
+    if (virAsprintf(&proc->monarg, "unix:%s,server,nowait", proc->monpath) < 0)
         goto error;
 
     /* ".pidfile" suffix is used rather than ".pid" to avoid a possible clash
@@ -8156,19 +8156,19 @@ qemuProcessQmpNew(const char *binary,
      * -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(&cmd->pidfile, "%s/%s", libDir, "capabilities.pidfile") < 0)
+    if (virAsprintf(&proc->pidfile, "%s/%s", libDir, "capabilities.pidfile") < 0)
         goto error;
 
-    virPidFileForceCleanupPath(cmd->pidfile);
+    virPidFileForceCleanupPath(proc->pidfile);
 
-    cmd->config.type = VIR_DOMAIN_CHR_TYPE_UNIX;
-    cmd->config.data.nix.path = cmd->monpath;
-    cmd->config.data.nix.listen = false;
+    proc->config.type = VIR_DOMAIN_CHR_TYPE_UNIX;
+    proc->config.data.nix.path = proc->monpath;
+    proc->config.data.nix.listen = false;
 
-    return cmd;
+    return proc;
 
  error:
-    qemuProcessQmpFree(cmd);
+    qemuProcessQmpFree(proc);
     return NULL;
 }
 
@@ -8178,7 +8178,7 @@ qemuProcessQmpNew(const char *binary,
  *          1 when probing QEMU failed
  */
 int
-qemuProcessQmpRun(qemuProcessQmpPtr cmd,
+qemuProcessQmpRun(qemuProcessQmpPtr proc,
                   bool forceTCG)
 {
     virDomainXMLOptionPtr xmlopt = NULL;
@@ -8192,7 +8192,7 @@ qemuProcessQmpRun(qemuProcessQmpPtr cmd,
         machine = "none,accel=kvm:tcg";
 
     VIR_DEBUG("Try to probe capabilities of '%s' via QMP, machine %s",
-              cmd->binary, machine);
+              proc->binary, machine);
 
     /*
      * We explicitly need to use -daemonize here, rather than
@@ -8201,55 +8201,55 @@ qemuProcessQmpRun(qemuProcessQmpPtr cmd,
      * daemonize guarantees control won't return to libvirt
      * until the socket is present.
      */
-    cmd->cmd = virCommandNewArgList(cmd->binary,
-                                    "-S",
-                                    "-no-user-config",
-                                    "-nodefaults",
-                                    "-nographic",
-                                    "-machine", machine,
-                                    "-qmp", cmd->monarg,
-                                    "-pidfile", cmd->pidfile,
-                                    "-daemonize",
-                                    NULL);
-    virCommandAddEnvPassCommon(cmd->cmd);
-    virCommandClearCaps(cmd->cmd);
-    virCommandSetGID(cmd->cmd, cmd->runGid);
-    virCommandSetUID(cmd->cmd, cmd->runUid);
+    proc->cmd = virCommandNewArgList(proc->binary,
+                                     "-S",
+                                     "-no-user-config",
+                                     "-nodefaults",
+                                     "-nographic",
+                                     "-machine", machine,
+                                     "-qmp", proc->monarg,
+                                     "-pidfile", proc->pidfile,
+                                     "-daemonize",
+                                     NULL);
+    virCommandAddEnvPassCommon(proc->cmd);
+    virCommandClearCaps(proc->cmd);
+    virCommandSetGID(proc->cmd, proc->runGid);
+    virCommandSetUID(proc->cmd, proc->runUid);
 
-    virCommandSetErrorBuffer(cmd->cmd, cmd->qmperr);
+    virCommandSetErrorBuffer(proc->cmd, proc->qmperr);
 
     /* Log, but otherwise ignore, non-zero status.  */
-    if (virCommandRun(cmd->cmd, &status) < 0)
+    if (virCommandRun(proc->cmd, &status) < 0)
         goto cleanup;
 
     if (status != 0) {
         VIR_DEBUG("QEMU %s exited with status %d: %s",
-                  cmd->binary, status, *cmd->qmperr);
+                  proc->binary, status, *proc->qmperr);
         goto ignore;
     }
 
-    if (virPidFileReadPath(cmd->pidfile, &cmd->pid) < 0) {
-        VIR_DEBUG("Failed to read pidfile %s", cmd->pidfile);
+    if (virPidFileReadPath(proc->pidfile, &proc->pid) < 0) {
+        VIR_DEBUG("Failed to read pidfile %s", proc->pidfile);
         goto ignore;
     }
 
     if (!(xmlopt = virDomainXMLOptionNew(NULL, NULL, NULL, NULL, NULL)) ||
-        !(cmd->vm = virDomainObjNew(xmlopt)))
+        !(proc->vm = virDomainObjNew(xmlopt)))
         goto cleanup;
 
-    cmd->vm->pid = cmd->pid;
+    proc->vm->pid = proc->pid;
 
-    if (!(cmd->mon = qemuMonitorOpen(cmd->vm, &cmd->config, true, true,
+    if (!(proc->mon = qemuMonitorOpen(proc->vm, &proc->config, true, true,
                                      0, &callbacks, NULL)))
         goto ignore;
 
-    virObjectLock(cmd->mon);
+    virObjectLock(proc->mon);
 
     ret = 0;
 
  cleanup:
-    if (!cmd->mon)
-        qemuProcessQmpAbort(cmd);
+    if (!proc->mon)
+        qemuProcessQmpAbort(proc);
     virObjectUnref(xmlopt);
 
     return ret;
@@ -8261,34 +8261,34 @@ qemuProcessQmpRun(qemuProcessQmpPtr cmd,
 
 
 void
-qemuProcessQmpAbort(qemuProcessQmpPtr cmd)
+qemuProcessQmpAbort(qemuProcessQmpPtr proc)
 {
-    if (cmd->mon)
-        virObjectUnlock(cmd->mon);
-    qemuMonitorClose(cmd->mon);
-    cmd->mon = NULL;
+    if (proc->mon)
+        virObjectUnlock(proc->mon);
+    qemuMonitorClose(proc->mon);
+    proc->mon = NULL;
 
-    virCommandAbort(cmd->cmd);
-    virCommandFree(cmd->cmd);
-    cmd->cmd = NULL;
+    virCommandAbort(proc->cmd);
+    virCommandFree(proc->cmd);
+    proc->cmd = NULL;
 
-    if (cmd->monpath)
-        unlink(cmd->monpath);
+    if (proc->monpath)
+        unlink(proc->monpath);
 
-    virDomainObjEndAPI(&cmd->vm);
+    virDomainObjEndAPI(&proc->vm);
 
-    if (cmd->pid != 0) {
+    if (proc->pid != 0) {
         char ebuf[1024];
 
-        VIR_DEBUG("Killing QMP caps process %lld", (long long)cmd->pid);
-        if (virProcessKill(cmd->pid, SIGKILL) < 0 && errno != ESRCH)
+        VIR_DEBUG("Killing QMP caps process %lld", (long long)proc->pid);
+        if (virProcessKill(proc->pid, SIGKILL) < 0 && errno != ESRCH)
             VIR_ERROR(_("Failed to kill process %lld: %s"),
-                      (long long)cmd->pid,
+                      (long long)proc->pid,
                       virStrerror(errno, ebuf, sizeof(ebuf)));
 
-        VIR_FREE(*cmd->qmperr);
+        VIR_FREE(*proc->qmperr);
     }
-    if (cmd->pidfile)
-        unlink(cmd->pidfile);
-    cmd->pid = 0;
+    if (proc->pidfile)
+        unlink(proc->pidfile);
+    proc->pid = 0;
 }
diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h
index 6d4fbda5fc..dea5a84e8c 100644
--- a/src/qemu/qemu_process.h
+++ b/src/qemu/qemu_process.h
@@ -237,11 +237,11 @@ qemuProcessQmpPtr qemuProcessQmpNew(const char *binary,
                                     gid_t runGid,
                                     char **qmperr);
 
-void qemuProcessQmpFree(qemuProcessQmpPtr cmd);
+void qemuProcessQmpFree(qemuProcessQmpPtr proc);
 
 int qemuProcessQmpRun(qemuProcessQmpPtr cmd,
                       bool forceTCG);
 
-void qemuProcessQmpAbort(qemuProcessQmpPtr cmd);
+void qemuProcessQmpAbort(qemuProcessQmpPtr proc);
 
 #endif /* __QEMU_PROCESS_H__ */
-- 
2.17.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]