From patchwork Wed Oct 25 14:00:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 13436209 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AE715C0032E for ; Wed, 25 Oct 2023 14:02:52 +0000 (UTC) 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 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; 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 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> 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;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h5QOeBxgqttUBay6mV94uJiXRGupFC9r760rpMx12tawBqS4xVrCZMn9kguYdkFfLrYnjP6d6O+tCtSepp8rNT3Uezqg3UJ7/QW4d0KTau6e5ybwdZA2QwFND5bOZbtMgzVrrDI+XJp4hw3OnvSPBvGShRRvy9cTUhdxBrghec9SHdwqJwj4p4y+ll4oRbwUDSCad3Rt6cZ+3qVqYfb939ytzNDWWrL81gBsIqdVOVrOy6d1Gx58EB4n77ihfvbtUKj78WuZIYBTltTa95sh2UmP2gOeT+C31WH/O2xkusI55GUMVmhKi6zegMxKqmUgaC42lzos9d7AzyPwIyCQYQzQ7sNl9LLxa+aCns+dv/+t7X63GfwtbwEZZWK7MirqTQtRxOk4/drtI7Gg5rH4H9NGUYV9sbUhAcxPtf0mqfkbP06VLwhNUEYJod4RTEc8WsLMEmnmcMDHSJ4jBwqgPDos1kbVurJCDJxP4xsk50+PNZDnOQ2u9KIXQD4pNRPalQaJ4nVUVr4XSQFLHJdALmYmhZIEdpDr7jEo0/eL0Wjnsdy8mW//BK4XeTZxYpBXeqfkDT12ns8SksYwnAIhb41j1B9p8zcpARRxU9nPeEGVkLM= 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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 *gfh, */ char *qga_get_host_name(Error **errp); +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 #include "guest-agent-core.h" #include "vss-win32.h" @@ -2522,3 +2523,66 @@ GuestCpuStatsList *qmp_guest_get_cpustats(Error **errp) 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 = NULL; + bool added, success; + int res = 0; + + snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); + if (snapshot == INVALID_HANDLE_VALUE) { + return GetLastError(); + } + + pid_list = g_list_append(pid_list, GUINT_TO_POINTER(pid)); + + proc_entry.dwSize = sizeof(PROCESSENTRY32); + do { + added = false; + for (success = Process32First(snapshot, &proc_entry); + success; success = Process32Next(snapshot, &proc_entry)) { + gpointer ppid_p, pid_p; + ppid_p = GUINT_TO_POINTER(proc_entry.th32ParentProcessID); + pid_p = GUINT_TO_POINTER(proc_entry.th32ProcessID); + if (g_list_find(pid_list, ppid_p) && !g_list_find(pid_list, pid_p)) { + pid_list = g_list_append(pid_list, pid_p); + added = true; + } + } + } while (added); + + for (success = Process32First(snapshot, &proc_entry); + success; success = Process32Next(snapshot, &proc_entry)) { + if (g_list_find(pid_list, GUINT_TO_POINTER(proc_entry.th32ProcessID))) { + g_debug("killing pid=%u ppid=%u name=%s", + (guint)proc_entry.th32ProcessID, + (guint)proc_entry.th32ParentProcessID, + proc_entry.szExeFile); + } + } + + CloseHandle(snapshot); + + for (pid_entry = pid_list; pid_entry; pid_entry = pid_entry->next) { + pid = GPOINTER_TO_UINT(pid_entry->data); + process = OpenProcess(PROCESS_TERMINATE, FALSE, pid); + if (process == INVALID_HANDLE_VALUE) { + if (!res) { + res = GetLastError(); + if (res == ERROR_FILE_NOT_FOUND) { + res = 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; } +void qmp_guest_exec_terminate(int64_t pid, Error **errp) +{ + GuestExecInfo *gei; + + slog("guest-exec-terminate called, pid: %u", (uint32_t)pid); + + gei = guest_exec_info_find(pid); + if (gei == NULL) { + error_setg(errp, QERR_INVALID_PARAMETER, "pid"); + return; + } + + if (gei->finished) { + return; + } + +#ifdef G_OS_WIN32 + char buf[32]; + int res; + + res = kill_process_tree(pid); + if (res != 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 != 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': 'GuestExecCaptureOutput' }, 'returns': 'GuestExec' } +## +# @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' } } ## # @GuestHostName: From patchwork Wed Oct 25 14:00:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 13436204 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4AE8AC07545 for ; Wed, 25 Oct 2023 14:02:02 +0000 (UTC) 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 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; 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 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> 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: yWq0Xd0THeXnK6nj+jjtjFwMazsRtquS4W+AL/2FnuT4rzv6IUYTniSNerTC7OPrr6Amnw00yjRw3sRvCf9Sfy08J6ZeVlEJz5WYIXydISUhH4mRQTLkQgyVCQbV1wUtnVlEIV0eX5vhQnoPo4zTc9hB85V6icAXqMWBdW4LuTBv8qiOVP10NxBbADoca7VSCLUOJntAQQOR5dBT6yd1Z52EA6JGEqmj2PcKte4X2XuRyTCO85yeynO+eLQTOtVv+0r9Ve2bcTIDou6YG5b0ns34/I/tkqBvk6i1+XBDm5qAWwUGOjfBI+aomPi6fH+BmC3Yjson38/2g1H7rOn3BdaZUNjoxuBoLbUWi+95v5Oa/bBc3jqfS8/kFRZ9GG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ljYZuKU5yCUaCLqWBIRrlr0dDIf1TLyAUB1L7OrfObAlUW+/oneZgFvN7QWYqzuGVl5WjaNP74cQG5QnHzqu5sbMPtLlV+WQbFdOIfVUbyWVEVg+18B384+1NikxJRWfOiWsSbaOQ+N8OMFK/lF6vX/myumb15Kigiie0PVl9ALm52M6UToKYLKX5eK+vjvW/AM/4= 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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(GuestLogicalProcessorList *vcpus, Error **errp) #endif /* __linux__ */ #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 **errp) { Error *local_err = NULL; - char *passwd_path = NULL; pid_t pid; - int status; + int in_len, status; int datafd[2] = { -1, -1 }; + + if (!g_unix_open_pipe(datafd, FD_CLOEXEC, NULL)) { + error_setg(errp, "cannot create pipe FDs"); + goto out; + } + + pid = fork(); + if (pid == 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] = -1; + + in_len = strlen(in_str); + + if (qemu_write_full(datafd[1], in_str, in_len) != in_len) { + error_setg_errno(errp, errno, "cannot write new account password"); + goto out; + } + close(datafd[1]); + datafd[1] = -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] != -1) { + close(datafd[0]); + } + if (datafd[1] != -1) { + close(datafd[1]); + } +} + +void qmp_guest_set_user_password(const char *username, + const char *password, + bool crypted, + Error **errp) +{ + char *passwd_path = NULL; char *rawpasswddata = NULL; - size_t rawpasswdlen; char *chpasswddata = NULL; - size_t chpasswdlen; + size_t rawpasswdlen; rawpasswddata = (char *)qbase64_decode(password, -1, &rawpasswdlen, errp); if (!rawpasswddata) { @@ -2155,79 +2213,26 @@ void qmp_guest_set_user_password(const char *username, passwd_path = g_find_program_in_path("chpasswd"); #endif - chpasswdlen = 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 = fork(); - if (pid == 0) { - close(datafd[1]); - /* child */ - setsid(); - dup2(datafd[0], 0); - reopen_fd_to_null(1); - reopen_fd_to_null(2); - + const char *argv[] = { #ifdef __FreeBSD__ - const char *h_arg; - h_arg = (crypted) ? "-H" : "-h"; - execl(passwd_path, "pw", "usermod", "-n", username, h_arg, "0", NULL); + 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] = -1; + }; - if (qemu_write_full(datafd[1], chpasswddata, chpasswdlen) != chpasswdlen) { - error_setg_errno(errp, errno, "cannot write new account password"); - goto out; - } - close(datafd[1]); - datafd[1] = -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); out: g_free(chpasswddata); g_free(rawpasswddata); g_free(passwd_path); - if (datafd[0] != -1) { - close(datafd[0]); - } - if (datafd[1] != -1) { - close(datafd[1]); - } } #else /* __linux__ || __FreeBSD__ */ void qmp_guest_set_user_password(const char *username, From patchwork Wed Oct 25 14:00:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 13436206 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3AACEC25B47 for ; Wed, 25 Oct 2023 14:02:29 +0000 (UTC) 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 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; 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 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> 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: j9f6H22wxaouXW8fyDhrR2oelx4eRMgBsd/tvDrx6JDhezlXawlriUaTumczwNAViv7JAUEfNdUBNIUpry4twhIkKVgszhVDPuHyUV6IAsnSm1CQDP7eflnz/W0dSBDiI3rOUwqsYHn+RRjqcNiRe5rtWyvhBhpK64xc5G8uAhXXNDKtl6cLiLKl8Zfxp9rB7JfymgAdpNflW6qOrP0bguX5vPRqX5DSEdwBCVzC1flSo7gAm/QqUtfD41QfgF3jivcmtMMcucf9th8zlKXVxRY2GK6hEdFmnbhCDpHyCWzbMoZPSaz0m/mMbL/NoY6Duck2poXkwTHqs13cjTcoXHlhHVqTaJXfU4SQQtyQW2cC2OJX9br2CHhJvagnDTumwNNrLTHkmEF29RCIoWh8tgCjwp90IhKSba0CdZGbx/hENJwRm9DlIoEB/i7sFurMUA/+Sp+gXc3wlpwt1M24XI3Q3eVoVHyJCSGUE+3CBQw27OTTjuaANwJ3k6pZmCha4noHqNNhsGnB/5GiJIHkQri68tFXt55EB2q5LbvVaOQzd3c+SknmjUJvnpTYMOZnjWr/nCXMCzdRXLrXYg/A2eDc7LetbFubNr+NLi+nZ7l71ucCTOOIR24lEPiJXSQkVrvL1DqRj8ai6OIzhfSaC0HEvCQB2Ipq/k+UF4tOWxVaas/JMWBgfO4Hwhx8EUpsX20MouPC3v/C/cEEiSzKmSvIFILmEUvI0SLssNXlGn0wTvU/+Qv/IkugeFqnt8kakCeX0iuegyTehFOsf24+cE+coUJ73WhsFzJHdaFxLo5KQ0V8YYeKgAQb/4NvnRHOndebR1GZDuNw+kEcxiSrqLASM7lF5Ocfls0kh8QndF2ejtfaFkWFYOzhpZbVqKGKP/Wdsu4ZTyiwGVeXwBJBOytF6kvbrOguhhHnuePFOiykWCzBzCJR8hTlT6f8LssvC5lSK+pTxT/98sB8EL0OaHzvKgL3p6svEpa+2d+9WIo56w65viooY/bTYETWtIYGtdHI8NOzsM7AN03lLtYa2q5obC3C0EQ5H1vknANZb4aS0URcYM+Q2no5oDfxa2pUSnhZp7hRT3n1mmKk48Lan1B4oKcOSvDAGvSBR3T3LhW6QfWCH/XMqZzQOx++el4JgfghwK2mbtwX6yVysPwcL9JS529Hbl2J5lGj3GXtY2kj2Qa8hBWjy411D1ZAnhUQEI1hBsRw9t0ashHjZ22cQBqf5noFzaCtlkp13qYXl+kjeP8kDczlax0UvUg08mQi8kaFXzVPFoLSYDiaqiL0J16lc8jS21Io1I5SsiR2yU6p2k/AY3OaaQMxXyWLcyybUZxsw8YkzsLQQGLDNmQK+u2Af+KWWpI2JDGxVuBErWwdwzxqQzGUXW1b+9PCnQXodbSHNA9YaToyQatYrdDNnBdUJGXfH5EpbpuifnYoQeqL85R0lLY4fFadPrqrXFCRN1etafTBnkgFF9tisD1oN6XYwwwa7nnhM8JV87oV/miqhbiq6022EctZ15L8peFxGb3BxSvFJYvhl/KSfd5nwyIp/cu7qwTf88m5/5rRWlI+7mcOBQjYJVf4uSuUCW8QBATgmNjfIOaTGQlPuXr34DGBMYyoWp/767kEicMVVG4= 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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 char *in_str, Error **errp) int in_len, status; int datafd[2] = { -1, -1 }; - 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; + } } pid = fork(); if (pid == 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); @@ -2141,17 +2147,20 @@ static void run_command(const char *argv[], const char *in_str, Error **errp) error_setg_errno(errp, errno, "failed to create child process"); goto out; } - close(datafd[0]); - datafd[0] = -1; - in_len = strlen(in_str); + if (in_str) { + close(datafd[0]); + datafd[0] = -1; - if (qemu_write_full(datafd[1], in_str, in_len) != in_len) { - error_setg_errno(errp, errno, "cannot write new account password"); - goto out; + in_len = strlen(in_str); + if (qemu_write_full(datafd[1], in_str, in_len) != in_len) { + error_setg_errno(errp, errno, "cannot write new account password"); + goto out; + } + + close(datafd[1]); + datafd[1] = -1; } - close(datafd[1]); - datafd[1] = -1; ga_wait_child(pid, &status, &local_err); if (local_err) { From patchwork Wed Oct 25 14:00:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 13436207 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 58833C0032E for ; Wed, 25 Oct 2023 14:02:29 +0000 (UTC) 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 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; 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 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> 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: +oSLuH/uBl9+ap7TEmj4S9CC+TJeKbPAr8C2bQHnlHxXhwG1iw0taAqI3qKYRTRMsd90+jciHlaWCWo/NumQSHr5G/AZV/pFA8f2obw6Pwjc5M2OknqtYKUTCQ9ruFufaVszGqvYaUZCqkDyyfHqaYSCSvjjkGe3cmLmCRYcJLCalFK5Cv4YAimrCTvhdaxa9vtsJ+eO+quEbE08pUdO++4AvSFtQ0nDWwzzzIPq5na1ZNITUE9shmnp+scCAmG6/5YcNaSRNQmdRjtEf6kqoGRLn7flyR6G+S3Z5DbtbxK0ibRVQ40oX4Gj4FQc10RXRK+UdEKYJFl4bcMRQw6LcIHwOWHv7UDbakDrrsv3VQ0MZMmgpWYpV2Z9zURetVLs8CMxRX+cwQgPBsfDdOvvqCKxtcKSjPmduGSesATPVPHlUP+h6185GnnnrNo5sbB08oZaCUdWAlZE2NFYPOSDwybyf/Hy9nrmx4QpFI8l+OC63W7zHQj8y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DHxooHpllFggYzzELZigzTwVRL60/aPUtvs8ShX4H5Vj1FA= 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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 = NULL; @@ -2227,6 +2228,24 @@ void qmp_guest_set_user_password(const char *username, goto out; } + /* create new user if requested */ + if (has_create && create) { + char *str = g_shell_quote(username); + char *cmd = 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[] = { + "/bin/sh", "-c", cmd, NULL + }; + run_command(argv, NULL, errp); + g_free(str); + g_free(cmd); + if (*errp) { + goto out; + } + } + const char *argv[] = { #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 *username, goto done; } + if (has_create && create) { + USER_INFO_1 ui = { 0 }; + + ui.usri1_name = user; + ui.usri1_password = wpass; + ui.usri1_priv = USER_PRIV_USER; + ui.usri1_flags = UF_SCRIPT | UF_DONT_EXPIRE_PASSWD; + nas = NetUserAdd(NULL, 1, (LPBYTE) & ui, NULL); + + if (nas == NERR_Success) { + goto done; + } + + if (nas != NERR_UserExists) { + gchar *msg = get_net_error_message(nas); + error_setg(errp, "failed to add user: %s", msg); + g_free(msg); + goto done; + } + } + pi1003.usri1003_password = wpass; nas = 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' } } ## # @GuestMemoryBlock: From patchwork Wed Oct 25 14:00:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 13436205 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 24388C07545 for ; Wed, 25 Oct 2023 14:02:29 +0000 (UTC) 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 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; 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 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> 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: n63HpQFfKcctBt1gx8kgXrEd7aKzdnWZM6DuI/CjAc8Z5Lfx4sikKFMxOygTBlNmHcClZSEEuU5/bOMJY7b+MruVcGweP7Y3dKLz+ZmG3XCZMQFtjLn1BLRSitRhccS/Ww3l9jFTXUqHIYRwhWkO8+P7keXWrmInTUBw8LiiOU4ELrXE4Rvb/zubOoVrgJ/1TyJ2V0sHohAHc90FUMVpkPi2vAlDrPBC1tKE3zig3y4uMzouHwa4cp/X1+cy/eAeDiHfxmBIzQaq2tV7CTc56C936dLH/fzHDcW3YFtkqUr0nzy5T98XxjitgG9EoJ7MiOT3JsSyawHj3e+GLXG7WTVOoNyUmm3CdBQk7RIp49KNWwc2yhXs5u1LLxHaXs8Tcj3Ds+CnwoLTMWP719Kh80Z1bTZOADZHMOoPNAPa5f7A5k/sG1Bvg8T7PGIWOsskS7bo1dtEcknxJIA4ovdofJuIebfss6Y5nSoCeONsClTzc430vXvTY9J/63PhO4gtLrL6DlUZ7/dRUzDssI7CLA+DxIiw95FPEMB9dr4gHMr0jS8CEE37x0zA+B9DVmOCyHNiXDw3QXMAsYLEk0CyIjRhRrP1S8rIlgSKIjFZ1rSG2RQ4mQVFHI1n0ZDaEgUfL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-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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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; } -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, timeout, + errp); } 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_mountpoints, return -1; } + if (!has_timeout || timeout < 0) { + timeout = 0; + } /* cannot risk guest agent blocking itself on a write in this state */ - ga_set_frozen(ga_state); + ga_set_frozen(ga_state, timeout); ret = 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 /* linux-specific implementations. avoid this if at all possible. */ @@ -3119,6 +3132,8 @@ int64_t qmp_guest_fsfreeze_freeze(Error **errp) 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); } 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_mountpoints, slog("guest-fsfreeze called"); + if (!has_timeout || timeout < 0) { + timeout = 0; + } /* cannot risk guest agent blocking itself on a write in this state */ - ga_set_frozen(ga_state); + ga_set_frozen(ga_state, timeout); qga_vss_fsfreeze(&i, true, mountpoints, &local_err); if (local_err) { @@ -1299,6 +1305,12 @@ static void guest_fsfreeze_cleanup(void) vss_deinit(true); } +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; } -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 = g_timeout_add_seconds(timeout, + ga_frozen_timeout_cb, + NULL); + } else { + s->frozen_timeout_id = 0; + } +#endif } void ga_unset_frozen(GAState *s) @@ -500,6 +510,13 @@ void ga_unset_frozen(GAState *s) return; } +#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' } ## @@ -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' } ## From patchwork Wed Oct 25 14:00:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 13436208 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1F4DDC07545 for ; Wed, 25 Oct 2023 14:02:51 +0000 (UTC) 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 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; 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 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> 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-Ex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RbxbnPb0R8A8zpjNU4j0kHpDZEE8lucDPpsW1/CHLrjButclATu9AalrzJKn23JQqAGnnWlO8ksZphH2dfn/l5ELKjft+8C6UNH6ZZkP47dazDOiQoCu/RghMI0xdGE0W/XOjb6OJFNFwwR5zT8Suxc2AChChrdvFzqoIn8MwI2pp+OkQQfPZV+kd74O2egVEyu9LbKkAEABlPiU0JtCBV1f8kuyK+qXOKt1s7+b8SHrmZLXmpSNnujn00TWa2EgMePoMI03uPTOBL3wh1ybi/y2AJiDzCNbjY+j4VXt/PWP8KpeLmM+fLWM806dkt2OdmlYWGbptqC/gaiCeBoBpzvh3jHA1OJs+rvqqTcIPxWDtmT9f3KFc844IOQepsJqsILadcQ34EtdTSsGmAxvKTA4vwZBvHoM4XVMdI4fg+kc/34IGQog7u56v3B/fNImPJIAL3CPeol6A8Xv/QRzGFRUiGf5HaEDSOZ1ROGYpIKG5VDc5MVk/cp4voQ28HrvZUG0L+sdFDCaKA0AxUYKj/XYJ7F6d2MpG+75F5DR9MwTDIsqZU9Wd2DL+2IlVAEPK1Wc= 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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) } if (wait_status != WAIT_OBJECT_0) { + vss_ctx.pAsyncSnapshot->Cancel(); err_set(errset, E_FAIL, "couldn't receive Frozen event from VSS provider"); goto out;