From nobody Wed Nov 27 12:30:21 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; arc=pass (i=1 dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1698242573; cv=pass; d=zohomail.com; s=zohoarc; b=m8bLN5Ayo+RcoAEWYxwdtcN7cfaiQBSxG2DHHaMgZ58R2a6W0l+Yc5K5Tq0D+8KReIRrMhqoK6cF7Ei3PCBzckAZpNopm+f94Lz8B43Ew58rVohei5dr7m+a7LNTJrGhMT8J6whqL9eEoaZHiOP+vIgFZTw5qKHfFgIUOro10AM= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1698242573; 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=QiKEJZAMreISJPc0Piy0EJbV//TtR7aZLs63Xu4O4bw=; b=jzraKB7vvR5rORSZdNna21RIEb3OR6EdscoqHkyIBzylKd9juOsBYxq4D9ijKMOrZG4BaJKD1+ntBe8qHAu/miHzoHG3p9ZXzuwVsMHMSjpzd1w8CYQKsRln/v2VFH9oyabJlC+LXqH9yqQuD1u8jc7qiFP9b6MgEXP+/ZJeNBU= ARC-Authentication-Results: i=2; 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; arc=pass (i=1 dmarc=pass fromdomain=virtuozzo.com); 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 1698242573084570.7299863643674; Wed, 25 Oct 2023 07:02:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qveRm-0003y0-51; Wed, 25 Oct 2023 10:01:22 -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 1qveRk-0003xR-8K for qemu-devel@nongnu.org; Wed, 25 Oct 2023 10:01:20 -0400 Received: from mail-vi1eur04on070f.outbound.protection.outlook.com ([2a01:111:f400:fe0e::70f] helo=EUR04-VI1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qveRh-0005dH-2o for qemu-devel@nongnu.org; Wed, 25 Oct 2023 10:01:20 -0400 Received: from VI0PR08MB10743.eurprd08.prod.outlook.com (2603:10a6:800:205::19) by AS8PR08MB10363.eurprd08.prod.outlook.com (2603:10a6:20b:56b::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.31; Wed, 25 Oct 2023 14:01:09 +0000 Received: from VI0PR08MB10743.eurprd08.prod.outlook.com ([fe80::22f7:6498:de53:5371]) by VI0PR08MB10743.eurprd08.prod.outlook.com ([fe80::22f7:6498:de53:5371%4]) with mapi id 15.20.6863.043; Wed, 25 Oct 2023 14:01:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jNhall0swdBQVMZ20kij1T1dlc+FIWzpBpLcZ27pwa1m2/TNvqVLDzBw9eTwCnWoWai2gBNYYw9PzGpVx3MZx5g2mpBluZXeu805TzGVIqWNGEMzUeSRDzS7MYtwXwaWlUUt87pspLynohF/RuS8tWOrOTxFFFnuBDxZ7k97RQ3ZzDUKx4+Z5V0M63tFCkg6g0XJpoGX2plJ3PU3hb0A4DFDgUulys02vzeXXIN4Q3RFS3+lADNN5WEmAhyy5cQIhN6cLUVDkRB7vjHrGKO4XQX8NkV3Y8FualnhNNldddFEgyDuHpVdjZFZLpp3cW5p7FKEuIhIdZfXu353gTJIKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=QiKEJZAMreISJPc0Piy0EJbV//TtR7aZLs63Xu4O4bw=; b=kcPVdlPt/X5aPPyE4NoBR3Bf/qNy3aBW5TQSEaailP6Mph8VbES0hOYAm9FL7C7qkoHeGM2esY3ikZ0HkgINkp3TOvLrGKaQHgg1+DGHWeVt99/+vPnOH5zHHO+LZCBxxwWZkebeV08X13KGCl3J4ubTji/UXHzEgXPJeElqYNLZcdQxm15YbOqPctzFdz2VWSu5nVuux6bqAGNJGq/WftUqIqQSec+FaNDYOpyPF+dNGuBHxmwNQFLdgRFfhboVc1OcTPrNZo1twviHEbLamsRkC/dTiuGx+mBHjBjfMMEHmPiQ2U1OBEmUtktXApbyUIq49JJaK7XKdgLFpNsXQg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QiKEJZAMreISJPc0Piy0EJbV//TtR7aZLs63Xu4O4bw=; b=o0kQ5iUBhUAxRo1bpJpBR4gRQaHo2Q5hE4UvLd66r45Fa5lM/vXCDAg5twkKu5SN1g15C06vvs1A1qy9U6kwzu+s2aGxIZ8q2Lh9/LQJ9IfuURIIefdrqePGxOHgr98luXf6q2yAWRXtNN+mT91bP7TDfZsat8Fg+LwBe8VWKjMHgxBBOcRDcHW1rjtKubRz+DFIXqQKkHSQ9jCVKDKqq6VEr3NhbbwuJptpKIXqKCpcHx32ZfXzvxYdpb7UHQJkgBGk7maqto2+Fzp9t6MhWD6dKu/iVB7jlBtaHPMJXA0bA9G5N6GhwRqBJPwcBf+QCpvt2eB7egesINOVgiZcRw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; From: Alexander Ivanov To: qemu-devel@nongnu.org Cc: den@virtuozzo.com, michael.roth@amd.com, kkostiuk@redhat.com, marcandre.lureau@gmail.com Subject: [PATCH 1/6] qga: Add process termination functionality Date: Wed, 25 Oct 2023 16:00:53 +0200 Message-Id: <20231025140058.113376-2-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231025140058.113376-1-alexander.ivanov@virtuozzo.com> References: <20231025140058.113376-1-alexander.ivanov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: VI1PR06CA0167.eurprd06.prod.outlook.com (2603:10a6:803:c8::24) To VI0PR08MB10743.eurprd08.prod.outlook.com (2603:10a6:800:205::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI0PR08MB10743:EE_|AS8PR08MB10363:EE_ X-MS-Office365-Filtering-Correlation-Id: d315f134-865d-4f3f-734e-08dbd562d6be X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nZ93+tp9ytY7xVLrLB3Ob8IdEtl4GZ1EBGtjLev1e7Z0EtttR2lOf9WEGmRJBZRiDSyk9o7KLS111j8K/9CWRDgAUD/pgavwKz4St9JJl16nAQigkMtPy3kiam0icSUOPxBcNMM2qUyamk5+omjjMoA9d4BxbteIEIVcesuOd/caDDdeTzMW342353FGzK6nn/A8o04R2lSuhv/Uxs0pTVXG8PIBCsWm8lZJdbG0MmZmzGHOeLmjplPnW5sq6oBsv89k6Vj+PSfHREUp4H5fyoexdPiKpAyoblklZ+8sIZ/1a4GSmU4/QlQWmcZva0awIUWl3UG6bLbBhb/WFGITETF3g9kFElKT5oXUD0Yt47LSAlPL2gqMj2fJk2OBF5HB2ZMk8XkJFWrjKrmlIKGwzqnmu+pVH7v1pJnP+SreSTOr//dHYC8lMKoWsZsAtHVfWRG3/HnKqbWwBo66KpkjmCIK34+ofZIY1QitPIu6XovAomgLoj1/CE0NKyzEt3W2i+uF44bk7P6vyiDi6/kLre4qK0HvRGZQlCEGyqFWY4HDvTa3wjJ/I8Ud4qQjtI9psh/PfWVzjLvYE1EKnlGtzepwy/LYUvgSfCpOIGDrP3nAms0d2K8bLos7c2y9okzn X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI0PR08MB10743.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(396003)(136003)(346002)(39850400004)(366004)(376002)(230922051799003)(64100799003)(1800799009)(451199024)(186009)(2906002)(38100700002)(66946007)(2616005)(66476007)(316002)(66556008)(6916009)(6666004)(6506007)(478600001)(1076003)(6486002)(6512007)(52116002)(83380400001)(36756003)(44832011)(5660300002)(86362001)(4326008)(8676002)(41300700001)(8936002)(26005)(38350700005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?3EXRMjJ5eDRzqDOuRvshh1ZYsYLLFEr8zXdM9+9bMuZza4pTbr3VBtZ3YdTN?= =?us-ascii?Q?sGPfz/2D0OZNrxLiTUVAPcKHgx2CF1OitbPbCzGl/h7cEYrYeEaqixjBsHf6?= =?us-ascii?Q?ITfHimRmI72H+wyuhc78VCDBhh13EZ0OrvElzBqP9KuTRdp0m4L6KD0vsnI7?= =?us-ascii?Q?mECvn2dasSEDBClpEmCyZm61o5waQ0pZ1R/mnjr20RYJ+HBaRKqEF73RWYxX?= =?us-ascii?Q?Qcoiu4WFpR8YGJzDuTnOjb1aX/3/eybPPIXsC8qjFEJH/Vum5VFlS0+2wAro?= =?us-ascii?Q?SJI/I3+KP9NU3ov23ZnOXnFbNvnORt0SBn4PDxU1sp2Od8zhntUGb+HnkUDA?= =?us-ascii?Q?HN/IYY3iEmB2JtS+E4XwItJmYFyNpIPlDp7ZTbmvad6qy63MAGNlmp1EJCpP?= =?us-ascii?Q?n8bj/Hg95kvKLU92/yXhEjboPkIk8wdVl3ulGYkIcy7ylpjf4W77X3dcUi5v?= =?us-ascii?Q?4zUsK2CHxvmAEIe+bItyyKc6aGy25Ufb12VgoW31gVMQVTcksBBQfIYplcht?= =?us-ascii?Q?opBdLCrHkBnkI0Gj2eCWzppTEpD83gNyBOjtEgiiZhDBat/tPOdQDcKNcPsM?= =?us-ascii?Q?dcd09RuHDtNODI6b9FUQBmAceIOI/iwmZKmL7J0Wa1gafM4IWbwoYqqXoRT5?= =?us-ascii?Q?Kz6Bplouzb4kq81oErzUZcBrmtCGEiC1U4nmzHRQOtSkbmdFaKza6v5IZJZN?= =?us-ascii?Q?b8mWa3FDxMZOsurdwcb7c2S6OzaPium/ikH9++FhFVq5Knkh2KDWq0H3lnn8?= =?us-ascii?Q?LKYIBrYOh5GNRB0oGODKr32fEtEa495I24JVp2PTL2dft08I4BnIhKo87Cdd?= =?us-ascii?Q?ya0plhU4JJqLyPu7Xs6O6at4wDOEAXGUgWzvHbiUQxx7hr8gUCRp4B6AG/c+?= =?us-ascii?Q?/EmlTfKuZ4sZW66fh1JvmqpUEB6cAFmUmTXEpYru85KR16JqgKnRIMp4TWXr?= =?us-ascii?Q?hbMpkSbNRrMHM/8m+pjmTE4guHCNkiu6ccaVzyvKUpLFmNOi549nCdZCl/xk?= =?us-ascii?Q?h5QOeBxgqttUBay6mV94uJiXRGupFC9r760rpMx12tawBqS4xVrCZMn9kguY?= =?us-ascii?Q?dkFfLrYnjP6d6O+tCtSepp8rNT3Uezqg3UJ7/QW4d0KTau6e5ybwdZA2QwFN?= =?us-ascii?Q?D5bOZbtMgzVrrDI+XJp4hw3OnvSPBvGShRRvy9cTUhdxBrghec9SHdwqJwj4?= =?us-ascii?Q?p4y+ll4oRbwUDSCad3Rt6cZ+3qVqYfb939ytzNDWWrL81gBsIqdVOVrOy6d1?= =?us-ascii?Q?Gx58EB4n77ihfvbtUKj78WuZIYBTltTa95sh2UmP2gOeT+C31WH/O2xkusI5?= =?us-ascii?Q?5GUMVmhKi6zegMxKqmUgaC42lzos9d7AzyPwIyCQYQzQ7sNl9LLxa+aCns+d?= =?us-ascii?Q?v/+t7X63GfwtbwEZZWK7MirqTQtRxOk4/drtI7Gg5rH4H9NGUYV9sbUhAcxP?= =?us-ascii?Q?tf0mqfkbP06VLwhNUEYJod4RTEc8WsLMEmnmcMDHSJ4jBwqgPDos1kbVurJC?= =?us-ascii?Q?DJxP4xsk50+PNZDnOQ2u9KIXQD4pNRPalQaJ4nVUVr4XSQFLHJdALmYmhZIE?= =?us-ascii?Q?dpDr7jEo0/eL0Wjnsdy8mW//BK4XeTZxYpBXeqfkDT12ns8SksYwnAIhb41j?= =?us-ascii?Q?1B9p8zcpARRxU9nPeEGVkLM=3D?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: d315f134-865d-4f3f-734e-08dbd562d6be X-MS-Exchange-CrossTenant-AuthSource: VI0PR08MB10743.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Oct 2023 14:01:09.0646 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: LHNtP73bD3YZlvs+D9FUL+372SxxFPKPpaYQP47IqUuTDogbDzHw3Q/AoM9EscECGhm0VctI4bwKCp5a4c9Hey9m3lkY3Vej0vXbooKKBeE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB10363 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=2a01:111:f400:fe0e::70f; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR04-VI1-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 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: 1698242574409100007 Content-Type: text/plain; charset="utf-8" We need to terminate processes executed with guest-exec command. Add guest-exec-terminate command for process termination by PID. Signed-off-by: Alexander Ivanov --- qga/commands-common.h | 2 ++ qga/commands-win32.c | 64 +++++++++++++++++++++++++++++++++++++++++++ qga/commands.c | 34 +++++++++++++++++++++++ qga/qapi-schema.json | 13 +++++++++ 4 files changed, 113 insertions(+) diff --git a/qga/commands-common.h b/qga/commands-common.h index 8c1c56aac9..34b9a22578 100644 --- a/qga/commands-common.h +++ b/qga/commands-common.h @@ -80,4 +80,6 @@ GuestFileRead *guest_file_read_unsafe(GuestFileHandle *gf= h, */ char *qga_get_host_name(Error **errp); =20 +int kill_process_tree(int64_t pid); + #endif diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 697c65507c..5aa43a9ed7 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -27,6 +27,7 @@ #include #include #include +#include =20 #include "guest-agent-core.h" #include "vss-win32.h" @@ -2522,3 +2523,66 @@ GuestCpuStatsList *qmp_guest_get_cpustats(Error **er= rp) error_setg(errp, QERR_UNSUPPORTED); return NULL; } + +int kill_process_tree(int64_t pid) +{ + PROCESSENTRY32 proc_entry; + HANDLE snapshot, process; + GList *pid_entry, *pid_list =3D NULL; + bool added, success; + int res =3D 0; + + snapshot =3D CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); + if (snapshot =3D=3D INVALID_HANDLE_VALUE) { + return GetLastError(); + } + + pid_list =3D g_list_append(pid_list, GUINT_TO_POINTER(pid)); + + proc_entry.dwSize =3D sizeof(PROCESSENTRY32); + do { + added =3D false; + for (success =3D Process32First(snapshot, &proc_entry); + success; success =3D Process32Next(snapshot, &proc_entry)) { + gpointer ppid_p, pid_p; + ppid_p =3D GUINT_TO_POINTER(proc_entry.th32ParentProcessID); + pid_p =3D GUINT_TO_POINTER(proc_entry.th32ProcessID); + if (g_list_find(pid_list, ppid_p) && !g_list_find(pid_list, pi= d_p)) { + pid_list =3D g_list_append(pid_list, pid_p); + added =3D true; + } + } + } while (added); + + for (success =3D Process32First(snapshot, &proc_entry); + success; success =3D Process32Next(snapshot, &proc_entry)) { + if (g_list_find(pid_list, GUINT_TO_POINTER(proc_entry.th32ProcessI= D))) { + g_debug("killing pid=3D%u ppid=3D%u name=3D%s", + (guint)proc_entry.th32ProcessID, + (guint)proc_entry.th32ParentProcessID, + proc_entry.szExeFile); + } + } + + CloseHandle(snapshot); + + for (pid_entry =3D pid_list; pid_entry; pid_entry =3D pid_entry->next)= { + pid =3D GPOINTER_TO_UINT(pid_entry->data); + process =3D OpenProcess(PROCESS_TERMINATE, FALSE, pid); + if (process =3D=3D INVALID_HANDLE_VALUE) { + if (!res) { + res =3D GetLastError(); + if (res =3D=3D ERROR_FILE_NOT_FOUND) { + res =3D 0; + } + } + continue; + } + TerminateProcess(process, 255); + CloseHandle(process); + } + + g_list_free(pid_list); + + return res; +} diff --git a/qga/commands.c b/qga/commands.c index ce172edd2d..af8459c587 100644 --- a/qga/commands.c +++ b/qga/commands.c @@ -529,6 +529,40 @@ done: return ge; } =20 +void qmp_guest_exec_terminate(int64_t pid, Error **errp) +{ + GuestExecInfo *gei; + + slog("guest-exec-terminate called, pid: %u", (uint32_t)pid); + + gei =3D guest_exec_info_find(pid); + if (gei =3D=3D NULL) { + error_setg(errp, QERR_INVALID_PARAMETER, "pid"); + return; + } + + if (gei->finished) { + return; + } + +#ifdef G_OS_WIN32 + char buf[32]; + int res; + + res =3D kill_process_tree(pid); + if (res !=3D 0) { + snprintf(buf, sizeof(buf), "win32 err %d", res); + error_setg(errp, QERR_QGA_COMMAND_FAILED, buf); + } +#else + if (kill(pid, SIGKILL) < 0) { + if (errno !=3D ESRCH) { + error_setg(errp, QERR_QGA_COMMAND_FAILED, strerror(errno)); + } + } +#endif +} + /* Convert GuestFileWhence (either a raw integer or an enum value) into * the guest's SEEK_ constants. */ int ga_parse_whence(GuestFileWhence *whence, Error **errp) diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json index 876e2a8ea8..b39be4cdc2 100644 --- a/qga/qapi-schema.json +++ b/qga/qapi-schema.json @@ -1326,6 +1326,19 @@ '*input-data': 'str', '*capture-output': 'GuestExecCaptureO= utput' }, 'returns': 'GuestExec' } =20 +## +# @guest-exec-terminate: +# +# Terminate process associated with PID retrieved via guest-exec. +# +# @pid: pid returned from guest-exec +# +# Returns: Nothing on success. +# +# Since: 8.2 +## +{ 'command': 'guest-exec-terminate', + 'data': { 'pid': 'int' } } =20 ## # @GuestHostName: --=20 2.34.1 From nobody Wed Nov 27 12:30:21 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; arc=pass (i=1 dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1698242523; cv=pass; d=zohomail.com; s=zohoarc; b=GV2aYH7sBiXUAjOdiAWktMUiuGfho6NKJveDUOJTG/gpsJxCmrTjNuqUtL5hKaPXoQCHJ292+vfl3eNToGHU5q8IU+RLnXDww6GjA3vkPl1RhanXyZ1QVB2NoiA3bJhUTCChuhCaK14aykHjKoTkRA9grpIYUqwFSe352Jo81qs= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1698242523; 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=gIS1iMBgN5PYmhLo4ft1oZBzpwvYIL4FppP3JuHN5VA=; b=iy75fVMOfvKO9v/nu/3U1VLKSJf9Xb4zOkUvf0ro8Ss812MuJ31THa9rBhtZ/fMOoStx8B1oPA1W+zbNpCwRooMI4BmfF+zPGVM0P8amnbob7HxCR55HToYSPBmNlMFgVq83xNdteuGWHg7eZAtkvy+kHRLkDxwA5s6/bSABB/A= ARC-Authentication-Results: i=2; 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; arc=pass (i=1 dmarc=pass fromdomain=virtuozzo.com); 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 1698242523060533.2526375536312; Wed, 25 Oct 2023 07:02:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qveRq-0003yl-Sj; Wed, 25 Oct 2023 10:01:26 -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 1qveRp-0003ya-9T for qemu-devel@nongnu.org; Wed, 25 Oct 2023 10:01:25 -0400 Received: from mail-vi1eur04on070f.outbound.protection.outlook.com ([2a01:111:f400:fe0e::70f] helo=EUR04-VI1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qveRk-0005dH-L6 for qemu-devel@nongnu.org; Wed, 25 Oct 2023 10:01:25 -0400 Received: from VI0PR08MB10743.eurprd08.prod.outlook.com (2603:10a6:800:205::19) by AS8PR08MB10363.eurprd08.prod.outlook.com (2603:10a6:20b:56b::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.31; Wed, 25 Oct 2023 14:01:09 +0000 Received: from VI0PR08MB10743.eurprd08.prod.outlook.com ([fe80::22f7:6498:de53:5371]) by VI0PR08MB10743.eurprd08.prod.outlook.com ([fe80::22f7:6498:de53:5371%4]) with mapi id 15.20.6863.043; Wed, 25 Oct 2023 14:01:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jBqgWxtk6wMbQKZXyTyl2OskNcGyaWvxDJrNZXnwSG7vBt2Uvf3Nyj8zkQyEjCl2QlOeWAvMgHhlWbiQKvpj0QUVPSgChxzLL64FZqvlh2lGTC6ed338yJawYB1xQKZWlw0HZ4elKHEpovtGwYIK/OEME03c87Uv1vZPS44JSJufIQ0nbCdWpCIUFV3Y3jkCKhBkM7OWmh+D1UOBrLZaR2bMlEkQAYY+ABdZte3RzI/80DJokej37G4TUXutK7nZbzYMAUtBogIU2IWMmsSE5WG9bbxuZ/wrj3FwBP7lqxkzXbHII4Ou/fXyLsbBHwBVAqvOf72cFS1gStxijU1RPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=gIS1iMBgN5PYmhLo4ft1oZBzpwvYIL4FppP3JuHN5VA=; b=N4VYvETkqrXE0y6ELFaGs4SXH8o+WaUKYs+5CLiaHIM07HJpHLl1uetLAi7hUCqFw0NNE655sWIUyIO2NV0GpDoiL5x9aSzbefnCkVKo6JveVPKzmtytOwyJK77Cl854IXoeCtC2Tk1SQtgWDw/7qDV3KwNPFZC94fd1QxsXqwEBJAixJa6W9ouAANAbJWROVZ6vumhEc8pPCJjK1Doax+fJf2rPAYxILGanrV7OQMYxGNvIRBq8Gw3ZW6evuoRQOv2p4k/O/FUBA9ogjCbk7IH7hx5FBnJURDRo6oD6htdYq3vhz8ToIEkPKtwvhMrFodnuc9GThf5IVuMknx8lgQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=gIS1iMBgN5PYmhLo4ft1oZBzpwvYIL4FppP3JuHN5VA=; b=pIQrtt6kWQu34ZbXSKAZ1YftpoyJWg1JWN25YNvQUmG77yidUgJ29jx1o9LlL+nHPRMw2mYRyeEfPFX41b/aWpg2UrHu60G4SzxcHdDOm0uQObgYf8gVZ7RdTfaRU1wkfyjj47eqCldJ+HHqNAxMazqJw5A83HaT5HoEip4scbkVu+DDL8qe28howzM0v7BE3nLZ9HMgn2T8HpyJCHap+pYiG2gC53aopHNnxL9hxCt3UvNFomVgJ29sGDmnJg8paE/WCq6AeC97aPgKyiNHNPi5HlmSu/muti55g8Py5Qm+74f+skXBTSJsIMW0mE7rIGbGitKW/YDF58l9m49zhw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; From: Alexander Ivanov To: qemu-devel@nongnu.org Cc: den@virtuozzo.com, michael.roth@amd.com, kkostiuk@redhat.com, marcandre.lureau@gmail.com Subject: [PATCH 2/6] qga: Move command execution code to a separate function Date: Wed, 25 Oct 2023 16:00:54 +0200 Message-Id: <20231025140058.113376-3-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231025140058.113376-1-alexander.ivanov@virtuozzo.com> References: <20231025140058.113376-1-alexander.ivanov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: VI1PR06CA0167.eurprd06.prod.outlook.com (2603:10a6:803:c8::24) To VI0PR08MB10743.eurprd08.prod.outlook.com (2603:10a6:800:205::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI0PR08MB10743:EE_|AS8PR08MB10363:EE_ X-MS-Office365-Filtering-Correlation-Id: c419e42b-4f95-4308-4b25-08dbd562d6f5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 17KxugMFTzMVca1b05Th4q7M5gPtBPZwW35mknUO7ZbhUQxJUdPdt5iXNPTjZXPysqqy4gNB3q7U6apNive1GYD8WiYJqplKXQ2boe8Pq1sQnEM6hMViyMENw4VJqx6kCOgCmt7gbbpwPcAlFhEqdVTZjVCVr4krbuYbguPErld3Hsg0QLeyxiNsa8vYX0Ixtz/qYZa4YBzFjtFmZoZXFVNMNgiHvlEO84QZScAh2xIKgOWE3eiA6PYzvRtTyRC/BM5PbkDcIP/oVzVp0653mvvUFMJ/GypJ3QA9jOGvboSv6zWAoXVlXx5MY4Cc819k2w9UQW1AJ4u2/480b3fWoseYSKNOoJ7ta0D3qiRMKhKqTTLWPk6tLItQO2RghUlk3eaGRbxt7WerkBooRxlNg0MrLtU2gkJ3edx5AiCPs2BKrgnTfxDijjTzWakXvIR+AQy1Q+deCv/2JYjrLBxqf59GTgsjPK8HiL+DVK5PdwALETBRsBU/QMI+Y6/GsfgOPwwrJbs80BXyVkKYH55u7drwTk8FWuYGBHVCWM+uHhYqUFAxA/OUq7kU+BjRCTJyXK9eP6wiHVfA1Oqu0FvVAulRyr74geSdWcp5qitwHLcBvZWS3GwUZTtbZg5VqAD2 X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI0PR08MB10743.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(396003)(136003)(346002)(39850400004)(366004)(376002)(230922051799003)(64100799003)(1800799009)(451199024)(186009)(2906002)(38100700002)(66946007)(2616005)(66476007)(316002)(66556008)(6916009)(6666004)(6506007)(478600001)(1076003)(6486002)(6512007)(52116002)(83380400001)(36756003)(44832011)(5660300002)(86362001)(4326008)(8676002)(41300700001)(8936002)(26005)(38350700005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?yWq0Xd0THeXnK6nj+jjtjFwMazsRtquS4W+AL/2FnuT4rzv6IUYTniSNerTC?= =?us-ascii?Q?7OPrr6Amnw00yjRw3sRvCf9Sfy08J6ZeVlEJz5WYIXydISUhH4mRQTLkQgyV?= =?us-ascii?Q?CQbV1wUtnVlEIV0eX5vhQnoPo4zTc9hB85V6icAXqMWBdW4LuTBv8qiOVP10?= =?us-ascii?Q?NxBbADoca7VSCLUOJntAQQOR5dBT6yd1Z52EA6JGEqmj2PcKte4X2XuRyTCO?= =?us-ascii?Q?85yeynO+eLQTOtVv+0r9Ve2bcTIDou6YG5b0ns34/I/tkqBvk6i1+XBDm5qA?= =?us-ascii?Q?WwUGOjfBI+aomPi6fH+BmC3Yjson38/2g1H7rOn3BdaZUNjoxuBoLbUWi+95?= =?us-ascii?Q?v5Oa/bBc3jqfS8/kFRZ9GGmOt4MjZ/fwCWHm1axGklEXFfEq0q6cT9V87+0h?= =?us-ascii?Q?ecXWQ2+ESRTMESCjdVsPlfHnaxZxXVnxzYU1Cit7HuVlyGDpcKR1Gbe2SUXh?= =?us-ascii?Q?v+iNHJPkpKzN4HQxQCeStDlZloQ9BEX2bwZrTzAmnpkycmsS4xq1ZL8qusFt?= =?us-ascii?Q?cJ5oci/bOcrqCf+cAYf7I5BDC7eKj4lw0kMlkRNp+0GttuIFI23mT+p0+Ujy?= =?us-ascii?Q?adPVRqSZBfLvb69aQivTUnoN4/C7DdHcXtxqBCc3iC6pNwwSxa4LMzX5IYTv?= =?us-ascii?Q?EYLxCrdlGfcuMn0DR2zcwnncYyMEDcUiu7CvGSXcHJ/YxJmJXWRtC5neNAu7?= =?us-ascii?Q?spd+U6yO4pVB4EQL9VEhLO4/wHL9q2T/Zs3T/ZMMOjo8Zl5Ci6Nvf004FKyK?= =?us-ascii?Q?izrgzy8b9yLdLduO7F8qUJZ8CsW7nrjNjYU1qgZl54bccoLMwalGYK3U+RH7?= =?us-ascii?Q?t+kNn2jEuWRrcu7QJiDboj1N0lBXMcXmMYVIFnqkFXe1DjnTcPb9wajj02Yz?= =?us-ascii?Q?8Yp07wi1+R3tqa+VNmCMtnBfju0uAuHG4LtxpxUHfIUlLhH9ZpIIfd9eOmFL?= =?us-ascii?Q?eqw+MyyxS0P5mm1s/QJ01lsqZuk9qVZUQzTMxWXITRJw5IrXxxW8Q/o7482o?= =?us-ascii?Q?+nhaqdkPj/OmaCgC0jg6FPkN2V4oKBpA0F/C7H5ZNRyfPt0WjL/BnYjFXdEy?= =?us-ascii?Q?X10p2V5X14in9Mv/VroaImy70uPXrxkRu6o8bSkvkphCROxjDZ/4ktXqZiB/?= =?us-ascii?Q?QzWk3j2rMrZ5S4DXKB4TOmXxmli1xlfXQXZ0VlxobVFc6swgcBf3HFmDZNUw?= =?us-ascii?Q?AHE2Yb7GUNYlxJZ4SUjcGlWOpNTy2DkOUlDpsy+400ezOLppoelaOEqwH+6w?= =?us-ascii?Q?YBwPCyqyVGO5/AaFhIwV+tBazURWsORKv4HtRs4oACi0zocTQOqkd+GQzvYM?= =?us-ascii?Q?RnphLLlPZpsLd5TTAaJrHEI7W0vpALeAmccc95/MnhgvI8oUiC0ROKsPOaPe?= =?us-ascii?Q?6ui7Z6McKXC1FihOX811MSKAlTOCV0LavR9mWZLYXU2s815tRSTftm9L3GQ4?= =?us-ascii?Q?U/abFyljYZuKU5yCUaCLqWBIRrlr0dDIf1TLyAUB1L7OrfObAlUW+/oneZgF?= =?us-ascii?Q?vN7QWYqzuGVl5WjaNP74cQG5QnHzqu5sbMPtLlV+WQbFdOIfVUbyWVEVg+18?= =?us-ascii?Q?B384+1NikxJRWfOiWsSbaOQ+N8OMFK/lF6vX/myumb15Kigiie0PVl9ALm52?= =?us-ascii?Q?M6UToKYLKX5eK+vjvW/AM/4=3D?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: c419e42b-4f95-4308-4b25-08dbd562d6f5 X-MS-Exchange-CrossTenant-AuthSource: VI0PR08MB10743.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Oct 2023 14:01:09.4390 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: hh/b/Zo54BQneKhM3qyGLbGASb2x4lZaXDF9RlyzdPTphfo/rku7PmC+NCcFuPX7KUCccmoJhKZigZob0yJNE6VHmhjl/z3Yz/R6LMWrAw0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB10363 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=2a01:111:f400:fe0e::70f; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR04-VI1-obe.outbound.protection.outlook.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 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, FORGED_SPF_HELO=1, SPF_HELO_PASS=-0.001, T_SPF_TEMPERROR=0.01 autolearn=no 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: 1698242524209100003 Content-Type: text/plain; charset="utf-8" In qmp_guest_set_user_password() we have a part of code that we can reuse in the future commits. Move this code to a separate function. Signed-off-by: Alexander Ivanov --- qga/commands-posix.c | 139 ++++++++++++++++++++++--------------------- 1 file changed, 72 insertions(+), 67 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 6169bbf7a0..e7b82aaf37 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -2114,20 +2114,78 @@ int64_t qmp_guest_set_vcpus(GuestLogicalProcessorLi= st *vcpus, Error **errp) #endif /* __linux__ */ =20 #if defined(__linux__) || defined(__FreeBSD__) -void qmp_guest_set_user_password(const char *username, - const char *password, - bool crypted, - Error **errp) + +static void run_command(const char *argv[], const char *in_str, Error **er= rp) { Error *local_err =3D NULL; - char *passwd_path =3D NULL; pid_t pid; - int status; + int in_len, status; int datafd[2] =3D { -1, -1 }; + + 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]); + setsid(); + dup2(datafd[0], 0); + reopen_fd_to_null(1); + reopen_fd_to_null(2); + + execve(argv[0], (char *const *)argv, environ); + _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; + + in_len =3D strlen(in_str); + + if (qemu_write_full(datafd[1], in_str, in_len) !=3D in_len) { + 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); + 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: %s", argv[0]); + } + +out: + if (datafd[0] !=3D -1) { + close(datafd[0]); + } + if (datafd[1] !=3D -1) { + close(datafd[1]); + } +} + +void qmp_guest_set_user_password(const char *username, + const char *password, + bool crypted, + Error **errp) +{ + char *passwd_path =3D NULL; char *rawpasswddata =3D NULL; - size_t rawpasswdlen; char *chpasswddata =3D NULL; - size_t chpasswdlen; + size_t rawpasswdlen; =20 rawpasswddata =3D (char *)qbase64_decode(password, -1, &rawpasswdlen, = errp); if (!rawpasswddata) { @@ -2155,79 +2213,26 @@ void qmp_guest_set_user_password(const char *userna= me, passwd_path =3D g_find_program_in_path("chpasswd"); #endif =20 - chpasswdlen =3D strlen(chpasswddata); - if (!passwd_path) { error_setg(errp, "cannot find 'passwd' program in PATH"); goto out; } =20 - 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); - + const char *argv[] =3D { #ifdef __FreeBSD__ - const char *h_arg; - h_arg =3D (crypted) ? "-H" : "-h"; - execl(passwd_path, "pw", "usermod", "-n", username, h_arg, "0", NU= LL); + passwd_path, "pw", "usermod", "-n", username, + (crypted) ? "-H" : "-h", "0", NULL}; #else - if (crypted) { - execl(passwd_path, "chpasswd", "-e", NULL); - } else { - execl(passwd_path, "chpasswd", NULL); - } + passwd_path, "chpasswd", (crypted) ? "-e" : NULL, 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; + }; =20 - 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); - 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; - } + run_command(argv, chpasswddata, errp); =20 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]); - } } #else /* __linux__ || __FreeBSD__ */ void qmp_guest_set_user_password(const char *username, --=20 2.34.1 From nobody Wed Nov 27 12:30:21 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; arc=pass (i=1 dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1698242549; cv=pass; d=zohomail.com; s=zohoarc; b=bORZeFUoonSNaLB1LYWU6zWSpwqO3nQzwNbmw2do+KerrIz8HPtNjJ1NFUcu9HrcfUEjgjVTmrIYiMm+j5Lc0mur9KRa/oFqGXqOrnyQYY4B2uir9NAd7c/NmzW+8xemrHwjqDQqax/ifAb3hER5HhuNdIruiw6tdX7Lx4VkiLg= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1698242549; 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=k1j6wdAPLklf+4ZSuJxzVOi4eVpH21DF166Vux9f7w8=; b=kW1hdp3qMELvg1vCE65qdlnC3j5kyGQvfveZtNfG71VMH1GDGQeMnYr1N6P4DEEjMpNDsWw7X1i6QneiboJH1nEboQH4dYzGk6lNVMCk8HZWp+Q1ZDp+m8oFPf1JYPJbPxky5WLSRrOKbBllyO36lLQEEVr5fVPvb4ATeBYWmI4= ARC-Authentication-Results: i=2; 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; arc=pass (i=1 dmarc=pass fromdomain=virtuozzo.com); 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 1698242549775370.7004341909043; Wed, 25 Oct 2023 07:02:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qveRs-0003zd-Qm; Wed, 25 Oct 2023 10:01:28 -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 1qveRr-0003z6-CD for qemu-devel@nongnu.org; Wed, 25 Oct 2023 10:01:27 -0400 Received: from mail-vi1eur04on070f.outbound.protection.outlook.com ([2a01:111:f400:fe0e::70f] helo=EUR04-VI1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qveRp-0005dH-PQ for qemu-devel@nongnu.org; Wed, 25 Oct 2023 10:01:27 -0400 Received: from VI0PR08MB10743.eurprd08.prod.outlook.com (2603:10a6:800:205::19) by AS8PR08MB10363.eurprd08.prod.outlook.com (2603:10a6:20b:56b::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.31; Wed, 25 Oct 2023 14:01:10 +0000 Received: from VI0PR08MB10743.eurprd08.prod.outlook.com ([fe80::22f7:6498:de53:5371]) by VI0PR08MB10743.eurprd08.prod.outlook.com ([fe80::22f7:6498:de53:5371%4]) with mapi id 15.20.6863.043; Wed, 25 Oct 2023 14:01:10 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GZaXwAFp+kGsASfBibVxBO9ZWn5G9hBvdlE9B3bjwN5MtM8hbQiYtzqqV00DtquIlWqIImoGxQKOFaDOjNZTboIVg+weu33SUYxSekbTDHpYMkLtUmZH8jnOKklwaZ/2Br7sWVwgi8SSXp0EWQ7y2og7Ol8Lfb1mozMDyB+P3zzghi1B7lgQbzX08B3fMHodizu1mYgQjaXRyNB617W5gC7SyNej8+/Inv1EtCpFjmjvFsjYYZ5c1IFbhXyr3dC+W6v4iTVd7YlGPpbNOrHBwPabqfkXTnKddHcYo9zX/zZ81xKBOykLa16riPMJUQ9pQPwVB/0DvPnJHCAyrmzd1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=k1j6wdAPLklf+4ZSuJxzVOi4eVpH21DF166Vux9f7w8=; b=isu2rSsZpPRbr5YxHPwjf3XEkYtbeAIWxXmmD5q71sYinmrjEYBwj2C/QpSg4UHyNF5DM7luNedcKxTEttG6ISEuZJDHTf1bP7lg12BQCQwQYKmk6jq0c5YvH7DGrjLa1L6SBe5eGNtNSkqUp+svHWtyjpmk7tsD25JNaBQWN4+pbBx7B/MTzM5jZvy5/H5C63+8Tra31y7uc41bhj3cjqrKHSPCPpX9oaWfZ5xYF3mAhTrN6SyO8V+DwjSYipTr1Fw2QRCP4mTXTe9n+oXqtONcSNpj1VaHngwT/6dglSRqLpVRg0/P7859OYzcEXlVwiXqSKcpJIOcbJs1YDII2A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=k1j6wdAPLklf+4ZSuJxzVOi4eVpH21DF166Vux9f7w8=; b=HA3dcON8Sit+VN3K1+04JZQNbo/xWbqsVe0mWSI/z1HyOeEbQsXjSPg/JGXsFwcTrIiNoh+8jmWqGTsnqB4fqG6YoH6ridhZfrTcx5J47WqQEfp0J0kDm1sCPimyp0IGoSfYrRjtAF2cK0Od8Fmty21fpUwRoIqJksXYhWE2qFTHZkF9wowWi6ooi5oIdZB0teqzjZGmQ5Jp2WBH1FtzIGW3N1q7mZbAlNuDpJF1/BU5ghbJkYlbb/ZL0/8KEoUKQ4jklsACo/4vPap4uF9eyKuv1W92NyBuIZCfKWmjugPd3Lz+lTiWm3E5cOPTwApjm11jxhRz4YU7C8H5cGJfGA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; From: Alexander Ivanov To: qemu-devel@nongnu.org Cc: den@virtuozzo.com, michael.roth@amd.com, kkostiuk@redhat.com, marcandre.lureau@gmail.com Subject: [PATCH 3/6] qga: Let run_command() work without input data Date: Wed, 25 Oct 2023 16:00:55 +0200 Message-Id: <20231025140058.113376-4-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231025140058.113376-1-alexander.ivanov@virtuozzo.com> References: <20231025140058.113376-1-alexander.ivanov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: VI1PR06CA0167.eurprd06.prod.outlook.com (2603:10a6:803:c8::24) To VI0PR08MB10743.eurprd08.prod.outlook.com (2603:10a6:800:205::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI0PR08MB10743:EE_|AS8PR08MB10363:EE_ X-MS-Office365-Filtering-Correlation-Id: 9bd76c85-6880-4f70-846a-08dbd562d76c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xKmpZiUV7/dh804G1mwO34hSJaHY56AyNeQcrNrmORCKviKAF9o3UyQr0l2gU+bX1lVKEDeTIaaaHfyVpDVI5+2t1TBpNEq0dnPF1LskDIh/pl7RNvfXouDMsIWAuNx0TAR9U39R3ke6m0bzEQDSR0DI0ZCZGBSy1/rZuNSzTdNlwjGMjy3WehZ5fSbcrYzgTwi4G1ZFnk0d6r6BC+ajxDJC2zzDi8qfgbTmxY8fMoV6q2dHVx+iet5ctH8B7ICsvmec+WgK+jxDAFVxO3nYkyhS33XUGVQ3ql8XDzW5OZ0iJ8hKzYmeCiFBxTWrYAC+qyoUIuUSWtAnNpszj0rOEvLpmwRdBBUrpLcXybxitmt8oeRJvv9Hs52mxvhqAPZRXAx83bEnlCyN709kmWsbzoECGrqZlrfIq2DKGYI0AjiPFx/o3V1x/cgGocl1MbmWZhglBpKMAm/Z+YLukqrLHjFCJoS385SYCpxii9BxgnmphC/9CLOUCjQHaFbDqrE52tSFEFUWZGiexuU9jSBUX0qVOHmsYS4lAKdxKw+xfMuprVqzDkB3K/FNWaqmJjoV/dVPDVt0+ceUHYIwVuAOP4wV1Wr4oK+KONfI2eTfFzXt4pDF3fQwINsOzMgPItUh X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI0PR08MB10743.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(396003)(136003)(346002)(39850400004)(366004)(376002)(230922051799003)(64100799003)(1800799009)(451199024)(186009)(2906002)(38100700002)(66946007)(2616005)(66476007)(316002)(66556008)(6916009)(6666004)(6506007)(478600001)(1076003)(6486002)(6512007)(52116002)(83380400001)(36756003)(44832011)(5660300002)(86362001)(4326008)(8676002)(41300700001)(8936002)(26005)(38350700005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?j9f6H22wxaouXW8fyDhrR2oelx4eRMgBsd/tvDrx6JDhezlXawlriUaTumcz?= =?us-ascii?Q?wNAViv7JAUEfNdUBNIUpry4twhIkKVgszhVDPuHyUV6IAsnSm1CQDP7eflnz?= =?us-ascii?Q?/W0dSBDiI3rOUwqsYHn+RRjqcNiRe5rtWyvhBhpK64xc5G8uAhXXNDKtl6cL?= =?us-ascii?Q?iLKl8Zfxp9rB7JfymgAdpNflW6qOrP0bguX5vPRqX5DSEdwBCVzC1flSo7gA?= =?us-ascii?Q?m/QqUtfD41QfgF3jivcmtMMcucf9th8zlKXVxRY2GK6hEdFmnbhCDpHyCWzb?= =?us-ascii?Q?MoZPSaz0m/mMbL/NoY6Duck2poXkwTHqs13cjTcoXHlhHVqTaJXfU4SQQtyQ?= =?us-ascii?Q?W2cC2OJX9br2CHhJvagnDTumwNNrLTHkmEF29RCIoWh8tgCjwp90IhKSba0C?= =?us-ascii?Q?dZGbx/hENJwRm9DlIoEB/i7sFurMUA/+Sp+gXc3wlpwt1M24XI3Q3eVoVHyJ?= =?us-ascii?Q?CSGUE+3CBQw27OTTjuaANwJ3k6pZmCha4noHqNNhsGnB/5GiJIHkQri68tFX?= =?us-ascii?Q?t55EB2q5LbvVaOQzd3c+SknmjUJvnpTYMOZnjWr/nCXMCzdRXLrXYg/A2eDc?= =?us-ascii?Q?7LetbFubNr+NLi+nZ7l71ucCTOOIR24lEPiJXSQkVrvL1DqRj8ai6OIzhfSa?= =?us-ascii?Q?C0HEvCQB2Ipq/k+UF4tOWxVaas/JMWBgfO4Hwhx8EUpsX20MouPC3v/C/cEE?= =?us-ascii?Q?iSzKmSvIFILmEUvI0SLssNXlGn0wTvU/+Qv/IkugeFqnt8kakCeX0iuegyTe?= =?us-ascii?Q?hFOsf24+cE+coUJ73WhsFzJHdaFxLo5KQ0V8YYeKgAQb/4NvnRHOndebR1GZ?= =?us-ascii?Q?DuNw+kEcxiSrqLASM7lF5Ocfls0kh8QndF2ejtfaFkWFYOzhpZbVqKGKP/Wd?= =?us-ascii?Q?su4ZTyiwGVeXwBJBOytF6kvbrOguhhHnuePFOiykWCzBzCJR8hTlT6f8Lssv?= =?us-ascii?Q?C5lSK+pTxT/98sB8EL0OaHzvKgL3p6svEpa+2d+9WIo56w65viooY/bTYETW?= =?us-ascii?Q?tIYGtdHI8NOzsM7AN03lLtYa2q5obC3C0EQ5H1vknANZb4aS0URcYM+Q2no5?= =?us-ascii?Q?oDfxa2pUSnhZp7hRT3n1mmKk48Lan1B4oKcOSvDAGvSBR3T3LhW6QfWCH/XM?= =?us-ascii?Q?qZzQOx++el4JgfghwK2mbtwX6yVysPwcL9JS529Hbl2J5lGj3GXtY2kj2Qa8?= =?us-ascii?Q?hBWjy411D1ZAnhUQEI1hBsRw9t0ashHjZ22cQBqf5noFzaCtlkp13qYXl+kj?= =?us-ascii?Q?eP8kDczlax0UvUg08mQi8kaFXzVPFoLSYDiaqiL0J16lc8jS21Io1I5SsiR2?= =?us-ascii?Q?yU6p2k/AY3OaaQMxXyWLcyybUZxsw8YkzsLQQGLDNmQK+u2Af+KWWpI2JDGx?= =?us-ascii?Q?VuBErWwdwzxqQzGUXW1b+9PCnQXodbSHNA9YaToyQatYrdDNnBdUJGXfH5Ep?= =?us-ascii?Q?bpuifnYoQeqL85R0lLY4fFadPrqrXFCRN1etafTBnkgFF9tisD1oN6XYwwwa?= =?us-ascii?Q?7nnhM8JV87oV/miqhbiq6022EctZ15L8peFxGb3BxSvFJYvhl/KSfd5nwyIp?= =?us-ascii?Q?/cu7qwTf88m5/5rRWlI+7mcOBQjYJVf4uSuUCW8QBATgmNjfIOaTGQlPuXr3?= =?us-ascii?Q?4DGBMYyoWp/767kEicMVVG4=3D?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9bd76c85-6880-4f70-846a-08dbd562d76c X-MS-Exchange-CrossTenant-AuthSource: VI0PR08MB10743.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Oct 2023 14:01:10.2009 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: yYN2aLRAtWUbvEPWPqrEgvArREIFsCnMkZ/mpnwaGjwXTkakNXKHB1I7fWC4/sDHe+N8Tn81ohQIAN4AIxdkse3VAgL3IJqWcypo55tDok0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB10363 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=2a01:111:f400:fe0e::70f; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR04-VI1-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 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: 1698242550268100003 Content-Type: text/plain; charset="utf-8" run_command() has in_str argument that specifies the input string. Let it be NULL if there is no input. Signed-off-by: Alexander Ivanov --- qga/commands-posix.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index e7b82aaf37..461b4d7bb6 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -2122,16 +2122,22 @@ static void run_command(const char *argv[], const c= har *in_str, Error **errp) int in_len, status; int datafd[2] =3D { -1, -1 }; =20 - if (!g_unix_open_pipe(datafd, FD_CLOEXEC, NULL)) { - error_setg(errp, "cannot create pipe FDs"); - goto out; + if (in_str) { + if (!g_unix_open_pipe(datafd, FD_CLOEXEC, NULL)) { + error_setg(errp, "cannot create pipe FDs"); + goto out; + } } =20 pid =3D fork(); if (pid =3D=3D 0) { - close(datafd[1]); setsid(); - dup2(datafd[0], 0); + if (in_str) { + close(datafd[1]); + dup2(datafd[0], 0); + } else { + reopen_fd_to_null(0); + } reopen_fd_to_null(1); reopen_fd_to_null(2); =20 @@ -2141,17 +2147,20 @@ static void run_command(const char *argv[], const c= har *in_str, Error **errp) error_setg_errno(errp, errno, "failed to create child process"); goto out; } - close(datafd[0]); - datafd[0] =3D -1; =20 - in_len =3D strlen(in_str); + if (in_str) { + close(datafd[0]); + datafd[0] =3D -1; =20 - if (qemu_write_full(datafd[1], in_str, in_len) !=3D in_len) { - error_setg_errno(errp, errno, "cannot write new account password"); - goto out; + in_len =3D strlen(in_str); + if (qemu_write_full(datafd[1], in_str, in_len) !=3D in_len) { + error_setg_errno(errp, errno, "cannot write new account passwo= rd"); + goto out; + } + + close(datafd[1]); + datafd[1] =3D -1; } - close(datafd[1]); - datafd[1] =3D -1; =20 ga_wait_child(pid, &status, &local_err); if (local_err) { --=20 2.34.1 From nobody Wed Nov 27 12:30:21 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; arc=pass (i=1 dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1698242549; cv=pass; d=zohomail.com; s=zohoarc; b=R0xWZ9Siuc8gFDvzLmQQaVtDH3MYeKTihZ8odn3xLQJ1bK5MCeFfKGFRkspp3IAtZH7y/gqXVeLwqFyLNE3LfS+P8pTf9aaiGMGrC8D7xreJouQio8SDev5I5RiqKAage8a20iO1PGAgeTnJ/p9ioqDt9TCAg/U2acfnhO2OcPk= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1698242549; 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=e9s5W0nSK1DqegJPmFL70njD6Ic22z0A3vfxiaJ87+0=; b=PGAN/N3jaDPA+vxmXGMfB7Nbmj7yHYcUxWcbwFtWeS2dPUfeCQIHYo6vU77DUV/I+dHTUzOJZes/yPEHB1f4GIVG42U5C5hGRRhdbRH2rFHCSXWQHDnKLoB6lbRA99RT4vv8kvJyoLTkrjDVg67qq8ZgIhoxyYUkQpBUh/FbnJM= ARC-Authentication-Results: i=2; 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; arc=pass (i=1 dmarc=pass fromdomain=virtuozzo.com); 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 1698242549504816.3171831778884; Wed, 25 Oct 2023 07:02:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qveRx-0003zz-HV; Wed, 25 Oct 2023 10:01:33 -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 1qveRt-0003ze-EE for qemu-devel@nongnu.org; Wed, 25 Oct 2023 10:01:31 -0400 Received: from mail-vi1eur04on070f.outbound.protection.outlook.com ([2a01:111:f400:fe0e::70f] helo=EUR04-VI1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qveRr-0005dH-NJ for qemu-devel@nongnu.org; Wed, 25 Oct 2023 10:01:29 -0400 Received: from VI0PR08MB10743.eurprd08.prod.outlook.com (2603:10a6:800:205::19) by AS8PR08MB10363.eurprd08.prod.outlook.com (2603:10a6:20b:56b::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.31; Wed, 25 Oct 2023 14:01:10 +0000 Received: from VI0PR08MB10743.eurprd08.prod.outlook.com ([fe80::22f7:6498:de53:5371]) by VI0PR08MB10743.eurprd08.prod.outlook.com ([fe80::22f7:6498:de53:5371%4]) with mapi id 15.20.6863.043; Wed, 25 Oct 2023 14:01:10 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=I/5Z4XSdqy5J1t0XLADpKpYEs8bEqaGZRwzx6WqDWws2+bIEx1Jpq0vOkiEJjeHw4KK3rjF4nszX/Y1AsWuTYLx3RvNzqmPMi9UK3TY0XFgCMu9AkTqsmAoAXLdeN8IyuQhilh2V6AK+Y9IAfyzEa6rBRuLRuHqzMkX1d3SgBjWk1PCLE/AsJTtcR8KElpPHIYJw0Gnw5YRCTEVDrJbkA7koxmtDS+l5de7tH7NUAX2NtuMbEmp744zo36B58jvEO9qC0DrEP7aiHTKjl+nuVJPhb/Wf9v3PI6t8Ea7Rp0ziYR2dXZPDU+tigHF3aEQ1TTfnKO/Xy/+tjdA9qzCEuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=e9s5W0nSK1DqegJPmFL70njD6Ic22z0A3vfxiaJ87+0=; b=bQGvdDe4UCF4Yz7SwbET1tg4b9J0gsS0ovRjIIp2MIdd8tQrS79FhXykF8B+hnWjvhOOBMLQqv6uWYVeLrk0PMQpszK048QxDEYKxBQG4KWTE3Yy9jhzo1RcB7T/f8KNMFXap5UlyBJb9+WYWQuO4PeAHsuq5IK/emuZ8w8nbh5KkBp1iouJG7CjOkUE487JdsEH766gy0vEHhNiHiK4vFz+/LujS+BHf3oz5fk4a8rK9zafR+ba6CaxljZznnwYKOSWaPaynWyYcZKXCss3BQQK61SAbAG8+Ls30ZDFdVVAGroh/VwPuyP6Eg8dyZmO+Unx9HywLD61R5/hQExpew== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=e9s5W0nSK1DqegJPmFL70njD6Ic22z0A3vfxiaJ87+0=; b=SIZOPJIpTmTaa73dRW9YLXInzSYCKJ3N8v3tD0V5ZKYz/7pFzxYeEdih9xPL2Jbdw42jgRN3Lq38+EOtyxt0M/T/HANSlMqnd8+/bO/aPCynd/ONccFimaCQNFBs/80ovZ0ck4v2MMOp36pFuLTM0xHiUR52MM5KWiw3A4PlaOdh928zBoRX9PE1AL6dJlL09qEZJZP0cLCD7p6cRdQ9MiMtnthPq/CDegL8bFRessN4ImtI0Q57i10VA2fjrBX7DVc/kib2dxjeAGzbw4C5JazfIVzXl0cG2D3htxmrnCpIJcGc/bGMLQjrTC8YjpLdtBYjhhV6Nuoac4gSxpdF1A== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; From: Alexander Ivanov To: qemu-devel@nongnu.org Cc: den@virtuozzo.com, michael.roth@amd.com, kkostiuk@redhat.com, marcandre.lureau@gmail.com Subject: [PATCH 4/6] qga: Add user creation functionality Date: Wed, 25 Oct 2023 16:00:56 +0200 Message-Id: <20231025140058.113376-5-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231025140058.113376-1-alexander.ivanov@virtuozzo.com> References: <20231025140058.113376-1-alexander.ivanov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: VI1PR06CA0167.eurprd06.prod.outlook.com (2603:10a6:803:c8::24) To VI0PR08MB10743.eurprd08.prod.outlook.com (2603:10a6:800:205::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI0PR08MB10743:EE_|AS8PR08MB10363:EE_ X-MS-Office365-Filtering-Correlation-Id: 00a22a65-7b7a-4a55-aaac-08dbd562d7b1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: H/+KL+cctVPH7qRTzKNc8HcrxCkqmq+d4Gkxhgp/isdzR7Dm4VhVcmpiQ2sQCshA0FI2NZs2eSN2Z5+YeO2zv5Pv4sNTku9JQtDX8yo9knT4tDY0LqrMMmAxm43grFQRYEYeC8L/Uh915JQnzQezltFKLGZYICIJxSUuoVwhC9WvOklMtmRpligN4N1+YWZn5vYCgHFdjAI7/SYvFa4xeitwOXMDCcU5mzBwQKmbBr8pQ+tI/48bymn/OixPF3WG4J9Q7P8Iz2wIpBmYBnM2DMpMJT7HnVNb2XZ0yqTHJUIglssRImE0QIESeYzgXQKgNb4z1b09R/erFdkRgJusFZpnM5w9nIIszoTDzfMXgktww4AiYyB/JPvOpKeLS8hrMmJMNvwE5gY1upY2Uyt9Lvwx4veHGA9VAQFU5IfAGVVc0BBm9NVoHoVHx3GBc9sI0AHW6Omf9n3Mb4Prj4orr+gXuvXwWCxK8ObTgiCnbbXRyIRm9WWdUKUkg12cSxKIdD6NG3XN7VwZyxQ4VQjE8ctLBi+Qm/jcT15noj/MiEHotmVPXxE8KLbe4iWtBAz/Nb8GS3c9PShL8YV1bO/Xa54BsSD+LPxZCl6ZFwQd2dMRaGTWFmWtwRPPimTeSCYJ X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI0PR08MB10743.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(396003)(136003)(346002)(39850400004)(366004)(376002)(230922051799003)(64100799003)(1800799009)(451199024)(186009)(2906002)(38100700002)(66946007)(2616005)(66476007)(316002)(66556008)(6916009)(6666004)(6506007)(478600001)(1076003)(6486002)(6512007)(52116002)(83380400001)(36756003)(44832011)(5660300002)(86362001)(4326008)(8676002)(41300700001)(8936002)(26005)(38350700005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?+oSLuH/uBl9+ap7TEmj4S9CC+TJeKbPAr8C2bQHnlHxXhwG1iw0taAqI3qKY?= =?us-ascii?Q?RTRMsd90+jciHlaWCWo/NumQSHr5G/AZV/pFA8f2obw6Pwjc5M2OknqtYKUT?= =?us-ascii?Q?CQ9ruFufaVszGqvYaUZCqkDyyfHqaYSCSvjjkGe3cmLmCRYcJLCalFK5Cv4Y?= =?us-ascii?Q?AimrCTvhdaxa9vtsJ+eO+quEbE08pUdO++4AvSFtQ0nDWwzzzIPq5na1ZNIT?= =?us-ascii?Q?UE9shmnp+scCAmG6/5YcNaSRNQmdRjtEf6kqoGRLn7flyR6G+S3Z5DbtbxK0?= =?us-ascii?Q?ibRVQ40oX4Gj4FQc10RXRK+UdEKYJFl4bcMRQw6LcIHwOWHv7UDbakDrrsv3?= =?us-ascii?Q?VQ0MZMmgpWYpV2Z9zURetVLs8CMxRX+cwQgPBsfDdOvvqCKxtcKSjPmduGSe?= =?us-ascii?Q?sATPVPHlUP+h6185GnnnrNo5sbB08oZaCUdWAlZE2NFYPOSDwybyf/Hy9nrm?= =?us-ascii?Q?x4QpFI8l+OC63W7zHQj8yy/RpBt/ABhPPEsLCQtXWUzhUj29xn4uSHbDo3Fv?= =?us-ascii?Q?6fYClRFKFJHrO/TNbGnGsV9TIzos6TyrITFkS7eobjgaPsZGILdKQTg2DcQZ?= =?us-ascii?Q?VmPgcv2Otgkpeye3xUOsVwsejanZEvagy08FN+Hqk2QyDd89mSxFFVgTtPZh?= =?us-ascii?Q?yST7baqxS8EDce/P7niEAwp3rNqBrh8uAz7SEPChUES3QZXx7F8gfWybaSRU?= =?us-ascii?Q?H0ML0oPBr8J4u+45yhtQq8VAOyeAbfpqJ7WGQDHhEeSPomgIuhVMSugrEZLE?= =?us-ascii?Q?XZznJHLUd4gL7PcfJchRbVMjoudc0wD0miKtX0tJzobE9ByVzECmLk5uCCEr?= =?us-ascii?Q?emgc0+gUimOh17I7S4wz2Io30cAIwByp1nSsyuxFuWonoOVBtotSHNrh5JY6?= =?us-ascii?Q?Wgia0ldmHmIB5ZntsKRJ2hp/aI++aZ6j9Nj0GdRdkwgBiS3yIKh32rY/Xdnv?= =?us-ascii?Q?hNvnFaq08KjDfCtGcmXz0frP5/oXzrNIqxhh4iV2pa/NYWcDFwqEJHG29JOC?= =?us-ascii?Q?bu/kOrWcAxbvTLVMRpHJHcyLKKQiQAqPialSACKxnxlowTZ24AfjSM25X3qu?= =?us-ascii?Q?Kl4td/ui4IVZQw6064bxbnPmiiNEc+1s0C09lRZy0NKQKruKhX0wGHlIuukM?= =?us-ascii?Q?l2xVFPmOERtVtoU2opF/3fIgGjDDfpX8sSGe5OF7RgL0tqNZcHK036HleAkm?= =?us-ascii?Q?ll96+Yj79OVzlyp+TzHFNqja2IRCgmZ0AQkfbh98bpngs2OB3zRwmefjCleX?= =?us-ascii?Q?kljhBDC/3YmdSNRf3klvYKQt+KOEmKoQgISMDE3E3JYvR4QeNYxtWl4BeWI8?= =?us-ascii?Q?Nud6zJfG9TmMy+sKz5CFBZ02GLm2KYykj/MXQJNxeo14xkxjZt/3JJDSLvgF?= =?us-ascii?Q?UtDKV9tLWTatwlLvVl2qG9e8kuloPRUoqOGHaJAEd5Tf/mqopMRbJUz4DZLg?= =?us-ascii?Q?yHK4UZkMgrhSPN1B4gxsmaZ7xBGafh+Nb7aFhl5D0tyBTRNDCOQp6nru7v2q?= =?us-ascii?Q?+zDvg2hYGUY5fU6hUdJdd4wIo9MrM2gaqdAja19g4DlZ138aSUAlRVfC7yxk?= =?us-ascii?Q?Ip+OaVQmzFP5NMH4od5et0NWrOvtecDcXN+XDHxooHpllFggYzzELZigzTwV?= =?us-ascii?Q?RL60/aPUtvs8ShX4H5Vj1FA=3D?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 00a22a65-7b7a-4a55-aaac-08dbd562d7b1 X-MS-Exchange-CrossTenant-AuthSource: VI0PR08MB10743.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Oct 2023 14:01:10.6727 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: CcJuuOU+/haR5I/3s0jv/pVIDHXItAzaPX0mggBVMLyaJR+iGHNP2+l+pu9lBWqh7bVu/TFzzRz1ynXgKB+SPMdbytRqyZ2FPR8BhRcxWp4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB10363 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=2a01:111:f400:fe0e::70f; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR04-VI1-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 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: 1698242550270100004 Content-Type: text/plain; charset="utf-8" Add an optional argument "create" to guest-set-user-password command to create a user with provided username and password. Signed-off-by: Alexander Ivanov --- qga/commands-posix.c | 19 +++++++++++++++++++ qga/commands-win32.c | 22 ++++++++++++++++++++++ qga/qapi-schema.json | 5 ++++- 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 461b4d7bb6..26711a1a72 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -2189,6 +2189,7 @@ out: void qmp_guest_set_user_password(const char *username, const char *password, bool crypted, + bool has_create, bool create, Error **errp) { char *passwd_path =3D NULL; @@ -2227,6 +2228,24 @@ void qmp_guest_set_user_password(const char *usernam= e, goto out; } =20 + /* create new user if requested */ + if (has_create && create) { + char *str =3D g_shell_quote(username); + char *cmd =3D g_strdup_printf( + /* we want output only from useradd command */ + "id -u %s >/dev/null 2>&1 || useradd -m %s", + str, str); + const char *argv[] =3D { + "/bin/sh", "-c", cmd, NULL + }; + run_command(argv, NULL, errp); + g_free(str); + g_free(cmd); + if (*errp) { + goto out; + } + } + const char *argv[] =3D { #ifdef __FreeBSD__ passwd_path, "pw", "usermod", "-n", username, diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 5aa43a9ed7..618d862c00 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -1921,6 +1921,7 @@ get_net_error_message(gint error) void qmp_guest_set_user_password(const char *username, const char *password, bool crypted, + bool has_create, bool create, Error **errp) { NET_API_STATUS nas; @@ -1952,6 +1953,27 @@ void qmp_guest_set_user_password(const char *usernam= e, goto done; } =20 + if (has_create && create) { + USER_INFO_1 ui =3D { 0 }; + + ui.usri1_name =3D user; + ui.usri1_password =3D wpass; + ui.usri1_priv =3D USER_PRIV_USER; + ui.usri1_flags =3D UF_SCRIPT | UF_DONT_EXPIRE_PASSWD; + nas =3D NetUserAdd(NULL, 1, (LPBYTE) & ui, NULL); + + if (nas =3D=3D NERR_Success) { + goto done; + } + + if (nas !=3D NERR_UserExists) { + gchar *msg =3D get_net_error_message(nas); + error_setg(errp, "failed to add user: %s", msg); + g_free(msg); + goto done; + } + } + pi1003.usri1003_password =3D wpass; nas =3D NetUserSetInfo(NULL, user, 1003, (LPBYTE)&pi1003, diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json index b39be4cdc2..e96d463639 100644 --- a/qga/qapi-schema.json +++ b/qga/qapi-schema.json @@ -1059,6 +1059,8 @@ # @password: the new password entry string, base64 encoded # # @crypted: true if password is already crypt()d, false if raw +# @create: #optinal user will be created if it does not exist yet. +# The default value is false. (since 8.2) # # If the @crypted flag is true, it is the caller's responsibility to # ensure the correct crypt() encryption scheme is used. This command @@ -1078,7 +1080,8 @@ # Since: 2.3 ## { 'command': 'guest-set-user-password', - 'data': { 'username': 'str', 'password': 'str', 'crypted': 'bool' } } + 'data': { 'username': 'str', 'password': 'str', 'crypted': 'bool', + '*create': 'bool' } } =20 ## # @GuestMemoryBlock: --=20 2.34.1 From nobody Wed Nov 27 12:30:21 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; arc=pass (i=1 dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1698242549; cv=pass; d=zohomail.com; s=zohoarc; b=iyQKOG92KkL5l0ORiGbxQMuYgamj/UFgw8pyy5i/1DNDvYAGYIXAP0DB+rkl2BZIBtq5Cp3+9r7H2tS0vouN3Nt02EthO6dFjJ46XYOwKhNP3uTBF9x7+DquWmL9DJNOflvDhE20iS7Fm40t0za0AwyUsqOemgSh6S2s7aCTnvU= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1698242549; 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=R5VoQPBHvnBJdxo3utUCRy5WdZkxc4cqOEYjXSFJf6U=; b=YoRecNboTncEJbyfb+shpFJx7aH16ZLLevZftSvdh1mdVBO6GQbYSUxJnQM+wiXJ5aRGL2BYKZabmpW0QlW2WjpUYaGZQpjwHnQ/hgAPPamtwrPK3vO2V2pFmZoEpovlPfwCw1cNl10OKeA3wb3cVdOHLjjcXuVyuC7ifwvaNC8= ARC-Authentication-Results: i=2; 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; arc=pass (i=1 dmarc=pass fromdomain=virtuozzo.com); 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 1698242549719190.75604206192122; Wed, 25 Oct 2023 07:02:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qveRz-00040Y-8x; Wed, 25 Oct 2023 10:01:35 -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 1qveRv-0003zj-Se for qemu-devel@nongnu.org; Wed, 25 Oct 2023 10:01:31 -0400 Received: from mail-vi1eur04on070f.outbound.protection.outlook.com ([2a01:111:f400:fe0e::70f] helo=EUR04-VI1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qveRu-0005dH-0N for qemu-devel@nongnu.org; Wed, 25 Oct 2023 10:01:31 -0400 Received: from VI0PR08MB10743.eurprd08.prod.outlook.com (2603:10a6:800:205::19) by AS8PR08MB10363.eurprd08.prod.outlook.com (2603:10a6:20b:56b::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.31; Wed, 25 Oct 2023 14:01:11 +0000 Received: from VI0PR08MB10743.eurprd08.prod.outlook.com ([fe80::22f7:6498:de53:5371]) by VI0PR08MB10743.eurprd08.prod.outlook.com ([fe80::22f7:6498:de53:5371%4]) with mapi id 15.20.6863.043; Wed, 25 Oct 2023 14:01:11 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dDbevDX8FtB6TH4ZbBRt99gTtCUWHIUdV1N3b29zwSEUVqjQRIVAoywuvvd/rSozXuMfda/G7eSU+cbwWxPixoHLPDhILJqf7RqgnQ2pPMemUPVISO5yWwmuZqFlT61MFJqzdb5JWF32AbuThTu5HU0kgN53t5o9+aBo9l6Zr3WwlOf75CTf14k7uRs/EH3m5IAL6DhcsZSzKdUcokG8TcnIrMmsMQk/FzZa4pha46zlT1Zm3+DLeRMcdaBz+rB57ieRqghYbP7ThvNmdv+9l5IYlDKmsbX3ohy3FghMUTcrPJmz9nSkehWDBaE8o8NivLGh1o8CNiBFCQ4a5nArVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=R5VoQPBHvnBJdxo3utUCRy5WdZkxc4cqOEYjXSFJf6U=; b=ZJWXbxUjSiRA2ICNKw9MT87TusApUzurlVeKN2WEylraBE9s2cWKE3lfkEzxcp30ywwSsa0pZc9W+CnuCQyPmDb3xDNTH7clsJJqC3ck0nojb+RpXDJDEuKc02cBW6UrQUYmEcxeg/N8wgRt7J5LMktPvyTnV19St9wJqAzpbttPs3ckidaDT83sikG9eqrUM6vKDt08+utUvF6mQhuk3dxtQhxvJT9IMcVoG1YrRlWxOUqVbArJcrmXRsodtazCthG41yZuyPIT78Mxwcm+eIjsfdbHCepF4knCTYasDJy2GAi5N6n3aEYJLUadFSoPgruEY9US3ed3TSbKAF8dBQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=R5VoQPBHvnBJdxo3utUCRy5WdZkxc4cqOEYjXSFJf6U=; b=oyNHAnyga15p1AgKV1POasAkcDEtWJV+h/GzkSc1MosK37Km2Pozpfzsa735UFGydDL5lhFi4ySBRQAhMp8b451ag8zpObzD7xmf0Perf+5dnWsdtt1LvWnYjbJxZVChivU/WGQH6pTUN6GoYUSEz04xUUwE/k2EFFhLIlnh6j2tpkKPlSfp7oYhLEX26pDkNiIkE0S+7PHVaShxUAHP+r66k5efYEiaqJSYlTgj/vhpj5L/d2aaR5R7Cjnc1QaMkfHgC7AQd3OKz1W4Y4qp8y77rcua7elFFUYq45wPJi24UcG8p0ya5P1XPOZzCl7RhEUN96y07kpe5I+W6v4FQg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; From: Alexander Ivanov To: qemu-devel@nongnu.org Cc: den@virtuozzo.com, michael.roth@amd.com, kkostiuk@redhat.com, marcandre.lureau@gmail.com Subject: [PATCH 5/6] qga: Add timeout for fsfreeze Date: Wed, 25 Oct 2023 16:00:57 +0200 Message-Id: <20231025140058.113376-6-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231025140058.113376-1-alexander.ivanov@virtuozzo.com> References: <20231025140058.113376-1-alexander.ivanov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: VI1PR06CA0167.eurprd06.prod.outlook.com (2603:10a6:803:c8::24) To VI0PR08MB10743.eurprd08.prod.outlook.com (2603:10a6:800:205::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI0PR08MB10743:EE_|AS8PR08MB10363:EE_ X-MS-Office365-Filtering-Correlation-Id: 11326a1f-e1b2-4c6a-0bc5-08dbd562d811 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +k6tUvuNXVPtpUJuahSc9s2LqvoZuhPy6NXnFRsg8hNNiu6CsxMj0oeCUMvGodQ9aQyBbrt042xl6T03gE7f7EUhzU87HkAnKHP6Q1BkzrI66jkpaATLNhAOWYO3nmtAamLD8Yzh7FZxO9uJJLtsXnqt3DvOwgRf4iAxHvKLHFzRHrRSFjRGMk+vgvDPyDy71y/tpR+yHXVKNY6JN1sTfl2zdqbZf2MbVVnyQvo/eGWV9Ba1JPqnJWsuGJN5epidpqvHvabBC9LPWaHgBkxIMHrYFqGoFPmxZx26UGWi7g/AI87UwIjP/d5sIqqd6TtmWgkV5D0mNvTqgVvSmXXE0I+uZ5P9DbiA+2y9VFseA3NDVLPJ1s8k8v2nuLG7sFzAPgkAUSVoUiaMmz7sRUDGq2x0+mf8WxsvHBslc7c0vBQEzqfwf57BJwrHAEEw428gYXB2oPcUiwucFeCi/Eaj5pOEaIFhUbBFNZft5MQ+dhtLocWYJJoP/bHgCRnVcL88nPcu9ZENx49iT47L0G+NCfFsTbWfdIot29wBdxy2aTFvfd+uEEt+czSVDb/OIzBg8oD40E34o1+067hjLsBYYDo4pycI6ERESubIM5VIBqXYN/vUoLtbEZN4Kn91dvxl X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI0PR08MB10743.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(396003)(136003)(346002)(39850400004)(366004)(376002)(230922051799003)(64100799003)(1800799009)(451199024)(186009)(2906002)(38100700002)(66946007)(2616005)(66476007)(316002)(66556008)(6916009)(6666004)(6506007)(478600001)(1076003)(6486002)(6512007)(52116002)(83380400001)(36756003)(44832011)(5660300002)(86362001)(4326008)(8676002)(41300700001)(8936002)(26005)(38350700005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?n63HpQFfKcctBt1gx8kgXrEd7aKzdnWZM6DuI/CjAc8Z5Lfx4sikKFMxOygT?= =?us-ascii?Q?BlNmHcClZSEEuU5/bOMJY7b+MruVcGweP7Y3dKLz+ZmG3XCZMQFtjLn1BLRS?= =?us-ascii?Q?itRhccS/Ww3l9jFTXUqHIYRwhWkO8+P7keXWrmInTUBw8LiiOU4ELrXE4Rvb?= =?us-ascii?Q?/zubOoVrgJ/1TyJ2V0sHohAHc90FUMVpkPi2vAlDrPBC1tKE3zig3y4uMzou?= =?us-ascii?Q?Hwa4cp/X1+cy/eAeDiHfxmBIzQaq2tV7CTc56C936dLH/fzHDcW3YFtkqUr0?= =?us-ascii?Q?nzy5T98XxjitgG9EoJ7MiOT3JsSyawHj3e+GLXG7WTVOoNyUmm3CdBQk7RIp?= =?us-ascii?Q?49KNWwc2yhXs5u1LLxHaXs8Tcj3Ds+CnwoLTMWP719Kh80Z1bTZOADZHMOoP?= =?us-ascii?Q?NAPa5f7A5k/sG1Bvg8T7PGIWOsskS7bo1dtEcknxJIA4ovdofJuIebfss6Y5?= =?us-ascii?Q?nSoCeONsClTzc430vXvTY9J/63PhO4gtLrL6DlUZ7/dRUzDssI7CLA+DxIiw?= =?us-ascii?Q?95FPEMB9dr4gHMr0jS8CEE37x0zA+B9DVmOCyHNiXDw3QXMAsYLEk0CyIjRh?= =?us-ascii?Q?RrP1S8rIlgSKIjFZ1rSG2RQ4mQVFHI1n0ZDaEgUfLW3jY3KRggwdSfn4ZcnW?= =?us-ascii?Q?Ppu+kUh21pExTOTIZhAeYoSCNKk9HtoDG4lVYFXnU3bd2ZDlgYGzbbnp+/G+?= =?us-ascii?Q?xWGietXKIoCApVqTtHuaqhN/QIPFGN81C/MwdG789HAfM58eBNRvhMTBI5gn?= =?us-ascii?Q?uniV+KWVU6F8PC+FrMSmodtJhbpi1xhRSSrci50EbfNVGSHKnCEHDFSnNQrJ?= =?us-ascii?Q?MWMg1lFT1LsPot+eJTMdEoPDiez/QQR/Tj/GlmElgaHvC+yCUlbJjna/yWus?= =?us-ascii?Q?EfNgfmdpcus/5tH6oer0Wzv6XDJdY/yfy6os6y9Pcf5htUVa+luPQiwcUoKx?= =?us-ascii?Q?l0ZctzdjULG0gLS4n9XHQ69Xm0pZQ0IVIdhN1FctpVVun9Yh7g/W2uhu3hpl?= =?us-ascii?Q?iZks7jFrdrHCNJ5xZ+es52LOrVrbvVfsc6XGH6P+jTo6AyZ7URfM7ztPyqqu?= =?us-ascii?Q?KVtRYrIw3FJltwQKN/d/u4zI15r3DXRaDogxqWdfl6vq+eIbO4s+Ekm9iHoV?= =?us-ascii?Q?cAz62O7RgMQfpxpcTUPDlsF+MTZxLcCppJi9aCZ2GFMbK4EKjSV0VOSEIj2K?= =?us-ascii?Q?DnQxWtTNIYb3+64oTPEH7O+cW7q+tfM3peoeoCgaGdAXiM1aLfm57vPF7NYc?= =?us-ascii?Q?1qggR3IiA6boSfYeP3V5EkDNZ8FMQygsVQdgD8pdejWUcAUNr7E1N/FubCBN?= =?us-ascii?Q?zLxE687SFIKHyBzQjG4WLJMufxoBP4QKy3f7R4MLrMwz2j6jebe2tXVrMEnR?= =?us-ascii?Q?XJGwv56jWUXf0lv6Tqvjk23Lcehk+wNe4l0JUyrdNNeYs4Uk1Zgbg4wKYr37?= =?us-ascii?Q?oKw+6MAQMU6B9FWm4jTu6Yodoh+dzs6ilkFsVOBHIdI6SZHJ5UaJWRwOCRio?= =?us-ascii?Q?SMZlZxLTFaRroWnGDvuqkUYsEa1CEJ6ib0ewhPK8rBWhK4mJ/Z+9VuTwuzi1?= =?us-ascii?Q?DFObRd2A2LmSLj6FdBslnwLIopSLtnORNJUK7aY8RJIG/Cp2aJ4od7Dd7n6n?= =?us-ascii?Q?mpY+yqVAcTMrOZJ2jiMI5Og=3D?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 11326a1f-e1b2-4c6a-0bc5-08dbd562d811 X-MS-Exchange-CrossTenant-AuthSource: VI0PR08MB10743.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Oct 2023 14:01:11.2829 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 9Is1rcGGaaJejeE/CW5knP7czwIhImGthyhmrkYlUocgjJdhExEMtdp+WzBZ9m4fe+me5e8JVjyd1aVk5ZCqtUbRxfAoge45qASHTwJd1vA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB10363 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=2a01:111:f400:fe0e::70f; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR04-VI1-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 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: 1698242550341100007 Content-Type: text/plain; charset="utf-8" In some cases it would be useful to thaw a filesystem by timeout after freezing this filesystem by guest-fsfreeze-freeze-list. Add an optional argument "timeout" to the command. Signed-off-by: Alexander Ivanov --- qga/commands-posix.c | 21 ++++++++++++++++++--- qga/commands-win32.c | 16 ++++++++++++++-- qga/guest-agent-core.h | 3 ++- qga/main.c | 19 ++++++++++++++++++- qga/qapi-schema.json | 9 ++++++++- 5 files changed, 60 insertions(+), 8 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 26711a1a72..e8a79e0a41 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -707,13 +707,17 @@ GuestFsfreezeStatus qmp_guest_fsfreeze_status(Error *= *errp) return GUEST_FSFREEZE_STATUS_THAWED; } =20 -int64_t qmp_guest_fsfreeze_freeze(Error **errp) +int64_t qmp_guest_fsfreeze_freeze(bool has_timeout, int64_t timeout, + Error **errp) { - return qmp_guest_fsfreeze_freeze_list(false, NULL, errp); + return qmp_guest_fsfreeze_freeze_list(false, NULL, has_timeout, timeou= t, + errp); } =20 int64_t qmp_guest_fsfreeze_freeze_list(bool has_mountpoints, strList *mountpoints, + bool has_timeout, + int64_t timeout, Error **errp) { int ret; @@ -734,8 +738,11 @@ int64_t qmp_guest_fsfreeze_freeze_list(bool has_mountp= oints, return -1; } =20 + if (!has_timeout || timeout < 0) { + timeout =3D 0; + } /* cannot risk guest agent blocking itself on a write in this state */ - ga_set_frozen(ga_state); + ga_set_frozen(ga_state, timeout); =20 ret =3D qmp_guest_fsfreeze_do_freeze_list(has_mountpoints, mountpoints, mounts, errp); @@ -780,6 +787,12 @@ static void guest_fsfreeze_cleanup(void) } } } + +gboolean ga_frozen_timeout_cb(gpointer data) +{ + guest_fsfreeze_cleanup(); + return G_SOURCE_REMOVE; +} #endif =20 /* linux-specific implementations. avoid this if at all possible. */ @@ -3119,6 +3132,8 @@ int64_t qmp_guest_fsfreeze_freeze(Error **errp) =20 int64_t qmp_guest_fsfreeze_freeze_list(bool has_mountpoints, strList *mountpoints, + bool has_timeout, + int64_t timeout, Error **errp) { error_setg(errp, QERR_UNSUPPORTED); diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 618d862c00..51fd6dcd58 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -1221,13 +1221,16 @@ GuestFsfreezeStatus qmp_guest_fsfreeze_status(Error= **errp) * Freeze local file systems using Volume Shadow-copy Service. * The frozen state is limited for up to 10 seconds by VSS. */ -int64_t qmp_guest_fsfreeze_freeze(Error **errp) +int64_t qmp_guest_fsfreeze_freeze(bool has_timeout, int64_t timeout, + Error **errp) { return qmp_guest_fsfreeze_freeze_list(false, NULL, errp); } =20 int64_t qmp_guest_fsfreeze_freeze_list(bool has_mountpoints, strList *mountpoints, + bool has_timeout, + int64_t timeout, Error **errp) { int i; @@ -1240,8 +1243,11 @@ int64_t qmp_guest_fsfreeze_freeze_list(bool has_moun= tpoints, =20 slog("guest-fsfreeze called"); =20 + if (!has_timeout || timeout < 0) { + timeout =3D 0; + } /* cannot risk guest agent blocking itself on a write in this state */ - ga_set_frozen(ga_state); + ga_set_frozen(ga_state, timeout); =20 qga_vss_fsfreeze(&i, true, mountpoints, &local_err); if (local_err) { @@ -1299,6 +1305,12 @@ static void guest_fsfreeze_cleanup(void) vss_deinit(true); } =20 +gboolean ga_frozen_timeout_cb(gpointer data) +{ + guest_fsfreeze_cleanup(); + return G_SOURCE_REMOVE; +} + /* * Walk list of mounted file systems in the guest, and discard unused * areas. diff --git a/qga/guest-agent-core.h b/qga/guest-agent-core.h index b4e7c52c61..d8d1bb9505 100644 --- a/qga/guest-agent-core.h +++ b/qga/guest-agent-core.h @@ -39,8 +39,9 @@ void ga_enable_logging(GAState *s); void G_GNUC_PRINTF(1, 2) slog(const gchar *fmt, ...); void ga_set_response_delimited(GAState *s); bool ga_is_frozen(GAState *s); -void ga_set_frozen(GAState *s); +void ga_set_frozen(GAState *s, int64_t timeout); void ga_unset_frozen(GAState *s); +gboolean ga_frozen_timeout_cb(gpointer data); const char *ga_fsfreeze_hook(GAState *s); int64_t ga_get_fd_handle(GAState *s, Error **errp); int ga_parse_whence(GuestFileWhence *whence, Error **errp); diff --git a/qga/main.c b/qga/main.c index 8668b9f3d3..6c7c7d68d8 100644 --- a/qga/main.c +++ b/qga/main.c @@ -94,6 +94,7 @@ struct GAState { const char *pid_filepath; } deferred_options; #ifdef CONFIG_FSFREEZE + guint frozen_timeout_id; const char *fsfreeze_hook; #endif gchar *pstate_filepath; @@ -478,7 +479,7 @@ bool ga_is_frozen(GAState *s) return s->frozen; } =20 -void ga_set_frozen(GAState *s) +void ga_set_frozen(GAState *s, int64_t timeout) { if (ga_is_frozen(s)) { return; @@ -492,6 +493,15 @@ void ga_set_frozen(GAState *s) g_warning("unable to create %s, fsfreeze may not function properly= ", s->state_filepath_isfrozen); } +#ifdef CONFIG_FSFREEZE + if (timeout) { + s->frozen_timeout_id =3D g_timeout_add_seconds(timeout, + ga_frozen_timeout_cb, + NULL); + } else { + s->frozen_timeout_id =3D 0; + } +#endif } =20 void ga_unset_frozen(GAState *s) @@ -500,6 +510,13 @@ void ga_unset_frozen(GAState *s) return; } =20 +#ifdef CONFIG_FSFREEZE + /* remove timeout callback */ + if (s->frozen_timeout_id) { + g_source_remove(s->frozen_timeout_id); + } +#endif + /* if we delayed creation/opening of pid/log files due to being * in a frozen state at start up, do it now */ diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json index e96d463639..29ad342f0a 100644 --- a/qga/qapi-schema.json +++ b/qga/qapi-schema.json @@ -440,6 +440,9 @@ # command succeeded, you may call @guest-fsfreeze-thaw later to # unfreeze. # +# @timeout: after this period in seconds filesystems will be thawed +# (since 8.2) +# # Note: On Windows, the command is implemented with the help of a # Volume Shadow-copy Service DLL helper. The frozen state is # limited for up to 10 seconds by VSS. @@ -452,6 +455,7 @@ # Since: 0.15.0 ## { 'command': 'guest-fsfreeze-freeze', + 'data': { '*timeout': 'int' }, 'returns': 'int' } =20 ## @@ -464,13 +468,16 @@ # If omitted, every mounted filesystem is frozen. Invalid mount # points are ignored. # +# @timeout: after this period in seconds filesystems will be thawed +# (since 8.2) +# # Returns: Number of file systems currently frozen. On error, all # filesystems will be thawed. # # Since: 2.2 ## { 'command': 'guest-fsfreeze-freeze-list', - 'data': { '*mountpoints': ['str'] }, + 'data': { '*mountpoints': ['str'], '*timeout': 'int' }, 'returns': 'int' } =20 ## --=20 2.34.1 From nobody Wed Nov 27 12:30:21 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; arc=pass (i=1 dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1698242571; cv=pass; d=zohomail.com; s=zohoarc; b=BfUOCOEuE+XBZPqsWMdlWq+jn1PP4TgS5WVFJQvJMYu5Ov03kE/reOXJGSdWwlHUJ96cjMEj5ajz3RE7TAPBCk3tGf9AmV4+EL/Qh5jzKS1utEMYEk0ETuCrZgi4kNuoqoVq52useX7SbHuaFWbj9/vaMlevvoJNLFNv+ZoKYkI= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1698242571; 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=01N/Pl1AxQGsNtLAbQit5+BT+FyXQfOr8XWNMb5DDj4=; b=FtTKgvFeGRB1sj6YsePYUqzc9BJcb7X1YFK/hFc1Jq3x8XCqkEVn3WX9SoxANk6nCaDg0G39OoI4bJe1TnnUkARW4ImWoLuMV/9WF3zwv/5/JtGeThZ3OIzlGmWuRQRENKD484N6ZznFq4aWBVAqTpz38AxnvcJ9mUhs9U9jsGM= ARC-Authentication-Results: i=2; 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; arc=pass (i=1 dmarc=pass fromdomain=virtuozzo.com); 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 1698242571478926.9665968877092; Wed, 25 Oct 2023 07:02:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qveS5-00041m-8V; Wed, 25 Oct 2023 10:01:41 -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 1qveS1-000411-2M for qemu-devel@nongnu.org; Wed, 25 Oct 2023 10:01:37 -0400 Received: from mail-vi1eur04on070f.outbound.protection.outlook.com ([2a01:111:f400:fe0e::70f] helo=EUR04-VI1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qveRw-0005dH-77 for qemu-devel@nongnu.org; Wed, 25 Oct 2023 10:01:36 -0400 Received: from VI0PR08MB10743.eurprd08.prod.outlook.com (2603:10a6:800:205::19) by AS8PR08MB10363.eurprd08.prod.outlook.com (2603:10a6:20b:56b::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.31; Wed, 25 Oct 2023 14:01:11 +0000 Received: from VI0PR08MB10743.eurprd08.prod.outlook.com ([fe80::22f7:6498:de53:5371]) by VI0PR08MB10743.eurprd08.prod.outlook.com ([fe80::22f7:6498:de53:5371%4]) with mapi id 15.20.6863.043; Wed, 25 Oct 2023 14:01:11 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UizAqPubzWY6XRfgAW8HwI2LUxXqObnCz3b3LI3vX2o8cGdaDvGJItbI261TxxspQu7yZP8TBVZ+3PUndYWLoarxIZa1JT6wcrSmbfliJUS5cdRKNgsPjWC7gQGx3Bd1/yrUf3Cn7ImiWwb3f8Sl672RsVPhIV+VEo8qJDmM3q539PC9zFFs9l3SF+fGhWKVqhdgf62lsZShWdiGnvGdBirQJJgxBaFw6KjTO8YYCm6mcuI5Q682KirXlKXPDRDUPqO7ZpdMrjvkdVMv2jcvvqZo7ouJ0vLt2ZZkPSCwmLhJyIKotv3k4xKTQ1qyC1dAH1Nn9shbg/FDdJ5DOfyCNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=01N/Pl1AxQGsNtLAbQit5+BT+FyXQfOr8XWNMb5DDj4=; b=Mo5Nh+bB6JPcPuO++epRKcKf9lYhCn2LhdOvDTDALIRHcBVmDzNIo7vadHoBA/N+efbdzxScCW+Cz4QXO82xkFs5sa+i7Wc9EtgsBstacdrhsF7hzGLI+gdnTso7Z5Zfk47Aw+zQ3S9QHtWICSCkuDDi8WtCaS/hsTHtjwOzQDOJZOqVGaqckBo6d+6E3ZW7JDMCWfwwdzzi5wMy/p63TgVmddvbPMKt2EKMhGKg0p0lnmYneurHUEeuAT138ssTeeMB67eRXnzuKszS9M39rUgTEBAkFM+gRocMAVo8KuVQfqzmYUGq5FnnU9mCd+vA9ZC15mRXL6J5wXkdFJlqWQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=01N/Pl1AxQGsNtLAbQit5+BT+FyXQfOr8XWNMb5DDj4=; b=D6vXQjwYz22CwFYc0PsPrah0OWDteZxO+UC/bW+S5IkodRZhmxkaBdNptsahrOFEfDhIpC+NTQtocqpL0jEe43NzpUUfpGdh0bURwnUkRYuDBnaiynrPaqSMmIpK2KfPuq6ZMOjBMrXahTT9AODBreSlUEFy6MteDlyTdXmp5USWiEJER9Xv+SCL1l6wsi0T44Fze66e81YhF5jDFgIkX7eacgNShbe97A4RFvL2mgXkr80v7M5tSoVY1Y3GaG996IAntdloSBlozFuxkcii8cx4f5mWp0eF6lABM6C/gBS0XU8qVNE/DRb+qQmmpTjotzawRJkoG1dOfvNEqN3QWA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; From: Alexander Ivanov To: qemu-devel@nongnu.org Cc: den@virtuozzo.com, michael.roth@amd.com, kkostiuk@redhat.com, marcandre.lureau@gmail.com Subject: [PATCH 6/6] qga: Cancel async snapshot before abort Date: Wed, 25 Oct 2023 16:00:58 +0200 Message-Id: <20231025140058.113376-7-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231025140058.113376-1-alexander.ivanov@virtuozzo.com> References: <20231025140058.113376-1-alexander.ivanov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: VI1PR06CA0167.eurprd06.prod.outlook.com (2603:10a6:803:c8::24) To VI0PR08MB10743.eurprd08.prod.outlook.com (2603:10a6:800:205::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI0PR08MB10743:EE_|AS8PR08MB10363:EE_ X-MS-Office365-Filtering-Correlation-Id: 415cd5dd-dc22-4261-596a-08dbd562d85d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: j1ywvobi7xwJcDhGQBMRLNT597WkCWgvxQJgB3RZYGTKriiW+iWiyJecKGXeD0hONJpNZ4jw7o5l2cYAcl67lsBQb+ljaTlJof4c0y0JubmAgcWzOS2OLWfWlJKKm5aetDpg3Gk0tfx2h3tLwOeSaxot6X7C3YB4Jd7peSdA2E9ROmzw0ty/u0+nPNUN8pi8FPVO+LqkE+7hFKBSTkOnGcjAQ7JE+4siXq5ihk7khFGBSz5c76tCQG8AwO6oBXkZFGoX7RUhK1lyqDF0eTzF0GBQ3sL2ncC6k1q3bt0J7k72GM69lFyiIqh+S51I2dMib2AFwTAoLOAbcrHzyuagpN+vQnquv3g0lZgJjSNNsWaNWYr9BjUvBV8vFvlKyEpltAKSmlM3m8K6FCA92uHJ0HAk014gUro5hamskvnu/yyzePwyzPxPTM9PGZaeoxjcstr0aNVw/XEYUxJ21PXi7G1rIY7RdF6TiOuDfia+brkHaVimAUU3oJWVsW81PfYNLjv0EjJhuBnkT1rhLZ1N2wcAucT8BNLCDvZJhnGEpn25UIJUtuGr2Z4ZdCc5fHMVerk+c41tBCthQJq7WqHLbndcMSY7NU9ABf+9xBje2o0jk7n3coizDq6avm2lerPR X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI0PR08MB10743.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(396003)(136003)(346002)(39850400004)(366004)(376002)(230922051799003)(64100799003)(1800799009)(451199024)(186009)(4744005)(2906002)(38100700002)(66946007)(2616005)(66476007)(316002)(66556008)(6916009)(6666004)(6506007)(478600001)(1076003)(6486002)(6512007)(52116002)(83380400001)(36756003)(44832011)(5660300002)(86362001)(4326008)(8676002)(41300700001)(8936002)(26005)(38350700005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?qHETaNjUaw0zHJ+ksOArBJZCJfeTLXkjm3YZKHNHNaSNi4Ps8oDbBMPiQUEh?= =?us-ascii?Q?2CgFD7kWuXVNFNk1nHBWGrSOfBKcCLPhe5l0dfEVJfnodEcycnoq+BE3yRxJ?= =?us-ascii?Q?gHQcRSsK1zo6C/+ZErtahLCPhT+HaSmmYxYYHONADDZsiFT4xLX8VeIb3aDi?= =?us-ascii?Q?kU9FfwdU7KTNgghWoRS9Qt2AU3UNtR1+r2IsxecmtcBeiwT8Y9U1rG9fTJcR?= =?us-ascii?Q?IbyE+erZGeOgE7+hUfIvToCLRnX7b0L4yVVoM5C4DHlzyCqI1EMbcEP3GNfH?= =?us-ascii?Q?u3MyNaqEun7E2Yn/nxrEyvylCJzXYlULCnmJura/frJc4nbFekko2c1irPjd?= =?us-ascii?Q?iH341fblPmsT4jrwFMbgD1+1Wco2BNy2cNZqC2FwTi9Z59YCaHjZ/3N6F3JD?= =?us-ascii?Q?ttvd7PnNZOFfV7yHMI+L3yYZGqYKn/YsTXT848CW9Ka/Sti1fD8YkgZXlIj9?= =?us-ascii?Q?zwEqHrRPD1/p9q2B0MZhLx9UBgcpA0ruM48Jw7v6MzDEcrkduAObzyru1khM?= =?us-ascii?Q?YmtKc9BdgGevdVyyLuy+2vAkL01+fsS1Nfbaj6L4kZnTB7HZasJFSMw2JeGp?= =?us-ascii?Q?kXPaHeNuHXgVJWsKTC5Lj1h7myZWb5nomGYgNLNAxbZ0XPTEy6eoOXkvI315?= =?us-ascii?Q?1YDv1IB6poPPTET1Xjfjq6QEtaFwXjQzIk+AvXeWdpqduupZXcncoSzfb7Vh?= =?us-ascii?Q?qcd7IOZ6D5SI0bszT6yN0xGxJKUIQ4hGvS/BL97SdGpfza6lw1igc15dZofq?= =?us-ascii?Q?0QvF8wWEm/L8+1NZXvMys3i/GBKwwxxhng9yCy8LU4xEFxJOysW+iM1UThjs?= =?us-ascii?Q?lIF2sck22pZqlUBj7DjWJzV0gRnQ0UtREAnttYIKHN8SptN5B4GloUJCDxOL?= =?us-ascii?Q?/QZgaH2k9yDJ0RPG5gCV7DgUmpO5WqRlG0stqtif3OtonhIf0KF7bZ8pf89E?= =?us-ascii?Q?K6MCZhgJbfQNei4wVE9GanyDUe7cBPXpSDFBHMK39nkiANicx6g49fX2v/nG?= =?us-ascii?Q?5baz5HKU2c6ExLI8yZDu2t77l5IhXCJlbivdo0zhH+hRbxbnPb0R8A8zpjNU?= =?us-ascii?Q?4j0kHpDZEE8lucDPpsW1/CHLrjButclATu9AalrzJKn23JQqAGnnWlO8ksZp?= =?us-ascii?Q?hH2dfn/l5ELKjft+8C6UNH6ZZkP47dazDOiQoCu/RghMI0xdGE0W/XOjb6OJ?= =?us-ascii?Q?FNFwwR5zT8Suxc2AChChrdvFzqoIn8MwI2pp+OkQQfPZV+kd74O2egVEyu9L?= =?us-ascii?Q?bKkAEABlPiU0JtCBV1f8kuyK+qXOKt1s7+b8SHrmZLXmpSNnujn00TWa2EgM?= =?us-ascii?Q?ePoMI03uPTOBL3wh1ybi/y2AJiDzCNbjY+j4VXt/PWP8KpeLmM+fLWM806dk?= =?us-ascii?Q?t2OdmlYWGbptqC/gaiCeBoBpzvh3jHA1OJs+rvqqTcIPxWDtmT9f3KFc844I?= =?us-ascii?Q?OQepsJqsILadcQ34EtdTSsGmAxvKTA4vwZBvHoM4XVMdI4fg+kc/34IGQog7?= =?us-ascii?Q?u56v3B/fNImPJIAL3CPeol6A8Xv/QRzGFRUiGf5HaEDSOZ1ROGYpIKG5VDc5?= =?us-ascii?Q?MVk/cp4voQ28HrvZUG0L+sdFDCaKA0AxUYKj/XYJ7F6d2MpG+75F5DR9MwTD?= =?us-ascii?Q?IsqZU9Wd2DL+2IlVAEPK1Wc=3D?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 415cd5dd-dc22-4261-596a-08dbd562d85d X-MS-Exchange-CrossTenant-AuthSource: VI0PR08MB10743.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Oct 2023 14:01:11.8217 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: FaoUfp1wz3SBGuQ1+4MrTmfHu2J2M2bh6NlYjDLi2sTqIYRir/aNB97ImVeLLNO/2j98w3KVBZVvgcDK08x0EzZRxradpoHpCC5esSA/6xs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB10363 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=2a01:111:f400:fe0e::70f; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR04-VI1-obe.outbound.protection.outlook.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 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, FORGED_SPF_HELO=1, SPF_HELO_PASS=-0.001, T_SPF_TEMPERROR=0.01 autolearn=no 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: 1698242572323100003 Content-Type: text/plain; charset="utf-8" VSS requestor calls abort after the timeout of the backup operation expires. In the result later the process hangs on some internal VSS lock. Cancel async snapshot before abort. Signed-off-by: Alexander Ivanov Reviewed-by: Konstantin Kostiuk --- qga/vss-win32/requester.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/qga/vss-win32/requester.cpp b/qga/vss-win32/requester.cpp index 9884c65e70..20680a42a1 100644 --- a/qga/vss-win32/requester.cpp +++ b/qga/vss-win32/requester.cpp @@ -533,6 +533,7 @@ void requester_freeze(int *num_vols, void *mountpoints,= ErrorSet *errset) } =20 if (wait_status !=3D WAIT_OBJECT_0) { + vss_ctx.pAsyncSnapshot->Cancel(); err_set(errset, E_FAIL, "couldn't receive Frozen event from VSS provider"); goto out; --=20 2.34.1