From patchwork Tue Jul 30 01:09:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746118 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D1734C8C0 for ; Tue, 30 Jul 2024 01:09:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722301767; cv=none; b=W9WlQpGEUD+zL6Y3lgTdaGXZYwboN83Znc9P2LeuKlsQYbbZZ+dZ/4xS0/v5dcgRVjfm08zr0yhMYWbrRtET7N5EHITZKsAey1JZTOUp1POKBS+vYZ14M2ssUeZvQIbdDrdgn00zMouRjq3acXwiE7jvTq3FbP8sCBKh4qT/mlg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722301767; c=relaxed/simple; bh=kDR/a6OSfnxuqLtc1Ws8KRE+ZoVS+raJIaoVL9xvQTA=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jGHRIZfxCGBJOB+tJ28qkf+t3oNLinMmmTFFqsHf9CAuo+kJBX2ENlQ4G8EZLV/wuW9XcX7T1LKXLGdlGTEGojSto6ZsZ2uigRRHVu5a8NeuXnLbEnsh2EDrpVQcj2O8ChGt1Y1rebljpapebOb7dvXDlkydte5Y1aWRkrLbT+k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jau07q9N; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jau07q9N" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 56534C32786; Tue, 30 Jul 2024 01:09:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722301767; bh=kDR/a6OSfnxuqLtc1Ws8KRE+ZoVS+raJIaoVL9xvQTA=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=jau07q9NUMLjo0C73lTZSiWASsG5uKqD2jYJi8V7RPFbVIxdonxN1BdnkFj/S9FGv 2RKvZTehGPJAsYwTabfOpUODBvtvPokrsdcHSYsu1oTNCVJpRX/K0xoqcM7u2qr/Hw rx9CfLyxFUGWzupS5wZh9p4MjKaeRnm6IWEWi3SyeIoSm3AwJPopTKeFiiorNbFuH6 npfs0moJ02UrvXyrdQAo0uixFJEH4cMLa+H+ELQaYuFJVZUxLA7DOAIt/1MCLDXYeB 71moQSSuOBPTcAn1PIUu7mbvxc9OyEsJWrvgRzAQf9t2HTlQA0ae8js873NzvHFLGS PJ99GPZwylALg== Date: Mon, 29 Jul 2024 18:09:26 -0700 Subject: [PATCH 1/7] xfs_scrub: move FITRIM to phase 8 From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229848049.1349330.8783228525240729602.stgit@frogsfrogsfrogs> In-Reply-To: <172229848026.1349330.12889405227098722037.stgit@frogsfrogsfrogs> References: <172229848026.1349330.12889405227098722037.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Issuing discards against the filesystem should be the *last* thing that xfs_scrub does, after everything else has been checked, repaired, and found to be clean. If we can't satisfy all those conditions, we have no business telling the storage to discard itself. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- scrub/Makefile | 1 + scrub/phase4.c | 30 ++---------------------- scrub/phase8.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++ scrub/xfs_scrub.h | 3 ++ 4 files changed, 73 insertions(+), 27 deletions(-) create mode 100644 scrub/phase8.c diff --git a/scrub/Makefile b/scrub/Makefile index c11c2b5fe..8ccc67d01 100644 --- a/scrub/Makefile +++ b/scrub/Makefile @@ -68,6 +68,7 @@ phase4.c \ phase5.c \ phase6.c \ phase7.c \ +phase8.c \ progress.c \ read_verify.c \ repair.c \ diff --git a/scrub/phase4.c b/scrub/phase4.c index 9080d3881..451101811 100644 --- a/scrub/phase4.c +++ b/scrub/phase4.c @@ -227,16 +227,6 @@ repair_everything( return action_list_process(ctx, ctx->fs_repair_list, XRM_FINAL_WARNING); } -/* Trim the unused areas of the filesystem if the caller asked us to. */ -static void -trim_filesystem( - struct scrub_ctx *ctx) -{ - if (want_fstrim) - fstrim(ctx); - progress_add(1); -} - /* Fix everything that needs fixing. */ int phase4_func( @@ -248,7 +238,7 @@ phase4_func( if (action_list_empty(ctx->fs_repair_list) && action_list_empty(ctx->file_repair_list)) - goto maybe_trim; + return 0; /* * Check the resource usage counters early. Normally we do this during @@ -281,20 +271,7 @@ phase4_func( if (ret) return ret; - ret = repair_everything(ctx); - if (ret) - return ret; - - /* - * If errors remain on the filesystem, do not trim anything. We don't - * have any threads running, so it's ok to skip the ctx lock here. - */ - if (ctx->corruptions_found || ctx->unfixable_errors != 0) - return 0; - -maybe_trim: - trim_filesystem(ctx); - return 0; + return repair_everything(ctx); } /* Estimate how much work we're going to do. */ @@ -307,10 +284,9 @@ phase4_estimate( { unsigned long long need_fixing; - /* Everything on the repair list plus FSTRIM. */ + /* Everything on the repair lis. */ need_fixing = action_list_length(ctx->fs_repair_list) + action_list_length(ctx->file_repair_list); - need_fixing++; *items = need_fixing; *nr_threads = scrub_nproc(ctx) + 1; diff --git a/scrub/phase8.c b/scrub/phase8.c new file mode 100644 index 000000000..07726b5b8 --- /dev/null +++ b/scrub/phase8.c @@ -0,0 +1,66 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2018-2024 Oracle. All Rights Reserved. + * Author: Darrick J. Wong + */ +#include "xfs.h" +#include +#include +#include +#include +#include "list.h" +#include "libfrog/paths.h" +#include "libfrog/workqueue.h" +#include "xfs_scrub.h" +#include "common.h" +#include "progress.h" +#include "scrub.h" +#include "repair.h" +#include "vfs.h" +#include "atomic.h" + +/* Phase 8: Trim filesystem. */ + +/* Trim the unused areas of the filesystem if the caller asked us to. */ +static void +trim_filesystem( + struct scrub_ctx *ctx) +{ + fstrim(ctx); + progress_add(1); +} + +/* Trim the filesystem, if desired. */ +int +phase8_func( + struct scrub_ctx *ctx) +{ + if (action_list_empty(ctx->fs_repair_list) && + action_list_empty(ctx->file_repair_list)) + goto maybe_trim; + + /* + * If errors remain on the filesystem, do not trim anything. We don't + * have any threads running, so it's ok to skip the ctx lock here. + */ + if (ctx->corruptions_found || ctx->unfixable_errors != 0) + return 0; + +maybe_trim: + trim_filesystem(ctx); + return 0; +} + +/* Estimate how much work we're going to do. */ +int +phase8_estimate( + struct scrub_ctx *ctx, + uint64_t *items, + unsigned int *nr_threads, + int *rshift) +{ + *items = 1; + *nr_threads = 1; + *rshift = 0; + return 0; +} diff --git a/scrub/xfs_scrub.h b/scrub/xfs_scrub.h index ed86d0093..6272a3687 100644 --- a/scrub/xfs_scrub.h +++ b/scrub/xfs_scrub.h @@ -98,6 +98,7 @@ int phase4_func(struct scrub_ctx *ctx); int phase5_func(struct scrub_ctx *ctx); int phase6_func(struct scrub_ctx *ctx); int phase7_func(struct scrub_ctx *ctx); +int phase8_func(struct scrub_ctx *ctx); /* Progress estimator functions */ unsigned int scrub_estimate_ag_work(struct scrub_ctx *ctx); @@ -112,5 +113,7 @@ int phase5_estimate(struct scrub_ctx *ctx, uint64_t *items, unsigned int *nr_threads, int *rshift); int phase6_estimate(struct scrub_ctx *ctx, uint64_t *items, unsigned int *nr_threads, int *rshift); +int phase8_estimate(struct scrub_ctx *ctx, uint64_t *items, + unsigned int *nr_threads, int *rshift); #endif /* XFS_SCRUB_XFS_SCRUB_H_ */ From patchwork Tue Jul 30 01:09:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746119 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 97AC0D268 for ; Tue, 30 Jul 2024 01:09:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722301783; cv=none; b=NkGTyank6zOfhvG0Z70LQQWbrMmfBkwz7mO6iQKUwhnEbdcox5Yypp9fyyCoAFEMzCIFqeIBnYH2auIclnWLb2rJmJY0RaXEVBysgC/cpHPFHVc/GOcc0jElCk2ZpvZ0UiB8jOW3qlZzhiqtDjzS20gBWSssi63sU7mKixrYiW0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722301783; c=relaxed/simple; bh=zAC+vqUJufFpa6yVoEPQ4AWn7sLyLMODGoeU2304eBg=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=PsYOnpiiSTPZbzhXVl5Hst2fhuH0Y6m4LsbaUoZboI14lacWhSJtKaRihHfui5eyRK94zDWCh3UXUfOsNjUWmQqKJB5IkRs34A5b5sQ5BT9hwfR8EaXBQliRwbE24jIUhe5kSMMUbmD9xmaNncQ/duOtxKCCXZfkyaUkVDGxTzk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CiRwTxOh; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CiRwTxOh" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 16B47C32786; Tue, 30 Jul 2024 01:09:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722301783; bh=zAC+vqUJufFpa6yVoEPQ4AWn7sLyLMODGoeU2304eBg=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=CiRwTxOhnQahBFvL8GP7zNPCbJ2OB45TQ3+pB7vLLVM+cSa7KALGALaZhJ6DjkVn9 SZYGJ8BtTSKIVGCjwGf4KMk1LOT/2yQI+u6tgZOoVowETNH5Zn3EYENeSbhHRXi0II usCgazO2DYoDEHBQ+6zxVzCDwwD1onqUrHdO+2Ib10dzTBi2H4M93wOOFdrYJWVCNC jVlJaB8ABE8irWAdkYP3ccwnRZJiZb3HMF64L6yAFNRQHGkZjEV461dU90Vot+pP9C AIlGv8qCy9X2o2GUSD8uOfC2n91hZE6SMu6UwWFVGMDMIUsibAT9tju5Uv6BnwV+SD JiLl3f0PEivJw== Date: Mon, 29 Jul 2024 18:09:42 -0700 Subject: [PATCH 2/7] xfs_scrub: ignore phase 8 if the user disabled fstrim From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229848063.1349330.15343951073553604167.stgit@frogsfrogsfrogs> In-Reply-To: <172229848026.1349330.12889405227098722037.stgit@frogsfrogsfrogs> References: <172229848026.1349330.12889405227098722037.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong If the user told us to skip trimming the filesystem, don't run the phase at all. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- scrub/xfs_scrub.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/scrub/xfs_scrub.c b/scrub/xfs_scrub.c index e49538ca1..edf58d07b 100644 --- a/scrub/xfs_scrub.c +++ b/scrub/xfs_scrub.c @@ -249,6 +249,7 @@ struct phase_rusage { /* Operations for each phase. */ #define DATASCAN_DUMMY_FN ((void *)1) #define REPAIR_DUMMY_FN ((void *)2) +#define FSTRIM_DUMMY_FN ((void *)3) struct phase_ops { char *descr; int (*fn)(struct scrub_ctx *ctx); @@ -429,6 +430,11 @@ run_scrub_phases( .fn = phase7_func, .must_run = true, }, + { + .descr = _("Trim filesystem storage."), + .fn = FSTRIM_DUMMY_FN, + .estimate_work = phase8_estimate, + }, { NULL }, @@ -449,6 +455,8 @@ run_scrub_phases( /* Turn on certain phases if user said to. */ if (sp->fn == DATASCAN_DUMMY_FN && scrub_data) { sp->fn = phase6_func; + } else if (sp->fn == FSTRIM_DUMMY_FN && want_fstrim) { + sp->fn = phase8_func; } else if (sp->fn == REPAIR_DUMMY_FN && ctx->mode == SCRUB_MODE_REPAIR) { sp->descr = _("Repair filesystem."); @@ -458,7 +466,8 @@ run_scrub_phases( /* Skip certain phases unless they're turned on. */ if (sp->fn == REPAIR_DUMMY_FN || - sp->fn == DATASCAN_DUMMY_FN) + sp->fn == DATASCAN_DUMMY_FN || + sp->fn == FSTRIM_DUMMY_FN) continue; /* Allow debug users to force a particular phase. */ From patchwork Tue Jul 30 01:09:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746120 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4A95FD528 for ; Tue, 30 Jul 2024 01:09:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722301799; cv=none; b=BfzkSZGfYHm4NDrbIsDhmZ5TTxS/8vtVoSJftoZoZbQToMaeIWcCMmwIxwM12Y8l1C0GOn1buBw9GmYGPtrNfdzQnhpA7Iz8HUwMndhmlk0Xmkid/sU1rWXwV4kTJzsz6q6G1xSRXZCnP9zfaEfbxb+iHh7oIhtFq02hPPBvmhc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722301799; c=relaxed/simple; bh=RLr8v64eJCBKjvQ0cZ/KwSE/5/mcsOPxY5+dQj9wUJM=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=olzYS4YCdrJiw1/bvfknMaX3zGQpKclLTYGpiJ1AmeF9YNbfHbsoEmeWdy+evXbk6hZmYkxFVAnQ6zhYXG6Prob2Wf/hRiBBjxNbRe11TTns+B4CQVgW1sd0nilE3y1ELeNF4tshug55zKfcRsw97XKX3dhN48WetYtQKGr3gFQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CBZ7VORr; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CBZ7VORr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CA8ACC32786; Tue, 30 Jul 2024 01:09:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722301798; bh=RLr8v64eJCBKjvQ0cZ/KwSE/5/mcsOPxY5+dQj9wUJM=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=CBZ7VORrBuK0KDDz8nXDCIIjxChpbCWkzd8GaSPE8fjffvCbRrTjSK+axpGSHNLdf Xs8nckzYg3U5RAOia9EZ6kVmMsH7rEUgQTT2Ymd913upuPqR/fB1sSjuCsY6gTLgMg QdrDvDkF5YwsRmx4B192qu7UI3knwejOZ0hR18bc/f5Qni5p+COOceS4TC9+arJxDM UoIPYOOC1+ugnI5SGk+mJbqBvKyqiGkv+k3J7ag2ccgzDtH6st+nzEWoTsK9JuU6KB d/+YikStXpRMRo265uropY5HI+PPVkkirRc54AVAuvHzjmGav0VVJxJrwfeNQIXlKv keHThxs3m/p0Q== Date: Mon, 29 Jul 2024 18:09:58 -0700 Subject: [PATCH 3/7] xfs_scrub: collapse trim_filesystem From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229848078.1349330.4131439093892039359.stgit@frogsfrogsfrogs> In-Reply-To: <172229848026.1349330.12889405227098722037.stgit@frogsfrogsfrogs> References: <172229848026.1349330.12889405227098722037.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Collapse this two-line helper into the main function since it's trivial. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- scrub/phase8.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/scrub/phase8.c b/scrub/phase8.c index 07726b5b8..e577260a9 100644 --- a/scrub/phase8.c +++ b/scrub/phase8.c @@ -21,15 +21,6 @@ /* Phase 8: Trim filesystem. */ -/* Trim the unused areas of the filesystem if the caller asked us to. */ -static void -trim_filesystem( - struct scrub_ctx *ctx) -{ - fstrim(ctx); - progress_add(1); -} - /* Trim the filesystem, if desired. */ int phase8_func( @@ -47,7 +38,8 @@ phase8_func( return 0; maybe_trim: - trim_filesystem(ctx); + fstrim(ctx); + progress_add(1); return 0; } From patchwork Tue Jul 30 01:10:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746121 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E64338F40 for ; Tue, 30 Jul 2024 01:10:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722301815; cv=none; b=ZTSAgeeqi/jjJM6tATd2ArKiqF5EmKoOppgnV/si4cGJYnZ5be0hK/eU+8eWJyQr5ETLuljyWCCse6wlY+amjaNdbFLaTatMjy2WUrdy8mLDb7Ht9jqor0Vy3l/OyjJVeXnVnBtlzHNLFCTe0VQEMTxZhBHlJnyD4ylbFcGAZ+o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722301815; c=relaxed/simple; bh=elHh/OJYcjGgqqAvBkoF7q3Jyy07/IqTsX03PTirwj8=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=oR+n8iRz0DSBQMOqMjDEjkF9QH07l2WdFut2Lj5uWyBQz7JabETWGPDhM3bDjD1amf4VdmDVnkGGYPYH+mqM68LLicXzCS6+oQoma9E9g3Ptb+G9s+vpHlR5mycLjYLwUhFKGI501h2liC/bcb8NFGp7JJuawktnCbNI87W0jw0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VQzw8uVX; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VQzw8uVX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 70E40C32786; Tue, 30 Jul 2024 01:10:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722301814; bh=elHh/OJYcjGgqqAvBkoF7q3Jyy07/IqTsX03PTirwj8=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=VQzw8uVX1kh2G56qIJd0MKsHXHPnh6lN9/k7AioGy0do5iee5X8mSB59+7BGBHiiT WgoJn/Q0cNdTYKgcd+WeYmRqBIAueEG583r4KApXQHyPVdqPvz0i/ZYUe+PvasuZmQ 2dEvLEXq5tUsiQ+asiVlcIQzw6gHseL97u1dEXVORxg66MpSGuwQeGoIGjqmXNcEMx hf3wSvqHGaxCzp4lIpivja7vFrj+/Oacocik8hv5y/pxlUdmokjlYf7yfgUSZllrJs tJLNr0iS0XFMQuQXgMySQTpOUW9EERUvRAHzPqNDORjam0ySBhPwfg/OxJde0aqtYq /DKnYkmfF/Z9Q== Date: Mon, 29 Jul 2024 18:10:13 -0700 Subject: [PATCH 4/7] xfs_scrub: fix the work estimation for phase 8 From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229848093.1349330.5114879856116788288.stgit@frogsfrogsfrogs> In-Reply-To: <172229848026.1349330.12889405227098722037.stgit@frogsfrogsfrogs> References: <172229848026.1349330.12889405227098722037.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong If there are latent errors on the filesystem, we aren't going to do any work during phase 8 and it makes no sense to add that into the work estimate for the progress bar. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- scrub/phase8.c | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/scrub/phase8.c b/scrub/phase8.c index e577260a9..dfe62e8d9 100644 --- a/scrub/phase8.c +++ b/scrub/phase8.c @@ -21,23 +21,35 @@ /* Phase 8: Trim filesystem. */ -/* Trim the filesystem, if desired. */ -int -phase8_func( +static inline bool +fstrim_ok( struct scrub_ctx *ctx) { - if (action_list_empty(ctx->fs_repair_list) && - action_list_empty(ctx->file_repair_list)) - goto maybe_trim; - /* * If errors remain on the filesystem, do not trim anything. We don't * have any threads running, so it's ok to skip the ctx lock here. */ - if (ctx->corruptions_found || ctx->unfixable_errors != 0) + if (!action_list_empty(ctx->fs_repair_list)) + return false; + if (!action_list_empty(ctx->file_repair_list)) + return false; + + if (ctx->corruptions_found != 0) + return false; + if (ctx->unfixable_errors != 0) + return false; + + return true; +} + +/* Trim the filesystem, if desired. */ +int +phase8_func( + struct scrub_ctx *ctx) +{ + if (!fstrim_ok(ctx)) return 0; -maybe_trim: fstrim(ctx); progress_add(1); return 0; @@ -51,7 +63,11 @@ phase8_estimate( unsigned int *nr_threads, int *rshift) { - *items = 1; + *items = 0; + + if (fstrim_ok(ctx)) + *items = 1; + *nr_threads = 1; *rshift = 0; return 0; From patchwork Tue Jul 30 01:10:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746122 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 87B95C8D7 for ; Tue, 30 Jul 2024 01:10:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722301830; cv=none; b=ZEXwRJw4T8O8Sl9g9RfW6X6GqWZ6pDbYgGpLqH6TpAsbD9wUojpxn/LIZzR19RjPzpIXh4/UshDM3noHeJETqZ29s5xAZjR91kBsbDhHWIpt1L6noxhPy9+n9U150QVmAzgrKLOyAYVDrxGgHzYvGEM5y01TPeML9g2XbiBUBfA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722301830; c=relaxed/simple; bh=YR9YmA00yTaL9KAhXeOr1R8goAwaA+FBABiD9DEOws0=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EcB5zax2i+7UohLu/uIKp+ZNYG8NPZUVp14WHlMx7PdOM4KbtFmPR/F+UGvju3Lzy315PnWVr9NPIvqy6SunlnFOQ0PgpaHc/FQS6F6tqU8wWTjEuuldBqmISp0PvhFFCamLsPaCfG1Sh7H3vhq2Ie/RO0cjmD7G/u1rh7e03Qo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jgZtR95L; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jgZtR95L" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 15E36C32786; Tue, 30 Jul 2024 01:10:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722301830; bh=YR9YmA00yTaL9KAhXeOr1R8goAwaA+FBABiD9DEOws0=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=jgZtR95LDesFLrrrBhxEqmhEuzXZG3GDW7nQG9WPq747jFlrDpHlBuWMtaQ0Nz72b 7fcL1ePfk+LOy8TPyVdu66sYFqtT9WgiTGuIw78hQzL0pzrM9xQsBap84xd+gRmta8 +Nz4tac3sVUhLcqMtMWnS+p5I4HPn9EEMRC/Yqa1G2OBuqPoH1WzZFrZT0+0SaxSRY 9qnRy2+oCK2BK6LOxD65MMS1H7CZPJjDbdXLSnOvs/qN6S6X9JXiFZyXIMyZliMa9g caMpE+A1cS4VmS+R8twB6W80BuysnOogUqR6aTUVkU4DPOWEjP3WPpeHHlov+TiEls e5GjLDe9nbYHQ== Date: Mon, 29 Jul 2024 18:10:29 -0700 Subject: [PATCH 5/7] xfs_scrub: report FITRIM errors properly From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229848108.1349330.13679178387676040837.stgit@frogsfrogsfrogs> In-Reply-To: <172229848026.1349330.12889405227098722037.stgit@frogsfrogsfrogs> References: <172229848026.1349330.12889405227098722037.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Move the error reporting for the FITRIM ioctl out of vfs.c and into phase8.c. This makes it so that IO errors encountered during trim are counted as runtime errors instead of being dropped silently. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- scrub/phase8.c | 12 +++++++++++- scrub/vfs.c | 12 +++++++----- scrub/vfs.h | 2 +- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/scrub/phase8.c b/scrub/phase8.c index dfe62e8d9..288800a76 100644 --- a/scrub/phase8.c +++ b/scrub/phase8.c @@ -47,10 +47,20 @@ int phase8_func( struct scrub_ctx *ctx) { + int error; + if (!fstrim_ok(ctx)) return 0; - fstrim(ctx); + error = fstrim(ctx); + if (error == EOPNOTSUPP) + return 0; + + if (error) { + str_liberror(ctx, error, _("fstrim")); + return error; + } + progress_add(1); return 0; } diff --git a/scrub/vfs.c b/scrub/vfs.c index 9e459d624..bcfd4f42c 100644 --- a/scrub/vfs.c +++ b/scrub/vfs.c @@ -296,15 +296,17 @@ struct fstrim_range { #endif /* Call FITRIM to trim all the unused space in a filesystem. */ -void +int fstrim( struct scrub_ctx *ctx) { struct fstrim_range range = {0}; - int error; range.len = ULLONG_MAX; - error = ioctl(ctx->mnt.fd, FITRIM, &range); - if (error && errno != EOPNOTSUPP && errno != ENOTTY) - perror(_("fstrim")); + if (ioctl(ctx->mnt.fd, FITRIM, &range) == 0) + return 0; + if (errno == EOPNOTSUPP || errno == ENOTTY) + return EOPNOTSUPP; + + return errno; } diff --git a/scrub/vfs.h b/scrub/vfs.h index 1ac41e5aa..a8a4d72e2 100644 --- a/scrub/vfs.h +++ b/scrub/vfs.h @@ -24,6 +24,6 @@ typedef int (*scan_fs_tree_dirent_fn)(struct scrub_ctx *, const char *, int scan_fs_tree(struct scrub_ctx *ctx, scan_fs_tree_dir_fn dir_fn, scan_fs_tree_dirent_fn dirent_fn, void *arg); -void fstrim(struct scrub_ctx *ctx); +int fstrim(struct scrub_ctx *ctx); #endif /* XFS_SCRUB_VFS_H_ */ From patchwork Tue Jul 30 01:10:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746123 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3DF4DD502 for ; Tue, 30 Jul 2024 01:10:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722301846; cv=none; b=c8aSazHf8LoBJM92QV+geHcS+YZWzDEcVz7S2wJtbv7TBixcSZRK0uvBzgAG9EB+geTKnWelU2ePnmS4PoZupjipRwEY6uhIpNpNL1DMv8mFN2uWRZxHZxUrE0TY58hx0QgJ0oc+xCxU9AGVn6VPcMbiL0+vCjS3WB+uy9w0D1Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722301846; c=relaxed/simple; bh=KSXMI0hWNh6vzD2vnemy+0fpUODX5Uh5r9Oumx1NoWA=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uc63tmZGZ5hlR/KV9b5LRCO25q1npNuhdZ70voei/u7di18//k8ICh63S7cy9WtSQ60b36uuu7B2FZFDSicTs7r1FxSZS4ykJWfkRK2/a+y1OPQ+HtEBeHYFAZFng+xtIBCTQprpXDwnbAPQEkVwIngDeyHju6FDaVdDyCdU6xM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=C5/hv1lG; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="C5/hv1lG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BB2DBC32786; Tue, 30 Jul 2024 01:10:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722301845; bh=KSXMI0hWNh6vzD2vnemy+0fpUODX5Uh5r9Oumx1NoWA=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=C5/hv1lGwC3TII60Er3dkdH+R7BoDPXXo5pbSUASfV9fHftCsS9Uz5fno6TbKO8lV Kk7su5gSHDe5UXRoGJqqsW/6MKPdtiy14k92xNNpfHkOmqS6GIEc3udZsXrtq4g6ry EDLYR2HjeQoOea1V/ztUQpxTkJSnPON61smCBzL8HAV0CfFCYEPrZa4AC3RQYxlc0J exwpTUY2AExK7NCN7ur1p5dFXzWM66Wip9KVXjTJ/2YTnUFSX/ovdHHaAWq9I1gm4F lfkN5j9XSvL5wbTdZwRrstjltD+8ee479JvpJdRKaQ4WotEnHraG3uiN9p8Yn2XVkf jdRcCQr8ywCTw== Date: Mon, 29 Jul 2024 18:10:45 -0700 Subject: [PATCH 6/7] xfs_scrub: don't call FITRIM after runtime errors From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229848123.1349330.4056000330400170809.stgit@frogsfrogsfrogs> In-Reply-To: <172229848026.1349330.12889405227098722037.stgit@frogsfrogsfrogs> References: <172229848026.1349330.12889405227098722037.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Don't call FITRIM if there have been runtime errors -- we don't want to touch anything after any kind of unfixable problem. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- scrub/phase8.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scrub/phase8.c b/scrub/phase8.c index 288800a76..75400c968 100644 --- a/scrub/phase8.c +++ b/scrub/phase8.c @@ -39,6 +39,9 @@ fstrim_ok( if (ctx->unfixable_errors != 0) return false; + if (ctx->runtime_errors != 0) + return false; + return true; } From patchwork Tue Jul 30 01:11:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13746124 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9300C10E3 for ; Tue, 30 Jul 2024 01:11:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722301861; cv=none; b=s0Q6vXgSP9c+aFsyeGfmMqgYoO/gIzEX3g7AzfrkLPo2Hqd8iv5WY7BXSgrV2NMi/kSDTPfpkiYlQmGbmjaxMbWxSTwc3P5dj98jSLmeaEQ8lT9x9PbOaQfze2zt/WvNx2utKns35xrT6THol878B04gALGVc3qZ0OBYVFtIZms= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722301861; c=relaxed/simple; bh=8XChWzotnXNdjHNOruyLXW2cI9kJWIMBSjU/gI11kd0=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=G8ihJIZL4tpyXDstpG4g+PUE6k992X8pw1GgxERG1Y0tgDvMeafTS+RC0lzB3GLwBL2fWzaM2KkYs5XD+P0ODha7Gpeffm1VYhxtrfcWx3UYTy52JXhidZ4BdOKKkVYkhpGwglSWhZmP+twSNpvU9Z8RBXBdBfP0FhbFWprdmUc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EmrW7JKN; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="EmrW7JKN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 68D67C32786; Tue, 30 Jul 2024 01:11:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722301861; bh=8XChWzotnXNdjHNOruyLXW2cI9kJWIMBSjU/gI11kd0=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=EmrW7JKNqrlS/kAtg8mWP6nKn9tlVSvdjvAK9SzHFSzNXIpuaDRD/9igMvjyOkoQx gtNJC0xtJH/G3WIXfaPbtXKdwCWRNUqXCClKJljNpxIqFFR4XVpxTUFMoOlAIfAlq0 r0gtMPBn4pz2eCKyiv028i0UWUJeZkWp1gSYQsYjbvuuVoC7YH9Zmy0FC6KgisBA/o XP7cOmrwCKaqxDhguEHpC6zNidbJ8KAJXSden1ib7jxcFDWAEgETo2rt7JVAYcVg9P S2CPGBp6/bDKYnki1NHyTNJ3odMefxoTbVYfhzYm0JA4GAOFxrHzO2c9XraFgXoLiv hR4DyLWb38OiA== Date: Mon, 29 Jul 2024 18:11:00 -0700 Subject: [PATCH 7/7] xfs_scrub: improve responsiveness while trimming the filesystem From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172229848138.1349330.4764336698265605990.stgit@frogsfrogsfrogs> In-Reply-To: <172229848026.1349330.12889405227098722037.stgit@frogsfrogsfrogs> References: <172229848026.1349330.12889405227098722037.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong On a 10TB filesystem where the free space in each AG is heavily fragmented, I noticed some very high runtimes on a FITRIM call for the entire filesystem. xfs_scrub likes to report progress information on each phase of the scrub, which means that a strace for the entire filesystem: ioctl(3, FITRIM, {start=0x0, len=10995116277760, minlen=0}) = 0 <686.209839> shows that scrub is uncommunicative for the entire duration. We can't report any progress for the duration of the call, and the program is not responsive to signals. Reducing the size of the FITRIM requests to a single AG at a time produces lower times for each individual call, but even this isn't quite acceptable, because the time between progress reports are still very high: Strace for the first 4x 1TB AGs looks like (2): ioctl(3, FITRIM, {start=0x0, len=1099511627776, minlen=0}) = 0 <68.352033> ioctl(3, FITRIM, {start=0x10000000000, len=1099511627776, minlen=0}) = 0 <68.760323> ioctl(3, FITRIM, {start=0x20000000000, len=1099511627776, minlen=0}) = 0 <67.235226> ioctl(3, FITRIM, {start=0x30000000000, len=1099511627776, minlen=0}) = 0 <69.465744> I then had the idea to limit the length parameter of each call to a smallish amount (~11GB) so that we could report progress relatively quickly, but much to my surprise, each FITRIM call still took ~68 seconds! Unfortunately, the by-length fstrim implementation handles this poorly because it walks the entire free space by length index (cntbt), which is a very inefficient way to walk a subset of an AG when the free space is fragmented. To fix that, I created a second implementation in the kernel that will walk the bnobt and perform the trims in block number order. This algorithm constrains the amount of btree scanning to something resembling the range passed in, which reduces the amount of time it takes to respond to a signal. Therefore, break up the FITRIM calls so they don't scan more than 11GB of space at a time. Break the calls up by AG so that each call only has to take one AGF per call, because each AG that we traverse causes a log force. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- scrub/phase8.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++---------- scrub/vfs.c | 10 ++++- scrub/vfs.h | 2 + 3 files changed, 91 insertions(+), 23 deletions(-) diff --git a/scrub/phase8.c b/scrub/phase8.c index 75400c968..e35bf11bf 100644 --- a/scrub/phase8.c +++ b/scrub/phase8.c @@ -45,27 +45,90 @@ fstrim_ok( return true; } +/* + * Limit the amount of fstrim scanning that we let the kernel do in a single + * call so that we can implement decent progress reporting and CPU resource + * control. Pick a prime number of gigabytes for interest. + */ +#define FSTRIM_MAX_BYTES (11ULL << 30) + +/* Trim a certain range of the filesystem. */ +static int +fstrim_fsblocks( + struct scrub_ctx *ctx, + uint64_t start_fsb, + uint64_t fsbcount) +{ + uint64_t start = cvt_off_fsb_to_b(&ctx->mnt, start_fsb); + uint64_t len = cvt_off_fsb_to_b(&ctx->mnt, fsbcount); + int error; + + while (len > 0) { + uint64_t run; + + run = min(len, FSTRIM_MAX_BYTES); + + error = fstrim(ctx, start, run); + if (error == EOPNOTSUPP) { + /* Pretend we finished all the work. */ + progress_add(len); + return 0; + } + if (error) { + char descr[DESCR_BUFSZ]; + + snprintf(descr, sizeof(descr) - 1, + _("fstrim start 0x%llx run 0x%llx"), + (unsigned long long)start, + (unsigned long long)run); + str_liberror(ctx, error, descr); + return error; + } + + progress_add(run); + len -= run; + start += run; + } + + return 0; +} + +/* Trim each AG on the data device. */ +static int +fstrim_datadev( + struct scrub_ctx *ctx) +{ + struct xfs_fsop_geom *geo = &ctx->mnt.fsgeom; + uint64_t fsbno; + int error; + + for (fsbno = 0; fsbno < geo->datablocks; fsbno += geo->agblocks) { + uint64_t fsbcount; + + /* + * Make sure that trim calls do not cross AG boundaries so that + * the kernel only performs one log force (and takes one AGF + * lock) per call. + */ + progress_add(geo->blocksize); + fsbcount = min(geo->datablocks - fsbno, geo->agblocks); + error = fstrim_fsblocks(ctx, fsbno, fsbcount); + if (error) + return error; + } + + return 0; +} + /* Trim the filesystem, if desired. */ int phase8_func( struct scrub_ctx *ctx) { - int error; - if (!fstrim_ok(ctx)) return 0; - error = fstrim(ctx); - if (error == EOPNOTSUPP) - return 0; - - if (error) { - str_liberror(ctx, error, _("fstrim")); - return error; - } - - progress_add(1); - return 0; + return fstrim_datadev(ctx); } /* Estimate how much work we're going to do. */ @@ -76,12 +139,13 @@ phase8_estimate( unsigned int *nr_threads, int *rshift) { - *items = 0; - - if (fstrim_ok(ctx)) - *items = 1; - + if (fstrim_ok(ctx)) { + *items = cvt_off_fsb_to_b(&ctx->mnt, + ctx->mnt.fsgeom.datablocks); + } else { + *items = 0; + } *nr_threads = 1; - *rshift = 0; + *rshift = 30; /* GiB */ return 0; } diff --git a/scrub/vfs.c b/scrub/vfs.c index bcfd4f42c..cc958ba94 100644 --- a/scrub/vfs.c +++ b/scrub/vfs.c @@ -298,11 +298,15 @@ struct fstrim_range { /* Call FITRIM to trim all the unused space in a filesystem. */ int fstrim( - struct scrub_ctx *ctx) + struct scrub_ctx *ctx, + uint64_t start, + uint64_t len) { - struct fstrim_range range = {0}; + struct fstrim_range range = { + .start = start, + .len = len, + }; - range.len = ULLONG_MAX; if (ioctl(ctx->mnt.fd, FITRIM, &range) == 0) return 0; if (errno == EOPNOTSUPP || errno == ENOTTY) diff --git a/scrub/vfs.h b/scrub/vfs.h index a8a4d72e2..1af8d80d1 100644 --- a/scrub/vfs.h +++ b/scrub/vfs.h @@ -24,6 +24,6 @@ typedef int (*scan_fs_tree_dirent_fn)(struct scrub_ctx *, const char *, int scan_fs_tree(struct scrub_ctx *ctx, scan_fs_tree_dir_fn dir_fn, scan_fs_tree_dirent_fn dirent_fn, void *arg); -int fstrim(struct scrub_ctx *ctx); +int fstrim(struct scrub_ctx *ctx, uint64_t start, uint64_t len); #endif /* XFS_SCRUB_VFS_H_ */