From patchwork Thu Sep 29 07:52:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 12993667 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 258C7C04A95 for ; Thu, 29 Sep 2022 08:00:15 +0000 (UTC) Received: from localhost ([::1]:52390 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1odoSs-0003F8-2A for qemu-devel@archiver.kernel.org; Thu, 29 Sep 2022 04:00:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33250) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odoMJ-0005LW-O1 for qemu-devel@nongnu.org; Thu, 29 Sep 2022 03:53:31 -0400 Received: from mail-eopbgr60106.outbound.protection.outlook.com ([40.107.6.106]:26178 helo=EUR04-DB3-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 1odoMG-0000p0-NB for qemu-devel@nongnu.org; Thu, 29 Sep 2022 03:53:27 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=l+NjBYFaVxEdVyp//ZoOFvDyG7eeWkCIm8W8LxFeyw9polHzD+PgnPxPOVPpo1bCykPRTGk5lGCOPoZrFW/iOvmM0Kmi0xLTwChrnG99iTGSFGwEgFGYd5tw41S+qavwXoghdJxSsEBKRyAeu8a6EyRCX2nLa8X7/AulzfrjEs3kLksdKuPXsgP4dqktPzCCv0k6TkmTkO+0N70jDfLaAS5OK/W1XySRJEp26e4QF5Z5Mo1FJfM09wKPYrG6fGaKc+LPJphMX2oOeikcbT3v4FhQ9tAb1nWSm780VonoqEm6Og9zzCqwKzCdeHsySeOpEh2UeMgxVSbWP6uragBw5w== 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=ib2e5xzdE0WiFHNs69iekKSNbMFGK80IhRwHxNZSI9Y=; b=bZ2UuiX2Q0YH5L+3Vk7XZGyoSOuOsuhLJYKgTyBA7FTFCTy7jZwe5K8Gh7Fpn4bt8kq5PlsD8ZI2xPWDF8ces0MYz1IEE01WWh8/hnY75vDsD32YnkBlA1qPaAmpm7+7+P1eDFX9oWfbiDwav4yJFa/T8LpsJmWekdMzqw0rTPQDuIUVfWL3rWi5XeNvXMun5dUuIN+g6fQC6WxeQZiqDPG/P0r6Qev0AqExe+v0tJcQU1hI06I2EOmfQAhsWvMcp00y4RZmH9IYReGsVXIGfi14bJK1NQDwvlIIF4mqEqIypVeOi2DLhW6IS7yom9ExI6N2btfFmVM1UYdrurSyfA== 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=ib2e5xzdE0WiFHNs69iekKSNbMFGK80IhRwHxNZSI9Y=; b=hpd5EbwmzvkkHHhoUZutAj5svVNh37BhKA/Hgt5PgicvHnNTO0SOKEGJQMlp2b6fBkbLxraf3Gj0DWYL1oTogDcQwuJb9sV0fniEPqb7uu2UF3H7d3mFyAvpHPfBbABvAkQdNaCmWnh3LoBluCZQa78LtZR+AMRTmsXwCFxmi08kfp/RTMFgSdgwuKSXYfnHEH+SUWBD0VRXTi4VOcJeBRgur/VWO6Xgu90ocMU5k/z8vM1VJb56cB5u/dZAzc2/Cqt/5uy6z82oitdTw0aKVAvVV+M87clje5kUAUzKnR8JSHofacASD9zv88oRLXYIW81aQ79iYHCVo7Zx+bB8EA== 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 DU0PR08MB9509.eurprd08.prod.outlook.com (2603:10a6:10:44f::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.25; Thu, 29 Sep 2022 07:52:46 +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.020; Thu, 29 Sep 2022 07:52:46 +0000 From: Alexander Ivanov To: qemu-devel@nongnu.org Cc: den@virtuozzo.com, michael.roth@amd.com, kkostiuk@redhat.com Subject: [PATCH 1/7] qga: Add initial FreeBSD support Date: Thu, 29 Sep 2022 09:52:33 +0200 Message-Id: <20220929075239.1675374-2-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220929075239.1675374-1-alexander.ivanov@virtuozzo.com> References: <20220929075239.1675374-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: AS9PR0301CA0039.eurprd03.prod.outlook.com (2603:10a6:20b:469::8) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR08MB7095:EE_|DU0PR08MB9509:EE_ X-MS-Office365-Filtering-Correlation-Id: 45c40b43-6b40-4cfb-3646-08daa1ef9938 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ETccrTm5YNs64j22QkMOR7UIsNAOjqWWT6+p73eg8xXQMx3n/lmEmH+gSUVSXR2StmyAQawlZ7KPEqRD8uY4pCwjRQBxdVVa8q2Ewh5igl1c+ggMUV6+ccOIbpmsTuo2dekV8IhnB+MJ0YJaMATmrEVSUCYJ6f0OC53SZw12Aou6QnjYC9U554zpDL2J6+wDokqh+Lic9eXUrb2C4XN1OTrSRzUqg3Zrps9ViyboRhYiAd//NACSe+sKo+QvyYb2mEJcQbgQvWoQ3F8q3pOQQ751iggJOhmKtJeSRvP4hkt/01K+haDUT3pgED7U+0Gbt61aCpSPdFvLMi8Q9rkyALkWBuUJNgtoWU4bXbiy6HhkH3+9FOU0BpjEnYOIEgMhNoQeGRBkpPR/scz5wj6ZMPqZXcbLTYh05AacIayonuUsSk1YdXtCgVK39tuMfeaogzh6VV6/WFqt0V0RztdiNaGkF+piMj0j3AV3+0BKA8florqz+Sbcf1I03ojc+/Se52B50wRjlrWUryITFns4L12EhODi9XFLzPbz4pCO0L8lM6tTjt8tXPfbFuvExJOTCMoH9vkqeqUm862vquq02/P679nq3Mzd6dNo8ME2JaBQw/9mJJurFR6G4a5O8iALWv6RsL096Sgybt6XX1q1RATZIgzVnGoI1rjXs+x7ZkxsOiA2XlpefN9rQxOuKXs+ZjJyJZ7fJBrI34Hl5tMNqs/JRQD/VN/QZJ7zTrwuMTnSVpLo+9pK+PV7fGm1no9DL97Jbog4e44AysDCzYJalw== 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)(366004)(39850400004)(376002)(396003)(346002)(451199015)(2616005)(38100700002)(38350700002)(86362001)(6486002)(478600001)(8936002)(83380400001)(5660300002)(6506007)(26005)(6512007)(316002)(6666004)(2906002)(6916009)(41300700001)(8676002)(36756003)(52116002)(44832011)(186003)(66476007)(66556008)(66946007)(4326008)(1076003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 7r0PVYtpcXW5d223F6ORUEQn9RChbr7LMOpTK1VlVTq/u0+s8rKGYvfc/qNABU/vNEOZBwrgH4w08vkbfVOQQgZyKrEIZqeaKnAhxo41SQzy3HhsiR/wUCejZ2PwP5K65+/O1laJAi/6yC+fpBFer0skDz2LVzdKUjdbPsL1UViMSHWEDHTW2ty6fjrGg9M1DgsOe0teCGssvRCVl1qbbn3kOgl7AowNfF8kTtKEE15JZI4BSZSsTUo5LRFlkV8IovFcuDLPQ1eEOkss523jVo/rckYQu0zOdnNmoJkcfYT4JCuiFmsVjR5DSVHZRxtysSrwlazScHSV7RZIRGWcKtC8FQwgawQwMPjD+4j6xEiXwSmZD+LNdy4MAv3jd9i4yF8JhT0f58aEdRq9U1VCp2XaEWTmRXQZ0lJeNRCzuvkQpblFkdHBgQd+615nzHO1/UIVewz5K5AovOdj1sqjGPMw7I1773TgPJway5IriEQdrxLIKNob8aGoA7qovITiVfx50GCIq3ZEYtExhnjZcAMq+Pml2H++4xVA+ynmDinuyH7iPEQWp5J3Z/eStjrpn8qVaJWyuN7JtwL5F5LBmO7zXPGFR+PS6bH0fZwuOMs6YiSOmZz6m+ckqojRuVz5TxehNb6hvWchFBbPnlufGrO+woelxNKim4V0rERxD9GKxrBR/CfG5a/SW3iRGoYfseR7rAg21ABjt40HVM0VhxPBAwgCIEFZkr0jJINRX6L9xAvCig+eMFRNGmddEJH3dy95hDmS4KFGI3fZ2kUzjlRd0hP3O63hUnTL5GyForXIxxJJ5Zt6/OEoyzU3M6I/Vh7Ipds9lcX3WVtG9z1B6cdtLRIT3kIjLyVqZKjUwmB1c4JJ7lPjRdi4jtPgOmbiGliCb6oYnDbAN+VcTu1Q5U4q2PNkq6Qi//RPDYQ7bqizMvyJ83nheA1rx+55uj2U7iMscuzixJwKTU9t24/gEJPxgpoxWC0HttW97XPpHfSNtKZ7KW0dXX7lG+FBRA52VXY38Ijeu3ttfmiceKrxX9aK08/rrkmrTzwQEJJtZelJgFpoAIdQUhWWJebCuyNE6scquTLr/aW19ktmiW1lrxQT7sUWd0sqZlNDo5H9ahVZfv/EbCZqKs29nVxyoCUMzvYEPRJZQPzgQc1o8wokrVI4Jki1O5btR4qwtKnEr05T7IMHacNC/l/93VsBb2phOHp35tz/EpB3bhnF75sgLTuR2IaRTcZpoVbplOraU8eRoZ/NK4Fuent2CYNjN30ou1zD5rKxtcfeC7RIKGisa0WYiQcv3/bZJAEcp8iVs4ntA001fP52rLaAKze1PuvOSZFILZ2gLCkp09OjaHUhDc2cBe9IXdOAJvgWhSi+i5GP2k+eHcHhHW+KoJsAGMuQTPvMpdXyczVslKV/SVBCaa0Sk/lNaoqqe+AS22kgDe0P2XmL4Ylaru9KSEDpFbEuWyqTCstRXbYEoWZF0XFCpV/2OJULSQc3WzTA2cHR0X5u29nWlvuUfk46GS46E1ofYjqjV3TIG04VCkXnpOuO0TNBu2Q+VHwN5SQGdrQ6AKPOlmjK/NJQW65v6pEWdhdJEPCWvwBVfUjrPIUWX8uK0/iaBzKyEY4IALj+8BdXaB8= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 45c40b43-6b40-4cfb-3646-08daa1ef9938 X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Sep 2022 07:52:46.7293 (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: tNhGCfTW7cZ+D9NirL+Xgh36T4O4SgcGlh1LzZSK24/KAHcuUFJeM2tO42yqQmQec5r1Yie1TPkpMQmxCQV/CaVbxxRe0MjZQdzmzH4iVv8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR08MB9509 Received-SPF: pass client-ip=40.107.6.106; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR04-DB3-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" - Fix device path. - Fix virtio-serial channel initialization. - Make the code buildable in FreeBSD. Signed-off-by: Alexander Ivanov Acked-by: Marc-André Lureau --- meson.build | 2 +- qga/channel-posix.c | 14 ++++++++++++++ qga/commands-posix.c | 8 ++++++++ qga/main.c | 6 +++++- 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index 8dc661363f..5c11abc8aa 100644 --- a/meson.build +++ b/meson.build @@ -75,7 +75,7 @@ have_tools = get_option('tools') \ .allowed() have_ga = get_option('guest_agent') \ .disable_auto_if(not have_system and not have_tools) \ - .require(targetos in ['sunos', 'linux', 'windows'], + .require(targetos in ['sunos', 'linux', 'windows', 'freebsd'], error_message: 'unsupported OS for QEMU guest agent') \ .allowed() have_block = have_system or have_tools diff --git a/qga/channel-posix.c b/qga/channel-posix.c index 6796a02cff..0f14246563 100644 --- a/qga/channel-posix.c +++ b/qga/channel-posix.c @@ -149,6 +149,20 @@ static gboolean ga_channel_open(GAChannel *c, const gchar *path, return false; } #endif +#ifdef __FreeBSD__ + struct termios tio; + if (tcgetattr(fd, &tio) < 0) { + error_setg_errno(errp, errno, "error getting channel termios attrs"); + close(fd); + return false; + } + tio.c_lflag &= ~ECHO; + if (tcsetattr(fd, TCSAFLUSH, &tio) < 0) { + error_setg_errno(errp, errno, "error setting channel termios attrs"); + close(fd); + return false; + } +#endif /* __FreeBSD__ */ ret = ga_channel_client_add(c, fd); if (ret) { error_setg(errp, "error adding channel to main loop"); diff --git a/qga/commands-posix.c b/qga/commands-posix.c index eea819cff0..16d67e9f6d 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -51,6 +51,14 @@ #endif #endif +#ifdef __FreeBSD__ +/* + * The code under HAVE_GETIFADDRS condition can't be compiled in FreeBSD. + * Fix it in one of the following patches. + */ +#undef HAVE_GETIFADDRS +#endif + #ifdef HAVE_GETIFADDRS #include #include diff --git a/qga/main.c b/qga/main.c index 5a9d8252e0..0d27c97d38 100644 --- a/qga/main.c +++ b/qga/main.c @@ -45,9 +45,13 @@ #endif #ifndef _WIN32 +#ifdef __FreeBSD__ +#define QGA_VIRTIO_PATH_DEFAULT "/dev/vtcon/org.qemu.guest_agent.0" +#else /* __FreeBSD__ */ #define QGA_VIRTIO_PATH_DEFAULT "/dev/virtio-ports/org.qemu.guest_agent.0" -#define QGA_STATE_RELATIVE_DIR "run" +#endif /* __FreeBSD__ */ #define QGA_SERIAL_PATH_DEFAULT "/dev/ttyS0" +#define QGA_STATE_RELATIVE_DIR "run" #else #define QGA_VIRTIO_PATH_DEFAULT "\\\\.\\Global\\org.qemu.guest_agent.0" #define QGA_STATE_RELATIVE_DIR "qemu-ga" From patchwork Thu Sep 29 07:52:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 12993691 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 07A60C07E9D for ; Thu, 29 Sep 2022 08:17:22 +0000 (UTC) Received: from localhost ([::1]:40264 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1odojQ-00020D-SP for qemu-devel@archiver.kernel.org; Thu, 29 Sep 2022 04:17:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33254) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odoMM-0005N2-Va for qemu-devel@nongnu.org; Thu, 29 Sep 2022 03:53:39 -0400 Received: from mail-eopbgr60106.outbound.protection.outlook.com ([40.107.6.106]:26178 helo=EUR04-DB3-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 1odoMK-0000p0-6m for qemu-devel@nongnu.org; Thu, 29 Sep 2022 03:53:30 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gVPLgFMgxkTfBwPOz+BF6ahMVljbkABQz+XEdlUGdxlqIqZQX3cWt8PN7lSa0zYfaYp4Knq1ihADpKuqTSaeQzBK9GEj4Y3PS1NtQr+B0Rm6JXNH1d/n02iSrZBdFeFxfxTjZuPRgwAcFYV+MPHwDtEM1v0IAhh14gNl1gMGNEiagCdAfao2la9t3/EhCfkwzj3Ou0wO7g+hDBnhTTv+rvg7LC8Fnp3bKBpMexXkW8Mq1O4V59pFyUgi6+Q+O1UpZgkGLYzQ2L/VpbQ1tvnKo84zrULkRP+ZUVLoXg3iWW7MvTlCjXpVcbtccea+QTy5Ag3ivxcrPZZTU3MImCFsnA== 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=AQgo/lQsufBuyPF1gE5iyXXohWKD6JjRPtOTuVhV0Yg=; b=mgBwzZ68FPJK9q74NG+RVak7QNsDAy3gvxvO+DEqxQgP0gV3pB82yfnLSeBekWkUUUyrJ9l7goG2c60qEfDe3M7ZSdTU3l2+fxtG5sfGzLbs8YMPm5nPJqls5inXrK1k47rRem+EictsKnJH3EA9ZkFkrLdzgkqh7OS2r29VpSpwIu+Ue5gSGa9H1Bc3VISl+Qwyq934mDr1AmuuxLn8sHBFu3nTCn20KAOMP8HwHdo9eTxeGPBIImL32QA721Tb1nj2GiIgnIPLejNobzYc8TrmL4nXuc4KKgrCKS46mpFnkrexywPXmyzHSXRq5qPJMgY9gn/MpaZdaKIrmeHDWQ== 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=AQgo/lQsufBuyPF1gE5iyXXohWKD6JjRPtOTuVhV0Yg=; b=nPsek4E0Dv8Do2aaOdtAkESlYxmKbgeV7rgBcUUeOjgOtp+WlbegFsJzOtkYDfya/dxSSBzyik2nA6LCFduASAOSE7epJ7bJGHsUegLG+7DW5qdbnSP5sEFSPr6+OYxpAcFnpVmMulv7iumb3+dNYnSJkp0W5i1985E/E0ptO6XlRkcdzysytBzxQ6bWKmA86yMSY35WxjmzzfvbHgKbFbZmZdYkkJZHnpMZU2muYfwaYsY0UMW5ZEYqr9rXKLJ3c6mY7nRSw0TWoZjyyishu4fNku+iiIVIOfavf6F/asqtkhJ8v4f6kUjn4fBno7wX784x/MCblPCPbXA3EuniGA== 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 DU0PR08MB9509.eurprd08.prod.outlook.com (2603:10a6:10:44f::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.25; Thu, 29 Sep 2022 07:52:47 +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.020; Thu, 29 Sep 2022 07:52:47 +0000 From: Alexander Ivanov To: qemu-devel@nongnu.org Cc: den@virtuozzo.com, michael.roth@amd.com, kkostiuk@redhat.com Subject: [PATCH 2/7] qga: Move Linux-specific FS freeze/thaw code to a separate file Date: Thu, 29 Sep 2022 09:52:34 +0200 Message-Id: <20220929075239.1675374-3-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220929075239.1675374-1-alexander.ivanov@virtuozzo.com> References: <20220929075239.1675374-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: AS9PR0301CA0039.eurprd03.prod.outlook.com (2603:10a6:20b:469::8) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR08MB7095:EE_|DU0PR08MB9509:EE_ X-MS-Office365-Filtering-Correlation-Id: 23bd9cbb-5235-4637-0c57-08daa1ef9987 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /SeRolP07bWIkltl5UHuz/fqAxcOiCMh1rLSzvc3F3pLiJan3Ddhgp1irfbcR4THgMfp+QnNCTqKZN4szmRWL6RVarQreW/WlHtbrB4vEIzkUqTC8SY5/YXIkLXKkff4HSP8knn6d6yV6LK+sv6g1MqRIits5wBMjP/si6GnCUs1NGgumkWg5CkN3a9Qtl90+rCFvrqRLs2/QW7lgnG81bYQgA6aJTrf4bh+FQjRSW6qxOILjrePgqFB5EqFZ0k/TVjFdxkSdgkcGcSMphFAKSK3P4eD+y7IYKeMS2+sCsPoNFixcNDwgQnDadrZbJdlVmUpD3Uy30AIufqn/DZ+Cw0oo+Q9UDSSzlTwTMMprMNVS16WEAtBC5MoaeQCd1T8c/94Bb/Tv/OJ20cBQTwh2ar1eapUuxEMUSXtNaQxcZAQj1ArDH7rP7h23AV0jk5L2HsyuQcEEW1wqilk6M9v5N7pLv6MLNkvroC0ekIPIWB/L77x3a+MhZ2rY/0IDUp92c3MnZsFN6/mlLwwhd2IAQ1dS8HvIvfMcnT0kLuYCsxpHZ0UNPcY4zWYmSX6yAL0Ks5Ci98Ajgsys/5GfJ2J+iakrh7jmtAVkt6TJy35YMv5i6jPcFDThlClyZ21ABjCGqLskYf4bEfO+KacMP6gUpYv2EuB00OEpOcOXBfPE5G86UU1aulCRkvLp6I1VJOeot243cRT/kOnKfdQPWgsuyo9LXvtTPtlZQ81Nhah/5pepTCMaR0CS6NvyTboVae/Ljl8OrduDaxHGIeUPB8BQw== 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)(366004)(39850400004)(376002)(396003)(346002)(451199015)(2616005)(38100700002)(38350700002)(86362001)(6486002)(478600001)(8936002)(83380400001)(5660300002)(6506007)(26005)(6512007)(316002)(6666004)(2906002)(30864003)(6916009)(41300700001)(8676002)(36756003)(52116002)(44832011)(186003)(66476007)(66556008)(66946007)(4326008)(1076003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: aOrqFtmzgP1KU2l7v0JMVLDSncBcykyxP7MfIyWDUZBRp3iEClvs3rd4raIo7H1dQzI25DX51cxrZHgwHnG5wJkx0JSzsz0sCJHXH5InQjlk78KTMDHq1ZgL4uDZ+fwVZBN8za7a/xQIaQJnw+gopkZsm3ZyaxCH9+12OH7lcL+KNVigCm2YuSPtyW8Mi2ngQg3BgGFDLeJ3JJl9h7QajgUlXOZ/z4L8xYoS9bKJ4RbmFfDOBo7I/adxmWzUx6Sm+V3OYAGeO754l3jlf1rIj19EimdVrjrutsvGVqw5lcmRhzGsGxzUYVsQnOeui0+nSzga2Kdn7BKFso1hPkaHHhNMCftIjXaGBBNoYyYtI5b2M/d8pOXKk6PukQFWvLOOZmCNkxsoNjwi0i5hlWuwdK1mujaKVlqBqf9uAuHsGBjBut1N630xT3MrY3x2q3q4mixelqTxS7GXIB5324PyeTdy2We03waNjHbbcVmFxwIBRj7pmRy7HN1JGUv8VIAlRGXjk/5sSLDIcJCi9FMQ3dNtoDBAA1CjYymdoDn2+Sgm8JtKyg7s5FC2hmN70lAgaslAB1/Lt7UD704Q6vUZidNGZwNPuvXiQ/TQmqucUwYgqWXagxZ2RqiBowq5OFABlN97gtlDqeVoEMgFPX8CZnxjTTWPWrAjM2fbRxVrKJwZXcUeL0+7o7DPQPJ8Ms95yVOYwnsNRAqB5CN1MCCcB2GcUDYImp4yip+4HDz8ranaUg7ijijJepqyklCTaUcqN8TJ4AXd9rjYEFEe4SbsNFVTtD/2nDDQNMmZbPoglbumh9yB5WB7B+LrzB3eKzCdDwzXa2l4dmDcS5xDRaGj+LXnTfr98kj43W3hHoocrxQnx5/uhrOfKVp0DVszAU9ThAjwFyiOAFsU8XP9xi9UVWOL1NCTIrUTv1Dfy8Xyk/3VU6hIe+BP6UxF/wx0kNmO/u8yhyOctXmUG0/xTUjRLF7+PqaSjQVsQ4l1FnfFtMipQPGU9DG9b2JrUb+u5MAahav9VEYfAV6Yncg8Th15zlk2W6PJYaKzm1+LZzPBR5FKLSmgFZaTDMSoa6wn8zeWSu+PA66G8uh7L3fdUdyuko1tQLgqwAFheC3MnMWe4bUSfbRu4EksUGvoltqZMtq/HOn63HlNM3CLtcOPKxc9cQXRAmmIZYtZzw5LnAKhfVkYJ10zeYxuP0SIqxQ1i6w338w8xVYs1YXcewvaDknH82l+D/W8b8DlwKI6Fru4qFh1tMEVDhDYdZGEmJybMw7Jj1QWTN/WOVUDhAYu+LN9QpH75fcXff65fRFOacgctlUzEbathdNMGKewUJ1KqruMR363YpDYKv9Q2O/d1IPU1r8P9+RUQePTIwOyLHnS4FZdf7QxK3QTxHEhoQEDgEGRfaL/Or4T4u9VGhRoDE7jkrMutxSfxJoLqBTxBM6dqyM7nQznF+adqlCGXptTd2UKAtreg1tbees46mSvEGRIxjnVYvuKZcEdA7XOSR5jDY4iqw/wuImm7GAjBjfyYiBcb0gyGFU0w2moxG37Nv561APTk2FBChHz2V/cyIHGskz8zugW+1lRNBI9q+ubQE7ZGY3WmE6OfXox06kVl7ihRbdPYFy5w0/r8+X4bAynbhM= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 23bd9cbb-5235-4637-0c57-08daa1ef9987 X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Sep 2022 07:52:47.3398 (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: wQwX/If6bE2xRAhnDhX/lWOBlVVuYir+f/N/wZ7/jvuLaDhha0UGT9H9WRlwnPUPy6AEAGmIZGkc1MoR+y1OjNmAWGhTomamD+CpKWZANN0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR08MB9509 Received-SPF: pass client-ip=40.107.6.106; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR04-DB3-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. Signed-off-by: Alexander Ivanov Reviewed-by: Marc-André Lureau --- qga/commands-common.h | 35 +++++ qga/commands-linux.c | 286 +++++++++++++++++++++++++++++++++++++++++ qga/commands-posix.c | 289 +++--------------------------------------- qga/meson.build | 3 + 4 files changed, 340 insertions(+), 273 deletions(-) create mode 100644 qga/commands-linux.c diff --git a/qga/commands-common.h b/qga/commands-common.h index d0e4a9696f..181fc330aa 100644 --- a/qga/commands-common.h +++ b/qga/commands-common.h @@ -10,6 +10,40 @@ #define QGA_COMMANDS_COMMON_H #include "qga-qapi-types.h" +#include "guest-agent-core.h" +#include "qemu/queue.h" + +#if defined(__linux__) +#include +#ifdef FIFREEZE +#define CONFIG_FSFREEZE +#endif +#ifdef FITRIM +#define CONFIG_FSTRIM +#endif +#endif /* __linux__ */ + +#if defined(CONFIG_FSFREEZE) || defined(CONFIG_FSTRIM) +typedef struct FsMount { + char *dirname; + char *devtype; + unsigned int devmajor, devminor; + QTAILQ_ENTRY(FsMount) next; +} FsMount; + +typedef QTAILQ_HEAD(FsMountList, FsMount) FsMountList; + +bool build_fs_mount_list(FsMountList *mounts, Error **errp); +void free_fs_mount_list(FsMountList *mounts); +#endif /* CONFIG_FSFREEZE || CONFIG_FSTRIM */ + +#if defined(CONFIG_FSFREEZE) +int64_t qmp_guest_fsfreeze_do_freeze_list(bool has_mountpoints, + strList *mountpoints, + FsMountList mounts, + Error **errp); +int qmp_guest_fsfreeze_do_thaw(Error **errp); +#endif /* CONFIG_FSFREEZE */ typedef struct GuestFileHandle GuestFileHandle; @@ -29,4 +63,5 @@ GuestFileRead *guest_file_read_unsafe(GuestFileHandle *gfh, */ char *qga_get_host_name(Error **errp); +void ga_wait_child(pid_t pid, int *status, Error **errp); #endif diff --git a/qga/commands-linux.c b/qga/commands-linux.c new file mode 100644 index 0000000000..214e408fcd --- /dev/null +++ b/qga/commands-linux.c @@ -0,0 +1,286 @@ +/* + * QEMU Guest Agent Linux-specific command implementations + * + * Copyright IBM Corp. 2011 + * + * Authors: + * Michael Roth + * Michal Privoznik + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "commands-common.h" +#include "cutils.h" +#include +#include + +#if defined(CONFIG_FSFREEZE) || defined(CONFIG_FSTRIM) +static int dev_major_minor(const char *devpath, + unsigned int *devmajor, unsigned int *devminor) +{ + struct stat st; + + *devmajor = 0; + *devminor = 0; + + if (stat(devpath, &st) < 0) { + slog("failed to stat device file '%s': %s", devpath, strerror(errno)); + return -1; + } + if (S_ISDIR(st.st_mode)) { + /* It is bind mount */ + return -2; + } + if (S_ISBLK(st.st_mode)) { + *devmajor = major(st.st_rdev); + *devminor = minor(st.st_rdev); + return 0; + } + return -1; +} + +static bool build_fs_mount_list_from_mtab(FsMountList *mounts, Error **errp) +{ + struct mntent *ment; + FsMount *mount; + char const *mtab = "/proc/self/mounts"; + FILE *fp; + unsigned int devmajor, devminor; + + fp = setmntent(mtab, "r"); + if (!fp) { + error_setg(errp, "failed to open mtab file: '%s'", mtab); + return false; + } + + while ((ment = getmntent(fp))) { + /* + * An entry which device name doesn't start with a '/' is + * either a dummy file system or a network file system. + * Add special handling for smbfs and cifs as is done by + * coreutils as well. + */ + if ((ment->mnt_fsname[0] != '/') || + (strcmp(ment->mnt_type, "smbfs") == 0) || + (strcmp(ment->mnt_type, "cifs") == 0)) { + continue; + } + if (dev_major_minor(ment->mnt_fsname, &devmajor, &devminor) == -2) { + /* Skip bind mounts */ + continue; + } + + mount = g_new0(FsMount, 1); + mount->dirname = g_strdup(ment->mnt_dir); + mount->devtype = g_strdup(ment->mnt_type); + mount->devmajor = devmajor; + mount->devminor = devminor; + + QTAILQ_INSERT_TAIL(mounts, mount, next); + } + + endmntent(fp); + return true; +} + +static void decode_mntname(char *name, int len) +{ + int i, j = 0; + for (i = 0; i <= len; i++) { + if (name[i] != '\\') { + name[j++] = name[i]; + } else if (name[i + 1] == '\\') { + name[j++] = '\\'; + i++; + } else if (name[i + 1] >= '0' && name[i + 1] <= '3' && + name[i + 2] >= '0' && name[i + 2] <= '7' && + name[i + 3] >= '0' && name[i + 3] <= '7') { + name[j++] = (name[i + 1] - '0') * 64 + + (name[i + 2] - '0') * 8 + + (name[i + 3] - '0'); + i += 3; + } else { + name[j++] = name[i]; + } + } +} + +/* + * Walk the mount table and build a list of local file systems + */ +bool build_fs_mount_list(FsMountList *mounts, Error **errp) +{ + FsMount *mount; + char const *mountinfo = "/proc/self/mountinfo"; + FILE *fp; + char *line = NULL, *dash; + size_t n; + char check; + unsigned int devmajor, devminor; + int ret, dir_s, dir_e, type_s, type_e, dev_s, dev_e; + + fp = fopen(mountinfo, "r"); + if (!fp) { + return build_fs_mount_list_from_mtab(mounts, errp); + } + + while (getline(&line, &n, fp) != -1) { + ret = sscanf(line, "%*u %*u %u:%u %*s %n%*s%n%c", + &devmajor, &devminor, &dir_s, &dir_e, &check); + if (ret < 3) { + continue; + } + dash = strstr(line + dir_e, " - "); + if (!dash) { + continue; + } + ret = sscanf(dash, " - %n%*s%n %n%*s%n%c", + &type_s, &type_e, &dev_s, &dev_e, &check); + if (ret < 1) { + continue; + } + line[dir_e] = 0; + dash[type_e] = 0; + dash[dev_e] = 0; + decode_mntname(line + dir_s, dir_e - dir_s); + decode_mntname(dash + dev_s, dev_e - dev_s); + if (devmajor == 0) { + /* btrfs reports major number = 0 */ + if (strcmp("btrfs", dash + type_s) != 0 || + dev_major_minor(dash + dev_s, &devmajor, &devminor) < 0) { + continue; + } + } + + mount = g_new0(FsMount, 1); + mount->dirname = g_strdup(line + dir_s); + mount->devtype = g_strdup(dash + type_s); + mount->devmajor = devmajor; + mount->devminor = devminor; + + QTAILQ_INSERT_TAIL(mounts, mount, next); + } + free(line); + + fclose(fp); + return true; +} +#endif /* CONFIG_FSFREEZE || CONFIG_FSTRIM */ + +#ifdef CONFIG_FSFREEZE +/* + * Walk list of mounted file systems in the guest, and freeze the ones which + * are real local file systems. + */ +int64_t qmp_guest_fsfreeze_do_freeze_list(bool has_mountpoints, + strList *mountpoints, + FsMountList mounts, + Error **errp) +{ + struct FsMount *mount; + strList *list; + int fd, ret, i = 0; + + QTAILQ_FOREACH_REVERSE(mount, &mounts, next) { + /* To issue fsfreeze in the reverse order of mounts, check if the + * mount is listed in the list here */ + if (has_mountpoints) { + for (list = mountpoints; list; list = list->next) { + if (strcmp(list->value, mount->dirname) == 0) { + break; + } + } + if (!list) { + continue; + } + } + + fd = qga_open_cloexec(mount->dirname, O_RDONLY, 0); + if (fd == -1) { + error_setg_errno(errp, errno, "failed to open %s", mount->dirname); + return -1; + } + + /* we try to cull filesystems we know won't work in advance, but other + * filesystems may not implement fsfreeze for less obvious reasons. + * these will report EOPNOTSUPP. we simply ignore these when tallying + * the number of frozen filesystems. + * if a filesystem is mounted more than once (aka bind mount) a + * consecutive attempt to freeze an already frozen filesystem will + * return EBUSY. + * + * any other error means a failure to freeze a filesystem we + * expect to be freezable, so return an error in those cases + * and return system to thawed state. + */ + ret = ioctl(fd, FIFREEZE); + if (ret == -1) { + if (errno != EOPNOTSUPP && errno != EBUSY) { + error_setg_errno(errp, errno, "failed to freeze %s", + mount->dirname); + close(fd); + return -1; + } + } else { + i++; + } + close(fd); + } + return i; +} + +int qmp_guest_fsfreeze_do_thaw(Error **errp) +{ + int ret; + FsMountList mounts; + FsMount *mount; + int fd, i = 0, logged; + Error *local_err = NULL; + + QTAILQ_INIT(&mounts); + if (!build_fs_mount_list(&mounts, &local_err)) { + error_propagate(errp, local_err); + return -1; + } + + QTAILQ_FOREACH(mount, &mounts, next) { + logged = false; + fd = qga_open_cloexec(mount->dirname, O_RDONLY, 0); + if (fd == -1) { + continue; + } + /* we have no way of knowing whether a filesystem was actually unfrozen + * as a result of a successful call to FITHAW, only that if an error + * was returned the filesystem was *not* unfrozen by that particular + * call. + * + * since multiple preceding FIFREEZEs require multiple calls to FITHAW + * to unfreeze, continuing issuing FITHAW until an error is returned, + * in which case either the filesystem is in an unfreezable state, or, + * more likely, it was thawed previously (and remains so afterward). + * + * also, since the most recent successful call is the one that did + * the actual unfreeze, we can use this to provide an accurate count + * of the number of filesystems unfrozen by guest-fsfreeze-thaw, which + * may * be useful for determining whether a filesystem was unfrozen + * during the freeze/thaw phase by a process other than qemu-ga. + */ + do { + ret = ioctl(fd, FITHAW); + if (ret == 0 && !logged) { + i++; + logged = true; + } + } while (ret == 0); + close(fd); + } + + free_fs_mount_list(&mounts); + + return i; +} +#endif /* CONFIG_FSFREEZE */ diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 16d67e9f6d..9574b83c92 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -16,11 +16,9 @@ #include #include #include -#include "guest-agent-core.h" #include "qga-qapi-commands.h" #include "qapi/error.h" #include "qapi/qmp/qerror.h" -#include "qemu/queue.h" #include "qemu/host-utils.h" #include "qemu/sockets.h" #include "qemu/base64.h" @@ -70,7 +68,7 @@ #endif #endif -static void ga_wait_child(pid_t pid, int *status, Error **errp) +void ga_wait_child(pid_t pid, int *status, Error **errp) { pid_t rpid; @@ -629,16 +627,7 @@ void qmp_guest_file_flush(int64_t handle, Error **errp) #if defined(__linux__) #if defined(CONFIG_FSFREEZE) || defined(CONFIG_FSTRIM) -typedef struct FsMount { - char *dirname; - char *devtype; - unsigned int devmajor, devminor; - QTAILQ_ENTRY(FsMount) next; -} FsMount; - -typedef QTAILQ_HEAD(FsMountList, FsMount) FsMountList; - -static void free_fs_mount_list(FsMountList *mounts) +void free_fs_mount_list(FsMountList *mounts) { FsMount *mount, *temp; @@ -653,157 +642,6 @@ static void free_fs_mount_list(FsMountList *mounts) g_free(mount); } } - -static int dev_major_minor(const char *devpath, - unsigned int *devmajor, unsigned int *devminor) -{ - struct stat st; - - *devmajor = 0; - *devminor = 0; - - if (stat(devpath, &st) < 0) { - slog("failed to stat device file '%s': %s", devpath, strerror(errno)); - return -1; - } - if (S_ISDIR(st.st_mode)) { - /* It is bind mount */ - return -2; - } - if (S_ISBLK(st.st_mode)) { - *devmajor = major(st.st_rdev); - *devminor = minor(st.st_rdev); - return 0; - } - return -1; -} - -/* - * Walk the mount table and build a list of local file systems - */ -static bool build_fs_mount_list_from_mtab(FsMountList *mounts, Error **errp) -{ - struct mntent *ment; - FsMount *mount; - char const *mtab = "/proc/self/mounts"; - FILE *fp; - unsigned int devmajor, devminor; - - fp = setmntent(mtab, "r"); - if (!fp) { - error_setg(errp, "failed to open mtab file: '%s'", mtab); - return false; - } - - while ((ment = getmntent(fp))) { - /* - * An entry which device name doesn't start with a '/' is - * either a dummy file system or a network file system. - * Add special handling for smbfs and cifs as is done by - * coreutils as well. - */ - if ((ment->mnt_fsname[0] != '/') || - (strcmp(ment->mnt_type, "smbfs") == 0) || - (strcmp(ment->mnt_type, "cifs") == 0)) { - continue; - } - if (dev_major_minor(ment->mnt_fsname, &devmajor, &devminor) == -2) { - /* Skip bind mounts */ - continue; - } - - mount = g_new0(FsMount, 1); - mount->dirname = g_strdup(ment->mnt_dir); - mount->devtype = g_strdup(ment->mnt_type); - mount->devmajor = devmajor; - mount->devminor = devminor; - - QTAILQ_INSERT_TAIL(mounts, mount, next); - } - - endmntent(fp); - return true; -} - -static void decode_mntname(char *name, int len) -{ - int i, j = 0; - for (i = 0; i <= len; i++) { - if (name[i] != '\\') { - name[j++] = name[i]; - } else if (name[i + 1] == '\\') { - name[j++] = '\\'; - i++; - } else if (name[i + 1] >= '0' && name[i + 1] <= '3' && - name[i + 2] >= '0' && name[i + 2] <= '7' && - name[i + 3] >= '0' && name[i + 3] <= '7') { - name[j++] = (name[i + 1] - '0') * 64 + - (name[i + 2] - '0') * 8 + - (name[i + 3] - '0'); - i += 3; - } else { - name[j++] = name[i]; - } - } -} - -static bool build_fs_mount_list(FsMountList *mounts, Error **errp) -{ - FsMount *mount; - char const *mountinfo = "/proc/self/mountinfo"; - FILE *fp; - char *line = NULL, *dash; - size_t n; - char check; - unsigned int devmajor, devminor; - int ret, dir_s, dir_e, type_s, type_e, dev_s, dev_e; - - fp = fopen(mountinfo, "r"); - if (!fp) { - return build_fs_mount_list_from_mtab(mounts, errp); - } - - while (getline(&line, &n, fp) != -1) { - ret = sscanf(line, "%*u %*u %u:%u %*s %n%*s%n%c", - &devmajor, &devminor, &dir_s, &dir_e, &check); - if (ret < 3) { - continue; - } - dash = strstr(line + dir_e, " - "); - if (!dash) { - continue; - } - ret = sscanf(dash, " - %n%*s%n %n%*s%n%c", - &type_s, &type_e, &dev_s, &dev_e, &check); - if (ret < 1) { - continue; - } - line[dir_e] = 0; - dash[type_e] = 0; - dash[dev_e] = 0; - decode_mntname(line + dir_s, dir_e - dir_s); - decode_mntname(dash + dev_s, dev_e - dev_s); - if (devmajor == 0) { - /* btrfs reports major number = 0 */ - if (strcmp("btrfs", dash + type_s) != 0 || - dev_major_minor(dash + dev_s, &devmajor, &devminor) < 0) { - continue; - } - } - - mount = g_new0(FsMount, 1); - mount->dirname = g_strdup(line + dir_s); - mount->devtype = g_strdup(dash + type_s); - mount->devmajor = devmajor; - mount->devminor = devminor; - - QTAILQ_INSERT_TAIL(mounts, mount, next); - } - free(line); - - fclose(fp); - return true; -} #endif #if defined(CONFIG_FSFREEZE) @@ -1708,20 +1546,13 @@ int64_t qmp_guest_fsfreeze_freeze(Error **errp) return qmp_guest_fsfreeze_freeze_list(false, NULL, errp); } -/* - * Walk list of mounted file systems in the guest, and freeze the ones which - * are real local file systems. - */ int64_t qmp_guest_fsfreeze_freeze_list(bool has_mountpoints, strList *mountpoints, Error **errp) { - int ret = 0, i = 0; - strList *list; + int ret; FsMountList mounts; - struct FsMount *mount; Error *local_err = NULL; - int fd; slog("guest-fsfreeze called"); @@ -1740,122 +1571,34 @@ int64_t qmp_guest_fsfreeze_freeze_list(bool has_mountpoints, /* cannot risk guest agent blocking itself on a write in this state */ ga_set_frozen(ga_state); - QTAILQ_FOREACH_REVERSE(mount, &mounts, next) { - /* To issue fsfreeze in the reverse order of mounts, check if the - * mount is listed in the list here */ - if (has_mountpoints) { - for (list = mountpoints; list; list = list->next) { - if (strcmp(list->value, mount->dirname) == 0) { - break; - } - } - if (!list) { - continue; - } - } - - fd = qga_open_cloexec(mount->dirname, O_RDONLY, 0); - if (fd == -1) { - error_setg_errno(errp, errno, "failed to open %s", mount->dirname); - goto error; - } - - /* we try to cull filesystems we know won't work in advance, but other - * filesystems may not implement fsfreeze for less obvious reasons. - * these will report EOPNOTSUPP. we simply ignore these when tallying - * the number of frozen filesystems. - * if a filesystem is mounted more than once (aka bind mount) a - * consecutive attempt to freeze an already frozen filesystem will - * return EBUSY. - * - * any other error means a failure to freeze a filesystem we - * expect to be freezable, so return an error in those cases - * and return system to thawed state. - */ - ret = ioctl(fd, FIFREEZE); - if (ret == -1) { - if (errno != EOPNOTSUPP && errno != EBUSY) { - error_setg_errno(errp, errno, "failed to freeze %s", - mount->dirname); - close(fd); - goto error; - } - } else { - i++; - } - close(fd); - } + ret = qmp_guest_fsfreeze_do_freeze_list(has_mountpoints, mountpoints, + mounts, errp); free_fs_mount_list(&mounts); /* We may not issue any FIFREEZE here. * Just unset ga_state here and ready for the next call. */ - if (i == 0) { + if (ret == 0) { ga_unset_frozen(ga_state); + } else if (ret < 0) { + qmp_guest_fsfreeze_thaw(NULL); } - return i; - -error: - free_fs_mount_list(&mounts); - qmp_guest_fsfreeze_thaw(NULL); - return 0; + return ret; } -/* - * Walk list of frozen file systems in the guest, and thaw them. - */ int64_t qmp_guest_fsfreeze_thaw(Error **errp) { int ret; - FsMountList mounts; - FsMount *mount; - int fd, i = 0, logged; - Error *local_err = NULL; - QTAILQ_INIT(&mounts); - if (!build_fs_mount_list(&mounts, &local_err)) { - error_propagate(errp, local_err); - return 0; + ret = qmp_guest_fsfreeze_do_thaw(errp); + if (ret >= 0) { + ga_unset_frozen(ga_state); + execute_fsfreeze_hook(FSFREEZE_HOOK_THAW, errp); + } else { + ret = 0; } - QTAILQ_FOREACH(mount, &mounts, next) { - logged = false; - fd = qga_open_cloexec(mount->dirname, O_RDONLY, 0); - if (fd == -1) { - continue; - } - /* we have no way of knowing whether a filesystem was actually unfrozen - * as a result of a successful call to FITHAW, only that if an error - * was returned the filesystem was *not* unfrozen by that particular - * call. - * - * since multiple preceding FIFREEZEs require multiple calls to FITHAW - * to unfreeze, continuing issuing FITHAW until an error is returned, - * in which case either the filesystem is in an unfreezable state, or, - * more likely, it was thawed previously (and remains so afterward). - * - * also, since the most recent successful call is the one that did - * the actual unfreeze, we can use this to provide an accurate count - * of the number of filesystems unfrozen by guest-fsfreeze-thaw, which - * may * be useful for determining whether a filesystem was unfrozen - * during the freeze/thaw phase by a process other than qemu-ga. - */ - do { - ret = ioctl(fd, FITHAW); - if (ret == 0 && !logged) { - i++; - logged = true; - } - } while (ret == 0); - close(fd); - } - - ga_unset_frozen(ga_state); - free_fs_mount_list(&mounts); - - execute_fsfreeze_hook(FSFREEZE_HOOK_THAW, errp); - - return i; + return ret; } static void guest_fsfreeze_cleanup(void) diff --git a/qga/meson.build b/qga/meson.build index 65c1e93846..409f49a000 100644 --- a/qga/meson.build +++ b/qga/meson.build @@ -72,6 +72,9 @@ qga_ss.add(when: 'CONFIG_POSIX', if_true: files( 'commands-posix.c', 'commands-posix-ssh.c', )) +qga_ss.add(when: 'CONFIG_LINUX', if_true: files( + 'commands-linux.c', +)) qga_ss.add(when: 'CONFIG_WIN32', if_true: files( 'channel-win32.c', 'commands-win32.c', From patchwork Thu Sep 29 07:52:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 12993688 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 52E2CC04A95 for ; Thu, 29 Sep 2022 08:15:36 +0000 (UTC) Received: from localhost ([::1]:55950 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1odohi-0001JT-VQ for qemu-devel@archiver.kernel.org; Thu, 29 Sep 2022 04:15:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33256) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odoMQ-0005N7-BD for qemu-devel@nongnu.org; Thu, 29 Sep 2022 03:53:39 -0400 Received: from mail-eopbgr60106.outbound.protection.outlook.com ([40.107.6.106]:26178 helo=EUR04-DB3-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 1odoMN-0000p0-W6 for qemu-devel@nongnu.org; Thu, 29 Sep 2022 03:53:34 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mt2Xt4GUY4u8inODNHwI5nYV4jUY6m3FUUL9O+SZ5f9I+d2fzx+u3mnuJBqNaeETWbUgxj+7DFgaKuiw24G9iqNKfsQJHh5yZi+71EWakLz0eG0NUGBI/xc2GtUWH1qLAbF3n7ddZhL0ujEOLVN4okfhC0f38iXVrjesM1+aBBL6Ond7SUsLWir/udcMlzALTIQaR0PtGKxASe3T13V6FUsyEqF0Od8gz0HalRRYu1sM8L7HtQREIAJBColnIMADvYoqixU+o9pYqpR/wMUCTWMHUYrdxG3OQMtVWjQk2IiSBmOVRMUxY6YERnj0USjZe+S02YuS8nG89mckHz75RQ== 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=gV04v505/VaveTt2QFQG0nOmZ5puqbO6INppFCEbxXI=; b=GV5xu/EPR45jW4Hgddq9of5Tgx3W7yX9Lgj2nrv3hMKrYAEPQho7pzns7lZQUh3NI3s9IKyT1nR0evrHLM8UgqhzEOh91p8yfX5IEn00tG1hNsJdLnwoPTldAmyEpZ/HN5nPm0DRjJV3Tb4En2veHoxecuqnKGA5IJ6eQSFE/TXnuoGiMzu4/vArPaX9+HHbCQOPxTAEv9U4Shwt5MWn3vlimUTWyS4YCqHd9oiR/I0XDFm7oGUudHtVozH7Q0Qx184Kc1bGVnCF+7DRk6q2J201jB2gcuwd355V0j0PkG6x+wQdlAXWqGyRpSe/qhWv4qj9oJ7kVNF5bA8uf2nTOw== 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=gV04v505/VaveTt2QFQG0nOmZ5puqbO6INppFCEbxXI=; b=Z1cZaWkY6UtGX9qdbuJshIiX9qvmbLXkaEKF6933XUpANkuHDyWE9AdcglPsShfcSJrtclFPtI9Nv49jd8avyCKha2LUR75ACblVToP7HPg885uTwR3drHhw1lIpW1KdoYeriAsoBwUnGIEGE2Nd7kc2saV/TPZCbTdPmHabVVMMiKOpqZVHb4Y6lwZM1yLrlLdgkpuPKNKRkS72XrHd0qoUwI+ImwReAoDPVeMdSzv6qXgkFVViNLIa+OeDg9T56tk0QzIPgayfSF8D7K5nSZ53qUtchRjXV/DYlPyn8nm4L+WDinM6/GzB7rhydlB6vnMgcGG8KHePif3rUdG3dA== 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 DU0PR08MB9509.eurprd08.prod.outlook.com (2603:10a6:10:44f::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.25; Thu, 29 Sep 2022 07:52:48 +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.020; Thu, 29 Sep 2022 07:52:48 +0000 From: Alexander Ivanov To: qemu-devel@nongnu.org Cc: den@virtuozzo.com, michael.roth@amd.com, kkostiuk@redhat.com Subject: [PATCH 3/7] qga: Add UFS freeze/thaw support for FreeBSD Date: Thu, 29 Sep 2022 09:52:35 +0200 Message-Id: <20220929075239.1675374-4-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220929075239.1675374-1-alexander.ivanov@virtuozzo.com> References: <20220929075239.1675374-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: AS9PR0301CA0039.eurprd03.prod.outlook.com (2603:10a6:20b:469::8) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR08MB7095:EE_|DU0PR08MB9509:EE_ X-MS-Office365-Filtering-Correlation-Id: c7037c03-6799-4da7-a3e6-08daa1ef99e1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HlUt2FC7wRqOURFFOtrtGCwjn0vHXgvyarHf5mA2Q6Agf2QYmbqpzRBhD0R2XCn3gFLiGAUZ9CZPvL/dxN4AVeUbsZVNEHTec8JBwCy1kG0luBESu48TvR8169JoOzmGvC++nh5+txlzZ6qB4kdjyugL3VmU5Ov6HdU1NMUB873I5FjsQRDCnEarbfXEo+2UCNRO8ZwTboB9I5+UzN0wmRQnAe5dynXgT5gTkA57p/th8gAHhDG/xEDmxVQTkEdC22AylrHFEzT4JyTPIpa0qAG2yDwBjlMqrYg0/o5UsXFSaNg1jxSQnu5ObCz9/1OjVEDj5Kjic3OXDTTzGDEJ1OoP2IQnJNnS9YmvtNqq6cD3/z/YiQmUKi8dbjIxr9E1iSxUf0ZRNWr+spqswLxwt9IKAC78JqTHnjzJGJQWNHUOfvoKI1LeFY5rWieUJr98f31XG2yd/3ckj+g8LR77EPlxcVkMGhUokaRF6gtxikPFTLNX0lwJYn3+QhufoGaKWiB1gFpTj3kbYyCDnQtAcUEfN6EQ6sV4bfUDPk+9CPLdx4BsjRJr2CRqu9FqqXsN07i2cJrn3vdoaLMlv7rxKIuWw2HAIl2KdUFmrMu6hrBsAD4/e2S3umMzdDxm5WMLEMlKIvijRhGkfn58XIEktATGMw5/KMOMrs1iOvkfebgRAi/O2rlsrB9bwtd5J5JYvx4+Odm20/lWEf/51B9p8YvKEiuVwnF3AP3XszfM3iBDTuz5Hi71bCP9SXxh5E1ZqFfGSZsaE5LVdn8nr/jQ7Q== 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)(366004)(39850400004)(376002)(396003)(346002)(451199015)(2616005)(38100700002)(38350700002)(86362001)(6486002)(478600001)(8936002)(83380400001)(5660300002)(6506007)(26005)(6512007)(316002)(6666004)(2906002)(30864003)(6916009)(41300700001)(8676002)(36756003)(52116002)(44832011)(186003)(66476007)(66556008)(66946007)(4326008)(1076003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 38u2S/5K572VLIYKYE3HB8lbptsc+m0yaCD0Iel0JVTHb603DtLnfYTVQQ7e6Cvq7fjGbA2bvW5HnoYIg9gGP6RkAD7vngvZ3hYNDJV5dz4EcAh4gU+18iPClpjFeAJ4ko23RTwfTDbhN9htFFMROboH0RnXpM2dgLUyLwREMlFrPeLe/Tm9Zjs+0dNrmZj9nkelmdE8T5igvMrQVhCY3RPCpINo1Id9LCV1vwL+XAdEBKpaDXo+EW9nn9YAXpTfp4nY5/p6pM08IavgRRfexa8wAhHDx75FbNKQrBYkFbr4kBfRGrIM1veGhUi2d4KwBa3w4Iuk/yHtrHa7NKxOCejwPBwOiOnhMw24mbiJw8eaZs5H+6q2UYQxh5AUo+s18UfcWCakpgXqtv66kzXx9hfz0SkLH3mXrZNcOtB0fotOwtWLo7q0tu2klQ9xWvf4i5twVM4t6xsa96l/0HkAWEBg6vBr8yJ5nVDjBagi1L4R09HuoHcjWtQy8u3+LGs5O1y9AyUQsFZrB7086xCdDwN++0oVZ2zphXPtRKF97JsvE0C8TQYwz82IF3Q081HmKyWGPl5TXQ3KUd4oy0tjmCmKo4Wf9vRLB910cfDNkBjn/9+ubAh9lfObSTDMi7nEaUWerwdmXRU/pxqyo3wKIMVwVcxJgDRSfXpipl+YTnQEWBG2t9IZscvZAXUhGD9YXMBISHwEchaE6tbdd898BURlqdHIuv3pVsoWF8pJDO9Du0WEJwqFn/igjjFb4jeykx6BbCukuF4ZQzy/Yu9MHp5tboyV1Kpr6J0QMn1glwcGZdMQRw/AlI/KkccM2qFQSoc2B9j+acQqoKaltk4fX5NxhpUAX/NYU+Z4U5wbmtRlm9NNOK6PmCY41C5IkFHMUz0v9+XrFncC3uH/uVM2LDd/3bVCcOdGg6m5h3IEW52tVmGp9SHZSGuCEi74gYdgFb1mmbT9VCPJ4T0I6EY4o47qJ208UNKEvX/FAek9MjVnWl0uQr0DdU0wFzd15nlgN5eWFiJGTqXsjRDn1wTwfqu19wY/+C1has75G0TkxjtAME+eqyNQrOK8zPD89AJM5sEPzWNdt6k0gj5LTXWdMLc/exTae9036k4+KH60DlWnQVxw/sm0ru3nBiWpjV9US57wd8Pd7WVmruY40CtLZZL3E2yI37JRpO0cVIkihocyziAYgPOoDTGmAlo8ookOnFego1G4dfGRDDbA0YIJTEInF7RBSYcVSmUvKUJjCw2v5QURhuyP7mNWa4daoI9laGYQCj3q2Ahr2NvGAgHFOfpR776qWRlx4OGR2BYdRcTI30maqT5BEQMDzFpXKbV+RE8+Lztm6iDgsdrshofPLj+GntB+ZnYza1i9FGAn3bNP6XbDMb1knieEYkgBxp9GAM7Q+h6rt7jud0+YgMCR2gZHfVVV4kF50I5jGX2hamr1sFsMOtXMoEo4OcmJl/nKaMHgKEnNYUF/KcrZ18CAZuQsc6S1N9neKGkskBigFyisW6HA/3hu4OtMgLJ5lIZMU0fuedAQYFebYgTFHOFpLzXjsVrZLGO5j+griB506VmwrMGIhSOW3Yi3NEX2Tf+dbh8EslyhB2yCJegzi2NanEovMEMMMqnOp2r1Jwq4IxA= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: c7037c03-6799-4da7-a3e6-08daa1ef99e1 X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Sep 2022 07:52:47.9022 (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: PKKKIRpGw7yAqCys00hIOxp1M/VmhbB4qXDSBfSRTobNOH47UpQTW1JT0XLbuLeHPULitnLE9+kZ+wdGhKsf/f4/ZzpdOfUbnNOOsIZjxGE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR08MB9509 Received-SPF: pass client-ip=40.107.6.106; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR04-DB3-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" UFS supports FS freezing through ioctl UFSSUSPEND on /dev/ufssuspend. Frozen FS can be thawed by closing /dev/ufssuspend file descriptior. Use getmntinfo to get a list of mounted FS. Signed-off-by: Alexander Ivanov Reviewed-by: Marc-André Lureau --- qga/commands-bsd.c | 169 +++++++++++++++++++++++ qga/commands-common.h | 11 ++ qga/commands-posix.c | 308 ++++++++++++++++++++---------------------- qga/main.c | 7 +- qga/meson.build | 3 + 5 files changed, 334 insertions(+), 164 deletions(-) create mode 100644 qga/commands-bsd.c diff --git a/qga/commands-bsd.c b/qga/commands-bsd.c new file mode 100644 index 0000000000..ca06692179 --- /dev/null +++ b/qga/commands-bsd.c @@ -0,0 +1,169 @@ +/* + * QEMU Guest Agent BSD-specific command implementations + * + * Copyright (c) Virtuozzo International GmbH. + * + * Authors: + * Alexander Ivanov + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "qga-qapi-commands.h" +#include "qapi/qmp/qerror.h" +#include "qapi/error.h" +#include "qemu/queue.h" +#include "commands-common.h" +#include +#include +#include +#include +#include + +#if defined(CONFIG_FSFREEZE) || defined(CONFIG_FSTRIM) +bool build_fs_mount_list(FsMountList *mounts, Error **errp) +{ + FsMount *mount; + struct statfs *mntbuf, *mntp; + struct stat statbuf; + int i, count, ret; + + count = getmntinfo(&mntbuf, MNT_NOWAIT); + if (count == 0) { + error_setg_errno(errp, errno, "getmntinfo failed"); + return false; + } + + for (i = 0; i < count; i++) { + mntp = &mntbuf[i]; + ret = stat(mntp->f_mntonname, &statbuf); + if (ret != 0) { + error_setg_errno(errp, errno, "stat failed on %s", + mntp->f_mntonname); + return false; + } + + mount = g_new0(FsMount, 1); + + mount->dirname = g_strdup(mntp->f_mntonname); + mount->devtype = g_strdup(mntp->f_fstypename); + mount->devmajor = major(mount->dev); + mount->devminor = minor(mount->dev); + mount->fsid = mntp->f_fsid; + mount->dev = statbuf.st_dev; + + QTAILQ_INSERT_TAIL(mounts, mount, next); + } + return true; +} +#endif /* CONFIG_FSFREEZE || CONFIG_FSTRIM */ + +#if defined(CONFIG_FSFREEZE) +static int ufssuspend_fd = -1; +static int ufssuspend_cnt; + +int64_t qmp_guest_fsfreeze_do_freeze_list(bool has_mountpoints, + strList *mountpoints, + FsMountList mounts, + Error **errp) +{ + int ret; + strList *list; + struct FsMount *mount; + + if (ufssuspend_fd != -1) { + error_setg(errp, "filesystems have already frozen"); + return -1; + } + + ufssuspend_cnt = 0; + ufssuspend_fd = qemu_open(_PATH_UFSSUSPEND, O_RDWR, errp); + if (ufssuspend_fd == -1) { + return -1; + } + + QTAILQ_FOREACH_REVERSE(mount, &mounts, next) { + /* + * To issue fsfreeze in the reverse order of mounts, check if the + * mount is listed in the list here + */ + if (has_mountpoints) { + for (list = mountpoints; list; list = list->next) { + if (g_str_equal(list->value, mount->dirname)) { + break; + } + } + if (!list) { + continue; + } + } + + /* Only UFS supports suspend */ + if (!g_str_equal(mount->devtype, "ufs")) { + continue; + } + + ret = ioctl(ufssuspend_fd, UFSSUSPEND, &mount->fsid); + if (ret == -1) { + /* + * ioctl returns EBUSY for all the FS except the first one + * that was suspended + */ + if (errno == EBUSY) { + continue; + } + error_setg_errno(errp, errno, "failed to freeze %s", + mount->dirname); + goto error; + } + ufssuspend_cnt++; + } + return ufssuspend_cnt; +error: + close(ufssuspend_fd); + ufssuspend_fd = -1; + return -1; + +} + +/* + * We don't need to call UFSRESUME ioctl because all the frozen FS + * are thawed on /dev/ufssuspend closing. + */ +int qmp_guest_fsfreeze_do_thaw(Error **errp) +{ + int ret = ufssuspend_cnt; + ufssuspend_cnt = 0; + if (ufssuspend_fd != -1) { + close(ufssuspend_fd); + ufssuspend_fd = -1; + } + return ret; +} + +GuestFilesystemInfoList *qmp_guest_get_fsinfo(Error **errp) +{ + error_setg(errp, QERR_UNSUPPORTED); + return NULL; +} + +GuestDiskInfoList *qmp_guest_get_disks(Error **errp) +{ + error_setg(errp, QERR_UNSUPPORTED); + return NULL; +} + +GuestDiskStatsInfoList *qmp_guest_get_diskstats(Error **errp) +{ + error_setg(errp, QERR_UNSUPPORTED); + return NULL; +} + +GuestCpuStatsList *qmp_guest_get_cpustats(Error **errp) +{ + error_setg(errp, QERR_UNSUPPORTED); + return NULL; +} +#endif /* CONFIG_FSFREEZE */ diff --git a/qga/commands-common.h b/qga/commands-common.h index 181fc330aa..2d9878a634 100644 --- a/qga/commands-common.h +++ b/qga/commands-common.h @@ -23,11 +23,22 @@ #endif #endif /* __linux__ */ +#ifdef __FreeBSD__ +#include +#ifdef UFSSUSPEND +#define CONFIG_FSFREEZE +#endif +#endif /* __FreeBSD__ */ + #if defined(CONFIG_FSFREEZE) || defined(CONFIG_FSTRIM) typedef struct FsMount { char *dirname; char *devtype; unsigned int devmajor, devminor; +#if defined(__FreeBSD__) + dev_t dev; + fsid_t fsid; +#endif QTAILQ_ENTRY(FsMount) next; } FsMount; diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 9574b83c92..49f9996a9c 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -33,20 +33,12 @@ #if defined(__linux__) #include -#include #include #include #ifdef CONFIG_LIBUDEV #include #endif - -#ifdef FIFREEZE -#define CONFIG_FSFREEZE -#endif -#ifdef FITRIM -#define CONFIG_FSTRIM -#endif #endif #ifdef __FreeBSD__ @@ -623,9 +615,6 @@ void qmp_guest_file_flush(int64_t handle, Error **errp) } } -/* linux-specific implementations. avoid this if at all possible. */ -#if defined(__linux__) - #if defined(CONFIG_FSFREEZE) || defined(CONFIG_FSTRIM) void free_fs_mount_list(FsMountList *mounts) { @@ -644,6 +633,156 @@ void free_fs_mount_list(FsMountList *mounts) } #endif +#if defined(CONFIG_FSFREEZE) +typedef enum { + FSFREEZE_HOOK_THAW = 0, + FSFREEZE_HOOK_FREEZE, +} FsfreezeHookArg; + +static const char *fsfreeze_hook_arg_string[] = { + "thaw", + "freeze", +}; + +static void execute_fsfreeze_hook(FsfreezeHookArg arg, Error **errp) +{ + int status; + pid_t pid; + const char *hook; + const char *arg_str = fsfreeze_hook_arg_string[arg]; + Error *local_err = NULL; + + hook = ga_fsfreeze_hook(ga_state); + if (!hook) { + return; + } + if (access(hook, X_OK) != 0) { + error_setg_errno(errp, errno, "can't access fsfreeze hook '%s'", hook); + return; + } + + slog("executing fsfreeze hook with arg '%s'", arg_str); + pid = fork(); + if (pid == 0) { + setsid(); + reopen_fd_to_null(0); + reopen_fd_to_null(1); + reopen_fd_to_null(2); + + execl(hook, hook, arg_str, NULL); + _exit(EXIT_FAILURE); + } else if (pid < 0) { + error_setg_errno(errp, errno, "failed to create child process"); + return; + } + + ga_wait_child(pid, &status, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + + if (!WIFEXITED(status)) { + error_setg(errp, "fsfreeze hook has terminated abnormally"); + return; + } + + status = WEXITSTATUS(status); + if (status) { + error_setg(errp, "fsfreeze hook has failed with status %d", status); + return; + } +} + +/* + * Return status of freeze/thaw + */ +GuestFsfreezeStatus qmp_guest_fsfreeze_status(Error **errp) +{ + if (ga_is_frozen(ga_state)) { + return GUEST_FSFREEZE_STATUS_FROZEN; + } + + return GUEST_FSFREEZE_STATUS_THAWED; +} + +int64_t qmp_guest_fsfreeze_freeze(Error **errp) +{ + return qmp_guest_fsfreeze_freeze_list(false, NULL, errp); +} + +int64_t qmp_guest_fsfreeze_freeze_list(bool has_mountpoints, + strList *mountpoints, + Error **errp) +{ + int ret; + FsMountList mounts; + Error *local_err = NULL; + + slog("guest-fsfreeze called"); + + execute_fsfreeze_hook(FSFREEZE_HOOK_FREEZE, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return -1; + } + + QTAILQ_INIT(&mounts); + if (!build_fs_mount_list(&mounts, &local_err)) { + error_propagate(errp, local_err); + return -1; + } + + /* cannot risk guest agent blocking itself on a write in this state */ + ga_set_frozen(ga_state); + + ret = qmp_guest_fsfreeze_do_freeze_list(has_mountpoints, mountpoints, + mounts, errp); + + free_fs_mount_list(&mounts); + /* We may not issue any FIFREEZE here. + * Just unset ga_state here and ready for the next call. + */ + if (ret == 0) { + ga_unset_frozen(ga_state); + } else if (ret < 0) { + qmp_guest_fsfreeze_thaw(NULL); + } + return ret; +} + +int64_t qmp_guest_fsfreeze_thaw(Error **errp) +{ + int ret; + + ret = qmp_guest_fsfreeze_do_thaw(errp); + if (ret >= 0) { + ga_unset_frozen(ga_state); + execute_fsfreeze_hook(FSFREEZE_HOOK_THAW, errp); + } else { + ret = 0; + } + + return ret; +} + +static void guest_fsfreeze_cleanup(void) +{ + Error *err = NULL; + + if (ga_is_frozen(ga_state) == GUEST_FSFREEZE_STATUS_FROZEN) { + qmp_guest_fsfreeze_thaw(&err); + if (err) { + slog("failed to clean up frozen filesystems: %s", + error_get_pretty(err)); + error_free(err); + } + } +} +#endif + +/* linux-specific implementations. avoid this if at all possible. */ +#if defined(__linux__) #if defined(CONFIG_FSFREEZE) static char *get_pci_driver(char const *syspath, int pathlen, Error **errp) @@ -1467,153 +1606,6 @@ GuestFilesystemInfoList *qmp_guest_get_fsinfo(Error **errp) free_fs_mount_list(&mounts); return ret; } - - -typedef enum { - FSFREEZE_HOOK_THAW = 0, - FSFREEZE_HOOK_FREEZE, -} FsfreezeHookArg; - -static const char *fsfreeze_hook_arg_string[] = { - "thaw", - "freeze", -}; - -static void execute_fsfreeze_hook(FsfreezeHookArg arg, Error **errp) -{ - int status; - pid_t pid; - const char *hook; - const char *arg_str = fsfreeze_hook_arg_string[arg]; - Error *local_err = NULL; - - hook = ga_fsfreeze_hook(ga_state); - if (!hook) { - return; - } - if (access(hook, X_OK) != 0) { - error_setg_errno(errp, errno, "can't access fsfreeze hook '%s'", hook); - return; - } - - slog("executing fsfreeze hook with arg '%s'", arg_str); - pid = fork(); - if (pid == 0) { - setsid(); - reopen_fd_to_null(0); - reopen_fd_to_null(1); - reopen_fd_to_null(2); - - execl(hook, hook, arg_str, NULL); - _exit(EXIT_FAILURE); - } else if (pid < 0) { - error_setg_errno(errp, errno, "failed to create child process"); - return; - } - - ga_wait_child(pid, &status, &local_err); - if (local_err) { - error_propagate(errp, local_err); - return; - } - - if (!WIFEXITED(status)) { - error_setg(errp, "fsfreeze hook has terminated abnormally"); - return; - } - - status = WEXITSTATUS(status); - if (status) { - error_setg(errp, "fsfreeze hook has failed with status %d", status); - return; - } -} - -/* - * Return status of freeze/thaw - */ -GuestFsfreezeStatus qmp_guest_fsfreeze_status(Error **errp) -{ - if (ga_is_frozen(ga_state)) { - return GUEST_FSFREEZE_STATUS_FROZEN; - } - - return GUEST_FSFREEZE_STATUS_THAWED; -} - -int64_t qmp_guest_fsfreeze_freeze(Error **errp) -{ - return qmp_guest_fsfreeze_freeze_list(false, NULL, errp); -} - -int64_t qmp_guest_fsfreeze_freeze_list(bool has_mountpoints, - strList *mountpoints, - Error **errp) -{ - int ret; - FsMountList mounts; - Error *local_err = NULL; - - slog("guest-fsfreeze called"); - - execute_fsfreeze_hook(FSFREEZE_HOOK_FREEZE, &local_err); - if (local_err) { - error_propagate(errp, local_err); - return -1; - } - - QTAILQ_INIT(&mounts); - if (!build_fs_mount_list(&mounts, &local_err)) { - error_propagate(errp, local_err); - return -1; - } - - /* cannot risk guest agent blocking itself on a write in this state */ - ga_set_frozen(ga_state); - - ret = qmp_guest_fsfreeze_do_freeze_list(has_mountpoints, mountpoints, - mounts, errp); - - free_fs_mount_list(&mounts); - /* We may not issue any FIFREEZE here. - * Just unset ga_state here and ready for the next call. - */ - if (ret == 0) { - ga_unset_frozen(ga_state); - } else if (ret < 0) { - qmp_guest_fsfreeze_thaw(NULL); - } - return ret; -} - -int64_t qmp_guest_fsfreeze_thaw(Error **errp) -{ - int ret; - - ret = qmp_guest_fsfreeze_do_thaw(errp); - if (ret >= 0) { - ga_unset_frozen(ga_state); - execute_fsfreeze_hook(FSFREEZE_HOOK_THAW, errp); - } else { - ret = 0; - } - - return ret; -} - -static void guest_fsfreeze_cleanup(void) -{ - Error *err = NULL; - - if (ga_is_frozen(ga_state) == GUEST_FSFREEZE_STATUS_FROZEN) { - qmp_guest_fsfreeze_thaw(&err); - if (err) { - slog("failed to clean up frozen filesystems: %s", - error_get_pretty(err)); - error_free(err); - } - } -} #endif /* CONFIG_FSFREEZE */ #if defined(CONFIG_FSTRIM) diff --git a/qga/main.c b/qga/main.c index 0d27c97d38..b3580508fa 100644 --- a/qga/main.c +++ b/qga/main.c @@ -37,12 +37,7 @@ #include "qga/service-win32.h" #include "qga/vss-win32.h" #endif -#ifdef __linux__ -#include -#ifdef FIFREEZE -#define CONFIG_FSFREEZE -#endif -#endif +#include "commands-common.h" #ifndef _WIN32 #ifdef __FreeBSD__ diff --git a/qga/meson.build b/qga/meson.build index 409f49a000..456ba4c29f 100644 --- a/qga/meson.build +++ b/qga/meson.build @@ -75,6 +75,9 @@ qga_ss.add(when: 'CONFIG_POSIX', if_true: files( qga_ss.add(when: 'CONFIG_LINUX', if_true: files( 'commands-linux.c', )) +qga_ss.add(when: 'CONFIG_BSD', if_true: files( + 'commands-bsd.c', +)) qga_ss.add(when: 'CONFIG_WIN32', if_true: files( 'channel-win32.c', 'commands-win32.c', From patchwork Thu Sep 29 07:52:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 12993732 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 EEC8AC07E9D for ; Thu, 29 Sep 2022 09:02:46 +0000 (UTC) Received: from localhost ([::1]:59880 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1odpRN-0007YH-RB for qemu-devel@archiver.kernel.org; Thu, 29 Sep 2022 05:02:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51106) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odoMT-0005NB-JY for qemu-devel@nongnu.org; Thu, 29 Sep 2022 03:53:46 -0400 Received: from mail-eopbgr60106.outbound.protection.outlook.com ([40.107.6.106]:26178 helo=EUR04-DB3-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 1odoMR-0000p0-Kb for qemu-devel@nongnu.org; Thu, 29 Sep 2022 03:53:37 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=K2+Uh9un4F2FOylNqB19TtCgv0S9SiWl8j8pOnqgw+gAjd82bWoc4YVbRBCrLugIxH/XNaRb2pTFmjgZEs+lMUXh5smq1XFh5zNdl+cej4zw6/QlQxY6oS8A8xFsoTANY4F9hN2vXRpg7K7MR4LjQPzC8gkveSLDTX38ymNHZ3tLaalUry4d0MgTGwygbj6jf48O/twhjbylqmOFH6Bsxa6L1XW8sIivIrQmlOaWUSP7dzHg3lOaT0QCr2sSgg4rdnMlbqMlhy3ZRlQvLnLKGtmvI0jbSR67uqgmdWrkCTSTajPQG8zMzwNCVh6mdoQxXQmY44FVCGh6593Ya9s6SQ== 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=9DZSm4z5DofDfGSRj6kGXnR9CPkDe8yQ8zWjJ8ehoeI=; b=bUaQW6obF2VtVuFQLAuOGBoBUa3G2Ufmwn04pJTh1GlAW3dYegPTgpJzHtA0uhGD910JRSzfOggbxA+1IDJPvqgMf0wFttzR2kiMzAo7LFgO9gEVx9g0qjntm8TNyq+0kBWzlb9N941/uERYj1jrBNvLJt+i1SFH4ID/y33KItNdMOhqd+fV34JGNKERWJJDkzYwEXz5/UlaSObvQWSewjirQbS3v7kij6NMFYvi6HWGh/Y3IthXp94tdcwej1Jyz1AbUHSnZcXPAeXCnS0/j4Dcj4eiG9pVNbsTMLhTbCPNOMbx/FGcqsZ1msCjlSUT57d4Fx6t5aup4vezB6wA4w== 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=9DZSm4z5DofDfGSRj6kGXnR9CPkDe8yQ8zWjJ8ehoeI=; b=Fvg6ef3iK2r/w1dGpvtvlmGhjKd7fgX/dKYohgxXDv3QQi75RnO2cHslRRNxV1eIThTS5SEmcCnDMcNFFgBbEOl5VVxmjnf5bFsd+HJnTISY8lj3MMEYGwaJVEB2WgIM81im6aA+rSQXYsu+km7WdgR1QPKTI74iIOoBsX7NgvmeQgfPEbPkPtxQLrFh2WR31zYi2AFCy/RurgyTRoFJcNIqqwyy2GDYuCRgLXVZh8NfgfLYvcjB9tlyILQS3K+QMjvhKQPe07hTzDjpvdODSREr0A3jKx/AWAuNQsRT+NK5eC0capwnlr5AltFVBm5mq0SkyeNIaEir7+Oebl265A== 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 DU0PR08MB9509.eurprd08.prod.outlook.com (2603:10a6:10:44f::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.25; Thu, 29 Sep 2022 07:52:48 +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.020; Thu, 29 Sep 2022 07:52:48 +0000 From: Alexander Ivanov To: qemu-devel@nongnu.org Cc: den@virtuozzo.com, michael.roth@amd.com, kkostiuk@redhat.com Subject: [PATCH 4/7] qga: Add shutdown/halt/reboot support for FreeBSD Date: Thu, 29 Sep 2022 09:52:36 +0200 Message-Id: <20220929075239.1675374-5-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220929075239.1675374-1-alexander.ivanov@virtuozzo.com> References: <20220929075239.1675374-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: AS9PR0301CA0039.eurprd03.prod.outlook.com (2603:10a6:20b:469::8) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR08MB7095:EE_|DU0PR08MB9509:EE_ X-MS-Office365-Filtering-Correlation-Id: 12823860-0752-44a8-aca1-08daa1ef9a37 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: CpMKMGPErpPLrCojf8gtpwoL7b6JvmRxL+Nlf1xqXWkBXC0WJmwZgaTyNZHnJ6NYPSEHpKxfCAOPlKYrN1b7ndhSofuuz/KMwM7SG3C7oGKtrCxzdtk/PVXfKdBV/rGKdYqKHJg00CyIG6Mur/VdFzxlpogc6egAxTnBkaYpLXpnh00qAlszBc/T0wCXl7aEcgQI8CsD/aWAGOGw1lBlFB6fjWniIh8sKBcf+DALgz6P3/J4p8/KBKm+dLC0DghnhLyooLSVY/qw+uF+nFXKlH2VZ2HODVpqPsX5mkSYRzRwsx93Jd9qx5aUMejNiwiOwjLFwjisMpIp5rJUgrDpRirSXFfZZ+S7rdSCXAF+CI2VCTLmYGWgA/PuI7sGOcJHgzlb7fLVl5iMk825xrd0pedIgOQFX1V+OrjMpFYom0o03wyLiLuYm6cuHVtgqKPpI6XkVnKKIvmZom5S0FzzfouO7aXh9qULRW0HjDgqwLb2FN0ySWPlQAZ0Igne5xer48r3TLzJEpi60gb4heqlUNlSzkDJm3TAH8ikNeghWEVEAld2yTxkfnXApRe7ARo/Q2JJDv8h0gRs6LMTtWoMRK+3vUWAv9+cleMBvqv3SUWno9s5FFKNQC1ObLFgnTWIfirfp028owDj8Ldg7bbMCThxcEpy4bAIyUTePM8hF1sZxZKnKd9hh0oGsYGVUfp/Rgc2VrdZYDzVIogxkBB9ElvwFcnsaakwuTjjIPukpWU62Ym0cJbkzehdFVeW+1z4U4bLM41Pe5HS7h2cDHqnOw== 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)(366004)(39850400004)(376002)(396003)(346002)(451199015)(2616005)(38100700002)(38350700002)(86362001)(6486002)(478600001)(8936002)(5660300002)(6506007)(26005)(6512007)(316002)(6666004)(2906002)(6916009)(41300700001)(8676002)(36756003)(52116002)(44832011)(186003)(66476007)(66556008)(66946007)(4326008)(1076003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: LxylNh8jBxuD8bgZdCNQVR5S3qKKVMy4OSU0ZbnnA3rowPV1wGkWJW6k2Cugr4LJRLFGi1srcwZcwrxT2pGq4vtTuShU5AF7sPwerbi+2VZb9U56mhUcREFYFVxBU9IyRMoQWEu9ROthhsoyjJBUACrFazTm4xgZnKPP+zABjm10evafQGGnUaNYSDwMxk+8W74MMT/vbqUM+pYhIM0L6Sby6+QwZXXkkdx7+PUHgTZeP6sPKHqTw85Sm4kSlV1MkYA4Ywq5KHwSzhB/Rvth6I59c0BbgEb1GXTQH/DTvVSONE/djQWSWbj3uj9bE65Xm28dhaIcb58Wac5QSBNa+3AoteIrIOldg4Hpe1Q6MXc54K0SpwBMRuyh2pA9+q7kSZwlnPzk4aScp0RbZ5f32EGiZruztkF200IWF2geOpLUTYqj+PP2z7q5NGS3KdVd9xmfZ4NlFetrfDKXSvNNtColY+g5Oq6LqX9eWu/B3bPGqy1zqUw+56UE/Izq4C3aFkfmC6K9HtxK3gi0YZZBsVQhN4he5KbyPXTDZHPV8MHdfWOPA5YCNaV89Ll2/M+lOb6JYdTegck/eDm4hBOknU64kh8uMsa2r+rY71N7LYPOtVhK47Snd9FBVtcIuygbMkiLXVZ3xqhy5kdfu/wZRh7jMzCY1h31vY+VYFknTjUcuoDXXVL3lzTjEidLU0Th4U8VOFK7yuh6LJNad+Xo+2Fc63km+vDG3a/PKsr/9Lr9GZbw2EN6noPkbV0uw2t3bOc1pf/QnNGWSCbxljyi3yuRIZ77Q/YMJWRc3Wyc5uGfRKUNO4hE6l1guXVHJH4DCpOmyW71FEjGz0gYwJDl0zGDWznljcePNU6k4PNAnV3YDefXTlaFCacrEnQ+62rWP5SpBz9WR6SDaNU5UnPpzGS7ugs2BVuWJ/VkaBQ5wyvEqJ1sBwT/KdrJI2vpult4/s2wYZVOBi/P1Aq+yftZcjqxWEf9W78FmziBS9b9EAg1dizsp/prfV1OQPeWeJrBduMdHHKleY5X19ESGk+v7bIvQXwyP7BF34e/bXKav09/IPBFWDGtL8E6vR9b9SH7hDYViAtaVywH/laNjQLyxrVzUFGCmlY7OVxsbWCwB8Sr8PHK1yRLDzBSUwyqUfYCgJcrzjgxEHhqewPSUFsmba4R368nyt5mPjnOIrJwXqjcctDwC2xOQxdjPSMtlnK/8HSp03ths3+uJmuHHL01D+FfbrQHFN//vPXqi9WC7txglODlLuJJYe94jm+EC1CRe4RnXZNmUfe+49NnqbCef00+ieN+LKelWgcUOdfCMPKGs5pgTJApvTr8BIzNICS9dADnTVpzqKAH8fBaK+bLLgC2OoqXE/PpP20CsRe5eP2udgVhisJIzjjzQiYCo+bBZ5i6T3R/X10xVoNA9K/1j918c6SJ8ri8T5Zczv9PsA72LcFfLfMnwcCyHr2/kqZLvm7elZktTRhUBk2QuZsYXEoY8DoxMaCeQ2Wq6HiOnOK/meviaR42yiID0m0g74UgCbRTfXaZhHsAN7Q8OkcKJV/pvlAAkf9wLYiMiNcJzi8GGa2vU073e+UPz+eXOwh6wAVkRBq/Oss9qP3GySc7Sg== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 12823860-0752-44a8-aca1-08daa1ef9a37 X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Sep 2022 07:52:48.4514 (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: O9M6vmwjdkLU8EJVd5Efn8sLfID17aBnBM8brFkkOoqzZjshdfQqeVpc+GqUCL6MLd+YpGsjFGYaIudt+FY2nhtGwkqn8V+xOxozue6gPqI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR08MB9509 Received-SPF: pass client-ip=40.107.6.106; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR04-DB3-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Add appropriate shutdown command arguments to qmp_guest_shutdown() for FreeBSD. Signed-off-by: Alexander Ivanov Reviewed-by: Marc-André Lureau --- qga/commands-posix.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 49f9996a9c..88e0d0fe24 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -90,6 +90,10 @@ void qmp_guest_shutdown(bool has_mode, const char *mode, Error **errp) const char *powerdown_flag = "-i5"; const char *halt_flag = "-i0"; const char *reboot_flag = "-i6"; +#elif defined(CONFIG_BSD) + const char *powerdown_flag = "-p"; + const char *halt_flag = "-h"; + const char *reboot_flag = "-r"; #else const char *powerdown_flag = "-P"; const char *halt_flag = "-H"; @@ -120,6 +124,9 @@ void qmp_guest_shutdown(bool has_mode, const char *mode, Error **errp) #ifdef CONFIG_SOLARIS execl("/sbin/shutdown", "shutdown", shutdown_flag, "-g0", "-y", "hypervisor initiated shutdown", (char *)NULL); +#elif defined(CONFIG_BSD) + execl("/sbin/shutdown", "shutdown", shutdown_flag, "+0", + "hypervisor initiated shutdown", (char *)NULL); #else execl("/sbin/shutdown", "shutdown", "-h", shutdown_flag, "+0", "hypervisor initiated shutdown", (char *)NULL); From patchwork Thu Sep 29 07:52:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 12993706 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 25638C07E9D for ; Thu, 29 Sep 2022 08:55:08 +0000 (UTC) Received: from localhost ([::1]:58512 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1odpJy-0001Z9-Tr for qemu-devel@archiver.kernel.org; Thu, 29 Sep 2022 04:55:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53910) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odoLq-0004yH-9q for qemu-devel@nongnu.org; Thu, 29 Sep 2022 03:53:00 -0400 Received: from mail-eopbgr50137.outbound.protection.outlook.com ([40.107.5.137]:58243 helo=EUR03-VE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odoLm-0000hg-4s for qemu-devel@nongnu.org; Thu, 29 Sep 2022 03:52:57 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VVuuy6jI7XQa4y5v45HR8+zKHNGq6cp9QhdRTbXOEDnjt+9fws2OO/A5vAnF5lOBSd3/YvWRKii/6+k2ozjNi9z3NLN34U1hyJM+mclLEi4nf9nApI6xS86yNq76WPSuv3/0wmagJCwdrxyEh6tOOi5nzcKMLWe1IrQ7eWLlvNRg2bOq7QBytj/6DnpaIF4RMbEb2wp9zUwrutrq215ILi39jYXMEntMQv5S/aK+/UNtxi3JRi/bBho6SIynac+rdG/7+5tBMfDC1ne93X5e8+I3HEKncTGW8w2AP+g1FlXQ5dJWv/H3exW+RHxkdWmfN71L5joldkAPqnhhm/NtTw== 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=8qXr0XSfpeFEa750zuWHJLcULj297xzhC393Kuyr8AU=; b=Qf1ssCGAPdkI5vH4GiT9Bi9b8FPXX2aGC1anQLQ1DMnFDvoWEvPqvIDhtHnlodc45zwriPC0umAy3npK6+6mnsxCvOK93YMLLoZE2xTbQWuqE8dSPdx8XvcrwqTv6ys5/vb5JFitgi+zPNTp8NUNjA9AztxPlo6Freb4B0nowZM9pVsdEdUXCAOy+FMMQoG1bg7KfCubR2/CphhO+4TJmzYtq3Q3HFdqKXKvXI7FChOnaIUtb3byUP5vKloJ+DR5yd6wPBGclN/CcCWwqHdByg6Y5KQjyYndHFycLXqdkmXKlsm3gkskj7ZbzW/EUTvVzhnBY5Khn8Y8vLnPOm7/7Q== 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=8qXr0XSfpeFEa750zuWHJLcULj297xzhC393Kuyr8AU=; b=KFrAxpFbLIi813zpDnHU0/OlTweXnG+iKtThDdg2SWhMeIoknIwgGxGbW9JqCddp6chRK5EFLd327pN9pDCZOQzF+Q5GIs3kjESqvgSbcGijh/kvB2aHZ2nD31PEdKwfQUCQFgfQUsSHajHTvKtYLUQhDSxiB18N9uS6h9QdhP9tZcFU142TuLM9ZCB+L0CrR3hhXjScvqJMJIZsosivlknfLzmVu/c3++RRq7nAAsJYQTpl6Z3whD2aHHbSsFII+R+KgaOpvEk5glAvEdnD4RW63kQYju0SnqY3ce60zqtkz0ZHDgiLCIyu1xFCYDds2Q8ef18p70oeG1PbNaT8Ag== 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 PAXPR08MB6461.eurprd08.prod.outlook.com (2603:10a6:102:153::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.26; Thu, 29 Sep 2022 07:52:49 +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.020; Thu, 29 Sep 2022 07:52:49 +0000 From: Alexander Ivanov To: qemu-devel@nongnu.org Cc: den@virtuozzo.com, michael.roth@amd.com, kkostiuk@redhat.com Subject: [PATCH 5/7] qga: Add support for user password setting in FreeBSD Date: Thu, 29 Sep 2022 09:52:37 +0200 Message-Id: <20220929075239.1675374-6-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220929075239.1675374-1-alexander.ivanov@virtuozzo.com> References: <20220929075239.1675374-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: AS9PR0301CA0039.eurprd03.prod.outlook.com (2603:10a6:20b:469::8) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR08MB7095:EE_|PAXPR08MB6461:EE_ X-MS-Office365-Filtering-Correlation-Id: ff203256-e632-4a95-e1a3-08daa1ef9a88 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GlHvzCWmL0HUHrOelDzlJcGjW9QEnqdJo9Awwb+1jIo1hY8uo9nVJ4kayc+cDcup7TQjxZW/6zGHVCOrvTMYC8z3AkjnU+wyVt1PrenVEpvY9y7AcDCblBcJYIY8ucp1xxFGor1+mSL/boK0EiSQ5btYVPbFV4MyalFSAHsUyf9/OTqm0ptu4X59W0wm45DX9HnwgHs4vonzf6jCWiQdisncrq4CZB6xM0Y/BB0eyjYY34/kSe2RIhi7RhXgy8p5pX/S7QxWBI0dTt2BH29YaiSeLyS+/b6Di/RV/amS42GsBnuz9mKg3QzDe0+N8ZobnGsym2La6cCTPnvxYBbrtgg6TK+Tjb0s3X4xTM6dCpfDL+085lyLbl1aU/qTesUeS3LcfNaSyFpR+um7hkluHA7h4B7b1FyDSQLXvvgl7zBNcaU/I3z7UYJy9TIEmrxqEztL58dEwgnXubkxGhZMXwt+EDTFJ0GtdYGAnduWZ6IAqZ2fX7b5QlxNxo3vZO/VpYoL0Pjs83rR9gdR1vpcW6VPJRCwTAteRMcR4549czg7VEOp58BvGK0TbzzVq20THYvXQ6g7cRPCrx2BGz/DNW4tfFHRiwxhs+fSn7WJRyRbbnAZWzUlXk4Iow4fpu7ibmcJI6muQq4r1CTICNVJS9yCB8fSpTMZdXdrn4CB8FX7AiCuAO1CAl+nUGdAbDx0mp6BHwt9o/eTL+hRZPsM9ZUQq81z2l8FCSrX1vNtj4VHZk1DIN6vvin8UADaAANu2e0J7+xqDzsdJv223a4B5g== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR08MB7095.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(4636009)(366004)(136003)(346002)(396003)(376002)(39850400004)(451199015)(38350700002)(41300700001)(38100700002)(6666004)(6506007)(478600001)(26005)(186003)(316002)(36756003)(6512007)(44832011)(86362001)(2616005)(52116002)(83380400001)(8936002)(6916009)(6486002)(8676002)(1076003)(5660300002)(4326008)(66556008)(2906002)(66476007)(66946007); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ZUylDQrtUeGB/BmK1N2C7vm8MxHFCNtPiZWKMcgtQ4mw0fmxeZlJPcyKZpEEyxkbv8Zn/eoupXOfs8c6rULYFp4zaZHQyLw6gxzRDwkOh37mudybVXlcVUcwrXDHVLQDw5SVOWZi7nkHUZU7SZgViK/hZaHmguzJ5TTdR5gLIVZORXWh6tU2ELgPQ0B/ajjK3DHx2AVlZZFblybjRhGKi3Ade+EhXdhYYudLb2B0nRbb5F5g9ohsU2L0eHNclLasDyDNav+7nS4zwf/Z88uSjmO06dmA0Obc8DjVoG48IIeKeYS/xz65weJgPOM9zTrtZCNeEeuwfdZ7gwceC87skibXBbehCGLNoPorP88sBc1oepOsKvAVXXRB4QK/o6UDvhDr3HU6oIomvYH2qiWK+h2g4iISG4NY5pzor5bEdRAvyXiq21mYSMeGhlo6sSHUH+nyeHoB6zxv77bfnkP9anUstnlG+2F788/QKscNK30kYyqClBUV3H8Fk/YhOrzWPtC3+0YSMi03do5ak3wUOp/LI/Sv6ogybWvPhbbyVsTc6l1ircXKPO010nkO/ZwjnpZvZAW2sIGBeKdleZl28uc4QfRku0etsXy+M41mpw4DDbP1g5TMIxgRLAZ1WIKjyksd+BsuD28taIVv7C+HLKHoAzsrPbEvHd9v9Wit4IYC3YEyAdfPSQDCMq/6O9sThPlbDhSBnQaQ9OUUUUU3ofe1ggFlZABo4ZR2w2s+NBz6POW0E710MlRXf3Z4vBtQpkubQ4fFxYT+P0g9n4AvJTUR7t1T+gqBIU0GqoVUZ5lQOHOukaEScm8v+WpWdKlsZ3Kk7gGtD+OsMYZPPspSTSTV0rtk/nQvBnsSJxEzC4huLUJuVL1ED98RwQHR3CTrYJXOdx2Ota9GY3mH8zmgMNnwSceVUQu1r+yd7Vj0vg/8CsDBqjxrfuuWL1p/+rVo28y/e7bMGta4jT74ZJZBTxxF60ta+2HpheE0CLwulxCf2/WigqTet6+t73j4sJ7xDvyecEtIOLkH6RRifTsiR/wghL1Okqap7CEaIbDKcWJ9A4R2Yr7I58v1QnS8hV2CCI0olk5I2phxL9Cimd1zeQY/IeyTz8LKmK5GIbTzMHufUOheta9udYf0B9VwZ/D6827BZJiCyogyLc/5JM7M8A9C87GOFjTtazJ9EXnX3x5VMsA6AzjuRVE8/Qku7nwTErEThR9z14GEP/qiQRDiPtGGexPXTFhsXqWmA/j90qXBJFWMesga1jOAYymHNorAWGbwHNnRWtg7pWbCJaQHxwXGzomsesAcYHdCf/kf1Da6tiFGzxNdui7Od0p5xhS4dTVN79yKO7Mjf166H/ewPqINgEeFtLCQDjX0+jv6UgRa5GzOJsfKJtrqfICmBXihCoPCcMEbFzkkQKPX9g9yUURE64HeuXr/Omz1T9ujrKq+/9CFzRpWs/CjKfQIJA1MAOzDcKkEBI34+v1HomIhUuBzAlxCRKqmiVVzdMXzGxQzjIHoQ4hCXSDzeUFB0M1105tnvY8dyrDPVF1tQWYvSUcdJN5lDSdM8D2vP8khrKInZpK+LYQ0FOZ5WnoHHo+5VM2bH02bLWqohSf5KSwK2Q== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: ff203256-e632-4a95-e1a3-08daa1ef9a88 X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Sep 2022 07:52:48.9670 (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: Hm5R6hU8614gFKQY/5CxQlbwk0sKJGQ1LF4vSz+4AGrUg8oOt+9JNaQycHzjOTQn2R4Box1K1Lo6P8sZfMTnrZVpeYyThFeRvaWeoDrIHuI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR08MB6461 Received-SPF: pass client-ip=40.107.5.137; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR03-VE1-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Move qmp_guest_set_user_password() from __linux__ condition to (__linux__ || __FreeBSD__) condition. Add command and arguments for password setting in FreeBSD. Signed-off-by: Alexander Ivanov --- qga/commands-posix.c | 223 +++++++++++++++++++++++-------------------- 1 file changed, 118 insertions(+), 105 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 88e0d0fe24..6ce894ca6e 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -2123,111 +2123,6 @@ int64_t qmp_guest_set_vcpus(GuestLogicalProcessorList *vcpus, Error **errp) return processed; } -void qmp_guest_set_user_password(const char *username, - const char *password, - bool crypted, - Error **errp) -{ - Error *local_err = NULL; - char *passwd_path = NULL; - pid_t pid; - int status; - int datafd[2] = { -1, -1 }; - char *rawpasswddata = NULL; - size_t rawpasswdlen; - char *chpasswddata = NULL; - size_t chpasswdlen; - - rawpasswddata = (char *)qbase64_decode(password, -1, &rawpasswdlen, errp); - if (!rawpasswddata) { - return; - } - rawpasswddata = g_renew(char, rawpasswddata, rawpasswdlen + 1); - rawpasswddata[rawpasswdlen] = '\0'; - - if (strchr(rawpasswddata, '\n')) { - error_setg(errp, "forbidden characters in raw password"); - goto out; - } - - if (strchr(username, '\n') || - strchr(username, ':')) { - error_setg(errp, "forbidden characters in username"); - goto out; - } - - chpasswddata = g_strdup_printf("%s:%s\n", username, rawpasswddata); - chpasswdlen = strlen(chpasswddata); - - passwd_path = g_find_program_in_path("chpasswd"); - - if (!passwd_path) { - error_setg(errp, "cannot find 'passwd' program in PATH"); - goto out; - } - - if (!g_unix_open_pipe(datafd, FD_CLOEXEC, NULL)) { - error_setg(errp, "cannot create pipe FDs"); - goto out; - } - - pid = fork(); - if (pid == 0) { - close(datafd[1]); - /* child */ - setsid(); - dup2(datafd[0], 0); - reopen_fd_to_null(1); - reopen_fd_to_null(2); - - if (crypted) { - execl(passwd_path, "chpasswd", "-e", NULL); - } else { - execl(passwd_path, "chpasswd", NULL); - } - _exit(EXIT_FAILURE); - } else if (pid < 0) { - error_setg_errno(errp, errno, "failed to create child process"); - goto out; - } - close(datafd[0]); - datafd[0] = -1; - - if (qemu_write_full(datafd[1], chpasswddata, chpasswdlen) != chpasswdlen) { - error_setg_errno(errp, errno, "cannot write new account password"); - goto out; - } - close(datafd[1]); - datafd[1] = -1; - - ga_wait_child(pid, &status, &local_err); - if (local_err) { - error_propagate(errp, local_err); - goto out; - } - - if (!WIFEXITED(status)) { - error_setg(errp, "child process has terminated abnormally"); - goto out; - } - - if (WEXITSTATUS(status)) { - error_setg(errp, "child process has failed to set user password"); - goto out; - } - -out: - g_free(chpasswddata); - g_free(rawpasswddata); - g_free(passwd_path); - if (datafd[0] != -1) { - close(datafd[0]); - } - if (datafd[1] != -1) { - close(datafd[1]); - } -} - static void ga_read_sysfs_file(int dirfd, const char *pathname, char *buf, int size, Error **errp) { @@ -2793,6 +2688,124 @@ GuestMemoryBlockInfo *qmp_guest_get_memory_block_info(Error **errp) #endif +#if defined(__linux__) || defined(__FreeBSD__) +void qmp_guest_set_user_password(const char *username, + const char *password, + bool crypted, + Error **errp) +{ + Error *local_err = NULL; + char *passwd_path = NULL; + pid_t pid; + int status; + int datafd[2] = { -1, -1 }; + char *rawpasswddata = NULL; + size_t rawpasswdlen; + char *chpasswddata = NULL; + size_t chpasswdlen; + + rawpasswddata = (char *)qbase64_decode(password, -1, &rawpasswdlen, errp); + if (!rawpasswddata) { + return; + } + rawpasswddata = g_renew(char, rawpasswddata, rawpasswdlen + 1); + rawpasswddata[rawpasswdlen] = '\0'; + + if (strchr(rawpasswddata, '\n')) { + error_setg(errp, "forbidden characters in raw password"); + goto out; + } + + if (strchr(username, '\n') || + strchr(username, ':')) { + error_setg(errp, "forbidden characters in 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); + passwd_path = g_find_program_in_path("chpasswd"); +#endif + + chpasswdlen = strlen(chpasswddata); + + if (!passwd_path) { + error_setg(errp, "cannot find 'passwd' program in PATH"); + goto out; + } + + if (!g_unix_open_pipe(datafd, FD_CLOEXEC, NULL)) { + error_setg(errp, "cannot create pipe FDs"); + goto out; + } + + pid = fork(); + if (pid == 0) { + close(datafd[1]); + /* child */ + setsid(); + dup2(datafd[0], 0); + reopen_fd_to_null(1); + reopen_fd_to_null(2); + +#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"); + goto out; + } + close(datafd[0]); + datafd[0] = -1; + + if (qemu_write_full(datafd[1], chpasswddata, chpasswdlen) != chpasswdlen) { + error_setg_errno(errp, errno, "cannot write new account password"); + goto out; + } + close(datafd[1]); + datafd[1] = -1; + + ga_wait_child(pid, &status, &local_err); + if (local_err) { + error_propagate(errp, local_err); + goto out; + } + + if (!WIFEXITED(status)) { + error_setg(errp, "child process has terminated abnormally"); + goto out; + } + + if (WEXITSTATUS(status)) { + error_setg(errp, "child process has failed to set user password"); + goto out; + } + +out: + g_free(chpasswddata); + g_free(rawpasswddata); + g_free(passwd_path); + if (datafd[0] != -1) { + close(datafd[0]); + } + if (datafd[1] != -1) { + close(datafd[1]); + } +} +#endif + #ifdef HAVE_GETIFADDRS static GuestNetworkInterface * guest_find_interface(GuestNetworkInterfaceList *head, From patchwork Thu Sep 29 07:52:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 12993676 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 C9FDFC04A95 for ; Thu, 29 Sep 2022 08:03:16 +0000 (UTC) Received: from localhost ([::1]:36546 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1odoVn-0005aH-Pu for qemu-devel@archiver.kernel.org; Thu, 29 Sep 2022 04:03:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53912) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odoLr-0004zq-PE for qemu-devel@nongnu.org; Thu, 29 Sep 2022 03:53:03 -0400 Received: from mail-eopbgr50137.outbound.protection.outlook.com ([40.107.5.137]:58243 helo=EUR03-VE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odoLp-0000hg-QO for qemu-devel@nongnu.org; Thu, 29 Sep 2022 03:52:59 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mOEtPf5MIj2UTDN62rYpbI9OZNJO8OQlvp7zi+HDHF7kQwLIqq3p7h6cUKAzGCIO3GmhFADxA3O71IdW9rrgVu0lIxvUfiX0dNneWIxnMrJC9ujeegbLJEBaQ4aaeYdQIM9X+qxbP7CzrU+briS/MN6vGvyuqkVFRD9/QvFgTfX0s09gkn8q50RW8k+aX6Sxj6gjN79yR8RzA5pRQPMcZStpVDJWtiNUm6R7nJxQYXgqqNbug/onv7no45nSOEMBEm3xJJ9yVUWdyYkgOUjbRhIweZKPHVxB3aWl7fxngjXbE6DXZLuR4gypBdUpQbxaI/uPf+8ldZBJT9XHWPqYWQ== 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=n6IYw1Yuo9xEANhuQwTiGpnfATLTImxbVXiIyCqZeas=; b=em9QmaRpRAwSTyaKvQeN++q01jiuM9cAjLuk7Fn23GvpjROXoClx6psBaqTxSt/xmsscSG2DiDdbMNJ+7YHx9P2ar59fAQDuQfNp+fjTYThmvZRUxSII4STwcCIorKeSeEV7Sh46A1IiRKs8NxYri6g6V0fsLR8jtGHjXT8Mjpn6CK9GcOf97s3slXdPuAws06V6hCrDZ+cXWeyWeUl1TmMi1xP4nWJubLPrwkWFP4PDUi5bJ4JzTQYBrt16bMCxRtKDljRL00aUrgB9RSxlhsRuhmDKXw87HFQdoRf/aZSgi8idiUIsh+u1n8oeMuN6ouuSgC1xHw3FI4P4YJlVvQ== 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=n6IYw1Yuo9xEANhuQwTiGpnfATLTImxbVXiIyCqZeas=; b=jzG+S80lasTlKng5eexs8pLMPg0z+8eJE0iiYiY9j2iU3XAGSY55aWJM7ZyId1OD/R/8nzZgsjne2qeiR8ofp8icqe4iO+F/ruP+eCAPoxNgDdwXKEMa5CHzp+vLs9Dau6EgEK9OrajyRHmGcE9t1nAr9QZz+8s9HBuDcFkamQqT/WByzjOEZLbAa7Dk2SQyHTOGQe1/JhcoTkYioB4NXKrdlS9kGxO5So2BCt8DA/0Hw1JMBN3jNkGRgxH5jhwVw59K2JL4cl99SPTMEBOhsuzz1e7zstZbQIykXE3hXm1uoGpx48aOZ5k5Kd55wsMS5htwMVCrahCroYeaeYNPvw== 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 PAXPR08MB6461.eurprd08.prod.outlook.com (2603:10a6:102:153::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.26; Thu, 29 Sep 2022 07:52:49 +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.020; Thu, 29 Sep 2022 07:52:49 +0000 From: Alexander Ivanov To: qemu-devel@nongnu.org Cc: den@virtuozzo.com, michael.roth@amd.com, kkostiuk@redhat.com Subject: [PATCH 6/7] qga: Move HW address getting to a separate function Date: Thu, 29 Sep 2022 09:52:38 +0200 Message-Id: <20220929075239.1675374-7-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220929075239.1675374-1-alexander.ivanov@virtuozzo.com> References: <20220929075239.1675374-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: AS9PR0301CA0039.eurprd03.prod.outlook.com (2603:10a6:20b:469::8) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR08MB7095:EE_|PAXPR08MB6461:EE_ X-MS-Office365-Filtering-Correlation-Id: 77a16c04-9065-4c08-b3f0-08daa1ef9ade X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6vdm8xRJL9mIYRsgYkrh7fPJuvCO2Hno4FjQ1E9tqmB1yRaHrlZMPTCoBzh2D8rZgH+CviHPiIC8+O/IT/Zc9VOceJVlAIIuNeXmZXjoUHkhyIfoX4Pc1/SQrjgPGGk/58ghai7fKBTPYL1rAZLwTvhrhywu4u48yfRS0HlbHfPLhYLGLhANHEN8gRQcijxZc0p3RMk1ydhO7BrWvEGu/FrlCe9BLjH3NeNoEzpozOGCrBPWJ6Nw4qt8rXj/ZwvWU14NRipde3ZH9nf1tw5WWygjG80oVoj8LT7E2u4p7sr1Zt+ncS3CnCxds7/hb5TuhPXu0slrhN9N92/wQh1SGZU4rYK1vYGH8nTV6diexc36qGgEKiH0GSqq6KWXhag7gpphc/8bAHprHIWfvS0JKp+RxS6O/0f7+iFvhTijujORgMrCZi20w3zWyuwsZ47s2bVnYSE0cEYwb3D7uyq1ZSmzmdBU8GUUUUTnLgqenCbtWM7dZ3CmouMkhNFiZzpLVMQ6JAVOrcOHRJmrL4d6tsj6nO2ZBslE88yvnoAKI3dDUMAHxQeIBcRUU6lGJ4R6DUVJESbLZDXDM0jMmyTbkGDc0xuLGp5TeOFn2wP1tQgXC6cIWzMdDHCoiTRacd7GtrMHtN5hngHz8PR7ZZ1WmMEGNMou+609VltuGzuSMByx7jMrc8k+6xYhtRFVZ7dR+/SvZMMi7jzfgPNx4dh7XSNgnCZkEQNGt+udLts58WcZCX1nN7ldNnMS60ZqSyKzlge3mzUpxc7S6Vx9cCr6KQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR08MB7095.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(4636009)(366004)(136003)(346002)(396003)(376002)(39850400004)(451199015)(38350700002)(41300700001)(38100700002)(6666004)(6506007)(478600001)(26005)(186003)(316002)(36756003)(6512007)(44832011)(86362001)(2616005)(52116002)(83380400001)(8936002)(6916009)(6486002)(8676002)(1076003)(5660300002)(4326008)(66556008)(2906002)(66476007)(66946007); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 1vK6vlm6R/NlOOEW97GGVMGuOTHykY0cZe2pwIHY6Dziv7JF6qRWdBLNqzNXD3RwdAshVGdYzzpqkcHHnGbGaPcBIM5SMn2K7BKLN0kmpkuq5RrWlgNL25VMRWpMe4m54pS3v7pVC2bMSvhhHCz8dgc+zhwt0hFsjweG1hrYlpXFXp4h0Dnl3Rfa/QuI5jlaUbWMLPnCs8WTZo6sbrkT56H+zW81NEiBMaAHY43GIZy0jm2wk9ECIVDyFPhWYn+OxNOIFrHXNcyXEewrtxD/ElT2ygN53sS+ZKSFBVQoEfPJJSP8fl26JTHTnxcpqCNY/LzQA+uBfqVhdEE86G9S9mHDa5i08661ezuqXdYFjd8TWzFXdCibDF/FfNfPsyCvUFbkSrtyjG0481xkn/b7Po0oQwUDTmTwJDaLSpW38+c3ZtXZG0OfJIpz0J1GcywzTVJgZu/Y+zaQkW94b1+ZzW+kA6FVi/iLTxv3G3NCE76cFC2NM5k6QATJeKIJ+C7YPNewhAtFmnXuqHX0+lafwaWD3A90xz6BYOoLW0ojIREzvvURfLyKP5pGwFutC/4/w4GLT+ecs6spIH4FXk5KCkY1w9EBjGnoNq5fU2WTXNGKjLsThe5aSwU3XIZ34Lr/qqlEQ0/SEB4p/DFxIx5iXAQhg355p7ztGTNOWNI1ZAeEhb650DYMf4N2+mzxTyo8BGL1+f00TsnV4qXZH8ZWqFjgsu67SYoIQEJ/CXdzzjHLfUOzdaMfp52M7ZbOZmxf08V4BGn8iUv4PuWDpXUP+I/ob4VDspCZStQyqxy1QaIKd6ZPxmbVEbPXFrA4v6vOYpj7N8gQE4YUF0b3VhBurd9QhHURmL3Xe+uVC8GmBqdptDgVB0zIN4OZmkQl4v3vchh+3sGlhGLpxFLpwLLDTDe2zorME4hqi2dQoHJSvhOyCjzbLyBY2Q3+sZqKULopOBiNDdzBklmTlxY2PbOSgr9PKpF1GVBJBmFVUMDQFj6qDe+b4Z+n8btnqig1fAw92rykMLbCzqPL6vDT28qYu+iL2XxyP0JHgR/Er+/llupsNqsGjYsuUtFNc92SZpx5pCaGVcueH/0TUNspsxe/ciMIU78C2M8B8CNwtBKs8c8jGNcMxeog4kGdrDgUKg5wJ/deovrJ+IgMXFeSXBSWocUjkqNVjBHnJjp6lXyaYrrlrM5rvO23uolhd0awgeXXL7SQz8jp3P6MdmFEErxSzSSSwv7zX2PZ9hWa54C1qunivwU5iQa7NlGbg0sMznNpI+opj8Ww5f8CKyLfWxPk9GOZDulSGDRLE/+Ljw1rgGNJdu92N21fk8zYwsQGbpKOeoNvLWEirFCxEWdXya60sbaBCYwUcGju3DjxfsQGfx9KgpoqvEusrU8ne9uB6Bf6rG1KSpbH4mwvXRSStH4vXXzt898Q3jvyP34lOqq1ujEOiQjQgQO0xya1Vhhy7kQdmGqXKOe7e6YbGRcwoO4PsqObxN17BKSTvgbYa37PkHOxic3ntzccmDnYZATyQmu4+lzQ95ZM39IThqDmgDmmtLHmjVDLpckmpZC88OEjNOlgcPG/v4Ytg3ZEw638MdRFEYEHNp80dFikRvGgAw4H0A== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 77a16c04-9065-4c08-b3f0-08daa1ef9ade X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Sep 2022 07:52:49.5606 (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: KV6jugwKT24eWfX8KDiCQWEfrFQYqHMBy9vhsTfWWqmDo9rDebuchS3CeRVoAAP50YsdXK5CsvO4JG67r2QDKy8B8Ze06MRStHlBo6CtSpA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR08MB6461 Received-SPF: pass client-ip=40.107.5.137; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR03-VE1-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" In the next patch FreeBSD support for guest-network-get-interfaces will be added. Previously move Linux-specific code of HW address getting to a separate functions and add a dumb function to commands-bsd.c. Signed-off-by: Alexander Ivanov --- qga/commands-bsd.c | 18 +++++++ qga/commands-common.h | 6 +++ qga/commands-posix.c | 114 +++++++++++++++++++++++------------------- 3 files changed, 87 insertions(+), 51 deletions(-) diff --git a/qga/commands-bsd.c b/qga/commands-bsd.c index ca06692179..ca81114171 100644 --- a/qga/commands-bsd.c +++ b/qga/commands-bsd.c @@ -167,3 +167,21 @@ GuestCpuStatsList *qmp_guest_get_cpustats(Error **errp) return NULL; } #endif /* CONFIG_FSFREEZE */ + +#ifdef HAVE_GETIFADDRS +/* + * Fill buf with MAC address by ifaddrs. Pointer buf must point to a + * buffer with ETHER_ADDR_LEN length at least. + * + * Returns -1 in case of an error, 0 if MAC address can't be obtained or + * 1 if MAC addres is obtained. + */ +int guest_get_hw_addr(struct ifaddrs *ifa, unsigned char *buf, Error **errp) +{ + /* + * We can't get the hw addr of this interface, + * but that's not a fatal error. + */ + return 0; +} +#endif /* HAVE_GETIFADDRS */ diff --git a/qga/commands-common.h b/qga/commands-common.h index 2d9878a634..2485a037fd 100644 --- a/qga/commands-common.h +++ b/qga/commands-common.h @@ -56,6 +56,12 @@ int64_t qmp_guest_fsfreeze_do_freeze_list(bool has_mountpoints, int qmp_guest_fsfreeze_do_thaw(Error **errp); #endif /* CONFIG_FSFREEZE */ +#ifdef HAVE_GETIFADDRS +#include + +int guest_get_hw_addr(struct ifaddrs *ifa, unsigned char *buf, 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 6ce894ca6e..0bebd9e690 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 @@ -2659,14 +2651,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); @@ -2804,7 +2788,15 @@ out: close(datafd[1]); } } -#endif +#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 HAVE_GETIFADDRS static GuestNetworkInterface * @@ -2887,6 +2879,54 @@ static int guest_get_network_stats(const char *name, return -1; } +#ifndef __FreeBSD__ +/* + * Fill buf with MAC address by ifaddrs. Pointer buf must point to a + * buffer with ETHER_ADDR_LEN length at least. + * Returns -1 in case of an error, 0 if MAC address can't be obtained or + * 1 if MAC addres is obtained. + */ +int guest_get_hw_addr(struct ifaddrs *ifa, unsigned char *buf, Error **errp) +{ + struct ifreq ifr; + int sock; + + /* we haven't obtained HW address yet */ + sock = socket(PF_INET, SOCK_STREAM, 0); + if (sock == -1) { + error_setg_errno(errp, errno, "failed to create socket"); + return -1; + } + + memset(&ifr, 0, sizeof(ifr)); + pstrcpy(ifr.ifr_name, IF_NAMESIZE, ifa->ifa_name); + if (ioctl(sock, SIOCGIFHWADDR, &ifr) == -1) { + /* + * We can't get the hw addr of this interface, but that's not a + * fatal error. 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)); + } + close(sock); + return 0; + } +#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 + close(sock); + return 1; +} +#endif /* __FreeBSD__ */ + /* * Build information about guest interfaces */ @@ -2907,10 +2947,9 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp) GuestNetworkInterfaceStat *interface_stat = NULL; char addr4[INET_ADDRSTRLEN]; char addr6[INET6_ADDRSTRLEN]; - int sock; - struct ifreq ifr; - unsigned char *mac_addr; + unsigned char mac_addr[ETHER_ADDR_LEN]; void *p; + int ret; g_debug("Processing %s interface", ifa->ifa_name); @@ -2924,45 +2963,18 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp) } if (!info->has_hardware_address) { - /* we haven't obtained HW address yet */ - sock = socket(PF_INET, SOCK_STREAM, 0); - if (sock == -1) { - error_setg_errno(errp, errno, "failed to create socket"); + ret = guest_get_hw_addr(ifa, mac_addr, errp); + if (ret == -1) { goto error; } - - memset(&ifr, 0, sizeof(ifr)); - pstrcpy(ifr.ifr_name, IF_NAMESIZE, info->name); - if (ioctl(sock, SIOCGIFHWADDR, &ifr) == -1) { - /* - * We can't get the hw addr of this interface, but that's not a - * fatal error. Don't set info->hardware_address, but keep - * going. - */ - if (errno == EADDRNOTAVAIL) { - /* The interface doesn't have a hw addr (e.g. loopback). */ - g_debug("failed to get MAC address of %s: %s", - ifa->ifa_name, strerror(errno)); - } else{ - g_warning("failed to get MAC address of %s: %s", - ifa->ifa_name, strerror(errno)); - } - - } else { -#ifdef CONFIG_SOLARIS - mac_addr = (unsigned char *) &ifr.ifr_addr.sa_data; -#else - mac_addr = (unsigned char *) &ifr.ifr_hwaddr.sa_data; -#endif + if (ret == 1) { info->hardware_address = g_strdup_printf("%02x:%02x:%02x:%02x:%02x:%02x", (int) mac_addr[0], (int) mac_addr[1], (int) mac_addr[2], (int) mac_addr[3], (int) mac_addr[4], (int) mac_addr[5]); - info->has_hardware_address = true; } - close(sock); } if (ifa->ifa_addr && From patchwork Thu Sep 29 07:52:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 12993666 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 3FF88C6FA82 for ; Thu, 29 Sep 2022 07:56:22 +0000 (UTC) Received: from localhost ([::1]:34562 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1odoP7-0007yJ-7y for qemu-devel@archiver.kernel.org; Thu, 29 Sep 2022 03:56:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53914) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odoLt-00050r-Lq for qemu-devel@nongnu.org; Thu, 29 Sep 2022 03:53:03 -0400 Received: from mail-eopbgr50137.outbound.protection.outlook.com ([40.107.5.137]:58243 helo=EUR03-VE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1odoLs-0000hg-66 for qemu-devel@nongnu.org; Thu, 29 Sep 2022 03:53:01 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bf6kPZIOX0oq9rj8p/ztAkX7JyErjjucD5akR54+6/BwyXUXoa6y9FYyQAqJ0LT9EZjzgr4Nc7eezhqDP+J3wV8rCAUvkR00zLquXFzZI+hT/Ndlxtew4JJQ4ma1LGI3DpSwOcqi36N538iCKAr50F5SG+v/OoDj9+2fZQ371XvUlfucmHF181fC3qPSaK9v4EgPimaRqmolsMRES7I4xnpjI66Bg27cq7uLyjB4UxQOr3hSl8VH1oedUo2yRK162+6pms4K+Cwrk8a+3ZF6phe8TJNSp3g3VYNgHMs8XuOaaHwLX5Eam39A9L/mOZWAJHjWeZ555HG2El1Z5Fl6aA== 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=vDuHrHOpjnvbR81Z5wHjnGTZSs+7jewXbm4TYdlL0tY=; b=QN4t9rUbn19mfvrfDSx8YOgI1EFADnLM9cMxH5FOLuguIr+01QIR/ZEkSgvpICnVb7oX52C6/cDf3d4bqQ92OxlhqLqK6Q7k3EDmyceFS+6t4xpolm902QFn9Elrt6JW41PkuAWJEG7lioWgR5EGr435Nx1QGdFeUu2d70lcc+9cZqtna/H70jeWFIyYdh3zZswmaKPJu+NnOxVjHB4YDWcXU4+kvgTPnBLtQxzJQygtdG226o7rmbxN11oMLk3VrTOQp8H1bHBC5Vkeord7ZStA7X8vaaOL34Uo4scOPrSQ4pJcoTcUZhmbvS7vztTU9P8tA813GnrkNJYJusQdcw== 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=vDuHrHOpjnvbR81Z5wHjnGTZSs+7jewXbm4TYdlL0tY=; b=tCRB2k4OAutMl9iET/Z146S7oU6LoMHhmHDaLiwsHB0Myd0LrGUhUnJMdn42amaFEZJtGl2z+QfakHzpGdCVsPdvh42L0W2Doges/Lw77YFvtqkxL3EZy2PoNA6XBOJQ6k8mdRWy7BfJK3/1z3lqxhWu6QTs35zmeNkC43JyRfHKR49RSUhmwRx0GBiGbhqD3QEhYJEW3flA5W8lwSolW9fPDOH2/pymi0T4Kt7g0TFafOtIo+oMvt8oGQzo1bOxj6CaWPy2qkSllTjKHQ16X5HN8gqFkKP8FChb2Mtf0AYO5jw6cjfwu/cGsrHSkjhiiGDfI1/xzQRyE5oxRwBosQ== 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 PAXPR08MB6461.eurprd08.prod.outlook.com (2603:10a6:102:153::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.26; Thu, 29 Sep 2022 07:52:50 +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.020; Thu, 29 Sep 2022 07:52:50 +0000 From: Alexander Ivanov To: qemu-devel@nongnu.org Cc: den@virtuozzo.com, michael.roth@amd.com, kkostiuk@redhat.com Subject: [PATCH 7/7] qga: Add HW address getting for FreeBSD Date: Thu, 29 Sep 2022 09:52:39 +0200 Message-Id: <20220929075239.1675374-8-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220929075239.1675374-1-alexander.ivanov@virtuozzo.com> References: <20220929075239.1675374-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: AS9PR0301CA0039.eurprd03.prod.outlook.com (2603:10a6:20b:469::8) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR08MB7095:EE_|PAXPR08MB6461:EE_ X-MS-Office365-Filtering-Correlation-Id: da4d66c5-871a-4092-76f9-08daa1ef9b6b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ag4Mkq2rz0gvhF+Na1mthlHP7Vw2aXnuWiPvrUBNpOfV4qXcJSwtzqThGo5QSWwLziExZFOwxlx2xWrOBMNVx38a2+Kb6Hrsx8jlW9hz18NUOfF4X+Zv49kpMP7JHapSALEEzYJdoQVX7fRl4T2CxYxwNnmaK5NfCHgjc1yymxu25MF6hEQzZq3mTqgmpQelER0ie5s9qVBZXFTmY8jzO9TAFiZI/cwrtiPS2pBAGczRFNuVuLW+kzMwNZqpMLBh/4YSVjhNn4G6/WKnywAXZXxLWCc1wPPo2OJdNsQH7eoSPIFMdS5/fGrve0X9XY0FTcojbH0BTJopEamTj5QSXuElJ+qQyoSwvUf38yrY6oSqcuYOBF92RnGiACF1UBBKAidM03BRtZysgQe/SF12tiWBu+CFLPC5wKxNXqplKlyy3O8wQLbhPFHHbJbjKTEk0CwXkMkjN9OsGTNtqhtx3jSqHruW7+0DC+7meieHJ+FgCUcopEms/aG/hYiBfrwgNqUoDxiqjGMlbuHqxGeidhKtp0MAdSYEguAw147Zw+nb86k7N66kwGO6XCN0lfVrdFiAQZ6uPE36oj9kO6BaLFWNytLFu8rbNbr6h+wH+YPB3Ubfk6Bt4yIi73iC46Tm44QcYzSG+KzcYCjF2lMaLgvoL4Q51EJRcTBeaKzE0bJbNPZUVUPoG1PHfHHLGJR/tk6BY+TFdiE0iCh3rol0JT0PG/T7SUPTd7xxPH20wIaSTp1sA+2xvfeiKqxwVoXG X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR08MB7095.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(4636009)(366004)(136003)(346002)(396003)(376002)(39850400004)(451199015)(38350700002)(41300700001)(38100700002)(6666004)(6506007)(478600001)(26005)(186003)(316002)(36756003)(6512007)(44832011)(86362001)(2616005)(52116002)(83380400001)(8936002)(6916009)(6486002)(8676002)(1076003)(5660300002)(4326008)(66556008)(2906002)(66476007)(66946007); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: dhmZy0rHZV0biZln1Cu8Zl2Ux/PfI7sgg+WgbAM+HnmD1rTzgHBNF24eJTsLTPklT5UyHxUMWYiXW64qTyC52WKgUEkfr0oXCGyEFj+a+LtJtwpC+Q60OYUJMVGw4Al/v4HvD+ZMq0bQ94JjpOC7FsSsZCEl9nRF7riW7iefw2InhWiSnldA8PpduRdT565jJ5GLYkhJevDrGSaMF+d9iVJTfFJubhMPnkwCJ/ZM2sVWcFXlWOmrxJfgWMEQK9VjTsDgSqrVRX2BB6+Zr6OXeUVVSO/L8zDurSP8SJhVSoxd4GQUlXTiOsduOb4zakJkiLCxLsR1YnsocxWDvT+Ezhgy/gUqTWxIu8zNBeHVT+3/4i2llYnUzLL39AyRe/KM8keTtPi2CfQToxbYV8iOjRH5cmJL7MWnSqi9FiBZPKfmwos+zHtw5YimW4rIfWSdnO/FItVNpc9/IFE47b8cofdywwTykKaUJeg9u4qx+m2/YXa8/5OiEpBHHNkA4IDikg+UV3+L45+3oo1ykZxofaPCkC+lgj/HmH9GZi3+nHOK0yDnnUHm0VqVYZtWl+BZVjNt1c21aPndC0UbAUMnxG6wH9QS1aA66/qKPWSYJLQlfMtKzKPmdy39I0DcsCFqaW/Qov4EbFl5m35fKpUYhYfP+Z6Vlo0NkCIsWUz49/JIBxqK4qurteDBFEHRpOFx0wxl5wXwz3NtC7T7FTWdWthwCrvAI8XU+9GlzafdJgao1tHXI9ZdMAOMZ0osGSjDxTbP5bqHvlMJISXHxauCP5DB1GcOX/Y75RgL3C55TUy5NQd42+v7s8u36CveHTURmhj12f5rEtM8zgR8/CCDLleQ0STv7SZsj/X3tT545mTUIYDfoSj6whpnBWGtzFLmK9edpnbb/6FQ8Xdpv1qE5pNKPIJ9nO3jVRWqhncFJZFootvzxxr9I2Nk3lGd7k80w6mUpKH2QS++hsXSB3/Z+/WSAkw9uDnETSrEmHyWdOt2K7Ud8y/A+yiCXCcwNMUbt6qV4kAnvBqmGl2dEivA8ePGRiMfSFR3hght7391wEnOuiekBrZfdOJ8aX+EbdD5dQpQUXcZEqPMJw8frpVgNHn/TyysGRONLWIIRiniRseusFmDjXobiqY2I9yTdsWvgU4jpgW0kKACipODx5MgvQnEWhFUiEsRrjHwS2+sYW9pkae4fOMWeeT73oefVU8HBQcn0fWwKREmZdlpRMUuT4PrCkIAjnKYwrv1bBTbJbtTc28jwT2AvZrVZP9TfSGqgvR7x9azZrTOdoW/u4Kdf//TrkZP2jbyblPPRQZXWRZXG67sG4doL9hea386eyIOaSg6VfxSFkHIAI3ln6PhY4cGmb6+zgX4tujI0RXX4XucDWxGjDoK7mhrhVQGLZ8QrvPTSVVBjipPOJpB0dF3WY50g/jOZf8zFznLz4WufVu9qCCtpd+skxzcsIeGBziUZandODKMbObtfSIJsFFOvX/mNSilVQx3TUoTJqjDHL3Gq0piynGz8gpf/0/X1Z04vNq1bYDB5Ua3O3OGnVCelIUyh+fxX78V23dZO8T0zqHqDotVGABk5Hel0PlJSY0qElg5eUBHSz7OZklEv6ky8g== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: da4d66c5-871a-4092-76f9-08daa1ef9b6b X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Sep 2022 07:52:50.4675 (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: UEYs+q+lLOoX1CdfRm8744J01R5jNgLdjN55LqLsMQZlOT9VCvltXyvqIecAA2Uyjj3GnkpFrfJTjDCYI2/SxqbJnQAywSHbBQ7n8ZrCJvM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR08MB6461 Received-SPF: pass client-ip=40.107.5.137; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR03-VE1-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Replace a dumb function in commands-bsd.c by the code of HW address getting. Signed-off-by: Alexander Ivanov Reviewed-by: Marc-André Lureau --- qga/commands-bsd.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/qga/commands-bsd.c b/qga/commands-bsd.c index ca81114171..f9997ee1ec 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) @@ -178,10 +180,15 @@ GuestCpuStatsList *qmp_guest_get_cpustats(Error **errp) */ int guest_get_hw_addr(struct ifaddrs *ifa, unsigned char *buf, Error **errp) { - /* - * We can't get the hw addr of this interface, - * but that's not a fatal error. - */ - return 0; + struct sockaddr_dl *sdp; + + if (ifa->ifa_addr->sa_family != AF_LINK) { + /* We can get HW address only for AF_LINK family */ + g_debug("failed to get MAC address of %s", ifa->ifa_name); + return 0; + } + sdp = (struct sockaddr_dl *)ifa->ifa_addr; + memcpy(buf, sdp->sdl_data + sdp->sdl_nlen, ETHER_ADDR_LEN); + return 1; } #endif /* HAVE_GETIFADDRS */