From patchwork Tue Jul 30 03:21:48 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: 13746481 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 9D6C61854 for ; Tue, 30 Jul 2024 03:21:49 +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=1722309709; cv=none; b=iCkVJJ1MHDpci46X0WE14zOy8SKqne4mRQDl/BFWc9aKn4+7FDtn98c1SIpmYbCRluotq2cxnHk9KeSRZhRqrvtB89qWuqnhm8a0yNF6gXujYuFW2Jlpily/cMZ+dU6DpdAqholGivFUPky6prEOSAOfcI3eH2vop/HLQSW/+9c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722309709; c=relaxed/simple; bh=x3MG6+QNI5V/KjrHr2x69TH02ac4NPYo1jU7NAn4Vtg=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rjJG//r33tD8yLmTdUh0SFH8lmFt9bMaQifyqTbt1kfvYs3ONFfECHLW1/I1AmKt+WbxxBO5R8n/s8i3Eo4NXsPqFGdB3ggY5fSWK4dVd+jlpjl8gqblVoQBs9dC7xHr1DpL0rqNKB1dXbUQPeYddFTwcEpEfrDDY6l6FNDDgoQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GnJv9Gmb; 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="GnJv9Gmb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2B399C32786; Tue, 30 Jul 2024 03:21:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722309709; bh=x3MG6+QNI5V/KjrHr2x69TH02ac4NPYo1jU7NAn4Vtg=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=GnJv9Gmbdaxr23ebC0IeLsjyH9bM0V/K/DaT2tPR7o3vrxxbc5VW5bqLcSrc9fyf6 a6KHZMhXZYpkKUFWir2dmbcaOV6EtTKEyTEBoXisZnz5ETii86H9KM2oh1vHvuUnrc GHJBhS3fqd5Akh0tCuf8zZXCOdRZremv98YbTZP7f5coy7MfmgmwecKEdRQtOr2dyV VPgdQ3V75R9PbWq17Ddo+qeOcTcbyRI5BkTKftJgPq2r6S0yUFkm920EUSolc8DMwp pYIn/NGYpIvu0emOvfO9JEnvB1MSi5q9Hbs8qUymcl+2Bv0Fkpw2Y6+CO7x4jtGTRX kJLN34mzeltxg== Date: Mon, 29 Jul 2024 20:21:48 -0700 Subject: [PATCH 1/3] libfrog: define a self_healing filesystem property From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <172230941003.1544039.14396399914334113330.stgit@frogsfrogsfrogs> In-Reply-To: <172230940983.1544039.13001736803793260744.stgit@frogsfrogsfrogs> References: <172230940983.1544039.13001736803793260744.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 Signed-off-by: Darrick J. Wong --- libfrog/fsproperties.c | 38 ++++++++++++++++++++++++++++++++++++++ libfrog/fsproperties.h | 13 +++++++++++++ 2 files changed, 51 insertions(+) diff --git a/libfrog/fsproperties.c b/libfrog/fsproperties.c index c317d15c1de0..4ccd0edd8453 100644 --- a/libfrog/fsproperties.c +++ b/libfrog/fsproperties.c @@ -29,11 +29,49 @@ __fsprops_lookup( #define fsprops_lookup(values, value) \ __fsprops_lookup((values), ARRAY_SIZE(values), (value)) +/* Self-healing fs property */ + +static const char *fsprop_self_healing_values[] = { + [FSPROP_SELFHEAL_UNSET] = NULL, + [FSPROP_SELFHEAL_NONE] = "none", + [FSPROP_SELFHEAL_CHECK] = "check", + [FSPROP_SELFHEAL_OPTIMIZE] = "optimize", + [FSPROP_SELFHEAL_REPAIR] = "repair", +}; + +/* Convert the self_healing property enum to a string. */ +const char * +fsprop_write_self_healing( + enum fsprop_self_healing x) +{ + if (x <= FSPROP_SELFHEAL_UNSET || + x >= ARRAY_SIZE(fsprop_self_healing_values)) + return NULL; + return fsprop_self_healing_values[x]; +} + +/* + * Turn a self_healing value string into an enumerated value, or _UNSET if it's + * not recognized. + */ +enum fsprop_self_healing +fsprop_read_self_healing( + const char *value) +{ + int ret = fsprops_lookup(fsprop_self_healing_values, value); + if (ret < 0) + return FSPROP_SELFHEAL_UNSET; + return ret; +} + /* Return true if a fs property name=value tuple is allowed. */ bool fsprop_validate( const char *name, const char *value) { + if (!strcmp(name, FSPROP_SELF_HEALING_NAME)) + return fsprops_lookup(fsprop_self_healing_values, value) >= 0; + return true; } diff --git a/libfrog/fsproperties.h b/libfrog/fsproperties.h index 6dee8259a437..7004d339715a 100644 --- a/libfrog/fsproperties.h +++ b/libfrog/fsproperties.h @@ -47,4 +47,17 @@ bool fsprop_validate(const char *name, const char *value); /* Specific Filesystem Properties */ +#define FSPROP_SELF_HEALING_NAME "self_healing" + +enum fsprop_self_healing { + FSPROP_SELFHEAL_UNSET = 0, /* do not set property */ + FSPROP_SELFHEAL_NONE, /* no background scrubs */ + FSPROP_SELFHEAL_CHECK, /* allow only background checking */ + FSPROP_SELFHEAL_OPTIMIZE, /* allow background optimization */ + FSPROP_SELFHEAL_REPAIR, /* allow background repair & optimization */ +}; + +const char *fsprop_write_self_healing(enum fsprop_self_healing x); +enum fsprop_self_healing fsprop_read_self_healing(const char *value); + #endif /* __LIBFROG_FSPROPERTIES_H__ */ From patchwork Tue Jul 30 03:22:04 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: 13746482 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 25E0A1854 for ; Tue, 30 Jul 2024 03:22:04 +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=1722309725; cv=none; b=Donb9AyD0epbvOGWZshwQFt5lk3WfMUyLMSkK8FlRRm8XFtztNk0ZMAkndbNzgvP4P0T6xkg9Pc9KahGoqWqzbmJhHDVk8p0FcSB2TSwSbyxy6DljnM13JCDSU6yjtPQu0RIHteXGcptVNUL58V+NwYJbvuRU81vBsXaaIH4cg0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722309725; c=relaxed/simple; bh=7n1SWZRIg3qfp31ocesCYJY39H6harth53lP5v146Vc=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qdIF/oB6Ay8Wg8ivczMoq75GwOvQUPO30p7cQx4Vn46XNlH0Zw3m7HQs9UMcWBS53Tsw4pXBX1bBMt9QlDNg4ZQ25bPmZFg8nDUAKb5nOER9Ydzx8a4FWNi1UIMFLcD/oRE30E4/+5WNwVvenQeRZrTJm16zdVnEn8CmVsbD1Ck= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kr3jGVVY; 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="kr3jGVVY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BF0CDC32786; Tue, 30 Jul 2024 03:22:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722309724; bh=7n1SWZRIg3qfp31ocesCYJY39H6harth53lP5v146Vc=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=kr3jGVVYY9TWjApPVF5i1W+gCACheyY7MIH/Z+0QQKBiy8782d3JSDxxWG1lEvgf4 27/tH8UaVXZQmXvPOdEX6zwH7J8LZyr+qBUmbi1Bd6zaysJVDWQqrOfy+zvyAmqzj9 pByKaGXcRoi0VWl7Sl9KKPOkjp9JA/O1adf8l08bQsHZ1O13E/YVWB2V3OIXYreGlC ru//0znaFD9nzW+REZNgP+JR+8LxIPmpLYnSfVQmiOwuP/LccfNH1SxOfXxT0a7kcZ KgEmOrhVi6Z9rWH5wKmU0XYpXTSOupjoeWTKXOC4CFGRQfDB+AdSmbXeCggKqj8r2I HTFP4KcocVHgg== Date: Mon, 29 Jul 2024 20:22:04 -0700 Subject: [PATCH 2/3] xfs_scrub: allow sysadmin to control background scrubs From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <172230941018.1544039.12505916924928894120.stgit@frogsfrogsfrogs> In-Reply-To: <172230940983.1544039.13001736803793260744.stgit@frogsfrogsfrogs> References: <172230940983.1544039.13001736803793260744.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 Define a "self_healing" filesystem property so that sysadmins can indicate their preferences for background online fsck. Add an extended option to xfs_scrub so that it selects the operation mode from the self healing fs property. Signed-off-by: Darrick J. Wong --- man/man8/xfs_scrub.8 | 44 +++++++++++++++++++++++++++ scrub/phase1.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++ scrub/xfs_scrub.c | 14 +++++++++ scrub/xfs_scrub.h | 7 ++++ 4 files changed, 146 insertions(+) diff --git a/man/man8/xfs_scrub.8 b/man/man8/xfs_scrub.8 index 1fd122f2a242..1e017078019c 100644 --- a/man/man8/xfs_scrub.8 +++ b/man/man8/xfs_scrub.8 @@ -107,6 +107,14 @@ The supported are: .RS 1.0i .TP +.B fsprops_advise +Decide the operating mode from the value of the +.I self_healing +filesystem property. +See the +.B filesytem properties +section for more details. +.TP .BI fstrim_pct= percentage To constrain the amount of time spent on fstrim activities during phase 8, this program tries to balance estimated runtime against completeness of the @@ -192,6 +200,42 @@ Scheduling a quotacheck for the next mount. .PP If corrupt metadata is successfully repaired, this program will log that a repair has succeeded instead of a corruption report. +.SH FILESYSTEM PROPERTIES +System administrators can convey their preferences for scrubbing of a +particular filesystem by setting the filesystem property +.B self_healing +via the +.B setfsprops +subcommand of the +.B xfs_spaceman +on the filesystem. +These preferences will be honored if the +.B -o fsprops_advise +option is specified. + +Recognized values for the +.B self_healing +property are: +.RS +.TP +.I none +Do not scan the filesystem at all. +.TP +.I check +Scan and report corruption and opportunities for optimization, but do not +change anything. +.TP +.I optimize +Scan the filesystem and optimize where possible. +Report corruptions, but do not fix them. +.TP +.I repair +Scan the filesystem, fix corruptions, and optimize where possible. +.RE + +If the property is not set, the default is +.IR check . + .SH EXIT CODE The exit code returned by .B xfs_scrub diff --git a/scrub/phase1.c b/scrub/phase1.c index 091b59e57e7b..5fa215a5bb79 100644 --- a/scrub/phase1.c +++ b/scrub/phase1.c @@ -28,6 +28,8 @@ #include "repair.h" #include "libfrog/fsgeom.h" #include "xfs_errortag.h" +#include "libfrog/fsprops.h" +#include "libfrog/fsproperties.h" /* Phase 1: Find filesystem geometry (and clean up after) */ @@ -130,6 +132,77 @@ enable_force_repair( return error; } +#define MAX_SELFHEAL_LEN 128 +/* + * Decide the operating mode from filesystem properties. No fs property or + * system errors means we only check. + */ +static void +mode_from_fsprops( + struct scrub_ctx *ctx) +{ + struct fsprops_handle fph = { }; + char valuebuf[MAX_SELFHEAL_LEN + 1] = { 0 }; + size_t valuelen = MAX_SELFHEAL_LEN; + enum fsprop_self_healing shval; + int ret; + + ret = fsprops_open_handle(&ctx->mnt, &ctx->fsinfo, &fph); + if (ret) { + ctx->mode = SCRUB_MODE_DRY_RUN; + goto summarize; + } + + ret = fsprops_get(&fph, FSPROP_SELF_HEALING_NAME, valuebuf, &valuelen); + if (ret) { + ctx->mode = SCRUB_MODE_DRY_RUN; + goto summarize; + } + + shval = fsprop_read_self_healing(valuebuf); + switch (shval) { + case FSPROP_SELFHEAL_NONE: + ctx->mode = SCRUB_MODE_NONE; + break; + case FSPROP_SELFHEAL_OPTIMIZE: + ctx->mode = SCRUB_MODE_PREEN; + break; + case FSPROP_SELFHEAL_REPAIR: + ctx->mode = SCRUB_MODE_REPAIR; + break; + case FSPROP_SELFHEAL_UNSET: + str_info(ctx, ctx->mntpoint, + _("Unknown self_healing directive \"%s\"."), + valuebuf); + fallthrough; + case FSPROP_SELFHEAL_CHECK: + ctx->mode = SCRUB_MODE_DRY_RUN; + break; + } + + fsprops_free_handle(&fph); + +summarize: + switch (ctx->mode) { + case SCRUB_MODE_NONE: + str_info(ctx, ctx->mntpoint, + _("Disabling scrub per self_healing directive.")); + break; + case SCRUB_MODE_DRY_RUN: + str_info(ctx, ctx->mntpoint, + _("Checking per self_healing directive.")); + break; + case SCRUB_MODE_PREEN: + str_info(ctx, ctx->mntpoint, + _("Optimizing per self_healing directive.")); + break; + case SCRUB_MODE_REPAIR: + str_info(ctx, ctx->mntpoint, + _("Checking and repairing per self_healing directive.")); + break; + } +} + /* * Bind to the mountpoint, read the XFS geometry, bind to the block devices. * Anything we've already built will be cleaned up by scrub_cleanup. @@ -206,6 +279,14 @@ _("Not an XFS filesystem.")); return error; } + /* + * If we've been instructed to decide the operating mode from the + * fs properties set on the mount point, do that now before we start + * downgrading based on actual fs/kernel capabilities. + */ + if (ctx->mode == SCRUB_MODE_NONE) + mode_from_fsprops(ctx); + /* Do we have kernel-assisted metadata scrubbing? */ if (!can_scrub_fs_metadata(ctx) || !can_scrub_inode(ctx) || !can_scrub_bmap(ctx) || !can_scrub_dir(ctx) || diff --git a/scrub/xfs_scrub.c b/scrub/xfs_scrub.c index f5b58de12812..a9d7e5ffe6d7 100644 --- a/scrub/xfs_scrub.c +++ b/scrub/xfs_scrub.c @@ -526,6 +526,10 @@ _("Scrub aborted after phase %d."), if (ret) break; + /* Did background scrub get canceled on us? */ + if (ctx->mode == SCRUB_MODE_NONE) + break; + /* Too many errors? */ if (scrub_excessive_errors(ctx)) { ret = ECANCELED; @@ -630,12 +634,14 @@ report_outcome( enum o_opt_nums { IWARN = 0, FSTRIM_PCT, + FSPROPS_ADVISE, O_MAX_OPTS, }; static char *o_opts[] = { [IWARN] = "iwarn", [FSTRIM_PCT] = "fstrim_pct", + [FSPROPS_ADVISE] = "fsprops_advise", [O_MAX_OPTS] = NULL, }; @@ -688,6 +694,14 @@ parse_o_opts( ctx->fstrim_block_pct = dval / 100.0; break; + case FSPROPS_ADVISE: + if (val) { + fprintf(stderr, + _("-o fsprops_advise does not take an argument\n")); + usage(); + } + ctx->mode = SCRUB_MODE_NONE; + break; default: usage(); break; diff --git a/scrub/xfs_scrub.h b/scrub/xfs_scrub.h index 4d9a028921b5..582ec8e579e9 100644 --- a/scrub/xfs_scrub.h +++ b/scrub/xfs_scrub.h @@ -26,6 +26,13 @@ extern bool use_force_rebuild; extern bool info_is_warning; enum scrub_mode { + /* + * Prior to phase 1, this means that xfs_scrub should read the + * "self_healing" fs property from the mount and set the value + * appropriate. If it's still set after phase 1, this means we should + * exit without doing anything. + */ + SCRUB_MODE_NONE, SCRUB_MODE_DRY_RUN, SCRUB_MODE_PREEN, SCRUB_MODE_REPAIR, From patchwork Tue Jul 30 03:22:19 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: 13746483 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 005DD1854 for ; Tue, 30 Jul 2024 03:22:20 +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=1722309741; cv=none; b=hviRzO0o/xmylvV7wle86+j6/mb2+oyMJhmE5DpFcYOmgy1UrQ9gaX784aF6cuJRuXVOgz1uJMaJ+Cvv3wUCkxVwlaNsZjyBl6Ox81BLaBFfaHNaadNtTpte3/Mz64NEQVKuBW+Qwis1dZyBgc0M/MSObSJy6l3q2LEhD8VAJJo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722309741; c=relaxed/simple; bh=FGopIb3FnsVaJqg3ofu4rJLSAbVhOI+o1q/1dzouwoI=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UGy5CdogKeB6wDzlm4thEeM5cOQXkxPczkdkitIFOsjeVddqT+rAVtQfgvrsFB2m/CTyowbljtxf8iLaJgIGsOpqYWtBhOKALlyJ+bDNmspe6Yywt9HrV7CHoYFA3o/FaUgfdgBEcF0381RGtDPeujNiCmcN96rFd7Ai23kplmI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cH9V1sQm; 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="cH9V1sQm" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6C8DBC32786; Tue, 30 Jul 2024 03:22:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722309740; bh=FGopIb3FnsVaJqg3ofu4rJLSAbVhOI+o1q/1dzouwoI=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=cH9V1sQm8jfoxp85QcPOYGTSTl931Q8Gkr4uxO5EAo7bzNP3b3xL88xP7HX/AHafO H1cx+toN7iDdARTKXQP3/sl2mU8eaXKgBgcKBGoYCpRVI6pD0MNAU8NLIumHckuXDZ Vh4AtNtj6WiMh/PlTyB+uwQgtTpxnfbgGUi63FPNGM/l1ntZxD6XCFcKA056tV6o/0 zLqcOuuA8jtWYTaOAMyxg+9lQmVab7NW1g+6WB/tECZ+pYWCB9wWoNalWDpHn9y9+A YsdYsdQmL1L9AXlhk19F7GIs8STPWqJPVEX9ew8GfrfOGYEprIcn0qP0juj6D+IwEZ UiCmLTon+tH4w== Date: Mon, 29 Jul 2024 20:22:19 -0700 Subject: [PATCH 3/3] mkfs: set self_healing property From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <172230941034.1544039.10827364192939791397.stgit@frogsfrogsfrogs> In-Reply-To: <172230940983.1544039.13001736803793260744.stgit@frogsfrogsfrogs> References: <172230940983.1544039.13001736803793260744.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 Add a new mkfs options so that sysadmins can control the background scrubbing behavior of filesystems from the start. Signed-off-by: Darrick J. Wong --- man/man8/mkfs.xfs.8.in | 6 ++ mkfs/lts_4.19.conf | 1 mkfs/lts_5.10.conf | 1 mkfs/lts_5.15.conf | 1 mkfs/lts_5.4.conf | 1 mkfs/lts_6.1.conf | 1 mkfs/lts_6.6.conf | 1 mkfs/xfs_mkfs.c | 122 ++++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 133 insertions(+), 1 deletion(-) diff --git a/man/man8/mkfs.xfs.8.in b/man/man8/mkfs.xfs.8.in index d5a0783ac5d6..a66fd2a606ed 100644 --- a/man/man8/mkfs.xfs.8.in +++ b/man/man8/mkfs.xfs.8.in @@ -323,6 +323,12 @@ option set. When the option .B \-m crc=0 is used, the reference count btree feature is not supported and reflink is disabled. +.TP +.BI self_healing= value +Set the self_healing filesystem property to this value. +See the +.BI xfs_scrub (8) +manual page for more information on this property. .RE .PP .PD 0 diff --git a/mkfs/lts_4.19.conf b/mkfs/lts_4.19.conf index 9fa1f9378f32..291200a1ff23 100644 --- a/mkfs/lts_4.19.conf +++ b/mkfs/lts_4.19.conf @@ -8,6 +8,7 @@ finobt=1 inobtcount=0 reflink=0 rmapbt=0 +self_healing=0 [inode] sparse=1 diff --git a/mkfs/lts_5.10.conf b/mkfs/lts_5.10.conf index d64bcdf8c46b..7c95dcf4c1ce 100644 --- a/mkfs/lts_5.10.conf +++ b/mkfs/lts_5.10.conf @@ -8,6 +8,7 @@ finobt=1 inobtcount=0 reflink=1 rmapbt=0 +self_healing=0 [inode] sparse=1 diff --git a/mkfs/lts_5.15.conf b/mkfs/lts_5.15.conf index 775fd9ab91b8..8797078e406a 100644 --- a/mkfs/lts_5.15.conf +++ b/mkfs/lts_5.15.conf @@ -8,6 +8,7 @@ finobt=1 inobtcount=1 reflink=1 rmapbt=0 +self_healing=0 [inode] sparse=1 diff --git a/mkfs/lts_5.4.conf b/mkfs/lts_5.4.conf index 6f43a6c6d469..c741b8260d90 100644 --- a/mkfs/lts_5.4.conf +++ b/mkfs/lts_5.4.conf @@ -8,6 +8,7 @@ finobt=1 inobtcount=0 reflink=1 rmapbt=0 +self_healing=0 [inode] sparse=1 diff --git a/mkfs/lts_6.1.conf b/mkfs/lts_6.1.conf index a78a4f9e35dc..834facc1d5fb 100644 --- a/mkfs/lts_6.1.conf +++ b/mkfs/lts_6.1.conf @@ -8,6 +8,7 @@ finobt=1 inobtcount=1 reflink=1 rmapbt=0 +self_healing=0 [inode] sparse=1 diff --git a/mkfs/lts_6.6.conf b/mkfs/lts_6.6.conf index 91a25bd8121f..10e965942e38 100644 --- a/mkfs/lts_6.6.conf +++ b/mkfs/lts_6.6.conf @@ -8,6 +8,7 @@ finobt=1 inobtcount=1 reflink=1 rmapbt=1 +self_healing=0 [inode] sparse=1 diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c index 394a35771246..ea4e97725541 100644 --- a/mkfs/xfs_mkfs.c +++ b/mkfs/xfs_mkfs.c @@ -12,6 +12,7 @@ #include "libfrog/convert.h" #include "libfrog/crc32cselftest.h" #include "libfrog/dahashselftest.h" +#include "libfrog/fsproperties.h" #include "proto.h" #include @@ -148,6 +149,7 @@ enum { M_REFLINK, M_INOBTCNT, M_BIGTIME, + M_SELFHEAL, M_MAX_OPTS, }; @@ -809,6 +811,7 @@ static struct opt_params mopts = { [M_REFLINK] = "reflink", [M_INOBTCNT] = "inobtcount", [M_BIGTIME] = "bigtime", + [M_SELFHEAL] = "self_healing", [M_MAX_OPTS] = NULL, }, .subopt_params = { @@ -852,6 +855,12 @@ static struct opt_params mopts = { .maxval = 1, .defaultval = 1, }, + { .index = M_SELFHEAL, + .conflicts = { { NULL, LAST_CONFLICT } }, + .minval = 0, + .maxval = 1, + .defaultval = 1, + }, }, }; @@ -917,6 +926,8 @@ struct cli_params { char *cfgfile; char *protofile; + enum fsprop_self_healing self_healing; + /* parameters that depend on sector/block size being validated. */ char *dsize; char *agsize; @@ -1037,7 +1048,7 @@ usage( void ) /* blocksize */ [-b size=num]\n\ /* config file */ [-c options=xxx]\n\ /* metadata */ [-m crc=0|1,finobt=0|1,uuid=xxx,rmapbt=0|1,reflink=0|1,\n\ - inobtcount=0|1,bigtime=0|1]\n\ + inobtcount=0|1,bigtime=0|1,self_healing=xxx]\n\ /* data subvol */ [-d agcount=n,agsize=n,file,name=xxx,size=num,\n\ (sunit=value,swidth=value|su=num,sw=num|noalign),\n\ sectsize=num,concurrency=num]\n\ @@ -1858,6 +1869,20 @@ meta_opts_parser( case M_BIGTIME: cli->sb_feat.bigtime = getnum(value, opts, subopt); break; + case M_SELFHEAL: + if (!value || value[0] == 0 || isdigit(value[0])) { + long long ival = getnum(value, opts, subopt); + + if (ival) + cli->self_healing = FSPROP_SELFHEAL_REPAIR; + else + cli->self_healing = FSPROP_SELFHEAL_NONE; + } else { + cli->self_healing = fsprop_read_self_healing(value); + if (cli->self_healing == FSPROP_SELFHEAL_UNSET) + illegal(value, "m self_heal"); + } + break; default: return -EINVAL; } @@ -2323,6 +2348,32 @@ _("Directory ftype field always enabled on CRC enabled filesystems\n")); usage(); } + /* + * Self-healing through online fsck relies heavily on back + * reference metadata, so we really want to try to enable rmap + * and parent pointers. + */ + if (cli->self_healing >= FSPROP_SELFHEAL_CHECK) { + if (!cli->sb_feat.rmapbt) { + if (cli_opt_set(&mopts, M_RMAPBT)) { + fprintf(stdout, +_("self-healing=%s is less effective without reverse mapping\n"), + fsprop_write_self_healing(cli->self_healing)); + } else { + cli->sb_feat.rmapbt = true; + } + } + if (!cli->sb_feat.parent_pointers) { + if (cli_opt_set(&nopts, N_PARENT)) { + fprintf(stdout, +_("self-healing=%s is less effective without parent pointers\n"), + fsprop_write_self_healing(cli->self_healing)); + } else { + cli->sb_feat.parent_pointers = true; + } + } + } + } else { /* !crcs_enabled */ /* * The V4 filesystem format is deprecated in the upstream Linux @@ -2406,6 +2457,14 @@ _("parent pointers not supported without CRC support\n")); usage(); } cli->sb_feat.parent_pointers = false; + + if (cli->self_healing != FSPROP_SELFHEAL_UNSET && + cli_opt_set(&mopts, M_SELFHEAL)) { + fprintf(stderr, +_("self-healing not supported without CRC support\n")); + usage(); + } + cli->self_healing = FSPROP_SELFHEAL_UNSET; } if (!cli->sb_feat.finobt) { @@ -4332,6 +4391,63 @@ cfgfile_parse( cli->cfgfile); } +static void +set_self_healing( + struct xfs_mount *mp, + struct cli_params *cli) +{ + struct xfs_da_args args = { + .geo = mp->m_attr_geo, + .whichfork = XFS_ATTR_FORK, + .op_flags = XFS_DA_OP_OKNOENT, + .attr_filter = LIBXFS_ATTR_ROOT, + .owner = mp->m_sb.sb_rootino, + }; + const char *word; + char *p; + int error; + + error = fsprop_name_to_attr_name(FSPROP_SELF_HEALING_NAME, &p); + if (error < 0) { + fprintf(stderr, + _("%s: error %d while allocating fs property name\n"), + progname, error); + exit(1); + } + args.namelen = error; + args.name = p; + + word = fsprop_write_self_healing(cli->self_healing); + if (!word) { + fprintf(stderr, + _("%s: not sure what to do with self_healing value %u\n"), + progname, cli->self_healing); + exit(1); + } + args.value = (void *)word; + args.valuelen = strlen(word); + + error = -libxfs_iget(mp, NULL, mp->m_sb.sb_rootino, 0, &args.dp); + if (error) { + fprintf(stderr, + _("%s: error %d while opening root directory\n"), + progname, error); + exit(1); + } + + libxfs_attr_sethash(&args); + + error = -libxfs_attr_set(&args, XFS_ATTRUPDATE_UPSERT, false); + if (error) { + fprintf(stderr, + _("%s: error %d while setting self_healing property\n"), + progname, error); + exit(1); + } + + libxfs_irele(args.dp); +} + int main( int argc, @@ -4361,6 +4477,7 @@ main( .is_supported = 1, .data_concurrency = -1, /* auto detect non-mechanical storage */ .log_concurrency = -1, /* auto detect non-mechanical ddev */ + .self_healing = FSPROP_SELFHEAL_UNSET, }; struct mkfs_params cfg = {}; @@ -4669,6 +4786,9 @@ main( if (mp->m_sb.sb_agcount > 1) rewrite_secondary_superblocks(mp); + if (cli.self_healing != FSPROP_SELFHEAL_UNSET) + set_self_healing(mp, &cli); + /* * Dump all inodes and buffers before marking us all done. * Need to drop references to inodes we still hold, first.