From nobody Tue Nov 26 06:49:46 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=1709314243; cv=none; d=zohomail.com; s=zohoarc; b=Yzj61y/YUZnpCvWCorAZE+L51TbwNJ6NlCAXMrY4EGjzTm/AtTOM6e/uK6at2WTCra/7pbw0M3TKCzXIPcRREO75xySGNyYDOEUW51on0fkRBNna3puh9Fts1+lNIurLsEEFnoyawf99/hRAZlSi+fo2YgtmLKDrJiizIeQ8jGk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709314243; 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=z+2upVLm5CJLKbcQAz4YdhJ9C1wGGiDlSEOSE/EyGsY=; b=KOSumHM+xkwVSVTSH+VsuLiFjXWqNfuyCvJhznPFqDX6kk89YKvko6n3TWx3HiZ9m7zt0RGb31/Qo1YtwzQoR8XsuaTEdw52zISd4rDcGTphS7rkMivcP/+nlxiUOUGCgIFy4fS4EhKweiWZUWtHzpDQRNSLDMpWz1or9bSCLwU= 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 1709314243557622.2729702964426; Fri, 1 Mar 2024 09:30:43 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rg6h3-0003nv-TO; Fri, 01 Mar 2024 12:29:09 -0500 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 1rg6h2-0003me-0Y for qemu-devel@nongnu.org; Fri, 01 Mar 2024 12:29:08 -0500 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 1rg6gx-0005d1-VX for qemu-devel@nongnu.org; Fri, 01 Mar 2024 12:29:07 -0500 Received: from [130.117.225.1] (helo=dev005.ch-qa.vzint.dev) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1rg6fM-0022sZ-0b; Fri, 01 Mar 2024 18:28:57 +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=z+2upVLm5CJLKbcQAz4YdhJ9C1wGGiDlSEOSE/EyGsY=; b=WEtGjaprVOM9 3oi6XZ7u1Xm+AnZ++p2+HndqRrEsznR0fYwa5CNE0TOFZlJNSA4xbdzOBIqfAyqagL7SnkoR3/woy iZXnGaRzGB5Odi0krFHqF4QPIgdtgrtEOra4qHxeKEggipiNLTiFRGZd8p/PNndwlyq65nxy7AX2V 0OVco3OI1KHeVZRn87NzXG/ugWupSnn+30tnOuqkFJE2a1U6MHs3gqoWss7a7G9pBpMuUqYQym7bf pQcxwA1m4nidt8MEUYjBwD14zaIQ/XVOhrTprQOhA6H5JlqGCKYvpZ2nUmmoYyySu98cwQlq/fk8A DTyoBUiCTHzGuCkfXh90ew==; From: Andrey Drobyshev To: qemu-devel@nongnu.org Cc: michael.roth@amd.com, kkostiuk@redhat.com, marcandre.lureau@redhat.com, philmd@linaro.org, andrey.drobyshev@virtuozzo.com, den@virtuozzo.com Subject: [PATCH v2 1/7] qga: guest-get-fsinfo: add optional 'total-bytes-root' field Date: Fri, 1 Mar 2024 19:28:52 +0200 Message-Id: <20240301172858.665135-2-andrey.drobyshev@virtuozzo.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240301172858.665135-1-andrey.drobyshev@virtuozzo.com> References: <20240301172858.665135-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, 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: 1709314244690100003 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-root' to GuestFilesystemInfo struct, which'd only be reported on POSIX and represent f_blocks value as returned by statvfs(3). While here, let's document better where those values come from in both POSIX and Windows. Signed-off-by: Andrey Drobyshev Reviewed-by: Konstantin Kostiuk Tested-by: Dehan Meng --- qga/commands-posix.c | 2 ++ qga/commands-win32.c | 1 + qga/qapi-schema.json | 12 +++++++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 26008db497..8207c4c47e 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_root =3D buf.f_blocks * fr_size; =20 fs->has_total_bytes =3D true; + fs->has_total_bytes_root =3D true; fs->has_used_bytes =3D true; } =20 diff --git a/qga/commands-win32.c b/qga/commands-win32.c index a1015757d8..9e820aad8d 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_root =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 b8efe31897..093a5ab602 100644 --- a/qga/qapi-schema.json +++ b/qga/qapi-schema.json @@ -1031,8 +1031,18 @@ # @type: file system type string # # @used-bytes: file system used bytes (since 3.0) +# * POSIX: (f_blocks - f_bfree) * f_frsize, as returned by statvfs(3) +# * Windows: (TotalNumberOfBytes - TotalNumberOfFreeBytes), as returned +# by GetDiskFreeSpaceEx() # # @total-bytes: non-root file system total bytes (since 3.0) +# * POSIX: (f_blocks - f_bfree + f_bavail) * f_frsize, as returned by +# statvfs(3) +# * Windows: TotalNumberOfBytes, as returned by GetDiskFreeSpaceEx() +# +# @total-bytes-root: total file system size in bytes (as visible for a +# priviledged user) (since 8.3) +# * POSIX only: (f_blocks * f_frsize), returned by statvfs(3) # # @disk: an array of disk hardware information that the volume lies # on, which may be empty if the disk type is not supported @@ -1042,7 +1052,7 @@ { 'struct': 'GuestFilesystemInfo', 'data': {'name': 'str', 'mountpoint': 'str', 'type': 'str', '*used-bytes': 'uint64', '*total-bytes': 'uint64', - 'disk': ['GuestDiskAddress']} } + '*total-bytes-root': 'uint64', 'disk': ['GuestDiskAddress']} } =20 ## # @guest-get-fsinfo: --=20 2.39.3 From nobody Tue Nov 26 06:49:46 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=1709314238; cv=none; d=zohomail.com; s=zohoarc; b=gFznwUzAEmSZVO9S2kumzerWk9MaPgY/xKcAJ+MPY8bvUvyWecOgWu8gN7IaMHqV2XsKGofwB81j5S9QqU6ooPIiC2MEyDTgcVWzBZWq1PBO6fmIwUj3wpcAS3cTWV78nq22tpVZxOH5rujZv0XwDhXmjrb6y6oiLhyV70WIw6s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709314238; 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=GsygPxWNyTKxxDZM8oS5g4+qWI+r/5+qm83ovsg8YcM=; b=nGRP1xt9ZHiWfW4pK4Le6zoMYSENNZK0hLMvwVwIu+oWzIG6w/A1rdmEVWZMWj8/vYBXd5n9MNQvMSH5sMPyr8nCEIdVLw5dO/p5NdiVtMQshnluOdOOn01B4xdRcMTaB+Jr9XMivNqHMyOK+UiAsiEhI9110nXrVXqFGuhtFr0= 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 1709314238435300.453712371698; Fri, 1 Mar 2024 09:30:38 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rg6h3-0003o4-VE; Fri, 01 Mar 2024 12:29:09 -0500 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 1rg6h1-0003mX-Tp for qemu-devel@nongnu.org; Fri, 01 Mar 2024 12:29:07 -0500 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 1rg6gx-0005d0-VY for qemu-devel@nongnu.org; Fri, 01 Mar 2024 12:29:07 -0500 Received: from [130.117.225.1] (helo=dev005.ch-qa.vzint.dev) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1rg6fM-0022sZ-0m; Fri, 01 Mar 2024 18:28:57 +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=GsygPxWNyTKxxDZM8oS5g4+qWI+r/5+qm83ovsg8YcM=; b=qZeClQaVu4KL /XYUTeYpkEmQOhqbNwikPzp0shBV1SVLeSVjebVK5J1TDycMix3esvJDPZ4RYsKo2FTFlKtYNI8Uf OB9TOpDSJoVVxFXaka5sUHqK1dyRmBEymLAqC7NZUUVGqHG483r96jmOxf/ccYElQWWWPVlDngiO3 WWt6TCdg+L9yMy4AFDfQftC1Cn0bGMGzumfcPHSceM2X7gvMX+yN1rm29+B5nXO4r8vFTtWT9lb11 r1RMKHClbi5WpC50IGnnDM8v3+Qd5TKQHkPa6CpkRH6CSBuNYvToDHdVSUykpYjJ6/ATZiZkZQvfG oUUPFZlhg/2X3CFmK9pR6g==; From: Andrey Drobyshev To: qemu-devel@nongnu.org Cc: michael.roth@amd.com, kkostiuk@redhat.com, marcandre.lureau@redhat.com, philmd@linaro.org, andrey.drobyshev@virtuozzo.com, den@virtuozzo.com Subject: [PATCH v2 2/7] qga: introduce ga_run_command() helper for guest cmd execution Date: Fri, 1 Mar 2024 19:28:53 +0200 Message-Id: <20240301172858.665135-3-andrey.drobyshev@virtuozzo.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240301172858.665135-1-andrey.drobyshev@virtuozzo.com> References: <20240301172858.665135-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, 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: 1709314238719100001 Content-Type: text/plain; charset="utf-8" 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: Konstantin Kostiuk Tested-by: Dehan Meng --- qga/commands-posix.c | 140 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 8207c4c47e..781498418f 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -76,6 +76,146 @@ static void ga_wait_child(pid_t pid, int *status, Error= **errp) g_assert(rpid =3D=3D pid); } =20 +static void ga_pipe_read_str(int fd[2], char **str, size_t *len) +{ + ssize_t n; + 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 { + break; + } + } + *str =3D g_realloc(*str, *len + n); + memcpy(*str + *len, buf, n); + *len +=3D n; + } + close(fd[0]); + fd[0] =3D -1; +} + +/* + * 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; + size_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; + } + + ga_pipe_read_str(outfd, &str, &len); + + 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 Tue Nov 26 06:49:46 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=1709314203; cv=none; d=zohomail.com; s=zohoarc; b=EUPyXuYp4EDMe/hvz0r42LW8wWigDeL+O7i7ieK4UfgLeja8VRR+gIGFiJFOEI1EK3jBeuY5AhBYHJEDm6pG9/HtWDfBaLgeGLp3akefVfzm4n62Tzq5aRI7QXOZdpA+kp99KdyKfbfdlOFTTSaFwlMLJ3AL8OO4m7Z58Env0k0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709314203; 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=FgvpgkvZbPaUxVLeqEy30dvsqfYQF42BbnXb+x7RtN4=; b=ZJ3MPJSzO3mgsroYsJzX8faAN4XhKdWQlDqolhkDNysnrGYnS/03qrS58HEch1f1ITUVsFHbP2HfRBUjOMu6cPXaUOdX24koRfnSwNzFu3kndb5qM/HI1FxJcTtbj78PEM4btC3koo1n2QXwDMi87F42B2RYWlHsKpuPRCpAAvE= 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 1709314203232380.01562229574006; Fri, 1 Mar 2024 09:30:03 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rg6h5-0003p7-U9; Fri, 01 Mar 2024 12:29:11 -0500 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 1rg6h1-0003mV-Qm for qemu-devel@nongnu.org; Fri, 01 Mar 2024 12:29:07 -0500 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 1rg6gx-0005d4-Vb for qemu-devel@nongnu.org; Fri, 01 Mar 2024 12:29:07 -0500 Received: from [130.117.225.1] (helo=dev005.ch-qa.vzint.dev) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1rg6fM-0022sZ-0x; Fri, 01 Mar 2024 18:28:57 +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=FgvpgkvZbPaUxVLeqEy30dvsqfYQF42BbnXb+x7RtN4=; b=FUUJSPzQE4x5 8cezk+wrQHFHabBhiDJ6709BS4y8cu+IXIIWylwvc/xF8rI+rsKDAvlQQHNV1LO4/jH4pa1R0uM/m U46RlZqiNXVkuQOqofcK8VqcpWQJHFkH6y9PIZXheFp+uTd2iKRxr0ITPuDhCmXT+59EdIn0wnL+7 vSMLOu/5IU3nuXzJU9gDB9nTn8ApKFYCt9h5kM234V4Sqwh9mpJ3e6zgTH9kt/qNkfJMpBlu4HF7I pbyQX98P1SqX5ke4R+RJS6VzpsqhQyuIAGo13fbwXIIux+HDa2LZrmWsNiEf66xj3uoIWBwFPq0wA bwAdccmZgNTksZvqmJ/oLw==; From: Andrey Drobyshev To: qemu-devel@nongnu.org Cc: michael.roth@amd.com, kkostiuk@redhat.com, marcandre.lureau@redhat.com, philmd@linaro.org, andrey.drobyshev@virtuozzo.com, den@virtuozzo.com Subject: [PATCH v2 3/7] qga/commands-posix: qmp_guest_shutdown: use ga_run_command helper Date: Fri, 1 Mar 2024 19:28:54 +0200 Message-Id: <20240301172858.665135-4-andrey.drobyshev@virtuozzo.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240301172858.665135-1-andrey.drobyshev@virtuozzo.com> References: <20240301172858.665135-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, 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: 1709314204729100003 Content-Type: text/plain; charset="utf-8" Also remove the G_GNUC_UNUSED attribute added in the previous commit from the helper. Signed-off-by: Andrey Drobyshev Reviewed-by: Konstantin Kostiuk Tested-by: Dehan Meng --- 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 781498418f..003054891f 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -103,7 +103,6 @@ static void ga_pipe_read_str(int fd[2], char **str, siz= e_t *len) * 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) { @@ -220,8 +219,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"; @@ -250,46 +247,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 Tue Nov 26 06:49:46 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=1709314249; cv=none; d=zohomail.com; s=zohoarc; b=N6lOOBIYnFxUfgwloYh/X4fn8ApJleOCXM8E3CpgFMhC+sVNhxYIaQEtE43blnBe9dztZjTYUe6nn0AarcGUldMlQ7ZLe9jOixnBHesAgt01+0p1+M4QcVbWZv/AOvycUzFIncM5xGuVGZ8ojshNrAEaQHH09B1DjVXSs7kJPvA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709314249; 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=rih3hdm+11U4Ol1ngr62njSzb6IySI6jIVRER8pZI5o=; b=fxhVFTEOWUlzBvZGEhdZgY4Se/S5+0Gpel7llseI1wopIxvbyDFCOws2ALaBqT+RpPGBf9Us5p2AqrSGLHOnVUosOj6sdm02j7wq55jEzQcSixPdHpdY+7a45iVNLt4H6juI48W13D1lSHb91ELCeN4f5apgagXzDVqYU1XYOPs= 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 1709314249834878.9546227770969; Fri, 1 Mar 2024 09:30:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rg6h3-0003nn-OZ; Fri, 01 Mar 2024 12:29:09 -0500 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 1rg6h2-0003nD-Ky for qemu-devel@nongnu.org; Fri, 01 Mar 2024 12:29:08 -0500 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 1rg6gx-0005cy-V9 for qemu-devel@nongnu.org; Fri, 01 Mar 2024 12:29:08 -0500 Received: from [130.117.225.1] (helo=dev005.ch-qa.vzint.dev) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1rg6fM-0022sZ-18; Fri, 01 Mar 2024 18:28:57 +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=rih3hdm+11U4Ol1ngr62njSzb6IySI6jIVRER8pZI5o=; b=qaHvazn+jvab l2Usrb+l6izivZLH6nwKa8khKQqfpC7d86ygQ6ZGNXsZkfe5aLGc1maq091CR0IMPNiiteQVXJHqY s2yzsTsC5mAu7rABaHR1xpS/v1iPrewDcEotfckKAlPyJvA0ncV9TFp5Azd2OEG/J/pGfXh20CbGV LBnBMIsgChSca1P1QJ0zmr3QlciD1DAYs/45xJd85LNi8c99hWNxQEl0jS/M058aoiGheS6A3vNFI pHvmM0Gp7/9Gcri8+JJh599tkuXdr7QbjgvHmGaOr0DctvjjJbk/jqgatdTGLa0WTATV4OqjP80as QPDmcWOiNjSoQyUClKJzUQ==; From: Andrey Drobyshev To: qemu-devel@nongnu.org Cc: michael.roth@amd.com, kkostiuk@redhat.com, marcandre.lureau@redhat.com, philmd@linaro.org, andrey.drobyshev@virtuozzo.com, den@virtuozzo.com Subject: [PATCH v2 4/7] qga/commands-posix: qmp_guest_set_time: use ga_run_command helper Date: Fri, 1 Mar 2024 19:28:55 +0200 Message-Id: <20240301172858.665135-5-andrey.drobyshev@virtuozzo.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240301172858.665135-1-andrey.drobyshev@virtuozzo.com> References: <20240301172858.665135-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: 1709314250762100003 Content-Type: text/plain; charset="utf-8" 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: Konstantin Kostiuk Tested-by: Dehan Meng --- 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 003054891f..e44203a273 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -269,21 +269,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) { @@ -314,37 +302,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 Tue Nov 26 06:49:46 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=1709314240; cv=none; d=zohomail.com; s=zohoarc; b=C5tLNtOtyGrd4zwyGov2xd2KdlWIxd/oUaMm3zGRRo5+cogQrsORWL32N5CKuY8WYFyHrOpVvS/Ifcc9OFoZvDclqaP4PNNg+hwtBPYLIv5/7vYPmnJA/qUvpBSO90JoqW94pUi1aI1Y2+4IvbI06iuVKs+2QUS0d6VqPlz3Ysk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709314240; 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=2f25Xvl+7dbrNkTuSEg5zBbFIGFCzRZwAf4Oxr9ZJTI=; b=n00g+bH5ZZSuSREYSlovJh46xXlTDNfCkLXX5v1yrWNfYYUvZGY8JGmtitTtz1neCrYkKUtS6jmmET+HL1ITc5t9XDxZpE+Im9PUaIHry9yLb4c5xrGEGYP3l9OjEpQx8JMeQ4KkjrhODkCj215vDGoVd3qf+bd/cpuKG4eFIZI= 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 1709314240393421.67326937101177; Fri, 1 Mar 2024 09:30:40 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rg6h3-0003nV-2q; Fri, 01 Mar 2024 12:29:09 -0500 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 1rg6h1-0003mW-S2 for qemu-devel@nongnu.org; Fri, 01 Mar 2024 12:29:07 -0500 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 1rg6gx-0005d5-V8 for qemu-devel@nongnu.org; Fri, 01 Mar 2024 12:29:07 -0500 Received: from [130.117.225.1] (helo=dev005.ch-qa.vzint.dev) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1rg6fM-0022sZ-1J; Fri, 01 Mar 2024 18:28:57 +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=2f25Xvl+7dbrNkTuSEg5zBbFIGFCzRZwAf4Oxr9ZJTI=; b=ovAhIKoyg+dk bhAE+6Bb77yCDhO1oYviek+BqPMWw72Ztk501L2ZHLfX1Z5EGIsihNXTeq177aaZbKhXdRg8GnIfP nNSnMXrFVkTIHySD48e9Fg/XOCh0Z+DcgdHHvg1HrvXV5UW1QLu8QzTmasHXox7rwsS9Skj9YtmKR AbElJ81K+w8qASPeG0oYb/ze5NuBlFkWITfrmQBoXbEIws5nvoot9QPz3AjOSGmdg0kP7EdApnuzT wkSb6/Mr2Tek+Mch2R67WFP+CVGo8eo81Jt46GMP/Ghi1aciijXC0Iy2pKJx/vWdjUJT3cWIT+p0G aFarcIPHsEbdACeQBDDVFg==; From: Andrey Drobyshev To: qemu-devel@nongnu.org Cc: michael.roth@amd.com, kkostiuk@redhat.com, marcandre.lureau@redhat.com, philmd@linaro.org, andrey.drobyshev@virtuozzo.com, den@virtuozzo.com Subject: [PATCH v2 5/7] qga/commands-posix: execute_fsfreeze_hook: use ga_run_command helper Date: Fri, 1 Mar 2024 19:28:56 +0200 Message-Id: <20240301172858.665135-6-andrey.drobyshev@virtuozzo.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240301172858.665135-1-andrey.drobyshev@virtuozzo.com> References: <20240301172858.665135-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, 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: 1709314240665100005 Content-Type: text/plain; charset="utf-8" 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: Konstantin Kostiuk Tested-by: Dehan Meng --- 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 e44203a273..dd2a7ad2e6 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -726,8 +726,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; @@ -736,42 +734,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 Tue Nov 26 06:49:46 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=1709314198; cv=none; d=zohomail.com; s=zohoarc; b=O0ou5Ju9PraGJEDj/4nwL6XCce8awJs/5nhawa9r7a3O1CzmGlP6kzoOqxqCmJKT1yjpmpxO+Xg2CPntIV3dNU5543e056iuXmHo9OK0fC8bWLuumV0nQPih8NNPDSQccR5QCazPrV+wi8/kmoAGwlmCqb1iW++dQN7WaGSIndg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709314198; 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=B+XurtnpYoJZP5kVIIxzoSwbJmwbE81ygmsZxH5LmXM=; b=NracxBCgUOd0KZVWiaLoL1gAQYdiY98KIx+W9MrtVgjRsSn8oz1BRj3KTEpV2HMUowsxb+cmp7r7sgbHo3IZLJuyW0ix0EByB4UgljpqM3OVJLJ30FyFlzgpEiw0x+K0rEs9gmSw1fdSAaDSeCInNgI2hWvVomnamXpH3TRzU6A= 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 1709314198214155.34410987018623; Fri, 1 Mar 2024 09:29:58 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rg6h2-0003n1-Av; Fri, 01 Mar 2024 12:29:08 -0500 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 1rg6h0-0003mL-Fe for qemu-devel@nongnu.org; Fri, 01 Mar 2024 12:29:06 -0500 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 1rg6gx-0005d3-Ve for qemu-devel@nongnu.org; Fri, 01 Mar 2024 12:29:06 -0500 Received: from [130.117.225.1] (helo=dev005.ch-qa.vzint.dev) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1rg6fM-0022sZ-1U; Fri, 01 Mar 2024 18:28:57 +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=B+XurtnpYoJZP5kVIIxzoSwbJmwbE81ygmsZxH5LmXM=; b=HgMHYh9tec3s unHYZogQn7vprxNDBv7Lda4bGPTU0l5JKhVGD4QIRGZeFUrtx9A9hXN/xyZyx/3VZ3Gnlh4dhUZn0 SNAgRV/lWzU7ayz5BC5QNCr1iQ1qTIV4kywmbFhBEDH/FLN2Ss2/8Z1DdzSKfbH9eqK3C8DQpwsGl LxASjS4U1CH8RGBHASbsiT2uBKmhmpHcBibQhdKsds+YuwO7fs3/9FQOv13sn67ShRPIqzrps+QBC /C8IP4txM49zhwYGtwyqtpYZ5kqVTVt45QQNA+ZltfNgct5RL0Q+x/1+Now/9MXBRM//+3Yv6jDte qbkiwAQcYAYuZWpH0kC1GA==; From: Andrey Drobyshev To: qemu-devel@nongnu.org Cc: michael.roth@amd.com, kkostiuk@redhat.com, marcandre.lureau@redhat.com, philmd@linaro.org, andrey.drobyshev@virtuozzo.com, den@virtuozzo.com Subject: [PATCH v2 6/7] qga/commands-posix: use ga_run_command helper when suspending via sysfs Date: Fri, 1 Mar 2024 19:28:57 +0200 Message-Id: <20240301172858.665135-7-andrey.drobyshev@virtuozzo.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240301172858.665135-1-andrey.drobyshev@virtuozzo.com> References: <20240301172858.665135-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, 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: 1709314198528100001 Content-Type: text/plain; charset="utf-8" We replace the direct call to open() with a "sh -c 'echo ...'" call, so that it becomes an executable command. Signed-off-by: Andrey Drobyshev Reviewed-by: Konstantin Kostiuk Tested-by: Dehan Meng --- qga/commands-posix.c | 36 ++++-------------------------------- 1 file changed, 4 insertions(+), 32 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index dd2a7ad2e6..f3f4a05e2d 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -1921,49 +1921,21 @@ static void linux_sys_state_suspend(SuspendMode mod= e, Error **errp) Error *local_err =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; - } + g_autofree char *echo_cmd =3D g_strdup_printf( + "echo %s > " LINUX_SYS_STATE_FILE, sysfile_str); + const char *argv[] =3D {"sh", "-c", echo_cmd, NULL}; =20 - ga_wait_child(pid, &status, &local_err); + ga_run_command(argv, NULL, "suspend", &local_err); if (local_err) { error_propagate(errp, local_err); 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 Tue Nov 26 06:49:46 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=1709314220; cv=none; d=zohomail.com; s=zohoarc; b=cN/Qh4JScTeihEKdUnjo/m3+43HazJlxcW3s7rEpo/1txNkarc4Vkrio1x6TEKmVE5sh+GJOaU4TYoWEcmzuDWlBO5EfB6s/n70btHdA03AjlXiwaDKuteqO1cHfwDkXvcw/ObI+9msjG6XkUJTzp/cODom54fwnHKDmARAqd8w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709314220; 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=TCjNFTmDj5adwMm8mWkF67k/DsXhNQZYrvO3a6rbjt8=; b=kVWvd0Mbu269dUseWBtnfOL9zNy6cwqTeF8TlLB1PWsUc2I1K9uG7LNn7ufFFahexiZtC7qbLCHLXQSn6wv4baogbCunW7QxZOeYeplwdfyFRKofEZy6w3tbMXP4C1Oasso1tUQVN0HarnSLoex12FjO8KBaC/ChPQc7PjhfQcY= 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 1709314220219148.04146678386007; Fri, 1 Mar 2024 09:30:20 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rg6h6-0003pN-Ka; Fri, 01 Mar 2024 12:29:12 -0500 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 1rg6h3-0003nb-8P for qemu-devel@nongnu.org; Fri, 01 Mar 2024 12:29:09 -0500 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 1rg6gx-0005d2-Vb for qemu-devel@nongnu.org; Fri, 01 Mar 2024 12:29:08 -0500 Received: from [130.117.225.1] (helo=dev005.ch-qa.vzint.dev) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1rg6fM-0022sZ-1X; Fri, 01 Mar 2024 18:28:57 +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=TCjNFTmDj5adwMm8mWkF67k/DsXhNQZYrvO3a6rbjt8=; b=s9G+joeXG388 rOyPVvjEvjBmzFXLv3zJNu5/RNebrLi9R+PR7JJ/n1FbmHmdtL17u2ppGVn8+MxE+BfQpfQ149zY6 Iz802ZkYn/d6S6KwAuzKNch9SVYoGVOcz71IEW0orJVy5l4Bmpe8ryXwpgruaJ3y82O47g2fX6jKE /kBLoInB+Trq3tgm1jDPBAj7ETdrAMz4wDI/LjbLfB/SVCJjn8dZP88O5Td6JGiBro5Ij0RC+dSkN 9siavpHCs1iWf+zk8noMMhGOXPjMqlG3LB0mCPpfeBT7HqDJih8lSXxlLPuStdzEfwnLSdMmafFEX hJAh+0JKdTiLffqmSnj4jQ==; From: Andrey Drobyshev To: qemu-devel@nongnu.org Cc: michael.roth@amd.com, kkostiuk@redhat.com, marcandre.lureau@redhat.com, philmd@linaro.org, andrey.drobyshev@virtuozzo.com, den@virtuozzo.com Subject: [PATCH v2 7/7] qga/commands-posix: qmp_guest_set_user_password: use ga_run_command helper Date: Fri, 1 Mar 2024 19:28:58 +0200 Message-Id: <20240301172858.665135-8-andrey.drobyshev@virtuozzo.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240301172858.665135-1-andrey.drobyshev@virtuozzo.com> References: <20240301172858.665135-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, 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: 1709314220632100001 Content-Type: text/plain; charset="utf-8" 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: Konstantin Kostiuk Tested-by: Dehan Meng --- 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 f3f4a05e2d..f2e9496b80 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -2144,14 +2144,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) { @@ -2162,95 +2156,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