[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 09/14] qga: refactoring qmp_guest_suspend_* functions
From: |
Michael Roth |
Subject: |
[Qemu-devel] [PULL 09/14] qga: refactoring qmp_guest_suspend_* functions |
Date: |
Tue, 3 Jul 2018 15:52:16 -0500 |
From: Daniel Henrique Barboza <address@hidden>
To be able to add new suspend mechanisms we need to detach
the existing QMP functions from the current implementation
specifics.
At this moment we have functions such as qmp_guest_suspend_ram
calling bios_suspend_mode and guest_suspend passing the
pmutils command and arguments as parameters. This patch
removes this logic from the QMP functions, moving them to
the respective functions that will have to deal with which
binary to use.
Signed-off-by: Daniel Henrique Barboza <address@hidden>
Signed-off-by: Michael Roth <address@hidden>
---
qga/commands-posix.c | 87 +++++++++++++++++++++++++++++++++-------------------
1 file changed, 55 insertions(+), 32 deletions(-)
diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index 7b7c78d85a..bd2c3514d8 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -1474,15 +1474,38 @@ qmp_guest_fstrim(bool has_minimum, int64_t minimum,
Error **errp)
#define LINUX_SYS_STATE_FILE "/sys/power/state"
#define SUSPEND_SUPPORTED 0
#define SUSPEND_NOT_SUPPORTED 1
+#define SUSPEND_MODE_DISK 1
+#define SUSPEND_MODE_RAM 2
+#define SUSPEND_MODE_HYBRID 3
-static void bios_supports_mode(const char *pmutils_bin, const char
*pmutils_arg,
- const char *sysfile_str, Error **errp)
+static void bios_supports_mode(int suspend_mode, Error **errp)
{
Error *local_err = NULL;
+ const char *pmutils_arg, *sysfile_str;
+ const char *pmutils_bin = "pm-is-supported";
char *pmutils_path;
pid_t pid;
int status;
+ switch (suspend_mode) {
+
+ case SUSPEND_MODE_DISK:
+ pmutils_arg = "--hibernate";
+ sysfile_str = "disk";
+ break;
+ case SUSPEND_MODE_RAM:
+ pmutils_arg = "--suspend";
+ sysfile_str = "mem";
+ break;
+ case SUSPEND_MODE_HYBRID:
+ pmutils_arg = "--suspend-hybrid";
+ sysfile_str = NULL;
+ break;
+ default:
+ error_setg(errp, "guest suspend mode not supported");
+ return;
+ }
+
pmutils_path = g_find_program_in_path(pmutils_bin);
pid = fork();
@@ -1559,14 +1582,39 @@ out:
g_free(pmutils_path);
}
-static void guest_suspend(const char *pmutils_bin, const char *sysfile_str,
- Error **errp)
+static void guest_suspend(int suspend_mode, Error **errp)
{
Error *local_err = NULL;
+ const char *pmutils_bin, *sysfile_str;
char *pmutils_path;
pid_t pid;
int status;
+ bios_supports_mode(suspend_mode, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
+ }
+
+ switch (suspend_mode) {
+
+ case SUSPEND_MODE_DISK:
+ pmutils_bin = "pm-hibernate";
+ sysfile_str = "disk";
+ break;
+ case SUSPEND_MODE_RAM:
+ pmutils_bin = "pm-suspend";
+ sysfile_str = "mem";
+ break;
+ case SUSPEND_MODE_HYBRID:
+ pmutils_bin = "pm-suspend-hybrid";
+ sysfile_str = NULL;
+ break;
+ default:
+ error_setg(errp, "unknown guest suspend mode");
+ return;
+ }
+
pmutils_path = g_find_program_in_path(pmutils_bin);
pid = fork();
@@ -1629,42 +1677,17 @@ out:
void qmp_guest_suspend_disk(Error **errp)
{
- Error *local_err = NULL;
-
- bios_supports_mode("pm-is-supported", "--hibernate", "disk", &local_err);
- if (local_err) {
- error_propagate(errp, local_err);
- return;
- }
-
- guest_suspend("pm-hibernate", "disk", errp);
+ guest_suspend(SUSPEND_MODE_DISK, errp);
}
void qmp_guest_suspend_ram(Error **errp)
{
- Error *local_err = NULL;
-
- bios_supports_mode("pm-is-supported", "--suspend", "mem", &local_err);
- if (local_err) {
- error_propagate(errp, local_err);
- return;
- }
-
- guest_suspend("pm-suspend", "mem", errp);
+ guest_suspend(SUSPEND_MODE_RAM, errp);
}
void qmp_guest_suspend_hybrid(Error **errp)
{
- Error *local_err = NULL;
-
- bios_supports_mode("pm-is-supported", "--suspend-hybrid", NULL,
- &local_err);
- if (local_err) {
- error_propagate(errp, local_err);
- return;
- }
-
- guest_suspend("pm-suspend-hybrid", NULL, errp);
+ guest_suspend(SUSPEND_MODE_HYBRID, errp);
}
static GuestNetworkInterfaceList *
--
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, 2018/07/03
- [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 <=
- [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
- Re: [Qemu-devel] [PULL 00/14] qga patch queue for soft-freeze, Peter Maydell, 2018/07/05