From patchwork Mon Oct 17 07:28:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 13008264 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 B8F6DC43217 for ; Mon, 17 Oct 2022 07:44:50 +0000 (UTC) Received: from localhost ([::1]:44114 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1okKnp-0000dN-5q for qemu-devel@archiver.kernel.org; Mon, 17 Oct 2022 03:44:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55480) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okKYk-0004kU-9R for qemu-devel@nongnu.org; Mon, 17 Oct 2022 03:29:23 -0400 Received: from mail-db8eur05on2129.outbound.protection.outlook.com ([40.107.20.129]:65301 helo=EUR05-DB8-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 1okKYh-0001Je-UE for qemu-devel@nongnu.org; Mon, 17 Oct 2022 03:29:13 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cn9GReXWtYfSv0UbqRp3BBuIDkZ+Qim7QVo5zS7cDlI1raLybciQ07ORZxeVTQ//rgkQCN5+SrGvkMgXIpuaMBTIzM45GpYNRsDVNADCUyvi5jJ4KIp/CLofn/Zwi2YdB3f5uAORW2hwJ3APmOmdqrdFnEO3yo0XsPzpCegJco4AzR+VTq1YRTcW4CMvZeIqMkfEsMlJDaFHb3geSqDJfM6xeZ+wwgSn1EWesh/+3/lbeJaU1I6tigwMMp3OVSXDkSMzUBzG6lXGGGU7+R/ChcuVPhu0L4lDlZvVtA8ImQDrR2g98ISNerE3guNK+o4SWkl1/SqIYO5gW9kx4Wihow== 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=C3ZCZJhH32SA8taJe662Ni/pMf92rh0F1IfWR3W+PZdOnfYngKJKnKVV0L6UIDN2eDckUv/Kay1Z5O6t+HmJ6pk2rfcm7EJo+dUsjwfgjsVPoPMs38M2CXpw8jLdM/DKQLdzToUXNzt2W77FPr2tT1M1y5kMJZtLe5mUD5HMfdQBWyI6RpWdf8mWV2Vagz3Byjl2oGPOGh0lz8uSdS/ouUYViDMDAv3wA1Yxqydyerq1BBDjIB+h9E3mUFkv8WEINeL2eWp9h/0jRLkQdma0qcep2XUyoG0rvmDezQdu3yK6CNrrU6HgDFFQqv3HZCcLlZRd/Bh2uCTMEDVH3UnO2g== 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=ocfEPaZ4banjtejk19WbObJjp57thUqBh6+DmZsfSUEHOjUZ+m8JvwBL4yy/0Ay/vFXiF4NK68mG2CTqIMjuqEmtqvt2RO+AW7XjJ/1IsdyIOiy2LYzVmSapSdMyA7aNB5uyjxseeMR1gHDyHyWeKO39gQjCSw6o+kgrAdjVHcw7gI3Q1DKmuTERIsBiNzEM/nmaZt51LuKm6PUvLSPqux+mN+f5VkRqndiA2dozCi+O6Gp8D/o082ZuQoI1OPhIFS9QpIDmTHK6tdMKarOQriuK9eWdN3ndu1pjP39CQmnlhP2UZrcX4W3x9y7m5cd3HgJLKaXJS7uiQ+q55Z2YNg== 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 AS2PR08MB8286.eurprd08.prod.outlook.com (2603:10a6:20b:555::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.30; Mon, 17 Oct 2022 07:28: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; Mon, 17 Oct 2022 07:28: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 v5 1/7] qga: Add initial FreeBSD support Date: Mon, 17 Oct 2022 09:28:19 +0200 Message-Id: <20221017072825.72867-2-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221017072825.72867-1-alexander.ivanov@virtuozzo.com> References: <20221017072825.72867-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: FR3P281CA0033.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::12) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR08MB7095:EE_|AS2PR08MB8286:EE_ X-MS-Office365-Filtering-Correlation-Id: 3ab66c2d-dbb5-43c3-f61e-08dab01134cb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: iDfxdOI6U085ABahK262AR9SO6qcjU1j9jWdJkWeLVXWY5qGSP6fyIQuN4RdoTPMtLORw+89q1X56T7HqIxb16w96JZQpBIbDq2P6dAV4y0txwEJzgl01WiLI45OIcDMdifN2uZ1F3sKq1ayw6z/WRFJ9JLE0v/cI3y8pGaM9rN3rCYReHXjHVwFwX+EoMbuwTYAIS8X8FqZOIBucSXl3zlfFuECPy6x/N9uMRTMbbPBGVqJmU+n0lQ6nzqKhFK3TLXBWsAGSp3C+xg8m9wOo1PScwuQMogxzEAB4jwBY4oUYSloq7YaHRtWEc/ZiVqRE6kHouDz6DaicLJkr7ETvATjyCV4uGRLx6C0I7mUjg4FpG/yRxg3Ar0NsfvPndh+4J+o2QSy0eOooU+QDv0NcTA6KIhguNUWVhKxFgRxNGkD+zsIvDiLOVequ3+5nEdOxigvPtEHGon1qmm5o0s//X1f8SzWhyWsTvtRGq6hjD43rboOVk/vOsNxOipfOtbF0mzHeasMkE937JQME2TTigbjw1Foi2ifJEokDMhAcMNEVSdzS0s4kO5GsjlYTOe14OEHHaP1LwoseWb23eqyjLPUZa2NatvmWuyv8JL4kGohYVqsnQaqBC8IbQZ9gWu603bgwg54TatnMuEsEWKkluSd0l1smfI9JeocYpN3jzUuHbLTkH5M+cr1NKRG5PfdUL+JO8Yc8eKjrFqpNwLoR2CweQ2cWEiBeMsfR74bLp9ZzWT2GE1wWLvDpy6nCzfqssHFD0rZkCa9jppa1wUmUg== 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)(136003)(376002)(346002)(39850400004)(396003)(366004)(451199015)(6916009)(66946007)(8676002)(66476007)(6666004)(66556008)(36756003)(6506007)(41300700001)(4326008)(5660300002)(316002)(26005)(6512007)(86362001)(8936002)(83380400001)(2906002)(2616005)(38100700002)(52116002)(186003)(1076003)(38350700002)(478600001)(6486002)(44832011); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?Rmh3XbcoanHBiM1EjbBIc4EbkwF4?= =?utf-8?q?5Pju+ad/fTfGSW7quaEJQ9077EmEkCJoRkz0V3393z8xl9HLsFmsfBr0Hkr8s57Y2?= =?utf-8?q?v5wBpLcrbyKNbe2jZ7iLjbB4T0kU9Xq//L48E2CQWhYwNJH/nezUrE2TPL/AcGHyn?= =?utf-8?q?wt0zcGsetLNGRMocyiOofw8yHBiB8wUlNQ+sB464PevNukgJrFNDqm7BB+COv2DzK?= =?utf-8?q?XfjQHTHmVCSiZdYCXsfigvipbNZDAQKyG86RJcYEHJ5nKZdsahJszY6FKTSRnNAkz?= =?utf-8?q?vUYf330/j0cWEdV3FWslS54TP6dy2s1/+VbM+b5kbWCRMW4gY1Ys9+SNLEkAXRejG?= =?utf-8?q?xISAZHadUJ6Xg36Rogu5FxZ6sMwoTxvCgtZ+hHgS4R6szJh33ABTC6iwoMZ+mv7Ik?= =?utf-8?q?VOSbNFtOtmQh95XTB/YPgVCW/AtysGGMvMfUCx0n7PJ0kxCRXNc0zgUKXk1s/XuaD?= =?utf-8?q?NZ2UaapMGxzl2HTp6VRK4bSTrkZfnIgmzw/qLd2Qqcun+PeYGT63JGq11u8Rjjrnk?= =?utf-8?q?FGP10o4y53bnxXfdxRd6zlHRluSRh4nv2KgH8bVCTOJrxRk8klqdbiPgEpaOTmc4y?= =?utf-8?q?2+5AcrcSgzUb+9WloGD7hzgei/+iCZAa+mtGhQMKDZoJuIlRNO9uvVkLTrlV9Wt4d?= =?utf-8?q?kFVr/ZUIhZCaOFnb+B4+0f2hSePbVCYLA2ugHkc3KtbyBHqGCoTIVqQobDbTkll44?= =?utf-8?q?SKdPlPwZAnt3gTicGajy6cuYDeUnDQAHkiv27UMMDVa9pZBTCpMskMNOkakiBmoZQ?= =?utf-8?q?f2ZSwoEwiNmBkTE/eHrGk2OZQJSP8lTdiaslUwclFtrO7VTEGnyI6zbbTnFOdeave?= =?utf-8?q?nd5yJRWyMZHnUtEd9ER6Wmy7/p8ijEsbsP9d2ygd1jVy2P6urN3mqGR7bccapdSIf?= =?utf-8?q?1CkW45nnNEX/DiO+I+YgkIKBzQyuX9+f6O8QiO4hU5xc0+1fpNc1DJxy9qCiuJmJU?= =?utf-8?q?kSeuysW0t8tM7NHAMvawCyGq3fD7jpXDORmkre0w+MIzVsriIhOOklvgcdSfySyA3?= =?utf-8?q?Zzre1v9aNqWu0FWEPK7gqnMMGQKil3PPjo+60A+9KDJpEGbO9QxhCTpA+GrdcRNNO?= =?utf-8?q?+6/sMx4NdZTnsSgRE70sfkJsN2mjbo2yHB8KDohCZqn0b5yH+dPSbvbG6IF5ZhnyB?= =?utf-8?q?Age4qCCpfiiWf2mgXS9ZhDf3CmcQolGxrZ6oNO9cElkWH9hkx13hrFAjyMuoodQ4b?= =?utf-8?q?YZKbMbFc9D2foNgfHfW87OXikKn6lLtRoerDGF5xekG+IPCJ/KfjpTKUTwkgPkp+D?= =?utf-8?q?JjJkJn8JmqnJ4ZTis0RXaw4oN9TxwbvC7suyXrj9NCblAj7GPCNDzXk5Auy+pGyyX?= =?utf-8?q?tRs0YSFTDAB1LeJLiuaNcSXYxPgGSMbVLevKo5SDyI8Ypaekj39E5UABaiy4TyXyC?= =?utf-8?q?q5IJjogutwBWiDaYY1lp17EvMDId4OaD9ZXo7JrI+FdkWTcwQ5sutvPBnZI5kvizv?= =?utf-8?q?jDdNpboE9TjdR8TorMPmN3PwRSViwetJ7wVMij6JVxIr3yKJRE3GfNHqhOJJ2c0EP?= =?utf-8?q?uLvEotXP/otMVpBHgfg3FZU0ZBM3HzMoXA=3D=3D?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3ab66c2d-dbb5-43c3-f61e-08dab01134cb X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Oct 2022 07:28:37.4310 (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: hsp9yOxFGdz8DU6hCBlbLreHDahoYZaQKxM2S+aGkqJvjPAV/D7OUI6uRMqFwtKTtfj86Ic8rMbA5liyeeSWbiG2zBzaPYuLu6PHGXemuRc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS2PR08MB8286 Received-SPF: pass client-ip=40.107.20.129; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR05-DB8-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 Mon Oct 17 07:28: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: 13008265 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 46522C4332F for ; Mon, 17 Oct 2022 07:45:17 +0000 (UTC) Received: from localhost ([::1]:48150 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1okKoD-0000j5-2D for qemu-devel@archiver.kernel.org; Mon, 17 Oct 2022 03:45:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55868) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okKYn-0004km-64 for qemu-devel@nongnu.org; Mon, 17 Oct 2022 03:29:23 -0400 Received: from mail-db8eur05on2129.outbound.protection.outlook.com ([40.107.20.129]:65301 helo=EUR05-DB8-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 1okKYk-0001Je-F5 for qemu-devel@nongnu.org; Mon, 17 Oct 2022 03:29:16 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UnSc399AaTP6gCXQXwCh25yGCoyE6plmgKOeaaCyCXV0XdmNSMsoGb55PY8TddHmhMDvfQvUu8VAMU7MzVmNkPi7dDV3/JXlP+yErOBNiM+qJi7bzZmmqJlI2Bt1D1jxrGd3/A0ns3AJZ6RD6P/0DZsXVQwKlDtpkZVpH3wFBhuu9LLhm9FuLgSckRzzV9g2/uXEigri7IhDwn+Sf/aY9+YBbaxUrJVUQ4QgV0r/SW4SJA9bCneUvGCXzLcR+nEP4mlgY/n8sb9e+B+glgBkMvCtKim76AAaBUN2++K7nmZ6U37GAaaNeX3E11m28zw0Me+XjVFr8ddwZ/5FHCHjjw== 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=90yaN/ZPijff8/jFBt2y179WRMXRaLZAWtUrg5jzAEg=; b=nOQ0zku9RKC0T3YLIFbrF8Zp7Sz815z0yW9yEdomEr60iKgsnUWRfTzaDRPbBIaqfuF1L6anAzJ+BpuXQDbeGqUY6jnLZzdkU2Sy13RIQALhzxqTeTO52teKgiIPKLUWKs9gn8flnBggooDCyHvBKX7ouMbk1u5EiQwzgL3OBbalRdNCSkuA1Gd8YvFEnLqn68ScpLc9DLhU937e6mvH2DBDB7M0jorLyR1R++sKRYV612QH9t+BPmUETTq9fVbOuj8hi4nPi5AqABlu+vfiCotfO/CN9LW/xjTU9bsGFWzsLC8sZL7lX+qZr7Ft1XxAfru3p3IA/ySD24+uGPg/IQ== 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=90yaN/ZPijff8/jFBt2y179WRMXRaLZAWtUrg5jzAEg=; b=sMDKwIzdAvgXlcmKHnCQPzF8c/R/PmZCiNjChIsKZh/OnIPvB0jSNTL4r4kFEaq+m+VIAQz5TYeGkS3Dr+hXQoZdxzYtUotzbsq5ushCeJbYYyz9aevlKm0hloLI/rv6nGb0kCNTHbPjiq2agDV9abtzUBKSnbavLqrZLvvk49CnoPrSD01pMUGyrO6FLrHipaye9MMVPLHof2Ei74ZU3piH+9FeVyXCcdrHfVdhl8FQDRAdS7oDQ+HTbX7OGFvfCvnwSDGt09C6dqeyyrZ4q3/ghcfvCgmHUisa4TlYucYnOoAj28d2XIML3fCwk9sVAIGWrmEJASz1zil5vc+nNw== 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 AS2PR08MB8286.eurprd08.prod.outlook.com (2603:10a6:20b:555::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.30; Mon, 17 Oct 2022 07:28: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; Mon, 17 Oct 2022 07:28: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 v5 2/7] qga: Move Linux-specific FS freeze/thaw code to a separate file Date: Mon, 17 Oct 2022 09:28:20 +0200 Message-Id: <20221017072825.72867-3-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221017072825.72867-1-alexander.ivanov@virtuozzo.com> References: <20221017072825.72867-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: FR3P281CA0033.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::12) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR08MB7095:EE_|AS2PR08MB8286:EE_ X-MS-Office365-Filtering-Correlation-Id: 8ab22149-e855-43c9-8b4c-08dab0113526 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EZnxSaxHjIKTUp9ky9pW52pJsYKA2rU5KnSGTtbODUJRzcBCL+De3eHFqb/Lm2SVNJ95/TK15kmwcegZoUGosICrFOba8VtKn98RcGtUwm4I7bXBhwMBNeClvmro8JNBXhWENePFY+bOL3PhTkmavAVjvHWCcFREZqVBgU8jfSeI9FEvSBawADVnY7kq9pI0zY2I+rn7dGUzSnRNKb2tGt+zOkuZ9cmmqSfV0D4TYxbGo9WceWXinYiwQ/Olzo+2w0ADgcsxiTfqJKBHTN0MKHNs8vyWl60EVJ3xdiXkJ6pCTq2D5fJ7vQNIiVewoU913Nt93UBi42+KY1HNm81ihm1Noq9FRcMWNkfcdSFt0icP9FkuMSlgTvxj6nD9PDRhuNCeF55q+VSNc9mu7Vna7Iugqwq8GtW0AgxIn80tJT6WYs0NGYD94uV9CCIQrounITPBqnxS4smz2oV9zOa0zdOLF1xEegsf0vUsTlJ0z2oged3xzRfJ6EEn4lFZdDZiCROYyY5A7nP0K7MOlxl+J0bxGOzIVqU6mV0gmKnPe9fwfBRtM8jV+3gqbcfSxrVFYzwu4hr4l4KRxDZ1mEmgI4JBSsIoV1kMuECP9iMz4BU4wLksx9+9CvYWPQp8cmGWliUumOoTiglsIuG6Tb6CHQ1avJoZ56/B7JFWCYff6niLrc4fKvCwU1dki6P0WVCatWIgK/6FB/glUJTtir2e/eI6XInUPdszHPiRDFimHJXx6DFzaqxaDwxl5lbDvLW+gV1F+z/BhKZZC2VEhdcDjw== 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)(136003)(376002)(346002)(39850400004)(396003)(366004)(451199015)(30864003)(6916009)(66946007)(8676002)(66476007)(6666004)(66556008)(36756003)(6506007)(41300700001)(4326008)(5660300002)(316002)(26005)(6512007)(86362001)(8936002)(83380400001)(2906002)(2616005)(38100700002)(52116002)(186003)(1076003)(38350700002)(478600001)(6486002)(44832011); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?D1YVs9oI1AxqWwyAugCdbCJC9xfh?= =?utf-8?q?XrWl8KRaiEm4vPJ8n3AO/imGROQbFVPPpR3+SjCL+VDdkzV1lt1PsrRPgSme+j14C?= =?utf-8?q?3HlTzQSWOREI/8So5+ERmHgrjXF7zL1qqxFWQfjKVSkAo07LljPNeCERGMvI9y8Ex?= =?utf-8?q?zMhKibhyreD1ZxzppC0LO1dH7IZCEfqpNiORPDBEFDf+TyD7Z92+tGzQUEcXIFZ3N?= =?utf-8?q?lZbH79QJ7hwiU/ZeubVkePc47cogrh9oYHXGgsuKWJReg78tPLuljggKXtCQEr/sx?= =?utf-8?q?cUHM9CDUkCb6VnmQ6M53hLn3+iU9YiaFdaTs4DPrIhl6/TqkjB0SMevKJArZB+8gI?= =?utf-8?q?Iqv+Nh3z331U3bAUGeQmDO2+rvB5UWdGU5JzB1TQ3Tq2J5/TTSZoZNC3ojn/Qvoue?= =?utf-8?q?94lSzcbwixCg2+CwWdDXH2heKdvewnVzY8Wt4BDS7E6m58u2uwm00eXjcqpX7aZlJ?= =?utf-8?q?qWJd5IT6LlmRilQy10k3bPtLSS62pwzVABW717/hbXCC3Zlfz+s2YEgdjgZrzAtsB?= =?utf-8?q?pEHs8Nc/pG6S7am+dP7M5hKV6fgBgVr4KsLVQr9qGOQKLWNuYHsI2CT5hvNiYICHR?= =?utf-8?q?BJ2Id+Wgr/WcP9I2A7VSyyIV2a+mQOLSgC9xcU2yU7blJ61QnRx+RoZgWJBhySHXH?= =?utf-8?q?43gVjAB9pYaC8bCA2gnDgDu+/W33XjdaDhj/W/lInE74/22jX8Qe9MswB5XmjYhDu?= =?utf-8?q?0ZKElfWuETVQpQ2BXCsSyfvZ4GqXv6lNi5bnntK/gh5SEND8O2674MQIfHzCJPLSh?= =?utf-8?q?hiSgkZDG1ExagWj1uNvBMTl46ifiEsP8SZRSp70npr3B1uvne6Rqvca8vszZm8BNC?= =?utf-8?q?+gO5+5bgHyQeOX7Kuv4KxgQ++hcW15aEMQfOd9AY1CyVdYugNBf5jGJRODcsEcFCP?= =?utf-8?q?Id/VnPlravGioGb6Dy95/eBF5ujzS/WBHM3rVvvh0SblSjNWx4NCqdtEFi+YEzUzN?= =?utf-8?q?3dYZykA4nZD7REZMNOXVKIF+KA1zDhvT0Ih7L+3tAD1sUfIIRqNw8/aOjKpNce8GZ?= =?utf-8?q?ePicPzAuO4z8r/M/oCuUx+5Qr1gojbgxyYtwpSCMooCJKcd3Q46JyJplmW/FmM9St?= =?utf-8?q?QCM1Gri1A8mV7Pj5eU9BBb25zLK6M9sieWyaPeLCBwoX90gcYnxQBzim/zu1JUEW1?= =?utf-8?q?Dm/OVNCGGoO0xeWhNOJ3MdBM8fbZtaIV/aD4qqFLV2P3ng61HMJfBNgDT8sC4M1xP?= =?utf-8?q?e3QHbg5T+P3+PYARm2X6PH7YoI9Qbph3EalOoqiSvBa+pLZT2avWj3GsVBDlHUBNT?= =?utf-8?q?xNs0CiY5+ZnsZ3V9KCMqrExqD0txyacRkMQmT0FY7KcBqjASlaRe4tnlrdshQ1rDQ?= =?utf-8?q?CMcmJYxSQR3uJ6eKe7cs2caWFVLIBQPepqoYtovVX+AINzgHyD8dOqIG8OeaMkDHL?= =?utf-8?q?EP9ugBqWaRfbHBdZXELkzOXmHCTfjtP99B/mTEB7viDiXWPoabZFLJkoq4E8Wxx/7?= =?utf-8?q?8DuoMATQ/73J1yHQZvjspu70VrAnOxWrzEThMgrQynWoP/On8FbxgDblJaHglaBDk?= =?utf-8?q?ciOiT7jTHJWJpc38cbN+3O4lI2X9YIv+CA=3D=3D?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8ab22149-e855-43c9-8b4c-08dab0113526 X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Oct 2022 07:28:38.0716 (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: 6LWIRYraY8sJ0sOhEfL8v1RzY1u+dFUSczK0YonltkSUJMAYNKyhNxVtRD998X0eaIKj6nuYUogV/zPl3jo3OMPj6LKnWNrmEeAXgFJBkIY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS2PR08MB8286 Received-SPF: pass client-ip=40.107.20.129; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR05-DB8-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 | 34 +++++ qga/commands-linux.c | 286 +++++++++++++++++++++++++++++++++++++++++ qga/commands-posix.c | 287 +++--------------------------------------- qga/meson.build | 3 + 4 files changed, 338 insertions(+), 272 deletions(-) create mode 100644 qga/commands-linux.c diff --git a/qga/commands-common.h b/qga/commands-common.h index d0e4a9696f..cb51b1c6e9 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; 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..d24f2fafd8 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" @@ -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 Mon Oct 17 07:28: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: 13008270 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 74B45C4332F for ; Mon, 17 Oct 2022 07:47:38 +0000 (UTC) Received: from localhost ([::1]:56566 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1okKqT-0003Bz-Ik for qemu-devel@archiver.kernel.org; Mon, 17 Oct 2022 03:47:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59440) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okKd9-00086W-V2 for qemu-devel@nongnu.org; Mon, 17 Oct 2022 03:33:53 -0400 Received: from mail-vi1eur04on071a.outbound.protection.outlook.com ([2a01:111:f400:fe0e::71a]:42753 helo=EUR04-VI1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okKd5-00029p-VR for qemu-devel@nongnu.org; Mon, 17 Oct 2022 03:33:47 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=T0bJcEu7fenr1PFmvRixefOZdt713xyXMWbq1rGJ9g7B64WaCIRSqHfS+oUI11enyNs19SAtdtJ2wkepmeHAbUUq2vCbdl+Nzt8PwE+GFImG2U1K/JmU+AmB3sOitpeGFRakX2lN9rHwpK2VvlwO12sqysfz5VP5oj3lAUpnnnw9WtN1nobtF1weTudB1T08LjhCBM4A2tr0jVUYot8+Rh0Qu15S3VvGEXL6W7SsJfjRIIjpzkk8CwaQgnjWF/hQgx+OyH20jJ3KmlYJqiLLh71PtRZjgRReRZFOBfZkOGct53zQOrUHDX1KthtzYJULoMpKIHURBWmXHdOkbMbC8A== 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=ntgPPnTOKgxTnF+LfBEBgtehlf04PvP6KLfYZLNlrmc=; b=Lx+aoK8jvypmnQEiJUshjt++yUNCcmB04upzBfJQUFmPzX7tfL+XMN4JdYgo2HgtQ59aTFjMd2zEpzPJqHiblotl1AohKnvA93XYQcdpC4TnTe/pqpAHgfgZVKrclhQEo2JuUtIBG4EW1a91tOF2OkJPDSwAg7CH/RoLqTcQGrlASs3NJ9tEbHEBWT/8frGi5I5zVqkalT2F91ULGb3RdZLZ2Dxe7T24mKRmsxpLhhzfuukhO7Jmogg0Fk2qO2jcEyq1ANdBLr2QM0ZZ/m4jmZnEqRRdsiX9+WK4aQ01B2EWSL1IA8KcAuNeGCmDMbOvDF0KR6iAQCQfh/oKuP42RQ== 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=ntgPPnTOKgxTnF+LfBEBgtehlf04PvP6KLfYZLNlrmc=; b=rqu4JVrcl/Oxz1xLAa4MECrxLaoCKq3vLK+WwvuIb7nb7wwgLA5y2K9bm8Vi71+kydCZNuKyWF6sy2iOFHKce+kJ39Rt4sF01/KxOHpeijFQU1nW8ENZqmMEAxBQCb3KLSKmEhwaQIlrhpP9oQBlkUuUalV73peF2W0BWgJB+exkbF6ZXMAQJ2OX+Su/pHwEM8+FM+a3Pk1FAmLd4ayqqOOcthxPzU+rW21vHS3SjgvyfKjft6eHpYTdoWyi/Tl39Y5xWOD2/CWtr927ZmKJ0edMsrjjYy7PHTTPvx1VFtMqtpPwpKDJw6rqWOgtrGHCuwQeAUPHIgMAmUEQIff/Tg== 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 AS8PR08MB6710.eurprd08.prod.outlook.com (2603:10a6:20b:397::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.29; Mon, 17 Oct 2022 07:28: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; Mon, 17 Oct 2022 07:28: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 v5 3/7] qga: Add UFS freeze/thaw support for FreeBSD Date: Mon, 17 Oct 2022 09:28:21 +0200 Message-Id: <20221017072825.72867-4-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221017072825.72867-1-alexander.ivanov@virtuozzo.com> References: <20221017072825.72867-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: FR3P281CA0033.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::12) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR08MB7095:EE_|AS8PR08MB6710:EE_ X-MS-Office365-Filtering-Correlation-Id: 39236878-a793-4c63-4737-08dab0113588 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bolLiR5ECIH4wVyhxVAK3e4M7QG6jWdUXel+LA1MTfYt4/riZJ1P3pMdc19UppWKTLqc0J40jvc2dRat4bPveQZTQvLNFu9d/TlwbI7f8N/5GNHHkVkMOlQEVpyKzk/OJXjQB5e6L1TF6XZ9yifqPwX6ke1AxnRSFMC8kev3ZJsARLYKEsfFtUwjED7+E1g1x8/sqlgCu7kHdT7t8HOyJBdQ8Uu3uCqcvh6VU/xDPk3hdjIqI6KbtvBNJM5JJADqPJvk+qgDamKz4yMvNJObpvbdoFHWo2SWJE/2BQ5m4Z8rQok0ScD6fNYfGONRKHlrMgNoriA35gO287dSVkE56/gEcljS4rf2MJF5f1gtG3a7diznmBS010nBwf4XwbD7mN4TKUsS8ZPoqtBc4SrhrMUjh9yNG6cUJvFeFAjI0ka2yGzutjjhgfTyj2hauPasV4LofjpZxWr2lToR+Ibfq74ZYxTvzZEJ9hURZnw4wAXm1ArX8TxiIDf9+lCvyi60X1R4E0Pu4suQyvfmL/MhaMKZhAuUy6ccTHK5SBUD2mBCSAhO97v3LNvdpiUe1sTuX9HFf8lHaHMyDenJ4ZF/ps2VOc0h480NKEBJHjJ4xHGnPnSaTKr/Rodn5zNZejj/CUayVpPrCCk6Xzi6LeLJ+kIZOz3HAGSyxHWmjFPc8KDU3+BR1hsCPDCvUXbsxDSEVyOKobKbVre0EuA+5TUMbjHQQPiBZ/aK2AK79lFlpcfqClZitS/HAzrSvtCFJK+9GntrcjChhryJo3HQej1QWw== 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)(346002)(376002)(396003)(39850400004)(136003)(366004)(451199015)(316002)(2906002)(1076003)(186003)(83380400001)(86362001)(36756003)(38350700002)(38100700002)(6486002)(478600001)(6916009)(41300700001)(52116002)(44832011)(6506007)(8936002)(2616005)(5660300002)(26005)(30864003)(66476007)(6512007)(66946007)(4326008)(66556008)(8676002)(6666004); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?kq6rQACcL2ybeNbXleLVNX7Nlttw?= =?utf-8?q?fLp1Vf7IpgdPdVy6T6y84IhVWzHg7guEoSKIjErr1W6htLeMKozqX7qiYApHaHbQr?= =?utf-8?q?fjgb/+mLbdR8LHloF6MJAmFISfKVevjk3c0PxA9Dn1dpocJk42JSSNUGh8jXgZWJh?= =?utf-8?q?IUAcvBIRzE/FLsIWyxymDLcif4nHWEfQSizBKqarb5RsOy9GTFbMkI8TeRYv6B/zz?= =?utf-8?q?fbHnQ94kv2Sc3c76pYQGefbzTxQ2v6AjCKnSTf6HVaIczi3ZTbqiKj3zIpPt4wihL?= =?utf-8?q?qtvo5RhlSMwAiDvp4P5Y100vPJEFMwqkicR02lmzaoKtmUzAaP5ZuvoFwPpGOJIly?= =?utf-8?q?6KqWIElaJfvZfOj5NXOgOk10j+wW0I5ATMYvhtZKAYDIPyd6w7bNbHM5LtFtgVxoR?= =?utf-8?q?mDkwW5o8j3wPPwSHRHoc2rawp5RfiJ1hn8sfZ0syPVUN2ew9hIOuJn8Np4T38VUcG?= =?utf-8?q?6AIN9gHtuGCjNxa2f7JA4AC/QJx66rfHtLidawKtrUWArWKCdR2o2cZYEcUaM23sX?= =?utf-8?q?iLVmn2TUt6CBLipl8ZQVR309OozA7fmeg1tYLlVW5oj7UmWEiJH3UcGLZgp5MyQvU?= =?utf-8?q?how30Be4Eje68Db0g1E//d7LAVWCpR7/BwGyNh2UdjcF9Qfi0QCtZwW2eXgSeN1sE?= =?utf-8?q?iHdPNXwPuz+mM6H13Q47JoAK+jFSQvWGjveWXXrfljA1oe2Litz2IstY6mS4fXNWN?= =?utf-8?q?6gHggPB0IF1wxfnpQQipbXJsD4OkV0rbaGagQUiCS8H7yEEYwLPzFFI+FIOWzFstb?= =?utf-8?q?rmzFfHhaXTPsYiZQMKZDKBq3PA9+6+06zdITV9PKk4cr0Xt/McW4wYSTvbA0srtC+?= =?utf-8?q?uODp67xRyaxmztKkKp1I0PD4v/wuRjs+/GnZGa34FHdQWCGZRU8nlsrLvjy7M1lSI?= =?utf-8?q?xWU5547+p2CcFfh1T/PcHrBH8VzIoYhBnw7g9jkLEsGJN8c7fM1O0MxxRLV/5IeHz?= =?utf-8?q?d8XGKIDOgH6EUEFipp4BHw88jyXa48iLekBYB/2F7vPJZvgLVkYXH77yT7jlSorpz?= =?utf-8?q?Wfjr5TLf/69zQYlRGhjGHUlHpqTxWUl7OEX/6aaavm/lfcMZOxHaSpoWv9ZdXDtbJ?= =?utf-8?q?7oM37oDSqgnzMeLkPpDYk611XoyjjJ+TvuPoe5EX3VDhFoEr5H83EKqgGS+hB3AJ7?= =?utf-8?q?dTp1/ItVTN3VdRyBefM2DbRhjVmeda+7IPy5HsbZG+UNLQx2VtZUdlAXK7gyxrqUd?= =?utf-8?q?dsQMAZwPkuYHEMBDA5X6+jR9Z4D/Az08HTGaIYp7d66rTpYh6lkNrc0corUhFEUeD?= =?utf-8?q?Ud6rJYZ0vPtctgog8AGOusyhGgF2onxzGFvh9pOEBo+9EnVWG9RohY9CTYPyyVgYG?= =?utf-8?q?jOTSpGYUauLHWEKBtfJu5rWBxVmqDz0beEbUBrFEHqDhv3/0nDkOgjaCAgX/Tvde3?= =?utf-8?q?zBCmTJGRsNfP3vYeNG9V+O8nN7kmvnimVH6TZ9rsS4Jd29n/6p9neHqDxTYPCSQWs?= =?utf-8?q?w7ojp+zUoEREUM8xJ+wJQPrBr3Y2gwfv3B2LZmG98xxFPFHanAW4Q2H1TwAxFgUCE?= =?utf-8?q?coyY5R5fCxWSzd4X9ed2SCr++/gzIoiULg=3D=3D?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 39236878-a793-4c63-4737-08dab0113588 X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Oct 2022 07:28:38.7121 (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: q7CHP29i89bXR3yFn/aU94WiYXOyDQVxpiUXpBm0xeS/AHD7z94XsUbhswMfZZjx+0bNeB3wVITpBv/a+OFH6kBRr6YEhKuHus+QSbLOApI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB6710 Received-SPF: pass client-ip=2a01:111:f400:fe0e::71a; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR04-VI1-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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 cb51b1c6e9..d0583c6ddb 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 d24f2fafd8..6875ea8888 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 Mon Oct 17 07:28: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: 13008278 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 A06DAC4332F for ; Mon, 17 Oct 2022 07:52:29 +0000 (UTC) Received: from localhost ([::1]:56350 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1okKvD-0002bm-OA for qemu-devel@archiver.kernel.org; Mon, 17 Oct 2022 03:52:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59436) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okKd9-00086R-Rw for qemu-devel@nongnu.org; Mon, 17 Oct 2022 03:33:53 -0400 Received: from mail-am6eur05on20730.outbound.protection.outlook.com ([2a01:111:f400:7e1b::730]:31873 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 1okKd5-00029q-UV for qemu-devel@nongnu.org; Mon, 17 Oct 2022 03:33:46 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=e+lYg+RzLLWnE+rA4BPKtG70qaHedPtwXJlM/czz5XHxfJZ3t2osazhgAU1a3X8KXKj79N6LyBD0FpyTTcPt3PcAZTb4Y8gVcdbeSv+0jrDUN9WgnG7xMdboZkKlGiNxeXWvEOeRFxZIFo+y8rh/9g0Hp+svhT4yNvXiDOyYhdNyFJbmHJXXnu3/aoA/bKK8W2GmcC3CNrdYf8VAczeD5PGpZxO16JnR0BhjGvI+vE44JDEG+O3MBeCoD6fZ+RbtdWApexr/L+dqDyHAxyKHFbT7ATx0vBkmOW1VbVLJnoufG8coEFQxPwS/GGeGzHtlHC8chtduPk0Wzr7E+PQFuQ== 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=ku6Djti0TjfMuEVA+aLc+awmoKymOD59H9ccnlZTYRM=; b=Dc52DeNTD/fhNjz6YAhXpX2vOfFVXEvO2vznkLiekU/8iR7aUrSrFl/KyJ5SnJG6UGUJPUyUMbyvdMDlSO1+qUQRa3MPtKo8vCEdzHDVDpX/lhJwddybQFK2LblwmW+jwjqDhCK+67xiS/Uz/7sv+/RTOcN6IhABd3V+PJXQ+IvnBCTohNaOdMzgr4+EUdV952bZIAVCJhuKMBkQwC9Zl5BXtWNF4SpZT2InXVairyoiYOrrj6aTi8fVtPOLc3NfU8RF55Elwm3L0RjH3AzvAZd0sa3fzhFy9RfQwcxp7FUu+C/xQNGalx9kk4qFFkC5fjJsguSfdzcy5T56o6bq+g== 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=ku6Djti0TjfMuEVA+aLc+awmoKymOD59H9ccnlZTYRM=; b=c9WPAy2R8y/oo2Ab+AB2ijjVqTlBmpNak3jOoccUU9eSMJRKQNjohvkVaHcRRI3NbZb96nJmXfIkRRXE7d1DDw0fijodPQguapiYQCQJfZWDTNRXVQI2jmo80oRM5kll0X628FxSOKYAxa6b4+MuNWVKceYHiQTJnGRCBvKjKhmACpWq97h3nzx3l4fS+TGmF0m6nwL93Yxvzfsv3XL60uHkLsVUukHpu0WljSIhcsbS4pfsptZXZaiNuPfr2XV86+VL0IrVD1IFEOhTgYWXzDDwIcGdUCZy2no6nKz3yYK8un2yYg5LQK+sdhZ/ovoNcPrDJa/w+LoZ++BZDMTFTA== 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 PA4PR08MB7458.eurprd08.prod.outlook.com (2603:10a6:102:2a5::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.29; Mon, 17 Oct 2022 07:28: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; Mon, 17 Oct 2022 07:28: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 v5 4/7] qga: Add shutdown/halt/reboot support for FreeBSD Date: Mon, 17 Oct 2022 09:28:22 +0200 Message-Id: <20221017072825.72867-5-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221017072825.72867-1-alexander.ivanov@virtuozzo.com> References: <20221017072825.72867-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: FR3P281CA0033.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::12) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR08MB7095:EE_|PA4PR08MB7458:EE_ X-MS-Office365-Filtering-Correlation-Id: d9998b73-0480-4495-d486-08dab01135e7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /ny8pDCgdFjOBlXqh9cgTB7810WPMP5n6pq65uQ0uCAgKuc31RflXYtYHRkyoao6bfOyyEfMHaBoBZh3voeJSkfErJK5xSxI8kX/t0pXyJwKmLyVDAntt1vNmZoxtyJ0bRUwzy1vM08c0uFqcdz2lgh6IJ1fSUAralfOLNeDu5SRAtH4CS/8N/y/wbOTTK+U6RiK+MQCuZa8JlSDf9KkfW/WZKGvjDSDDDdJGwqiXtk3KPCn++HRIYy/qr8iaa18TV6V0TuKANJjsRD5I9eXC9g/hVNwS1jgfvXmD1hrxlSjdwSgfsdWNn4buYpGXqDducE1YsRPE1a74w9QVmqV91Emy2n3com6yj8v99vqJrKDVSccm71eY1P9MenM730mM/Juw4UH3QHTryGZZTDZi8IP3W0rJFRJEv+s+vsrR+BfSkM8cQfPHU/mW2AMvILHPxHQCQgm/5X/0OMP6qNqWpgCEjvPLgFuBRcmYwa8KraxuMw4NipM/LnNj6zYkWFQT5rPdFaC70zIAMCV4VSBM2HAQj7+zPPKRBfGh4Lw6beOAWMoiAQluSJT+KBdvLOcV/Uvjo62YMHL9tuNU7McDShjTNRrWxkyzLOxBiYCPAY3M3tqjhzAwAEjDwU/nHpwjkCQv7UKYBR2wQ40QAMd0O7xc5H/dHaRrE5stJfz13wAz0ETVcAOOHuZ3BG0LhiJbyb/C0SEinkPO6zIvyrp2tdyRIve2UZNLHEvXX+NISHBKYk/Q8vBPCY0MIKFIfFvOkeLygz4HzC/aQRHTSuX5g== 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)(396003)(39850400004)(346002)(136003)(366004)(376002)(451199015)(36756003)(86362001)(38100700002)(38350700002)(1076003)(186003)(2906002)(5660300002)(44832011)(6506007)(6666004)(26005)(6512007)(2616005)(478600001)(52116002)(6486002)(316002)(6916009)(66946007)(66556008)(8676002)(4326008)(66476007)(41300700001)(8936002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?Q+GIEpuMNmb6bnsL2ZOXuzLcASLe?= =?utf-8?q?5nAH5UDBNCthqH3XBgy8CqpzrIjt3+ofYlYeyAyL0ltWCDSbqdRivtvpef2h7s97O?= =?utf-8?q?o6voszCWTmR86vO+mlmqySjEZ25E52YwNNSvNy0y0o6E6Z9mZtke20nOL6hUqNDJ/?= =?utf-8?q?FrxfN+JA+Xig2BFz0n1gdAbr1yhSrj/eAAMfqTSydDIWIN8fwNjSeU2OTf2rdBIWQ?= =?utf-8?q?/4yJNx/Gad5qLS9gHqhZ/Qh98VawdyP4guXPAUacj7hWemtFGgsW4lvS2SXAcNiuW?= =?utf-8?q?rY9ZshtqH5RFfBG4Hg5SeNRN2J+fCSM3F5/9OCN4i68gcY9y1EivEP7dhtXa7Cngd?= =?utf-8?q?bv5T9VWQHCQMf9ekwlwmpfcnmpkP+zBXmBybJKrQm79Yh/3f+aFi0dF0c6Gmm7wKa?= =?utf-8?q?eT6I9f9HEy8rrgmVxgmUWOFd949xZ7p3e00GuvAkWYh4ktrye1/nqE8uDkfo0cP4S?= =?utf-8?q?14WHncv88oL1fFQ2BOZ98P1Vg/AH/b6axYCQKFV0szyc+arq/LFeupEVfv9u147RR?= =?utf-8?q?ERzrXVjXSZTj/6CYRt74QZhq9RYCRtWaTm1a7/BPMBkqf8ZG0RPI7636j2ka6s5NZ?= =?utf-8?q?Q+raL4u+MDqv5qN8rzXBiSwWOdLsCPC4cUWraIY+YDMqOYp+3+6wkfEblrkNvsian?= =?utf-8?q?t2rYbKtZ67K8kWL4HQBxv6vbC57nWZd7vL0//h5p/OL+GYXz8PUmjWa5PoYAx5hSx?= =?utf-8?q?IaLz6SL9M7A330n3plL4ODGY17+FqX/YKqYajWnqhKFuf2wcs60or0nroS2RprUA6?= =?utf-8?q?P4t0L9b0PVfMQEDX61r33GmArjulqqCsLTa6fK4PGwLju/IkMf80mG/vZKTGvmLBo?= =?utf-8?q?hQIrah6f2BBm6A9xshdW3S0Gi3RGBvoMfl8ybDYBCq4nsqHb9s1Lzv7GQonYZiA4y?= =?utf-8?q?h8xn3sZU13ibK0H8lv/rJJnX9jlky3WBAp6IbGtLY2CwUd715ykpDIWXzqMEBinAR?= =?utf-8?q?mC/Bz52uY3zraV6/0J++msf5q3zWB4chinM6Q2oxoaLnOApD0HakhozKLXrHkU0zP?= =?utf-8?q?Sv8LER3XX6PWRZjQHqp8DuMkD+DKJbSC7d0REkqgxBEMtPvCuW1I9usKKZ7BLbCKS?= =?utf-8?q?NJM4Dp+aON/HoziCNTu0MEBL5eIxAsuqrRiZyuhZLyfTQet29m5VmHfPE9BTWuel0?= =?utf-8?q?gRcOKyh/pzxVA4yeKXIZxc+eJQFWwRJE6/b077vo6/1MP18gdrxPmU4yWCDGp0ap9?= =?utf-8?q?egLwhAgn231gHje3nXbPm0iLthDMkwJvEUJmOzxlCI879EuzkBNJdVo1xGbDNLRnl?= =?utf-8?q?U5m0WmyGdOklGxde6hWF8FEtzGil/UTRWpI8Lw8CVbSbceCSp8juaefDmDBN+5Jxl?= =?utf-8?q?GKAeqW1z9bDpTW45W6DQ8JFZOMbp/aNgneJ0alwPgM78+jPWgoiu+XCVVnUq7B6Ap?= =?utf-8?q?Ld4X+MKn9uuh8X164EQOzOGmdy/p4q7a9lg04IL4Zy6l3gi6EE7M5gttE3oAMBN/2?= =?utf-8?q?HocDlwFi9vigHqYTo8VBXHROJRYM4FkT0SMFQQUFOdzwjf60gMH3kdHYB6UxX+gAi?= =?utf-8?q?Pzemy5qjZbGIY+RCdcAp6ZlUjuryJcNBxw=3D=3D?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: d9998b73-0480-4495-d486-08dab01135e7 X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Oct 2022 07:28:39.3226 (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: lEFdauscYJAfGREOHyqqV2BptKqcbf7uuXH893blhw2gjANXEJPk5HXSlRClfQTJGlcnucXeKUceHh3DKICfHKp3mn9pE001av4mSeUgw98= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR08MB7458 Received-SPF: pass client-ip=2a01:111:f400:7e1b::730; 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, RCVD_IN_DNSWL_NONE=-0.0001, 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 6875ea8888..b0b467ebdb 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -90,6 +90,10 @@ void qmp_guest_shutdown(bool has_mode, const char *mode, Error **errp) const char *powerdown_flag = "-i5"; const char *halt_flag = "-i0"; const char *reboot_flag = "-i6"; +#elif defined(CONFIG_BSD) + const char *powerdown_flag = "-p"; + const char *halt_flag = "-h"; + const char *reboot_flag = "-r"; #else const char *powerdown_flag = "-P"; const char *halt_flag = "-H"; @@ -120,6 +124,9 @@ void qmp_guest_shutdown(bool has_mode, const char *mode, Error **errp) #ifdef CONFIG_SOLARIS execl("/sbin/shutdown", "shutdown", shutdown_flag, "-g0", "-y", "hypervisor initiated shutdown", (char *)NULL); +#elif defined(CONFIG_BSD) + execl("/sbin/shutdown", "shutdown", shutdown_flag, "+0", + "hypervisor initiated shutdown", (char *)NULL); #else execl("/sbin/shutdown", "shutdown", "-h", shutdown_flag, "+0", "hypervisor initiated shutdown", (char *)NULL); From patchwork Mon Oct 17 07:28: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: 13008262 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 C597BC4332F for ; Mon, 17 Oct 2022 07:44:15 +0000 (UTC) Received: from localhost ([::1]:53074 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1okKnG-0008Sx-HD for qemu-devel@archiver.kernel.org; Mon, 17 Oct 2022 03:44:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40870) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okKYU-0004PH-Ng for qemu-devel@nongnu.org; Mon, 17 Oct 2022 03:28:58 -0400 Received: from mail-eopbgr00109.outbound.protection.outlook.com ([40.107.0.109]:35648 helo=EUR02-AM5-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 1okKYF-0001HN-G3 for qemu-devel@nongnu.org; Mon, 17 Oct 2022 03:28:56 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fKA+Lh9N1OFLSPHGyxRjo7EJnSTwhrgijvr4ErqukTzih4vDRbvsdN1RLW6lQ9CUfGvI8nH2MC1qvjO3hRaVhtH9OhQocKiXvxRFFC3zTUhjaS0qWN6FhTX+GfbO0VqxYUNO63Grc3kf59iiXGOW0b1JDbhGG5krK69yjjtpyYVZDZ+k5w5s2xboXQcRA/Tf3sPBC3UN3CIInvrCE/wwYMT5NzIzeGW78yuJqSBQ0U+yl3CcAjckxtQOj62HXp89+RCVVlODU9iutSKR53WqIXc0RgnqDEHytfQLqVIyo3c6KIH+2/zl537rJSUFjYrGDlfElOAJAzV2rrID0aWcLg== 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=2Q3/Bc7F321/DYdYUKBzwEL+ZcqV9hd6HNm5kUp3zdI=; b=YDHMkDh+sr60b5+z/4rr04wMKnjVA/4V2CxUcl1PGLCQ78jG81sL/7ToNsxug97bBAleM4GSyf1sKtIRsnudGE2Ny2yD2epMX1g4Bob/1ffxdb1W17fsYngoNdjDiCA2ObCD9cCgDoIOPl9HGNaPY6TmAdY5Iv4tQ5Z6/OZArLEctnrIlHX4M5R0fDMcrXCpWovLripONuz+hXQMLHv5eF9YYA7Wlat6MvnMsC674vWK2ILpb66Rdocrmm93BmljaSePxwG757MlFwM91u4eG5O7ik0Uk3FuH739mC48oZAScvS7FXERI+M6vCl5nbG0bFQpBOUlmQ2eKbDVxb70+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=2Q3/Bc7F321/DYdYUKBzwEL+ZcqV9hd6HNm5kUp3zdI=; b=uRs+IX8Z7KcKjmZVT062E4v3ZO2QbX25EVmWStIiLak6XiIzLrLsLXEB9EgrFPbTDsH3K6Mh5hZSQ1tkjITIHZGhklMtxcmIfJbX4/QMsfD7G937tGnFg6Dv4H3PaNeXVrrHYDIveRFmJaGqjoMcdwUUoQQfGYpbXsC7Hk25CWfywt42t6Z8smF2vS6R7YLl0OCxHCM2Bxt+Iz8gZvV/oan5mvcDoD5k61aN8c+WMoLx1mZHVr+j6ERXamHC+5oAJqxK8/NhIcUehxuvkFXXcW9EPJLddmQ7lqPqWSw0OjIYGPpDpDnZkRjtmErDjQpYfgE1slksw/YeGYK79ZAD8w== 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 GV2PR08MB8653.eurprd08.prod.outlook.com (2603:10a6:150:b9::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.26; Mon, 17 Oct 2022 07:28: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; Mon, 17 Oct 2022 07:28: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 v5 5/7] qga: Add support for user password setting in FreeBSD Date: Mon, 17 Oct 2022 09:28:23 +0200 Message-Id: <20221017072825.72867-6-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221017072825.72867-1-alexander.ivanov@virtuozzo.com> References: <20221017072825.72867-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: FR3P281CA0033.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::12) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR08MB7095:EE_|GV2PR08MB8653:EE_ X-MS-Office365-Filtering-Correlation-Id: e086770f-661f-46b5-2e23-08dab0113647 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: L1AVdaJ8WrlHM/wh5iEVPouJCQQ/OuUTNEE7jDHcLtWdDQOMolzcV64r7b9k+INiWmMijWXJo1qm2Sg8SsijXfvQpo6TPicKrhtdQSRY6JAY7xZolgIeGLv6CyAd0YnctrD3BQafL03Bu6qF01Z25v5dmHJDhhbznT1lW+44x2pYDDPCxX2OzIv/sY+3c4ELvSFOUR8QKF0R57wbj+CccIGRZ/5U7Q/4q6ePjXcm11sPSrzCYsa5eGBpw//F/eQufa4nc6qAaS4KdF3107uiVttc0k8ux07ibQvJuY7fiwd4OXZr0Q6gqaTYfVYQ6EIV9kL8FnQ9liGsknVLF8EoE7TlXI8IksZgFbH8sHCarF/1H2eAje9iOi9D42durj8jO83FfQMTAW4i0XTbsezu81h5TQw9htA1vWYdW8QvjGUdGnpIl9Lb44RmOoXfr+DjI9Ypla9xGXuGDKulw6P4lS7MDMokCfJhKLnQgzdVFwVsN8LVpvT0yGwLWvwa0qGVlWticsem3icW0NtOfPZkBUsC/rrbxLYy0w0pE3Y6byCudYxBHrmINY6MSkjJZpV4Z+7ere/sDqfKry182IKm/Z3shm4xApXzZTTacvrd2RMm2hoQlr68J+MT+ZbHckcDW41UllFCeuRQzlfpVosUaqTQp+E9xeBof0qY4hF7+mwT9Q54f4gLy5DMplOLs4DG9PDKrwFQE1AXXrSG6E59XbjY2RhwWIkCVAp7mOPIenkMwI4qisDcpCUgdzq9GwtJ 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)(136003)(376002)(39850400004)(396003)(346002)(366004)(451199015)(36756003)(86362001)(5660300002)(44832011)(2906002)(38100700002)(38350700002)(1076003)(186003)(2616005)(83380400001)(52116002)(6506007)(316002)(26005)(478600001)(6512007)(6916009)(6486002)(66946007)(66556008)(66476007)(41300700001)(4326008)(8936002)(6666004)(8676002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?Du9/6Pt5MZ8GFVT5V6WrugCtoWjm?= =?utf-8?q?EKFx0o6/h4chENWaYaOgi7aV/AaM6WfcTYco3ndWml2X8Rmh5uS70+N+L2R+TnQwd?= =?utf-8?q?VuBZ9Tl9fcU7vDHEFWzBLDNYZqfEW5O05ZehWAp+mzYSxnJ7BGt3uhqnxhshzlOPq?= =?utf-8?q?yD2Hm+Y1taZGz+60x41L73JU9pveNku5xQxVkSEttDuaFcefsOUVZw38qcStQ3q26?= =?utf-8?q?DG8Zbkt9buQ/+BEob7dWlk1UUUy/Yw303sZCnOaKYltgiCAV4sKcwkwLJ/g5AKBz9?= =?utf-8?q?mY+Jro5FIKlEKnBHZXJbZJzI1Imi92Mkhd6I/SoUazLbXNQSObrvIgJyhDZfJqxlq?= =?utf-8?q?PpeGGBPF5UMA8XnLlZQe9j9EdO58UFeknTYo1N5O9sJxlldUncojSvEaIoD/nnV1O?= =?utf-8?q?gNm4mw6Szd/j8DmiJtjF5O4G1rpzB632okBCUGXXvVtGPJ0F/7e/ZuahH/KiW4030?= =?utf-8?q?b7yKgY+g0qTJjMgEFn76cUNgYroJhfZ4FDCHQxT9+QISaxd4KFbSPfigsZ5FHqP4/?= =?utf-8?q?jgliAn3XYvOhIyuFSP5Gr/BLkNd92Gonj25PW7wI1f9/HXwDDiyCuGIWXN+CWPy0x?= =?utf-8?q?hLiQeAoqDtW4VfnayYSi5oCNFbF9wRSuNKFBD53YQ1cR4vcfks+GS5UeEgs+E5nNS?= =?utf-8?q?n+afHcN2WNIjVFSsQ+SsEgWjSDjgtQEZMZX7ieriaiiBOJv8FTtX8serb1f2wBmKs?= =?utf-8?q?CtIyP/Y24AyrOhydwSlzj2uPunvTOePLpskvlfNJM0aheD6TMARz2PkKXCwxEAokW?= =?utf-8?q?Mxu3UWRBF0hjn9YgS1PxghqrrILAty5UWuTujtDYiLGmpEy99ctEq2dZdH5SAHI6/?= =?utf-8?q?v9LbZHqZRefMGPuZrfiSNdWtqLlxUqGFLCWOtjplqXaHdkh4hQyuT77VZswDbGetY?= =?utf-8?q?Ys3xg108UsV67PSzpcSoGFKuPBhxhm/kbk9mVk7gB5c3GgOOhopAjT0EGQ7vx5/rq?= =?utf-8?q?tuJxRh/s2QdpLN7hzMrZxcGwIKlNssDdRfEu6PZK+LxkQiTXrVHffXR+5GxCbGqae?= =?utf-8?q?a09npBBtXYLyb0uAfI+X//P6ldOVkYlvpTB0zW4B/siEp7Z2+Np8/HLvQY/WmNHJO?= =?utf-8?q?A4jjNIKcaoIu/05viBh6DEWp+Rb8x7QiDj7h2w/2a6+t+w5MFsZ2pQ0cwT9pkmgdS?= =?utf-8?q?pxUCFORScuZvJJzzDyS0pdymHUmWW4hnnvXxWWrkNDj+EWu480lPUs0iP2OKOBYq/?= =?utf-8?q?oTukK+tD7udyFPDFGHi83goQmkua1MRYsFhOB+CpBC5rpfJCwoR8EeNSVAuwp8kCe?= =?utf-8?q?Phaor+87aJSCnbHlKDn1cmKBvsULf48BUxz/3GTK2st8s63o9/LCwZYPMkwX+YFOT?= =?utf-8?q?cXKnPvGAsIdcrDQQFMgg8M3vGCrWgpXPODykgfq2ONIbPhyD5Lm2RGeMaQh8zzxmg?= =?utf-8?q?OUBRqDqW7xbEM/XHgsESfjxo28e93CkF/ECCEr3LvN/ipjo7a4OwHt7H9LmMpzmWa?= =?utf-8?q?gZ4pOMc7IlSl7aMTVJ1Z+Q/ZauxnuDc2dqtLrKquYUanxM9pvkFZJLrj8cJCD1yAL?= =?utf-8?q?jnPbG33lMp7Kjnui+hwYfh3j76yuxVA3NA=3D=3D?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: e086770f-661f-46b5-2e23-08dab0113647 X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Oct 2022 07:28:39.9163 (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: qZmUc3JH5HDsbigM+IJzMCNAgN6L4y2UuaYpviDNTv2waUptDffhSQ9epKSF5KuLMLb0zX2YepjZeqmPq6ln1aZKS9xObGO7XGTscMp3eQU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV2PR08MB8653 Received-SPF: pass client-ip=40.107.0.109; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR02-AM5-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" 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 b0b467ebdb..e0ee0bea00 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -2122,7 +2122,9 @@ int64_t qmp_guest_set_vcpus(GuestLogicalProcessorList *vcpus, Error **errp) return processed; } +#endif /* __linux__ */ +#if defined(__linux__) || defined(__FreeBSD__) void qmp_guest_set_user_password(const char *username, const char *password, bool crypted, @@ -2156,10 +2158,15 @@ void qmp_guest_set_user_password(const char *username, goto out; } +#ifdef __FreeBSD__ + chpasswddata = g_strdup(rawpasswddata); + passwd_path = g_find_program_in_path("pw"); +#else chpasswddata = g_strdup_printf("%s:%s\n", username, rawpasswddata); - chpasswdlen = strlen(chpasswddata); - passwd_path = g_find_program_in_path("chpasswd"); +#endif + + chpasswdlen = strlen(chpasswddata); if (!passwd_path) { error_setg(errp, "cannot find 'passwd' program in PATH"); @@ -2180,11 +2187,17 @@ void qmp_guest_set_user_password(const char *username, reopen_fd_to_null(1); reopen_fd_to_null(2); +#ifdef __FreeBSD__ + const char *h_arg; + h_arg = (crypted) ? "-H" : "-h"; + execl(passwd_path, "pw", "usermod", "-n", username, h_arg, "0", NULL); +#else if (crypted) { execl(passwd_path, "chpasswd", "-e", NULL); } else { execl(passwd_path, "chpasswd", NULL); } +#endif _exit(EXIT_FAILURE); } else if (pid < 0) { error_setg_errno(errp, errno, "failed to create child process"); @@ -2227,7 +2240,17 @@ out: close(datafd[1]); } } +#else /* __linux__ || __FreeBSD__ */ +void qmp_guest_set_user_password(const char *username, + const char *password, + bool crypted, + Error **errp) +{ + error_setg(errp, QERR_UNSUPPORTED); +} +#endif /* __linux__ || __FreeBSD__ */ +#ifdef __linux__ static void ga_read_sysfs_file(int dirfd, const char *pathname, char *buf, int size, Error **errp) { @@ -2764,14 +2787,6 @@ int64_t qmp_guest_set_vcpus(GuestLogicalProcessorList *vcpus, Error **errp) return -1; } -void qmp_guest_set_user_password(const char *username, - const char *password, - bool crypted, - Error **errp) -{ - error_setg(errp, QERR_UNSUPPORTED); -} - GuestMemoryBlockList *qmp_guest_get_memory_blocks(Error **errp) { error_setg(errp, QERR_UNSUPPORTED); From patchwork Mon Oct 17 07:28: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: 13008263 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 51D54C4332F for ; Mon, 17 Oct 2022 07:44:50 +0000 (UTC) Received: from localhost ([::1]:44094 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1okKnp-0000O9-3a for qemu-devel@archiver.kernel.org; Mon, 17 Oct 2022 03:44:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40872) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okKYX-0004X1-Q2 for qemu-devel@nongnu.org; Mon, 17 Oct 2022 03:29:01 -0400 Received: from mail-eopbgr00109.outbound.protection.outlook.com ([40.107.0.109]:35648 helo=EUR02-AM5-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 1okKYT-0001HN-GO for qemu-devel@nongnu.org; Mon, 17 Oct 2022 03:29:00 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=h8ChEJ/V/S9gCZf1D9s21HdTCAUepU76QDZy3Xnkcz08nHRA8ASmgGWSfDCo7nF8EmURoUWojad65MTrW4Tqxdu2Su+lR9H/3mf9drEcdkGa4gBRjIchG5x22wAku/ALmBqEqlZpnH9m2Z5fOKYNtcB0RA9YrRzo81WcSB1KS0wjGpBJvDCjfsTycPEMsGc4x6Zvdfff6pmpi4E6mtNeXRwG2547QU8yvmv2OIguK78fG6Yeiv4UwKprsQy/3fDxkUqhF6mJ4QSlDIa73JQ1vsWaG/ho6LnfsPvw1RfWCvpZPMoxcC9QEfS4DOl8JfRTcWrhBAfdLNrliJFtHzuoZA== 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=97GU8ZgrfrryHI07Vu27eApS8SJlI5utNtISknybh44=; b=DKfVDASIohZHeEI2Y1ikrzLkb3wZN0JBVTs3xY4qrJMDGCRjIFEU8ZVEu3EO1pGD0K/nTxk0hoyJw8OPo0zFL5Fwix0yZtryC+jFEOWakmEfhFM9xn0chVPctZO8TPqPhFog49AembTvUrPL5VTJo4seMgKS6WlYsNc3Wzd/pcnS2CnO/iQm56pcDbaLZ5Gy5b1mPP2U6k4XdDmrqOOK1s6UWvwksO2uOI3+AIw7c1XOs2xroujNrXcuIrZF9GJ1exKt30GZD9vZCr5g1HANIw222HmbO3ErzPV6KL0r1V6vVh5u03bPp77jo+WL//wk6OkqC7nuBUPpVu3TtofDTg== 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=97GU8ZgrfrryHI07Vu27eApS8SJlI5utNtISknybh44=; b=dh7LcoPy3NypZW2S++7naoDRqrxahc4Zn+dt34eJTzRL2+L2BDYFteoVE799T18WRIM287gZ4tn/IM6p+nWFTR4FfWwhh0hvf9mS1Vp6rSfEdYQhNbJl5GjR62GxZUcZDGciRyIceNZqISmwf/r0guKStgG1vH02fIvoEd9t84FRAxixJTXCBZojw7moujLc3X+N3rbE6JGFMu18XaYnEjsZS7rJwQca4ShU9b43x7jodZDZmLd8puxtBIvc6nz5xG9zo+iRDTqx6rMXYUbxFbfLm6Db6hgpXpz6cU1UCru5sSrEoVCO5u3d3R6YfhnBIyyY6Na81nzcyiV2qjFRlg== 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 GV2PR08MB8653.eurprd08.prod.outlook.com (2603:10a6:150:b9::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.26; Mon, 17 Oct 2022 07:28: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; Mon, 17 Oct 2022 07:28: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 v5 6/7] qga: Move HW address getting to a separate function Date: Mon, 17 Oct 2022 09:28:24 +0200 Message-Id: <20221017072825.72867-7-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221017072825.72867-1-alexander.ivanov@virtuozzo.com> References: <20221017072825.72867-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: FR3P281CA0033.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::12) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR08MB7095:EE_|GV2PR08MB8653:EE_ X-MS-Office365-Filtering-Correlation-Id: 8bdaf1c4-b980-4e93-610e-08dab011369f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: J1KPBFfOgxiOvlwEzRJbqS6/+0mp0DhLod1WXU1Zt7+aDykS+aaFnuFzwyLXcHcv6j9TraWpcWCnx5SRBvhQXaUkHsmxmoS34Qz4yO/IBotbabZhNXrooHbHrxHY2FcCnX3qr+VHWw3uMNvbNtLDynCBHFkHiYO+RlA2fHjCdXV7+l9jmEoiaaGTBMfYfXGGJymOdyp29MtzFuxqXPcqCg6s0vji5ora4FYDTVU5nI9VNELT6HA6zubzvJr8FARnE7D44lxbjAmg5NEdy4W9S7TwA00MOP90HK5k5BJ2vU/K9NdtxmUZotHOuP3Y2RBt2lRymFNt6QLxn8kiHRoY/dZ18pu+DhOhKBapEs1c3pDTkxmNvCT4Vp88xPKMKfa1AnzQ6n7vbRWKk2TzUcAVDqLmsAcR/292H9rrsWBFvRiYjwNJx0Wl+Kwwwvb1nuoyE25jNRbdAX1xiY3XKOeEkqxZawUZQ7rkCgcm8/RHFLLarFJWEcnTogr33Qbuj/FPyaRefyS4Dbp3LA7nKm0i3aQWPjMfMd3pM/co28bHFLDAm+VAfXwVL1khZi1wubjYuJctmJWJoCPYaVFo5ILxAdV5QSLjRA6ktqncbbu4IXpQay0Cw9uWiytTJoChzS11YCn7thLmEM5ptxswtwaBFrpge5cmA1n4d6xtkVZ7smdBfUtPADKFJX8sdaz7+hoDLzINkXboTmJsYX70bURnGYdOYNu/JqnTmsOGRHpb77fvcRP+Hsdl6NVlKXldeoY3cAyR3poqZlSExysWI3gOJA== 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)(136003)(376002)(39850400004)(396003)(346002)(366004)(451199015)(36756003)(86362001)(5660300002)(44832011)(2906002)(38100700002)(38350700002)(1076003)(186003)(2616005)(83380400001)(52116002)(6506007)(316002)(26005)(478600001)(6512007)(6916009)(6486002)(66946007)(66556008)(66476007)(41300700001)(4326008)(8936002)(6666004)(8676002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?fOXHvmokSNd4o6vuw3ZrY0ZKjpmi?= =?utf-8?q?OEXMJpyPVhwLZsyktdvBUZji5kQf1eqXp1nS33rryTiCxBYgAGYwE8BanwaR0ZiKp?= =?utf-8?q?o8CEibWtBYNtndiIG2MOLj5r8lpjpqW6RbbXpekgKxjPVw3YwjsJIQ3zoVeof5Wzx?= =?utf-8?q?lX63/ZYNnfCwA+FbinRep+TOtfuBhaaUW3Donx3LiZXt4CjAY/HNNpMxqFfCwATxu?= =?utf-8?q?4UoIwWHmU01NVtywlCHqXj4Cn2ODSL43Z5E6E+J8jbmeg6/F45DANlTaRZFSIAZAl?= =?utf-8?q?lXP8J3AduJaGeJAVvrKdg5wb8ZmZ9n+nVSZ4N3jw/s7q5Sky0k6xkTbe3UJVLfq2t?= =?utf-8?q?5TCABLFQzDZsWHfjjsUNhzlunE0omYj5ZIsI/DC2gvSDM//CKqgyKxnvOWv76kF+N?= =?utf-8?q?DaotonBn0qQbK8kbkHLnOeOK5FXRFjqjx0BfF/cih+GD2/E3FcddrWiN+N4PuWO0e?= =?utf-8?q?NEt2EwU83Aw/objOU635YTsLvbfTQZCRtK3d8O3QjoAThVewqq59ucVAgG1OWAd6v?= =?utf-8?q?y9gCK3dHaP0HgQ0IHA7/ag/VgvAhVinWQl4jXknvtgnC6zhagNc882yH2CaBE+j3n?= =?utf-8?q?O4g1CXHUEr732osZ1GLqNh3pj7mPTYSXN6VZJorinQgmkF+SVEUCHGuCEtezZ8j09?= =?utf-8?q?MuOyNPZUcHgGc3FbHXVkrWaRA2NX4yN0KKg7KrlHA8bd9DXaPx7cCbiPw5yEwvRhR?= =?utf-8?q?a+2p9ZqTqRwOR2cf2BeXn1NHJde4HavNP//qq6vp2EZMp/Kn+trbi6Yzw/CTA0S5c?= =?utf-8?q?bbBiwhINjo8FfST5HBA3LXnjpfGwrkH8Smch98R7eG31SGs1hnTlVRLodyrYpZghT?= =?utf-8?q?l7fd8CvZ3SNO75rFnrgCUBQnq0iq5jFAkbqO0XyFgoNHywtvpkL6v2yO4mTArPfEY?= =?utf-8?q?HGxyJusqQlsoJYNf7AzAFJ9SCy7Ik0qIIRaivXG2pP2TxGgAFeRMKETDGLtl03vZl?= =?utf-8?q?y412eU4ZPQc8cfh+F5FJL56YmGew2HbYHStYAghcreRiAVW3DBGimD7Nm8Mv8E4TY?= =?utf-8?q?OEUPhu0p7mBXi9Gg5fQGvOIpJK18wr95tpJFdeGrXKnWV49sLlp6qaS1C8T67xBz5?= =?utf-8?q?vfrLKzWRtj62wR7OSXlWCw1WVf1sPSSzUFADP0jFegxX8aphBV33zmJDakTtasg27?= =?utf-8?q?Sa5hN6rxtkW0WuRFsIIjpa0xOkQjtGCH3KsHMpx3NtacyE3UOcuyYAOX/AhR58aQQ?= =?utf-8?q?q1WrpTzlh5d9gSIiiQYOAyvGV9Q2mWlzTZPkReU3mHLfbKtCvu7s0eci2XZ8NnZUy?= =?utf-8?q?Hpr9sa4ql1/bfNuFLrZTcf8HjyS62e1xLb8mJwxi0w1BNVz/BqwFXFVqWjlxccvHb?= =?utf-8?q?fouVh8knt7YlpZhbQkIEqzFWRvov6OtedzpknVpfJkMtj0sPsz92KuoM4ovBWKY6+?= =?utf-8?q?qW+gRQAJhBLKWxS7Gy4k84WHRGqnwbBV1a8xOJeY+yfKxV5Js8KMhRj49ePeG/ZNL?= =?utf-8?q?xiMVXj9uI7u3l0MBlEBMfckzLC87fr690ZXdx4BCNF8C9bFuRFcf9+UqEg4JQoxVW?= =?utf-8?q?UAyk8mDNv9N5ye2s5utSk0AdheU815taDA=3D=3D?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8bdaf1c4-b980-4e93-610e-08dab011369f X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Oct 2022 07:28:40.4787 (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: vCojPqbswj8PvAf9b9JQR4J/EfepunLP8LOd/xcOWs6gwJPwIXD7HqN6MikEzgUcxuqODvg3IvCOs02JW5QIHioMole1G3t4alGgu2qanG0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV2PR08MB8653 Received-SPF: pass client-ip=40.107.0.109; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR02-AM5-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 d0583c6ddb..8c1c56aac9 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 e0ee0bea00..32493d6383 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 Mon Oct 17 07:28: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: 13008269 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 606BEC433FE for ; Mon, 17 Oct 2022 07:47:10 +0000 (UTC) Received: from localhost ([::1]:42498 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1okKq5-0002lC-7x for qemu-devel@archiver.kernel.org; Mon, 17 Oct 2022 03:47:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40876) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okKYZ-0004cF-3s for qemu-devel@nongnu.org; Mon, 17 Oct 2022 03:29:03 -0400 Received: from mail-eopbgr00109.outbound.protection.outlook.com ([40.107.0.109]:35648 helo=EUR02-AM5-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 1okKYX-0001HN-Eg for qemu-devel@nongnu.org; Mon, 17 Oct 2022 03:29:02 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NUopEGLYtu4G1EHg2EXTR8hoHihG3cmga5/kyC9Tk73SHH7VkVc+8a9I3P0miKw0NE+jhtAvfAho63WmibojUm/iEGEpaYD+jkDqlmkv633ZQZt5sczqIciLFMRdhxnVwZmGVxB+vsmtyKNbgC5uobLWfsc+dk6gW5iWfxbCL6DejWNcVQzqINfI6/vc8IR3LKcNgk6zuv3I6/vu9LZNIqbNGcGVyWtL0kXaPpfO6kTun+jaMfW+PwwosG81b62qomzeQggA1yJ+xcIPs/efVRLg9jaqDPX1XHIrWlkYuJmjXaiVGVXAraC3wuNXI60w9W7y2+lfNxwyTeDthhnLdg== 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=V3Mx2EqfRc9oeboLAmpMnogS7QgWa/LcbDHfOxhZ284zivR23m5G60iqm9fG5Spt4acIJK8Nwij8N6tSylXpz9FGJ4IZ1ExsGiHU58Rxc6eONVW+6W9AmX/lt8aieZzxqG8acBmgo9g5l57uOVuq9U+/6reW1LsPcFa80vjpUOKn2jV0uypx1IZQJgQ/bvNAr2qUbJIC6Seo2SxHgAOfnn9leUJVzrjGnvnBlqyZexLVQQsXfACSfMnwaI7dACqRf4qcg7tJ8SeZP98eh8rR0loGF5PUwaONiV//gVCOzNzSDWUIU3yivB/17Xt8Pa7/ukOpLD7/lH5G2FYMokXfFQ== 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=TyMm27s3TjLZ/lqnQU6xxmLO3uqKBSfN8yo3/dxJxn+Ftnso+xsdrPQ2bV0ZzjlTZKZrd/KGDkWCYa/Bi6f9Ct/vsskw8OFfj9IIVrVhVcMaLLjLpoKcYk+y8wgxnwZbBVZQgJl6+ukA1NgTRCGw24su+3BrZsswbEcH3JsnNx2SLjfFiZSWo9ORpZha1kMN3G2Xev3/QkzfAbFt+M6BzezDslGlxp66skQRfz93p/DFIKY4ShBLmjzpM3zyzAM8vpkIVQj+LlBbHlV/F38hvPExwFuRHlhMQP8NZRg1IT+OuQJcRGfyi4ydNFd8DTe3bBZlBFirR9QNwAZzJ+Bgkw== 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 GV2PR08MB8653.eurprd08.prod.outlook.com (2603:10a6:150:b9::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.26; Mon, 17 Oct 2022 07:28:41 +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; Mon, 17 Oct 2022 07:28:41 +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 v5 7/7] qga: Add HW address getting for FreeBSD Date: Mon, 17 Oct 2022 09:28:25 +0200 Message-Id: <20221017072825.72867-8-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221017072825.72867-1-alexander.ivanov@virtuozzo.com> References: <20221017072825.72867-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: FR3P281CA0033.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1c::12) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR08MB7095:EE_|GV2PR08MB8653:EE_ X-MS-Office365-Filtering-Correlation-Id: 409558ea-1e7c-4368-cf84-08dab01136f2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wA8kvoViXqK7n5cAKlQ0GgM4Ke/xl7psWb5aSBfCCVZYSMEojNdsQiPRVGuUNn60s4v9eK+YV8a5fu1SlVAP9CtZOhke03V5hpXoylWK6TbGc+67RIctHj7vzwYx8ucScp0RbttFJnmJPJo+891e83apXlPyGOMIhia2x/LvMDah713WKPl3Mg4VvVoXz27lnlWiQ5rQr75dy4hKbMh2CMTRpLa0Q01jrKXihpZ0zEfvgOaGjJa1SODFCr/lED6SGs8JK0c3mrfY6D7CYCjUtTS6Gk2y1LfBZiX6e0PtQhPAaYZq1kbIKmFunXcP3NiEgvmcX3MccE+bT9SI65foUDUBtsvLf/yKmyk7qaH+9plJLRP42cGLyBTGYIHjCjvg31dwgjFAcEUaaogkxgTZzx4KAJah2LKjwgn0a/nFkEDJaFqjNv/PugfoDypfDjpDD50OYTnO/TW3wWO30CFFZ+lIhJ46r+zX1T9rrQTAA1Wg/3xBwqBoyuK9cOG+qhA1okJ4STuHO5tudbJXJczxQHkM6fyx3xO+bC5M3K6k85fpM2FMe2SH5NiXBXSCxWFtafz4OfkAZW65qpM7m3WDZmeM+GSwPMdPhP+VhOdMEn9u6Iven6ELq9xU3rFSabBXNRtxNvdhRdU+yX+hGz2M9PjAIAHj0SItjfN4ZxY9e2QQMlK6XxYN9TB+lUAIqy3cYpmgJT0oSNKbQ5U+gIOaVY1PHX0CoeByuepEg/ix0yROnD1Bp22TwEUo8i7K+BF4n2Ii9/QwdoyXyAstfKRo1w== 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)(136003)(376002)(39850400004)(396003)(346002)(366004)(451199015)(36756003)(86362001)(5660300002)(44832011)(2906002)(38100700002)(38350700002)(1076003)(186003)(2616005)(52116002)(6506007)(316002)(26005)(478600001)(6512007)(6916009)(6486002)(66946007)(66556008)(66476007)(41300700001)(4326008)(8936002)(6666004)(8676002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?SJVEzlx8coqLIrPMrr1+Wcb/Oyjg?= =?utf-8?q?7EFnGV+rY3DoW5aLvlOnm7ouZwrzL/S/SY5sXMvMnFQEwzBmZQdzlZRu4JWVsg26m?= =?utf-8?q?3HZHmTVWJx0u0Q4Af5wvj3mwCBqUMoK4Dy8PNuqKpRZtTEWFJylMpuQJGTJ2nqSrV?= =?utf-8?q?unR0sc+WerOWHkdjEky1YWkZzCeyU1Ruz4k41WNUSU+Ijo0MtxcUjzUF15OlHqwS6?= =?utf-8?q?ewcaH7t2AZi838JLTNVNnau8aqoc3rQIO/RIcv+R5Fi1nNLk82Sx4ovjqSDAydk+8?= =?utf-8?q?uIkj0B2+2YRZF+OOZCQ7ko2mMa1sdi4hbdheV/HbPT7624sk2zBePiG7lYLoV3WO8?= =?utf-8?q?R83o6eviT/iDuBBe8bwxun+oy9B0+uOAW1q1Cef8YdAt5ulxPma887PL+woCRGS3h?= =?utf-8?q?kJkQ14uocBUDk43CRjVsHHpkseOdnvyYnd3C46pRVJevlzFYDfqxv317PUuTeXNUU?= =?utf-8?q?M4wdhi0ZMhBDBLURoFniKb3J6smGkiWyKP2g3E6uizU8jDn7EW6fvHAH5NCGjofiH?= =?utf-8?q?mAxoJN+tHqJwzYugVY0CkpdM7X54fdeOfpmgDOE1g3UQFa+q4zEIIrQr1YUsj25rO?= =?utf-8?q?P2SzNvKaSY35zL3xeVqB5GCrudcOakjgbP47+PxVD52SXks3KaL4gwPOZ2L5Z4jBA?= =?utf-8?q?Xx2Xoz9Us6aqdqNwBvHKQmeTw+f7T1Mwu0kO9KQSfILcrdKX8LKyoh6ryDjXK/GYa?= =?utf-8?q?1Xla4k/WqJauIYIZLAhF6gVDRHnVmSfMdRoqzhVIzJzZYTY1H6lOv6YhDVem3SFBk?= =?utf-8?q?Jc10j9RvwHbHxy7GKRq/PO6BrTlxYpcf/lsQjXn4jFP/8KrJ/CZdj7g+h/bkp+ikH?= =?utf-8?q?RPiPpi4SmWzOUTF3ct5LvHYfnnsYHWP7/qh9OFNQK9yPfHYErJ4npNKnQDtNh+KgB?= =?utf-8?q?4zI68NUqF/rXGdAJo2arCmFjhdG8cs4nKmxwitm3soC/jTwD6Y6Wa6luoLoiCbyjb?= =?utf-8?q?viCFg6wY2HzVtbc+IROA8/6OHmfnLn4e6TXJ7E7S/CfLgHnjL5HNjsVWEPC3zZbqv?= =?utf-8?q?hwhxIrovbFNYlvBChC7fiXWmOTtLk1P70slrgxL7hUQpwed7IyAtXLPTkKusVgKgj?= =?utf-8?q?2GopWhX733wcSTXAsL9YE+6a/qLJoZQ40t3JEjLKRM5awVb/fDNmZQgiF7TBAc+Oz?= =?utf-8?q?kjPUqc5a2ez1RTSN7GfHNMfLsdwuwIWlW7LdZ/luVZX8yhKL4ram0Zm7xrdCYaFCp?= =?utf-8?q?6OkEnTYcQNak3dBqLo7s3/btlwXCyFc/q0anGnwOofPp6ScvnYMcIIbkoT9eJZTsW?= =?utf-8?q?TPl4mL9KTborVvnjsnj741C0GWZMnHT7AnupnzLT7fBTL32MR3oDDl+22eQV5vw6T?= =?utf-8?q?Hn5R9Rheh28Si1H6LgUmBQLfUm9BpIN7JS5M0CaCeg3ZUNeKr7Yt7M61pcflN1MSs?= =?utf-8?q?e/XjGxHHQFesoK5QyYbBOd+eURHdQxK4tmD4axlQ6hK9eURSmRjZNRnyZV8hXbnY2?= =?utf-8?q?48ieu/vvBZN9wwZozXtuxYxFC21XTbtH5DjMdvq8qSSqGz482M3tk73SIv6ny3vVA?= =?utf-8?q?ycNFUa/A89O/Kw9LUwViVh5o4/luzbCbQA=3D=3D?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 409558ea-1e7c-4368-cf84-08dab01136f2 X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Oct 2022 07:28:41.3079 (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: 9RvBeajlmyWEb4hmSPA0R2DBAs+l+0EifiWSOA4iG3F243EHztnDttpE1clVqmnLBuHzoVRYEJu7DtmrxUyenBv1Z1MCBM4XRx/m+GvftDk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV2PR08MB8653 Received-SPF: pass client-ip=40.107.0.109; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR02-AM5-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 */