From patchwork Thu Oct 13 09:23:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 13005840 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 27378C433FE for ; Thu, 13 Oct 2022 10:11:54 +0000 (UTC) Received: from localhost ([::1]:60892 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oivBx-0003Fa-7x for qemu-devel@archiver.kernel.org; Thu, 13 Oct 2022 06:11:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56586) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oiuRL-0001zk-Bz for qemu-devel@nongnu.org; Thu, 13 Oct 2022 05:23:44 -0400 Received: from mail-eopbgr140123.outbound.protection.outlook.com ([40.107.14.123]:28929 helo=EUR01-VE1-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 1oiuRI-0004g6-Oy for qemu-devel@nongnu.org; Thu, 13 Oct 2022 05:23:42 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YbHKGp5kmXNjdnmi5M4/pSeWEKpgukQjnBp6I8eB5F1fs/CDp7bnIZc58kKJWrKsVUHFUBGMsb+/HZh7XD3xgmbF0hmbUKzcenNIO/a5zXe0uLx8YM2DOEWBNqc8lbAM/AXbY4wLfjaGffX21amJRgWyWHZjQqfYHYtpgn6dc5D3eFumcFpceVvBSn2SicZnYgkwFdvpe1CLgHp99WpDXAw117fFbjLCTh+wSIOuvDorszbgJ5+HzlB7DRoX5jfKf79QgqHbxQs+F9nmYEgk8LZ+9xdGlBKFNVx81uH9UhtBtmjX0rGPN3Q6tkc1iaF7NqCs+XKgV5x6/klUSIHl3w== 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=bV9wrn2ZNFyUxTphZO2ecIz35cNR6OWMtpYLx3aL51c=; b=oM1FPvy1uhRL0eetadC1jmXnD5y5eEDLJ8i/3nvPXtSR/ttHk9Muwoj8doYQ7zf8EBwyUDLWJ+WiCsDGCxhhlaE7dqErVvx9lRlJV0vOqo6lxp7u6AYRGsGnrs8MJMGj/BBttPomQfflbE42n5Q0Bs6uh5dKkWzHAHg+FLOgsZGYLNJ7SRORLiwBnNKj8fmVJmRZmMct7uWluqw/4dT3teHer++Nhnyvoni1XIwSLFYug6UzNEniwAZQusRW8ZAOd2BV0Yn6zyWiplgw8aKauk4IMsydvcBwxPfoF0wd8iNzu0FMnth2FW0USiFXZjF1U0YtFrakY8XCWS0oZVO5NA== 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=bV9wrn2ZNFyUxTphZO2ecIz35cNR6OWMtpYLx3aL51c=; b=0JvP/Ar/5YFj/QIj6gY8+6YQn2+uPl1d4IPi2sTrXtUl+pY2fOVS9dLRO+2fTelx5KJuJKatwU/YSD9la9dI7arvRFeCorYZOVuMwkTAIzjYqFZdfkZJo/NXMKBimpD+s14H9tgjzAOmbAyklbzGNR+hcwY2qx84NeSxpzRYPRx+00j3QV0TkCX7KNp3WJmb0KMDbdzSTeOE6qFksS0j6NWIUz+v0vRMIXnAlwVvxPVRtBcqQiTx37FBVVcgjlbUpClFeNI9P0zwr1FT9b4p4j8ELlRa5gtIo7ThSbvDiTeZ6/5HiY15vK129QRJs3/G2YYA45zvrxNJG/hoCnpjBQ== 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 AM8PR08MB6466.eurprd08.prod.outlook.com (2603:10a6:20b:363::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5709.21; Thu, 13 Oct 2022 09:23:35 +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.040; Thu, 13 Oct 2022 09:23:35 +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 v4 1/7] qga: Add initial FreeBSD support Date: Thu, 13 Oct 2022 11:23:20 +0200 Message-Id: <20221013092326.2194646-2-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221013092326.2194646-1-alexander.ivanov@virtuozzo.com> References: <20221013092326.2194646-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: FR0P281CA0069.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:49::22) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR08MB7095:EE_|AM8PR08MB6466:EE_ X-MS-Office365-Filtering-Correlation-Id: 13baa343-8ad9-4aa9-4584-08daacfc9a65 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: A1SK7ClPiew7qosc0yt7sy2BiD4CHVhRdbXWSjaDsbPe0iUyUNLhISja51k97sMLLcV7bPqEuSRr4T9kfakUbI4bUF/GS79vw3orh8R8yxy/266VZYIb4RZHUxvsRRFf73dsFf6MEGgPAndzPSpK4y1HEGqIKZyha4UXEQJN/gszH9FsPqdWr/MUaRajCElqfgCWM9unWvy+eBS0lN9lNE+iNt5XB0Yubv+Rv5HqezbC8bWKdn1mSZJtMLRcZsfCnOxhzw+ChxkBKHZRyhDcoByOPD+oCCzfuW022lqRRGggcVsuzClwB8fKNW2euk6IikXNVrL4tcbh5m/SmeG9NF2pJ3tdLpoW7RMZtzSkT4SDLR2VpqPvsXokY8E8vHw4xCNrzmo5XhvgWtp69pCFyd0BMtBbWtGN+ZHtfsZ5+/sqy/QHDaxCx+Ur0OpyE+ZBbV75S02PyLO7Tr2k9BvTTO8Nbw3q79gtyTuDg7O+gNlCtBKR6bwSZvJc2NxyJJJLE+uWzY+jRh7Gd0At7rnc1gvRh8gzd1fNYW2PbOaWY7CDljZsuLIaL+e2Oi76AldRDO0dccmee/yIPFNeY4fpTqYUYL8de0k1E3MArshvc+8csz9WWd8Ds56hMctB1Wbxd8c9zZzoAOyKEVLzYvnQ0JaChM0EsHxSGB3QOI1Nz6k/o8ntbacw0hQqHjp0NUPL0CQdFT1fVpgryzBfecZZ1bgk70ofAEQxylTnO2eB4pi7bUEQOYkrUZF64Ntb/cqbAOHypf4hi/+AALL0YRsEDg== 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)(376002)(346002)(136003)(39850400004)(396003)(451199015)(36756003)(2906002)(44832011)(4326008)(6512007)(5660300002)(41300700001)(8676002)(66556008)(316002)(86362001)(6916009)(66946007)(66476007)(8936002)(38100700002)(478600001)(6486002)(6666004)(38350700002)(83380400001)(26005)(6506007)(52116002)(2616005)(186003)(1076003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?4W0Qlfes6tRcTCv3av3TJPjmAnqJ?= =?utf-8?q?U7k5gJIu6trUug7TXzmSUVU/O60IAHauCYhQmnBKAH85PXqc6hVg/CPIMmBPX2Tk1?= =?utf-8?q?jxNl4m54n9Ii2MPuOjgwTadTuiTIiFmwps0dKhoOpcDQbSnfZdO2q/iRQAwHCluh0?= =?utf-8?q?41vq5FE0ag0R+nYDj8x5e0thdEZXtyWwgsMPHQ/i9B5t16kE+qFJO3DoHEJ1Up+sO?= =?utf-8?q?5hFRuxm8K9yx+2nWjpunB7aaz9in0lCKDPlIanlyNsPWX2FgQgJAO+b5h2UrHaaHd?= =?utf-8?q?LNmd5qSjrlP5n6tfPMX/9qewlMroLtX15dYCnTtXRsbRvgDOckYtI/Vc53pd8WKrX?= =?utf-8?q?UdLGN86/YKqvHAYQAVOB1wldh5gaEwt+nxJvhWRTwTGFlxAJ4IuQVFwYPpBYUyuYT?= =?utf-8?q?RRj99pr7ScM7dkzx8uQJj7LuQTSR9y2ZFvhZhQOan5QVgT9mf6ck130QwGgcJN0UZ?= =?utf-8?q?//4EiimRXi5g1c0mFzbcNSlc0GYapoRFNj+DlnJUTTr4gDlTKyuLRVT9RKn42Mh7c?= =?utf-8?q?ulvk6x04CmL5DBJ2qUp+tNyrgZIBqjCH7eu0wglZ6cLg9mmWCBC6qwPFdsZ1AeYlb?= =?utf-8?q?M2re6V2LNvg2sdSVcR4fdnKaMVHP61JVKQ9liFtQ8pCGjB9463efuK+1sFqvLoxDH?= =?utf-8?q?GRAnKJwNBDN5vXNvJPLWjx5Xf1xHGcgpAUUgvCN5ulJpIQRjT+f6HgstOC2BQhxpa?= =?utf-8?q?LgAMsefDcsBi/1jiBXQm9CQGAeIX3nQ37oz9FXlrP7hge9ZzF5z/T09c58vCJfH5f?= =?utf-8?q?VnPnHhbOw8mEDeaFwO8rjjlHBcCTrSidMPX/vvTNkXy8WdsVSknHbMXWjVX77BwMb?= =?utf-8?q?0IYizuFVJiWmQFvd9LzVvt7cP+JhqsbwvoA5q/IsIyQHkSpDcbMwRxIqERzDIYQx1?= =?utf-8?q?glHmpBhHjblAX5BNXrX+iFodhK2UFFUinbbHQLuQ4GUHGiUKrq0NVlyBMgIbhud5X?= =?utf-8?q?QaewttHKGwK5W2XvXU69kuIkeChJvJRll6mU6oQt2tGrQMf0qIWYO7rIV8NQBd7YA?= =?utf-8?q?y6GkmpIHWsknapXgHyKczniOs+Wl4QWRhllDHD97zWYzK5WDgyxS6j21UFFD6BulW?= =?utf-8?q?Tga5lkZ9EjDBmoKsK++ZedAULzEpx1AAobJvTFfT7EXgwrbXvCnACdIN0G/k4PVCq?= =?utf-8?q?r1NIp+bnPuxGYVAWGbNSXOn0328C+uxS40gkt95lK/fzMidVEhbS6QOIwAVO8aPzv?= =?utf-8?q?vzKFrDHeYROjF13Ybe9f8uiqHiIPq8ajaFNanvu9exhsgW6mLuPc0nluHr4aiHeli?= =?utf-8?q?v2CpP4Ig8c3C03pGr3NGwfd9oVXBf2jyTtJDfnxauVUSPw6b1tQ0dtsRDHDS3+Dq6?= =?utf-8?q?hwXnTow5pgs6KgoX/Bx+ExtLetwRiJmqKAfWxoiwqvpBPOqYy5xfRzZq1GfDvYATM?= =?utf-8?q?UqeQRogzcvT/wQwUqfPlDdipKspCKd819VHU9sZLDBjP/b7d28LgNS3KSfamFI2Ww?= =?utf-8?q?9QmqnAdvxs+BdL0JV8kfanwBsnH4rVwX/in62GZ6ES4ZiNXqZnAsuXHoWDkobsQeU?= =?utf-8?q?OAUYi76ablI+gJxtWR9kt/fXO6xmPvmpKy4YHxDVr8xPV0eKXJMBIBc=3D?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 13baa343-8ad9-4aa9-4584-08daacfc9a65 X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2022 09:23:35.1861 (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: FRA1xlHAlD9/B0NRcPUfdQ+W7DmRaUgjBki/x2q+u/8n74do2HkDfratMte7gPcIhiLpIr8eI4H0ZZ20HLVppaJySxOHG7eGnSURpmpZkjs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR08MB6466 Received-SPF: pass client-ip=40.107.14.123; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR01-VE1-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. Reviewed-by: Konstantin Kostiuk Acked-by: Marc-André Lureau Signed-off-by: Alexander Ivanov --- 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 b686dfef75..71fe72ea06 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 Thu Oct 13 09:23:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 13005837 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 7C192C4332F for ; Thu, 13 Oct 2022 10:03:44 +0000 (UTC) Received: from localhost ([::1]:52956 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oiv42-0004VA-8E for qemu-devel@archiver.kernel.org; Thu, 13 Oct 2022 06:03:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34348) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oiuRO-000270-1I for qemu-devel@nongnu.org; Thu, 13 Oct 2022 05:23:46 -0400 Received: from mail-eopbgr140123.outbound.protection.outlook.com ([40.107.14.123]:28929 helo=EUR01-VE1-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 1oiuRL-0004g6-5i for qemu-devel@nongnu.org; Thu, 13 Oct 2022 05:23:45 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Vyv132ViO3qbhG//xK6vKxKPgFNxdaryWXZdUQEINBUP9vITlJQEhVeruOxBAZuw63s9ze2YBdKeMOMRByBZO4Ie20W7dz/oytiWdmRqe0QLCRracRdzsvAFz10geM7zCCZUj4iO8ORvxge4uh+UIFdZZLlDvUwzfxz1jCrvLg6O5yGKAIfqtppGAZc/R4dPh8+QuIYLp3pQqHtiTMh7nKcnCKHq6Ge3LVEnZK64rPa/IG5hzkpK2wGcmJG+iVBqORouy4AUskUQepJ6P3o9EuzNNTr//0oe8eGWpFli4YTeH8+uJ6ncsMmqU/c1E5cl8/d3hJs6uFfJObp9a8Hucg== 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=u15BCkbSjlZVJHbXgI4URmaqBqsXo8JWEDlk0o/JTJc=; b=GGa7vNC2XHQdcu9QZ/ZnOELmjgTyV8QcKTdMfcxfFtBQVe6NM0knmqgVwHUijr87KRSCvpyxQZFHYe8goGuy+bIAOFNyDNA/lEx0I4I2I9OFAQPyt5lfrMtCdrbDpU5HQkcrezMnt4xfCCcXrKfesUXVjyls7TxiO/9MRYgrorTDZYq7TcM9VzsXQL8+77Ny9GpqWiZXTQ5OcIsNZUTRgvNVQkPRHX9VTyC/fu0bPn1kTiY/HOU5+tS6XH1qfpKEeHsI8cjjbgPkM1Ezei6CdgM5bhsV0uO9oSqbefDEmjzZiJiqwpLwuv7r3RhTtSI49JpZRv1QQrDdoJMI67jxFA== 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=u15BCkbSjlZVJHbXgI4URmaqBqsXo8JWEDlk0o/JTJc=; b=CTqKb1N13QSLEVUHQGk3BmQpA/NLX2gBbSvPWq9JH8bfoir9qbacANgdVyiL+fJHuqKRhDHU/FiYY3h8DTBofcgRwDq9N6lloSpfPlOBWvUcYO2s61qBNJARv9upEnrMJfCsDC2N3jr8nuXoIpJ6xfOcvN+wAK3WkDQDmquOaUs2xHinvVdmfqE8s49MfmUB4Wx0syBzMkTZkndv/8UP+1Ftg9QVrzKESHZtyNw4b+jmsATrrbaVmf1Ip8Cyb8VA3kcmsACsQ7ICBK5ERawqZjEZbcOYYHQL5i+IhXhB/0PwszngwT2pOpJouW61tQm+x1DEMYn1uZNkYXxSV0mUsA== 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 AM8PR08MB6466.eurprd08.prod.outlook.com (2603:10a6:20b:363::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5709.21; Thu, 13 Oct 2022 09:23:36 +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.040; Thu, 13 Oct 2022 09:23:36 +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 v4 2/7] qga: Move Linux-specific FS freeze/thaw code to a separate file Date: Thu, 13 Oct 2022 11:23:21 +0200 Message-Id: <20221013092326.2194646-3-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221013092326.2194646-1-alexander.ivanov@virtuozzo.com> References: <20221013092326.2194646-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: FR0P281CA0069.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:49::22) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR08MB7095:EE_|AM8PR08MB6466:EE_ X-MS-Office365-Filtering-Correlation-Id: f8d7b00b-39eb-47bf-0281-08daacfc9b4a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Gs3U4cr4oBS9jIfXtyMl/Yq1g0hAP9C4r3bHr7mGxltqNWYO8HMWWPMXzEghz8EHkn0KjV/IDCJdgcxi+XgVMml4lUVCk1ImaugQcUPF/2tt9HNI5sgKUFKkbpgR1uwex/6d3puVLZfNObIbcu+JI+SxQqdejQMdz5yDli/yBxyP5brzEHt2Qg7R/41T2Nt1jN3ZCX5mKcSK5kkfpIgZke4VQaQnDRbfLO1buuC754jzUn1GhHzEiT18CTilYgI4TrAFZ8eCjqflNRDiDCiKyjkyRqKU+fdQqQSIShlFKWQ+wUOZbGOlm831hP4JDR7esZOJmvuifLjovtSLeG9gmq8dxAtD1JAneOsXSmzZW6UC+5FoS1LJQO3DZpNh+sQaIV0Mrzx7mow03xupYAKOKLsOR/r/TKfSV7+BwWoPKsi1UhpRVsZge/QoLBq6A3MYUy2LAtrDBmz1qYSpSCwHc+UufSnJehAjf6GlAHKZkTY0/hKN9Nudg7GwcpOM5TqjmfDFaOr8/8gMjS3wUK4SWqTBx96tgnnaa1Z6cU0TTsEI0T2krXRlp0fxa/IfCSJ3v/WngE49qRMIpbELnZGnkqYj7UJ2bF/cgTz2nnOQL9ZnjfeW2oT3J+zp6GftQ1z4j3IXZ/mnefBnUDe8wAtGpmekJcbM6IqapG//My48y1ulOgEQW9cYGVwxUMtE+xe3izD1jl59IcWQP58FcfKDYl2gzpIdfoVL2DUXn8kuzRDvOEuhnD6eoM3b+98c3Qs/8/rRx2POoi4Obc1kkWk4tQ== 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)(376002)(346002)(136003)(39850400004)(396003)(451199015)(36756003)(2906002)(44832011)(4326008)(30864003)(6512007)(5660300002)(41300700001)(8676002)(66556008)(316002)(86362001)(6916009)(66946007)(66476007)(8936002)(38100700002)(478600001)(6486002)(6666004)(38350700002)(83380400001)(26005)(6506007)(52116002)(2616005)(186003)(1076003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?kjzLeCrmZcA17xDk2VYYeyWhbezG?= =?utf-8?q?DLIkeraY2AjlwTb/Et7iMqO1aYfjtBLcUhjJJTDPz4+/e3WvZEd9gVaIrb7owLJ6Y?= =?utf-8?q?6R1xGnk2p965bj7gAX8f5TfGH7hRXJoSHq1VDUiGNAIeAxmMK4UFHh6NYryWp49bK?= =?utf-8?q?Ha5NieA2ROGotVI4v7ON4tKuapLqfLUP2kiO4lh+ZmcZ+mIII+XdRny3LDrcIdi6k?= =?utf-8?q?378+ZgNy8icoGvR1Dp58vrNJPs8jfFYw0i/oj1OH2LXLRGQATxwMNRFWuT4+LxKY4?= =?utf-8?q?asIVMHg1DH5q47ZOsEMEiDlIFFbYObF6GxWY+04431UHRS5TjazkbgcMT75G6lEtN?= =?utf-8?q?gRggVb1ZvIS1WsZi4GYtdfqHNqAI+txd1JFJwrByx0NucX9rqrjmPAGfC5DRekmge?= =?utf-8?q?M5hH1vK2NJf1hz6NzI7A1HY3mVvxC7tygiszBQUlpH2FEvUoVZBtfvubA/ksvzVNr?= =?utf-8?q?FQecrXRpq7fK7UKPR3uNFudpWfwvY6BvhdUOpAzJ4RZNNhL7fCS7+zgGkEzFiUaeR?= =?utf-8?q?9YATqtgA33sGL+5p5mFxxUmPluCHepDqjC330N8kLlFNSpLDjg8VcCDdNZoQl9Mcy?= =?utf-8?q?GWAbeQOqMlhcxtQD3vMAAcd96p1OLScquUEjgpNvVdmDCb2ldLg5aKm+rSqnh3pVq?= =?utf-8?q?A/TOLdFh6IuE68nFixQMwmKqY350MaOT7t8IXb99C1xlcOAkLxmYAFj99FUSoYflJ?= =?utf-8?q?oyDo1T9SnqhnBlbaSX+vRbkVr5Qx45nmF9vjcBAE6D/YrWkhHh2xvI7BF4gkdvxvb?= =?utf-8?q?IO5KW/baqp4cX+xOa0lSOI47TeX5/EPh7Jf24WsQDBqff/9BJni4rvzoAfPYCpi/q?= =?utf-8?q?b8wsppZkUJwdNX1KaEaJByr8kijl6AfH7seI7FnA+Pl4z/PxoYAbfsAWH33LNpNAT?= =?utf-8?q?QRdVcJKDJVsA2hn2ZxM9AotPaD/mkS8IpvYarpGtqvHBrQU7yoNZducDFbd5V62yC?= =?utf-8?q?pkt4ESj6TiSIpXGnRPAc+lyOYq3eWK2P7elFU6NMbm1SnTZMoRLiNy8N3hkeUTgQx?= =?utf-8?q?rfkKS/yfUS7eUV14zBHiR7cI5xse7n8zBKuNdLasY3d8K1tZ9T+0SGsqJiKnGVOKr?= =?utf-8?q?QY7Qdq2YD2BBzNjOvW7u+D2mTEjGV4kzSmIwXSQ46Ug3eWqF6AdljrlhtmA8g7koE?= =?utf-8?q?CMCCrsBtSG7ad33F3NW2MRAmcNIG6+HtRbnswQQ75OlRdyVxl5y9BnRl5lvHZFWmQ?= =?utf-8?q?LEN64+5b7X77B9P2Z2iAH8sX8NXCOMt6FBL2sIKtRIi17bLc0VLmgItV7yjOBiEdO?= =?utf-8?q?vUfdVmRJfs2Q8rE+C/niUgXrZiXy9Q4zBdz7MzGs5SZQg8bi/TR1cmycR46r+3Okr?= =?utf-8?q?fpk4RMMqY8zeGbISmHSYsGuMivj2H9ncLcz8qB+XpK5Mi3+dC9X/QaMkNcfK8Me+C?= =?utf-8?q?JqstF8+RYQjHFYQqXZRBlN+FKbsVjBd01cF3omcXoR/dnW2fguf9aFRZNK9QpSMne?= =?utf-8?q?f/2b9ZmgzcGT1nm1VqhdqUONMAiAdZz8oO+/BJCdpwHufP6gZDPOC/fG95HZbyDUR?= =?utf-8?q?BRXC9hUB1B7FdQjKcU/UdGtcjlfcQ1qj42eE2kqcXPo35X3L+S7nvrg=3D?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: f8d7b00b-39eb-47bf-0281-08daacfc9b4a X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2022 09:23:36.5900 (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: YklAPgVw67EL7J6Q7M2luHNHVuri1mxUG4XORivCr9d+4yUZ9x9t89NzpS61Iszv53wI3RREe9KmkHIVuM4hiC9ZJvSwu1TXfue2tcMd5lE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR08MB6466 Received-SPF: pass client-ip=40.107.14.123; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR01-VE1-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: Konstantin Kostiuk Reviewed-by: Marc-André Lureau Signed-off-by: Alexander Ivanov --- 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 a0ffd6d268..932b4e7ca8 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 Thu Oct 13 09:23:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 13005808 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 08A34C4332F for ; Thu, 13 Oct 2022 09:41:39 +0000 (UTC) Received: from localhost ([::1]:45908 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oiuif-0006Ga-PJ for qemu-devel@archiver.kernel.org; Thu, 13 Oct 2022 05:41:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33450) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oiuRc-0002M3-VX for qemu-devel@nongnu.org; Thu, 13 Oct 2022 05:24:02 -0400 Received: from mail-am6eur05on2109.outbound.protection.outlook.com ([40.107.22.109]:28065 helo=EUR05-AM6-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 1oiuRM-0004gX-OC for qemu-devel@nongnu.org; Thu, 13 Oct 2022 05:24:00 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WVUelJG57jRrSrwavXm8qaoQsSfVNgZivebU/56rx5vBQ5l7jp9HZHl9Sq7QLuq9qLNkw5a1nuUpuw0bexDv6s3zz9sRPD6E0OuO7YbdtEQygXZcUBIKonHKWR/vLlE+Afcij94onTDtwcDSE9RBykAyQ308lDYX3K3OFjgwWb2+MLsDo3q31eBaafEtdfbAclNYNDnJT3MdiXVUAcYEIGHxaBvpTvnfOQjHW3qGAGN74PoQyV5PErYHw6AHGf/m3OyJd2CxfIb7BUMhSE7C+BkGN67cfrEpips/nUNwbuplt36lQImeVpKZIlH3V7VpJyNXwJHqguHI+HNFmcLClQ== 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=DK7nD0sgWCX9/ZdHU/h1wq1s4gT+ZWz1xBxB/M+VB8Y=; b=bhu8m+j/qGwZ1jTyRyUWLbgrkCfnhG5JUxKbJitN6EUt3JOA4bKtsopLs8XqaU57DSZ5tNZ7ATslGYQrRNEBLOnoeNYKl6yBLZ/m2QkujjxY6eRmuWjRfNF6Yj94C7E5sM72IgncjUSZu58FPbA1vuHOqJWUhO3Oi8a499piKt0MDYIQsf4XKDHGzzeXgRdOBG6SekbIqyDYEI/m9VwpjE4wJaLQPnK82JXMZtP3BIs3eA5MhcQ/BBfUf0kWrqG9lrGH7CiZIuXBlWYPRd13tEgk/pI+TlzOcM4V40eKW8GjCUT7jHriEGDO+LzW2s1tlRYfgvVcCohYsZTW/WZM+A== 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=DK7nD0sgWCX9/ZdHU/h1wq1s4gT+ZWz1xBxB/M+VB8Y=; b=oXD7MCT4A2m+dfunaAQd+69/hrn4esDHXwpra2VediBQhjybq9lOGJidTPcDBWyDGVZJs5qlTuBnGE0qSWpf6k3PhlSVdJdiaIPm090/Z5gBPtLIljqGLvOxKwm6xlv6kBTw3joz/AOMKtOMPZzGZEo5C6G789+NWBRjtOZxgrGTnuTCJ3WK1RwHu9x6keapuI0mRxNhwT3ZwXS2Rrw5qxQSS+NW43nAksPgAfo5KJ/U/GYudTvt06hYSJHeY98B8g3XKB4uRR0e825tGsHT3poUw576bYRujMturlybspELQSdKTNjUkMclxNjeVDi55rle6j9nbAXGutWYiBsFgA== 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 AM8PR08MB6466.eurprd08.prod.outlook.com (2603:10a6:20b:363::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5709.21; Thu, 13 Oct 2022 09:23:37 +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.040; Thu, 13 Oct 2022 09:23:37 +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 v4 3/7] qga: Add UFS freeze/thaw support for FreeBSD Date: Thu, 13 Oct 2022 11:23:22 +0200 Message-Id: <20221013092326.2194646-4-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221013092326.2194646-1-alexander.ivanov@virtuozzo.com> References: <20221013092326.2194646-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: FR0P281CA0069.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:49::22) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR08MB7095:EE_|AM8PR08MB6466:EE_ X-MS-Office365-Filtering-Correlation-Id: 803d3e2f-ba73-4342-c740-08daacfc9bc3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9MvsZcDZBc0277G9qUL8clY9uDDNDDOmtVZDzClMO/1OrtM2Mae53JMhr/id8lUD1l3Lubchho182QMGvHNa8as8BHCF8MemJ6hnVNXx2ZuR3DQ5Brciw5xgqVlsJyj10tUmtGrl3xsV5rNVMQ2PJHAQUXnTuVZ7qMwRcgp+qNBJ9Q5W8yCU4qhGZcjdIvmJpm3/IiRLbpOqIfB0f0pdcTdQe5MxWc7Q85ULwX5/jB6NAYPKBfmkIvQ4OvMiwbmv70NoJ1VySOGCz4oF14aZYwuJcn+E+mewTjF2hxfKZQWgp+kZogTBNRc7HI0ArUrRnF2zquv4q60LaMwFGyi38ITvWkWoSUpIK8OWv88pSOb/5bJKivAFi/kBRHFx9CN4tk6rQVR3UoN1A4vpdVX6PBfz7jnxRUtBD2bTxFVTGzKY0RQYW7xLa5rTCSTeo97vEXrurRrszu7iywJN2QoFTmzK2aL2cEUZdKGOgrCSRbWqZolK71xpEfxRzf98womzAr5cUpEb1Ar54L3sNQxPtoXmsCiPReGuLTC5fHDVJ3qCzsqBvZ08UR/YbkJWYUc+8u+fPT6FBmnwNMtD1Pk6eiXpK8ALHCx3zz8SQtzdGxiaI/OD+pNPizEsKvys5+sq5+6hbUHI03DdyBTZ/Cb18u6LP871Zy/3WDho+3/iC+zTCDI6BYK6QMKGcYqmUgO2SI2IzBreLfW8t+M09jHxK5kiJUZYo2nN5lJWpbulT9LovZUddSw5lhgdkuIPoo589wIfZu1XlLsRPHk8FbtYsQ== 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)(376002)(346002)(136003)(39850400004)(396003)(451199015)(36756003)(2906002)(44832011)(4326008)(30864003)(6512007)(5660300002)(41300700001)(8676002)(66556008)(316002)(86362001)(6916009)(66946007)(66476007)(8936002)(38100700002)(478600001)(6486002)(6666004)(38350700002)(83380400001)(26005)(6506007)(52116002)(2616005)(186003)(1076003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?XLCGs1/DpGau/uuzEkLInbCGAaDt?= =?utf-8?q?KmIw5J6R/eLkp3ZmHVrQvkB34aC1ybfKQl8SJlwRdt4WoYS7BfO2ebXCZqPyG+8n7?= =?utf-8?q?vWQB/O1Wnv+/F3vY9f8QvnOqKphxWXms6ZLGVNeS6ecHAJRA8dGaW5XGPPQgQQjUc?= =?utf-8?q?sl3i/QTPPVMwDit9yA/KG4gIW8eLW4cl5gl0Tqb4VLdcf8VCQ5jZnF+i8eKs3Nezu?= =?utf-8?q?2yNA2NfkBR9gI13EpN8K3MMBrfbpoOTsa+avnMacYnji4F3nq2Z6rc+AUSf2I4ddI?= =?utf-8?q?wFxox/w/IkYXS9nbY+QnECXmTSAUqkrcaCNF1ekfVRsBeiA1OVeERIxCcGDHxhon2?= =?utf-8?q?3pm8/04udBHI/Q+985GGk089ns9UmB9B1ELUBUw87BcDOdEAsg2uQi6C9LetvcgWj?= =?utf-8?q?QqyzaBw4FBfX4kfvmtuTqgLh/fndOYApSBhI9XjSwrOXw3qLJuxOL9EX7VKhFZ9Uf?= =?utf-8?q?i5Y9NH0cxtVbSFj88sbaiMWA2HO5XnY4YtGeHsurfcmGZJT6LIifEUOHVPLsBahdN?= =?utf-8?q?pDi/0CBMv4oxtaNjx9pYzI8CJcS1NSLvLM37N2FPh3WGTgWDGLtusGuKtgUIvxN9h?= =?utf-8?q?N47pLrqca39WxSJm4m0GYDlyqZcFWiKuiXkzf4TP5dofVAJXh072cyC90wUgfFjth?= =?utf-8?q?yWLluVX6w+s7cTbgPeYqqKjRLaocgsLfRNWe9zsdoxKat+IKzu09OIk/fbF4nx6Ek?= =?utf-8?q?M+DsvSrXjvSKxvuAuPY6i3Ew/OJYPB+t5Pdds5zQwoEII4i4frHQVvwvUzkMlSl0F?= =?utf-8?q?K4kfCxMhbj5bA3+8Ue4wRfrGdWT284YOzQ/+ekJH/8rZrPYJLBOII7M9eop4xP/65?= =?utf-8?q?g3/YcBHhfMosQ+suc2aReMtT70NkcoxyuEmQnZSBoRfk9/KWerCVFThr7kL7prsj3?= =?utf-8?q?H9TQu7QfOmr9rpa/a4rSn42BhJW759K0oAD+X4d/82lADOB7PzRGaT40OhrNo8H6U?= =?utf-8?q?iw6XYhUsS0c5Q4tvIXyGoYITQ1L5+94b89FiVzvn3UIPBfBnFJIJxTatc0LYt1yDz?= =?utf-8?q?e9df8O+BVq74I048+RmTx/DzXcbwzEJCXJfLxUK2nGTLnud1GTIH9wU+LEEKDojqu?= =?utf-8?q?K9p8S3ogTsHNsGLHuDc+3cMe6DngeVRPgdXnnh1sJ0DRlrgdfLWZdTmGgDY6VC4kz?= =?utf-8?q?wXgplfnpkckd/bcLqyyZmCFVx8OiF3ci0LJzcNm45rubkQHmrcxy1WZaOYhPasnc1?= =?utf-8?q?N9sY8ewPk22ZfXu0uQC+W90Yyd7teJsmWfV2WvxmLjdReEWWFlWipmhdtu0pICGfT?= =?utf-8?q?T7EsX/0tIvbVbOiZ9lAjRRnsamCC3GEu/wIITot/7qYCwoYHbRt2mFG75af2ubNbw?= =?utf-8?q?q1j1wb39AM9OAmpXucTbXyods071oTPCOX6gQ2ymgjMTGGJPUWYnQM0CKQBfHypBU?= =?utf-8?q?4z8nZ+aupGeTXguBagWfjntH9k4ARlCfWcLponAo/arPgetx8yKVeW5/4y9W4k54W?= =?utf-8?q?FcSE1ZyHib7G0A/5sHqoI0A028fiQLE7FFo1P3p3AV10aVVoAF0FfouKfaWKXlBCF?= =?utf-8?q?gbVSwSxyd0PSHmHOd4AUPL01Y7NHipzmqsHvGqwaMmSNFSnxXUVOlrA=3D?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 803d3e2f-ba73-4342-c740-08daacfc9bc3 X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2022 09:23:37.2957 (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: 0A5RhK+MIxa8BhP477zfLBguRZhdaqyZzuiL6FjDe7UORSwh4ihSETFGuFJKN3GpXP16WhgwM/OIHwVmWoSTV6nLU8f5FnQQFvbidWEQ0SU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR08MB6466 Received-SPF: pass client-ip=40.107.22.109; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR05-AM6-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" 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: Konstantin Kostiuk Reviewed-by: Marc-André Lureau Signed-off-by: Alexander Ivanov --- 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 932b4e7ca8..3cfb9166e5 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 Thu Oct 13 09:23:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 13005841 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 4B6C0C433FE for ; Thu, 13 Oct 2022 10:15:57 +0000 (UTC) Received: from localhost ([::1]:52466 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oivFs-0007GM-3k for qemu-devel@archiver.kernel.org; Thu, 13 Oct 2022 06:15:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34350) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oiuRR-0002GB-NX for qemu-devel@nongnu.org; Thu, 13 Oct 2022 05:23:49 -0400 Received: from mail-eopbgr140123.outbound.protection.outlook.com ([40.107.14.123]:28929 helo=EUR01-VE1-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 1oiuRP-0004g6-Ly for qemu-devel@nongnu.org; Thu, 13 Oct 2022 05:23:48 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=W3BnmwIx9HFbpUEQRZe3GId4OEf1n3usGhIX4vu6lKc8sbxIqEEIao9FcylpNOSyG4XzVkzzlPTFH5XdGjITdScAklpzsgigt50XSYmYkkmJBV2BMZGlYufsJBzCEIuL/LJjtjLvMSBKDUmX/JqKZpdDziQCpcys0eau8Js7v/CIpV7VdeOFq5dRo6NTIUxgX9As5Msx4eMlet5oS1BRPe35ov83pTT5Dw85eqSffX+Q1g/BfgC8LDYelGgEuUwP9wOQkQAjV2dbNIdzf02fLj3SfFDsxcln1GYYGNJGnUYK/u83tEBmhsHUt+CrLEShvsN4gNE2Jl/ZdP8xJANosA== 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=rkK0u43PU85jFfHhbme9ZUTebOFAr5bhhPIK+wC4mG8=; b=KwU8Zots78kDaIRjlFrn06RQeAUksxmm5FCwkHjsFGqBmAY+DP6M5wv1fox9GUCOmJ8Y6vk8z1Brez5PJucM7QHxZS2xIiK6sWot641y0xqyT/2ZtY+PA2pKD2/o6NmksBaYdx8KtbNiKlCvzJUIrjjGhW0JDClPstH1FvolHwTK7MCp/B7ZcDx3fx6Ac4yMhShx7GdxCDaw28YuLOzX27KLS2xTaw5GPzjdB1YKp3nqsC97Ddl68g9LVGgOAwZ97h7ELrMYi/gLMSRXOILY2wfGnWCVjlRUrutvjJsFjlr4nymjoTgXbvGatgGEogUuJme8zxXXrKt18v+cD16Niw== 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=rkK0u43PU85jFfHhbme9ZUTebOFAr5bhhPIK+wC4mG8=; b=r9VS2HvYio6DOOvP5Xq1QKGA2qnzRPiWujSUrnsKeOWTPKN8dif5CwPJ0AsROCf3MI+s6VAEmNZc/uAvo7oa4lhO1WOGvmFpklYjYV9N43XQw4kIMv1tS969TzVfOzix0E8kbwZmL9jxlozyduC5tD3y36kpZK8GDCejBLbToiS/S40JKBiuUn4fLLe0pXEVG95eeQwAyxNwi2IkjeeI1pCLjazWdIlCmmfqJXXan355/1Zz10JGYSYGC7kuZkk3UrR81LpqkdzzYF/xa0t0nvZRjjgzrHSYI5GWQm0YoEhyfzxuUN/H6jCzBDtV+5CgW7+d/JZ4PlI3ZH8U9EsvMQ== 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 AM8PR08MB6466.eurprd08.prod.outlook.com (2603:10a6:20b:363::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5709.21; Thu, 13 Oct 2022 09:23:38 +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.040; Thu, 13 Oct 2022 09:23:38 +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 v4 4/7] qga: Add shutdown/halt/reboot support for FreeBSD Date: Thu, 13 Oct 2022 11:23:23 +0200 Message-Id: <20221013092326.2194646-5-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221013092326.2194646-1-alexander.ivanov@virtuozzo.com> References: <20221013092326.2194646-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: FR0P281CA0069.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:49::22) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR08MB7095:EE_|AM8PR08MB6466:EE_ X-MS-Office365-Filtering-Correlation-Id: f4d2ef11-21fd-4582-671a-08daacfc9c36 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: e3TfhCsooQhUULGDwKmks1iZvbOkyC8UZi1jyidmMOLTB/CIH75YoGhiS7vG0VsmR+HouShJ6c8ZIV9fpQCXr0pPloHPQm3dqQ465OPhTWPuPcC6tQCVAy8zQ4orPJog9vaV01VUNLNFFJYt4V1L5szEB0eTNmtH4VOK9V5zVv061xZj8BdpqLBCWNx4TPzLWCeqTLhuxUMih5M94LrxCO9B8IAn3mfp0KMIAcUpOk21QqOVmDJE62wVEAalGZt/DQuhI1WEbQKgAN8ZSvi9GoHlBw6Gan/mXXk5XPVTfyhfphG6d3eShtpCV1tK63mZQZx4IyYWCfeT3dFoNsJCBE8HSxOvkJ3EBqrIIPNG801/IU6Mpaz7M3HdF32e8pllOxcsFhbj66EhojEAFDubuN8p1pkYc6Z1LrIUFVuDSyDCTkbrDznFXAROslZdhGRbcSg14V8RJQ58ot9xEPEM1oxM88D40qOpIlpluqH/H2CVYjMsV6awBgT2wA0nhxkkLjqNhOvvET36s9oKfWgfXHUsvXLwU3Ilkr4OK7qWNNcz8xeK57H6hm1uPxkWBg5nusvEHanunlO6ytsxQvYAvCYqyWyLceYrJCja+NRumyKHo9qNT3arRbaQzRIoY0texrVL7ehtudjqWqJT+TxsAs//lVng4wcRy+ustPmBZcE1SOZt/aBmE8amqI4Pxz4EWCAHHN5+mlj6DybQZfzq+JBbZ3iveo4Dy5sjnxmuqHVNDRCAwicQl0jSlOo4P26USvzRnEZ5p+JlQ1pdA4PqiQ== 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)(376002)(346002)(136003)(39850400004)(396003)(451199015)(36756003)(2906002)(44832011)(4326008)(6512007)(5660300002)(41300700001)(8676002)(66556008)(316002)(86362001)(6916009)(66946007)(66476007)(8936002)(38100700002)(478600001)(6486002)(6666004)(38350700002)(26005)(6506007)(52116002)(2616005)(186003)(1076003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?rEeNqwnAWLHNYYqNThpB3W+Y7D3/?= =?utf-8?q?y1MH/P+V/lAgZKadMeqwVN4T5bFTf0JekMbrEqTAlkl9l5bw+s/Qbmfi3GGPM0qSj?= =?utf-8?q?Neey7bctooFebyjczEqFvK1zdWRLSTVjQ4DSKkP3IImEkyhSeMpEEoiDXmFty+Ixo?= =?utf-8?q?7C9suNq/30PVeiCqKi55yzfqH7sfnH3UNkHFNmK5VQ4k8vwIHAnmWYqrFotB1SKIt?= =?utf-8?q?1wQlGma+0wE/vPr0mSAxoTtoDseSGocF8OhwxCAkub/O7Haxe/34DXPiX3c/PR4mm?= =?utf-8?q?NpQ2MIzxX4gw8/Xwvuxh/VMIXXB4IGXiyNzhLcdmoHdNBGNWQatMkDmVEjadYdKf3?= =?utf-8?q?2Kxuk5BqSflGQMqfNGg/4h2hmoZNKji49l9ok6PnHoMnJoz9QIIHtGd4jeoBgJFbu?= =?utf-8?q?1vENwh3VWobDcITx6yYxzcAWnKkmdMKl7XIRhowXgnuU5rMSP7HbCev0gcaJSOMsU?= =?utf-8?q?LO78FB/c9RI5qKZWa0jMCmIUE1WvZd1jDTazjRKaF0+HFUUaVQn287C8DRR1urqZB?= =?utf-8?q?b95jOCBHjf2VhlTaT2KbMAabaTncF0MlSd+ydm4zZ6wjC8gsf+zuh3iqAYGN38BNS?= =?utf-8?q?9aDBJ99vxljECVwzeAk516iPKFvrmMGXzQ85a1jCfOXbNhUBnttKYXjN39Qi2xTMD?= =?utf-8?q?RGEFZP/W1w3wPtYk05lao6rYC2LWz9prDHCOjklbZbTLtuaKogvYx5YbhvQYBid7w?= =?utf-8?q?7mHHB4kS1MNbS1qXS6O5ZIwI5nQY5AJrt3s/pTKvKen+IDgyHKD+TLVtdAifVgdWs?= =?utf-8?q?JGPZjjgL2XNWCGfg1scRcE/+zwHkb1DEu43bpP+jsJWzAySS/UxtK8ONU5ukUQk+8?= =?utf-8?q?VwKLVErtBsje4TwKF2TVhcSyKG5XJjmxugyAy+kHJwYMswPn+ItExcNxIGLAaMDRl?= =?utf-8?q?gWdCCcw7KDfojwiHmNdIWx7Si8XqvyW0FnL/vCxgbP12XMHwH8yHMK3fD+sKsIJJR?= =?utf-8?q?8rkK33v3r4G+zo0Y9slj1IQSLthzA/k4srfBxEz7CItk6c5TuNUOWkPs86bZ4BIUO?= =?utf-8?q?WAu4WHm4f1X+nyv8uoMzrABk0DcwuM3cGJqTCFaD1UMON3Yer5+s+uUoh3kKm18hz?= =?utf-8?q?ftQPeyf3SM9drWpUjYtINuQfICASTCrqpG9YReTodkyfZDwdHhKJ8x+kc5NsZop9c?= =?utf-8?q?vSNcrZKZBZyYo7GebzU+ew9VsEgqbp9ShfexhO7UucCXH3q2Ogq8mmXpXJnRtYvqq?= =?utf-8?q?+U81qpW5FQexGccPkUy6fbVk469KF3fIYkYh2BoTtma7VIjKoRTskLtMdQ2GLvIdv?= =?utf-8?q?PCToVVraFzh4N4VdnI0VpvWmHBqAyhOx/D6E0SwE/RRbQh+Rv4GLIYPDT/QVE4S3x?= =?utf-8?q?/1BpZ2+y8z4m/k4owQsaSRMEwUDP5HETVFQzzQN6dY/NDbhB5TgCcEzru+UVT5t7e?= =?utf-8?q?u+OYvB8d99iGKQVL5qnwxNlf6vgHK8a/jHgVTRQqBxk9KTbBzzXyC6C0VDANzp5iu?= =?utf-8?q?GZTGRAfFBGUGzC2FKoDSKCpGdV5cyCqEk8sPlZa2sMdwNODceoHIBeV38fHxDx6Ui?= =?utf-8?q?Z5KLLeTMiLUY6+gi659Hw7lNKNDSyB4nkQ=3D=3D?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: f4d2ef11-21fd-4582-671a-08daacfc9c36 X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2022 09:23:38.1393 (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: KkrFMOwW9lAQ4BZfi3eO2Td8Pq1HrFX3+GUMjo1fbkZTXBS1yITdXR3668fMs/gU+rbvhNY/6pFpQ3GbWF15qU9Q29HMfVtoZTRjb069qXA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR08MB6466 Received-SPF: pass client-ip=40.107.14.123; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR01-VE1-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: Konstantin Kostiuk Reviewed-by: Marc-André Lureau Signed-off-by: Alexander Ivanov --- 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 Thu Oct 13 09:23:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 13005844 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 E23F7C433FE for ; Thu, 13 Oct 2022 10:20:05 +0000 (UTC) Received: from localhost ([::1]:36852 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oivJs-0001xN-Bv for qemu-devel@archiver.kernel.org; Thu, 13 Oct 2022 06:20:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34352) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oiuRU-0002JP-AU for qemu-devel@nongnu.org; Thu, 13 Oct 2022 05:23:52 -0400 Received: from mail-eopbgr140123.outbound.protection.outlook.com ([40.107.14.123]:28929 helo=EUR01-VE1-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 1oiuRR-0004g6-Ls for qemu-devel@nongnu.org; Thu, 13 Oct 2022 05:23:52 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Vhq04hOu6D+c6O9EgvoX1ej9HudCtb4N/r4Yg84op78mjkbJ/I0kZKyS7/TmTTCE7R8mp6S0Htl3nVv0SjLisQGWtdDgjSB2tUq7gx8XBtL4I1iu576z7ZZvKG0KRPwUmFp5m5h1m8dgN3Zzl/cJkiaqmoFI6IeuwEzdMFjC9O+H+q2vH/Nv6pJlawASYIulX19q5jrwV2NkjdneyPQaGNvAvb6cXh3CzqHYTJY3wY7K7/iZXeMyeVteJ8XX/PIz1sb8tg051vwggCDCGbt21FyqeUPgp4Fmt8HsFH1lj0S4xmXYQi6FuuOVJ1x2n65Bh9tOMO8tEt31HlwEtDuhEg== 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=iT73yPip7Y9KrhTJdJ9NiMxOTh3MLqVE4NRIId7eC2U=; b=enHoBXEIPQHoDzy4bVnPsrnjiu+BFd5jQ1dkT+TJyxIHgXR3zBEwI1qsZDTHpJt4/KocHeFEQqsCU/cOgRWGAyZp9BhqHqCFPYGj0pkxTeHQtdkOT/AgfEG6staokZ8stpXJ/kvWzirmbL+gEUTAifVfbkqMUf5AbF/omDdFj57BoxRjm1+ZNTgfq7+v+64NSA4dacUxYuYgtOm+NbeJ5uh6V1ZD+MWcq22BeNQkILO6JVrG0iRJVfF7Jb5SNAokYJ+i9afXnZfbx5G49I3wBdRyB6cTBXNIF8NMLCuEmwuW9I45jL6Wvo3AJu9OtDFqcFjJa3foLJUAilNK9/RSgQ== 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=iT73yPip7Y9KrhTJdJ9NiMxOTh3MLqVE4NRIId7eC2U=; b=ezCB8nJ/LYIT52E/QBt8tHX+n0OvbZsKX/pZVCZYex30nU5Ac496vGw4kAJ9gnuk1sfcMnR0T33IUMhdEEEYOIGjOy76+C4BNKjvdOnAUz+yFTm2SQBKFW9nYfLoxAxgAhuFezhlMFbANMvz8dxPATfbe7mhxK+7NR9biz+YUwXmfi9TzFz97MGdTY4qUrgMfGHOlv5jSAMtjya6E3ymlHeo4xoNc2UIYvLDx+CmIo/eec1mTn19WeYYZf3PR8ipx6wRD/HM8DRGGnHSZqEhiMqP/EbAx9gPn403zL4/AH0NIiY3Yfz5+1JqfTJX6QwEZnC9uS1Jsr/StVmAeFZiow== 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 AM8PR08MB6466.eurprd08.prod.outlook.com (2603:10a6:20b:363::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5709.21; Thu, 13 Oct 2022 09:23:39 +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.040; Thu, 13 Oct 2022 09:23:39 +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 v4 5/7] qga: Add support for user password setting in FreeBSD Date: Thu, 13 Oct 2022 11:23:24 +0200 Message-Id: <20221013092326.2194646-6-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221013092326.2194646-1-alexander.ivanov@virtuozzo.com> References: <20221013092326.2194646-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: FR0P281CA0069.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:49::22) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR08MB7095:EE_|AM8PR08MB6466:EE_ X-MS-Office365-Filtering-Correlation-Id: 12e30ef2-abff-45d3-f99c-08daacfc9caf X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: we0cty67ycuD4aWo5jy2KqzPy4HD/Gvi/gmEsPC+GCTOWbTMXRdbELGD9tw8ZTt9MYRLuzaT1EuGAR3zIkbxlGJiI3XsTK8bSUO00OLbtOvgsLjB68DQmKypt3/METrFY4v+zSLPqUiUn3m45P3GYvM4nDhTYizWUaMb7QdzKd53tq7QjbMz0fg7vJ25fGWJNbFBM6gI+tcQvlaPvE3PsM2a+9POtqazTszQJSIywslqXnWFJRKjXMP7VvGZ+nh+4tNCtrLCMXXZnPZ5xVJKCJjC4zch5tvghxXySPt5tSquJS0KtxjBU3Tb1YMsj5ZO9LZ9cm6zddReCVC8MTqwvvmCYJKnwPopYr19CNbWqVbOC+lvYHHk104g1RPcDe9pjBgndip7YUU1Bd5Mi5A5eB/5IaENyQSXTsHcReaXNwraU5Rbvn2R90gJRDW3tcQOmVMLebc8K0aZuxFDiGkjUp7ts40mzq6stObPsO9+L3W97H6+/KJYtcxNhzlRhY/r+YOaQULDxwlOKaY4YFjg4oS2/dpM488INr8jzN8gToBi3xY1wl+zlHYM6HY2qPFUeTvR6r5oXPHlYZJTe9cwM0wcz6RVbYi9Arx1KVWaAqrdqVk7ypwJ9eZPCs573tLGMQoSpn5q7u3A2MJIzhB68sGec0fsvG2b83laq2MG+33Gl/8NWdzWuGHHV/8U8/Pv8EMBlyGBOoGRwPH8dYTzmmhPUhwCND+pMCf3yoHvEnRtft04S5SAwmj65K7z/1jk 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)(376002)(346002)(136003)(39850400004)(396003)(451199015)(36756003)(2906002)(44832011)(4326008)(6512007)(5660300002)(41300700001)(8676002)(66556008)(316002)(86362001)(6916009)(66946007)(66476007)(8936002)(38100700002)(478600001)(6486002)(6666004)(38350700002)(83380400001)(26005)(6506007)(52116002)(2616005)(186003)(1076003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?/YJOmn+GNXSqKe2ZxXFG53KyjDI/?= =?utf-8?q?6F6lMODvVUiIhTYJNMwP94NBSExcB/Hx+N3oipRXnyO0iqFr+74TNu33o3ApRUxRq?= =?utf-8?q?xgtOJ8vH5ITGXfxI8kYWzm1HeCzltCZr/ymDWhpGXMjn3oG9W5zqiCQNwgz2d7WmD?= =?utf-8?q?8x4n8ikoll0Q0tjvTEHBBPoD3lm8Obj6EW382B2Hj2JzC4leZXlb4TvH2UgVIXV8e?= =?utf-8?q?j5lgSYb48a/KXipr8Kj6HIMip8yzCLVQKGllO2Cms8AGes+yqRs+AjdvQG9rOijDk?= =?utf-8?q?4V8F3CxcE6A0U9Zn/LgbP2kNpTQ/0Lqm2u5/FICXAUevvEjZ9p5Wg/aolZEs5QZBS?= =?utf-8?q?hhr8VRibcec2gXxQskUeD0ctPXiyE0SdtxX1KybPnZipIFJiu1VSdlBMfiCBZUGEq?= =?utf-8?q?0MgQBgIhL8j4u4XyYhnlTt7gDKvDypOkXw7J9jfPW/iiC7uRQIGVgZWTcjbgjMMw9?= =?utf-8?q?ZPH52IvtUU8ULJJUt7/HGk33kwu5yDjUD5oSkstv94Yk1vAYJKTTjigdxg/6HwQGG?= =?utf-8?q?lAASh+F7qD5MxUEtSNKHQVsPDNUmknBrj8ufIis5UHytCIsXWcZUhT4ZapRCfQarS?= =?utf-8?q?Dpu6RmgPYaYIM/uMEufehn9kn2u/vjbDUR15yWqnihfmxEVjFWO4H+2XY0IguiwNV?= =?utf-8?q?J9AU23yth62ES2O2uXTnGh0D9QFu8k9h1lJr7Y2ZpjKlnvRI6UZO13HFcNEt/dDSM?= =?utf-8?q?42LKbIFg/h4+TVV+ohVwuaeclaR/+4U47kN+tLlzql5XM1+9LMCCtl0IYe3Cgm2C8?= =?utf-8?q?ONhEeJCYqAhewe3r+574NjUr/yT/K/hcOnb+EUjuhZWCgYDBpZXcF7tkuE2+V97Fp?= =?utf-8?q?YA24AYEE1K4DmoT9fDK0d/NGCAjjNFacYUC3PZI9CwK9vdUfvLm8+rIL9SOBBZuwz?= =?utf-8?q?b5cRfvNZ7lsb6xYtCi/5P7hmadEzCocjvpfq8zbXiQGmNIMItN5tRBKxVa28HObOv?= =?utf-8?q?GDfUCbIGk6aVY3iW1CdNIOVUlpWOK+4IZZbllJ8fHdTtlMFEbTR91o7qGZBMd7qmS?= =?utf-8?q?3gTjajieYDNSCWC9xG7DEISetpxR5sLjeVQyDL48VJTxSnGNfLlfLO2gs9E+ACfhx?= =?utf-8?q?KsGLdoup/w1sN7HbdgkQ6p/COlPqs95ROrJCys/pmt4njkBFG0gAS2Wqpv1W2oDql?= =?utf-8?q?he/IOTYRDBjeSJDaUfba+ru6ViO+R6D+Aw9gDXFPudz/uIKbK7Wtx3wrCVVB9n0fA?= =?utf-8?q?mGYuzW3EXGx5hhhZRKh4dBHwtRZtFAv/eZgoNlHwE/uN0wowpn708Kp7ccjPsIqxj?= =?utf-8?q?eoiaK5joUoU75N9b7a37zHQ/Ye5IMHTTxNkS/q4BzENWYtjrYB/2nFaUXdwkwEAwQ?= =?utf-8?q?7XRzs/S9wGAShFgaTSe77VPQeglFLZtMAKu2TCmswr3iN+DPoNnO/jm4jNhGdUWkn?= =?utf-8?q?dYG4TGhaVKVc4MwQzkjpbbBr4Qpi3Y7Gny3KYfkUbwJhJOBUtleqwznH+/4nNPwCn?= =?utf-8?q?XXsqUsRq2bP+1WxX2ZovqSCd7R1/42cltvIQFFB4I/Hof51Jja/rXmGt0newLF8LU?= =?utf-8?q?7udy4/w5JB/SdOA6v7t1jBKunVaHtwhrBA=3D=3D?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 12e30ef2-abff-45d3-f99c-08daacfc9caf X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2022 09:23:38.9675 (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: gx3+qW/IhZv1NTGFlZC3EajunSxJ5IB0skIl4Fnnbn4ZKuzrS4qeedMqs4oE1h6OnjseWSbeyNTLi63eMU0OkcnsYBtLYIPVZgvaqYYK8oc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR08MB6466 Received-SPF: pass client-ip=40.107.14.123; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR01-VE1-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. Reviewed-by: Konstantin Kostiuk Reviewed-by: Marc-André Lureau Signed-off-by: Alexander Ivanov --- 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 Thu Oct 13 09:23:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 13005809 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 DC086C4332F for ; Thu, 13 Oct 2022 09:42:49 +0000 (UTC) Received: from localhost ([::1]:34222 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oiujo-0006px-Li for qemu-devel@archiver.kernel.org; Thu, 13 Oct 2022 05:42:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34354) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oiuRW-0002KE-K3 for qemu-devel@nongnu.org; Thu, 13 Oct 2022 05:23:55 -0400 Received: from mail-eopbgr140123.outbound.protection.outlook.com ([40.107.14.123]:28929 helo=EUR01-VE1-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 1oiuRU-0004g6-LY for qemu-devel@nongnu.org; Thu, 13 Oct 2022 05:23:54 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RybOU+TMjgRfyC0Fy4xt+sWgIZWj9ZFq5qH99Jm+CiMvmHTL/dXQ+DSDUH3JXagWjzj0DMNbC/KionrL03wmyHyqQrMy6YCdz8GgRSVx3ikZVy6CEmtvbuSFaeDck9YupodnQAMEelthylnbnp0gTDWpAfJT2+krh0e5PPHaHWESfnLDU2+/V6M7uR10sT4DNsgE8kZwNeYYX7/Tt5CxJO5XW6aYH2jQdDS8OqVAq/AlOy8WmdypCN9EKWfXbZf31k0ruoTXrEX85ZXBZV5XWSeMxE3RdJ9gRLqtJhOhq3C/ymx1c3EHm0spQmTsIZBZ6LfjwvkGDAZh0byB+K8noA== 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=vH3fbWs6m5SwLq6wrkYI4EghiwTsdYD/b7xbrn6+BCc=; b=JP/ouK312SkW92j1BHPxgGIhEpPUhV1qWn2twpfM9iNfjOBnxvhdUGONQSvHfnqFBJxgrXAEsa4IQl0xL5cY6i0+NTvb5FSZDMrjcrBXmegDyn/HxI/igbFSgZ/i64LH1s+VhfKx/AdQa6GnhfujhtP5rm4lBVCyuMON5EQ6/Wt2lHK+DGry6MffEcgISWaz1UEOnp6iwxavqDNn9ySkgI68dQpY6eDk8Yw+NtXpVJDT7aGYJAzka46UtjLygYTVmGJsQ1kmv5wfZY+fS04ClL4nB3xLXFUIQ6VRincKTOQlkDIp/GSeEu/K+7rsN21xKHBNM0JwN48m5nqIUq2ZKQ== 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=vH3fbWs6m5SwLq6wrkYI4EghiwTsdYD/b7xbrn6+BCc=; b=b19HqBMcbbf0d8gLqAIbawW75d0AUGZScDBtcMvexY6ssVgpd5Z2Q5WKBo/ms7WawomF9M7SFJpfCQ8mCKQctBRL1n88X+zv+RJJKBPbjK4RiOdOIAJckNX8CDtLt1ngLN54+ab09KnLmEfwPGeuIQU/U5Et5k9bawGzvyuEUauPARSqFSN+o4H8+I3Mpv8oba9Q74Gu8NN/BLuFHzycXEFfmDLrtC4ndI+TmfNZqKoZqg/hv3Dp0XMS9ftvAvLe4PYwOWdRJ5RdbHs7kFoX5X7VjafvqhhCNKYqHuNWFITgBksGqUQticigurt6Qw4jMh2gTckkad4MVUZV97G8lg== 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 AM8PR08MB6466.eurprd08.prod.outlook.com (2603:10a6:20b:363::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5709.21; Thu, 13 Oct 2022 09:23:39 +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.040; Thu, 13 Oct 2022 09:23:39 +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 v4 6/7] qga: Move HW address getting to a separate function Date: Thu, 13 Oct 2022 11:23:25 +0200 Message-Id: <20221013092326.2194646-7-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221013092326.2194646-1-alexander.ivanov@virtuozzo.com> References: <20221013092326.2194646-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: FR0P281CA0069.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:49::22) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR08MB7095:EE_|AM8PR08MB6466:EE_ X-MS-Office365-Filtering-Correlation-Id: b907b779-6266-43d4-6344-08daacfc9d27 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: eevKZ0K0itz/tRTCV6ecTqdwekw/hTntfPPMBj0Pe7mTb3jJy7C/O6KxZfgKsHVuFke+f0TyMXkv0LgaOUOSJSSi/O0zfx0phbPDU8mXCwklooXb3IVUAuSTHFX26GZ2ByjCI0H8dCD4jEUj5vM8cffPBqMgVeWMlqRXXiN9yFUElKLxf8Lzqnka/nd+Bwgjc1MNuigxRW+elwi7Sps1RBM5Pj3SmNf7gGYtPv3bXYmdsK0Qj+em32t0M9qx+/CgY5Zr+B4o6gD1i6CQbk9dO9FnshOCnjaI02Ec6XLsbGMiBzINxfEUqxP549jcry9rtREq2RMEClDuW0htnZPp/kVRLb1gQRbVWjcrB/dBrIZsdw+/IBHjsRy+8lY6GmnPrVZvNyi52PhqlYKqAnPER+XFI8u+G7sQGf8Xyk9EdKZeUajSxV7gcg6dlmJ7o4jLoOYT2Y6TCzW4JBBmq0sF1YmObohruhJksRIL+pf2PyUQP0B///cNfIHgmr68DSiEfAK5ZlGpyh/CNRrVO15iVjPj6uI+s2oM1SSoykwwAa75I5IQhnD+p5hdiPNnwtyP33bnnC1PCIhcR0W53VemQSXXlACvnxchPIJbpg44d95nolOTTdTLwmqvZfItXv4XnQZyCJ/5nBWqPhUz/cPMeKwURipOVxpEr7vQKQXG9mRlr+7rt+anBsCc4PAh96XXwOaEapFI6tCI2mCHBr9KY0vcLa7rkCVykFPFDfzLdijC36YlyoN5UyethCk/uOyg5KGQcVq4OuFiMToO8KdTyw== 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)(376002)(346002)(136003)(39850400004)(396003)(451199015)(36756003)(2906002)(44832011)(4326008)(6512007)(5660300002)(41300700001)(8676002)(66556008)(316002)(86362001)(6916009)(66946007)(66476007)(8936002)(38100700002)(478600001)(6486002)(6666004)(38350700002)(83380400001)(26005)(6506007)(52116002)(2616005)(186003)(1076003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?ch5dhderwdIfDK5jO4E3hcqZrdhE?= =?utf-8?q?/pN/0YVDiEDyIDEsDy2lzx9SF7UGNBLsPaL8T7OI0TUcM5bOJHyZ7nxgfeDn3E2yH?= =?utf-8?q?6HcVA9HC8SAhgsw/KsQZfYcETvUl0ycUwcCbOeLtMhkLM8KoJanKbFCy4/gstR7Dc?= =?utf-8?q?78gdNDZHaki0ghdSmDz/kjvuESG586tf+vJaBUz3HiYMSJ+66JFp8v6bwyOXSSkmC?= =?utf-8?q?RwgPndDE4Pjim447SxXA4srowfpl6+Jdu6ALXuCUtP5hWoRpOYa9AAn5kki4St1ry?= =?utf-8?q?DMvMc1lnqk7N+fMS77ND9uHhAazDp/mov8QrAKIF6x5qEzjM4Y9EDNmdBFa9Fg6XM?= =?utf-8?q?AK7LoWIDqpc+b/r0YVHFDK0+DPstlVqXFx2LayWmQFlVOW/t1JucgKbEup6tqR6Hf?= =?utf-8?q?jCp0mwtwoAH2ou901ZWM7NE51kKx18T/XGdJI4aUq6rXXm8vL+4El/0j3bqNehozw?= =?utf-8?q?Ysco/1zuP59PkpR7IgUaQd8HzQuFSugqBjGOMCq8iYb1mHEkglbZ6rEoP1aacctUn?= =?utf-8?q?X6Y5j4qLe4CG7cfswrWMw5ox7qBiIi8sFIxKB1lldtNcrD2UhN6GSjIpqFAkZja4I?= =?utf-8?q?ZlDpqlcALNKE9lIr6N6h4NOR8ifKkZ6yBTSTIHSSUP3Sc+AGQdbnlqYam9y+xioFF?= =?utf-8?q?l7mQLxvun8kQLZJv93ipslqbdUB4jtBCZ9GZw3DUo0qxDpaq4qSfYckXX7b5Yg56l?= =?utf-8?q?9KLubShU2CJW5nzGWnyGZasKtxa7l4g7RQQiML0/k3gR22pWkNxLj0Cf7ULj0OTB+?= =?utf-8?q?4QxMgZ0kJjiP/cIU7519Kp/1bzBZJY65Q0GH1914yZxjgtZ8N+NqKV8wkXRf6nnhx?= =?utf-8?q?WLe0b8uaw+/2nGhXYaAm4H1eGzArHV2a7u8P4JxdnBSAAqQr+ClY3Ck+HGyE3BHzX?= =?utf-8?q?UyfSce+KARC2n9KR4+h4kVtsbUPAp0Oz4pzEptW/IP/w7qc5BS5t50l4kIdoiprsl?= =?utf-8?q?44GgKhK+Ac9XsAuRAVy0KQD870s2LHjIkgE7sonRcaFKyJndDVriCXMkS1JZgITzZ?= =?utf-8?q?Ln9DMbzX27hnjrCSYgXO0lTlj4bJcdpzuMH2bxH12Ba2OycLP1l9S2yAXGiiFEkV3?= =?utf-8?q?cr6k2r2mGDr4lctvhx0mB6jjD0sVTEqOH5InIBF1/nTqw+BjC8QARmfEE9VFZ7PmZ?= =?utf-8?q?u2GE/vZYJHA/M4EGsKeZTcfeLyjHwywYLYuViXRi4v3z6K4ZFKHdXBEA26kzBLUhW?= =?utf-8?q?YTqhZZN3OvrrxQ7GP0uEDI57WSPxg14KIToemUG4Z+p+b4psQzdGbehV4uyZm5lgL?= =?utf-8?q?hMLTqelYdG2LFAqnFQa7HDN3JqT5vxGUymHUVPVQe5Wo5IPM99EwHbtIYtNzew8om?= =?utf-8?q?78FWuPh9r7PNmQmjd09AJcbokft6DdSDbsrVdNbaIxZWyisga5C9sK5V6XwfMapbM?= =?utf-8?q?7NoaipLUurhC9q2bgMO9WUlaleY90poTMozupDR4kuUId/6bkyL9hESUGkIuYK5Km?= =?utf-8?q?n0X2tvSOKIvEw5/qRJe4T0uUPxGg88D98fnd2HFa7nnUS7TBSSv8AEApBbaN0vc+G?= =?utf-8?q?P5eLTjTgZOikWLwuRpt2FRPX40pz/o9UsOKF1JMto7i2871lnnvRCcc=3D?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: b907b779-6266-43d4-6344-08daacfc9d27 X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2022 09:23:39.5624 (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: LwRR3iXNL/tGgDN2ogMxm34Ke4iCg+yrqPzLyDgSCDOBuHIDZsYr/kTLu1yUKbxMQ+Q2cvq9elktoFzceBGZIf8FAk4S1a1wQPSEyf22ueQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR08MB6466 Received-SPF: pass client-ip=40.107.14.123; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR01-VE1-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. Reviewed-by: Konstantin Kostiuk Reviewed-by: Marc-André Lureau Signed-off-by: Alexander Ivanov --- qga/commands-bsd.c | 16 +++++++ qga/commands-common.h | 6 +++ qga/commands-posix.c | 98 ++++++++++++++++++++++++------------------- 3 files changed, 78 insertions(+), 42 deletions(-) diff --git a/qga/commands-bsd.c b/qga/commands-bsd.c index ca06692179..ebf0fb8b0f 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 false in case of an error, otherwise true. "obtained" arguument + * is true if a MAC address was obtained successful, otherwise false. + */ +bool guest_get_hw_addr(struct ifaddrs *ifa, unsigned char *buf, + bool *obtained, Error **errp) +{ + *obtained = false; + return true; +} +#endif /* HAVE_GETIFADDRS */ diff --git a/qga/commands-common.h b/qga/commands-common.h index 2d9878a634..05d1f7ccdd 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 +bool 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..787ffb1562 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 false in case of an error, otherwise true. "obtained" argument + * is true if a MAC address was obtained successful, otherwise false. + */ +bool 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 false; + } + + 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 true; +} +#endif /* __FreeBSD__ */ + /* * Build information about guest interfaces */ @@ -2909,9 +2952,8 @@ 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]; + bool obtained; void *p; g_debug("Processing %s interface", ifa->ifa_name); @@ -2926,45 +2968,17 @@ 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"); + if (!guest_get_hw_addr(ifa, mac_addr, &obtained, errp)) { 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 Thu Oct 13 09:23:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 13005805 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 56700C4332F for ; Thu, 13 Oct 2022 09:31:27 +0000 (UTC) Received: from localhost ([::1]:43118 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oiuYo-0007kn-97 for qemu-devel@archiver.kernel.org; Thu, 13 Oct 2022 05:31:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33448) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oiuRa-0002Ll-DD for qemu-devel@nongnu.org; Thu, 13 Oct 2022 05:23:59 -0400 Received: from mail-eopbgr140123.outbound.protection.outlook.com ([40.107.14.123]:28929 helo=EUR01-VE1-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 1oiuRX-0004g6-Tt for qemu-devel@nongnu.org; Thu, 13 Oct 2022 05:23:57 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JcciapBzLuNKsRW0JRlO6csm3SrZ9img6WyiseARORedqnsdDXxameDx2R/CyCoO/Q/s3Cm37a6qamS4Sp1iABdy6p4OenMp0KTOawxV9inQ1NEMg/0v1bBtkptgliT4zas9ga1c3WGxGCZbReg6JAFJAOKH9Ijz5qxPfMFS3bHVM1rlqwgNmrcP6cSr3A9tlNK/mFCXmJIOlWZckZnpOegr7U5idiMXNcr51pimYWcc2RyOsF4iu0BehexAe/5ZEpdLgp72iTYhDXt+KxbBKRWXIireTlqf+N5YScsgrnXHUX8mFocS49LLYRuxgz8eaxxppRZv8PZSy0D47oUpHg== 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=gxxmbxAcZk965Xpx44CaaKqYjArE71BENpKHlF/1fPc=; b=Hbg6909E7NWtSNzcVF4PByKzN4ueHl55KxdFniyid1WF3upHJhJugNVwVSByhLVq8sWaSNQOf+Vs/klpFSm5tsXcxc8Uerouui2mH81Zhg5ylmBVBF04mso1JYJC9kUzaQHHezcbUxFER4aV+cO9GHs1AFDjxoRYKjvhtk3x4cOlcSoEL1kAoA1oSo47svP0VQftDlWVDwSx8BG+sNcu8fQHP+SWv6m7Avnw+RRJm95XJooy1sVx3YtbWkJDpOFsJXRF7ctBhuV37s4xALqlp3HZb38kIbN0f9HyDEHGqvBXFpeE/3SguwisyQZA7H+ax25soOMr3x39pyiFJxhcrg== 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=gxxmbxAcZk965Xpx44CaaKqYjArE71BENpKHlF/1fPc=; b=EbueDlinO6p8g7IuOxDMc2REII/o1t7ikKgH7xZFKVrwkVyQVf7nr3SnignppVAPDc3GlrQF20kFjTqqD1De6X4I3HEnOcs/KUBW+bg06n49yIxVLal64+60z8EZJqwDfSKMZHywPGutEz42q6ODqgoXy8wd45ywuB1uvcCpMyJ7zXmkqksZVfjqNl3D5ktOGoan8IqXAnqmqnRQUTiNKMqHkVzJ9/fvCkzcVjLUBqOalUGdPmt+qB0YtK7aoOwT9lurnlmuYo6N61vwYN0d0i2PJSKqwgZr6hQed/LAAFZmue0A67YiKvKMuW4RNCXn8nbpF2qOrXl4eClcR0Mx5Q== 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 AM8PR08MB6466.eurprd08.prod.outlook.com (2603:10a6:20b:363::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5709.21; Thu, 13 Oct 2022 09:23:40 +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.040; Thu, 13 Oct 2022 09:23:40 +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 v4 7/7] qga: Add HW address getting for FreeBSD Date: Thu, 13 Oct 2022 11:23:26 +0200 Message-Id: <20221013092326.2194646-8-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221013092326.2194646-1-alexander.ivanov@virtuozzo.com> References: <20221013092326.2194646-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: FR0P281CA0069.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:49::22) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR08MB7095:EE_|AM8PR08MB6466:EE_ X-MS-Office365-Filtering-Correlation-Id: 09540233-3558-411c-1f58-08daacfc9d89 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wbZLJNcSnhXIbLr9RHFKETFSr2YLqiHaj0Mlvy4NIGGUoWMJuHSmvArh33RIkvM/7K0CcvHVmRa1RWfFwDD0+wwxVur6siXUSH9M+P/WKq6bM6zpP+XcLqhBIfailztRDLWmtoleX1MKoRbV0G6ibC2AVPOQjRx/P5KeO4WwamcqqkdNa3vWG+j3ZZY5cIL2saMkAcxKridym7teprL6ZSvTa+9qoDRYPW/USMgdl+9xhvvHjR8T8mFw/kzhF7xjEo6Gn0MpRv29nBRvFDE+86mxyytvsu2A0wRlVBLBkn2suY+CM1g+LMgmqMhB2tiSg/GhmGeqXlcVEJNyAzNm2u+WNzCtnvbto7EkOSGMYqVmcuZOiLBD+2zHNIdA9f6jyr05rWf4HaCNqAwsCMe0Qac0yXVCQYqbKPxcg3Fw/XsQ5jeimjxeiYmCLRrbaBeVMQG0WK2UJi5fq8Li/TEpSPHX+CvItNYQ79xwKfWHY2ZjphWC0QxLcTvX3edT+aXbV0FAZ92Sp06+iXvHqYo1GHtPuetLw1o1BNg1wcVd5Tu4ao/l7gV8kDh5LfI9AtBsqZwJZ8mzCEU8bPh/huqm09Qhus1hXxMBwtIVW1DIo+lshef2IXTbx0jF9disH+bReeWYjGpqFBBA0/sS7LLC9QUf4Q3DvTKX5da3OUXUD+TZ0rcv8d/zLQJpGcFUHSW3YZCLFhxa9RfbVO70u+dN4zjOkko6de7C38TI4bjIk35qaDusFChS3rmod2p9x1PShBXuDANhU+SpHp5eRWGhjA== 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)(376002)(346002)(136003)(39850400004)(396003)(451199015)(36756003)(2906002)(44832011)(4326008)(6512007)(5660300002)(41300700001)(8676002)(66556008)(316002)(86362001)(6916009)(66946007)(66476007)(8936002)(38100700002)(478600001)(6486002)(6666004)(38350700002)(26005)(6506007)(52116002)(2616005)(186003)(1076003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?QrsMBblm9SyNFPIycBfHC16+LPNy?= =?utf-8?q?1UN0/+9pJpZYmgT77mUOWQYkhUwdS+D4WUmG69CMcilpzpjoncasgUTxxz1Bbxgow?= =?utf-8?q?AzB++IWm4TDGGnmJILtQDZ77dkAbD7ycz4ni1hgxkittw355JyJNItS28yI6YGpV6?= =?utf-8?q?T0OyAoQ+7RxpoUPSN7fjRJJjkjwttEslqOMv+VJkYteC2ZxBxjfXsAa1pr+UENoj+?= =?utf-8?q?HunOQ1F7tCz+JVUA3pf/SYBVZp0GQ7McxTCu1ChU1Jp709+Z+VYezRN1t0hEl0HTm?= =?utf-8?q?9x/m3e1V+OSQjTDjwXzM9gNr1I5070nEdRe32lZ7yotfropC/y7quINZx1nEKqP/i?= =?utf-8?q?3+zd0TWl4XdjQlxVfmnAkHyBx/05WQXBXyapZns7hRXrr/K6xg7lyXEWH0c9S4Qqq?= =?utf-8?q?CXp84OvUkSgS/KGauz1u04O/htmLKnGbhPYBHrPq3JQJWylX4svSMDGdDk3orphG8?= =?utf-8?q?Eu6CfB+DdWDers0ZYB2m+E+MwS1jOg9Ya3F7fTpjy5eg5HofeX4DtaJp8l1KXCI/M?= =?utf-8?q?IGDCZEQGE4DjKvhPPqkucJSZ8AvdKGe87PrZTuMIp2AHtBeVfNa3i+UNB76daXhNK?= =?utf-8?q?8YOr6qpfVgOAxwcGOGqprjLrZxAOwe3vCRyeqfOE86FrrtCsjj7fT1Mk/SLmmjwWN?= =?utf-8?q?FmKiE2JCD88iJJb5YS/2BIbMWmTrAHscz4odo45oendFaTLLWj+m1FCNRptCT26Dv?= =?utf-8?q?IpRadLQXCc37JoMWYHHhPckloTmErraRBPMElMrEEBwP7Ubqo/A58uwK8KLSaCwsR?= =?utf-8?q?QMcFYa2GP2Hwb4skccZRV7emVITroMm0DV/s5N8ew7Ew4/GJ2kqWsyyevwd40F0v1?= =?utf-8?q?bUtH8VXfibMRqpco4rgPWikNdaCBQWLTLbpSDa6Gihx+eHMXxJBPQhpGBeOoNpafy?= =?utf-8?q?e52B/kO+gChwJ0Vhk/mmoQiIhdfmr/XncFiPSBAsL23Zb3/+qL+Fsa+u5fuDQ8ySi?= =?utf-8?q?Ua0tHGuj0FDGeawXsVE9Xi0uhTB7xmtgJIyqp5yXblxTIWHcFqSPVxyrYOYUxhg6U?= =?utf-8?q?nJkH7VyLOvryxOmJJJAUh7m2vLgO73/kP/KsPm1UUPc254P5jE7yuZgEJGK0Pevz/?= =?utf-8?q?R6kG1uybc1JAl/U/xHJu6avD2od7H8JGXBdB59DxEgcMaGBVf4MvyrBBFV1IbL/L/?= =?utf-8?q?dITe4Atf7xiSMMlscIb9HnPFV1gRTsJc4InFCioz0vjkOtur/h39dpoz6zMUC9JVk?= =?utf-8?q?8mqh/PHhxbenyB9aENPipmr2BAeSU+/X+0g2hPXCfS60Iws8+d6MaIdWLI4jiC86u?= =?utf-8?q?xaaAUq/avtIlXY4dYAa4eZx+dKhW5zWv2ApdD36ad2kVcahcSNGzmu89hjSE0tVs/?= =?utf-8?q?CLPhDe7MG9jzBsNwHX4+CiQaU20N7BkWgKWrE2QCCiRKcH4WsVVgFhuk9o5KLWHuo?= =?utf-8?q?cU45L3MpbhRYTQTo+UY/qjKmYwU53GVm1tRATSe428c+CnfRVuPpKDKM2YmiDgUnM?= =?utf-8?q?4qv9v7oy6+KlKzNfYpfFLL5zlg4tuZQgdETxJFBe1+5SfG0TxQ3LPcrlysscGP8iW?= =?utf-8?q?4lAJ8J3LtSVGHnESpScty08I4KUkeXL9bA=3D=3D?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 09540233-3558-411c-1f58-08daacfc9d89 X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2022 09:23:40.2498 (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: zWTjW3Akn9pXYo+onZHVA50YvGLNePnA4LX4nRkPODSk+CETakxqmpDBMZxwfRvL8QY746Mt19Ge7UGL6Qkey42ED0ly4VIk3OHGLsPYoA8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR08MB6466 Received-SPF: pass client-ip=40.107.14.123; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR01-VE1-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" Replace a dumb function in commands-bsd.c by the code of HW address getting. Reviewed-by: Konstantin Kostiuk Reviewed-by: Marc-André Lureau Signed-off-by: Alexander Ivanov --- qga/commands-bsd.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/qga/commands-bsd.c b/qga/commands-bsd.c index ebf0fb8b0f..15cade2d4c 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,20 @@ GuestCpuStatsList *qmp_guest_get_cpustats(Error **errp) bool 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 true; + } + + sdp = (struct sockaddr_dl *)ifa->ifa_addr; + memcpy(buf, sdp->sdl_data + sdp->sdl_nlen, ETHER_ADDR_LEN); + *obtained = true; + return true; } #endif /* HAVE_GETIFADDRS */