[PATCHv1 10/12] qemu_capabilities: Introduce virQEMUCapsNewQMPCommandConnection

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

 



Start and connect to QEMU so QMP commands can be performed.

Isolates code for starting QEMU and establishing Monitor connections
from code for obtaining capabilities so that arbitrary QMP commands can
be exchanged with QEMU.
---
 src/qemu/qemu_capabilities.c | 40 +++++++++++++++++++++++++++++++++++-
 src/qemu/qemu_capabilities.h |  5 +++++
 2 files changed, 44 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 2bbbfc83f3..658f88b327 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -4285,7 +4285,7 @@ virQEMUCapsInitQMPCommandFree(virQEMUCapsInitQMPCommandPtr cmd)
 
 
 static virQEMUCapsInitQMPCommandPtr
-virQEMUCapsInitQMPCommandNew(char *binary,
+virQEMUCapsInitQMPCommandNew(const char *binary,
                              const char *libDir,
                              uid_t runUid,
                              gid_t runGid,
@@ -4426,6 +4426,44 @@ virQEMUCapsInitQMPCommandRun(virQEMUCapsInitQMPCommandPtr cmd,
 }
 
 
+/* Start and connect to QEMU so QMP commands can be performed.
+ */
+virQEMUCapsInitQMPCommandPtr
+virQEMUCapsNewQMPCommandConnection(const char *exec,
+                      const char *libDir, uid_t runUid, gid_t runGid,
+                      bool forceTCG)
+{
+    virQEMUCapsInitQMPCommandPtr cmd = NULL;
+    virQEMUCapsInitQMPCommandPtr rtn_cmd = NULL;
+
+    VIR_DEBUG("exec =%s", NULLSTR(exec));
+
+    /* Allocate and initialize QMPCommand structure */
+    if (!(cmd = virQEMUCapsInitQMPCommandNew(exec, libDir,
+                                             runUid, runGid, NULL)))
+        goto cleanup;
+
+    /* Spawn QEMU and establish connection for QMP commands */
+    if (virQEMUCapsInitQMPCommandRun(cmd, forceTCG) != 0)
+        goto cleanup;
+
+    /* Exit capabilities negotiation mode and enter QEMU command mode
+     * by issuing qmp_capabilities command to QEMU */
+    if (qemuMonitorSetCapabilities(cmd->mon) < 0) {
+        VIR_DEBUG("Failed to set monitor capabilities %s",
+                  virGetLastErrorMessage());
+        goto cleanup;
+    }
+
+    VIR_STEAL_PTR(rtn_cmd, cmd);
+
+ cleanup:
+    virQEMUCapsInitQMPCommandFree(cmd);
+
+    return rtn_cmd;
+}
+
+
 static int
 virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps,
                    const char *libDir,
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index c9618bb754..9a62b014ac 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -507,6 +507,11 @@ struct _virQEMUCapsInitQMPCommand {
     virDomainObjPtr vm;
 };
 
+virQEMUCapsInitQMPCommandPtr
+virQEMUCapsNewQMPCommandConnection(const char *exec,
+                                   const char *libDir, uid_t runUid, gid_t runGid,
+                                   bool forceTCG);
+
 void virQEMUCapsInitQMPCommandFree(virQEMUCapsInitQMPCommandPtr cmd);
 
 typedef struct _virQEMUCaps virQEMUCaps;
-- 
2.17.1

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



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux