From: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
To: qemu-devel@nongnu.org
Cc: berrange@redhat.com, michael.roth@amd.com, kkostiuk@redhat.com,
marcandre.lureau@redhat.com, philmd@linaro.org,
andrey.drobyshev@virtuozzo.com, den@virtuozzo.com
Subject: [PATCH v4 6/7] qga/commands-posix: don't do fork()/exec() when suspending via sysfs
Date: Wed, 20 Mar 2024 18:16:47 +0200 [thread overview]
Message-ID: <20240320161648.158226-7-andrey.drobyshev@virtuozzo.com> (raw)
In-Reply-To: <20240320161648.158226-1-andrey.drobyshev@virtuozzo.com>
Since commit 246d76eba ("qga: guest_suspend: decoupling pm-utils and sys
logic") pm-utils logic is running in a separate child from the sysfs
logic. Now when suspending via sysfs we don't really need to do that in
a separate process as we only need to perform one write to /sys/power/state.
Let's just use g_file_set_contents() to simplify things here.
Suggested-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
---
qga/commands-posix.c | 41 +++++------------------------------------
1 file changed, 5 insertions(+), 36 deletions(-)
diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index 9b993772f5..9910957ff5 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -1928,52 +1928,21 @@ static bool linux_sys_state_supports_mode(SuspendMode mode, Error **errp)
static void linux_sys_state_suspend(SuspendMode mode, Error **errp)
{
- Error *local_err = NULL;
+ g_autoptr(GError) local_gerr = NULL;
const char *sysfile_strs[3] = {"disk", "mem", NULL};
const char *sysfile_str = sysfile_strs[mode];
- pid_t pid;
- int status;
if (!sysfile_str) {
error_setg(errp, "unknown guest suspend mode");
return;
}
- pid = fork();
- if (!pid) {
- /* child */
- int fd;
-
- setsid();
- reopen_fd_to_null(0);
- reopen_fd_to_null(1);
- reopen_fd_to_null(2);
-
- fd = open(LINUX_SYS_STATE_FILE, O_WRONLY);
- if (fd < 0) {
- _exit(EXIT_FAILURE);
- }
-
- if (write(fd, sysfile_str, strlen(sysfile_str)) < 0) {
- _exit(EXIT_FAILURE);
- }
-
- _exit(EXIT_SUCCESS);
- } else if (pid < 0) {
- error_setg_errno(errp, errno, "failed to create child process");
- return;
- }
-
- ga_wait_child(pid, &status, &local_err);
- if (local_err) {
- error_propagate(errp, local_err);
+ if (!g_file_set_contents(LINUX_SYS_STATE_FILE, sysfile_str,
+ -1, &local_gerr)) {
+ error_setg(errp, "suspend: cannot write to '%s': %s",
+ LINUX_SYS_STATE_FILE, local_gerr->message);
return;
}
-
- if (WEXITSTATUS(status)) {
- error_setg(errp, "child process has failed to suspend");
- }
-
}
static void guest_suspend(SuspendMode mode, Error **errp)
--
2.39.3
next prev parent reply other threads:[~2024-03-20 16:17 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-20 16:16 [PATCH v4 0/7] qga/commands-posix: replace code duplicating commands with a helper Andrey Drobyshev
2024-03-20 16:16 ` [PATCH v4 1/7] qga: guest-get-fsinfo: add optional 'total-bytes-privileged' field Andrey Drobyshev
2024-03-22 10:39 ` Daniel P. Berrangé
2024-03-22 13:17 ` Andrey Drobyshev
2024-04-01 14:50 ` Andrey Drobyshev
2024-04-01 15:51 ` Konstantin Kostiuk
2024-03-20 16:16 ` [PATCH v4 2/7] qga: introduce ga_run_command() helper for guest cmd execution Andrey Drobyshev
2024-03-20 16:16 ` [PATCH v4 3/7] qga/commands-posix: qmp_guest_shutdown: use ga_run_command helper Andrey Drobyshev
2024-03-20 16:16 ` [PATCH v4 4/7] qga/commands-posix: qmp_guest_set_time: " Andrey Drobyshev
2024-03-20 16:16 ` [PATCH v4 5/7] qga/commands-posix: execute_fsfreeze_hook: " Andrey Drobyshev
2024-03-20 16:16 ` Andrey Drobyshev [this message]
2024-03-20 16:16 ` [PATCH v4 7/7] qga/commands-posix: qmp_guest_set_user_password: " Andrey Drobyshev
2024-04-24 9:34 ` [PATCH v4 0/7] qga/commands-posix: replace code duplicating commands with a helper Konstantin Kostiuk
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240320161648.158226-7-andrey.drobyshev@virtuozzo.com \
--to=andrey.drobyshev@virtuozzo.com \
--cc=berrange@redhat.com \
--cc=den@virtuozzo.com \
--cc=kkostiuk@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=michael.roth@amd.com \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).