[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 13/14] qga: systemd hibernate/suspend/hybrid-sleep su
From: |
Michael Roth |
Subject: |
[Qemu-devel] [PULL 13/14] qga: systemd hibernate/suspend/hybrid-sleep support |
Date: |
Tue, 3 Jul 2018 15:52:20 -0500 |
From: Daniel Henrique Barboza <address@hidden>
pmutils isn't being supported by newer OSes like Fedora 27
or Mint. This means that the only suspend option QGA offers
for these guests are writing directly into the Linux sys state
file. This also means that QGA also loses the ability to do
hybrid suspend in those guests - this suspend mode is only
available when using pmutils.
Newer guests can use systemd facilities to do all the suspend
types QGA supports. The mapping in comparison with pmutils is:
- pm-hibernate -> systemctl hibernate
- pm-suspend -> systemctl suspend
- pm-suspend-hybrid -> systemctl hybrid-sleep
To discover whether systemd supports these functions, we inspect
the status of the services that implements them.
With this patch, we can offer hybrid suspend again for newer
guests that do not have pmutils support anymore.
Signed-off-by: Daniel Henrique Barboza <address@hidden>
Signed-off-by: Michael Roth <address@hidden>
---
qga/commands-posix.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 72 insertions(+)
diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index 1559753d85..cdb825993f 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -1517,6 +1517,63 @@ static int run_process_child(const char *command[],
Error **errp)
return -1;
}
+static bool systemd_supports_mode(SuspendMode mode, Error **errp)
+{
+ Error *local_err = NULL;
+ const char *systemctl_args[3] = {"systemd-hibernate", "systemd-suspend",
+ "systemd-hybrid-sleep"};
+ const char *cmd[4] = {"systemctl", "status", systemctl_args[mode], NULL};
+ int status;
+
+ status = run_process_child(cmd, &local_err);
+
+ /*
+ * systemctl status uses LSB return codes so we can expect
+ * status > 0 and be ok. To assert if the guest has support
+ * for the selected suspend mode, status should be < 4. 4 is
+ * the code for unknown service status, the return value when
+ * the service does not exist. A common value is status = 3
+ * (program is not running).
+ */
+ if (status > 0 && status < 4) {
+ return true;
+ }
+
+ if (local_err) {
+ error_propagate(errp, local_err);
+ }
+
+ return false;
+}
+
+static void systemd_suspend(SuspendMode mode, Error **errp)
+{
+ Error *local_err = NULL;
+ const char *systemctl_args[3] = {"hibernate", "suspend", "hybrid-sleep"};
+ const char *cmd[3] = {"systemctl", systemctl_args[mode], NULL};
+ int status;
+
+ status = run_process_child(cmd, &local_err);
+
+ if (status == 0) {
+ return;
+ }
+
+ if ((status == -1) && !local_err) {
+ error_setg(errp, "the helper program 'systemctl %s' was not found",
+ systemctl_args[mode]);
+ return;
+ }
+
+ if (local_err) {
+ error_propagate(errp, local_err);
+ } else {
+ error_setg(errp, "the helper program 'systemctl %s' returned an "
+ "unexpected exit status code (%d)",
+ systemctl_args[mode], status);
+ }
+}
+
static bool pmutils_supports_mode(SuspendMode mode, Error **errp)
{
Error *local_err = NULL;
@@ -1660,6 +1717,14 @@ static void bios_supports_mode(SuspendMode mode, Error
**errp)
Error *local_err = NULL;
bool ret;
+ ret = systemd_supports_mode(mode, &local_err);
+ if (ret) {
+ return;
+ }
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
+ }
ret = pmutils_supports_mode(mode, &local_err);
if (ret) {
return;
@@ -1689,6 +1754,13 @@ static void guest_suspend(SuspendMode mode, Error **errp)
return;
}
+ systemd_suspend(mode, &local_err);
+ if (!local_err) {
+ return;
+ }
+
+ error_free(local_err);
+
pmutils_suspend(mode, &local_err);
if (!local_err) {
return;
--
2.11.0
- [Qemu-devel] [PULL 00/14] qga patch queue for soft-freeze, Michael Roth, 2018/07/03
- [Qemu-devel] [PULL 02/14] qga: check bytes count read by guest-file-read, Michael Roth, 2018/07/03
- [Qemu-devel] [PULL 10/14] qga: bios_supports_mode: decoupling pm-utils and sys logic, Michael Roth, 2018/07/03
- [Qemu-devel] [PULL 06/14] qga/schema: fix documentation for GuestOSInfo, Michael Roth, 2018/07/03
- [Qemu-devel] [PULL 13/14] qga: systemd hibernate/suspend/hybrid-sleep support,
Michael Roth <=
- [Qemu-devel] [PULL 04/14] qga-win: add driver path usage to GuestFilesystemInfo, Michael Roth, 2018/07/03
- [Qemu-devel] [PULL 09/14] qga: refactoring qmp_guest_suspend_* functions, Michael Roth, 2018/07/03
- [Qemu-devel] [PULL 05/14] test-qga: add trivial tests for some commands, Michael Roth, 2018/07/03
- [Qemu-devel] [PULL 08/14] qemu-ga: make get-fsinfo work over pci bridges, Michael Roth, 2018/07/03
- [Qemu-devel] [PULL 11/14] qga: guest_suspend: decoupling pm-utils and sys logic, Michael Roth, 2018/07/03
- [Qemu-devel] [PULL 07/14] qga-win: Fixing msi upgrade disallow in WiX file, Michael Roth, 2018/07/03
- [Qemu-devel] [PULL 14/14] qga: removing bios_supports_mode, Michael Roth, 2018/07/03
- [Qemu-devel] [PULL 01/14] qga: unset frozen state if no mount points are frozen, Michael Roth, 2018/07/03
- [Qemu-devel] [PULL 12/14] qga: removing switch statements, adding run_process_child, Michael Roth, 2018/07/03
- [Qemu-devel] [PULL 03/14] qga: add mountpoint usage info to GuestFilesystemInfo, Michael Roth, 2018/07/03