[PATCH v2 2/5] qemu-agent: Create suspend function

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

 



which allows guest to enter one of these modes:
-hibernation: RAM is stored onto disk and guest is powered off (S4)
-sleep: RAM stays powered, but CPUs are powered off (S3)
-hybrid: RAM is stored onto disk but guest is not powered off
---
 src/qemu/qemu_agent.c |   70 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_agent.h |   11 +++++++
 2 files changed, 81 insertions(+), 0 deletions(-)

diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
index 536724f..f2cae94 100644
--- a/src/qemu/qemu_agent.c
+++ b/src/qemu/qemu_agent.c
@@ -1219,3 +1219,73 @@ void qemuAgentSetSupportedLevel(qemuAgentPtr mon,
     mon->version = version;
     qemuAgentUnlock(mon);
 }
+
+static int
+qemuAgentSetSupportedLevelCommand(qemuAgentPtr mon)
+{
+    int ret = -1;
+    virJSONValuePtr cmd;
+    virJSONValuePtr reply = NULL;
+    unsigned int major, minor, micro;
+    unsigned int version = mon->version;
+
+    if (version < 1000*1000) {
+        qemuReportError(VIR_ERR_INTERNAL_ERROR,
+                        _("Invalid qemu version set: %u"),
+                        version);
+        return -1;
+    }
+
+    major = version / (1000 * 1000);
+    version %= 1000*1000;
+    minor = version / 1000;
+    version %= 1000;
+    micro = version;
+
+    cmd = qemuAgentMakeCommand("guest-set-support-level",
+                               "u:major", major,
+                               "u:minor", minor,
+                               "u:micro", micro,
+                               NULL);
+    if (!cmd)
+        return -1;
+
+    ret = qemuAgentCommand(mon, cmd, &reply);
+
+    if (ret == 0)
+        ret = qemuAgentCheckError(cmd, reply);
+
+    virJSONValueFree(cmd);
+    virJSONValueFree(reply);
+    return ret;
+}
+
+VIR_ENUM_DECL(qemuAgentSuspendMode);
+
+VIR_ENUM_IMPL(qemuAgentSuspendMode,
+              QEMU_AGENT_SUSPEND_LAST,
+              "hibernate", "sleep", "hybrid");
+
+int qemuAgentSuspend(qemuAgentPtr mon,
+                     qemuAgentSuspendMode mode)
+{
+    int ret = -1;
+    virJSONValuePtr cmd;
+    virJSONValuePtr reply = NULL;
+
+    cmd = qemuAgentMakeCommand("guest-suspend",
+                               "s:mode", qemuAgentSuspendModeTypeToString(mode),
+                               NULL);
+    if (!cmd)
+        return -1;
+
+    /* XXX Unconditionally set supported level until
+     * qemu learns to keep this information */
+    if ((ret = qemuAgentSetSupportedLevelCommand(mon)) == 0 &&
+        (ret = qemuAgentCommand(mon, cmd, &reply)) == 0)
+        ret = qemuAgentCheckError(cmd, reply);
+
+    virJSONValueFree(cmd);
+    virJSONValueFree(reply);
+    return ret;
+}
diff --git a/src/qemu/qemu_agent.h b/src/qemu/qemu_agent.h
index 2858207..56e5573 100644
--- a/src/qemu/qemu_agent.h
+++ b/src/qemu/qemu_agent.h
@@ -71,4 +71,15 @@ int qemuAgentFSThaw(qemuAgentPtr mon);
 
 void qemuAgentSetSupportedLevel(qemuAgentPtr mon,
                                 unsigned int version);
+
+typedef enum {
+    QEMU_AGENT_SUSPEND_HIBERNATE,
+    QEMU_AGENT_SUSPEND_SLEEP,
+    QEMU_AGENT_SUSPEND_HYBRID,
+
+    QEMU_AGENT_SUSPEND_LAST,
+} qemuAgentSuspendMode;
+
+int qemuAgentSuspend(qemuAgentPtr mon,
+                     qemuAgentSuspendMode mode);
 #endif /* __QEMU_AGENT_H__ */
-- 
1.7.3.4

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