From nobody Wed May 15 06:48:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1710951476; cv=none; d=zohomail.com; s=zohoarc; b=bJ99S3Xrhlo7kVEDpXtmCOJG7/KQbcQouLqqxVEi2emptmSlZkOHN6bhe2Qzc8BN0D/YMCSswLsnIkd+x18xp/dwMpXDPTVZgu3rxFRgv6ITSHGIhk/LbMZFFGhoGafNVgwAsbui7XtpFmFNAwP/COsU1VRWCHaiyorJYBjOjxw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710951476; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=piGTOfCHKlELerBHzZWEUaD5O2g+W0Jy64FNMvCKDD4=; b=fVa4FhLRgsvvz5P3wsVYjsmXRfJVPwltBHUFMSHs8lmkWbMkk0a+/FH/UtQLMMKkWjsVKLI5XV3XfzuMx6/sdTuCSaFu5CH5mijTjacdKV+LUZUd0/9IQsyWDKrtr3Ly3ns3qp4js0zO16L9tz0xCsrigQeV66zUO2mKOViHc0A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1710951476418146.7417400132315; Wed, 20 Mar 2024 09:17:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rmyd8-0007qA-ER; Wed, 20 Mar 2024 12:17:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rmycg-0007Wj-Tu for qemu-devel@nongnu.org; Wed, 20 Mar 2024 12:17:03 -0400 Received: from relay.virtuozzo.com ([130.117.225.111]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rmyca-0003sm-Hd for qemu-devel@nongnu.org; Wed, 20 Mar 2024 12:17:02 -0400 Received: from [130.117.225.1] (helo=dev005.ch-qa.vzint.dev) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1rmyaM-006TNN-1Y; Wed, 20 Mar 2024 17:16:37 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=MIME-Version:Message-Id:Date:Subject:From: Content-Type; bh=piGTOfCHKlELerBHzZWEUaD5O2g+W0Jy64FNMvCKDD4=; b=NeGCnap3RWld XKXeTg6Tstkh2dx1uaKdxw32ize/zUuL81fMfsUWC+z/+XGip1yIMQjH4K4nLQAanSOt5mYXMCNCV 9UZCht3WWNr2k5zSke+OFiuzi4I6kv7rjE4lVTSRjoGk/JN1cMRteTduxB7YdXf0MOnV3huzf6xeJ EFBHaO1WF6Br6Sn1onZw+z3sbZ3wUFYb3PlMotomLX3zuvi/BWgwOOKgY8A3k1IjvSPxXQ8c5yfDh uYQ3vbVqngOLEp7qFrios6iXsFtoodOaqtY0jzd9AvX3368bjM2oOtwaBGTw4iWHPXocax5RF6g8e Rk6l3LQjDDyz2D7h4yk94w==; From: Andrey Drobyshev 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 1/7] qga: guest-get-fsinfo: add optional 'total-bytes-privileged' field Date: Wed, 20 Mar 2024 18:16:42 +0200 Message-Id: <20240320161648.158226-2-andrey.drobyshev@virtuozzo.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240320161648.158226-1-andrey.drobyshev@virtuozzo.com> References: <20240320161648.158226-1-andrey.drobyshev@virtuozzo.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=130.117.225.111; envelope-from=andrey.drobyshev@virtuozzo.com; helo=relay.virtuozzo.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @virtuozzo.com) X-ZM-MESSAGEID: 1710951478011100003 Content-Type: text/plain; charset="utf-8" Since the commit 25b5ff1a86 ("qga: add mountpoint usage info to GuestFilesystemInfo") we have 2 values reported in guest-get-fsinfo: used =3D (f_blocks - f_bfree), total =3D (f_blocks - f_bfree + f_bavail) as returned by statvfs(3). While on Windows guests that's all we can get with GetDiskFreeSpaceExA(), on POSIX guests we might also be interested in total file system size, as it's visible for root user. Let's add an optional field 'total-bytes-privileged' to GuestFilesystemInfo struct, which'd only be reported on POSIX and represent f_blocks value as returned by statvfs(3). While here, also tweak the docs to reflect better where those values come from. Signed-off-by: Andrey Drobyshev Reviewed-by: Konstantin Kostiuk --- qga/commands-posix.c | 2 ++ qga/commands-win32.c | 1 + qga/qapi-schema.json | 7 +++++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 26008db497..7df2d72e9f 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -1569,8 +1569,10 @@ static GuestFilesystemInfo *build_guest_fsinfo(struc= t FsMount *mount, nonroot_total =3D used + buf.f_bavail; fs->used_bytes =3D used * fr_size; fs->total_bytes =3D nonroot_total * fr_size; + fs->total_bytes_privileged =3D buf.f_blocks * fr_size; =20 fs->has_total_bytes =3D true; + fs->has_total_bytes_privileged =3D true; fs->has_used_bytes =3D true; } =20 diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 6242737b00..6fee0e1e6f 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -1143,6 +1143,7 @@ static GuestFilesystemInfo *build_guest_fsinfo(char *= guid, Error **errp) fs =3D g_malloc(sizeof(*fs)); fs->name =3D g_strdup(guid); fs->has_total_bytes =3D false; + fs->has_total_bytes_privileged =3D false; fs->has_used_bytes =3D false; if (len =3D=3D 0) { fs->mountpoint =3D g_strdup("System Reserved"); diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json index 9554b566a7..dcc469b268 100644 --- a/qga/qapi-schema.json +++ b/qga/qapi-schema.json @@ -1026,7 +1026,10 @@ # # @used-bytes: file system used bytes (since 3.0) # -# @total-bytes: non-root file system total bytes (since 3.0) +# @total-bytes: filesystem capacity in bytes for unprivileged users (since= 3.0) +# +# @total-bytes-privileged: filesystem capacity in bytes for privileged use= rs +# (since 9.0) # # @disk: an array of disk hardware information that the volume lies # on, which may be empty if the disk type is not supported @@ -1036,7 +1039,7 @@ { 'struct': 'GuestFilesystemInfo', 'data': {'name': 'str', 'mountpoint': 'str', 'type': 'str', '*used-bytes': 'uint64', '*total-bytes': 'uint64', - 'disk': ['GuestDiskAddress']} } + '*total-bytes-privileged': 'uint64', 'disk': ['GuestDiskAddress= ']} } =20 ## # @guest-get-fsinfo: --=20 2.39.3 From nobody Wed May 15 06:48:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1710951438; cv=none; d=zohomail.com; s=zohoarc; b=ZHkYa3jpb8f6GVa74f+iKTyz6EVp3Z0TMq7KxZvhDtFtpGmhzlnxuJtlyUx+WtXysiHBSqCW76bq/UgJtU+5xFWQfTESnmUUunzpfjp2axkszC7tREPehbfC8Vgs6AzHSjS0tT6051zBplL+5wkFw0fEEcJfI1VayQMVzO+Ew1o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710951438; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Ktcfn+truaHsgdVNaP0RGvkmq8oZrw57gpLOr+xG5Wc=; b=AmjenGv09Zu6fm/i+Iw0CxBi8aOtEJMBGP74Qfmn6gEQ442JSXc0XI/rlVFAfP4EFW29yZnY8TyVDkPSFT3N4XDs+35UjE8apeb7C7KVRqkyQAfkykagYL69ZL4/oXXEH89I3UVHNkRkRJJm2AOTvEyGG1aX0To4ezXGPz2s/5Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 171095143822227.235403121426998; Wed, 20 Mar 2024 09:17:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rmyci-0007ZS-7w; Wed, 20 Mar 2024 12:17:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rmycc-0007TD-Be for qemu-devel@nongnu.org; Wed, 20 Mar 2024 12:16:59 -0400 Received: from relay.virtuozzo.com ([130.117.225.111]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rmyca-0003sn-Fg for qemu-devel@nongnu.org; Wed, 20 Mar 2024 12:16:58 -0400 Received: from [130.117.225.1] (helo=dev005.ch-qa.vzint.dev) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1rmyaM-006TNN-1j; Wed, 20 Mar 2024 17:16:37 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=Content-Type:MIME-Version:Message-Id:Date:Subject :From; bh=Ktcfn+truaHsgdVNaP0RGvkmq8oZrw57gpLOr+xG5Wc=; b=ek3tKiMNEnaNeMOADsG ChCXOKkdo7PKHra4hM/eSRrJ1Ln4zQxN9D4mJ8BmtFuDJpEwW/MpjPxkIDAIL7/rx1sGWJ/FJIpax aH5v4XWk9ymkK48gvajMuNMeNQ5SWV24LlL8V21CktTF2H3mY6EN6GH0ZzKOmQLKuSWklcy8HRVc8 aqYVPJrjf9AW1xmQ8b1fgjDtOI4OwngULIrHJ3lRwUjZ9/ajNFhyoO7CSJypK76iUKIsgYRqba2NJ BZIYQFK8NToHaNklcvJrHES7KxribORfp2m1K+ywpM7s4/47jh7tzFGJevmdS6fFXzAPoHWgilJkO L9KoNH5xAirwu2A==; From: Andrey Drobyshev 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 2/7] qga: introduce ga_run_command() helper for guest cmd execution Date: Wed, 20 Mar 2024 18:16:43 +0200 Message-Id: <20240320161648.158226-3-andrey.drobyshev@virtuozzo.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240320161648.158226-1-andrey.drobyshev@virtuozzo.com> References: <20240320161648.158226-1-andrey.drobyshev@virtuozzo.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=130.117.225.111; envelope-from=andrey.drobyshev@virtuozzo.com; helo=relay.virtuozzo.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @virtuozzo.com) X-ZM-MESSAGEID: 1710951439900100003 When executing guest commands in *nix environment, we repeat the same fork/exec pattern multiple times. Let's just separate it into a single helper which would also be able to feed input data into the launched process' stdin. This way we can avoid code duplication. To keep the history more bisectable, let's replace qmp commands implementations one by one. Also add G_GNUC_UNUSED attribute to the helper and remove it in the next commit. Originally-by: Yuri Pudgorodskiy Signed-off-by: Andrey Drobyshev Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Konstantin Kostiuk --- qga/commands-posix.c | 150 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 7df2d72e9f..9b1bdf194c 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -76,6 +76,156 @@ static void ga_wait_child(pid_t pid, int *status, Error= **errp) g_assert(rpid =3D=3D pid); } =20 +static ssize_t ga_pipe_read_str(int fd[2], char **str) +{ + ssize_t n, len =3D 0; + char buf[1024]; + + close(fd[1]); + fd[1] =3D -1; + while ((n =3D read(fd[0], buf, sizeof(buf))) !=3D 0) { + if (n < 0) { + if (errno =3D=3D EINTR) { + continue; + } else { + len =3D -errno; + break; + } + } + *str =3D g_realloc(*str, len + n + 1); + memcpy(*str + len, buf, n); + len +=3D n; + *str[len] =3D '\0'; + } + close(fd[0]); + fd[0] =3D -1; + + return len; +} + +/* + * Helper to run command with input/output redirection, + * sending string to stdin and taking error message from + * stdout/err. + */ +G_GNUC_UNUSED +static int ga_run_command(const char *argv[], const char *in_str, + const char *action, Error **errp) +{ + pid_t pid; + int status; + int retcode =3D -1; + int infd[2] =3D { -1, -1 }; + int outfd[2] =3D { -1, -1 }; + char *str =3D NULL; + ssize_t len =3D 0; + + if ((in_str && !g_unix_open_pipe(infd, FD_CLOEXEC, NULL)) || + !g_unix_open_pipe(outfd, FD_CLOEXEC, NULL)) { + error_setg(errp, "cannot create pipe FDs"); + goto out; + } + + pid =3D fork(); + if (pid =3D=3D 0) { + char *cherr =3D NULL; + + setsid(); + + if (in_str) { + /* Redirect stdin to infd. */ + close(infd[1]); + dup2(infd[0], 0); + close(infd[0]); + } else { + reopen_fd_to_null(0); + } + + /* Redirect stdout/stderr to outfd. */ + close(outfd[0]); + dup2(outfd[1], 1); + dup2(outfd[1], 2); + close(outfd[1]); + + execvp(argv[0], (char *const *)argv); + + /* Write the cause of failed exec to pipe for the parent to read i= t. */ + cherr =3D g_strdup_printf("failed to exec '%s'", argv[0]); + perror(cherr); + g_free(cherr); + _exit(EXIT_FAILURE); + } else if (pid < 0) { + error_setg_errno(errp, errno, "failed to create child process"); + goto out; + } + + if (in_str) { + close(infd[0]); + infd[0] =3D -1; + if (qemu_write_full(infd[1], in_str, strlen(in_str)) !=3D + strlen(in_str)) { + error_setg_errno(errp, errno, "%s: cannot write to stdin pipe", + action); + goto out; + } + close(infd[1]); + infd[1] =3D -1; + } + + len =3D ga_pipe_read_str(outfd, &str); + if (len < 0) { + error_setg_errno(errp, -len, "%s: cannot read from stdout/stderr p= ipe", + action); + goto out; + } + + ga_wait_child(pid, &status, errp); + if (*errp) { + goto out; + } + + if (!WIFEXITED(status)) { + if (len) { + error_setg(errp, "child process has terminated abnormally: %s", + str); + } else { + error_setg(errp, "child process has terminated abnormally"); + } + goto out; + } + + retcode =3D WEXITSTATUS(status); + + if (WEXITSTATUS(status)) { + if (len) { + error_setg(errp, "child process has failed to %s: %s", + action, str); + } else { + error_setg(errp, "child process has failed to %s: exit status = %d", + action, WEXITSTATUS(status)); + } + goto out; + } + +out: + g_free(str); + + if (infd[0] !=3D -1) { + close(infd[0]); + } + if (infd[1] !=3D -1) { + close(infd[1]); + } + if (outfd[0] !=3D -1) { + close(outfd[0]); + } + if (outfd[1] !=3D -1) { + close(outfd[1]); + } + + return retcode; +} + void qmp_guest_shutdown(const char *mode, Error **errp) { const char *shutdown_flag; --=20 2.39.3 From nobody Wed May 15 06:48:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1710951480; cv=none; d=zohomail.com; s=zohoarc; b=mxQPtSyJZv5fhsY1X7TPurjLExofHCrc3FGCYfS4i5f7D8jGN1NIaVQtIFybXR8CelUcIg77n2x9P2B/jRANUv3BOxjm2xtzQFzl/V9CYuQRtTPFX4H5Oa8DcEAsS0pESS8OrVKs5wa6S1dxK4ZmbBMYsPkMqIB7fvewt0CuPtk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710951480; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=PZWTqNmbKcfjj26fmVmiN5H+88Z5Ziac/wIPJxHChJw=; b=Z9TpiLFPpDSKMYY4ySIHdHkG8bVh+EMpWxN6te8PXrj2SM9YougWTqH4/yZkoqBviRqNKjyEPvQ8pXZlsMIKQenV9JBiMH0kCoP62DPyijiQ/hGJ1q4u1SGh+DzWc75EEUDLG0AgFzZ4DV2ro2624j3lpfA0TjNLq/2/feNM8GQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1710951480876420.30835005687766; Wed, 20 Mar 2024 09:18:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rmyd8-0007ph-DS; Wed, 20 Mar 2024 12:17:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rmycc-0007TI-Sq for qemu-devel@nongnu.org; Wed, 20 Mar 2024 12:16:59 -0400 Received: from relay.virtuozzo.com ([130.117.225.111]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rmyca-0003sq-B6 for qemu-devel@nongnu.org; Wed, 20 Mar 2024 12:16:58 -0400 Received: from [130.117.225.1] (helo=dev005.ch-qa.vzint.dev) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1rmyaM-006TNN-1u; Wed, 20 Mar 2024 17:16:37 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=Content-Type:MIME-Version:Message-Id:Date:Subject :From; bh=PZWTqNmbKcfjj26fmVmiN5H+88Z5Ziac/wIPJxHChJw=; b=aXfLkrALii7UgOWYLU0 TmEKA5GPZy9LpUtLaw37T0awqbmtFpjlLaCFPEw273MEtGOTNaWaVmkNeMfrwygRKFbWdmJg1QKzX 1g6bDbjkZ8NLOzonD1FkBqmW7fDM+LNLhChu8mToJVfHmoe8lFfz7MY13cwI6IcW/X6Ba/WS8SVP3 8yREfM/DJ0ybdHUlAC17EvfUhEh+hQc0RBnKo3bk+mWg9B/ZXprrWf3e7SM9zFbyuepf5Ftxf6S/J XSVqkUg5Ja0Jz7WDKbwMl8ASSJsT0wCDoGeIEcC4aB4TqzPyKpd2qkX1/ZMAwdXUSa6Y/hT3tPBeR EWLSLmw7YbeZKTA==; From: Andrey Drobyshev 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 3/7] qga/commands-posix: qmp_guest_shutdown: use ga_run_command helper Date: Wed, 20 Mar 2024 18:16:44 +0200 Message-Id: <20240320161648.158226-4-andrey.drobyshev@virtuozzo.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240320161648.158226-1-andrey.drobyshev@virtuozzo.com> References: <20240320161648.158226-1-andrey.drobyshev@virtuozzo.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=130.117.225.111; envelope-from=andrey.drobyshev@virtuozzo.com; helo=relay.virtuozzo.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @virtuozzo.com) X-ZM-MESSAGEID: 1710951482001100003 Also remove the G_GNUC_UNUSED attribute added in the previous commit from the helper. Signed-off-by: Andrey Drobyshev Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Konstantin Kostiuk --- qga/commands-posix.c | 39 ++++++--------------------------------- 1 file changed, 6 insertions(+), 33 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 9b1bdf194c..cb9eed9a0b 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -108,7 +108,6 @@ static ssize_t ga_pipe_read_str(int fd[2], char **str) * sending string to stdin and taking error message from * stdout/err. */ -G_GNUC_UNUSED static int ga_run_command(const char *argv[], const char *in_str, const char *action, Error **errp) { @@ -230,8 +229,6 @@ void qmp_guest_shutdown(const char *mode, Error **errp) { const char *shutdown_flag; Error *local_err =3D NULL; - pid_t pid; - int status; =20 #ifdef CONFIG_SOLARIS const char *powerdown_flag =3D "-i5"; @@ -260,46 +257,22 @@ void qmp_guest_shutdown(const char *mode, Error **err= p) return; } =20 - pid =3D fork(); - if (pid =3D=3D 0) { - /* child, start the shutdown */ - setsid(); - reopen_fd_to_null(0); - reopen_fd_to_null(1); - reopen_fd_to_null(2); - + const char *argv[] =3D {"/sbin/shutdown", #ifdef CONFIG_SOLARIS - execl("/sbin/shutdown", "shutdown", shutdown_flag, "-g0", "-y", - "hypervisor initiated shutdown", (char *)NULL); + shutdown_flag, "-g0", "-y", #elif defined(CONFIG_BSD) - execl("/sbin/shutdown", "shutdown", shutdown_flag, "+0", - "hypervisor initiated shutdown", (char *)NULL); + shutdown_flag, "+0", #else - execl("/sbin/shutdown", "shutdown", "-h", shutdown_flag, "+0", - "hypervisor initiated shutdown", (char *)NULL); + "-h", shutdown_flag, "+0", #endif - _exit(EXIT_FAILURE); - } else if (pid < 0) { - error_setg_errno(errp, errno, "failed to create child process"); - return; - } + "hypervisor initiated shutdown", (char *) NULL}; =20 - ga_wait_child(pid, &status, &local_err); + ga_run_command(argv, NULL, "shutdown", &local_err); if (local_err) { error_propagate(errp, local_err); return; } =20 - if (!WIFEXITED(status)) { - error_setg(errp, "child process has terminated abnormally"); - return; - } - - if (WEXITSTATUS(status)) { - error_setg(errp, "child process has failed to shutdown"); - return; - } - /* succeeded */ } =20 --=20 2.39.3 From nobody Wed May 15 06:48:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1710951459; cv=none; d=zohomail.com; s=zohoarc; b=GdMqFnqz7ZC0Zkx8Uh2bdToFZbD0T+YSysVx7akjMi6uUGv1j22hfbck8TyFlB/Kk1FsUunqb4KzExXno8D+7rDmems1jWi36+mTCR6OshfIFTTR5mIdj8IFkNh19LVGDEi3CD7gEgjxE2coAAZ2OlAjHKdGfeYArFMYD76tfg8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710951459; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=g1L3K5RZwrk4E61zfl//L6cqUbhJNBwq9TJTO8pP1iQ=; b=CH9Qg3gHsPKAl3PlVCNZEc7TTOXz2CdLlu1Q0VnzAm+mQpcSO11l8ihYhJ83AkyooetR4DMxhhUOa56OSTAqng+T6TZQ+/fjCk+Q1+EhdT2s4GahC/l5bx37MRw7ZrhLT2c6useGm7sC4j/uRzVxrNWnmE602AUBBUZptOsBQsw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1710951459308609.7691848199804; Wed, 20 Mar 2024 09:17:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rmydC-000838-CX; Wed, 20 Mar 2024 12:17:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rmyce-0007Tj-MW for qemu-devel@nongnu.org; Wed, 20 Mar 2024 12:17:01 -0400 Received: from relay.virtuozzo.com ([130.117.225.111]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rmyca-0003ss-Ga for qemu-devel@nongnu.org; Wed, 20 Mar 2024 12:17:00 -0400 Received: from [130.117.225.1] (helo=dev005.ch-qa.vzint.dev) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1rmyaM-006TNN-25; Wed, 20 Mar 2024 17:16:37 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=Content-Type:MIME-Version:Message-Id:Date:Subject :From; bh=g1L3K5RZwrk4E61zfl//L6cqUbhJNBwq9TJTO8pP1iQ=; b=u6pomiDLuI3uk68P59H d3HLabb9lQAXofdRdioTItlKWSUcgB18QGkWdoEQaPA23D/uhuxon/PjlTyd0p0IR/xmRH5iFXElO aCvIl+DKG49V5aHLIFvw5ZbR1VP7FwHRIoaWcIpKufzbYDTVvt4IP+keM8U2qyiKMI+GseCy9Au5n O8VyL2mysaHnb+9sbOCo1GbbZiU9/7oLb0s13kbONb+CBqto29KnLflbAZefJUv0IhabF2guoERmJ cRzzl+jFCpS3vW+anXPl3UdfLNVi2lc2PxSfqA5BuU0JsmaL4WEVHOJCbY1aOJbTgobmzSTzGTyez Q4exuToPOETDz2A==; From: Andrey Drobyshev 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 4/7] qga/commands-posix: qmp_guest_set_time: use ga_run_command helper Date: Wed, 20 Mar 2024 18:16:45 +0200 Message-Id: <20240320161648.158226-5-andrey.drobyshev@virtuozzo.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240320161648.158226-1-andrey.drobyshev@virtuozzo.com> References: <20240320161648.158226-1-andrey.drobyshev@virtuozzo.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=130.117.225.111; envelope-from=andrey.drobyshev@virtuozzo.com; helo=relay.virtuozzo.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @virtuozzo.com) X-ZM-MESSAGEID: 1710951459956100001 There's no need to check for the existence of "/sbin/hwclock", the exec() call will do that for us. Signed-off-by: Andrey Drobyshev Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Konstantin Kostiuk --- qga/commands-posix.c | 43 +++---------------------------------------- 1 file changed, 3 insertions(+), 40 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index cb9eed9a0b..545f3c99dc 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -279,21 +279,9 @@ void qmp_guest_shutdown(const char *mode, Error **errp) void qmp_guest_set_time(bool has_time, int64_t time_ns, Error **errp) { int ret; - int status; - pid_t pid; Error *local_err =3D NULL; struct timeval tv; - static const char hwclock_path[] =3D "/sbin/hwclock"; - static int hwclock_available =3D -1; - - if (hwclock_available < 0) { - hwclock_available =3D (access(hwclock_path, X_OK) =3D=3D 0); - } - - if (!hwclock_available) { - error_setg(errp, QERR_UNSUPPORTED); - return; - } + const char *argv[] =3D {"/sbin/hwclock", has_time ? "-w" : "-s", NULL}; =20 /* If user has passed a time, validate and set it. */ if (has_time) { @@ -324,37 +312,12 @@ void qmp_guest_set_time(bool has_time, int64_t time_n= s, Error **errp) * just need to synchronize the hardware clock. However, if no time was * passed, user is requesting the opposite: set the system time from t= he * hardware clock (RTC). */ - pid =3D fork(); - if (pid =3D=3D 0) { - setsid(); - reopen_fd_to_null(0); - reopen_fd_to_null(1); - reopen_fd_to_null(2); - - /* Use '/sbin/hwclock -w' to set RTC from the system time, - * or '/sbin/hwclock -s' to set the system time from RTC. */ - execl(hwclock_path, "hwclock", has_time ? "-w" : "-s", NULL); - _exit(EXIT_FAILURE); - } else if (pid < 0) { - error_setg_errno(errp, errno, "failed to create child process"); - return; - } - - ga_wait_child(pid, &status, &local_err); + ga_run_command(argv, NULL, "set hardware clock to system time", + &local_err); if (local_err) { error_propagate(errp, local_err); return; } - - if (!WIFEXITED(status)) { - error_setg(errp, "child process has terminated abnormally"); - return; - } - - if (WEXITSTATUS(status)) { - error_setg(errp, "hwclock failed to set hardware clock to system t= ime"); - return; - } } =20 typedef enum { --=20 2.39.3 From nobody Wed May 15 06:48:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1710951489; cv=none; d=zohomail.com; s=zohoarc; b=VeCvtw58XSrtBA7rpAa+O8HD539xJ1lEuOxvsZQcmEBiDgxmmMPi12jZqgEUQ+zZhpY1mY/tCjDkBGGlRLMzKVHf4e2ypfbz7dDFh9GYFIM03jZ445QCz81mG0CIiBqLGydEaRyh5f8HCx2L8f4+6bVdLUO1uGwj+l53ErM6hRY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710951489; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=J5GA2ToeZpS4Nt6uAUdq29B5O4s8bwbyayEo8FiUTnc=; b=HwREn+tPegDGkwb41mG89cOeIhDohss9Lt5PVFx8tAeapSkP+Txg7Ye+UqCNiqlDUcFUc0d/E/51cLagU/m0ApJa3a4lMekXvYJb1VGT7nJpqGHIfvnvAhs+aPYLwJpL55Nw7EdAu8oVu6hWCzItSsdmLwcoDeovFGRCSw29lR4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1710951489323903.2858409254665; Wed, 20 Mar 2024 09:18:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rmyd9-0007uI-7f; Wed, 20 Mar 2024 12:17:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rmycc-0007TH-SA for qemu-devel@nongnu.org; Wed, 20 Mar 2024 12:16:59 -0400 Received: from relay.virtuozzo.com ([130.117.225.111]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rmyca-0003sr-GD for qemu-devel@nongnu.org; Wed, 20 Mar 2024 12:16:58 -0400 Received: from [130.117.225.1] (helo=dev005.ch-qa.vzint.dev) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1rmyaM-006TNN-2H; Wed, 20 Mar 2024 17:16:38 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=Content-Type:MIME-Version:Message-Id:Date:Subject :From; bh=J5GA2ToeZpS4Nt6uAUdq29B5O4s8bwbyayEo8FiUTnc=; b=FgYUp7iGSk9URz/J9LK JV+7UUGYfoObLGjakl2FmAfpS+z6BwIbkZB6sCUiMt40nZ5dpiH//OGAVrd+aQ4dXiXnSWLUQvtZe GlHiMnywrUGsKvZ1+b2u+26nK2bqWlBVog+O7bL99h/1aRm10GrjKXgV6pzcigvkn/1y+lXNuOD1v mQATcE2JggD0mtZ7wBMcWSDePeEPRyov2LePYCXphHtRbhkvrh+zbaWJ7qgF+Xs5H+dXLyKr9EZ71 Gr5z3gz9d/H0814vnLqFIdSXgmsmXn7shoKsmrYiGfjDwzZX9B0rzKDR1BbSpiKNdLJ6GouvvDgcw v9iozL8xn+3THsw==; From: Andrey Drobyshev 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 5/7] qga/commands-posix: execute_fsfreeze_hook: use ga_run_command helper Date: Wed, 20 Mar 2024 18:16:46 +0200 Message-Id: <20240320161648.158226-6-andrey.drobyshev@virtuozzo.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240320161648.158226-1-andrey.drobyshev@virtuozzo.com> References: <20240320161648.158226-1-andrey.drobyshev@virtuozzo.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=130.117.225.111; envelope-from=andrey.drobyshev@virtuozzo.com; helo=relay.virtuozzo.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @virtuozzo.com) X-ZM-MESSAGEID: 1710951490102100001 There's no need to check for the existence of the hook executable, as the exec() call will do that for us. Signed-off-by: Andrey Drobyshev Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Konstantin Kostiuk --- qga/commands-posix.c | 35 +++-------------------------------- 1 file changed, 3 insertions(+), 32 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 545f3c99dc..9b993772f5 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -736,8 +736,6 @@ static const char *fsfreeze_hook_arg_string[] =3D { =20 static void execute_fsfreeze_hook(FsfreezeHookArg arg, Error **errp) { - int status; - pid_t pid; const char *hook; const char *arg_str =3D fsfreeze_hook_arg_string[arg]; Error *local_err =3D NULL; @@ -746,42 +744,15 @@ static void execute_fsfreeze_hook(FsfreezeHookArg arg= , Error **errp) if (!hook) { return; } - if (access(hook, X_OK) !=3D 0) { - error_setg_errno(errp, errno, "can't access fsfreeze hook '%s'", h= ook); - return; - } =20 - slog("executing fsfreeze hook with arg '%s'", arg_str); - pid =3D fork(); - if (pid =3D=3D 0) { - setsid(); - reopen_fd_to_null(0); - reopen_fd_to_null(1); - reopen_fd_to_null(2); - - execl(hook, hook, arg_str, NULL); - _exit(EXIT_FAILURE); - } else if (pid < 0) { - error_setg_errno(errp, errno, "failed to create child process"); - return; - } + const char *argv[] =3D {hook, arg_str, NULL}; =20 - ga_wait_child(pid, &status, &local_err); + slog("executing fsfreeze hook with arg '%s'", arg_str); + ga_run_command(argv, NULL, "execute fsfreeze hook", &local_err); if (local_err) { error_propagate(errp, local_err); return; } - - if (!WIFEXITED(status)) { - error_setg(errp, "fsfreeze hook has terminated abnormally"); - return; - } - - status =3D WEXITSTATUS(status); - if (status) { - error_setg(errp, "fsfreeze hook has failed with status %d", status= ); - return; - } } =20 /* --=20 2.39.3 From nobody Wed May 15 06:48:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1710951451; cv=none; d=zohomail.com; s=zohoarc; b=AbEVTILj52hU7GGXUSMFmCje5xHmo7NBAXwSJbqCBP2SGPlSVCoN+NdCChomToa9cwgKiTfHen/vDIHu1e0BlBR6jsQ0YZwiAbIQjWJo2E9mWHpD0Pw1Y9RtpER+h0M12TL2Wo8zDlSBn4sdJpo9Ci6ls6Rk1EMkFGjOdpOWfTk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710951451; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=dPDq2E1a5t3XOvJE0MnFN0/zcRmXvO+hIToGf+t3lWI=; b=BxC+e80MIUalitHchH2h8Y9lyIQR5wQoNnxPVmFyXhgPehUtWrX8Td5xnDeJx862VrVU3aD1CAsO+8Zlo0oSzrceUiZ07IQPIISt8FRO+QsLX34GCf/BQimGCuJo/jHfYc393dRdP1BCPkDYoo93W7gIy6Ipmnt5d0Qm5TjHXzo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1710951451045966.8249194395423; Wed, 20 Mar 2024 09:17:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rmycs-0007aE-Ck; Wed, 20 Mar 2024 12:17:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rmycc-0007TE-Ef for qemu-devel@nongnu.org; Wed, 20 Mar 2024 12:16:59 -0400 Received: from relay.virtuozzo.com ([130.117.225.111]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rmyca-0003sl-FL for qemu-devel@nongnu.org; Wed, 20 Mar 2024 12:16:58 -0400 Received: from [130.117.225.1] (helo=dev005.ch-qa.vzint.dev) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1rmyaM-006TNN-2R; Wed, 20 Mar 2024 17:16:38 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=Content-Type:MIME-Version:Message-Id:Date:Subject :From; bh=dPDq2E1a5t3XOvJE0MnFN0/zcRmXvO+hIToGf+t3lWI=; b=lr8sSaRGV+4pb/p4N4I 2sCsYZF+AcobbJA9SbZvZ1xwGY26NxymFHU7Yox68qHw+HOsba3sAHnA6Obbtm3JT4K2W1HHrELfc JqITv6ZWXQIoOLzqM8xlj3paq3Lq6TI9OGAQ52HoQn3XiCECl7MKjx/3UoVPMrId1Hw6dTQmS0J/B r0U5qQo51kyBEoe8IeICl+BwO8jIs363FQUengmv3rd/DfvYbWS1e1jVL158Ow4kmBrcRjlcZiY56 wk0v4pk0FDYjKjtHc+NOOgYehb7uSi5yxBGz3gVnkAtdFZae+w/k0SKvv61A1l44RUdRog86dUCt7 ar1HplfhfQdr3Mw==; From: Andrey Drobyshev 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 Message-Id: <20240320161648.158226-7-andrey.drobyshev@virtuozzo.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240320161648.158226-1-andrey.drobyshev@virtuozzo.com> References: <20240320161648.158226-1-andrey.drobyshev@virtuozzo.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=130.117.225.111; envelope-from=andrey.drobyshev@virtuozzo.com; helo=relay.virtuozzo.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @virtuozzo.com) X-ZM-MESSAGEID: 1710951451904100001 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=C3=A9 Signed-off-by: Andrey Drobyshev Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Konstantin Kostiuk --- 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(SuspendMo= de mode, Error **errp) =20 static void linux_sys_state_suspend(SuspendMode mode, Error **errp) { - Error *local_err =3D NULL; + g_autoptr(GError) local_gerr =3D NULL; const char *sysfile_strs[3] =3D {"disk", "mem", NULL}; const char *sysfile_str =3D sysfile_strs[mode]; - pid_t pid; - int status; =20 if (!sysfile_str) { error_setg(errp, "unknown guest suspend mode"); return; } =20 - pid =3D fork(); - if (!pid) { - /* child */ - int fd; - - setsid(); - reopen_fd_to_null(0); - reopen_fd_to_null(1); - reopen_fd_to_null(2); - - fd =3D 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"); - } - } =20 static void guest_suspend(SuspendMode mode, Error **errp) --=20 2.39.3 From nobody Wed May 15 06:48:09 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1710951486; cv=none; d=zohomail.com; s=zohoarc; b=j2XoGxG4z1HCrT81Ee0h94qheiPVBg5gc5HMaOJgnqbsn/F2/GQSqh4w45lfr5GKgF5MFkQw0pqrgx/yVPfHgRehbJnDxDJyZ1TXfCrQBF+N+J9wtol7DvdTStaACmJhLSeekV8royQp5HYUTEbZ2dEC6VFMBHsyzFFQEdFCl4s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710951486; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Qql1rspuc0/h/RwK0YXD5Wmgrn8PkgxM1TGmLutTWRc=; b=nPPlSYZB/AtGZ0iov43+BajBGqXzyId06TR2OWkXqx+X2iygl6ohkHgLeNgo4l74pM4xSdGiZTNOt/d8WJI6Qx3V71l0KeXBx08asR4ZlFF9pEmXR3w/oW+hKJdyBCVyJdQZYgmXqXkJqcr+EF+7S7YRZXZlZc8iUH9P9AHcYRQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1710951486777937.059113084979; Wed, 20 Mar 2024 09:18:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rmyd7-0007ja-Kw; Wed, 20 Mar 2024 12:17:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rmyce-0007Tg-2D for qemu-devel@nongnu.org; Wed, 20 Mar 2024 12:17:01 -0400 Received: from relay.virtuozzo.com ([130.117.225.111]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rmyca-0003sp-He for qemu-devel@nongnu.org; Wed, 20 Mar 2024 12:16:59 -0400 Received: from [130.117.225.1] (helo=dev005.ch-qa.vzint.dev) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1rmyaM-006TNN-2d; Wed, 20 Mar 2024 17:16:38 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=Content-Type:MIME-Version:Message-Id:Date:Subject :From; bh=Qql1rspuc0/h/RwK0YXD5Wmgrn8PkgxM1TGmLutTWRc=; b=aWHoRJGI4jxnOLuqAm4 0wXvSNk6XQiP44iY4JDF2raPUfpWKGXNKHjiE1hRofB77V9OcjSXcrAGSOikuPIytMcyzZxJK6aK/ CtM64vSvPYn//9NlZpQr1TWsRGBEy4RhWnpSkxTpfK/DejMguEg4qCdN/ORtZOPrKFe6so3lceg6B /GgjD+UfBGiapvcmx5H4zDpUNGazjxmQ5As1PHbH5Rgl1brG4/suDJOdkbgjBgRr0j2nrzpLTNhL0 6sYv+0s8b96SW5BZKDjL9QEph5TcRoOUkRSILssXoXgOkdUo8YG9+sNJAntbprJAbl/vLIYB2FQ7O XsuDO/76jXySlVQ==; From: Andrey Drobyshev 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 7/7] qga/commands-posix: qmp_guest_set_user_password: use ga_run_command helper Date: Wed, 20 Mar 2024 18:16:48 +0200 Message-Id: <20240320161648.158226-8-andrey.drobyshev@virtuozzo.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240320161648.158226-1-andrey.drobyshev@virtuozzo.com> References: <20240320161648.158226-1-andrey.drobyshev@virtuozzo.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=130.117.225.111; envelope-from=andrey.drobyshev@virtuozzo.com; helo=relay.virtuozzo.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @virtuozzo.com) X-ZM-MESSAGEID: 1710951488053100003 There's no need to check for the existence of the "chpasswd", "pw" executables, as the exec() call will do that for us. Signed-off-by: Andrey Drobyshev Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Konstantin Kostiuk --- qga/commands-posix.c | 96 ++++++-------------------------------------- 1 file changed, 13 insertions(+), 83 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 9910957ff5..7a065c4085 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -2151,14 +2151,8 @@ void qmp_guest_set_user_password(const char *usernam= e, Error **errp) { Error *local_err =3D NULL; - char *passwd_path =3D NULL; - pid_t pid; - int status; - int datafd[2] =3D { -1, -1 }; - char *rawpasswddata =3D NULL; + g_autofree char *rawpasswddata =3D NULL; size_t rawpasswdlen; - char *chpasswddata =3D NULL; - size_t chpasswdlen; =20 rawpasswddata =3D (char *)qbase64_decode(password, -1, &rawpasswdlen, = errp); if (!rawpasswddata) { @@ -2169,95 +2163,31 @@ void qmp_guest_set_user_password(const char *userna= me, =20 if (strchr(rawpasswddata, '\n')) { error_setg(errp, "forbidden characters in raw password"); - goto out; + return; } =20 if (strchr(username, '\n') || strchr(username, ':')) { error_setg(errp, "forbidden characters in username"); - goto out; + return; } =20 #ifdef __FreeBSD__ - chpasswddata =3D g_strdup(rawpasswddata); - passwd_path =3D g_find_program_in_path("pw"); + g_autofree char *chpasswdata =3D g_strdup(rawpasswddata); + const char *crypt_flag =3D crypted ? "-H" : "-h"; + const char *argv[] =3D {"pw", "usermod", "-n", username, + crypt_flag, "0", NULL}; #else - chpasswddata =3D g_strdup_printf("%s:%s\n", username, rawpasswddata); - passwd_path =3D g_find_program_in_path("chpasswd"); + g_autofree char *chpasswddata =3D g_strdup_printf("%s:%s\n", username, + rawpasswddata); + const char *crypt_flag =3D crypted ? "-e" : NULL; + const char *argv[] =3D {"chpasswd", crypt_flag, NULL}; #endif =20 - chpasswdlen =3D strlen(chpasswddata); - - if (!passwd_path) { - error_setg(errp, "cannot find 'passwd' program in PATH"); - goto out; - } - - if (!g_unix_open_pipe(datafd, FD_CLOEXEC, NULL)) { - error_setg(errp, "cannot create pipe FDs"); - goto out; - } - - pid =3D fork(); - if (pid =3D=3D 0) { - close(datafd[1]); - /* child */ - setsid(); - dup2(datafd[0], 0); - reopen_fd_to_null(1); - reopen_fd_to_null(2); - -#ifdef __FreeBSD__ - const char *h_arg; - h_arg =3D (crypted) ? "-H" : "-h"; - execl(passwd_path, "pw", "usermod", "-n", username, h_arg, "0", NU= LL); -#else - if (crypted) { - execl(passwd_path, "chpasswd", "-e", NULL); - } else { - execl(passwd_path, "chpasswd", NULL); - } -#endif - _exit(EXIT_FAILURE); - } else if (pid < 0) { - error_setg_errno(errp, errno, "failed to create child process"); - goto out; - } - close(datafd[0]); - datafd[0] =3D -1; - - if (qemu_write_full(datafd[1], chpasswddata, chpasswdlen) !=3D chpassw= dlen) { - error_setg_errno(errp, errno, "cannot write new account password"); - goto out; - } - close(datafd[1]); - datafd[1] =3D -1; - - ga_wait_child(pid, &status, &local_err); + ga_run_command(argv, chpasswddata, "set user password", &local_err); if (local_err) { error_propagate(errp, local_err); - goto out; - } - - if (!WIFEXITED(status)) { - error_setg(errp, "child process has terminated abnormally"); - goto out; - } - - if (WEXITSTATUS(status)) { - error_setg(errp, "child process has failed to set user password"); - goto out; - } - -out: - g_free(chpasswddata); - g_free(rawpasswddata); - g_free(passwd_path); - if (datafd[0] !=3D -1) { - close(datafd[0]); - } - if (datafd[1] !=3D -1) { - close(datafd[1]); + return; } } #else /* __linux__ || __FreeBSD__ */ --=20 2.39.3