From patchwork Mon Oct 3 09:39:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 12997415 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 DFE89C433FE for ; Mon, 3 Oct 2022 09:53:26 +0000 (UTC) Received: from localhost ([::1]:37910 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ofI8b-000820-Lr for qemu-devel@archiver.kernel.org; Mon, 03 Oct 2022 05:53:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50374) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofHvB-0006Oo-Fm for qemu-devel@nongnu.org; Mon, 03 Oct 2022 05:39:35 -0400 Received: from mail-eopbgr80119.outbound.protection.outlook.com ([40.107.8.119]:34208 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 1ofHv7-0002U6-UL for qemu-devel@nongnu.org; Mon, 03 Oct 2022 05:39:31 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ux8oBh1f6EBlyGTF8wBZZtbi6Fk9dHAM5pMVu+wiwr/lCcwq64eH3Fprj6P8CMhYk5RrSo4czl7jU8kob0nzkxWqnrISkKRnCjp54+wubMc6CJWScvl4Yu3vdy3DHewlN2t3bAYIAr9yNoM4pnHLlMbLyNpUoGmbkCcj/myeMtjwHf5CoClmk6ycA7Smtk2Q3xXnUMOSM8ZynlDi87xoJweI3X6n5wa+BOataKCqMijvgT/vEfolN1Lm02pMI0d2VTeSZVU+42wONfI66aG/HjT6whGJwb4Siwrao3Wd9fogrTKPul92EIhVDLBrcx7TOb9r7TaU5mjxgDX+g5MHoA== 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=T/82Gl6voQJFtnW6vuop4f0r45SnstBbJM5MVYGtscM=; b=aoLGrA4LvGofQQUvNplA34koRcWadNuNpCIJEewUG2d2InOM/AOKe6JC+OgNlKt91jqkJvs2wK4WW5LdTPQ4whC+AnZK8VbavIDXgFW37CxnTeOWLsiXFQQR6mbNubV43MwhLWNqn055kzspIw38fqDiifLeFX5T3ST6A5J0rC1tnuAQbCFHqq5h3En8UX+2OdTXjnojeoYYDGTTK3wc9/mIupOqq5PoJsmZAFQZx5oiEkksiW6ni41SvpmQHoc+5lU80MbMPLqeSgMxrG+E0gqgcAAMusy4PJHzCy6YdLfpZKx+39NmaK6GPRf4XThwVcvPGBtuMaepv0j5dAk0Zw== 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=T/82Gl6voQJFtnW6vuop4f0r45SnstBbJM5MVYGtscM=; b=EU7fTeUopTQCipHEahLyDTgUm647tyTYwAr7OAPc7psPAB/DwHvUXNu3oDp3vidCrZJOE0gWUhJ5WQrWfiS/jlzHwpl+9qWGh07UiO/GPAQvWgNRSce3A/Wywfn7tS5AePRb1ZVbK2NnmfMvxfmxtzTeF9u9BRyS5ao6dKiSqHZntIyIUYNaMOfr2GivOpDjRoUzEH/ui+E6cgitA5dlwLnYNHWxSINaQwD2caVpBHUGwU/Mv/JMfsU16cyB4AnNw/htmgrok+m+mM6EbpJeSkwefdLkH8pXJBeLFF22nnAzsOIt8qqjFhn1pHln1I/KEx5wmmI4/gKcY6swnvBPAw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) by DB9PR08MB8203.eurprd08.prod.outlook.com (2603:10a6:10:39e::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5676.17; Mon, 3 Oct 2022 09:39:21 +0000 Received: from AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::5174:25c7:6df8:741b]) by AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::5174:25c7:6df8:741b%8]) with mapi id 15.20.5676.028; Mon, 3 Oct 2022 09:39:21 +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 v3 1/7] qga: Add initial FreeBSD support Date: Mon, 3 Oct 2022 11:39:05 +0200 Message-Id: <20221003093911.1844031-2-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221003093911.1844031-1-alexander.ivanov@virtuozzo.com> References: <20221003093911.1844031-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: FR3P281CA0096.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a1::8) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR08MB7095:EE_|DB9PR08MB8203:EE_ X-MS-Office365-Filtering-Correlation-Id: bd3df395-eb79-4c2d-0ba7-08daa523262b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QowE5Djl3zDKrLCbribcnCjz5PODm8Izlg+6tXl+vPGiVGm8ojxG0o5RtzGQPGcCcR71C26wTpbbj85BL1SpI7CjwJvlPGb1u+4KyifHMMlJbc1wq6emPHF7bMyqFQ38z/STx70Mpu/ivat8o6LfpOsi8APXKTj5Ve5iy8svwh9981FXJ+6sJCVqpCgu7osIRdFqh5T1LFeEH/bzMbmbkmIT77TyEOtq3P7A1R10MsgBO63WAfqZcFzWboxSrIrdkWqiGa1wDZ1ZY1sxmN2Z2wb7pHqwR5aU8MXHuaBMfBuxtBB4XFVrm9AFqmAg7MI7lraR9V3CrbapJlh3sEzdSKFeDC1McKPD9BanvxcyNQyLwA3YmVGioeprWWF7G2WQ8WGumV0DJVTJCa5v0np4isuEEmLPOaAwzSSVTEwDxj9zrdkERQpQQyzbVNxzXDI+zRg59r0pMVZfwK3Oq7iQyJn9MJrvBnyeivKkyn6efVKvLPDlCEtAh4LG8JwPJcX+0s6zVJ3b5jbxVqU48hNIsPi5xKFk9zncsxtUeaL4KCQ0UWY3uZ9ZsPwtBTgJOdj11c89asK6guosP41XWRBwEVOv2At1lJREA2KFMJN/dgZ4SyXKoBOY6MOrZ2H2l+fVUx28HnKF2Jg0NWL0xyRDb2NFRx6pJuh56SLlYgUlLJGhWJYGG4RVmJOx9Sp3AdvSvuzr9bJaG0nFTMpieaFNGzdmMCbXTFydxRebPMEZGCsBTx8MGht+gmyD4ckxxkpH7jsyn9RmAj1EMa+WuqHndg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR08MB7095.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(4636009)(366004)(136003)(346002)(39850400004)(376002)(396003)(451199015)(6666004)(316002)(66476007)(66556008)(26005)(4326008)(8676002)(6512007)(6506007)(52116002)(2616005)(6916009)(478600001)(6486002)(66946007)(36756003)(38350700002)(38100700002)(86362001)(186003)(83380400001)(1076003)(44832011)(41300700001)(8936002)(5660300002)(2906002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 7B4OJt2Ztl7t6CasEoVyGY7DpHtQANTUeUt+ydUxG6c1+Ee2RVJ+xe6N95OYUq2WqxSj5kLSLx4+zU06MzuquEDtNSHWRJ8oZ0eX9G97r0twOpaPkDHUyHWn88LaIR2qaO1jfbFnZwC/Xoej2KKENLO4LeKmx7MC4CAzgnEacENgRH0atP8RxqJdAmUa32lu0cEXQe7tlvEZiX1OXa12hInvtQ/FZUpGwc71RGJqLyPIjOEdnZ7vAeOJvcSToSYjK7d+RvKj/mm9BUVMTKESY4hi15PwIHZT2K2F8TcviPMfkuXtiXNyGmnRVV8SGXu9XXQMRLZXS/QH1ptulDRS2bd0GcA2+JonY82eO5JTv0e07RgX/kLyGgczC/w64AsfQmJTuGPDn/YYFdQU+Jb7NYQayNDM8V03ESHBWMB+E/2FIY7SF/5Z4tOjTWkxpeYLOmQXlPZLHPWMqGnEYPTIgiZpbiHHIDKAhxp5KBFcCuI2ynbfTgkTmB2LiVcxwR2LvgeXMxQavyrmtCUZQFLs9tRxkTZQ2x64iXESba0J3gU8bvtdwuzU0ncjA5fkbreA0bWUDWZTTiq4zEMG9iU5ZQ9twpOQiYWclfg18RHIaCHaG58EL1QSCcH8d8v/vzWy8G68HEcRPHs3lGDPIZwmEhMQHAwGfVPh6O/bPpSq+tvO7lSQTimU1W+X/QABPo3SUSr6w7M+I4JKw1RgL3fZAdjmSq59cxlgs4q8s340IUNRtaYek8UXJGQpRvg+WCMEmIViRQtnq3fQItzdW/IDq9zhULttBHecd+J+/L1bjusYd1ZW06y2o+zNI6WbUb+3kNd/FiqO5u5I3y0gfwq/Mg9GwD8aN7iTlCa2fb4Vfy0ujvqtVlrhDcnInbokzzOD9wVXJxASYdd/gB9dF2IZvx7oX/VkbRTiZXIU4SIFDoOk1IuPlZpZebORd3C20KhbqJywfJmN4YMEqVy6O7JpM/KQ5FIW9zFnJq8wM6g5FyHXDGSf7Ol7R20+pa9209XNa5iOZzUa57smxvAx5VgqYlqHIiQsKZx6Xr+ey9n8FtzvZkCgT3YPhlz1m/WIKJ6IP1VHqks/Unwks1sZPPvAKfyTCN4StlFc4e2ybuOC3wpuN1DbSg+BINRigF6fPm1u4ACT4xMs98BqeLgHUqUIoS6apRhRMVt0nyJwq98aA9PMzg1c4eohThA8HBjz+xnWSme7PNglQCEQ8apTL6AqsDSCSC1W3Hjj6HNlUtVQ1hcNgJ98qhXnsJoGcgP9Dddoa59euGQOG7tZ8taotnM1ckCtTE7TSd7rfOtRAbUhW7bFu2rkxLA309m00tkSNIiySt0RkNjk+U0/6HxK1A71bmlyEQuQTLcjmAewuJtWCoDm5j/wbhDWZdhwRmArmeiOGyOiYn2jAuKtBIgWPC8YeqyqO8kvHHBk/m1JFXmODzNIEUafl9iLdrXKZDE8W90erdMA49RjVLWzaMljxGgkjAixSJ7oCsVg1fBLoRJ87Ctg6BhGacT59JiR1PKvEbH9JRk0B04SuffRnEQ4GhDd3S7OAgCeEMQRAoeJp/7+qScPiQspztacIuPDi/tIVJE9cTkdVxxbyri7S2h7OrDuzQ== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: bd3df395-eb79-4c2d-0ba7-08daa523262b X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Oct 2022 09:39:21.3997 (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: NtDZMVaOvDuggAf1g3DLKQTjYPKz69MK/3iA8yXi4ux8kp6g8lrWKTv573XeCRSYyt3R8AZjaE9vYrY2ModqpUmaQEYA8OXTk5WnnTWEvCg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR08MB8203 Received-SPF: pass client-ip=40.107.8.119; 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, 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" - Fix device path. - Fix virtio-serial channel initialization. - Make the code buildable in FreeBSD. Signed-off-by: Alexander Ivanov Acked-by: Marc-André Lureau Reviewed-by: Konstantin Kostiuk --- meson.build | 2 +- qga/channel-posix.c | 19 +++++++++++++++++++ qga/commands-posix.c | 8 ++++++++ qga/main.c | 6 +++++- 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index 8dc661363f..5c11abc8aa 100644 --- a/meson.build +++ b/meson.build @@ -75,7 +75,7 @@ have_tools = get_option('tools') \ .allowed() have_ga = get_option('guest_agent') \ .disable_auto_if(not have_system and not have_tools) \ - .require(targetos in ['sunos', 'linux', 'windows'], + .require(targetos in ['sunos', 'linux', 'windows', 'freebsd'], error_message: 'unsupported OS for QEMU guest agent') \ .allowed() have_block = have_system or have_tools diff --git a/qga/channel-posix.c b/qga/channel-posix.c index 6796a02cff..568350ded4 100644 --- a/qga/channel-posix.c +++ b/qga/channel-posix.c @@ -149,6 +149,25 @@ static gboolean ga_channel_open(GAChannel *c, const gchar *path, return false; } #endif +#ifdef __FreeBSD__ + /* + * In the default state channel sends echo of every command to a + * client. The client programm doesn't expect this and raises an + * error. Suppress echo by resetting ECHO terminal flag. + */ + struct termios tio; + if (tcgetattr(fd, &tio) < 0) { + error_setg_errno(errp, errno, "error getting channel termios attrs"); + close(fd); + return false; + } + tio.c_lflag &= ~ECHO; + if (tcsetattr(fd, TCSAFLUSH, &tio) < 0) { + error_setg_errno(errp, errno, "error setting channel termios attrs"); + close(fd); + return false; + } +#endif /* __FreeBSD__ */ ret = ga_channel_client_add(c, fd); if (ret) { error_setg(errp, "error adding channel to main loop"); diff --git a/qga/commands-posix.c b/qga/commands-posix.c index eea819cff0..16d67e9f6d 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -51,6 +51,14 @@ #endif #endif +#ifdef __FreeBSD__ +/* + * The code under HAVE_GETIFADDRS condition can't be compiled in FreeBSD. + * Fix it in one of the following patches. + */ +#undef HAVE_GETIFADDRS +#endif + #ifdef HAVE_GETIFADDRS #include #include diff --git a/qga/main.c b/qga/main.c index 5a9d8252e0..0d27c97d38 100644 --- a/qga/main.c +++ b/qga/main.c @@ -45,9 +45,13 @@ #endif #ifndef _WIN32 +#ifdef __FreeBSD__ +#define QGA_VIRTIO_PATH_DEFAULT "/dev/vtcon/org.qemu.guest_agent.0" +#else /* __FreeBSD__ */ #define QGA_VIRTIO_PATH_DEFAULT "/dev/virtio-ports/org.qemu.guest_agent.0" -#define QGA_STATE_RELATIVE_DIR "run" +#endif /* __FreeBSD__ */ #define QGA_SERIAL_PATH_DEFAULT "/dev/ttyS0" +#define QGA_STATE_RELATIVE_DIR "run" #else #define QGA_VIRTIO_PATH_DEFAULT "\\\\.\\Global\\org.qemu.guest_agent.0" #define QGA_STATE_RELATIVE_DIR "qemu-ga" From patchwork Mon Oct 3 09:39:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 12997399 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 71428C433FE for ; Mon, 3 Oct 2022 09:42:55 +0000 (UTC) Received: from localhost ([::1]:60712 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ofHyP-0000P4-6q for qemu-devel@archiver.kernel.org; Mon, 03 Oct 2022 05:42:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54034) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofHvH-0006QA-KO for qemu-devel@nongnu.org; Mon, 03 Oct 2022 05:39:39 -0400 Received: from mail-eopbgr80119.outbound.protection.outlook.com ([40.107.8.119]:34208 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 1ofHvA-0002U6-J4 for qemu-devel@nongnu.org; Mon, 03 Oct 2022 05:39:38 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MFQEgyU2BSLVHeZSqS70932KTuXIswGOwro1TObJXB50zmWrVGoAjjNTMPiWorFTFqLNLR0LllRnq+3opSaAWtkn3EKjs1J+D2Ilwel134a25OnWsmO07VVmzKZkrUEQb5v9ZUacdkm/2QragxKp4IKp0Ya3lt/B5wjT23IXm6rc1RoOAXW/3KtJI6UHW3UMG8F9NAOH4Z8zS+kqrn21ynSLLC8UaizNlSLwezuy1APhQ0gTuvi1ShCJZwhTcqyBtQBKBiLtUguOXcdHHQBPU+1ad2HYlOgu88PxYYMIB+jyk4fzkQL29agnJP+yp48U0v9vcpkGOpXoOhg793kdow== 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=zgRh0Iz7zGD5i5zCMDbOOLS3g9ELVqMWgvSnjCqL9AE=; b=NQz2JGCWKMdx72uUmVWEPvzbD+jpdm3C7xsRHaV9zp/3yEtlPnENlPULBxcMPo6GbpKWImNg01U6aT+/yID4Hc8/k4uc0NX66I4/Nd9FRlOZq3qbAe3R4rqqyw1Zh/p5SWz7fXmJ8ihXF9RT1nOiRrmxsT6R/jys6PMbGcE4G9+e/gvJ2X6rQHuxzpgACUH/ulK/US5vk2BswdfmnJht5skLLj15FBSD7h13CQgIOQGQGZd6kQVwpENccSjWyjA/cgy8ACHvvxfw4t7r/tMSSCUE4I+PGBolegrPOzpH3abCw2y+3DYWKGIg8Z1QvlqPZr+ibthYpJfnRwogMg5GfA== 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=zgRh0Iz7zGD5i5zCMDbOOLS3g9ELVqMWgvSnjCqL9AE=; b=Q1YECYO0LHfWXzNr20eQu5cGKR5hnHlaQj9vVE6TEY8CIHiPRLHI1SJ7H7Nge6fu3vqVuABHT/Ez2EbfxGNGyqS2JF1JaezrrgP6dW7/kX6hbdL83wmIIQ0BAZszhXQdaI3C04CqkmVWiVw2Nee2Mdo1oJ95lqIlSB8N+I54Zjf9s4HQQAVpI5MiWjpB8CnGD0P7KtAFA6Lu0gWEOs8Ywg51z/9Bw/hvwcahu/O58PybT+TYcB7iSNGFcma8f6/rezejMhqBZX9KMutWKk35VbZU0dY1Zpt6Wsa9HDfya/XpBmGNNYHloQZZpKqVYcwzytTywdhfJA2GqCynD4teHg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) by DB9PR08MB8203.eurprd08.prod.outlook.com (2603:10a6:10:39e::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5676.17; Mon, 3 Oct 2022 09:39:22 +0000 Received: from AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::5174:25c7:6df8:741b]) by AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::5174:25c7:6df8:741b%8]) with mapi id 15.20.5676.028; Mon, 3 Oct 2022 09:39:22 +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 v3 2/7] qga: Move Linux-specific FS freeze/thaw code to a separate file Date: Mon, 3 Oct 2022 11:39:06 +0200 Message-Id: <20221003093911.1844031-3-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221003093911.1844031-1-alexander.ivanov@virtuozzo.com> References: <20221003093911.1844031-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: FR3P281CA0096.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a1::8) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR08MB7095:EE_|DB9PR08MB8203:EE_ X-MS-Office365-Filtering-Correlation-Id: 50be285c-415a-4579-aea0-08daa52326bc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 31rmqB4Z06qWYFnbSd1GemzvUwV0F5ZDMrmDMceiusbnx1y/8gHANCWolp08KhWz+lg6sbQ8PrLmN+b7oDwEk5poIW/ehXWRWAIhRAYh6I7ggaJ2Yn4/aa2Kc/3gN7ol52IqhLhpQQGowRNgrKVe1bQ5HLdrt2asl4KTQh1VKeZj3YthBYBi9EVh/ELRcQcYGbQt5WuHyM+4HTrhLLlx3K1lJXq2V32f9z+k68ym5H3XmQiwIEJq27SR59pgeeETNJLkcHtgGGyyy1L4reqmzzFD3FT4GPHhT3hNmUb9+nMTSwr4/GsxKkmiktXzBPdlA4GUUlhvNAGo7l/4FJ2z7boE+8DWFVvrIgH2f+jSy0uJQOLM8j/aD69ozTuuGUrhbqyosTv8OGGTGKPqBuMOwA79DB2IQOo1Egu/4Lvf+Sf+zLeCYTqUwWCe56UobrMBtIjXvYPh9UaTOkuw7mEOBdViFu2IOr3H6irZFeQGRRL4moctp6mT7neo9ebaGjAQMvrZRsyv/hFRNmYXvlayDd1AnsQhduY2o/riHIwCVYlv+IC65NNcV1A7Q35pfQqBXKoEZ9uHNndeKEmNjZeA5EADQ5BgKuixKXdA69WTnf7CN4LWJuCPguaNrFzkWunOYI4UrPsdJzVJ+pia3e7wUdKrugfS+E2YyKxq4uQpWiubtcCIX6ww3jAvZBjMkfvqNFH4s2WXZrBpPHQThWIJcvlR9EchTjAyF9IJAdh/hL4iNB11T9r65hUth5+5Ndk+ak5qT614WBZnCXl/aAPHtg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR08MB7095.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(4636009)(366004)(136003)(346002)(39850400004)(376002)(396003)(451199015)(6666004)(316002)(66476007)(66556008)(26005)(4326008)(8676002)(6512007)(6506007)(52116002)(2616005)(6916009)(478600001)(6486002)(66946007)(36756003)(38350700002)(38100700002)(86362001)(186003)(83380400001)(1076003)(44832011)(30864003)(41300700001)(8936002)(5660300002)(2906002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?LqFQ+Rm2d55JcJNpsSxJKQrp90cZ?= =?utf-8?q?QMF63+Ka2JBV6Qa8E/h76wR2Ex/2gqGeZqCB2NE2EBaR8xo67mMxrlrdZxmFL1Hla?= =?utf-8?q?jKGhV7NSLh5n5/Bw0UGTl1g15ely8NXFJzhSkyMI8L6nJkZjG76Zvt/kHGrPSfIQF?= =?utf-8?q?YDBbSj7lY7sw3VERXuLXaE/jvnUsNAR7A9QmqEK9/TDFo+YT8ADOmkAcT0Fa+C3G7?= =?utf-8?q?IaPIOk+uvligyI4Ba00w9AHd20LBMxOeR/3NSgqENtF3h7Lpd9DCnDLAPlTDOvIjf?= =?utf-8?q?fctI68Q5MGeClLTXynS+xdirwH346IIWgF0MQn/i/bIqdLFPT2NhFE17tb1aCw5/P?= =?utf-8?q?7VvmwSB0LfCqZGXMvQJSIouEBscN6kNj37lE/RsvIzhW48r/hmArj0/WGl3IC7YQ9?= =?utf-8?q?/HHgn0yacNmN7ArSNo3YwMbMEGEZntPt7jDmIMkBAKw4UAv3ku+cBmoYEibahk1Cr?= =?utf-8?q?u3ek7WswBi8PtCYwHhDs9fEoJXkFQn9E/l94ZDMEdFpXQgRqPpLddu39WJyqfaGQl?= =?utf-8?q?xQJiBDSCYo0CKFO7U1HBTE1o0dCwCX0G4K9xBWnvvGFYGDntkXFlaYdH5H0Hbeqtq?= =?utf-8?q?zQ9KkzOYl0Ja7fMkrgXgpMAi//dbZZvaj2rG8i9mrs67FafcfDaaYF1SQ1YL+IbsK?= =?utf-8?q?MSW2Qz/WlWy6Wl7LoKfN+EpMDk/hed1glC6zXp/utgqSdrc8V+uuPGUjOAFvWTmVK?= =?utf-8?q?Xjuarmsoog7Jgm0aQ7bx8qzJcwed2lzYYyX9TvVZBe2H2OVIUDOtWVlHqxUlQXa9w?= =?utf-8?q?XdbxJU8EksVCi96nLIOxIR/yVxs3vrDTIqT9JgNiOToTlvQNviE6HooKiM86Q+jQ1?= =?utf-8?q?T6lv61fwzj9dKURg/gZiunevhcAHnkPoJUh1/n5LT5j8ceQxRPnKSOtBTXLYEowP+?= =?utf-8?q?B6Mp5EJzdCoPsZfLbNI5SDhe+kMJR2AV0HW3/Kl336BuztBnvMzG9Mawrb7EXM4of?= =?utf-8?q?kAasYl8F9q6youtaBAdz6FmJ6oKuiCoD53NZrlqLL6rV4+7U1PHyM/iK2tRWQ1udX?= =?utf-8?q?Ll9kQ4x6d2JXKYUTnaKTVTT2cA5Ho+XcisPCEUX53nkuKnPgSHqOq3lM093vpm6UN?= =?utf-8?q?dhgIX+XE8mENvaBjsYVcJLj82QEJKssCwTPfACpPXfVQsael3SPjIqaub7qSzv0fI?= =?utf-8?q?0rJN3Wg3IEq+z7jw+HXY4nC+zLWJE+qEzdJi7rj6VJetL1MbIWcGeeWsYH7kOwhQo?= =?utf-8?q?NKrvJVHWNeMU87+e6ayd8fu59AJ0Vgc/MtFMml9RUAKK6NlrvDXt+twDxndlcyjMR?= =?utf-8?q?sv26l92KiKI6VxtL5XpAdKBDNYp7caTTCrjCBFUJFyNhHTGekgvBkbxnpHJ7UEy6b?= =?utf-8?q?5lCd8uVWNb71OwScuDD7O1HnV6o8rAKXdimLTXdXt720KMCBS38Z+/YQficA1wgSr?= =?utf-8?q?7jav8hcNb+2d2k/Aook7lTFQtw56NfdpcN87prJSerkwsnv4vTq6WNaCSu8rYJfcl?= =?utf-8?q?MeWj21LrLwTtMVAALR+HFqkk2c9qmoYIDc768FUC+gw+y9KCo1OS/LvRwQOBAYjn9?= =?utf-8?q?FRbzvW3GQlExCoZT2qLus1evaOqdN8x3U+Hr9R6T/icXfF0glx7BZzY=3D?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 50be285c-415a-4579-aea0-08daa52326bc X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Oct 2022 09:39:22.0871 (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: XBVhFnj/2ViXZuC34PwiRIYDhsman6MJB/IdXrnkYWiHw7gOSAY0HnKEa8TL9WYLz9Gh6B5nYFpj7pOQCeRKm/qPUp5lsvfOsgAK8JLzMxA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR08MB8203 Received-SPF: pass client-ip=40.107.8.119; 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, 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" In the next patches we are going to add FreeBSD support for QEMU Guest Agent. In the result, code in commands-posix.c will be too cumbersome. Move Linux-specific FS freeze/thaw code to a separate file commands-linux.c keeping common POSIX code in commands-posix.c. Reviewed-by: Marc-André Lureau Signed-off-by: Alexander Ivanov Reviewed-by: Konstantin Kostiuk --- qga/commands-common.h | 35 +++++ qga/commands-linux.c | 286 +++++++++++++++++++++++++++++++++++++++++ qga/commands-posix.c | 289 +++--------------------------------------- qga/meson.build | 3 + 4 files changed, 340 insertions(+), 273 deletions(-) create mode 100644 qga/commands-linux.c diff --git a/qga/commands-common.h b/qga/commands-common.h index d0e4a9696f..181fc330aa 100644 --- a/qga/commands-common.h +++ b/qga/commands-common.h @@ -10,6 +10,40 @@ #define QGA_COMMANDS_COMMON_H #include "qga-qapi-types.h" +#include "guest-agent-core.h" +#include "qemu/queue.h" + +#if defined(__linux__) +#include +#ifdef FIFREEZE +#define CONFIG_FSFREEZE +#endif +#ifdef FITRIM +#define CONFIG_FSTRIM +#endif +#endif /* __linux__ */ + +#if defined(CONFIG_FSFREEZE) || defined(CONFIG_FSTRIM) +typedef struct FsMount { + char *dirname; + char *devtype; + unsigned int devmajor, devminor; + QTAILQ_ENTRY(FsMount) next; +} FsMount; + +typedef QTAILQ_HEAD(FsMountList, FsMount) FsMountList; + +bool build_fs_mount_list(FsMountList *mounts, Error **errp); +void free_fs_mount_list(FsMountList *mounts); +#endif /* CONFIG_FSFREEZE || CONFIG_FSTRIM */ + +#if defined(CONFIG_FSFREEZE) +int64_t qmp_guest_fsfreeze_do_freeze_list(bool has_mountpoints, + strList *mountpoints, + FsMountList mounts, + Error **errp); +int qmp_guest_fsfreeze_do_thaw(Error **errp); +#endif /* CONFIG_FSFREEZE */ typedef struct GuestFileHandle GuestFileHandle; @@ -29,4 +63,5 @@ GuestFileRead *guest_file_read_unsafe(GuestFileHandle *gfh, */ char *qga_get_host_name(Error **errp); +void ga_wait_child(pid_t pid, int *status, Error **errp); #endif diff --git a/qga/commands-linux.c b/qga/commands-linux.c new file mode 100644 index 0000000000..214e408fcd --- /dev/null +++ b/qga/commands-linux.c @@ -0,0 +1,286 @@ +/* + * QEMU Guest Agent Linux-specific command implementations + * + * Copyright IBM Corp. 2011 + * + * Authors: + * Michael Roth + * Michal Privoznik + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "commands-common.h" +#include "cutils.h" +#include +#include + +#if defined(CONFIG_FSFREEZE) || defined(CONFIG_FSTRIM) +static int dev_major_minor(const char *devpath, + unsigned int *devmajor, unsigned int *devminor) +{ + struct stat st; + + *devmajor = 0; + *devminor = 0; + + if (stat(devpath, &st) < 0) { + slog("failed to stat device file '%s': %s", devpath, strerror(errno)); + return -1; + } + if (S_ISDIR(st.st_mode)) { + /* It is bind mount */ + return -2; + } + if (S_ISBLK(st.st_mode)) { + *devmajor = major(st.st_rdev); + *devminor = minor(st.st_rdev); + return 0; + } + return -1; +} + +static bool build_fs_mount_list_from_mtab(FsMountList *mounts, Error **errp) +{ + struct mntent *ment; + FsMount *mount; + char const *mtab = "/proc/self/mounts"; + FILE *fp; + unsigned int devmajor, devminor; + + fp = setmntent(mtab, "r"); + if (!fp) { + error_setg(errp, "failed to open mtab file: '%s'", mtab); + return false; + } + + while ((ment = getmntent(fp))) { + /* + * An entry which device name doesn't start with a '/' is + * either a dummy file system or a network file system. + * Add special handling for smbfs and cifs as is done by + * coreutils as well. + */ + if ((ment->mnt_fsname[0] != '/') || + (strcmp(ment->mnt_type, "smbfs") == 0) || + (strcmp(ment->mnt_type, "cifs") == 0)) { + continue; + } + if (dev_major_minor(ment->mnt_fsname, &devmajor, &devminor) == -2) { + /* Skip bind mounts */ + continue; + } + + mount = g_new0(FsMount, 1); + mount->dirname = g_strdup(ment->mnt_dir); + mount->devtype = g_strdup(ment->mnt_type); + mount->devmajor = devmajor; + mount->devminor = devminor; + + QTAILQ_INSERT_TAIL(mounts, mount, next); + } + + endmntent(fp); + return true; +} + +static void decode_mntname(char *name, int len) +{ + int i, j = 0; + for (i = 0; i <= len; i++) { + if (name[i] != '\\') { + name[j++] = name[i]; + } else if (name[i + 1] == '\\') { + name[j++] = '\\'; + i++; + } else if (name[i + 1] >= '0' && name[i + 1] <= '3' && + name[i + 2] >= '0' && name[i + 2] <= '7' && + name[i + 3] >= '0' && name[i + 3] <= '7') { + name[j++] = (name[i + 1] - '0') * 64 + + (name[i + 2] - '0') * 8 + + (name[i + 3] - '0'); + i += 3; + } else { + name[j++] = name[i]; + } + } +} + +/* + * Walk the mount table and build a list of local file systems + */ +bool build_fs_mount_list(FsMountList *mounts, Error **errp) +{ + FsMount *mount; + char const *mountinfo = "/proc/self/mountinfo"; + FILE *fp; + char *line = NULL, *dash; + size_t n; + char check; + unsigned int devmajor, devminor; + int ret, dir_s, dir_e, type_s, type_e, dev_s, dev_e; + + fp = fopen(mountinfo, "r"); + if (!fp) { + return build_fs_mount_list_from_mtab(mounts, errp); + } + + while (getline(&line, &n, fp) != -1) { + ret = sscanf(line, "%*u %*u %u:%u %*s %n%*s%n%c", + &devmajor, &devminor, &dir_s, &dir_e, &check); + if (ret < 3) { + continue; + } + dash = strstr(line + dir_e, " - "); + if (!dash) { + continue; + } + ret = sscanf(dash, " - %n%*s%n %n%*s%n%c", + &type_s, &type_e, &dev_s, &dev_e, &check); + if (ret < 1) { + continue; + } + line[dir_e] = 0; + dash[type_e] = 0; + dash[dev_e] = 0; + decode_mntname(line + dir_s, dir_e - dir_s); + decode_mntname(dash + dev_s, dev_e - dev_s); + if (devmajor == 0) { + /* btrfs reports major number = 0 */ + if (strcmp("btrfs", dash + type_s) != 0 || + dev_major_minor(dash + dev_s, &devmajor, &devminor) < 0) { + continue; + } + } + + mount = g_new0(FsMount, 1); + mount->dirname = g_strdup(line + dir_s); + mount->devtype = g_strdup(dash + type_s); + mount->devmajor = devmajor; + mount->devminor = devminor; + + QTAILQ_INSERT_TAIL(mounts, mount, next); + } + free(line); + + fclose(fp); + return true; +} +#endif /* CONFIG_FSFREEZE || CONFIG_FSTRIM */ + +#ifdef CONFIG_FSFREEZE +/* + * Walk list of mounted file systems in the guest, and freeze the ones which + * are real local file systems. + */ +int64_t qmp_guest_fsfreeze_do_freeze_list(bool has_mountpoints, + strList *mountpoints, + FsMountList mounts, + Error **errp) +{ + struct FsMount *mount; + strList *list; + int fd, ret, i = 0; + + QTAILQ_FOREACH_REVERSE(mount, &mounts, next) { + /* To issue fsfreeze in the reverse order of mounts, check if the + * mount is listed in the list here */ + if (has_mountpoints) { + for (list = mountpoints; list; list = list->next) { + if (strcmp(list->value, mount->dirname) == 0) { + break; + } + } + if (!list) { + continue; + } + } + + fd = qga_open_cloexec(mount->dirname, O_RDONLY, 0); + if (fd == -1) { + error_setg_errno(errp, errno, "failed to open %s", mount->dirname); + return -1; + } + + /* we try to cull filesystems we know won't work in advance, but other + * filesystems may not implement fsfreeze for less obvious reasons. + * these will report EOPNOTSUPP. we simply ignore these when tallying + * the number of frozen filesystems. + * if a filesystem is mounted more than once (aka bind mount) a + * consecutive attempt to freeze an already frozen filesystem will + * return EBUSY. + * + * any other error means a failure to freeze a filesystem we + * expect to be freezable, so return an error in those cases + * and return system to thawed state. + */ + ret = ioctl(fd, FIFREEZE); + if (ret == -1) { + if (errno != EOPNOTSUPP && errno != EBUSY) { + error_setg_errno(errp, errno, "failed to freeze %s", + mount->dirname); + close(fd); + return -1; + } + } else { + i++; + } + close(fd); + } + return i; +} + +int qmp_guest_fsfreeze_do_thaw(Error **errp) +{ + int ret; + FsMountList mounts; + FsMount *mount; + int fd, i = 0, logged; + Error *local_err = NULL; + + QTAILQ_INIT(&mounts); + if (!build_fs_mount_list(&mounts, &local_err)) { + error_propagate(errp, local_err); + return -1; + } + + QTAILQ_FOREACH(mount, &mounts, next) { + logged = false; + fd = qga_open_cloexec(mount->dirname, O_RDONLY, 0); + if (fd == -1) { + continue; + } + /* we have no way of knowing whether a filesystem was actually unfrozen + * as a result of a successful call to FITHAW, only that if an error + * was returned the filesystem was *not* unfrozen by that particular + * call. + * + * since multiple preceding FIFREEZEs require multiple calls to FITHAW + * to unfreeze, continuing issuing FITHAW until an error is returned, + * in which case either the filesystem is in an unfreezable state, or, + * more likely, it was thawed previously (and remains so afterward). + * + * also, since the most recent successful call is the one that did + * the actual unfreeze, we can use this to provide an accurate count + * of the number of filesystems unfrozen by guest-fsfreeze-thaw, which + * may * be useful for determining whether a filesystem was unfrozen + * during the freeze/thaw phase by a process other than qemu-ga. + */ + do { + ret = ioctl(fd, FITHAW); + if (ret == 0 && !logged) { + i++; + logged = true; + } + } while (ret == 0); + close(fd); + } + + free_fs_mount_list(&mounts); + + return i; +} +#endif /* CONFIG_FSFREEZE */ diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 16d67e9f6d..9574b83c92 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -16,11 +16,9 @@ #include #include #include -#include "guest-agent-core.h" #include "qga-qapi-commands.h" #include "qapi/error.h" #include "qapi/qmp/qerror.h" -#include "qemu/queue.h" #include "qemu/host-utils.h" #include "qemu/sockets.h" #include "qemu/base64.h" @@ -70,7 +68,7 @@ #endif #endif -static void ga_wait_child(pid_t pid, int *status, Error **errp) +void ga_wait_child(pid_t pid, int *status, Error **errp) { pid_t rpid; @@ -629,16 +627,7 @@ void qmp_guest_file_flush(int64_t handle, Error **errp) #if defined(__linux__) #if defined(CONFIG_FSFREEZE) || defined(CONFIG_FSTRIM) -typedef struct FsMount { - char *dirname; - char *devtype; - unsigned int devmajor, devminor; - QTAILQ_ENTRY(FsMount) next; -} FsMount; - -typedef QTAILQ_HEAD(FsMountList, FsMount) FsMountList; - -static void free_fs_mount_list(FsMountList *mounts) +void free_fs_mount_list(FsMountList *mounts) { FsMount *mount, *temp; @@ -653,157 +642,6 @@ static void free_fs_mount_list(FsMountList *mounts) g_free(mount); } } - -static int dev_major_minor(const char *devpath, - unsigned int *devmajor, unsigned int *devminor) -{ - struct stat st; - - *devmajor = 0; - *devminor = 0; - - if (stat(devpath, &st) < 0) { - slog("failed to stat device file '%s': %s", devpath, strerror(errno)); - return -1; - } - if (S_ISDIR(st.st_mode)) { - /* It is bind mount */ - return -2; - } - if (S_ISBLK(st.st_mode)) { - *devmajor = major(st.st_rdev); - *devminor = minor(st.st_rdev); - return 0; - } - return -1; -} - -/* - * Walk the mount table and build a list of local file systems - */ -static bool build_fs_mount_list_from_mtab(FsMountList *mounts, Error **errp) -{ - struct mntent *ment; - FsMount *mount; - char const *mtab = "/proc/self/mounts"; - FILE *fp; - unsigned int devmajor, devminor; - - fp = setmntent(mtab, "r"); - if (!fp) { - error_setg(errp, "failed to open mtab file: '%s'", mtab); - return false; - } - - while ((ment = getmntent(fp))) { - /* - * An entry which device name doesn't start with a '/' is - * either a dummy file system or a network file system. - * Add special handling for smbfs and cifs as is done by - * coreutils as well. - */ - if ((ment->mnt_fsname[0] != '/') || - (strcmp(ment->mnt_type, "smbfs") == 0) || - (strcmp(ment->mnt_type, "cifs") == 0)) { - continue; - } - if (dev_major_minor(ment->mnt_fsname, &devmajor, &devminor) == -2) { - /* Skip bind mounts */ - continue; - } - - mount = g_new0(FsMount, 1); - mount->dirname = g_strdup(ment->mnt_dir); - mount->devtype = g_strdup(ment->mnt_type); - mount->devmajor = devmajor; - mount->devminor = devminor; - - QTAILQ_INSERT_TAIL(mounts, mount, next); - } - - endmntent(fp); - return true; -} - -static void decode_mntname(char *name, int len) -{ - int i, j = 0; - for (i = 0; i <= len; i++) { - if (name[i] != '\\') { - name[j++] = name[i]; - } else if (name[i + 1] == '\\') { - name[j++] = '\\'; - i++; - } else if (name[i + 1] >= '0' && name[i + 1] <= '3' && - name[i + 2] >= '0' && name[i + 2] <= '7' && - name[i + 3] >= '0' && name[i + 3] <= '7') { - name[j++] = (name[i + 1] - '0') * 64 + - (name[i + 2] - '0') * 8 + - (name[i + 3] - '0'); - i += 3; - } else { - name[j++] = name[i]; - } - } -} - -static bool build_fs_mount_list(FsMountList *mounts, Error **errp) -{ - FsMount *mount; - char const *mountinfo = "/proc/self/mountinfo"; - FILE *fp; - char *line = NULL, *dash; - size_t n; - char check; - unsigned int devmajor, devminor; - int ret, dir_s, dir_e, type_s, type_e, dev_s, dev_e; - - fp = fopen(mountinfo, "r"); - if (!fp) { - return build_fs_mount_list_from_mtab(mounts, errp); - } - - while (getline(&line, &n, fp) != -1) { - ret = sscanf(line, "%*u %*u %u:%u %*s %n%*s%n%c", - &devmajor, &devminor, &dir_s, &dir_e, &check); - if (ret < 3) { - continue; - } - dash = strstr(line + dir_e, " - "); - if (!dash) { - continue; - } - ret = sscanf(dash, " - %n%*s%n %n%*s%n%c", - &type_s, &type_e, &dev_s, &dev_e, &check); - if (ret < 1) { - continue; - } - line[dir_e] = 0; - dash[type_e] = 0; - dash[dev_e] = 0; - decode_mntname(line + dir_s, dir_e - dir_s); - decode_mntname(dash + dev_s, dev_e - dev_s); - if (devmajor == 0) { - /* btrfs reports major number = 0 */ - if (strcmp("btrfs", dash + type_s) != 0 || - dev_major_minor(dash + dev_s, &devmajor, &devminor) < 0) { - continue; - } - } - - mount = g_new0(FsMount, 1); - mount->dirname = g_strdup(line + dir_s); - mount->devtype = g_strdup(dash + type_s); - mount->devmajor = devmajor; - mount->devminor = devminor; - - QTAILQ_INSERT_TAIL(mounts, mount, next); - } - free(line); - - fclose(fp); - return true; -} #endif #if defined(CONFIG_FSFREEZE) @@ -1708,20 +1546,13 @@ int64_t qmp_guest_fsfreeze_freeze(Error **errp) return qmp_guest_fsfreeze_freeze_list(false, NULL, errp); } -/* - * Walk list of mounted file systems in the guest, and freeze the ones which - * are real local file systems. - */ int64_t qmp_guest_fsfreeze_freeze_list(bool has_mountpoints, strList *mountpoints, Error **errp) { - int ret = 0, i = 0; - strList *list; + int ret; FsMountList mounts; - struct FsMount *mount; Error *local_err = NULL; - int fd; slog("guest-fsfreeze called"); @@ -1740,122 +1571,34 @@ int64_t qmp_guest_fsfreeze_freeze_list(bool has_mountpoints, /* cannot risk guest agent blocking itself on a write in this state */ ga_set_frozen(ga_state); - QTAILQ_FOREACH_REVERSE(mount, &mounts, next) { - /* To issue fsfreeze in the reverse order of mounts, check if the - * mount is listed in the list here */ - if (has_mountpoints) { - for (list = mountpoints; list; list = list->next) { - if (strcmp(list->value, mount->dirname) == 0) { - break; - } - } - if (!list) { - continue; - } - } - - fd = qga_open_cloexec(mount->dirname, O_RDONLY, 0); - if (fd == -1) { - error_setg_errno(errp, errno, "failed to open %s", mount->dirname); - goto error; - } - - /* we try to cull filesystems we know won't work in advance, but other - * filesystems may not implement fsfreeze for less obvious reasons. - * these will report EOPNOTSUPP. we simply ignore these when tallying - * the number of frozen filesystems. - * if a filesystem is mounted more than once (aka bind mount) a - * consecutive attempt to freeze an already frozen filesystem will - * return EBUSY. - * - * any other error means a failure to freeze a filesystem we - * expect to be freezable, so return an error in those cases - * and return system to thawed state. - */ - ret = ioctl(fd, FIFREEZE); - if (ret == -1) { - if (errno != EOPNOTSUPP && errno != EBUSY) { - error_setg_errno(errp, errno, "failed to freeze %s", - mount->dirname); - close(fd); - goto error; - } - } else { - i++; - } - close(fd); - } + ret = qmp_guest_fsfreeze_do_freeze_list(has_mountpoints, mountpoints, + mounts, errp); free_fs_mount_list(&mounts); /* We may not issue any FIFREEZE here. * Just unset ga_state here and ready for the next call. */ - if (i == 0) { + if (ret == 0) { ga_unset_frozen(ga_state); + } else if (ret < 0) { + qmp_guest_fsfreeze_thaw(NULL); } - return i; - -error: - free_fs_mount_list(&mounts); - qmp_guest_fsfreeze_thaw(NULL); - return 0; + return ret; } -/* - * Walk list of frozen file systems in the guest, and thaw them. - */ int64_t qmp_guest_fsfreeze_thaw(Error **errp) { int ret; - FsMountList mounts; - FsMount *mount; - int fd, i = 0, logged; - Error *local_err = NULL; - QTAILQ_INIT(&mounts); - if (!build_fs_mount_list(&mounts, &local_err)) { - error_propagate(errp, local_err); - return 0; + ret = qmp_guest_fsfreeze_do_thaw(errp); + if (ret >= 0) { + ga_unset_frozen(ga_state); + execute_fsfreeze_hook(FSFREEZE_HOOK_THAW, errp); + } else { + ret = 0; } - QTAILQ_FOREACH(mount, &mounts, next) { - logged = false; - fd = qga_open_cloexec(mount->dirname, O_RDONLY, 0); - if (fd == -1) { - continue; - } - /* we have no way of knowing whether a filesystem was actually unfrozen - * as a result of a successful call to FITHAW, only that if an error - * was returned the filesystem was *not* unfrozen by that particular - * call. - * - * since multiple preceding FIFREEZEs require multiple calls to FITHAW - * to unfreeze, continuing issuing FITHAW until an error is returned, - * in which case either the filesystem is in an unfreezable state, or, - * more likely, it was thawed previously (and remains so afterward). - * - * also, since the most recent successful call is the one that did - * the actual unfreeze, we can use this to provide an accurate count - * of the number of filesystems unfrozen by guest-fsfreeze-thaw, which - * may * be useful for determining whether a filesystem was unfrozen - * during the freeze/thaw phase by a process other than qemu-ga. - */ - do { - ret = ioctl(fd, FITHAW); - if (ret == 0 && !logged) { - i++; - logged = true; - } - } while (ret == 0); - close(fd); - } - - ga_unset_frozen(ga_state); - free_fs_mount_list(&mounts); - - execute_fsfreeze_hook(FSFREEZE_HOOK_THAW, errp); - - return i; + return ret; } static void guest_fsfreeze_cleanup(void) diff --git a/qga/meson.build b/qga/meson.build index 65c1e93846..409f49a000 100644 --- a/qga/meson.build +++ b/qga/meson.build @@ -72,6 +72,9 @@ qga_ss.add(when: 'CONFIG_POSIX', if_true: files( 'commands-posix.c', 'commands-posix-ssh.c', )) +qga_ss.add(when: 'CONFIG_LINUX', if_true: files( + 'commands-linux.c', +)) qga_ss.add(when: 'CONFIG_WIN32', if_true: files( 'channel-win32.c', 'commands-win32.c', From patchwork Mon Oct 3 09:39:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 12997406 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 BF258C433F5 for ; Mon, 3 Oct 2022 09:50:05 +0000 (UTC) Received: from localhost ([::1]:50860 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ofI5I-0005fl-AF for qemu-devel@archiver.kernel.org; Mon, 03 Oct 2022 05:50:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54036) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofHvJ-0006RW-Bn for qemu-devel@nongnu.org; Mon, 03 Oct 2022 05:39:42 -0400 Received: from mail-eopbgr80119.outbound.protection.outlook.com ([40.107.8.119]:34208 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 1ofHvG-0002U6-Tv for qemu-devel@nongnu.org; Mon, 03 Oct 2022 05:39:40 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cu+gAd8NdTdtMWuj/n3KEL5izaClAeO7eVgvp2kLFVK3SJPplQam/Uegvh6Ndk15cJFZJ4VGWF+6vfQ7qUiqqC09RJg+BNrhZDGppdLvVLdfdaIWtIk24X0q2UZK0vxvkCmwnf8zZZCT1MlYHeyJuYYs51ADdn4qwy3fT1yhM2NuKVdm51yIuKfL60xHMNv7Ku9EAzDc5GHssgb/f7WP3eecDgazxlA90EcqptjFYILRa9Xb+WwYOt+mt/cuz5YU5YoF50E7OELBXBaZAUFc1URNywg73D4qyhrj8GrOeU7ZviURDyYwgzTx3BgvVCmaFafuffQKC3xj2GTPuc52eg== 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=7pRohLF15lHFmrvkX7AYU88DslNsDkv2W4101oQE7fY=; b=U7ca8Zzo41s2tnhokCTEYEz+NqDy6nelzDuAj+RZcAcNF3oN9Iylf/aCM00yC3cEV1K7jzeH2QCoN8sph9WeTM5pBJrjJSGqrF1u/RGVlcavcc+CnmuNmr9dwlT7rqGNOZwP9nCkAzkbjxV40uZLiPZTMft8r8mdfzxxHCud3RnLvoMuEX7/bEYkFp2CH1p7RZntWkTMBocJSGgHNhHbtUjVs19bUfbZO6wnP8JmFPmTnv13JwjoMLMzggTUZcV8Nx63hJgOuurYaWunQGd823+4NFnOm1rRBc7nJPl/aAW9Nqb/BJ6nm2pP3Vom6m73K8KjYIidh7MErqoizuoOeg== 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=7pRohLF15lHFmrvkX7AYU88DslNsDkv2W4101oQE7fY=; b=mmHomuNeLLzCsQ+zleMHr3AP8A1OOBOELK1YYA7fW55vS5REWQLaarbPPnHPXMEbe0w+/oqyrok5spwdwNv2xfhAmts0NUicx7CcXgvLjYJIx8ecZIjluVt/8+0y/dZcI55hswbxypiRfgIarxLhFvd0wFOYf2wyguR1u2aNCVl6/nx9BVrIBz+XVjsNUzmZyv9Yw0qIyrzXNFqjBH9Q8A6CXsCSu4BSjBg9s/0BPk/9K4DOZda7U6PsuayGC5lAyfkVdzI37qB6OKLvbLBOs5wgviAkrzslEJ9wrn4xVni8aOuVOyMcGWZ1W2Vugz5GypdplCYgUJWbjFfpNArbSA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) by DB9PR08MB8203.eurprd08.prod.outlook.com (2603:10a6:10:39e::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5676.17; Mon, 3 Oct 2022 09:39:22 +0000 Received: from AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::5174:25c7:6df8:741b]) by AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::5174:25c7:6df8:741b%8]) with mapi id 15.20.5676.028; Mon, 3 Oct 2022 09:39:22 +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 v3 3/7] qga: Add UFS freeze/thaw support for FreeBSD Date: Mon, 3 Oct 2022 11:39:07 +0200 Message-Id: <20221003093911.1844031-4-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221003093911.1844031-1-alexander.ivanov@virtuozzo.com> References: <20221003093911.1844031-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: FR3P281CA0096.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a1::8) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR08MB7095:EE_|DB9PR08MB8203:EE_ X-MS-Office365-Filtering-Correlation-Id: b1be7880-88f3-4710-f387-08daa5232727 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 86uM7GF6O1vJsM+qTarSR/cHej9lUH1sApYOcfaRy0r6sSgjgEATFpwgf8YISieamZVjzcvWswdUQ/dzjPKHR7Wp1TGmukCguak8z8UI88YfF+vnMMPDKnTo7BAIO7RDwHpKSGalzmywSBCdZiANptSBZniev3bFwrIlAux/Junm9DtAsddMHfKHZmP9X221NZPMb488L11hLqN/L0T6zXoMgVGnckRVm0w/16a15QsWtwPz0+Wv5AzZ3v42fmocJgZvwqDMWm5pOMeQqBuh7A98anXQIMobFMGSm0C6vcEtrISvl4YW/lVvALMmUdASSFera8GeC9RwA+GQ6rGWlOrQRI+2mdt4KD2seIRhzDahuAVwYBxFRHg+vNA0/G/waq8TTgnqdHps92zT3HCF8NViy+8ZbDIdcmNsEjb0H7RJnGJlCSylX0jDvPHKVhcn3M5r6ChyXLU8KcGoq/QS4I481dVMHnkMOUh723MRD5t/3MWUiFyOYLrCXKl+YMvtIfLeR8gGBMLSiQ/vTjcSvdwqBQnCMLstH2tqeVCHBC6MIzJ+brus8elE4YsbEstDDpst8pDPYK8oRWXKNgC88C1Ux/jUcfpOKrjh8kvq67BMJ8LFhqHMQKW+mNWGbNaj0HOAPOSjPxwayDJmrKdUzwUQgFW/jIxWlMf1vYn6IBal3JoLGwfoaXuSmkunAQRqDSvv8No6mspoyGHc+QWWPBUaiJhvVOmyNnhL/gXOPdE1TmfhukW+Y2pNDf12qYkhhTUn70rC78ajvZ3i6eEn1w== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR08MB7095.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(4636009)(366004)(136003)(346002)(39850400004)(376002)(396003)(451199015)(6666004)(316002)(66476007)(66556008)(26005)(4326008)(8676002)(6512007)(6506007)(52116002)(2616005)(6916009)(478600001)(6486002)(66946007)(36756003)(38350700002)(38100700002)(86362001)(186003)(83380400001)(1076003)(44832011)(30864003)(41300700001)(8936002)(5660300002)(2906002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?mk5ZPI1HCPUGIoN1YF3mGlQnYMAS?= =?utf-8?q?5LAYsmQclOlyiA0+Rj45G9mKuzi2CGJM7uZBKZ29pYs965KLZ/WDcGd3mSvhV+X4M?= =?utf-8?q?ilBbxRnBtmIFmOScPWGSyYQq6kFFcWe1Eb5ZcySTWcd3A2jbRQAmLvAq4gbuEF9De?= =?utf-8?q?d/i0vkC1SftfHXE+RBHKb+fPUIH8I/LP8x1IrKfnmtrJwM9SX9D50NIYiIy/wg2/M?= =?utf-8?q?1ZmRBtBJOWK3sPg97vT2kp1naJdE1OFtwdtsTz7b/3ZV3AyEOnLSLArMHqquYJPPt?= =?utf-8?q?X6ZHlqDX4S8YTj6MUXYk0uWwOMHsJDji+Ut0FleW33NzsVCccFPPpVegtlPDBIawk?= =?utf-8?q?XwpeITyBWLKJy0/fqL6NWB+4MvmOoy8QkwYwcsaC+LYOOxFig9Jy9+R7B5onNTDR3?= =?utf-8?q?SS6JP7QPDB0h5+2n6Ac7a8fzaq557vLQUw2aFEflGK2vFqxjSsn7Fw4/30+d+iwKO?= =?utf-8?q?fbpTbE5kugaKGNKBezIRBbGMxPrrfgbjlU0G4Wu+zSp837cRsmmKNMcJWbQsNGcI0?= =?utf-8?q?QEiubNXOqSo84lGTvnazKYeutqJ/2XVIel4fIvtVsJw2e3NKMWx9gettagfmdLUy7?= =?utf-8?q?HRFQRI5b2chU3f6CElY+DkYQSExUPUqTjXDFQqS/uQeT0xH11GprqKiMgkdXVMS1X?= =?utf-8?q?YN1HjroHslJ+cGFW7/tRHgpU5f/9DF05WMGCkLteZ/LToR2Y5rIbciDYIZ1QrfDWt?= =?utf-8?q?Jv1D1+a1yFRc5hswjRyq9SBjZXKqloyM7s/VfnMDiED0PGSaV4cVXZK7nJJ+sv742?= =?utf-8?q?vW9ahQjfptbznJWRms0/HGuiLzXMsh/txjDTgg5fTMsYcKJK48c0ZOQKLaWMYVwW4?= =?utf-8?q?yuB+F2lQxVDGfczRj4YcIe8YmUimt67NtNcW69pxAwTU2PIzO2YduZPmFDZlwwQhd?= =?utf-8?q?GR69e2gDEahuIiBsCrtNjUPWPTWtizm6gQCbzEZdWg6MP5HPELws18uie9Elvug4m?= =?utf-8?q?nIa3XBl/Cx8Z0XSZjYioglM7uAH4PEQbg+DyYwQj1tL6MZxJyjZ0MhuxNEd7PFK1t?= =?utf-8?q?yi+syrA8ZWd7RJa75o7VgQexAYfozWW2LgJlg3KAo/SGro5L0NVNnK3Se2K6Wo47G?= =?utf-8?q?CY4vs/k3HWz5w3ea/wU7sTb2CKkmnDSW6h7cBKKw547yZisP2oiIH8ANlVH/PG349?= =?utf-8?q?o6GDMAACJJy0PEm/341w2/KVxzcYUcko7oBB/ZTRHHaJpXcum9Fa1Vyn3B4FQq5gT?= =?utf-8?q?+Zi05j94fkLq16Dhnh1jUFpsjr1feGpxh+Zi585QpyRiCdmnmM2w4e/Gvd44Iw3AT?= =?utf-8?q?umvaNz9VdVctPtUvKXMkCnDqQu9C5O1IZTIgmgrxPBipqSHwmsyeEdsblWJTRq6P0?= =?utf-8?q?DpZqzoJMWQA419nMJ4STjYcG0WUoH2YHtUXSFwi5/uqx9KiwF1txErDjUUEgbN3CW?= =?utf-8?q?UkFXB2AVlbPmdSDvMN6JW5eqdyvE0cq/uQhO6wnFUui/efme3LPwC0u9wKhpO1oeF?= =?utf-8?q?OsHE4FeRVz0SNQasl9wG1mtBknbP9mYu4wHlt4IvLwawwCsf49S4dU0go8gm4bTnp?= =?utf-8?q?n6ijfYox0bDYkA0kKTA4n2k3z/sPKdf4ng=3D=3D?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: b1be7880-88f3-4710-f387-08daa5232727 X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Oct 2022 09:39:22.6808 (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: a/InRzCP2MfZpWbzAKjc8dnukDD2lY1RWITzlWxWhoatXm3hVerTIMhWQ8d5nODm0ypor8S967zvQdh+skI9z/3ILQDQ8iiT19zRZr72+yE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR08MB8203 Received-SPF: pass client-ip=40.107.8.119; 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, 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" UFS supports FS freezing through ioctl UFSSUSPEND on /dev/ufssuspend. Frozen FS can be thawed by closing /dev/ufssuspend file descriptior. Use getmntinfo to get a list of mounted FS. Reviewed-by: Marc-André Lureau Signed-off-by: Alexander Ivanov Reviewed-by: Konstantin Kostiuk --- qga/commands-bsd.c | 169 +++++++++++++++++++++++ qga/commands-common.h | 11 ++ qga/commands-posix.c | 308 ++++++++++++++++++++---------------------- qga/main.c | 7 +- qga/meson.build | 3 + 5 files changed, 334 insertions(+), 164 deletions(-) create mode 100644 qga/commands-bsd.c diff --git a/qga/commands-bsd.c b/qga/commands-bsd.c new file mode 100644 index 0000000000..ca06692179 --- /dev/null +++ b/qga/commands-bsd.c @@ -0,0 +1,169 @@ +/* + * QEMU Guest Agent BSD-specific command implementations + * + * Copyright (c) Virtuozzo International GmbH. + * + * Authors: + * Alexander Ivanov + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "qga-qapi-commands.h" +#include "qapi/qmp/qerror.h" +#include "qapi/error.h" +#include "qemu/queue.h" +#include "commands-common.h" +#include +#include +#include +#include +#include + +#if defined(CONFIG_FSFREEZE) || defined(CONFIG_FSTRIM) +bool build_fs_mount_list(FsMountList *mounts, Error **errp) +{ + FsMount *mount; + struct statfs *mntbuf, *mntp; + struct stat statbuf; + int i, count, ret; + + count = getmntinfo(&mntbuf, MNT_NOWAIT); + if (count == 0) { + error_setg_errno(errp, errno, "getmntinfo failed"); + return false; + } + + for (i = 0; i < count; i++) { + mntp = &mntbuf[i]; + ret = stat(mntp->f_mntonname, &statbuf); + if (ret != 0) { + error_setg_errno(errp, errno, "stat failed on %s", + mntp->f_mntonname); + return false; + } + + mount = g_new0(FsMount, 1); + + mount->dirname = g_strdup(mntp->f_mntonname); + mount->devtype = g_strdup(mntp->f_fstypename); + mount->devmajor = major(mount->dev); + mount->devminor = minor(mount->dev); + mount->fsid = mntp->f_fsid; + mount->dev = statbuf.st_dev; + + QTAILQ_INSERT_TAIL(mounts, mount, next); + } + return true; +} +#endif /* CONFIG_FSFREEZE || CONFIG_FSTRIM */ + +#if defined(CONFIG_FSFREEZE) +static int ufssuspend_fd = -1; +static int ufssuspend_cnt; + +int64_t qmp_guest_fsfreeze_do_freeze_list(bool has_mountpoints, + strList *mountpoints, + FsMountList mounts, + Error **errp) +{ + int ret; + strList *list; + struct FsMount *mount; + + if (ufssuspend_fd != -1) { + error_setg(errp, "filesystems have already frozen"); + return -1; + } + + ufssuspend_cnt = 0; + ufssuspend_fd = qemu_open(_PATH_UFSSUSPEND, O_RDWR, errp); + if (ufssuspend_fd == -1) { + return -1; + } + + QTAILQ_FOREACH_REVERSE(mount, &mounts, next) { + /* + * To issue fsfreeze in the reverse order of mounts, check if the + * mount is listed in the list here + */ + if (has_mountpoints) { + for (list = mountpoints; list; list = list->next) { + if (g_str_equal(list->value, mount->dirname)) { + break; + } + } + if (!list) { + continue; + } + } + + /* Only UFS supports suspend */ + if (!g_str_equal(mount->devtype, "ufs")) { + continue; + } + + ret = ioctl(ufssuspend_fd, UFSSUSPEND, &mount->fsid); + if (ret == -1) { + /* + * ioctl returns EBUSY for all the FS except the first one + * that was suspended + */ + if (errno == EBUSY) { + continue; + } + error_setg_errno(errp, errno, "failed to freeze %s", + mount->dirname); + goto error; + } + ufssuspend_cnt++; + } + return ufssuspend_cnt; +error: + close(ufssuspend_fd); + ufssuspend_fd = -1; + return -1; + +} + +/* + * We don't need to call UFSRESUME ioctl because all the frozen FS + * are thawed on /dev/ufssuspend closing. + */ +int qmp_guest_fsfreeze_do_thaw(Error **errp) +{ + int ret = ufssuspend_cnt; + ufssuspend_cnt = 0; + if (ufssuspend_fd != -1) { + close(ufssuspend_fd); + ufssuspend_fd = -1; + } + return ret; +} + +GuestFilesystemInfoList *qmp_guest_get_fsinfo(Error **errp) +{ + error_setg(errp, QERR_UNSUPPORTED); + return NULL; +} + +GuestDiskInfoList *qmp_guest_get_disks(Error **errp) +{ + error_setg(errp, QERR_UNSUPPORTED); + return NULL; +} + +GuestDiskStatsInfoList *qmp_guest_get_diskstats(Error **errp) +{ + error_setg(errp, QERR_UNSUPPORTED); + return NULL; +} + +GuestCpuStatsList *qmp_guest_get_cpustats(Error **errp) +{ + error_setg(errp, QERR_UNSUPPORTED); + return NULL; +} +#endif /* CONFIG_FSFREEZE */ diff --git a/qga/commands-common.h b/qga/commands-common.h index 181fc330aa..2d9878a634 100644 --- a/qga/commands-common.h +++ b/qga/commands-common.h @@ -23,11 +23,22 @@ #endif #endif /* __linux__ */ +#ifdef __FreeBSD__ +#include +#ifdef UFSSUSPEND +#define CONFIG_FSFREEZE +#endif +#endif /* __FreeBSD__ */ + #if defined(CONFIG_FSFREEZE) || defined(CONFIG_FSTRIM) typedef struct FsMount { char *dirname; char *devtype; unsigned int devmajor, devminor; +#if defined(__FreeBSD__) + dev_t dev; + fsid_t fsid; +#endif QTAILQ_ENTRY(FsMount) next; } FsMount; diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 9574b83c92..49f9996a9c 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -33,20 +33,12 @@ #if defined(__linux__) #include -#include #include #include #ifdef CONFIG_LIBUDEV #include #endif - -#ifdef FIFREEZE -#define CONFIG_FSFREEZE -#endif -#ifdef FITRIM -#define CONFIG_FSTRIM -#endif #endif #ifdef __FreeBSD__ @@ -623,9 +615,6 @@ void qmp_guest_file_flush(int64_t handle, Error **errp) } } -/* linux-specific implementations. avoid this if at all possible. */ -#if defined(__linux__) - #if defined(CONFIG_FSFREEZE) || defined(CONFIG_FSTRIM) void free_fs_mount_list(FsMountList *mounts) { @@ -644,6 +633,156 @@ void free_fs_mount_list(FsMountList *mounts) } #endif +#if defined(CONFIG_FSFREEZE) +typedef enum { + FSFREEZE_HOOK_THAW = 0, + FSFREEZE_HOOK_FREEZE, +} FsfreezeHookArg; + +static const char *fsfreeze_hook_arg_string[] = { + "thaw", + "freeze", +}; + +static void execute_fsfreeze_hook(FsfreezeHookArg arg, Error **errp) +{ + int status; + pid_t pid; + const char *hook; + const char *arg_str = fsfreeze_hook_arg_string[arg]; + Error *local_err = NULL; + + hook = ga_fsfreeze_hook(ga_state); + if (!hook) { + return; + } + if (access(hook, X_OK) != 0) { + error_setg_errno(errp, errno, "can't access fsfreeze hook '%s'", hook); + return; + } + + slog("executing fsfreeze hook with arg '%s'", arg_str); + pid = fork(); + if (pid == 0) { + setsid(); + reopen_fd_to_null(0); + reopen_fd_to_null(1); + reopen_fd_to_null(2); + + execl(hook, hook, arg_str, NULL); + _exit(EXIT_FAILURE); + } else if (pid < 0) { + error_setg_errno(errp, errno, "failed to create child process"); + return; + } + + ga_wait_child(pid, &status, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + + if (!WIFEXITED(status)) { + error_setg(errp, "fsfreeze hook has terminated abnormally"); + return; + } + + status = WEXITSTATUS(status); + if (status) { + error_setg(errp, "fsfreeze hook has failed with status %d", status); + return; + } +} + +/* + * Return status of freeze/thaw + */ +GuestFsfreezeStatus qmp_guest_fsfreeze_status(Error **errp) +{ + if (ga_is_frozen(ga_state)) { + return GUEST_FSFREEZE_STATUS_FROZEN; + } + + return GUEST_FSFREEZE_STATUS_THAWED; +} + +int64_t qmp_guest_fsfreeze_freeze(Error **errp) +{ + return qmp_guest_fsfreeze_freeze_list(false, NULL, errp); +} + +int64_t qmp_guest_fsfreeze_freeze_list(bool has_mountpoints, + strList *mountpoints, + Error **errp) +{ + int ret; + FsMountList mounts; + Error *local_err = NULL; + + slog("guest-fsfreeze called"); + + execute_fsfreeze_hook(FSFREEZE_HOOK_FREEZE, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return -1; + } + + QTAILQ_INIT(&mounts); + if (!build_fs_mount_list(&mounts, &local_err)) { + error_propagate(errp, local_err); + return -1; + } + + /* cannot risk guest agent blocking itself on a write in this state */ + ga_set_frozen(ga_state); + + ret = qmp_guest_fsfreeze_do_freeze_list(has_mountpoints, mountpoints, + mounts, errp); + + free_fs_mount_list(&mounts); + /* We may not issue any FIFREEZE here. + * Just unset ga_state here and ready for the next call. + */ + if (ret == 0) { + ga_unset_frozen(ga_state); + } else if (ret < 0) { + qmp_guest_fsfreeze_thaw(NULL); + } + return ret; +} + +int64_t qmp_guest_fsfreeze_thaw(Error **errp) +{ + int ret; + + ret = qmp_guest_fsfreeze_do_thaw(errp); + if (ret >= 0) { + ga_unset_frozen(ga_state); + execute_fsfreeze_hook(FSFREEZE_HOOK_THAW, errp); + } else { + ret = 0; + } + + return ret; +} + +static void guest_fsfreeze_cleanup(void) +{ + Error *err = NULL; + + if (ga_is_frozen(ga_state) == GUEST_FSFREEZE_STATUS_FROZEN) { + qmp_guest_fsfreeze_thaw(&err); + if (err) { + slog("failed to clean up frozen filesystems: %s", + error_get_pretty(err)); + error_free(err); + } + } +} +#endif + +/* linux-specific implementations. avoid this if at all possible. */ +#if defined(__linux__) #if defined(CONFIG_FSFREEZE) static char *get_pci_driver(char const *syspath, int pathlen, Error **errp) @@ -1467,153 +1606,6 @@ GuestFilesystemInfoList *qmp_guest_get_fsinfo(Error **errp) free_fs_mount_list(&mounts); return ret; } - - -typedef enum { - FSFREEZE_HOOK_THAW = 0, - FSFREEZE_HOOK_FREEZE, -} FsfreezeHookArg; - -static const char *fsfreeze_hook_arg_string[] = { - "thaw", - "freeze", -}; - -static void execute_fsfreeze_hook(FsfreezeHookArg arg, Error **errp) -{ - int status; - pid_t pid; - const char *hook; - const char *arg_str = fsfreeze_hook_arg_string[arg]; - Error *local_err = NULL; - - hook = ga_fsfreeze_hook(ga_state); - if (!hook) { - return; - } - if (access(hook, X_OK) != 0) { - error_setg_errno(errp, errno, "can't access fsfreeze hook '%s'", hook); - return; - } - - slog("executing fsfreeze hook with arg '%s'", arg_str); - pid = fork(); - if (pid == 0) { - setsid(); - reopen_fd_to_null(0); - reopen_fd_to_null(1); - reopen_fd_to_null(2); - - execl(hook, hook, arg_str, NULL); - _exit(EXIT_FAILURE); - } else if (pid < 0) { - error_setg_errno(errp, errno, "failed to create child process"); - return; - } - - ga_wait_child(pid, &status, &local_err); - if (local_err) { - error_propagate(errp, local_err); - return; - } - - if (!WIFEXITED(status)) { - error_setg(errp, "fsfreeze hook has terminated abnormally"); - return; - } - - status = WEXITSTATUS(status); - if (status) { - error_setg(errp, "fsfreeze hook has failed with status %d", status); - return; - } -} - -/* - * Return status of freeze/thaw - */ -GuestFsfreezeStatus qmp_guest_fsfreeze_status(Error **errp) -{ - if (ga_is_frozen(ga_state)) { - return GUEST_FSFREEZE_STATUS_FROZEN; - } - - return GUEST_FSFREEZE_STATUS_THAWED; -} - -int64_t qmp_guest_fsfreeze_freeze(Error **errp) -{ - return qmp_guest_fsfreeze_freeze_list(false, NULL, errp); -} - -int64_t qmp_guest_fsfreeze_freeze_list(bool has_mountpoints, - strList *mountpoints, - Error **errp) -{ - int ret; - FsMountList mounts; - Error *local_err = NULL; - - slog("guest-fsfreeze called"); - - execute_fsfreeze_hook(FSFREEZE_HOOK_FREEZE, &local_err); - if (local_err) { - error_propagate(errp, local_err); - return -1; - } - - QTAILQ_INIT(&mounts); - if (!build_fs_mount_list(&mounts, &local_err)) { - error_propagate(errp, local_err); - return -1; - } - - /* cannot risk guest agent blocking itself on a write in this state */ - ga_set_frozen(ga_state); - - ret = qmp_guest_fsfreeze_do_freeze_list(has_mountpoints, mountpoints, - mounts, errp); - - free_fs_mount_list(&mounts); - /* We may not issue any FIFREEZE here. - * Just unset ga_state here and ready for the next call. - */ - if (ret == 0) { - ga_unset_frozen(ga_state); - } else if (ret < 0) { - qmp_guest_fsfreeze_thaw(NULL); - } - return ret; -} - -int64_t qmp_guest_fsfreeze_thaw(Error **errp) -{ - int ret; - - ret = qmp_guest_fsfreeze_do_thaw(errp); - if (ret >= 0) { - ga_unset_frozen(ga_state); - execute_fsfreeze_hook(FSFREEZE_HOOK_THAW, errp); - } else { - ret = 0; - } - - return ret; -} - -static void guest_fsfreeze_cleanup(void) -{ - Error *err = NULL; - - if (ga_is_frozen(ga_state) == GUEST_FSFREEZE_STATUS_FROZEN) { - qmp_guest_fsfreeze_thaw(&err); - if (err) { - slog("failed to clean up frozen filesystems: %s", - error_get_pretty(err)); - error_free(err); - } - } -} #endif /* CONFIG_FSFREEZE */ #if defined(CONFIG_FSTRIM) diff --git a/qga/main.c b/qga/main.c index 0d27c97d38..b3580508fa 100644 --- a/qga/main.c +++ b/qga/main.c @@ -37,12 +37,7 @@ #include "qga/service-win32.h" #include "qga/vss-win32.h" #endif -#ifdef __linux__ -#include -#ifdef FIFREEZE -#define CONFIG_FSFREEZE -#endif -#endif +#include "commands-common.h" #ifndef _WIN32 #ifdef __FreeBSD__ diff --git a/qga/meson.build b/qga/meson.build index 409f49a000..456ba4c29f 100644 --- a/qga/meson.build +++ b/qga/meson.build @@ -75,6 +75,9 @@ qga_ss.add(when: 'CONFIG_POSIX', if_true: files( qga_ss.add(when: 'CONFIG_LINUX', if_true: files( 'commands-linux.c', )) +qga_ss.add(when: 'CONFIG_BSD', if_true: files( + 'commands-bsd.c', +)) qga_ss.add(when: 'CONFIG_WIN32', if_true: files( 'channel-win32.c', 'commands-win32.c', From patchwork Mon Oct 3 09:39:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 12997416 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 B2FB1C433FE for ; Mon, 3 Oct 2022 09:57:48 +0000 (UTC) Received: from localhost ([::1]:56958 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ofICp-00037r-Ji for qemu-devel@archiver.kernel.org; Mon, 03 Oct 2022 05:57:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54038) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofHvL-0006Rs-9t for qemu-devel@nongnu.org; Mon, 03 Oct 2022 05:39:43 -0400 Received: from mail-eopbgr80119.outbound.protection.outlook.com ([40.107.8.119]:34208 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 1ofHvJ-0002U6-O1 for qemu-devel@nongnu.org; Mon, 03 Oct 2022 05:39:43 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iptPtbUwQPAN96G85M8VdqwMf7HG3OG3p84P4sRL2uYXwo5lgUOiPN1hDVS0HfQG+imDUo1xIdI2Y4MzRXxGv/Vm9QipS2q1MNAGqstTQKHcug0k07e6V5IMRlJon/9vZ88dy3oHmdqkrdBWTPqQ2UQ5qmtDpvT7DB5ErImTNqDQ3bpbJjhFCwaFaEMCY5FkzFl6H7K6Ky5FZNGpdC+/zMfCbdLgnNgIy1tWXVGk2+q2a6JEFRnjRfJsx0fpl7iux5475t5oaDGt75+5qobPEupguQPPM81vAzBCv5H3NrFjAnw+/PlKfRsJpTbjGkMxOwOqe1dyaXOE0pLcVF/V4w== 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=Gwi7mqwrkktrvF2e3NWIDyzILu4okqwx7LzXpwqJwjI=; b=l7Wsv4/5xIx+n3QPu9zPkUgroglc59APGcVobePYavkiQ/jeYww7JXbAMw+vUus9bIzIoAj6VxyEmG4UqGl6q3nZGHAPiU5SiNwjqkoHdQLILGNVouJTwAJFFuv88ShDRHcevYjMyDpKlgFba2ZLUrGPab+ORw/l9UsyR+EusUbjJ2Sdrw9g6I1LnV2TvyCp6Wpn5/rvWSxjaaMfhQhVp7nyrfufuOILOMjqg0H+627Qon2BjFGwBaZQie39VF+NUxb4e1jO4uSswQB2XdnsGU/HWYrJ/pTAurWmOfNKyTgXAlEV7x8SZ74bvcUXBVmYZ2sw/53AS+3eVA3yKozTqA== 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=Gwi7mqwrkktrvF2e3NWIDyzILu4okqwx7LzXpwqJwjI=; b=n4zBocGPmjwCdBdDYy5NIXYwqq+gd6/WbILttJx1L6/MhbDqRNaTdnx3Vkx7aDEZycijRzNLStP3MEj8YPpLl4CLZO7hKAK8gEPMQ+PHgXuUImI9gbSCqJ27KHT8a2Obszqv5jCr0v0Z5XWGEPAclvDMl3DL+zHIye6bTxx3Qn5xAWtM1sGjLlgn/NSBzrZL8dz0UHhNHkILJgpAy9g1ZCai+oqp5QXRImwl0yZTuMHfF0yK4d112XVzKpPzkjBChsKKquksk8q5DXICRnK7hn85tgQijaKCbShWL9C0eFDbWIEJqABMbf7x+He86qjm18ddztz5wCnyDnOAvhJCpA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) by DB9PR08MB8203.eurprd08.prod.outlook.com (2603:10a6:10:39e::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5676.17; Mon, 3 Oct 2022 09:39:23 +0000 Received: from AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::5174:25c7:6df8:741b]) by AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::5174:25c7:6df8:741b%8]) with mapi id 15.20.5676.028; Mon, 3 Oct 2022 09:39:23 +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 v3 4/7] qga: Add shutdown/halt/reboot support for FreeBSD Date: Mon, 3 Oct 2022 11:39:08 +0200 Message-Id: <20221003093911.1844031-5-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221003093911.1844031-1-alexander.ivanov@virtuozzo.com> References: <20221003093911.1844031-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: FR3P281CA0096.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a1::8) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR08MB7095:EE_|DB9PR08MB8203:EE_ X-MS-Office365-Filtering-Correlation-Id: 7edd238b-0eb3-455f-bf97-08daa5232782 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sUWuf/1bt9Fon3Ro5rkgi7NOXDIsIw14dZnsxXkeq8/ik8QXNhXUFoT5m5ImDvoDHyuusvy3piPmUnqB7W0ZNPzGdBNfuLciJD39QA8W929vVqTOUA1RzFBCIQ2GjOBy1YkmLK7+U5zVjy4mmDFqjCsqJBTahiSVzx0mvdjy8GKSpYZkCec1edd35cHVA9ZgevZ1W+IUXC4hip8MOqk6evaN8CshyErfIQMtGz6OIzGstq9fEOkPFntljQsayldEixIUoysfwOwMkKLW+h5+f9qPxH1Z30ZtBn3a9mhPTJO7gsyDcd2ctfD8WyOik5+eOcRbjoN58l9CAgi3EOjdW/PhI1sxhcfiaZmaOa1D6XpznvF4BBLKqaIhvVOiTUeVHzbdfbQHG+/pV4G6UHSVTLuKCQjgaMd2ehC9nctB9qPOS3O0mpNSYZBw8SwqeEX6xLQLDDbD24N3hb7HfNCrLza2FeTsH64C2w662pvIuBjLYj8pSi18JkmDafZ+J1Ruqpa64sN6+8NoQ7egsXzAXTRxMNc7xuMT0jbghlvBewnDXk0GVNx1OHn1lyaX2AwNR18P4O7UeBK2OuFSnrX75i+Lc/oOaPcpDcJ7LbqZSv12rftLALYxFNUkMvGjtAU/8p6BZucZq39xA8+FfJ+Sc9HIluXLtIW8GP+1IJJIAvFFr9rZeU+g2DWY7kDgFumv4CZscGgsuSciu1pF+Gfb9eCJ7LM8fTorquE2H8/PrVMsuGKnaGtaw0vwjHgEh4wzgDWtkPFzCIF6kwBEb7vmuQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR08MB7095.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(4636009)(366004)(136003)(346002)(39850400004)(376002)(396003)(451199015)(6666004)(316002)(66476007)(66556008)(26005)(4326008)(8676002)(6512007)(6506007)(52116002)(2616005)(6916009)(478600001)(6486002)(66946007)(36756003)(38350700002)(38100700002)(86362001)(186003)(1076003)(44832011)(41300700001)(8936002)(5660300002)(2906002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?7GYzZoSx098SZfB9s0SGdn7FcxTs?= =?utf-8?q?m4xqBWw5uL51pDNbdcrtnE+aAIrzwskTQw6ViuOKT7Od9zqkeF/B8fFw59oYmtdOj?= =?utf-8?q?0ESeXDskanlsT2ttIjx5Elvd6x5otfKx0+AqG2G3YzFbhV3sCZOVFbWevllmV4ByW?= =?utf-8?q?bIfQe588JbYPB3o2Pt7H6G7QbkgXo3at5WHjQFT1EmN6gB8j1OES/3fhlQ9oH28fl?= =?utf-8?q?/WeDxUq9Y2Qe+yeI0M1jGm74Pvbn6ETepTaJYj3qVYCzARgnSeKzV7kmHbKIex0wY?= =?utf-8?q?nFjt+qd8+dP3tqkz8huXoGhDIOyb7khQJihHijJY6grIXoUFS/Sle2JehhqcNijZs?= =?utf-8?q?tzTUD0m8WOIAp9MtJNN4UswdkTCCEHwP2swxz6h/KMRD1m0iG8YCbp9IE288vxsrs?= =?utf-8?q?gqUiw2Hr7Ywzv1gTNbMsKE2ssr7sSQpHIOFB3l4laO67g85LanQP9SC8+aKMu3Zcr?= =?utf-8?q?LEeyld8JAT5R8gk7GEM2ZLIIJom1JGG3nD/TjOFBVr1P1A2ZtrwRoqdL/XT7kQDxM?= =?utf-8?q?sOHzFI0hHJ1qUhvSi3TXD1UCcuIed+OlkDh9BNn7xxRMqgml/eLw4K53m+KmWQ4c2?= =?utf-8?q?7kBM12W7fmnhUXCO29EiEE4l/dulTyurP5kGnJdwKCg7aBn3fMIKm3v8t0n1T/LlS?= =?utf-8?q?gwQ2EAXRjCGhTgDBBfzBIxZIcHK9nAErOsfjgtiD10mj34e/LWVC0MxSj1SyFkI9b?= =?utf-8?q?+9PLPYMQK1+g2f+Y1yWy3L9aTXqJX42lnTTT5PoGcw72cEmE5K/O91XmrCLGkB7vG?= =?utf-8?q?/FDV1EztuGKC29JW1cIS0ek5krIz5BWzfcJgC0biUPnv7Pz8e9s8OW/pfJ5ytXnCK?= =?utf-8?q?V+b40vanDMckOdOCcR4v/8b5JGInMMQJhZoUuzI36Gin6Rd3ETMrohgkNY+2CEt8y?= =?utf-8?q?Vk8BRjnfx1LRpX8GOtAzkXANgrN4YAdxRvFPriNycU71QqloBT+a5MJqW6SZKSStw?= =?utf-8?q?IsfK3E9x+eMJWNhssPDij/NbxbDKZoEVs0l3k91a4ryXbRCjz32QXDknz8QpjGClW?= =?utf-8?q?SShL7hfKjVNs7AbFe8R4SGET2VEkE4KqDDwmycxtCzDH1uRAP554KaHVCl9eWN+9u?= =?utf-8?q?AC+RoK3vgaheYGzQaVe9s68JG6nAZf4B0oIGEKidGzojJ7IpdZHZrJoa+VEXyMRkX?= =?utf-8?q?hxU6yRQ+bNVQYwiTv5Nf8O22t/QQmLd2qPxKAMA9eexgS4q8ku4end6nUBVO5vjOw?= =?utf-8?q?moTsuuDAhSPKZTJiHqWf37TL7td+MCAS8jRP277j5rDs2pGGe/ElHYwg91KPMsA9a?= =?utf-8?q?WdWQUq/W4WlSxSEN7gzqP8vMnVuetQD4NmCm9j4BPn9dOXlHluW7uCUgNaHO78/G2?= =?utf-8?q?mLf3R+s3VFCw3V2HVT+YRSHmX7AZjJRT7m/DxrwCz1Zu/dPaVqSTL0BO1ZHCgjZVA?= =?utf-8?q?BNJyHuB9HU5Tos+jirFeY5ZsqZKA8pe7t+sXt6GWggPXEjN4J++T2Z2C535NFOjYK?= =?utf-8?q?kqCp73rbWcRtU2rpHInmzmDuSAP5Zy+1rsMutt3VZ6x+NMcuxwweOvzBkCfa+mbK7?= =?utf-8?q?9/VQY0+8kk/3/CGaiNWFacS6gW903K5OGg=3D=3D?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7edd238b-0eb3-455f-bf97-08daa5232782 X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Oct 2022 09:39:23.2914 (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: 5XF4tj7J2DEOZEeUuIfhtJfAT84nKrECXY19fmGedWoAh/Z2YuWibZgjRmq82OHpE2/ZWGFGWvNcvRTDqTiimoVFsGnePfxMQ2EtVjVbmQY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR08MB8203 Received-SPF: pass client-ip=40.107.8.119; 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, 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" Add appropriate shutdown command arguments to qmp_guest_shutdown() for FreeBSD. Reviewed-by: Marc-André Lureau Signed-off-by: Alexander Ivanov Reviewed-by: Konstantin Kostiuk --- qga/commands-posix.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 49f9996a9c..88e0d0fe24 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -90,6 +90,10 @@ void qmp_guest_shutdown(bool has_mode, const char *mode, Error **errp) const char *powerdown_flag = "-i5"; const char *halt_flag = "-i0"; const char *reboot_flag = "-i6"; +#elif defined(CONFIG_BSD) + const char *powerdown_flag = "-p"; + const char *halt_flag = "-h"; + const char *reboot_flag = "-r"; #else const char *powerdown_flag = "-P"; const char *halt_flag = "-H"; @@ -120,6 +124,9 @@ void qmp_guest_shutdown(bool has_mode, const char *mode, Error **errp) #ifdef CONFIG_SOLARIS execl("/sbin/shutdown", "shutdown", shutdown_flag, "-g0", "-y", "hypervisor initiated shutdown", (char *)NULL); +#elif defined(CONFIG_BSD) + execl("/sbin/shutdown", "shutdown", shutdown_flag, "+0", + "hypervisor initiated shutdown", (char *)NULL); #else execl("/sbin/shutdown", "shutdown", "-h", shutdown_flag, "+0", "hypervisor initiated shutdown", (char *)NULL); From patchwork Mon Oct 3 09:39:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 12997398 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 0DFEBC433F5 for ; Mon, 3 Oct 2022 09:42:53 +0000 (UTC) Received: from localhost ([::1]:41164 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ofHyP-0000MB-0L for qemu-devel@archiver.kernel.org; Mon, 03 Oct 2022 05:42:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54040) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofHvN-0006TS-CU for qemu-devel@nongnu.org; Mon, 03 Oct 2022 05:39:45 -0400 Received: from mail-eopbgr80119.outbound.protection.outlook.com ([40.107.8.119]:34208 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 1ofHvL-0002U6-KY for qemu-devel@nongnu.org; Mon, 03 Oct 2022 05:39:45 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ja/g3xOduAAiV7MKbCcVRlmqDP91UWbf/YNLjVj7LN0nONsmVycquRknBT7ff7EX7RyveALg1Xx59gXgfNJQnmeKz3L7Cx8kU9nSTn4X9qNZWoylolZ58oSwt17gVZGlDiFT1/J3bZBJy8KhgBHr+cSPh06S8D86rmtjxiaENTqUqBhOfBytuVTlYiG+iUYjDHU6yoTWnouQ1N8DvrNfUAdza//+9SF7RaFng7PdkkZghjtKLL5TV/HZLUTWLMvj83aiaDRH44B03aXIqfVxYCN1xTmcuXHSGx59AQNQAndo7ZtIQKFavcWcuflw9sifz91RvLEX2/5pX/+rpEXz1w== 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=3AyknErPEb2iK1T9/eiwdanI8x8WzfCDcmkPNgBXRe8=; b=B+yiHTCGsMSzkn2fIdQ68u/EM8wjcROlvFujBuKIwcemzJ5ZWwLoz0Q3sBLjUvKapTSAo6xLBdixVl7UNtSn9G6IZb+VGT/1tndn5GXPF8v1sbLkW5ayZ5MxM5Ckx5wJsU8RrSfSB6/SWncrOC2taPoe3vQzi4YGaH9pVRvFuktqkfWxx4/4KyGUWjbP629oMaxEAyxwU5QqxnzyhfClswmtR7LfXOcPGxhixSHhQInEMSEGxqD9A0TX8qWBxk2GeS18dIgD6M2tAkAMmjo8Tfx+cNLfE6sM6a52jBskglRt/K3DW1hS5/mFvt3lKxSWZ8RP3YHLhi3ASXtdNPSv3Q== 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=3AyknErPEb2iK1T9/eiwdanI8x8WzfCDcmkPNgBXRe8=; b=nmhWMmAhmTxV2T/nSi8iY87e/J2QKyfQQhHyhRi/2A9eqnYR4bGXoeD5D6u0wEGWw5bYWIlWOk3NfrZ86KQjldd3h4Oo7TPZPMYNq962ucMFOWhTKkctftZuq131kjdRz4MKYBARR45ma92dgqz4XVGcVxuFU2/Hsi5Bes55j3KK8bhaRzQ34VR5K/cHy5HVNSG2eEdXepfJh4HrIT+UkEml3aoWvinTbv3yBFkYWLn0VhL/LzH8Bhs+EQXWdY8Q4yALposBu76zw/p/hoVfkUtTENv/RUZrbxtzOfa2C3GGR+zmMp8x4gmIETAgCuksbBYqxhYEFYXwF3vPlN8Gfg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) by DB9PR08MB8203.eurprd08.prod.outlook.com (2603:10a6:10:39e::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5676.17; Mon, 3 Oct 2022 09:39:24 +0000 Received: from AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::5174:25c7:6df8:741b]) by AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::5174:25c7:6df8:741b%8]) with mapi id 15.20.5676.028; Mon, 3 Oct 2022 09:39:24 +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 v3 5/7] qga: Add support for user password setting in FreeBSD Date: Mon, 3 Oct 2022 11:39:09 +0200 Message-Id: <20221003093911.1844031-6-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221003093911.1844031-1-alexander.ivanov@virtuozzo.com> References: <20221003093911.1844031-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: FR3P281CA0096.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a1::8) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR08MB7095:EE_|DB9PR08MB8203:EE_ X-MS-Office365-Filtering-Correlation-Id: 5f5ecf0f-08dd-4efe-5715-08daa52327dd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VFhFPQCFN0wUrfrL5WYNOnPw2CCpMOm+OvvNCCT+wYKD9lCXDvjjADO4Y+Z60LeOjbj3mYK/saC46GBI4WxQTB2G45YP9fSkSXb8qUgomLgR7gXZArwACHqomqh4bQ95VzbSci2GeGjLYg864+kODwbIBEj4oSAVCz5S+w9qVWw/UhsY5y2+/WpjDPPhliaM1+mJz6/rwzRmpCCFj5p6Xi3VEP8e8YLwVZ648/6xK6bss7mDNrtHRRezu7url/qcXeTTlnTtx1knamyf0RMGsIgvzihDZIybL7CW8lukwnaj5lZEwc11V60skAGLvKY8skAgDHbetLVNcolrZvCh4EG4efMGF41LouNXeqXaiXOJ52tqeqJnKjNhjKS7pGvXZHNnWIL6ugJ0PvcHVmdHYPLVnCfCeEI3D3/WTfX/kXKYnOrLXpVr20J7IkGAS4zb6M6PIWJkjE+/tt01duBYZtBMGo0qMkXwuY5KgN+QaSDt7VbBdVDfqiUzhrWf8qYEDeexn2ZhpNlcRuSaHBNhtYh91jroQWoV6bu9hyiiitlMIgdIDemMThVdm0BivObi+E37moymVD91DcUKtFjIjgW8Z/nCt8aMYwhKFxmEyboU3P87nEaNDZn3CVUbQD9wI3l9MmiQXW0EkaCjNHgRpUOHlbEsNFFP6WNrkDrj1I5ke3wu+wwYVBdvAWz0gM4Ef/pYzE2zICdkEWNv84NC0ofwos/DDnMTjjVdYUZgq8eXKjN5cUEVq46gQ+6vJp36 X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR08MB7095.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(4636009)(366004)(136003)(346002)(39850400004)(376002)(396003)(451199015)(6666004)(316002)(66476007)(66556008)(26005)(4326008)(8676002)(6512007)(6506007)(52116002)(2616005)(6916009)(478600001)(6486002)(66946007)(36756003)(38350700002)(38100700002)(86362001)(186003)(83380400001)(1076003)(44832011)(41300700001)(8936002)(5660300002)(2906002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: /WefOAu8DQzqIYLWqZJozUIf8AO+oMsnhZxjrbdMxpOB0PiRyZuPJDxHrj4Ky7owJMUWb1vJVjFWReDTWKkzecnq9JsGjm5mtk23lri/jlvHdrmYIWc2QLyEoctnaXrFJJhVsHSCicYsW53ZvuVpG3UzAA2mFhJvRJ+EzIaACZWdQS6Eh9jAeLlD7H06fDfHrklLD+MwhQ0Y+Q9WG3KQz5ZoiaUAzFU8SKiBiXK6lM75Q5/wckxjwf5VfG3jhTpVSEaAwoQ39kfi+h/k8Tt5i7kc9GGQpjHh/6R9iJ4/QuAGHPH7vA/QZzE1+UfzVg1MW80ZAF3CJ2RFN7e5bGGepuPT2KfRUYZ0bwywLgFuOQDQtB/evqGvRjI18/k8PVDG8LIKetEi2SjdUXMnjmOWL3/pWKjR0svWuJDAtsD+4NzTrcscoGuKjjIMD4nsccHeO1fRW3kp0Anpm2lxJWFjJZRafMrrrNHd4QPJ79df/6QrQTXM4fVB5x7teNrW4ul/5HVXsVI939M3fz1vkxmm72MSLO2NlNKRRB4xVv11kEiTl98FAL6pLYRhSOMdLUVmoQsbl5P0tumcyaJBq6cISsHMrbNgM5HhrHgfI/QzyZHaD0KJs2zFtniLhyjOTvV+qnbkEBJElDb/NzCDXtBZXG2sKz/OpEqbO80zCIf9LhgRljG51hcivW6VA3UGhSQyF+f0SsaCkZvId7XK7F1d3UnyjPsJ0gkUzWXivVLwi9j4/Tiwpqchh0DnIB1qPTvO/t3NcIdePcmxARwDItFkzXOSfN0e2fTqufjEf+muKQR8SjIlzzbGdmTisXpBgv1rIRtGqgDqpv7MSDlWZpN5J2pQH3Mf5a8G0BKWEtd7Clsxo9AuI8mOEW4LxRth2Ne73B1dywXSqg0hFKaTORxfv+eNgrxHhGCSK7uyBdTrST0/5ju863ZZcQgprch3HTB8Twe5WXqmACPCkfRSaz3Mc+XN6g78mwDAPEt1tAufIRaxZKongdzNFKTtlBiTxsUB8GUEi6+8l5H1nT4iBmKcwPiTB2T918lEJSp6KmiXdsByIoV9fl/zi6sdduw/zEviWiQ2EJ/xi+/5MfckIR8W7M8cUnHBuwTdxYQEw6DKJUQ/A2MrQugikIp3prgnCmXjXVHqYTW2FBBZeZRagJq4sHz1zLex1YjnCye4smat6tl5cP/vEN6gnqQHrt5WRrTJjD/tV5yBaBAQxsoN1lMPTj0TIABpyiYHDJ9grQNv72Xc82By4aTO56u4DTdpFx3w0E6bcal2ZHI/UPq/OFAmoLEeJHH19quIROk/dpVPjT0uBHAvPM9n1+nn/nXfJut+wXcEVYj2PijwNqZCsOj1WOL7SqFDVhVFTRfCB7XlweWXRGgw06SX8m6vjl5iLPOuyEWm7Is/ygCGIeIYR4M66R+lmF3VKMQzRUlmftlMUKkh5XpCp3PfXsde+G4zdV875ZfNp4EJttCLeY+FXpZPfGhyYxEWVfTH20ZDbeDONiY+L50Tdy7dujPh10LaEEk4HHzgctPvA+UDsbAlBls8w5g0r0ZTOA+OfAl73p2J/T5DmClUf6qfsysWDQfh9uMpzltbS1eUJcosxnjiqGxf2w== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5f5ecf0f-08dd-4efe-5715-08daa52327dd X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Oct 2022 09:39:23.8695 (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: udYl6pZF1ijJMsft3ldIRkrv2G+qJynRdUDUjvvdDY4ZMPF43cPLb6ApO6nHQSSBu56mODAa8qDU1bseLjcWq9ZGTJlAcNnxMtQhu7itodM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR08MB8203 Received-SPF: pass client-ip=40.107.8.119; 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, 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" Move qmp_guest_set_user_password() from __linux__ condition to (__linux__ || __FreeBSD__) condition. Add command and arguments for password setting in FreeBSD. Signed-off-by: Alexander Ivanov Reviewed-by: Marc-André Lureau Reviewed-by: Konstantin Kostiuk --- qga/commands-posix.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 88e0d0fe24..f5b9e5c530 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -2122,7 +2122,9 @@ int64_t qmp_guest_set_vcpus(GuestLogicalProcessorList *vcpus, Error **errp) return processed; } +#endif /* __linux__ */ +#if defined(__linux__) || defined(__FreeBSD__) void qmp_guest_set_user_password(const char *username, const char *password, bool crypted, @@ -2156,10 +2158,15 @@ void qmp_guest_set_user_password(const char *username, goto out; } +#ifdef __FreeBSD__ + chpasswddata = g_strdup(rawpasswddata); + passwd_path = g_find_program_in_path("pw"); +#else chpasswddata = g_strdup_printf("%s:%s\n", username, rawpasswddata); - chpasswdlen = strlen(chpasswddata); - passwd_path = g_find_program_in_path("chpasswd"); +#endif + + chpasswdlen = strlen(chpasswddata); if (!passwd_path) { error_setg(errp, "cannot find 'passwd' program in PATH"); @@ -2180,11 +2187,17 @@ void qmp_guest_set_user_password(const char *username, reopen_fd_to_null(1); reopen_fd_to_null(2); +#ifdef __FreeBSD__ + const char *h_arg; + h_arg = (crypted) ? "-H" : "-h"; + execl(passwd_path, "pw", "usermod", "-n", username, h_arg, "0", NULL); +#else if (crypted) { execl(passwd_path, "chpasswd", "-e", NULL); } else { execl(passwd_path, "chpasswd", NULL); } +#endif _exit(EXIT_FAILURE); } else if (pid < 0) { error_setg_errno(errp, errno, "failed to create child process"); @@ -2227,7 +2240,17 @@ out: close(datafd[1]); } } +#else /* __linux__ || __FreeBSD__ */ +void qmp_guest_set_user_password(const char *username, + const char *password, + bool crypted, + Error **errp) +{ + error_setg(errp, QERR_UNSUPPORTED); +} +#endif /* __linux__ || __FreeBSD__ */ +#ifdef __linux__ static void ga_read_sysfs_file(int dirfd, const char *pathname, char *buf, int size, Error **errp) { @@ -2764,14 +2787,6 @@ int64_t qmp_guest_set_vcpus(GuestLogicalProcessorList *vcpus, Error **errp) return -1; } -void qmp_guest_set_user_password(const char *username, - const char *password, - bool crypted, - Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); -} - GuestMemoryBlockList *qmp_guest_get_memory_blocks(Error **errp) { error_setg(errp, QERR_UNSUPPORTED); From patchwork Mon Oct 3 09:39:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 12997417 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 487D0C433FE for ; Mon, 3 Oct 2022 10:03:16 +0000 (UTC) Received: from localhost ([::1]:54018 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ofII7-0007br-8W for qemu-devel@archiver.kernel.org; Mon, 03 Oct 2022 06:03:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39162) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofHvP-0006XP-OD for qemu-devel@nongnu.org; Mon, 03 Oct 2022 05:39:47 -0400 Received: from mail-eopbgr80119.outbound.protection.outlook.com ([40.107.8.119]:34208 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 1ofHvN-0002U6-O9 for qemu-devel@nongnu.org; Mon, 03 Oct 2022 05:39:47 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=c3I6H2bOxjJiAko77L6vGk8zZnYh5Bnk9X6/dUQTVh7RFOr8nNgw2XpxDTOGexSfd3I5E9rAkdN2LMrraRwVtJwoU1xm0HR4sjjcE8UGoBuwVoOCQimfl03wvGNXssqAUY6N/dknGtfDIEcxrjNRVp8HauGTwmNwGI2zRaOKdVl160m1OuSsFNIpzEMbZdO2pTGgp4/75tTwD9qSozpNZKPColh2WvzVoBrZZcDdoaOXS2yrWhPd3WfQeFaDe9rhZglVYE6ewIUIMteDnVdnXdAkGbbqHQJ+n7tTw7rqJkPhTltz+utHmup9BOxaQxKmmq0fI4yZ/WmPhfLovGzTlA== 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=GMmb0KLPqmWq8e9j4AHAUqbvFRHTz+zJGmVL75zIHYk=; b=ZA21u4YQcCgG95QEwSl5dOx32RWgpY0whfbEwTuf1VI/l2nF9zNhi+m9jUgp6/r+yHBbYVGobUURsCCGo8pMPsBRNBCG5jzvYyS7LbZsMEoUJznZDV3uRKd5WDH4jNoATImwBhkIgXxOgNnjXp9gBBmJBSOiXHYJgU7eLywzVjpazq7StG/JtM7cmF1wDn1MU7CEQZlgRmxNuvls3NWuCXqLJPoPXxkgSCRurqyI/h3cwzwkP3yBEPq/NuPyJJ/wtyFWjT24nudMaX6dDTFQJkG9bn7W4/HvyFozwiLzaRN8l1BAcTE7PBo7Tuaf1SKju+p3LpKfCq8x6VyEDDTzsw== 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=GMmb0KLPqmWq8e9j4AHAUqbvFRHTz+zJGmVL75zIHYk=; b=EeAsdCifkrqDZ98buLhPcYooC5fVzpbRT5glxLffevqWFy1T/SNZxP7WHqIOIGo1d4PZTy2uX+T54lw6ByIxJ5WMuj9kxcek9Gk2sjP1E3okcJRoMGA5eiunUI+wm+2+CAmaZJPPkCpDIZkuOk3NYDG1MljHvaOGkahvdBeEIsianryC/v6WGIAv9Ua2JuVMEYDp3mwWz6sbjLBKHErWmidju+AtcWPlH7schtOmkwORXgr1MGElCkDFp2vGJUEXgV4axA1owoz1Gplr9v4324RqNcrQr6UIo9FEQtIysC37oY5Tk2q6FbRknpMB/9o/g3TGw6HOA5IlXlVUgU9ezA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) by DB9PR08MB8203.eurprd08.prod.outlook.com (2603:10a6:10:39e::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5676.17; Mon, 3 Oct 2022 09:39:24 +0000 Received: from AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::5174:25c7:6df8:741b]) by AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::5174:25c7:6df8:741b%8]) with mapi id 15.20.5676.028; Mon, 3 Oct 2022 09:39:24 +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 v3 6/7] qga: Move HW address getting to a separate function Date: Mon, 3 Oct 2022 11:39:10 +0200 Message-Id: <20221003093911.1844031-7-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221003093911.1844031-1-alexander.ivanov@virtuozzo.com> References: <20221003093911.1844031-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: FR3P281CA0096.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a1::8) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR08MB7095:EE_|DB9PR08MB8203:EE_ X-MS-Office365-Filtering-Correlation-Id: f26864a1-b788-410e-6655-08daa523283c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Z5uTOTTz5aZe0NFHJvLPQ/ZBFVLt4nJHJYdHFT+2Oo5fHwnWNLcXjX5L9pFkWHTdKUN95J02ruKuP7E3Or3UWwy/SrRSYgBvfLAZDXXVrS8xYsYOEPuQZ8Dzix6ynu/5bdWNPI8ejdUhP2aEfdsQKoRt04f+5dwtVITgcoMedzWXuKdlS/rpwdS316iXhGTge3cK2ayu/lYSsJt9jZEfEIak5VRUZKJg6yTfCxkHX6KV++Kpt1mcuTQqjaKAESgzmOQ052n39kP7UCNjfCk+ChFedtJKsd+oryGwTYK67YYFppoxHK3HW5aooHW5SmbNPRUYLt8DyiyLtAKgNYTsMjRcRO5Y6yMuR41NZBFuTGyhhIqZgv5C/oCtiNFKlHgapthB/y9QpUoxfHDtHwtLj03lJ8P+CIq1O9tNLAiiA5PZ1FB4rtEHMZJAQAuG/cNIVuQY3kP3xCqXhKCun5lFRk6itRszwe700DicKQUCy2GZRRXk5MQ8hSz8+KpbVnj/ENoT4hUwWJpem3V9IPH27A1yrb1I7l04OipgieigxSkT4a85tf24aWhfEVsq5hCC7Nn6bjDevspU72Wv2TCiA/xEopMExF5fAueqB/NKX95YTkFVlDOOc/+bGASDNju23ogoaevR6X7dirUtqILdr7XLhWrhCXp63e/vQmgeyXFiiD8O7jV/ffBpv/DZMz32GwJz/61WNJ1f+K/DrwUHYjetJIMx4FdhR3Dek5I1nfEF0u30l3DzuHFNKV9F1ERhRcmySDO7aj5qs3IHvj4PUg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR08MB7095.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(4636009)(366004)(136003)(346002)(39850400004)(376002)(396003)(451199015)(6666004)(316002)(66476007)(66556008)(26005)(4326008)(8676002)(6512007)(6506007)(52116002)(2616005)(6916009)(478600001)(6486002)(66946007)(36756003)(38350700002)(38100700002)(86362001)(186003)(83380400001)(1076003)(44832011)(41300700001)(8936002)(5660300002)(2906002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?fqOmUHJYNBblA2PsbtCQ/5E85rPC?= =?utf-8?q?0Kogsjmq9KP/xYrwMmP8TT+KKXUAKE4DJ0SYfpDT2B7ak8pZmos/sqGrdw259JseO?= =?utf-8?q?FJ9ElNd7mYjcj8OVjv8xME5pAP+ZMs8n0tR1f/xyK5N3uDiy8KcXL1VnVBEufFdPU?= =?utf-8?q?G5TtAZ1jHicOJp5HuznrccxzXw/0KUkXUhAqx0Fd52QwxFR75iD38ZrkqxbRVXcaW?= =?utf-8?q?D9Gt9QYUVm/UuJj7srWQdhr8H08cGr9DfRiSYFgrO7jNZE2mrdnz9GDC1mB01WKkL?= =?utf-8?q?rPN+LbshMXXBKMOgAB2nCf53B94hst6rYeXdeWCSyHemtjXFIrc7htvkKgxFTRBNL?= =?utf-8?q?QsAjZ2Giu0byF7GIj7cYqa+92g0eRyYzG2gRSVifN7oQ8qPqD1OFXVBcKWTU0Q5IU?= =?utf-8?q?xb00tImcAxejNVHKmPFgPsFD6L2DEAnxVJ9RibqNLHTcSChYfyL+l+XSy3wdEYY0g?= =?utf-8?q?iJc0fShYkjozjkxj6ltaxojNH3e9EwZAuFTeLM12LlT+Bizwp2iZ0o3e45Z1F7KT0?= =?utf-8?q?ZPzDvj/2J1P5HHDjqfsXYiHPOxpuZRBur7tXkWH47UiAbKxrMM9W0kPdjjFLYOZZc?= =?utf-8?q?3Q7UTLK+R4qHHdh4OFgCKFiYz3TLFsXCP296dFcXGnw8g4ZLDlip8gH5TVDP10iT2?= =?utf-8?q?w1nJrgjM3SZ9SrCF0Kp2CM9KXtyzpq9jorBW+8532s43S3kBVTnM6rIMj/DRaRLNG?= =?utf-8?q?/f/Mv3+j+IiWQrFg04e1gxH34nasLAlEWXVAQK9lKfadrzq04+hB0OfJVFnQYXMsz?= =?utf-8?q?nkKG60/uh7kCCIxaQSWhSvhBo31rP40ahHEu/fq7qAW+yfzasm74T7jOzcMTfP3Ob?= =?utf-8?q?5XMfnia+k9SYwJzsuFnK/WJVlNQ3yA7Jf+0WLmggLhRCUb97qD2Bu77HP1t7iXIFh?= =?utf-8?q?EKYpBQdktHsA82Na+hA2TqwDO98+Qpk732kfwoaAXMGs+DZmrIpfkDoWLw3zqNGWf?= =?utf-8?q?CLhyHfcYTrIouRsWvZjG53f5pNOU+TwfDtdTO9ZGF71D1eNweC1xfJ2BwaDnWw+kz?= =?utf-8?q?d3pg09j6KUcKCTaDe5BOmBKIWlMffms+Q8pdaoN0hgRN4hv/OFyIOQ8LqLAQwuiqH?= =?utf-8?q?gKqFWLdLiYqtkQ0EDrmtGEFTvfCJnu1PXw5U4K2BUg9Gu3xVwlmASr3p80V8VpDvz?= =?utf-8?q?BAoqi0Lw//8Pm8IK/0elcgnW35ChJZoBWwGYBc3WaCgiS19Hs/au+hgHspwAbVPjz?= =?utf-8?q?TzS6vEDil1jOGubk6/MbhuWotIRBFEw4HJTydEmvOUQ0CEB0h5asEe8vNMzu2a4x5?= =?utf-8?q?WcaC80XmVjspf+eH7pXfb81X4gtNgAMUPDIXKlVayynweY5dWv4KTyfQq+0AtRb5G?= =?utf-8?q?1mEUAU0bMqFxWJ606IMoIPhLiaInfHgXAwaFw639iOz6t0tFHbxtjfoHDhZ8KVlsp?= =?utf-8?q?h1EyfZkIZbMUrRY5gl1bPIW/yoQbHX26zgp+zA7SuPu6oFy0Jh1elKxaU8WfrMmxK?= =?utf-8?q?pFzGL0JDHw/fFoHm71c+4eW3nCOrV+s06TZC16ls6BJmR+FbbliCHC2Zjx3bxyHn+?= =?utf-8?q?E7KKgqpwbl7NuirxLNQPQbUF7nzkMVoP5Q=3D=3D?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: f26864a1-b788-410e-6655-08daa523283c X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Oct 2022 09:39:24.5081 (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: z0Tt1jQJO2sJIiPxBCEKBDBFrWeKnMacmKzFkX8GY0OMDjZGNwm6FBdo24za/N0tXqaVwEaqJ/9NN8+xzVKZiraBHubY6PYz9L/RPSEBv64= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR08MB8203 Received-SPF: pass client-ip=40.107.8.119; 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, 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" In the next patch FreeBSD support for guest-network-get-interfaces will be added. Previously move Linux-specific code of HW address getting to a separate functions and add a dumb function to commands-bsd.c. Signed-off-by: Alexander Ivanov Reviewed-by: Marc-André Lureau Reviewed-by: Konstantin Kostiuk --- qga/commands-bsd.c | 16 +++++++ qga/commands-common.h | 6 +++ qga/commands-posix.c | 100 ++++++++++++++++++++++++------------------ 3 files changed, 80 insertions(+), 42 deletions(-) diff --git a/qga/commands-bsd.c b/qga/commands-bsd.c index ca06692179..40f7ec7600 100644 --- a/qga/commands-bsd.c +++ b/qga/commands-bsd.c @@ -167,3 +167,19 @@ GuestCpuStatsList *qmp_guest_get_cpustats(Error **errp) return NULL; } #endif /* CONFIG_FSFREEZE */ + +#ifdef HAVE_GETIFADDRS +/* + * Fill "buf" with MAC address by ifaddrs. Pointer buf must point to a + * buffer with ETHER_ADDR_LEN length at least. + * + * Returns -1 in case of an error, otherwise 0. "obtained" arguument is + * true if a MAC address was obtained successful, otherwise false. + */ +int guest_get_hw_addr(struct ifaddrs *ifa, unsigned char *buf, + bool *obtained, Error **errp) +{ + *obtained = false; + return 0; +} +#endif /* HAVE_GETIFADDRS */ diff --git a/qga/commands-common.h b/qga/commands-common.h index 2d9878a634..a9cdaf7278 100644 --- a/qga/commands-common.h +++ b/qga/commands-common.h @@ -56,6 +56,12 @@ int64_t qmp_guest_fsfreeze_do_freeze_list(bool has_mountpoints, int qmp_guest_fsfreeze_do_thaw(Error **errp); #endif /* CONFIG_FSFREEZE */ +#ifdef HAVE_GETIFADDRS +#include +int guest_get_hw_addr(struct ifaddrs *ifa, unsigned char *buf, + bool *obtained, Error **errp); +#endif + typedef struct GuestFileHandle GuestFileHandle; GuestFileHandle *guest_file_handle_find(int64_t id, Error **errp); diff --git a/qga/commands-posix.c b/qga/commands-posix.c index f5b9e5c530..2a172c6492 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -41,20 +41,12 @@ #endif #endif -#ifdef __FreeBSD__ -/* - * The code under HAVE_GETIFADDRS condition can't be compiled in FreeBSD. - * Fix it in one of the following patches. - */ -#undef HAVE_GETIFADDRS -#endif - #ifdef HAVE_GETIFADDRS #include #include #include +#include #include -#include #ifdef CONFIG_SOLARIS #include #endif @@ -2889,6 +2881,57 @@ static int guest_get_network_stats(const char *name, return -1; } +#ifndef __FreeBSD__ +/* + * Fill "buf" with MAC address by ifaddrs. Pointer buf must point to a + * buffer with ETHER_ADDR_LEN length at least. + * + * Returns -1 in case of an error, otherwise 0. "obtained" arguument is + * true if a MAC address was obtained successful, otherwise false. + */ +int guest_get_hw_addr(struct ifaddrs *ifa, unsigned char *buf, + bool *obtained, Error **errp) +{ + struct ifreq ifr; + int sock; + + *obtained = false; + + /* we haven't obtained HW address yet */ + sock = socket(PF_INET, SOCK_STREAM, 0); + if (sock == -1) { + error_setg_errno(errp, errno, "failed to create socket"); + return -1; + } + + memset(&ifr, 0, sizeof(ifr)); + pstrcpy(ifr.ifr_name, IF_NAMESIZE, ifa->ifa_name); + if (ioctl(sock, SIOCGIFHWADDR, &ifr) == -1) { + /* + * We can't get the hw addr of this interface, but that's not a + * fatal error. + */ + if (errno == EADDRNOTAVAIL) { + /* The interface doesn't have a hw addr (e.g. loopback). */ + g_debug("failed to get MAC address of %s: %s", + ifa->ifa_name, strerror(errno)); + } else{ + g_warning("failed to get MAC address of %s: %s", + ifa->ifa_name, strerror(errno)); + } + } else { +#ifdef CONFIG_SOLARIS + memcpy(buf, &ifr.ifr_addr.sa_data, ETHER_ADDR_LEN); +#else + memcpy(buf, &ifr.ifr_hwaddr.sa_data, ETHER_ADDR_LEN); +#endif + *obtained = true; + } + close(sock); + return 0; +} +#endif /* __FreeBSD__ */ + /* * Build information about guest interfaces */ @@ -2909,9 +2952,9 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp) GuestNetworkInterfaceStat *interface_stat = NULL; char addr4[INET_ADDRSTRLEN]; char addr6[INET6_ADDRSTRLEN]; - int sock; - struct ifreq ifr; - unsigned char *mac_addr; + unsigned char mac_addr[ETHER_ADDR_LEN]; + int ret; + bool obtained; void *p; g_debug("Processing %s interface", ifa->ifa_name); @@ -2926,45 +2969,18 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp) } if (!info->has_hardware_address) { - /* we haven't obtained HW address yet */ - sock = socket(PF_INET, SOCK_STREAM, 0); - if (sock == -1) { - error_setg_errno(errp, errno, "failed to create socket"); + ret = guest_get_hw_addr(ifa, mac_addr, &obtained, errp); + if (ret == -1) { goto error; } - - memset(&ifr, 0, sizeof(ifr)); - pstrcpy(ifr.ifr_name, IF_NAMESIZE, info->name); - if (ioctl(sock, SIOCGIFHWADDR, &ifr) == -1) { - /* - * We can't get the hw addr of this interface, but that's not a - * fatal error. Don't set info->hardware_address, but keep - * going. - */ - if (errno == EADDRNOTAVAIL) { - /* The interface doesn't have a hw addr (e.g. loopback). */ - g_debug("failed to get MAC address of %s: %s", - ifa->ifa_name, strerror(errno)); - } else{ - g_warning("failed to get MAC address of %s: %s", - ifa->ifa_name, strerror(errno)); - } - - } else { -#ifdef CONFIG_SOLARIS - mac_addr = (unsigned char *) &ifr.ifr_addr.sa_data; -#else - mac_addr = (unsigned char *) &ifr.ifr_hwaddr.sa_data; -#endif + if (obtained) { info->hardware_address = g_strdup_printf("%02x:%02x:%02x:%02x:%02x:%02x", (int) mac_addr[0], (int) mac_addr[1], (int) mac_addr[2], (int) mac_addr[3], (int) mac_addr[4], (int) mac_addr[5]); - info->has_hardware_address = true; } - close(sock); } if (ifa->ifa_addr && From patchwork Mon Oct 3 09:39:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 12997404 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 ABF01C433F5 for ; Mon, 3 Oct 2022 09:49:51 +0000 (UTC) Received: from localhost ([::1]:50858 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ofI58-0005cZ-Bw for qemu-devel@archiver.kernel.org; Mon, 03 Oct 2022 05:49:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60632) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofI0B-0002h3-5X for qemu-devel@nongnu.org; Mon, 03 Oct 2022 05:44:43 -0400 Received: from mail-vi1eur04on070c.outbound.protection.outlook.com ([2a01:111:f400:fe0e::70c]:38159 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 1ofHzx-00037U-SN for qemu-devel@nongnu.org; Mon, 03 Oct 2022 05:44:42 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=X5cGCNgF+n/jHnGjafpC82JCBKVjjwPSZlQqggpKyjTo0GsvUXL5jGMnGfPn+FYyBxQ31AnKVRh4zTk5QBSa3lqjWIBGlVLBWXlUG/lGCf0IKMqnIvEvM5hFzdBgijqV7X6RtGfwd/AJ+ATMibi/xVx6zBQn+rtCscJwifFLDMWguaORObh+0ASH4dO60JiS9eF49Uu6WJdrALIs3PVnY195MmnkHZL0UL4vH4w9kkisk5szmKoyH6TIisO4jOOUSajBFO3+hYFHZKNuQFKebpXi+eVmF1TEpmBhoiGQolKl8eu2NBO7Qk87SHCzCY1A8ozsaNUcPTjw32JrssgIRw== 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=leL6W1bPjBeZBabQgAlReZDQI4PoSLYkYymsdEyK/aI=; b=dwg297aEZWea/0F/VkCtcS5ZCYj9tE0U1NePZvZdpET+bRnFMG5nf7CUR2N8XSCDo3YXVCTzpgn2ryAuPb6z8f2ieIlDeZKsLCpBiv4Ov4CQETO4DSvYAfk/f43CTbjwWdSWqPAb4lY/AUwY6zX08VWNCjWKCuhjiLd9I/zzpNn382hmcTJK7JTHKgpaD80v2/Da8mWqn+6K9xkinr+PCs4cc9h02MV06unOH/DFmCsvcBUfGZlRBrl2tbdskn9QeysZF30d/84oiUgmqTAsMTvmWClJu7YHTx8xGOueCZ36jA/Awt6wNXLSlwknLvRqsgKOyKOLaC9XGPYq2XQcdQ== 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=leL6W1bPjBeZBabQgAlReZDQI4PoSLYkYymsdEyK/aI=; b=MhjmrNfDmUKP2zPqvBLV7Vf/a+aWaQ6NGNXJk1XEaO+oUbJMAT13xggEkXL7dKzqn80xVr3W4882APJpkmPH2m6GHDm3wib6Dsb5TixTIYVA/ppTlh/lBW49LCoAWeOVm9L687ED0w1Nb/UWAlH33Eo3QK9kQZ5KeyWEjjT0oJShYJR7v2zJk5ZjWY4S4hRGZqyVORNukpUGiXmsKhWZASisNVxyEpCFOu0AfgsEHYMF4ztZ2J7Nr9I43vAh92f0C8C0Y2iorklFPlp0NutRQHGZeJRRKZZQz1XglE+zx5A8Pnn1uEzQXSzjQMC6i35n6aU+mbH2ys9cYrv6VEey1g== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) by DB9PR08MB8460.eurprd08.prod.outlook.com (2603:10a6:10:3d4::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5676.23; Mon, 3 Oct 2022 09:39:25 +0000 Received: from AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::5174:25c7:6df8:741b]) by AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::5174:25c7:6df8:741b%8]) with mapi id 15.20.5676.028; Mon, 3 Oct 2022 09:39:25 +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 v3 7/7] qga: Add HW address getting for FreeBSD Date: Mon, 3 Oct 2022 11:39:11 +0200 Message-Id: <20221003093911.1844031-8-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221003093911.1844031-1-alexander.ivanov@virtuozzo.com> References: <20221003093911.1844031-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: FR3P281CA0096.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a1::8) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR08MB7095:EE_|DB9PR08MB8460:EE_ X-MS-Office365-Filtering-Correlation-Id: b6cf0ba5-1d30-46b0-c69e-08daa5232896 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: LNCm65Dsq5WyF5G2m+8ZGkP3XNLv4oXqgDQc0q2SBsAfvvoECl14BdpZ3XXoaXMADRF2zANAyGUERcvCO4ezzsuBnNFNn3yiHQjo8kEDWqRPI1GCemcFsmcl0ek/edgabqo6bdT+zUNM5qexsgUwmarletCqpGtkLeRQOp1xXEupdh+qB+A4C2JFQPi689jlKuo4RhMSa+2jU67pCyUH4i+2k01NcA4seA7H87NQ52d/c7DMNsQCMarJh1LaNiAJP5qVr+qi7V5wf9HadzMOmToE0bi46vI4Aw76K901+A1YxpQuPI2rrSxB+rrVyJdLLspTo9uFzcQis26+Hv0LlSXjX4SSIzEkRPJDF8pCruW2lokhSyU4n8OayH73UPh+P9CaBugm2m282IEfsJGiOhHi6lev2xpUIOk9+Kz5Az6jjuDGAKQ2IPQWGfrL87brsnyUtd8R2gmOq5/pXeNF6QqGM5s6y16qo8/T08ff2CSfP2t2yhhqtyfFBezkC4eo3D3sIdhhYMoNT1EN5ACZlZqVX5jxemfXXT3B7eWVT3wwV9loRh2B/nHEB1rT1WiIRlbj86DOVnjTi2/qYoa9UI0fgrwpY7ITWbliua+dVYeCgGXLBuAZgHAIHV5/lw2NcvnuUyCNLa4NKo09nlQ2IUzNC5cTk54nGCp33++GwutHgskIMZovd/95A3wz79MMJEncab0yp1lq9C//BfBawH0dGb7FYpafilPEoHitf+mdAq8U0cM6Ox2imq0Cn3fc X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR08MB7095.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(4636009)(39850400004)(366004)(376002)(136003)(346002)(396003)(451199015)(26005)(36756003)(66946007)(52116002)(6506007)(66556008)(66476007)(6512007)(41300700001)(8676002)(4326008)(6486002)(6666004)(6916009)(316002)(86362001)(38100700002)(38350700002)(2906002)(478600001)(5660300002)(8936002)(44832011)(1076003)(2616005)(186003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?cniPXTVZK1y46pYdT1pX9FNIqeO7?= =?utf-8?q?MExXMxjSbL5mGcRNoP1TnxvNOgwPXNN0z1olHtt9IdFtmwpSBtWY0NhLZblfaZoxr?= =?utf-8?q?SNw6DLQNiHu2QrppLIVkRgIyqPn5C2J2c/sNJ1njpL9gc6Fg/Ttl9+SlDUdXaPqie?= =?utf-8?q?KOPgVSC/R9md0toxbyY4QOhCBIwqaU/l8xTXTQp4msMqWe+b0OYq1nrqrph1jcTnf?= =?utf-8?q?TOV1idQmgJHf/t6EifUCoZsw/UzuaWIwO+nYUXRPTJnrkynTDYtl12remhsjE1YHK?= =?utf-8?q?8j+7J63psWIpE9V1MjtIS6gMgRwEYtFGYH/1j7VlpIALGgAmJK8yr34kdyh8NsHEJ?= =?utf-8?q?+01Jnuo6ykqr8vDwH5U1Zwampmt2TkKcKb12sf4sVv9XNdb8Kwxs5OqwJzxcTP/JE?= =?utf-8?q?fydr8mO4bz7stO2ROVxNyKh5fZD5eOGTg/L7skZPQxQ6XjGSyID/8b8NQ5lKWjX39?= =?utf-8?q?b8JRgWwR4cCkjr4xN95LdaMkulHvxZibHqZ4dMCbjhM/Kj5HftHX1NJVk7KHNncwN?= =?utf-8?q?u9u1QdDEHK4TV98PmvWMRCkomWkF8z6oguqAiT5WQwJ0I81t6h0QQJmppiw+vzd1T?= =?utf-8?q?/YMq+RbvxUNjknXh4OO3cAGthuXvrsJNRgoEa68drDRnQoVP+Kwt2t0SXpz9O42rp?= =?utf-8?q?noQBxY0ANKYsMjlH6lnMGnw7gZQrtS8O9MYzVldyLWF3GDWhLxOBsqIglSpWQf0xc?= =?utf-8?q?iUepLogNUreS3BV1Ma4Cv3XxR8bCuZBldLGNvXolr+UxLvNAAfzbO05UuliOV0Enf?= =?utf-8?q?7vSZT8fihkLKhAcgTT+yImemW+bnHd3uK/p0+ScRPktJ9Vb1TuLA7iXU2x1ccDfiR?= =?utf-8?q?Cqp5eN0ZEIaBEIyCjYdAX+jja/KmQxcV62UMIe75dc0iYsJbfbDzjj0uM1VpMhkr6?= =?utf-8?q?aAIvrBLbEDMPHPSndhOJhjS1U38XIMoYswO8+hWlrt0Lx9x1OQ0sp+wuNvkyGj3P5?= =?utf-8?q?sILYWZaciBejjgQvC4EupphVhH7vm6avAO4wnsWsyHAqwretGbDnOFDxm4U6mtBXg?= =?utf-8?q?aAsVx8pTvHin53d0n4J+M+l6wPYDLE2/UYfg0u0w14hhxhDqT026PT/vs0AOStjXc?= =?utf-8?q?EcnYY8v61WNPnUeLufcVWJtlKDq80/Cfc499GfDjaH5G44CSZ8bcOpkSlnRLYckDk?= =?utf-8?q?4eyVDWaO2WdI52QXlCveFprYnQmFkGJHZRCV6TCw+IEzaRHbsnaoQ/3OYhaV6y+Ln?= =?utf-8?q?xZkFyxjd/Dks+PxaKJCBoYu2jNzq8lHNPtT3GyH0TKBPyReSaet+w7AbsLuqnP2oF?= =?utf-8?q?qn3Ptj+8XUCmsfvRBpMyQYjpwwr1cVTWxLWcK11bcNUcX5ciPXrwtZksjjEEb5rnS?= =?utf-8?q?jfPVvDEHMqw5Fmr8S4ZEZw1PaPG7lAwsfJHixPFPgfvVq0IZo6hsBzw0We/u2bgVP?= =?utf-8?q?FAqTGIeGh1Jx4Xxl/V47m/Gx8VslV97F2T7tFgrWY+x1RVy4y9KOvOr97Wi12BWne?= =?utf-8?q?3JOFLOHskZtfsv03kciZdkzalN4mDtACFegoKmmnNkT00+DGUhaCQad32QzmzWack?= =?utf-8?q?keEAF+Cdtb9TLSxUs98072SLA1oA0jSNRA=3D=3D?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: b6cf0ba5-1d30-46b0-c69e-08daa5232896 X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Oct 2022 09:39:25.1485 (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: XpBOZP/3pmEdDJzngYCbkiXUmROIuVfOcphJ8aPBzElQkrZywT5nOB/2j5YkMyCQ2KJVScN1vHuaEMRWy6wkV8i/DKI5q4gDIJj2SHZta2s= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR08MB8460 Received-SPF: pass client-ip=2a01:111:f400:fe0e::70c; 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" Replace a dumb function in commands-bsd.c by the code of HW address getting. Reviewed-by: Marc-André Lureau Signed-off-by: Alexander Ivanov Reviewed-by: Konstantin Kostiuk --- qga/commands-bsd.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/qga/commands-bsd.c b/qga/commands-bsd.c index 40f7ec7600..5f423a4710 100644 --- a/qga/commands-bsd.c +++ b/qga/commands-bsd.c @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include #if defined(CONFIG_FSFREEZE) || defined(CONFIG_FSTRIM) @@ -179,7 +181,19 @@ GuestCpuStatsList *qmp_guest_get_cpustats(Error **errp) int guest_get_hw_addr(struct ifaddrs *ifa, unsigned char *buf, bool *obtained, Error **errp) { + struct sockaddr_dl *sdp; + *obtained = false; + if (ifa->ifa_addr->sa_family != AF_LINK) { + /* We can get HW address only for AF_LINK family. */ + g_debug("failed to get MAC address of %s", ifa->ifa_name); + return 0; + } + + sdp = (struct sockaddr_dl *)ifa->ifa_addr; + memcpy(buf, sdp->sdl_data + sdp->sdl_nlen, ETHER_ADDR_LEN); + *obtained = true; + return 0; } #endif /* HAVE_GETIFADDRS */