From patchwork Tue Aug 6 18:21:24 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: 13755243 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 18D277441A; Tue, 6 Aug 2024 18:21:25 +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=1722968485; cv=none; b=CbCht8a6YHPXp2l1xJXaqhEgjS55rPskfcoGxAG0lc6eiAZ9pFppnbXoz1p3cdt2PoDw9gyhb3aAAgVGi417WekNoXKwxpI347xvr5NgASLxkpdOUWKogG/VCjY+yn9GLUlu15Mh14B0s5Suz/JOIhE3zi0Az3avZnqWDQZy4n8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722968485; c=relaxed/simple; bh=/zkvtDQSBpXNVN0eKLPUocTq1r6//W6MWVhL+mCxLvU=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=p6Hrnrv7TKimtF4EKAIFCMG7lt65lRpQgzv0wEkLKvhA54/X0NwXMP95zZD6Fxpqk4bro25wG/WasIvDNFMSxQKpPNmMnjb6f2/fqm4p7LWPDGMnP7qjRuxSnGhjz3sHer9mmlNt93rPTYMh9qMpXym8PVAISH/WgmsuBIPz0kw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YuksnlQ6; 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="YuksnlQ6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DE9D0C32786; Tue, 6 Aug 2024 18:21:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722968484; bh=/zkvtDQSBpXNVN0eKLPUocTq1r6//W6MWVhL+mCxLvU=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=YuksnlQ6GeoVRA5N/jFRQ2KCn+qqq8vPhbQME9l5xNr4QDp9By1c0n3vOcREpjAt4 2C3vfyXBXUpc8jvGyKNg8PYtEAm+XqbM8uHOb8KJNA3E9Pu4bHSLKfsPCzfQAAUYIl QEURT/NgQKBAC9BmmQfmbqAdmt669JV92N8XKNfTgFRxBTHtO43G7bruzzmKoaft1E lB28fl5RKIx8xQxrHSFDcZzK7BHbzL4qTXGJEPs2fzt6Pn0cF83045Pj6qYozPoqBh +cnYoinq9/1Zb12EBmm7Ssbl1d15zW3NJe35cEcNGTo5gMkOPnpP95p3OWbAYci6vm 6pvYTbDAE4DaQ== Date: Tue, 06 Aug 2024 11:21:24 -0700 Subject: [PATCH 1/4] libfrog: define a autofsck filesystem property From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: hch@lst.de, dchinner@redhat.com, fstests@vger.kernel.org, linux-xfs@vger.kernel.org Message-ID: <172296825613.3193344.6788691411989910358.stgit@frogsfrogsfrogs> In-Reply-To: <172296825594.3193344.4163676649578585462.stgit@frogsfrogsfrogs> References: <172296825594.3193344.4163676649578585462.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: fstests@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Now that we have the ability to set properties on filesystems, create an "autofsck" property so that sysadmins can control background xfs_scrub behaviors. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libfrog/fsproperties.c | 38 ++++++++++++++++++++++++++++++++++++++ libfrog/fsproperties.h | 13 +++++++++++++ 2 files changed, 51 insertions(+) diff --git a/libfrog/fsproperties.c b/libfrog/fsproperties.c index c317d15c1..72485f627 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)) +/* Automatic background fsck fs property */ + +static const char *fsprop_autofsck_values[] = { + [FSPROP_AUTOFSCK_UNSET] = NULL, + [FSPROP_AUTOFSCK_NONE] = "none", + [FSPROP_AUTOFSCK_CHECK] = "check", + [FSPROP_AUTOFSCK_OPTIMIZE] = "optimize", + [FSPROP_AUTOFSCK_REPAIR] = "repair", +}; + +/* Convert the autofsck property enum to a string. */ +const char * +fsprop_autofsck_write( + enum fsprop_autofsck x) +{ + if (x <= FSPROP_AUTOFSCK_UNSET || + x >= ARRAY_SIZE(fsprop_autofsck_values)) + return NULL; + return fsprop_autofsck_values[x]; +} + +/* + * Turn a autofsck value string into an enumerated value, or _UNSET if it's + * not recognized. + */ +enum fsprop_autofsck +fsprop_autofsck_read( + const char *value) +{ + int ret = fsprops_lookup(fsprop_autofsck_values, value); + if (ret < 0) + return FSPROP_AUTOFSCK_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_AUTOFSCK_NAME)) + return fsprops_lookup(fsprop_autofsck_values, value) >= 0; + return true; } diff --git a/libfrog/fsproperties.h b/libfrog/fsproperties.h index b1ac4cdd7..11d6530bc 100644 --- a/libfrog/fsproperties.h +++ b/libfrog/fsproperties.h @@ -50,4 +50,17 @@ bool fsprop_validate(const char *name, const char *value); /* Specific Filesystem Properties */ +#define FSPROP_AUTOFSCK_NAME "autofsck" + +enum fsprop_autofsck { + FSPROP_AUTOFSCK_UNSET = 0, /* do not set property */ + FSPROP_AUTOFSCK_NONE, /* no background scrubs */ + FSPROP_AUTOFSCK_CHECK, /* allow only background checking */ + FSPROP_AUTOFSCK_OPTIMIZE, /* allow background optimization */ + FSPROP_AUTOFSCK_REPAIR, /* allow background repair & optimization */ +}; + +const char *fsprop_autofsck_write(enum fsprop_autofsck x); +enum fsprop_autofsck fsprop_autofsck_read(const char *value); + #endif /* __LIBFROG_FSPROPERTIES_H__ */ From patchwork Tue Aug 6 18:21:40 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: 13755244 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 B9563770E8; Tue, 6 Aug 2024 18:21:40 +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=1722968500; cv=none; b=QOM/2GopgJeyWUSL199qXH5TjqYC4WES3lQosri35zNDp7BQZrvOxC5Uow4x5VF9upqr4PJrAbLLC2YmGIlOpnnY5YRRQtSeHexFXRelnEy+csvCEeXRNFVxuy9bqJee6aVXP0dY8HxnxeUqjP8Ed5OZMtCsHYdofKWUOPTK4vI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722968500; c=relaxed/simple; bh=1ugh6sTJnKCqRwrwmuXt+AbRnSKae7dfMjsCvwj3kTM=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=peagpcWZ0uQBYDwcWPKwcCianiKdyvgOBVP8Q13bR953i4z6Y5u8YcLM7IrE5Fp1Lg+qzQDbSRLizMcNCujtYoLgLw9GA+TesfdovpH7OecytI/7taagzu+J6BYc1agNM+JF496jn2MgP9Bqe+Yle5CYtc8C13JhJeWc6lVUlY4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oUqnMg6O; 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="oUqnMg6O" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9358FC32786; Tue, 6 Aug 2024 18:21:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722968500; bh=1ugh6sTJnKCqRwrwmuXt+AbRnSKae7dfMjsCvwj3kTM=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=oUqnMg6OlikEg5G4TboI89SgPg2exXLsfXwKq46CLifSYwbpCeSGBg69rShUwcssB aO4RBEWoJZb9ZsS6Ilv7RWM5hJcOwchuXjt9HqNjgSikG7DfVHJFuMNtMypvgsbJmI t2h7wWCTEu/RZHq7u+I1cm1MDUXsP7DCsT9EVwb/SR6hM8ehQri9ctZi3myWpyw/eo 4e6+ivapqpo+FuksqYH466yoUcqHzYPWL75TExNSQv3AQXUGcwCcVrFVqpBXGX6KT+ MZ/fR3BFLXT41FADzItiVtWnbbczsrHW1nKBTAkBEOJiU0/quh2HvmLuzgcCUCiTJZ yQSP3zaQvgkaw== Date: Tue, 06 Aug 2024 11:21:40 -0700 Subject: [PATCH 2/4] xfs_scrub: allow sysadmin to control background scrubs From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: hch@lst.de, dchinner@redhat.com, fstests@vger.kernel.org, linux-xfs@vger.kernel.org Message-ID: <172296825628.3193344.3037756123720880069.stgit@frogsfrogsfrogs> In-Reply-To: <172296825594.3193344.4163676649578585462.stgit@frogsfrogsfrogs> References: <172296825594.3193344.4163676649578585462.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: fstests@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Add an extended option -o autofsck to xfs_scrub so that it selects the operation mode from the "autofsck" filesystem property. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- man/man8/xfs_property.8 | 8 ++++ man/man8/xfs_scrub.8 | 46 ++++++++++++++++++++++++ scrub/phase1.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++ scrub/xfs_scrub.c | 14 +++++++ scrub/xfs_scrub.h | 7 ++++ 5 files changed, 166 insertions(+) diff --git a/man/man8/xfs_property.8 b/man/man8/xfs_property.8 index 19c1c0e37..9fb1fd7cc 100644 --- a/man/man8/xfs_property.8 +++ b/man/man8/xfs_property.8 @@ -59,3 +59,11 @@ was set. remove .IR name ... Unsets the given filesystem properties. + +.SH FILESYSTEM PROPERTIES +Known filesystem properties for XFS are: + +.I autofsck +See +.BR xfs_scrub (8) +for more information. diff --git a/man/man8/xfs_scrub.8 b/man/man8/xfs_scrub.8 index 1fd122f2a..1ed4b176b 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 autofsck +Decide the operating mode from the value of the +.I autofsck +filesystem property. +See the +.B filesystem 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,44 @@ 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 autofsck +via the +.BR xfs_property (8) +command on the filesystem. +These preferences will be honored if the +.B -o autofsck +option is specified. + +Recognized values for the +.B autofsck +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 +.I check +if the filesystem has either reverse mapping btrees or parent pointers enabled, +or +.I none +otherwise. + .SH EXIT CODE The exit code returned by .B xfs_scrub diff --git a/scrub/phase1.c b/scrub/phase1.c index 091b59e57..d03a9099a 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,87 @@ enable_force_repair( return error; } +/* + * Decide the operating mode from the autofsck fs property. No fs property or + * system errors means we check the fs if rmapbt or pptrs are enabled, or none + * if it doesn't. + */ +static void +mode_from_autofsck( + struct scrub_ctx *ctx) +{ + struct fsprops_handle fph = { }; + char valuebuf[FSPROP_MAX_VALUELEN + 1] = { 0 }; + size_t valuelen = FSPROP_MAX_VALUELEN; + enum fsprop_autofsck shval; + int ret; + + ret = fsprops_open_handle(&ctx->mnt, &ctx->fsinfo, &fph); + if (ret) + goto no_property; + + ret = fsprops_get(&fph, FSPROP_AUTOFSCK_NAME, valuebuf, &valuelen); + if (ret) + goto no_property; + + shval = fsprop_autofsck_read(valuebuf); + switch (shval) { + case FSPROP_AUTOFSCK_NONE: + ctx->mode = SCRUB_MODE_NONE; + break; + case FSPROP_AUTOFSCK_OPTIMIZE: + ctx->mode = SCRUB_MODE_PREEN; + break; + case FSPROP_AUTOFSCK_REPAIR: + ctx->mode = SCRUB_MODE_REPAIR; + break; + case FSPROP_AUTOFSCK_UNSET: + str_info(ctx, ctx->mntpoint, + _("Unknown autofsck directive \"%s\"."), + valuebuf); + goto no_property; + case FSPROP_AUTOFSCK_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 autofsck directive.")); + break; + case SCRUB_MODE_DRY_RUN: + str_info(ctx, ctx->mntpoint, + _("Checking per autofsck directive.")); + break; + case SCRUB_MODE_PREEN: + str_info(ctx, ctx->mntpoint, + _("Optimizing per autofsck directive.")); + break; + case SCRUB_MODE_REPAIR: + str_info(ctx, ctx->mntpoint, + _("Checking and repairing per autofsck directive.")); + break; + } + + return; +no_property: + /* + * If we don't find an autofsck property, check the metadata if any + * backrefs are available for cross-referencing. Otherwise do no + * checking. + */ + if (ctx->mnt.fsgeom.flags & (XFS_FSOP_GEOM_FLAGS_PARENT | + XFS_FSOP_GEOM_FLAGS_RMAPBT)) + ctx->mode = SCRUB_MODE_DRY_RUN; + else + ctx->mode = SCRUB_MODE_NONE; + goto summarize; +} + /* * 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 +289,14 @@ _("Not an XFS filesystem.")); return error; } + /* + * If we've been instructed to decide the operating mode from the + * autofsck fs property, do that now before we start downgrading based + * on actual fs/kernel capabilities. + */ + if (ctx->mode == SCRUB_MODE_NONE) + mode_from_autofsck(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 f5b58de12..3e7d9138f 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, + AUTOFSCK, O_MAX_OPTS, }; static char *o_opts[] = { [IWARN] = "iwarn", [FSTRIM_PCT] = "fstrim_pct", + [AUTOFSCK] = "autofsck", [O_MAX_OPTS] = NULL, }; @@ -688,6 +694,14 @@ parse_o_opts( ctx->fstrim_block_pct = dval / 100.0; break; + case AUTOFSCK: + if (val) { + fprintf(stderr, + _("-o autofsck 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 4d9a02892..5d336cb55 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 + * "autofsck" 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 Aug 6 18:21:55 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: 13755251 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 6C22677F08; Tue, 6 Aug 2024 18:21:56 +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=1722968516; cv=none; b=Rh6/qgrVi5Xi41Q3ggWDxbCghQEnPQdEYsFaxpWabJGe7nbIv6UoLktZTMUUHMM0mtIiDiPfQmZP/JWimEd4mizE/UlddqPwwfSTK5d2cWhS8/3oocqkILYQtjVv94cb82Ru5QmN3iX4CYMDYzlCbZzHGYUVXJXLB9ACUW7W4M8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722968516; c=relaxed/simple; bh=ovkuHAbYFi4xciqSBB5QDP6889hCZvDtrha7OUPXVu8=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=V3nKFFv1B92/NNr1SdwO8eXIdhMgI3/ijmafEyzMhgt/aVK776aGXuXJyajof/MJGjzFJXSAVkP5A+BtichfBxgN3QjCVadZcYfWW+62VElBNPy2HFwFIHWmBM6gPbq0hJ1baxNv4dgAcdUM8s3qbmmuqBI+IDs5V55nfyXj+FQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SzdHVTqh; 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="SzdHVTqh" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 396E9C32786; Tue, 6 Aug 2024 18:21:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722968516; bh=ovkuHAbYFi4xciqSBB5QDP6889hCZvDtrha7OUPXVu8=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=SzdHVTqheFEeeY4PrBhZpG60lrrJAtLorIWwdkI8C1i4Rn0Ys3ZSTetscQrAOU5hd E+5zeoytzi7FreAnOza2nvxaOVw9BAEfQm2k8sZ6sYPzvMxQ2+7hoKXJW5aDeJBvST 2iYcJViaZJzuxwjrNYXWZkUB+TPYjDJRE/1HPts7Lxusx3esru3BgwBWVZ733F8puE aKtxCka+4y7/qB+TPBHKcO/dVT8c0IhtJdQBE47Jdgh4DR4a388YDuBttYwt6vADmi 4zh3jKfrxgaBJsAwEurSZtZJbmB2siqKn4L3o6NKZNGH5wQZMLib8eJRzdlhuekeIf fcbFMlT4aAtrQ== Date: Tue, 06 Aug 2024 11:21:55 -0700 Subject: [PATCH 3/4] xfs_scrub: use the autofsck fsproperty to select mode From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: hch@lst.de, dchinner@redhat.com, fstests@vger.kernel.org, linux-xfs@vger.kernel.org Message-ID: <172296825643.3193344.4511195350690630042.stgit@frogsfrogsfrogs> In-Reply-To: <172296825594.3193344.4163676649578585462.stgit@frogsfrogsfrogs> References: <172296825594.3193344.4163676649578585462.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: fstests@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Now that we can set properties on xfs filesystems, make the xfs_scrub background service query the autofsck property to figure out which operating mode it should use. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- scrub/Makefile | 3 +-- scrub/xfs_scrub@.service.in | 2 +- scrub/xfs_scrub_media@.service.in | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/scrub/Makefile b/scrub/Makefile index 885b43e99..53e8cb02a 100644 --- a/scrub/Makefile +++ b/scrub/Makefile @@ -17,7 +17,7 @@ INSTALL_SCRUB = install-scrub XFS_SCRUB_ALL_PROG = xfs_scrub_all XFS_SCRUB_FAIL_PROG = xfs_scrub_fail XFS_SCRUB_ARGS = -p -XFS_SCRUB_SERVICE_ARGS = -b +XFS_SCRUB_SERVICE_ARGS = -b -o autofsck ifeq ($(HAVE_SYSTEMD),yes) INSTALL_SCRUB += install-systemd SYSTEMD_SERVICES=\ @@ -144,7 +144,6 @@ install: $(INSTALL_SCRUB) @echo " [SED] $@" $(Q)$(SED) -e "s|@sbindir@|$(PKG_SBIN_DIR)|g" \ -e "s|@scrub_service_args@|$(XFS_SCRUB_SERVICE_ARGS)|g" \ - -e "s|@scrub_args@|$(XFS_SCRUB_ARGS)|g" \ -e "s|@pkg_libexec_dir@|$(PKG_LIBEXEC_DIR)|g" \ -e "s|@pkg_state_dir@|$(PKG_STATE_DIR)|g" \ -e "s|@media_scan_interval@|$(XFS_SCRUB_ALL_AUTO_MEDIA_SCAN_INTERVAL)|g" \ diff --git a/scrub/xfs_scrub@.service.in b/scrub/xfs_scrub@.service.in index 5fa5f3282..fb38319e9 100644 --- a/scrub/xfs_scrub@.service.in +++ b/scrub/xfs_scrub@.service.in @@ -22,7 +22,7 @@ RequiresMountsFor=%f [Service] Type=oneshot Environment=SERVICE_MODE=1 -ExecStart=@sbindir@/xfs_scrub @scrub_service_args@ @scrub_args@ -M /tmp/scrub/ %f +ExecStart=@sbindir@/xfs_scrub @scrub_service_args@ -M /tmp/scrub/ %f SyslogIdentifier=%N # Run scrub with minimal CPU and IO priority so that nothing else will starve. diff --git a/scrub/xfs_scrub_media@.service.in b/scrub/xfs_scrub_media@.service.in index e670748ce..98cd1ac44 100644 --- a/scrub/xfs_scrub_media@.service.in +++ b/scrub/xfs_scrub_media@.service.in @@ -22,7 +22,7 @@ RequiresMountsFor=%f [Service] Type=oneshot Environment=SERVICE_MODE=1 -ExecStart=@sbindir@/xfs_scrub @scrub_service_args@ @scrub_args@ -M /tmp/scrub/ -x %f +ExecStart=@sbindir@/xfs_scrub @scrub_service_args@ -M /tmp/scrub/ -x %f SyslogIdentifier=%N # Run scrub with minimal CPU and IO priority so that nothing else will starve. From patchwork Tue Aug 6 18:22:11 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: 13755252 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 5674B78C75; Tue, 6 Aug 2024 18:22:12 +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=1722968532; cv=none; b=kbDX0SZH7OgrsDILfkNBY/atMV2RxH+w7ZI9CTxyRAF2JuMDKG0MatOA19d79cP0H18SoBmDLQ4newjoeN5WEHyDZJaCWIhcXHYa9NPh7R+zAswuAChirs792Ku2yIWq9+MQzEtkCWRNKoRbKxavwBAqSPWaDiwHz1vKmbYk6vM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722968532; c=relaxed/simple; bh=6B/qLVa2G54qOmaxfiw9R7OdyMcWTqu/IegZeLq/7Ns=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EUAt9ysEkurMiko9VWOskjWTExQUulnOG7tW8q07VehDneXD0YloDpIQ9dw89cVaHubjR9uWuA5Dbg0WcaEl+DXjh0ESQQpxezOCLP5h6MlntCiE6LlATt6DBZJ/EiivYTq0UbMdj+7f+1Jd1TIjU6jj508wInYsy/wAD9ltiJo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Zthfy+mO; 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="Zthfy+mO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DDA35C32786; Tue, 6 Aug 2024 18:22:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722968531; bh=6B/qLVa2G54qOmaxfiw9R7OdyMcWTqu/IegZeLq/7Ns=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Zthfy+mOz8VgV4surXCW7VeCPh9M+F20sVjSOwUy7WhYRqbBKjwD2n0i5haWIZq5y bzXsmH5Hy6WHkfybJLC51rijf4kOEcYqrJjELwK0kwmHuKWJaJJ55nIdsQ6ow4e/Uk qM9kC4BdgC1PgouiE3oWwigdzDN9iHDAzaAW8OzaHjMR+mffGVmXGdpK4AOx+U1Ff6 qnu24DqR2hI/OloBhTBWhvI9feM05kVCc6RteGaW1AGYgKHxRoOx954Q/B9BgaPPWz 5lCDFnnVwc7bSYnvJ27rLAoOl0hlQUBNf1p12PA3OFStliPFVNTQlr3GTuHPT8905Q fkx6wY9LjTNAQ== Date: Tue, 06 Aug 2024 11:22:11 -0700 Subject: [PATCH 4/4] mkfs: set autofsck filesystem property From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: hch@lst.de, dchinner@redhat.com, fstests@vger.kernel.org, linux-xfs@vger.kernel.org Message-ID: <172296825658.3193344.3348247369210100441.stgit@frogsfrogsfrogs> In-Reply-To: <172296825594.3193344.4163676649578585462.stgit@frogsfrogsfrogs> References: <172296825594.3193344.4163676649578585462.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: fstests@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Add a new mkfs option -m autofsck so that sysadmins can control the background scrubbing behavior of filesystems from the start. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- 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 d5a0783ac..a854b0e87 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 autofsck= value +Set the autofsck 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 9fa1f9378..4f190bacf 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 +autofsck=0 [inode] sparse=1 diff --git a/mkfs/lts_5.10.conf b/mkfs/lts_5.10.conf index d64bcdf8c..a55fc68e4 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 +autofsck=0 [inode] sparse=1 diff --git a/mkfs/lts_5.15.conf b/mkfs/lts_5.15.conf index 775fd9ab9..daea0b406 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 +autofsck=0 [inode] sparse=1 diff --git a/mkfs/lts_5.4.conf b/mkfs/lts_5.4.conf index 6f43a6c6d..0f807fc35 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 +autofsck=0 [inode] sparse=1 diff --git a/mkfs/lts_6.1.conf b/mkfs/lts_6.1.conf index a78a4f9e3..0ff5bbad5 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 +autofsck=0 [inode] sparse=1 diff --git a/mkfs/lts_6.6.conf b/mkfs/lts_6.6.conf index 91a25bd81..2ef5957e0 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 +autofsck=0 [inode] sparse=1 diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c index 394a35771..bbd0dbb6c 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_AUTOFSCK, M_MAX_OPTS, }; @@ -809,6 +811,7 @@ static struct opt_params mopts = { [M_REFLINK] = "reflink", [M_INOBTCNT] = "inobtcount", [M_BIGTIME] = "bigtime", + [M_AUTOFSCK] = "autofsck", [M_MAX_OPTS] = NULL, }, .subopt_params = { @@ -852,6 +855,12 @@ static struct opt_params mopts = { .maxval = 1, .defaultval = 1, }, + { .index = M_AUTOFSCK, + .conflicts = { { NULL, LAST_CONFLICT } }, + .minval = 0, + .maxval = 1, + .defaultval = 1, + }, }, }; @@ -917,6 +926,8 @@ struct cli_params { char *cfgfile; char *protofile; + enum fsprop_autofsck autofsck; + /* 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,autofsck=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_AUTOFSCK: + if (!value || value[0] == 0 || isdigit(value[0])) { + long long ival = getnum(value, opts, subopt); + + if (ival) + cli->autofsck = FSPROP_AUTOFSCK_REPAIR; + else + cli->autofsck = FSPROP_AUTOFSCK_NONE; + } else { + cli->autofsck = fsprop_autofsck_read(value); + if (cli->autofsck == FSPROP_AUTOFSCK_UNSET) + illegal(value, "m autofsck"); + } + 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->autofsck >= FSPROP_AUTOFSCK_CHECK) { + if (!cli->sb_feat.rmapbt) { + if (cli_opt_set(&mopts, M_RMAPBT)) { + fprintf(stdout, +_("-m autofsck=%s is less effective without reverse mapping\n"), + fsprop_autofsck_write(cli->autofsck)); + } else { + cli->sb_feat.rmapbt = true; + } + } + if (!cli->sb_feat.parent_pointers) { + if (cli_opt_set(&nopts, N_PARENT)) { + fprintf(stdout, +_("-m autofsck=%s is less effective without parent pointers\n"), + fsprop_autofsck_write(cli->autofsck)); + } 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->autofsck != FSPROP_AUTOFSCK_UNSET && + cli_opt_set(&mopts, M_AUTOFSCK)) { + fprintf(stderr, +_("autofsck not supported without CRC support\n")); + usage(); + } + cli->autofsck = FSPROP_AUTOFSCK_UNSET; } if (!cli->sb_feat.finobt) { @@ -4332,6 +4391,63 @@ cfgfile_parse( cli->cfgfile); } +static void +set_autofsck( + 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_AUTOFSCK_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 = (const uint8_t *)p; + + word = fsprop_autofsck_write(cli->autofsck); + if (!word) { + fprintf(stderr, + _("%s: not sure what to do with autofsck value %u\n"), + progname, cli->autofsck); + 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 autofsck 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 */ + .autofsck = FSPROP_AUTOFSCK_UNSET, }; struct mkfs_params cfg = {}; @@ -4669,6 +4786,9 @@ main( if (mp->m_sb.sb_agcount > 1) rewrite_secondary_superblocks(mp); + if (cli.autofsck != FSPROP_AUTOFSCK_UNSET) + set_autofsck(mp, &cli); + /* * Dump all inodes and buffers before marking us all done. * Need to drop references to inodes we still hold, first.