[PATCH 2/5] add qemuAgentCommand()

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

 



    Add qemuAgentCommand() for general qemu agent command.

 include/libvirt/libvirt-qemu.h |    5 +++++
 src/qemu/qemu_agent.c          |   38 ++++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_agent.h          |    5 +++++
 3 files changed, 48 insertions(+)

diff --git a/include/libvirt/libvirt-qemu.h b/include/libvirt/libvirt-qemu.h
index a37f897..ffc5ae5 100644
--- a/include/libvirt/libvirt-qemu.h
+++ b/include/libvirt/libvirt-qemu.h
@@ -44,6 +44,11 @@ virDomainPtr virDomainQemuAttach(virConnectPtr domain,
                                  unsigned int pid_value,
                                  unsigned int flags);

+typedef enum {
+    VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK = -1,
+    VIR_DOMAIN_QEMU_AGENT_COMMAND_NOWAIT = 0,
+} virDomainQemuAgentCommandTimeoutFlags;
+
 # ifdef __cplusplus
 }
 # endif
diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
index 7699042..1cfcafc 100644
--- a/src/qemu/qemu_agent.c
+++ b/src/qemu/qemu_agent.c
@@ -1401,3 +1401,41 @@ qemuAgentSuspend(qemuAgentPtr mon,
     virJSONValueFree(reply);
     return ret;
 }
+
+int qemuAgentQemuAgentCommand(qemuAgentPtr mon,
+                              const char *cmd_str,
+                              char **result,
+                              int timeout)
+{
+    int ret = -1;
+    int seconds;
+    virJSONValuePtr cmd;
+    virJSONValuePtr reply = NULL;
+
+    cmd = virJSONValueFromString(cmd_str);
+    if (!cmd)
+        return ret;
+
+    if (result == NULL) {
+        seconds = 0;
+    } else if (timeout == VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK) {
+        seconds = 5;
+    } else {
+        seconds = timeout;
+    }
+
+repeat:
+    ret = qemuAgentCommand(mon, cmd, &reply, timeout);
+
+    if (ret == 0) {
+        ret = qemuAgentCheckError(cmd, reply);
+        *result = virJSONValueToString(reply);
+    } else {
+        if (timeout == VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK) goto repeat;
+        *result = NULL;
+    }
+
+    virJSONValueFree(cmd);
+    virJSONValueFree(reply);
+    return ret;
+}
diff --git a/src/qemu/qemu_agent.h b/src/qemu/qemu_agent.h
index 2fdebb2..fc19c2f 100644
--- a/src/qemu/qemu_agent.h
+++ b/src/qemu/qemu_agent.h
@@ -77,4 +77,9 @@ int qemuAgentFSThaw(qemuAgentPtr mon);

 int qemuAgentSuspend(qemuAgentPtr mon,
                      unsigned int target);
+
+int qemuAgentQemuAgentCommand(qemuAgentPtr mon,
+                              const char *cmd,
+                              char **result,
+                              int timeout);
 #endif /* __QEMU_AGENT_H__ */

--
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]