From patchwork Wed May 22 03:19: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: 13670337 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 71DF9282E5 for ; Wed, 22 May 2024 03:19: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=1716347989; cv=none; b=as7a4wXi/nEjKMEaIFnK3y9T48z1aV7PlhzksbOiAideTAbxLvsfcjbnME8k73IlNnGUNsPfEfSJg3bOMhcvh+vmN8hoxARSXqeb+qmrcaFE7f7so3hEoGf9Dj6h5jSWaRZls0k9xHqS0fwrlhVmSCTOLDqKnCUkfTH/K3x1sNs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716347989; c=relaxed/simple; bh=b0ziBavsADgckRsPanyNVv3w3P6l9IYxtTBJjiIgOeE=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=egical/4hCc3VAZiMgVhESZ3VEZ21XjPA1kLzdJ/cJmo5oxKEoYlg6hb9BmYhMQ2DwfivtCKBHtggqxIxoytnnEjDnZHCdLmphS2qLq2cqvjhay98G9rWXSGL732zzyoEuV3/o7St+xIFCskcrMqENTLDl9AHkViWXqqq/Yz1xc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oyJ4O+ES; 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="oyJ4O+ES" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 49046C2BD11; Wed, 22 May 2024 03:19:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716347989; bh=b0ziBavsADgckRsPanyNVv3w3P6l9IYxtTBJjiIgOeE=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=oyJ4O+ESGpGETlM9cNsDIwowstPSoixAGfW7FKobropNNKRDmBxsyBt3fMc7ClF1M /knuifF8xarrNnmS2U1Ot7PisGPkUCPInUz02JexD3HnS8xTEYHVFpZURB/QZ76NzH 45/rN6vu1y8uQaoBhTon1d2lvd/AqYMXT6PF1hTaaMjBSMy5/opK9BtQIl3DoIUun3 qEn5RDZcXTXdRFCJEfVvK9i3eVRizv2CMVe8kEuM9tsrvnopXVaM2QCpIm2i/83l14 Y/uZCXZ0EaTbevZv6brpGQ7EXjepLVPjwTX6oytRM5WQAOBXSlzAwqaVfF63rL/8mw iPF2VHr77Ba+w== Date: Tue, 21 May 2024 20:19:48 -0700 Subject: [PATCH 1/5] xfs_scrub: implement live quotacheck inode scan From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <171634534729.2482960.3779611153495120282.stgit@frogsfrogsfrogs> In-Reply-To: <171634534709.2482960.7052575979502113240.stgit@frogsfrogsfrogs> References: <171634534709.2482960.7052575979502113240.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 Teach xfs_scrub to check quota resource usage counters when checking a filesystem. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libfrog/scrub.c | 5 +++++ scrub/phase4.c | 17 +++++++++++++++++ scrub/repair.c | 3 +++ scrub/scrub.c | 9 +++++++++ scrub/scrub.h | 1 + 5 files changed, 35 insertions(+) diff --git a/libfrog/scrub.c b/libfrog/scrub.c index 5a5f522a4..53c47bc2b 100644 --- a/libfrog/scrub.c +++ b/libfrog/scrub.c @@ -134,6 +134,11 @@ const struct xfrog_scrub_descr xfrog_scrubbers[XFS_SCRUB_TYPE_NR] = { .descr = "filesystem summary counters", .group = XFROG_SCRUB_GROUP_SUMMARY, }, + [XFS_SCRUB_TYPE_QUOTACHECK] = { + .name = "quotacheck", + .descr = "quota counters", + .group = XFROG_SCRUB_GROUP_ISCAN, + }, }; /* Invoke the scrub ioctl. Returns zero or negative error code. */ diff --git a/scrub/phase4.c b/scrub/phase4.c index 5dfc3856b..8807f147a 100644 --- a/scrub/phase4.c +++ b/scrub/phase4.c @@ -128,6 +128,7 @@ int phase4_func( struct scrub_ctx *ctx) { + struct xfs_fsop_geom fsgeom; int ret; if (!have_action_items(ctx)) @@ -143,6 +144,22 @@ phase4_func( if (ret) return ret; + /* + * Repair possibly bad quota counts before starting other repairs, + * because wildly incorrect quota counts can cause shutdowns. + * Quotacheck scans all inodes, so we only want to do it if we know + * it's sick. + */ + ret = xfrog_geometry(ctx->mnt.fd, &fsgeom); + if (ret) + return ret; + + if (fsgeom.sick & XFS_FSOP_GEOM_SICK_QUOTACHECK) { + ret = scrub_quotacheck(ctx, &ctx->action_lists[0]); + if (ret) + return ret; + } + ret = repair_everything(ctx); if (ret) return ret; diff --git a/scrub/repair.c b/scrub/repair.c index 65b6dd895..3cb7224f7 100644 --- a/scrub/repair.c +++ b/scrub/repair.c @@ -84,6 +84,9 @@ xfs_action_item_priority( case XFS_SCRUB_TYPE_GQUOTA: case XFS_SCRUB_TYPE_PQUOTA: return PRIO(aitem, XFS_SCRUB_TYPE_UQUOTA); + case XFS_SCRUB_TYPE_QUOTACHECK: + /* This should always go after [UGP]QUOTA no matter what. */ + return PRIO(aitem, aitem->type); case XFS_SCRUB_TYPE_FSCOUNTERS: /* This should always go after AG headers no matter what. */ return PRIO(aitem, INT_MAX); diff --git a/scrub/scrub.c b/scrub/scrub.c index 023cc2c2c..a22633a81 100644 --- a/scrub/scrub.c +++ b/scrub/scrub.c @@ -440,6 +440,15 @@ scrub_fs_counters( return scrub_meta_type(ctx, XFS_SCRUB_TYPE_FSCOUNTERS, 0, alist); } +/* Scrub /only/ the quota counters. */ +int +scrub_quotacheck( + struct scrub_ctx *ctx, + struct action_list *alist) +{ + return scrub_meta_type(ctx, XFS_SCRUB_TYPE_QUOTACHECK, 0, alist); +} + /* How many items do we have to check? */ unsigned int scrub_estimate_ag_work( diff --git a/scrub/scrub.h b/scrub/scrub.h index 0033fe7ed..927f86de9 100644 --- a/scrub/scrub.h +++ b/scrub/scrub.h @@ -27,6 +27,7 @@ int scrub_fs_metadata(struct scrub_ctx *ctx, unsigned int scrub_type, int scrub_iscan_metadata(struct scrub_ctx *ctx, struct action_list *alist); int scrub_summary_metadata(struct scrub_ctx *ctx, struct action_list *alist); int scrub_fs_counters(struct scrub_ctx *ctx, struct action_list *alist); +int scrub_quotacheck(struct scrub_ctx *ctx, struct action_list *alist); bool can_scrub_fs_metadata(struct scrub_ctx *ctx); bool can_scrub_inode(struct scrub_ctx *ctx); From patchwork Wed May 22 03:20: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: 13670338 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 6610D14295 for ; Wed, 22 May 2024 03:20:05 +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=1716348005; cv=none; b=QkN2oR5/vgrPkL6Y4+lphlfNBPhAhQlmph3chqcjj4YisJfDkgTS+x647ER7BPAIejnf72N8vn+6px3d4sfb5uR3q4VBycBHzcWq/8Wpp8H7DAu/CCZ6Z3+bJEgj69X+HFZxp9xvTjkf7MaSuVT89RrlVCZA9RtoaVrJzlEYMTg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716348005; c=relaxed/simple; bh=7Wm/xrBnHEkX0WwBgWywLm727BoZhI45CyPSn9OSAgg=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bFzPfvZfFGdy4gzHB3uophzX6QKxMlYG/Xf9/P1fKraQkXNA7f9z0n0dli/vRkg0JWVx8JN4dH/jc1Cwo+wUKNg2NrFoRv49W9ZwfuDwnH4NlLwsyW0Kyz88aMgW/XtLo3lAS/YyqdN7Gx7Edz3IIoe08dzpxX6FQQD783lGQhs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=adGFxbzn; 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="adGFxbzn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EC91FC2BD11; Wed, 22 May 2024 03:20:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716348005; bh=7Wm/xrBnHEkX0WwBgWywLm727BoZhI45CyPSn9OSAgg=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=adGFxbznDC0NCS3rWwPBZsz4/w2R6E6fY2yODPk+CwSyC3nPoqUcjMzKNy1rdnfkh DY152juOfOA9WzG31KsdNhOzYzmZrFs8fTTNiEgppI2jFYkXKwHHNt+hZpK46ZLaht S/eblzIpK78Pkc1+r8493hyZHc1SX0L4s7n0ovFQ1jFnXN9siMP3cghDgXUv1KhQ8y 5WNPTfnFCgItICjxD+Iz5rIHVzfJoT8KtPMOBPRGdShHf6355UfFbcB2xj0zi7uzUV FBcUY6YQQy3VlKTMqq4te6HqxH4ha4YuOFwvp2hdfHmYDZkbFizZj9opHlQ4jE0BlO F3MzhrWb7zviA== Date: Tue, 21 May 2024 20:20:04 -0700 Subject: [PATCH 2/5] xfs_scrub: check file link counts From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <171634534744.2482960.10112447380248089111.stgit@frogsfrogsfrogs> In-Reply-To: <171634534709.2482960.7052575979502113240.stgit@frogsfrogsfrogs> References: <171634534709.2482960.7052575979502113240.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 Check file link counts as part of checking a filesystem. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libfrog/scrub.c | 5 +++++ man/man2/ioctl_xfs_scrub_metadata.2 | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/libfrog/scrub.c b/libfrog/scrub.c index 53c47bc2b..b6b8ae042 100644 --- a/libfrog/scrub.c +++ b/libfrog/scrub.c @@ -139,6 +139,11 @@ const struct xfrog_scrub_descr xfrog_scrubbers[XFS_SCRUB_TYPE_NR] = { .descr = "quota counters", .group = XFROG_SCRUB_GROUP_ISCAN, }, + [XFS_SCRUB_TYPE_NLINKS] = { + .name = "nlinks", + .descr = "inode link counts", + .group = XFROG_SCRUB_GROUP_ISCAN, + }, }; /* Invoke the scrub ioctl. Returns zero or negative error code. */ diff --git a/man/man2/ioctl_xfs_scrub_metadata.2 b/man/man2/ioctl_xfs_scrub_metadata.2 index 046e3e365..8e8bb72fb 100644 --- a/man/man2/ioctl_xfs_scrub_metadata.2 +++ b/man/man2/ioctl_xfs_scrub_metadata.2 @@ -164,6 +164,10 @@ Examine all user, group, or project quota records for corruption. .B XFS_SCRUB_TYPE_FSCOUNTERS Examine all filesystem summary counters (free blocks, inode count, free inode count) for errors. + +.TP +.B XFS_SCRUB_TYPE_NLINKS +Scan all inodes in the filesystem to verify each file's link count. .RE .PD 1 From patchwork Wed May 22 03:20:20 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: 13670339 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 DA7E057CA6 for ; Wed, 22 May 2024 03:20: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=1716348020; cv=none; b=UmU6AzKH/LJCSEfeWDtxtfUwuvfr19oXLp9toTaG8pHZy8UiaeVmzmm6dFZT3AjdHGZx3St8bBR+h9Exe7sWRzKvnKS3ce+QWHRzyVMptTWFRj9e0W6vEAm6JIcRxdVA2j2fLTN9NdIemm2Qv8BAJE4pK2iWkclU2zT/pPPOVXk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716348020; c=relaxed/simple; bh=aZwhe3ZhywT4Od5QgWwbYcqIYrymTGf7G6C5NYTENkQ=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mIE8wB4dHS53KUytU1RZ8rLk5rPYho9kMcsfPjXAqKLokzX0hG4/sDi8iN+sXsYnzFCNcc592yVdU1fMYjDN6NJebVKO6sfxTqlKqpzSWbiFg0XPHjp7+Sz3ywT9cOA6L4zwMHcqbbwmiW4w5O3sVtx0KlV6Lt0oomM5OtIobQ8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dhycDZ/X; 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="dhycDZ/X" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AFB49C32786; Wed, 22 May 2024 03:20:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716348020; bh=aZwhe3ZhywT4Od5QgWwbYcqIYrymTGf7G6C5NYTENkQ=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=dhycDZ/XiM4uUGakNS4/c/yh4qnk4G1Wvd3vc9FH8txcMtLiJ3uhtA5tc/ETZ9zL1 eYeX3IuVORrz/7vON7wOYnuFVr4OFGZ2qJJLTmAHJigqTWfFaALtk0P89GD2S1sZ+C GTqZXYdqJbxnClwZ2ZKgIk0QgvQ5S8+FcOJ9a0ptmvtz5RnV0uM3bPp8/w2w/0pxbr qmSY4c3VjgYfFcQRBAgWkuIgBw6wDeF7ZLEq8jBfWgoQt4CuMbA2FfbRGEGtAJ6rwG ER7h2LvKjnPJZjKY1gSFt9Khj9f4sAjTyxvI+7rvgaXtxnOVZ0JnOYbpHEjnlkgqpx 23XSMVDvOJF4g== Date: Tue, 21 May 2024 20:20:20 -0700 Subject: [PATCH 3/5] xfs_scrub: update health status if we get a clean bill of health From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <171634534758.2482960.9090286545136554659.stgit@frogsfrogsfrogs> In-Reply-To: <171634534709.2482960.7052575979502113240.stgit@frogsfrogsfrogs> References: <171634534709.2482960.7052575979502113240.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 we checked a filesystem and it turned out to be clean, upload that information into the kernel. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libfrog/scrub.c | 5 +++++ man/man2/ioctl_xfs_scrub_metadata.2 | 6 ++++++ scrub/scrub.c | 7 +------ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/libfrog/scrub.c b/libfrog/scrub.c index b6b8ae042..1df2965fe 100644 --- a/libfrog/scrub.c +++ b/libfrog/scrub.c @@ -144,6 +144,11 @@ const struct xfrog_scrub_descr xfrog_scrubbers[XFS_SCRUB_TYPE_NR] = { .descr = "inode link counts", .group = XFROG_SCRUB_GROUP_ISCAN, }, + [XFS_SCRUB_TYPE_HEALTHY] = { + .name = "healthy", + .descr = "retained health records", + .group = XFROG_SCRUB_GROUP_NONE, + }, }; /* Invoke the scrub ioctl. Returns zero or negative error code. */ diff --git a/man/man2/ioctl_xfs_scrub_metadata.2 b/man/man2/ioctl_xfs_scrub_metadata.2 index 8e8bb72fb..9963f1913 100644 --- a/man/man2/ioctl_xfs_scrub_metadata.2 +++ b/man/man2/ioctl_xfs_scrub_metadata.2 @@ -168,6 +168,12 @@ count) for errors. .TP .B XFS_SCRUB_TYPE_NLINKS Scan all inodes in the filesystem to verify each file's link count. + +.TP +.B XFS_SCRUB_TYPE_HEALTHY +Mark everything healthy after a clean scrub run. +This clears out all the indirect health problem markers that might remain +in the system. .RE .PD 1 diff --git a/scrub/scrub.c b/scrub/scrub.c index a22633a81..436ccb0ca 100644 --- a/scrub/scrub.c +++ b/scrub/scrub.c @@ -39,20 +39,15 @@ format_scrub_descr( case XFROG_SCRUB_GROUP_PERAG: return snprintf(buf, buflen, _("AG %u %s"), meta->sm_agno, _(sc->descr)); - break; case XFROG_SCRUB_GROUP_INODE: return scrub_render_ino_descr(ctx, buf, buflen, meta->sm_ino, meta->sm_gen, "%s", _(sc->descr)); - break; case XFROG_SCRUB_GROUP_FS: case XFROG_SCRUB_GROUP_SUMMARY: case XFROG_SCRUB_GROUP_ISCAN: - return snprintf(buf, buflen, _("%s"), _(sc->descr)); - break; case XFROG_SCRUB_GROUP_NONE: - assert(0); - break; + return snprintf(buf, buflen, _("%s"), _(sc->descr)); } return -1; } From patchwork Wed May 22 03:20:35 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: 13670340 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 C591E200B7 for ; Wed, 22 May 2024 03:20:36 +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=1716348036; cv=none; b=A1hanM+ZnZL83V8D8XT6kWI/LnQhrGP8Iy2hldI6WIw/X8TaxQjzlh/zpO4JIr1gTarFkap0P7d7zl8u55enyAFAFIaKEnJ3U3s9S5J+FwUM7WvBhitrASBk9S7kpQvmSRKCoqHgJ0STQHts5ge3Pd8dLAaKkJ6NudDRo36JzTk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716348036; c=relaxed/simple; bh=qGllsgsbXSyVOfa2OO635v2rKSP6lTwkeGzMj0wlfQc=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KuuAwt12ebMS9iPARgDRP/z1+O6JcJC40DWn/G8QtOKUsPCjY8+Q+ylSibaLF0hCrRscVky8S9dPwyjtp5RxjAi0Ps4cwW/5bwnwEPPe1w9Q79xUVfwONhuOqg5ObO7rv4FJBHKmd0KI00JfV8f54AnBU+y9hHggCQ4KdaW1z5g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AvLJ7YgM; 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="AvLJ7YgM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4EF6CC2BD11; Wed, 22 May 2024 03:20:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716348036; bh=qGllsgsbXSyVOfa2OO635v2rKSP6lTwkeGzMj0wlfQc=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=AvLJ7YgM1B5eXy5UhKCcEtNbeFn6/uYK0kGvBb+FJimWpdZ1Q7a7b6w8cUGTwiZwl alVbp+7wTDa9Zo99JM9fCWmyyTmIm5cCpw2tH42VMWrIO9t288S6iPI/K9sqgDCUJD CBlUVISfnIy6/VIoA6TnBGOeeEE6/BcexUwM4G8TG2q0GgqEAVybRg3rBvrtasIsJs 7xlgKADLiAYbR7UJPAYCK46tzcT78CFsyM4J6ehxgWC68w1QQGhFH2Bjt4MuR/2dmD JoWHh77qc6mRZyZn/tz6L3WdTg2ImEEKJxuEbjODXD/w2OwZyhGyReoQMAOsE3kzhb COxOw0hwMoOhw== Date: Tue, 21 May 2024 20:20:35 -0700 Subject: [PATCH 4/5] xfs_scrub: use multiple threads to run in-kernel metadata scrubs that scan inodes From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <171634534772.2482960.11333660488790198337.stgit@frogsfrogsfrogs> In-Reply-To: <171634534709.2482960.7052575979502113240.stgit@frogsfrogsfrogs> References: <171634534709.2482960.7052575979502113240.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 Instead of running the inode link count and quotacheck scanners in serial, run them in parallel, with a slight delay to stagger the work to reduce inode resource contention. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- scrub/phase5.c | 150 ++++++++++++++++++++++++++++++++++++++++++++++++++------ scrub/scrub.c | 18 +++---- scrub/scrub.h | 1 3 files changed, 145 insertions(+), 24 deletions(-) diff --git a/scrub/phase5.c b/scrub/phase5.c index 0a91e4f06..b4c635d34 100644 --- a/scrub/phase5.c +++ b/scrub/phase5.c @@ -384,26 +384,146 @@ check_fs_label( return error; } -/* Check directory connectivity. */ -int -phase5_func( - struct scrub_ctx *ctx) -{ +typedef int (*fs_scan_item_fn)(struct scrub_ctx *, struct action_list *); + +struct fs_scan_item { struct action_list alist; - bool aborted = false; + bool *abortedp; + fs_scan_item_fn scrub_fn; +}; + +/* Run one full-fs scan scrubber in this thread. */ +static void +fs_scan_worker( + struct workqueue *wq, + xfs_agnumber_t nr, + void *arg) +{ + struct timespec tv; + struct fs_scan_item *item = arg; + struct scrub_ctx *ctx = wq->wq_ctx; int ret; /* - * Check and fix anything that requires a full inode scan. We do this - * after we've checked all inodes and repaired anything that could get - * in the way of a scan. + * Delay each successive fs scan by a second so that the threads are + * less likely to contend on the inobt and inode buffers. */ - action_list_init(&alist); - ret = scrub_iscan_metadata(ctx, &alist); - if (ret) - return ret; - ret = action_list_process(ctx, ctx->mnt.fd, &alist, + if (nr) { + tv.tv_sec = nr; + tv.tv_nsec = 0; + nanosleep(&tv, NULL); + } + + ret = item->scrub_fn(ctx, &item->alist); + if (ret) { + str_liberror(ctx, ret, _("checking fs scan metadata")); + *item->abortedp = true; + goto out; + } + + ret = action_list_process(ctx, ctx->mnt.fd, &item->alist, ALP_COMPLAIN_IF_UNFIXED | ALP_NOPROGRESS); + if (ret) { + str_liberror(ctx, ret, _("repairing fs scan metadata")); + *item->abortedp = true; + goto out; + } + +out: + free(item); + return; +} + +/* Queue one full-fs scan scrubber. */ +static int +queue_fs_scan( + struct workqueue *wq, + bool *abortedp, + xfs_agnumber_t nr, + fs_scan_item_fn scrub_fn) +{ + struct fs_scan_item *item; + struct scrub_ctx *ctx = wq->wq_ctx; + int ret; + + item = malloc(sizeof(struct fs_scan_item)); + if (!item) { + ret = ENOMEM; + str_liberror(ctx, ret, _("setting up fs scan")); + return ret; + } + action_list_init(&item->alist); + item->scrub_fn = scrub_fn; + item->abortedp = abortedp; + + ret = -workqueue_add(wq, fs_scan_worker, nr, item); + if (ret) + str_liberror(ctx, ret, _("queuing fs scan work")); + + return ret; +} + +/* Run multiple full-fs scan scrubbers at the same time. */ +static int +run_kernel_fs_scan_scrubbers( + struct scrub_ctx *ctx) +{ + struct workqueue wq_fs_scan; + unsigned int nr_threads = scrub_nproc_workqueue(ctx); + xfs_agnumber_t nr = 0; + bool aborted = false; + int ret, ret2; + + ret = -workqueue_create(&wq_fs_scan, (struct xfs_mount *)ctx, + nr_threads); + if (ret) { + str_liberror(ctx, ret, _("setting up fs scan workqueue")); + return ret; + } + + /* + * The nlinks scanner is much faster than quotacheck because it only + * walks directories, so we start it first. + */ + ret = queue_fs_scan(&wq_fs_scan, &aborted, nr, scrub_nlinks); + if (ret) + goto wait; + + if (nr_threads > 1) + nr++; + + ret = queue_fs_scan(&wq_fs_scan, &aborted, nr, scrub_quotacheck); + if (ret) + goto wait; + +wait: + ret2 = -workqueue_terminate(&wq_fs_scan); + if (ret2) { + str_liberror(ctx, ret2, _("joining fs scan workqueue")); + if (!ret) + ret = ret2; + } + if (aborted && !ret) + ret = ECANCELED; + + workqueue_destroy(&wq_fs_scan); + return ret; +} + +/* Check directory connectivity. */ +int +phase5_func( + struct scrub_ctx *ctx) +{ + bool aborted = false; + int ret; + + /* + * Check and fix anything that requires a full filesystem scan. We do + * this after we've checked all inodes and repaired anything that could + * get in the way of a scan. + */ + ret = run_kernel_fs_scan_scrubbers(ctx); if (ret) return ret; @@ -436,7 +556,7 @@ phase5_estimate( int *rshift) { *items = scrub_estimate_iscan_work(ctx); - *nr_threads = scrub_nproc(ctx); + *nr_threads = scrub_nproc(ctx) * 2; *rshift = 0; return 0; } diff --git a/scrub/scrub.c b/scrub/scrub.c index 436ccb0ca..cf0567795 100644 --- a/scrub/scrub.c +++ b/scrub/scrub.c @@ -417,15 +417,6 @@ scrub_summary_metadata( return scrub_group(ctx, XFROG_SCRUB_GROUP_SUMMARY, 0, alist); } -/* Scrub all metadata requiring a full inode scan. */ -int -scrub_iscan_metadata( - struct scrub_ctx *ctx, - struct action_list *alist) -{ - return scrub_group(ctx, XFROG_SCRUB_GROUP_ISCAN, 0, alist); -} - /* Scrub /only/ the superblock summary counters. */ int scrub_fs_counters( @@ -444,6 +435,15 @@ scrub_quotacheck( return scrub_meta_type(ctx, XFS_SCRUB_TYPE_QUOTACHECK, 0, alist); } +/* Scrub /only/ the file link counters. */ +int +scrub_nlinks( + struct scrub_ctx *ctx, + struct action_list *alist) +{ + return scrub_meta_type(ctx, XFS_SCRUB_TYPE_NLINKS, 0, alist); +} + /* How many items do we have to check? */ unsigned int scrub_estimate_ag_work( diff --git a/scrub/scrub.h b/scrub/scrub.h index 927f86de9..5e3f40bf1 100644 --- a/scrub/scrub.h +++ b/scrub/scrub.h @@ -28,6 +28,7 @@ int scrub_iscan_metadata(struct scrub_ctx *ctx, struct action_list *alist); int scrub_summary_metadata(struct scrub_ctx *ctx, struct action_list *alist); int scrub_fs_counters(struct scrub_ctx *ctx, struct action_list *alist); int scrub_quotacheck(struct scrub_ctx *ctx, struct action_list *alist); +int scrub_nlinks(struct scrub_ctx *ctx, struct action_list *alist); bool can_scrub_fs_metadata(struct scrub_ctx *ctx); bool can_scrub_inode(struct scrub_ctx *ctx); From patchwork Wed May 22 03:20:51 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: 13670341 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 7250E14295 for ; Wed, 22 May 2024 03:20:52 +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=1716348052; cv=none; b=GJsqFBKRRZvBq833eo/vzlMi4X0RQhORBkmPBSFHfGWD0Z1ND+By+t/+Gd+4Ciz2SmaRQxTtwNSbWKUX/faPMLCjHhrxhxVhjJxapSLoEkwkXcy+ETAvYLnMYPywBDFoeGfzOERrgowNChID1NyleHZ+thUoQ+S6olLCZTCVVRU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716348052; c=relaxed/simple; bh=O49T+99fOmADMEdO0KR2Brgp7lzIshf+j9nwXCZzpvE=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YX+x2FaeTtLxTs2ERJIGr70l7nmhCC+AAoagwH4lfelFlaKjoFIX7WJy++wupkMDBWI7pOigHUbEMsQk6glGJdDB8D2LGaeE5ZSLw106KATfeMMoSh/QrUaR8uXIGp5jeXj/tRHvOjL0J+QMx9dvyth54PyplTo3XHIq8ZujZt8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RaLmft6G; 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="RaLmft6G" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E8A20C2BD11; Wed, 22 May 2024 03:20:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716348052; bh=O49T+99fOmADMEdO0KR2Brgp7lzIshf+j9nwXCZzpvE=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=RaLmft6GQ8RimwlD7fZ5hT92nWDhwRdExDPq+Uscs/xf0M3xeGFi5i47U6CTD2FIM O33awEyC1il2GQwNzLdf7tHLfds6zVOYHzoDloCxU70q4UieEZZ7/L50JVRsTM8MNu 1/5AWEgyGBTnmX+fffwbIG6VV3sIVkadr9nLjqGXn1b6RfqhCwaNnrHqboHMHCu2qQ /QzyYUS48MXY6SKMxOa+eoHsE74FcHjxr1IbhkvdGGhF/13SA1R2KqUObPtZ5YIb/X urTpnwa9ok/lUbi+HYQeT9UIFH0QwBbhEOOvjLRpB8bt86z8SVTC6vvJlUqtWYpS0X gBlk0SwQJzipQ== Date: Tue, 21 May 2024 20:20:51 -0700 Subject: [PATCH 5/5] xfs_scrub: upload clean bills of health From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <171634534787.2482960.2432140369998421080.stgit@frogsfrogsfrogs> In-Reply-To: <171634534709.2482960.7052575979502113240.stgit@frogsfrogsfrogs> References: <171634534709.2482960.7052575979502113240.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 scrub terminates with a clean bill of health, tell the kernel that the result of the scan is that everything's healthy. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- scrub/phase1.c | 38 ++++++++++++++++++++++++++++++++++++++ scrub/repair.c | 15 +++++++++++++++ scrub/repair.h | 1 + scrub/scrub.c | 9 +++++++++ scrub/scrub.h | 1 + 5 files changed, 64 insertions(+) diff --git a/scrub/phase1.c b/scrub/phase1.c index 48ca8313b..96138e03e 100644 --- a/scrub/phase1.c +++ b/scrub/phase1.c @@ -44,6 +44,40 @@ xfs_shutdown_fs( str_errno(ctx, ctx->mntpoint); } +/* + * If we haven't found /any/ problems at all, tell the kernel that we're giving + * the filesystem a clean bill of health. + */ +static int +report_to_kernel( + struct scrub_ctx *ctx) +{ + struct action_list alist; + int ret; + + if (!ctx->scrub_setup_succeeded || ctx->corruptions_found || + ctx->runtime_errors || ctx->unfixable_errors || + ctx->warnings_found) + return 0; + + action_list_init(&alist); + ret = scrub_clean_health(ctx, &alist); + if (ret) + return ret; + + /* + * Complain if we cannot fail the clean bill of health, unless we're + * just testing repairs. + */ + if (action_list_length(&alist) > 0 && + !debug_tweak_on("XFS_SCRUB_FORCE_REPAIR")) { + str_info(ctx, _("Couldn't upload clean bill of health."), NULL); + action_list_discard(&alist); + } + + return 0; +} + /* Clean up the XFS-specific state data. */ int scrub_cleanup( @@ -51,6 +85,10 @@ scrub_cleanup( { int error; + error = report_to_kernel(ctx); + if (error) + return error; + action_lists_free(&ctx->action_lists); if (ctx->fshandle) free_handle(ctx->fshandle, ctx->fshandle_len); diff --git a/scrub/repair.c b/scrub/repair.c index 3cb7224f7..9ade805e1 100644 --- a/scrub/repair.c +++ b/scrub/repair.c @@ -172,6 +172,21 @@ action_lists_alloc( return 0; } +/* Discard repair list contents. */ +void +action_list_discard( + struct action_list *alist) +{ + struct action_item *aitem; + struct action_item *n; + + list_for_each_entry_safe(aitem, n, &alist->list, list) { + alist->nr--; + list_del(&aitem->list); + free(aitem); + } +} + /* Free the repair lists. */ void action_lists_free( diff --git a/scrub/repair.h b/scrub/repair.h index 486617f1c..aa3ea1361 100644 --- a/scrub/repair.h +++ b/scrub/repair.h @@ -24,6 +24,7 @@ static inline bool action_list_empty(const struct action_list *alist) unsigned long long action_list_length(struct action_list *alist); void action_list_add(struct action_list *dest, struct action_item *item); +void action_list_discard(struct action_list *alist); void action_list_splice(struct action_list *dest, struct action_list *src); void action_list_find_mustfix(struct action_list *actions, diff --git a/scrub/scrub.c b/scrub/scrub.c index cf0567795..7cb94af3d 100644 --- a/scrub/scrub.c +++ b/scrub/scrub.c @@ -444,6 +444,15 @@ scrub_nlinks( return scrub_meta_type(ctx, XFS_SCRUB_TYPE_NLINKS, 0, alist); } +/* Update incore health records if we were clean. */ +int +scrub_clean_health( + struct scrub_ctx *ctx, + struct action_list *alist) +{ + return scrub_meta_type(ctx, XFS_SCRUB_TYPE_HEALTHY, 0, alist); +} + /* How many items do we have to check? */ unsigned int scrub_estimate_ag_work( diff --git a/scrub/scrub.h b/scrub/scrub.h index 5e3f40bf1..cb33ddb46 100644 --- a/scrub/scrub.h +++ b/scrub/scrub.h @@ -29,6 +29,7 @@ int scrub_summary_metadata(struct scrub_ctx *ctx, struct action_list *alist); int scrub_fs_counters(struct scrub_ctx *ctx, struct action_list *alist); int scrub_quotacheck(struct scrub_ctx *ctx, struct action_list *alist); int scrub_nlinks(struct scrub_ctx *ctx, struct action_list *alist); +int scrub_clean_health(struct scrub_ctx *ctx, struct action_list *alist); bool can_scrub_fs_metadata(struct scrub_ctx *ctx); bool can_scrub_inode(struct scrub_ctx *ctx);