From patchwork Tue Nov 15 18:45:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 13044076 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 76A03C433FE for ; Tue, 15 Nov 2022 18:52:39 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ov127-0004bt-0c; Tue, 15 Nov 2022 13:51:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ov11j-0004Sr-0K for qemu-devel@nongnu.org; Tue, 15 Nov 2022 13:51:19 -0500 Received: from mail-db5eur02on2106.outbound.protection.outlook.com ([40.107.249.106] helo=EUR02-DB5-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 1ov11g-0000j5-Jz for qemu-devel@nongnu.org; Tue, 15 Nov 2022 13:51:18 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CXC28cPUQU8uR1X0/OdpuAWfBvJXo/9fQNrax+hP4SXeI+FpQ6kSt7ZZT+Afr5UluUdLokiOGbzP3TAB3Sab2tvww2WVDEsNA87Nds8pZ+N1QM65X8QwXGbfX0vTCvEQBhvsLbcC90MU+A4a4mWwgPOTCkixURdajfgs5qDIMVkekZEwgoEZ44LTyQOtWE7dvmfNRqyZlK8rqkq9KcTqVdBMXM8UIy4uUxP+aJy70HUAXZDbJSWFQgWvnE+i0cZM8blfLh0ww68AJ4tBr7acmasNBddtCMdh14I7jibDutAboyK8dtIspHQuSfry85+mrqzycEmsM0sBsn2+pB8Hog== 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=BX0P4Xob4TfSYXsIhi/vDmTban9yoBDoVQaxYd+BX3Q=; b=YtSKlDsLB/H9sZHzz3Bke0Kn/agIAe+2SU+zfLnauQ7i54uhpDzTUhSbTSTEQGSAxD0UDhKRvfjXNIOTHLUaf5r10eC9aLnyFYqdbLnaQSR8k4QUjPVZBBQaS5SQgawkdaYG6jGrypEes/663b6rLaolZzlfh08ez/1eKvo/x6XKS6vw3n2dCJfrZ1lQdCLU6VFnPr/61NJWbV9M8juR5gF63qh+s6GkEZRwQZ0YoncDlnE9H1eBDIsaNAHHUcAnZobHEa7LZ8MymJX8JQYYxrUSyvRJzEBVe0Fed5DOuCy/MxeSo29r+nQ1Qder799x1gv9WQIWYxF4xpt3o+KzZg== 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=BX0P4Xob4TfSYXsIhi/vDmTban9yoBDoVQaxYd+BX3Q=; b=C1+R90dV2/KHO2XBnVka91p4Cn4fxI1hAKeSX8xF2yJgcPzH6JZUd/TWjdXv3fRuHfnnyN75PvUy/5eqop0PWWIIPC/BqIRH+mqQXODLY6r+DzdDjMCGRNEPyHZQstuVa6QvFtlKTP1bq+7hdG+V2hVo+puHlLxznrk5FGq5RnRVXIaYnP03iWArWyIGnRdsYSdkUd8gOqHut4vwooV8Jb8yoKrOX+jzUcYYSfkaOMWv9P1hQa7xzbQWu1MpKphrsFFINABEr0PyciqEX8Z+z6wIyDByxB4DajcTMmQwelW47kQTWDM5XG8bhjIsK15HdL3yiafrN46yPPTYUqRzdg== 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 PAXPR08MB6607.eurprd08.prod.outlook.com (2603:10a6:102:152::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5834.6; Tue, 15 Nov 2022 18:46:09 +0000 Received: from AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::fa9b:7e41:680b:aeb5]) by AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::fa9b:7e41:680b:aeb5%8]) with mapi id 15.20.5834.007; Tue, 15 Nov 2022 18:46:09 +0000 From: Alexander Ivanov To: qemu-devel@nongnu.org Cc: den@virtuozzo.com, michael.roth@amd.com, kkostiuk@redhat.com, marcandre.lureau@gmail.com Subject: [PATCH 1/2] qga: Move FS TRIM code to commands-linux.c Date: Tue, 15 Nov 2022 19:45:59 +0100 Message-Id: <20221115184600.747961-2-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221115184600.747961-1-alexander.ivanov@virtuozzo.com> References: <20221115184600.747961-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: AM6P193CA0102.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:88::43) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR08MB7095:EE_|PAXPR08MB6607:EE_ X-MS-Office365-Filtering-Correlation-Id: 7d651923-b9db-4bb8-37fb-08dac739a94e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UbSpL4OiGaToXjBtgBcBl7TWjv3bD54pRO/DPh8B8te3oemtYbugpfG7Qklsd/oGOsaZgHxTNGPMiJhmTs/YjJjwOXOm0hNY84hrEz69BeA+4EGG81evF4gds7N+QB4mNdsMsSBWXhd0atG7jCCqd+8H9EjVAqnZdxjlvyFWOj57Ud6d8DIoDdKBqfMsKLUHYIfdWMT4BoevEGCBiEs3jjl6inP4GI4Hqjz2zc5tD0Utlc+d3gLNxm74VYyhjr7ya9ssBsbAer3Ez9MjPc1dMFD8ahA4oBHTGTCT4gCinflj65sqi+BYQ3auDK47d+6h9g09IDoC2uCmQ+LTulyd9uPjjs1QyDQ5NKyx4EUIhdhfcXShA/8DwEerNHJSV/lKjG9FbhezB/UGLwoN9JT5HeTsB7kms1Y+ASGavFvRNOFROkMyOXnesbnzYvfRCvP7WdeZiUpD74qO30SEsmAe8oPXhRYYF4e+rAOBZrf3D4ECrxGk0Jo4c5C05PUUH/wfwoEu2OEqqkaR5WPkn8KrJa94my0hq0b1bRIAWc8/BxvDf6sBEFQQho2zMGtQMRgabXvYf5tmHDYkHorN5Uv5dDtDGGqBVpQRWRX+DLbd8tPRNbaIY+jexix66teXNpi5oGQ0qNzhDOh4+co5RXR+mAVnftgqlG7IgasJQm43NByWZLCygLNmQVyZ//56T/JV+PnJxx7ZxZTsUHFQYWrvvgcyF55bwKfeXV9JARVLtuhfBRVjW3T8fbho/UYaQbZ6QmKTgK2YwsCl6icWa2PePA== 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)(376002)(136003)(39850400004)(346002)(366004)(396003)(451199015)(36756003)(38350700002)(2906002)(41300700001)(83380400001)(44832011)(86362001)(6916009)(478600001)(1076003)(2616005)(4326008)(316002)(6486002)(66946007)(186003)(8936002)(5660300002)(26005)(6512007)(38100700002)(8676002)(66556008)(52116002)(6666004)(66476007)(6506007); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: IZe7Z59x1HuD9VQCJLeZGcKExMYh4drvb9yr2YgNlONmsVejvnL4VXyA1tX0obZDVyLrkw1OcrRkPuAZbrqkuwETyhAb9ULBO0ibl5huDBfnSR0zeFOT3Vtches1NPAAQvvolQfGSr4pnOZeBVYkqdB3F81o0qbysr2Pe6W3+V140uzhC5rjJ1YEnE916IID7XodY02lzT6Kk++UTcQizEz/x+rQy/EMQrkcc2aXnKT3Rf3W94IU1K/3Igh9ys0yBOsBCkopNWLcnRiksV66hpx8lrnqdjrDwyIf9lJyyvIOuuIGZ8E3QEFX7gujGCzV3Sl/U2I5IGt4wIEKYsiKp2g+zE1+YXHz5UXPi9mkPA5eMnV+t2dQdJbadvnF3CxkQaV+Ilu5xEHkcaDeqwS229faI0whUGwAHUcheokJKBIEA7A0EsdzKQd2/FutIr2IAFY8zGutVDzAW5bgdvCOyt74BkKX8g/9GFFGtyhX5qdTQVXf+NBCxdyjmI9VuYZvwsf9TF0aJNjTKfSQYyZR6zUCu8XAagjz3E9YOjWrVuHFg55MsbLMOq5vYoQ4zP1iq+GwIrSo28AQaM/s9fK81FPDyP/+PwvV8yAbsBSzy0UdhEh6DgXLWscgdmXgqesnBpmTD7iebBsBnq300kr6RRnOBgp7VXuRbjcG3EM/6YNKBq+pHrD4CWgumSb/od0csUS7Qr40PSO9x0dURm63kr6mfcLSQEQQOBkCCdlWWYSgL59+BMT91Yj1tMD97O7ATl7R9pdXTkPXtOahYizzvodWH05/CgI9NdjjCvY0Xfqv0O6cyv7rzZohVa2k4Pi+vTyp/Qvq7Sw6koX66LYolhn3ibnm18uiVNj7GusJ3zlWeurxNgEoCoCcXTfPOL3GTLZiUtuHFbYa7pv3g5UZaxzhZEQRVLSmQJnNqocJNpOkj9mdmceFaToGrzeawyJmC4d+x2lvVeUSl3elnVH/+dAfVxq2NgXKQf7/wMyKxfTU3n2eZfchv/fV7uKXM4K40h1lmwRuZeAWXqFXZl2Ki9a5xTpRPsVo86dtD0/+SJzKs8ZbWtayh+imkuJPoZ0lnLGtUJ/n76ALRC7nvY4DHJ34vj6vt/7H0KKY1ap+YV/6znrduzxsMKtV1kOW0M+Vxv8JFqVadlX+9hYP2zWIR3RWo+ypNz6PiHsn/daKH93GWLdSPrC3ZSLQaZGG0IEJCd1lIOsxqB/k7M68hRg/H2nxNOL4THqVNAIx/DeFBUw9GPLCLGdtIyIx6EO1gIzXY1nK5QzRiVrSSBACNlJV48VHYjxZWct2+vhJ/W9SKuk7FnmPMDpTI2LZickj1PmOQdm8ypvip/5RSCmmsvIbq5GiztFqwvJrnFjrhYglE7lyKwwE8KsO/e4vKFzCvUl1hq4bdnohd18twCMQctiJ12x1NbjXq4keKR6z8hUHRnFmIX6G8zZdSg+UYOmnHz9wdaGFifm79SdVJpt35FOregFYO+d2JbugNjxstWdimDA9x0tWmcxlkF2MyRwoXoHV7vqu3bw36x15mCxaGXoQxdEzK8H+KPJ7TdjxPZpzcrENZbGp9yk8inMjEjOOa/fOBfvaAdAa249hy8cVkkdcFw== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7d651923-b9db-4bb8-37fb-08dac739a94e X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Nov 2022 18:46:09.5603 (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: 4JPwXAQUccUt90r3L0e35zefS5+JSLjkKutsJaoVBCw5L7h9FwbHmp2Dk7200YsLl5IXr6y+4QYkfpDkhg8aTqGsgzqJJQ4sT65jj5IGbjs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR08MB6607 Received-SPF: pass client-ip=40.107.249.106; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR02-DB5-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-bounces+qemu-devel=archiver.kernel.org@nongnu.org In the next patch ZFS TRIM support for FreeBSD will be added. Move Linux-specific TRIM code to commands-linux.c file. Signed-off-by: Alexander Ivanov Reviewed-by: Konstantin Kostiuk --- qga/commands-linux.c | 73 ++++++++++++++++++++++++++++++++++++++++++++ qga/commands-posix.c | 72 ------------------------------------------- 2 files changed, 73 insertions(+), 72 deletions(-) diff --git a/qga/commands-linux.c b/qga/commands-linux.c index 214e408fcd..fb01114153 100644 --- a/qga/commands-linux.c +++ b/qga/commands-linux.c @@ -13,6 +13,7 @@ #include "qemu/osdep.h" #include "qapi/error.h" +#include "qga-qapi-commands.h" #include "commands-common.h" #include "cutils.h" #include @@ -284,3 +285,75 @@ int qmp_guest_fsfreeze_do_thaw(Error **errp) return i; } #endif /* CONFIG_FSFREEZE */ + +#if defined(CONFIG_FSTRIM) +/* + * Walk list of mounted file systems in the guest, and trim them. + */ +GuestFilesystemTrimResponse * +qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **errp) +{ + GuestFilesystemTrimResponse *response; + GuestFilesystemTrimResult *result; + int ret = 0; + FsMountList mounts; + struct FsMount *mount; + int fd; + struct fstrim_range r; + + slog("guest-fstrim called"); + + QTAILQ_INIT(&mounts); + if (!build_fs_mount_list(&mounts, errp)) { + return NULL; + } + + response = g_malloc0(sizeof(*response)); + + QTAILQ_FOREACH(mount, &mounts, next) { + result = g_malloc0(sizeof(*result)); + result->path = g_strdup(mount->dirname); + + QAPI_LIST_PREPEND(response->paths, result); + + fd = qga_open_cloexec(mount->dirname, O_RDONLY, 0); + if (fd == -1) { + result->error = g_strdup_printf("failed to open: %s", + strerror(errno)); + result->has_error = true; + continue; + } + + /* We try to cull filesystems we know won't work in advance, but other + * filesystems may not implement fstrim for less obvious reasons. + * These will report EOPNOTSUPP; while in some other cases ENOTTY + * will be reported (e.g. CD-ROMs). + * Any other error means an unexpected error. + */ + r.start = 0; + r.len = -1; + r.minlen = has_minimum ? minimum : 0; + ret = ioctl(fd, FITRIM, &r); + if (ret == -1) { + result->has_error = true; + if (errno == ENOTTY || errno == EOPNOTSUPP) { + result->error = g_strdup("trim not supported"); + } else { + result->error = g_strdup_printf("failed to trim: %s", + strerror(errno)); + } + close(fd); + continue; + } + + result->has_minimum = true; + result->minimum = r.minlen; + result->has_trimmed = true; + result->trimmed = r.len; + close(fd); + } + + free_fs_mount_list(&mounts); + return response; +} +#endif /* CONFIG_FSTRIM */ diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 32493d6383..b2a6d8b227 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -1607,78 +1607,6 @@ GuestFilesystemInfoList *qmp_guest_get_fsinfo(Error **errp) } #endif /* CONFIG_FSFREEZE */ -#if defined(CONFIG_FSTRIM) -/* - * Walk list of mounted file systems in the guest, and trim them. - */ -GuestFilesystemTrimResponse * -qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **errp) -{ - GuestFilesystemTrimResponse *response; - GuestFilesystemTrimResult *result; - int ret = 0; - FsMountList mounts; - struct FsMount *mount; - int fd; - struct fstrim_range r; - - slog("guest-fstrim called"); - - QTAILQ_INIT(&mounts); - if (!build_fs_mount_list(&mounts, errp)) { - return NULL; - } - - response = g_malloc0(sizeof(*response)); - - QTAILQ_FOREACH(mount, &mounts, next) { - result = g_malloc0(sizeof(*result)); - result->path = g_strdup(mount->dirname); - - QAPI_LIST_PREPEND(response->paths, result); - - fd = qga_open_cloexec(mount->dirname, O_RDONLY, 0); - if (fd == -1) { - result->error = g_strdup_printf("failed to open: %s", - strerror(errno)); - result->has_error = true; - continue; - } - - /* We try to cull filesystems we know won't work in advance, but other - * filesystems may not implement fstrim for less obvious reasons. - * These will report EOPNOTSUPP; while in some other cases ENOTTY - * will be reported (e.g. CD-ROMs). - * Any other error means an unexpected error. - */ - r.start = 0; - r.len = -1; - r.minlen = has_minimum ? minimum : 0; - ret = ioctl(fd, FITRIM, &r); - if (ret == -1) { - result->has_error = true; - if (errno == ENOTTY || errno == EOPNOTSUPP) { - result->error = g_strdup("trim not supported"); - } else { - result->error = g_strdup_printf("failed to trim: %s", - strerror(errno)); - } - close(fd); - continue; - } - - result->has_minimum = true; - result->minimum = r.minlen; - result->has_trimmed = true; - result->trimmed = r.len; - close(fd); - } - - free_fs_mount_list(&mounts); - return response; -} -#endif /* CONFIG_FSTRIM */ - #define LINUX_SYS_STATE_FILE "/sys/power/state" #define SUSPEND_SUPPORTED 0 From patchwork Tue Nov 15 18:46:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 13044074 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 48E8AC4332F for ; Tue, 15 Nov 2022 18:47:42 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ov0xQ-0001PN-MS; Tue, 15 Nov 2022 13:46:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ov0xN-0001ON-8w for qemu-devel@nongnu.org; Tue, 15 Nov 2022 13:46:50 -0500 Received: from mail-ve1eur02on072c.outbound.protection.outlook.com ([2a01:111:f400:fe06::72c] helo=EUR02-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 1ov0xL-0007qz-HN for qemu-devel@nongnu.org; Tue, 15 Nov 2022 13:46:49 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SD/0ADTe90AQFwuyCihMpu8C/6EqYeWyoWlXnyAkkeKkudAU3taoHDPnvUywZ8n+X4oAGeqBLv8kMN2P26AfH3eb1YZ7FkgfQXYGI9vABMeLnw/yqFHLUAuayCzr8s2CgP6e9UrjuZAem0B2X02uEmja6sZ/nWELFooMRILMLc+OMb2bsO1itjRNkCChfwhB1caWenKU+aE+9K1gujc9n7DZRxkLQDUNPnsjM8JQdN5x1/8XUCVK6eEl/fEo61VNpn+eM1prUTBBQT9JrpWhd1gKFHNhhPSa8fjystjqZNmWb3ClTGu4NElitYF230ZguoweSqwn9Ul9XhSOtWMu+Q== 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=WNwrz3wOMOJ/dfpuiTcgtStHV/H+vkSjEA7jv2TxRbE=; b=FzZQBVDBSx+G6DGjGQZqLdPwQEX0+Yoyfk1QfJCu9/gsOkI2liWZq4Vf7MVvxfhT/A3ZiZS+jWM+JGccrpcYk3OJHWhfOzw0Kg1s7d3QzHLtFBVczVhUMNXCMtb+1YyWGtHbKjarTz57E3WFzCnU+n+SLnW57jL4xdV7VsvXrZzWa9OwV+W4NfICYD+FBPNAmrVF58szOzDrpExC+CUc7QyaER0Ya+H91au7MyMMOK/+fqAJmc8T4J4yDy+MWEAGv6fl3tFGcG9iCK8HNivJ5TAV5sjjPHM5BMCsjqkvBCfW1rEssIqZeTqsWczbjKkvl4Y6q/H27AYvCdLnAYWiZg== 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=WNwrz3wOMOJ/dfpuiTcgtStHV/H+vkSjEA7jv2TxRbE=; b=C1qFDT2ebDlV1lIIU/Sez+9NMBELP7soMhptN8yeeEErgksahmlIWUzmOP8hnxLb4e8aw6wqJLQur5OTHrMPs4rk4OLNOmf4tuOc/LwS4/g6etI0/NgubgDav6Q5Kt9A2q7GrIl/oUMcYS1firMNPSS9b6iDWWIrBVKJWcsHoT8ByGPSa6X5M+KnbSTFJDQeg6ivwG2htOppvBr0dqtFO8jzWVHR3oA/T/yA+Gw1nKlrQ3d+P/6rXor1FLPshSVIPshHvXMZj4UWIEwbENKh+h6kHJNDqDSlN9wnPmR+WSY3rkHEOabbEAy48n0WRoX1v2eznzcJZOhJ6Z28nMQkjQ== 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 PAXPR08MB6607.eurprd08.prod.outlook.com (2603:10a6:102:152::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5834.6; Tue, 15 Nov 2022 18:46:10 +0000 Received: from AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::fa9b:7e41:680b:aeb5]) by AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::fa9b:7e41:680b:aeb5%8]) with mapi id 15.20.5834.007; Tue, 15 Nov 2022 18:46:10 +0000 From: Alexander Ivanov To: qemu-devel@nongnu.org Cc: den@virtuozzo.com, michael.roth@amd.com, kkostiuk@redhat.com, marcandre.lureau@gmail.com Subject: [PATCH 2/2] qga: Add ZFS TRIM support for FreeBSD Date: Tue, 15 Nov 2022 19:46:00 +0100 Message-Id: <20221115184600.747961-3-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221115184600.747961-1-alexander.ivanov@virtuozzo.com> References: <20221115184600.747961-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: AM6P193CA0102.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:88::43) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR08MB7095:EE_|PAXPR08MB6607:EE_ X-MS-Office365-Filtering-Correlation-Id: bc0875a5-7f0c-47b0-391c-08dac739a9a4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bPXC7jWWacNUzoOhSYJvMq+VeFaG48s2a+PIeb/vvKFnTlhKO0MmS1ZTJUHlvo2S3hPMKQdM6Uvg5tFdKmX89ag/IUQJ8cEqY2oUHkbaK60KyDX8aG6wkGqxOWqqRb9L++R0YA+iXzqWrrinxAS7NEEVflwrmgf/hEB69UxkYugAtpjJX+N024CuAZe4yto//Zev0o+zaNC1nzGgJT/Bkg6AojmbJa+5i5j67fDKs5Vrss0kEpEnXv4c3CAP960EaxqDZG3tKGFIDRhbY9qIGOODivpdIoT0ig/MhjR/Hu3Ylk40xT71HOF7vv8WNKUgiAJdtBPBVp2oaJhEKExaXx0IrlokXas/z0TKE4s8Tn4Fh74O0nB8aAR8+9E1QsvzQ6OI2wOi6yYVkjxPboC1I8IwPzOTBVvMXcHpwY766y9nitQ1aInN+QsAssaQe3hKMQHj0cNGU7Uc752+H5RrKwxuORpsrcl6J7DjIxlklNZeoInX6YWLcWisYsrITbnXqrCvgKmlxjvqU9J3z4EkeINUVwF2aNMDprLw89FsZee+yrPpI9OygNnq8yq8j+39/f5/lwejv1u+Vag6mQxC/GsSMJetlOtQuTBjDxnEmW3zpvQxFtAtRyFI+UHceBbp01Go0uwe1WrpX/y3TGXiGkOrkhh3XTwly7R1aNMshAUFj546NmZb9nOuRF9yt8Cz9EbhmiIXyQt72fy5B5PSlr9ZjQC8kp0MQ3koBHk2Nd0HMcwC13eFDArdzqJLQ/6d 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)(376002)(136003)(39850400004)(346002)(366004)(396003)(451199015)(36756003)(38350700002)(2906002)(41300700001)(83380400001)(44832011)(86362001)(6916009)(478600001)(1076003)(2616005)(4326008)(316002)(6486002)(66946007)(186003)(8936002)(5660300002)(26005)(6512007)(38100700002)(8676002)(66556008)(52116002)(6666004)(66476007)(6506007); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 0Krxj7N1DpZ7nx3BggGyjBQ5OPIMBXJS4UOzlnvq2NYlkqbpfijLr5RHNG7gKHis9uVX31/pdGn/vYvD0V06LfAWnAzgeMhr+9VUztVGWu5ZFHA0RHeL+o8BnDSvDEc9l5CeE95lkkKdtrUj+AGilYceqUniOVUD+cD1yvEZ+o306rNEkbQ2q6ukcddbkYFSmvOv3UTJYOVlIk45YYPvAJH4a+FkBO86zywwD4LMN+oJF+5zQTxY2V0K8pTXmZVJfd/wGTR4UCej5M3joLrDsWXBQVFiKVsT1u5wBvi3/UdT9ivaSOHcADdGNn95NUHAxSQZAto01j3RSwehUZ9S8sMJzKZXzr76oXffGVBE2LH/tNd51JlNT/IROsD1xg4am52QUhGdg4RwEa6YloXoIZDS/uACSMRpuDTnxulFAnu8SVCHRvqmy8PQkm+dzTtBFM7eI++KOdW3ZZBHvky1Kav8zwWy3jod7F0V7G6UcNyg4VCG4nrXsc6s+WlT5yNFcfGzuzwTFeBkut0r30qcWncmlgpLv+bkubuncRrsmVTYYhmzs+tleAVw4zRypudtd1la+lYGK584Zmg8SpyPdtLAHLzcybs0inDxgGoaFqMwMuB82XJuSlN6gap3JxWhcAVRg8W0GPNVJQBIuqzMnt1UZuQpuCGx/oxtHLTG8iYhj+Mzfx5Wyo32HKPu9RVOeF5ySDsAsGR7NhvUDrJtEQr9JWYunYmlUoXLrAz8jdIKwv7vvz/OA7eOvhsmEEu33EzGsb6x9AWjECsJDc70s/i6eFaa9O4z4atn6XhxrhNjt2gc9ZuHxTDisz3LjljnhG532RUvwLW+efqeGWMhso3qfo94ntTUxyETvAuzZHJ/xIV7tILS41LN7a36BsC9m231LIM68Oe1HctYKE7Fs9IurZ0rmq2QPA8v0cLHB+KQO1izt9a69hznBGYYiu4z0Yl4h/RmJbBR7ajSB7PPL9OT11oEEBoag4+6nR1qJCGP3sA7LJ3KT7mi9o16ULlL+rSUgyds1isqnQqwDjb3ZusHDf7yBVLmUuyeA8eO6OmbleiYh1UqmUm9iCc+/FF0+nPdeqpXFUUX43DOnZGdHnk3gkCxhV9uip+YPAAs6jotHv9ZGHu9owhDsdMttWW49831X1CwPg+B9Qbt2Mys9krG3YSVtjiX9lMVdrNPECJfRUUWBxjf3cinMYUKQ1u2gYpNuw7/63P5WKBwzpxdx5d/25trXBsKYCUcJ8RdIcqCvAPdQIyPav1dQLS41LYsggZFLEClomp+tZzG/xCU3kNdgW6h5JiNA9/PzPyy9OPNV9DuaDVknmBh/iQlMfh7uealH8sr/GhKq2ZlVNMEgvTHFD8gtzh4qeEpoCjjj1km2v+pR8clINg3jvyH/ZK4/0YvvD9jrXGUqHC/AVZRgXV5ey90oM/vwNU1P4iFyQWxnaFdGgGPgZRL7LOCS4MGnk/KMOUGruzPuaqPgglnopIS8WwvPWpjdBt1LDtdySRU3/PDnG7NmBdZZvXYnDZ0R56ErCQMJ6Jmvqv/6JdPkM90PfdAih6y3IBwuzHrObGWflemzCoPX2WTINqEQonf1DWwQqtxyLM9JPb46NfM9Q== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: bc0875a5-7f0c-47b0-391c-08dac739a9a4 X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Nov 2022 18:46:10.1084 (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: 8IwOdOmMqkSws3dPTPrePhROe0fy9M1KuCcA3TsPQgiP/tSBsT4Y7A32xl45FMmTu6H5y9xD2EnRfyijEtjG8oezzn8OcEx847nfCmG2f90= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR08MB6607 Received-SPF: pass client-ip=2a01:111:f400:fe06::72c; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR02-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, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Use zpool tool for ZFS pools trimming in FreeBSD. Signed-off-by: Alexander Ivanov Reviewed-by: Konstantin Kostiuk --- qga/commands-bsd.c | 109 ++++++++++++++++++++++++++++++++++++++++++ qga/commands-common.h | 1 + 2 files changed, 110 insertions(+) diff --git a/qga/commands-bsd.c b/qga/commands-bsd.c index 15cade2d4c..960c4209e5 100644 --- a/qga/commands-bsd.c +++ b/qga/commands-bsd.c @@ -170,6 +170,115 @@ GuestCpuStatsList *qmp_guest_get_cpustats(Error **errp) } #endif /* CONFIG_FSFREEZE */ +#if defined(CONFIG_FSTRIM) +typedef struct FsPool { + char *name; + QTAILQ_ENTRY(FsPool) next; +} FsPool; + +typedef QTAILQ_HEAD(FsPoolList, FsPool) FsPoolList; + +static void build_fs_pool_list(FsPoolList *pools, Error **errp) +{ + FILE *fp; + char *line = NULL, *p; + size_t linecap = 0; + ssize_t linelen; + FsPool *pool; + + fp = popen("/sbin/zpool list -H", "r"); + if (fp == NULL) { + error_setg_errno(errp, errno, "failed to run zpool"); + return; + } + + while ((linelen = getline(&line, &linecap, fp)) > 0) { + p = strchr(line, '\t'); + if (!p) { + continue; + } + + *p = '\0'; + + pool = g_new0(FsPool, 1); + pool->name = g_strdup(line); + QTAILQ_INSERT_TAIL(pools, pool, next); + } + + free(line); + pclose(fp); +} + +static void free_fs_pool_list(FsPoolList *pools) +{ + FsPool *pool, *temp; + + if (!pools) { + return; + } + + QTAILQ_FOREACH_SAFE(pool, pools, next, temp) { + QTAILQ_REMOVE(pools, pool, next); + g_free(pool->name); + g_free(pool); + } +} + +/* + * Walk the list of ZFS pools in the guest, and trim them. + */ +GuestFilesystemTrimResponse * +qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **errp) +{ + GuestFilesystemTrimResponse *response; + GuestFilesystemTrimResultList *list; + GuestFilesystemTrimResult *result; + int ret; + FsPoolList pools; + FsPool *pool; + char cmd[256]; + Error *local_err = NULL; + + slog("guest-fstrim called"); + + QTAILQ_INIT(&pools); + build_fs_pool_list(&pools, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return NULL; + } + + response = g_malloc0(sizeof(*response)); + + QTAILQ_FOREACH(pool, &pools, next) { + result = g_malloc0(sizeof(*result)); + result->path = g_strdup(pool->name); + + list = g_malloc0(sizeof(*list)); + list->value = result; + list->next = response->paths; + response->paths = list; + + snprintf(cmd, sizeof(cmd), "/sbin/zpool trim %s", pool->name); + ret = system(cmd); + if (ret != 0) { + result->error = g_strdup_printf("failed to trim %s: %s", + pool->name, strerror(errno)); + result->has_error = true; + continue; + } + + result->has_minimum = true; + result->minimum = 0; + result->has_trimmed = true; + result->trimmed = 0; + } + + free_fs_pool_list(&pools); + return response; +} +#endif /* CONFIG_FSTRIM */ + #ifdef HAVE_GETIFADDRS /* * Fill "buf" with MAC address by ifaddrs. Pointer buf must point to a diff --git a/qga/commands-common.h b/qga/commands-common.h index 8c1c56aac9..922f9c479b 100644 --- a/qga/commands-common.h +++ b/qga/commands-common.h @@ -28,6 +28,7 @@ #ifdef UFSSUSPEND #define CONFIG_FSFREEZE #endif +#define CONFIG_FSTRIM #endif /* __FreeBSD__ */ #if defined(CONFIG_FSFREEZE) || defined(CONFIG_FSTRIM)