linux-xfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCHSET 0/7] xfs: small fixes and cleanups
@ 2021-03-02 22:28 Darrick J. Wong
  2021-03-02 22:28 ` [PATCH 1/7] xfs: fix uninitialized variables in xrep_calc_ag_resblks Darrick J. Wong
                   ` (6 more replies)
  0 siblings, 7 replies; 17+ messages in thread
From: Darrick J. Wong @ 2021-03-02 22:28 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs

Hi all,

This is an assortment of random patches that I'm submitting before I
send the deferred inactivation series.

The first six patches are small fixes and cleanups of the online fsck
code.

The last patch in the series switches the btree height validation code
to use the computed max heights instead of the static XFS_BTREE_MAXLEVEL
define.

If you're going to start using this mess, you probably ought to just
pull from my git trees, which are linked below.

This is an extraordinary way to destroy everything.  Enjoy!
Comments and questions are, as always, welcome.

--D

kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=random-fixes-5.13
---
 fs/xfs/libxfs/xfs_alloc.c      |    8 ++++----
 fs/xfs/libxfs/xfs_ialloc.c     |    4 ++--
 fs/xfs/libxfs/xfs_inode_fork.c |    2 +-
 fs/xfs/scrub/agheader.c        |   33 +++++++++------------------------
 fs/xfs/scrub/common.c          |   23 ++++++++++-------------
 fs/xfs/scrub/common.h          |    5 ++---
 fs/xfs/scrub/health.c          |    3 ++-
 fs/xfs/scrub/quota.c           |    6 ++++--
 fs/xfs/scrub/repair.c          |    6 +++++-
 fs/xfs/scrub/scrub.c           |    2 +-
 10 files changed, 40 insertions(+), 52 deletions(-)


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 1/7] xfs: fix uninitialized variables in xrep_calc_ag_resblks
  2021-03-02 22:28 [PATCHSET 0/7] xfs: small fixes and cleanups Darrick J. Wong
@ 2021-03-02 22:28 ` Darrick J. Wong
  2021-03-05  8:23   ` Christoph Hellwig
  2021-03-06  7:15   ` Christoph Hellwig
  2021-03-02 22:28 ` [PATCH 2/7] xfs: fix dquot scrub loop cancellation Darrick J. Wong
                   ` (5 subsequent siblings)
  6 siblings, 2 replies; 17+ messages in thread
From: Darrick J. Wong @ 2021-03-02 22:28 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs

From: Darrick J. Wong <djwong@kernel.org>

If we can't read the AGF header, we never actually set a value for
freelen and usedlen.  These two variables are used to make the worst
case estimate of btree size, so it's safe to set them to the AG size as
a fallback.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/xfs/scrub/repair.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)


diff --git a/fs/xfs/scrub/repair.c b/fs/xfs/scrub/repair.c
index 25e86c71e7b9..61bc43418a2a 100644
--- a/fs/xfs/scrub/repair.c
+++ b/fs/xfs/scrub/repair.c
@@ -207,7 +207,11 @@ xrep_calc_ag_resblks(
 
 	/* Now grab the block counters from the AGF. */
 	error = xfs_alloc_read_agf(mp, NULL, sm->sm_agno, 0, &bp);
-	if (!error) {
+	if (error) {
+		aglen = xfs_ag_block_count(mp, sm->sm_agno);
+		freelen = aglen;
+		usedlen = aglen;
+	} else {
 		struct xfs_agf	*agf = bp->b_addr;
 
 		aglen = be32_to_cpu(agf->agf_length);


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 2/7] xfs: fix dquot scrub loop cancellation
  2021-03-02 22:28 [PATCHSET 0/7] xfs: small fixes and cleanups Darrick J. Wong
  2021-03-02 22:28 ` [PATCH 1/7] xfs: fix uninitialized variables in xrep_calc_ag_resblks Darrick J. Wong
@ 2021-03-02 22:28 ` Darrick J. Wong
  2021-03-05  8:24   ` Christoph Hellwig
  2021-03-02 22:28 ` [PATCH 3/7] xfs: bail out of scrub immediately if scan incomplete Darrick J. Wong
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 17+ messages in thread
From: Darrick J. Wong @ 2021-03-02 22:28 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs

From: Darrick J. Wong <djwong@kernel.org>

When xchk_quota_item figures out that it needs to terminate the scrub
operation, it needs to return some error code to abort the loop, but
instead it returns zero and the loop keeps running.  Fix this by making
it use ECANCELED, and fix the other loop bailout condition check at the
bottom too.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/xfs/scrub/quota.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)


diff --git a/fs/xfs/scrub/quota.c b/fs/xfs/scrub/quota.c
index e34ca20ae8e4..343f96f48b82 100644
--- a/fs/xfs/scrub/quota.c
+++ b/fs/xfs/scrub/quota.c
@@ -85,7 +85,7 @@ xchk_quota_item(
 	int			error = 0;
 
 	if (xchk_should_terminate(sc, &error))
-		return error;
+		return -ECANCELED;
 
 	/*
 	 * Except for the root dquot, the actual dquot we got must either have
@@ -162,7 +162,7 @@ xchk_quota_item(
 
 out:
 	if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
-		return -EFSCORRUPTED;
+		return -ECANCELED;
 
 	return 0;
 }
@@ -238,6 +238,8 @@ xchk_quota(
 	error = xfs_qm_dqiterate(mp, dqtype, xchk_quota_item, &sqi);
 	sc->ilock_flags = XFS_ILOCK_EXCL;
 	xfs_ilock(sc->ip, sc->ilock_flags);
+	if (error == -ECANCELED)
+		error = 0;
 	if (!xchk_fblock_process_error(sc, XFS_DATA_FORK,
 			sqi.last_id * qi->qi_dqperchunk, &error))
 		goto out;


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 3/7] xfs: bail out of scrub immediately if scan incomplete
  2021-03-02 22:28 [PATCHSET 0/7] xfs: small fixes and cleanups Darrick J. Wong
  2021-03-02 22:28 ` [PATCH 1/7] xfs: fix uninitialized variables in xrep_calc_ag_resblks Darrick J. Wong
  2021-03-02 22:28 ` [PATCH 2/7] xfs: fix dquot scrub loop cancellation Darrick J. Wong
@ 2021-03-02 22:28 ` Darrick J. Wong
  2021-03-05  8:25   ` Christoph Hellwig
  2021-03-02 22:28 ` [PATCH 4/7] xfs: mark a data structure sick if there are cross-referencing errors Darrick J. Wong
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 17+ messages in thread
From: Darrick J. Wong @ 2021-03-02 22:28 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs

From: Darrick J. Wong <djwong@kernel.org>

If a scrubber cannot complete its check and signals an incomplete check,
we must bail out immediately without updating health status, trying a
repair, etc. because our scan is incomplete and we therefore do not know
much more.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/xfs/scrub/scrub.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


diff --git a/fs/xfs/scrub/scrub.c b/fs/xfs/scrub/scrub.c
index 8ebf35b115ce..47c68c72bcac 100644
--- a/fs/xfs/scrub/scrub.c
+++ b/fs/xfs/scrub/scrub.c
@@ -517,7 +517,7 @@ xfs_scrub_metadata(
 			goto out;
 		sc.flags |= XCHK_TRY_HARDER;
 		goto retry_op;
-	} else if (error)
+	} else if (error || (sm->sm_flags & XFS_SCRUB_OFLAG_INCOMPLETE))
 		goto out_teardown;
 
 	xchk_update_health(&sc);


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 4/7] xfs: mark a data structure sick if there are cross-referencing errors
  2021-03-02 22:28 [PATCHSET 0/7] xfs: small fixes and cleanups Darrick J. Wong
                   ` (2 preceding siblings ...)
  2021-03-02 22:28 ` [PATCH 3/7] xfs: bail out of scrub immediately if scan incomplete Darrick J. Wong
@ 2021-03-02 22:28 ` Darrick J. Wong
  2021-03-05  8:26   ` Christoph Hellwig
  2021-03-02 22:29 ` [PATCH 5/7] xfs: set the scrub AG number in xchk_ag_read_headers Darrick J. Wong
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 17+ messages in thread
From: Darrick J. Wong @ 2021-03-02 22:28 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs

From: Darrick J. Wong <djwong@kernel.org>

If scrub observes cross-referencing errors while scanning a data
structure, mark the data structure sick.  There's /something/
inconsistent, even if we can't really tell what it is.

Fixes: 4860a05d2475 ("xfs: scrub/repair should update filesystem metadata health")
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/xfs/scrub/health.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)


diff --git a/fs/xfs/scrub/health.c b/fs/xfs/scrub/health.c
index 83d27cdf579b..3de59b5c2ce6 100644
--- a/fs/xfs/scrub/health.c
+++ b/fs/xfs/scrub/health.c
@@ -133,7 +133,8 @@ xchk_update_health(
 	if (!sc->sick_mask)
 		return;
 
-	bad = (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT);
+	bad = (sc->sm->sm_flags & (XFS_SCRUB_OFLAG_CORRUPT |
+				   XFS_SCRUB_OFLAG_XCORRUPT));
 	switch (type_to_health_flag[sc->sm->sm_type].group) {
 	case XHG_AG:
 		pag = xfs_perag_get(sc->mp, sc->sm->sm_agno);


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 5/7] xfs: set the scrub AG number in xchk_ag_read_headers
  2021-03-02 22:28 [PATCHSET 0/7] xfs: small fixes and cleanups Darrick J. Wong
                   ` (3 preceding siblings ...)
  2021-03-02 22:28 ` [PATCH 4/7] xfs: mark a data structure sick if there are cross-referencing errors Darrick J. Wong
@ 2021-03-02 22:29 ` Darrick J. Wong
  2021-03-05  8:27   ` Christoph Hellwig
  2021-03-02 22:29 ` [PATCH 6/7] xfs: remove return value from xchk_ag_btcur_init Darrick J. Wong
  2021-03-02 22:29 ` [PATCH 7/7] xfs: validate ag btree levels using the precomputed values Darrick J. Wong
  6 siblings, 1 reply; 17+ messages in thread
From: Darrick J. Wong @ 2021-03-02 22:29 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs

From: Darrick J. Wong <djwong@kernel.org>

Since xchk_ag_read_headers initializes fields in struct xchk_ag, we
might as well set the AG number and save the callers the trouble.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/xfs/scrub/agheader.c |   18 ++++++------------
 fs/xfs/scrub/common.c   |   16 +++++++---------
 fs/xfs/scrub/common.h   |    3 +--
 3 files changed, 14 insertions(+), 23 deletions(-)


diff --git a/fs/xfs/scrub/agheader.c b/fs/xfs/scrub/agheader.c
index ae8e2e0ac64a..afe60a9ca93f 100644
--- a/fs/xfs/scrub/agheader.c
+++ b/fs/xfs/scrub/agheader.c
@@ -508,7 +508,7 @@ xchk_agf(
 	struct xfs_mount	*mp = sc->mp;
 	struct xfs_agf		*agf;
 	struct xfs_perag	*pag;
-	xfs_agnumber_t		agno;
+	xfs_agnumber_t		agno = sc->sm->sm_agno;
 	xfs_agblock_t		agbno;
 	xfs_agblock_t		eoag;
 	xfs_agblock_t		agfl_first;
@@ -518,9 +518,7 @@ xchk_agf(
 	int			level;
 	int			error = 0;
 
-	agno = sc->sa.agno = sc->sm->sm_agno;
-	error = xchk_ag_read_headers(sc, agno, &sc->sa.agi_bp,
-			&sc->sa.agf_bp, &sc->sa.agfl_bp);
+	error = xchk_ag_read_headers(sc, agno, &sc->sa);
 	if (!xchk_process_error(sc, agno, XFS_AGF_BLOCK(sc->mp), &error))
 		goto out;
 	xchk_buffer_recheck(sc, sc->sa.agf_bp);
@@ -691,14 +689,12 @@ xchk_agfl(
 {
 	struct xchk_agfl_info	sai;
 	struct xfs_agf		*agf;
-	xfs_agnumber_t		agno;
+	xfs_agnumber_t		agno = sc->sm->sm_agno;
 	unsigned int		agflcount;
 	unsigned int		i;
 	int			error;
 
-	agno = sc->sa.agno = sc->sm->sm_agno;
-	error = xchk_ag_read_headers(sc, agno, &sc->sa.agi_bp,
-			&sc->sa.agf_bp, &sc->sa.agfl_bp);
+	error = xchk_ag_read_headers(sc, agno, &sc->sa);
 	if (!xchk_process_error(sc, agno, XFS_AGFL_BLOCK(sc->mp), &error))
 		goto out;
 	if (!sc->sa.agf_bp)
@@ -846,7 +842,7 @@ xchk_agi(
 	struct xfs_mount	*mp = sc->mp;
 	struct xfs_agi		*agi;
 	struct xfs_perag	*pag;
-	xfs_agnumber_t		agno;
+	xfs_agnumber_t		agno = sc->sm->sm_agno;
 	xfs_agblock_t		agbno;
 	xfs_agblock_t		eoag;
 	xfs_agino_t		agino;
@@ -857,9 +853,7 @@ xchk_agi(
 	int			level;
 	int			error = 0;
 
-	agno = sc->sa.agno = sc->sm->sm_agno;
-	error = xchk_ag_read_headers(sc, agno, &sc->sa.agi_bp,
-			&sc->sa.agf_bp, &sc->sa.agfl_bp);
+	error = xchk_ag_read_headers(sc, agno, &sc->sa);
 	if (!xchk_process_error(sc, agno, XFS_AGI_BLOCK(sc->mp), &error))
 		goto out;
 	xchk_buffer_recheck(sc, sc->sa.agi_bp);
diff --git a/fs/xfs/scrub/common.c b/fs/xfs/scrub/common.c
index 53456f3de881..45c5bf37daaa 100644
--- a/fs/xfs/scrub/common.c
+++ b/fs/xfs/scrub/common.c
@@ -402,22 +402,22 @@ int
 xchk_ag_read_headers(
 	struct xfs_scrub	*sc,
 	xfs_agnumber_t		agno,
-	struct xfs_buf		**agi,
-	struct xfs_buf		**agf,
-	struct xfs_buf		**agfl)
+	struct xchk_ag		*sa)
 {
 	struct xfs_mount	*mp = sc->mp;
 	int			error;
 
-	error = xfs_ialloc_read_agi(mp, sc->tp, agno, agi);
+	sa->agno = agno;
+
+	error = xfs_ialloc_read_agi(mp, sc->tp, agno, &sa->agi_bp);
 	if (error && want_ag_read_header_failure(sc, XFS_SCRUB_TYPE_AGI))
 		goto out;
 
-	error = xfs_alloc_read_agf(mp, sc->tp, agno, 0, agf);
+	error = xfs_alloc_read_agf(mp, sc->tp, agno, 0, &sa->agf_bp);
 	if (error && want_ag_read_header_failure(sc, XFS_SCRUB_TYPE_AGF))
 		goto out;
 
-	error = xfs_alloc_read_agfl(mp, sc->tp, agno, agfl);
+	error = xfs_alloc_read_agfl(mp, sc->tp, agno, &sa->agfl_bp);
 	if (error && want_ag_read_header_failure(sc, XFS_SCRUB_TYPE_AGFL))
 		goto out;
 	error = 0;
@@ -547,9 +547,7 @@ xchk_ag_init(
 {
 	int			error;
 
-	sa->agno = agno;
-	error = xchk_ag_read_headers(sc, agno, &sa->agi_bp,
-			&sa->agf_bp, &sa->agfl_bp);
+	error = xchk_ag_read_headers(sc, agno, sa);
 	if (error)
 		return error;
 
diff --git a/fs/xfs/scrub/common.h b/fs/xfs/scrub/common.h
index 2e50d146105d..bf94b2db0b96 100644
--- a/fs/xfs/scrub/common.h
+++ b/fs/xfs/scrub/common.h
@@ -120,8 +120,7 @@ int xchk_ag_init(struct xfs_scrub *sc, xfs_agnumber_t agno,
 		struct xchk_ag *sa);
 void xchk_perag_get(struct xfs_mount *mp, struct xchk_ag *sa);
 int xchk_ag_read_headers(struct xfs_scrub *sc, xfs_agnumber_t agno,
-		struct xfs_buf **agi, struct xfs_buf **agf,
-		struct xfs_buf **agfl);
+		struct xchk_ag *sa);
 void xchk_ag_btcur_free(struct xchk_ag *sa);
 int xchk_ag_btcur_init(struct xfs_scrub *sc, struct xchk_ag *sa);
 int xchk_count_rmap_ownedby_ag(struct xfs_scrub *sc, struct xfs_btree_cur *cur,


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 6/7] xfs: remove return value from xchk_ag_btcur_init
  2021-03-02 22:28 [PATCHSET 0/7] xfs: small fixes and cleanups Darrick J. Wong
                   ` (4 preceding siblings ...)
  2021-03-02 22:29 ` [PATCH 5/7] xfs: set the scrub AG number in xchk_ag_read_headers Darrick J. Wong
@ 2021-03-02 22:29 ` Darrick J. Wong
  2021-03-05  8:28   ` Christoph Hellwig
  2021-03-02 22:29 ` [PATCH 7/7] xfs: validate ag btree levels using the precomputed values Darrick J. Wong
  6 siblings, 1 reply; 17+ messages in thread
From: Darrick J. Wong @ 2021-03-02 22:29 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs

From: Darrick J. Wong <djwong@kernel.org>

Functions called by this function cannot fail, so get rid of the return
and error checking.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/xfs/scrub/agheader.c |   15 +++------------
 fs/xfs/scrub/common.c   |    7 +++----
 fs/xfs/scrub/common.h   |    2 +-
 3 files changed, 7 insertions(+), 17 deletions(-)


diff --git a/fs/xfs/scrub/agheader.c b/fs/xfs/scrub/agheader.c
index afe60a9ca93f..749faa17f8e2 100644
--- a/fs/xfs/scrub/agheader.c
+++ b/fs/xfs/scrub/agheader.c
@@ -477,16 +477,13 @@ xchk_agf_xref(
 {
 	struct xfs_mount	*mp = sc->mp;
 	xfs_agblock_t		agbno;
-	int			error;
 
 	if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
 		return;
 
 	agbno = XFS_AGF_BLOCK(mp);
 
-	error = xchk_ag_btcur_init(sc, &sc->sa);
-	if (error)
-		return;
+	xchk_ag_btcur_init(sc, &sc->sa);
 
 	xchk_xref_is_used_space(sc, agbno, 1);
 	xchk_agf_xref_freeblks(sc);
@@ -660,16 +657,13 @@ xchk_agfl_xref(
 {
 	struct xfs_mount	*mp = sc->mp;
 	xfs_agblock_t		agbno;
-	int			error;
 
 	if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
 		return;
 
 	agbno = XFS_AGFL_BLOCK(mp);
 
-	error = xchk_ag_btcur_init(sc, &sc->sa);
-	if (error)
-		return;
+	xchk_ag_btcur_init(sc, &sc->sa);
 
 	xchk_xref_is_used_space(sc, agbno, 1);
 	xchk_xref_is_not_inode_chunk(sc, agbno, 1);
@@ -813,16 +807,13 @@ xchk_agi_xref(
 {
 	struct xfs_mount	*mp = sc->mp;
 	xfs_agblock_t		agbno;
-	int			error;
 
 	if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
 		return;
 
 	agbno = XFS_AGI_BLOCK(mp);
 
-	error = xchk_ag_btcur_init(sc, &sc->sa);
-	if (error)
-		return;
+	xchk_ag_btcur_init(sc, &sc->sa);
 
 	xchk_xref_is_used_space(sc, agbno, 1);
 	xchk_xref_is_not_inode_chunk(sc, agbno, 1);
diff --git a/fs/xfs/scrub/common.c b/fs/xfs/scrub/common.c
index 45c5bf37daaa..da60e7d1f895 100644
--- a/fs/xfs/scrub/common.c
+++ b/fs/xfs/scrub/common.c
@@ -452,7 +452,7 @@ xchk_ag_btcur_free(
 }
 
 /* Initialize all the btree cursors for an AG. */
-int
+void
 xchk_ag_btcur_init(
 	struct xfs_scrub	*sc,
 	struct xchk_ag		*sa)
@@ -502,8 +502,6 @@ xchk_ag_btcur_init(
 		sa->refc_cur = xfs_refcountbt_init_cursor(mp, sc->tp,
 				sa->agf_bp, agno);
 	}
-
-	return 0;
 }
 
 /* Release the AG header context and btree cursors. */
@@ -551,7 +549,8 @@ xchk_ag_init(
 	if (error)
 		return error;
 
-	return xchk_ag_btcur_init(sc, sa);
+	xchk_ag_btcur_init(sc, sa);
+	return 0;
 }
 
 /*
diff --git a/fs/xfs/scrub/common.h b/fs/xfs/scrub/common.h
index bf94b2db0b96..5e2c6f693503 100644
--- a/fs/xfs/scrub/common.h
+++ b/fs/xfs/scrub/common.h
@@ -122,7 +122,7 @@ void xchk_perag_get(struct xfs_mount *mp, struct xchk_ag *sa);
 int xchk_ag_read_headers(struct xfs_scrub *sc, xfs_agnumber_t agno,
 		struct xchk_ag *sa);
 void xchk_ag_btcur_free(struct xchk_ag *sa);
-int xchk_ag_btcur_init(struct xfs_scrub *sc, struct xchk_ag *sa);
+void xchk_ag_btcur_init(struct xfs_scrub *sc, struct xchk_ag *sa);
 int xchk_count_rmap_ownedby_ag(struct xfs_scrub *sc, struct xfs_btree_cur *cur,
 		const struct xfs_owner_info *oinfo, xfs_filblks_t *blocks);
 


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 7/7] xfs: validate ag btree levels using the precomputed values
  2021-03-02 22:28 [PATCHSET 0/7] xfs: small fixes and cleanups Darrick J. Wong
                   ` (5 preceding siblings ...)
  2021-03-02 22:29 ` [PATCH 6/7] xfs: remove return value from xchk_ag_btcur_init Darrick J. Wong
@ 2021-03-02 22:29 ` Darrick J. Wong
  2021-03-05  8:29   ` Christoph Hellwig
  6 siblings, 1 reply; 17+ messages in thread
From: Darrick J. Wong @ 2021-03-02 22:29 UTC (permalink / raw)
  To: djwong; +Cc: linux-xfs

From: Darrick J. Wong <djwong@kernel.org>

Use the AG btree height limits that we precomputed into the xfs_mount to
validate the AG headers instead of using XFS_BTREE_MAXLEVELS.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/xfs/libxfs/xfs_alloc.c      |    8 ++++----
 fs/xfs/libxfs/xfs_ialloc.c     |    4 ++--
 fs/xfs/libxfs/xfs_inode_fork.c |    2 +-
 3 files changed, 7 insertions(+), 7 deletions(-)


diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c
index 0c623d3c1036..aaa19101bb2a 100644
--- a/fs/xfs/libxfs/xfs_alloc.c
+++ b/fs/xfs/libxfs/xfs_alloc.c
@@ -2906,13 +2906,13 @@ xfs_agf_verify(
 
 	if (be32_to_cpu(agf->agf_levels[XFS_BTNUM_BNO]) < 1 ||
 	    be32_to_cpu(agf->agf_levels[XFS_BTNUM_CNT]) < 1 ||
-	    be32_to_cpu(agf->agf_levels[XFS_BTNUM_BNO]) > XFS_BTREE_MAXLEVELS ||
-	    be32_to_cpu(agf->agf_levels[XFS_BTNUM_CNT]) > XFS_BTREE_MAXLEVELS)
+	    be32_to_cpu(agf->agf_levels[XFS_BTNUM_BNO]) > mp->m_ag_maxlevels ||
+	    be32_to_cpu(agf->agf_levels[XFS_BTNUM_CNT]) > mp->m_ag_maxlevels)
 		return __this_address;
 
 	if (xfs_sb_version_hasrmapbt(&mp->m_sb) &&
 	    (be32_to_cpu(agf->agf_levels[XFS_BTNUM_RMAP]) < 1 ||
-	     be32_to_cpu(agf->agf_levels[XFS_BTNUM_RMAP]) > XFS_BTREE_MAXLEVELS))
+	     be32_to_cpu(agf->agf_levels[XFS_BTNUM_RMAP]) > mp->m_rmap_maxlevels))
 		return __this_address;
 
 	if (xfs_sb_version_hasrmapbt(&mp->m_sb) &&
@@ -2939,7 +2939,7 @@ xfs_agf_verify(
 
 	if (xfs_sb_version_hasreflink(&mp->m_sb) &&
 	    (be32_to_cpu(agf->agf_refcount_level) < 1 ||
-	     be32_to_cpu(agf->agf_refcount_level) > XFS_BTREE_MAXLEVELS))
+	     be32_to_cpu(agf->agf_refcount_level) > mp->m_refc_maxlevels))
 		return __this_address;
 
 	return NULL;
diff --git a/fs/xfs/libxfs/xfs_ialloc.c b/fs/xfs/libxfs/xfs_ialloc.c
index 69b228fce81a..eefdb518fe64 100644
--- a/fs/xfs/libxfs/xfs_ialloc.c
+++ b/fs/xfs/libxfs/xfs_ialloc.c
@@ -2535,12 +2535,12 @@ xfs_agi_verify(
 		return __this_address;
 
 	if (be32_to_cpu(agi->agi_level) < 1 ||
-	    be32_to_cpu(agi->agi_level) > XFS_BTREE_MAXLEVELS)
+	    be32_to_cpu(agi->agi_level) > M_IGEO(mp)->inobt_maxlevels)
 		return __this_address;
 
 	if (xfs_sb_version_hasfinobt(&mp->m_sb) &&
 	    (be32_to_cpu(agi->agi_free_level) < 1 ||
-	     be32_to_cpu(agi->agi_free_level) > XFS_BTREE_MAXLEVELS))
+	     be32_to_cpu(agi->agi_free_level) > M_IGEO(mp)->inobt_maxlevels))
 		return __this_address;
 
 	/*
diff --git a/fs/xfs/libxfs/xfs_inode_fork.c b/fs/xfs/libxfs/xfs_inode_fork.c
index e080d7e07643..192bcf3e549d 100644
--- a/fs/xfs/libxfs/xfs_inode_fork.c
+++ b/fs/xfs/libxfs/xfs_inode_fork.c
@@ -195,7 +195,7 @@ xfs_iformat_btree(
 		     XFS_BMDR_SPACE_CALC(nrecs) >
 					XFS_DFORK_SIZE(dip, mp, whichfork) ||
 		     ifp->if_nextents > ip->i_d.di_nblocks) ||
-		     level == 0 || level > XFS_BTREE_MAXLEVELS) {
+		     level == 0 || level > XFS_BM_MAXLEVELS(mp, whichfork)) {
 		xfs_warn(mp, "corrupt inode %Lu (btree).",
 					(unsigned long long) ip->i_ino);
 		xfs_inode_verifier_error(ip, -EFSCORRUPTED,


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH 1/7] xfs: fix uninitialized variables in xrep_calc_ag_resblks
  2021-03-02 22:28 ` [PATCH 1/7] xfs: fix uninitialized variables in xrep_calc_ag_resblks Darrick J. Wong
@ 2021-03-05  8:23   ` Christoph Hellwig
  2021-03-05 17:49     ` Darrick J. Wong
  2021-03-06  7:15   ` Christoph Hellwig
  1 sibling, 1 reply; 17+ messages in thread
From: Christoph Hellwig @ 2021-03-05  8:23 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs

On Tue, Mar 02, 2021 at 02:28:42PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
> 
> If we can't read the AGF header, we never actually set a value for
> freelen and usedlen.  These two variables are used to make the worst
> case estimate of btree size, so it's safe to set them to the AG size as
> a fallback.

Do we actually want to continue with the rest of the funtion at all
in this case?

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 2/7] xfs: fix dquot scrub loop cancellation
  2021-03-02 22:28 ` [PATCH 2/7] xfs: fix dquot scrub loop cancellation Darrick J. Wong
@ 2021-03-05  8:24   ` Christoph Hellwig
  0 siblings, 0 replies; 17+ messages in thread
From: Christoph Hellwig @ 2021-03-05  8:24 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs

On Tue, Mar 02, 2021 at 02:28:47PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
> 
> When xchk_quota_item figures out that it needs to terminate the scrub
> operation, it needs to return some error code to abort the loop, but
> instead it returns zero and the loop keeps running.  Fix this by making
> it use ECANCELED, and fix the other loop bailout condition check at the
> bottom too.
> 
> Signed-off-by: Darrick J. Wong <djwong@kernel.org>

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 3/7] xfs: bail out of scrub immediately if scan incomplete
  2021-03-02 22:28 ` [PATCH 3/7] xfs: bail out of scrub immediately if scan incomplete Darrick J. Wong
@ 2021-03-05  8:25   ` Christoph Hellwig
  0 siblings, 0 replies; 17+ messages in thread
From: Christoph Hellwig @ 2021-03-05  8:25 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs

On Tue, Mar 02, 2021 at 02:28:53PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
> 
> If a scrubber cannot complete its check and signals an incomplete check,
> we must bail out immediately without updating health status, trying a
> repair, etc. because our scan is incomplete and we therefore do not know
> much more.
> 
> Signed-off-by: Darrick J. Wong <djwong@kernel.org>

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 4/7] xfs: mark a data structure sick if there are cross-referencing errors
  2021-03-02 22:28 ` [PATCH 4/7] xfs: mark a data structure sick if there are cross-referencing errors Darrick J. Wong
@ 2021-03-05  8:26   ` Christoph Hellwig
  0 siblings, 0 replies; 17+ messages in thread
From: Christoph Hellwig @ 2021-03-05  8:26 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs

On Tue, Mar 02, 2021 at 02:28:59PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
> 
> If scrub observes cross-referencing errors while scanning a data
> structure, mark the data structure sick.  There's /something/
> inconsistent, even if we can't really tell what it is.

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 5/7] xfs: set the scrub AG number in xchk_ag_read_headers
  2021-03-02 22:29 ` [PATCH 5/7] xfs: set the scrub AG number in xchk_ag_read_headers Darrick J. Wong
@ 2021-03-05  8:27   ` Christoph Hellwig
  0 siblings, 0 replies; 17+ messages in thread
From: Christoph Hellwig @ 2021-03-05  8:27 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs

On Tue, Mar 02, 2021 at 02:29:04PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
> 
> Since xchk_ag_read_headers initializes fields in struct xchk_ag, we
> might as well set the AG number and save the callers the trouble.
> 
> Signed-off-by: Darrick J. Wong <djwong@kernel.org>

Nice cleanup!

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 6/7] xfs: remove return value from xchk_ag_btcur_init
  2021-03-02 22:29 ` [PATCH 6/7] xfs: remove return value from xchk_ag_btcur_init Darrick J. Wong
@ 2021-03-05  8:28   ` Christoph Hellwig
  0 siblings, 0 replies; 17+ messages in thread
From: Christoph Hellwig @ 2021-03-05  8:28 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs

On Tue, Mar 02, 2021 at 02:29:10PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
> 
> Functions called by this function cannot fail, so get rid of the return
> and error checking.
> 
> Signed-off-by: Darrick J. Wong <djwong@kernel.org>

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 7/7] xfs: validate ag btree levels using the precomputed values
  2021-03-02 22:29 ` [PATCH 7/7] xfs: validate ag btree levels using the precomputed values Darrick J. Wong
@ 2021-03-05  8:29   ` Christoph Hellwig
  0 siblings, 0 replies; 17+ messages in thread
From: Christoph Hellwig @ 2021-03-05  8:29 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs

On Tue, Mar 02, 2021 at 02:29:16PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
> 
> Use the AG btree height limits that we precomputed into the xfs_mount to
> validate the AG headers instead of using XFS_BTREE_MAXLEVELS.
> 
> Signed-off-by: Darrick J. Wong <djwong@kernel.org>

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 1/7] xfs: fix uninitialized variables in xrep_calc_ag_resblks
  2021-03-05  8:23   ` Christoph Hellwig
@ 2021-03-05 17:49     ` Darrick J. Wong
  0 siblings, 0 replies; 17+ messages in thread
From: Darrick J. Wong @ 2021-03-05 17:49 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-xfs

On Fri, Mar 05, 2021 at 08:23:00AM +0000, Christoph Hellwig wrote:
> On Tue, Mar 02, 2021 at 02:28:42PM -0800, Darrick J. Wong wrote:
> > From: Darrick J. Wong <djwong@kernel.org>
> > 
> > If we can't read the AGF header, we never actually set a value for
> > freelen and usedlen.  These two variables are used to make the worst
> > case estimate of btree size, so it's safe to set them to the AG size as
> > a fallback.
> 
> Do we actually want to continue with the rest of the funtion at all
> in this case?

We do, because this function computes the amount of block reservation to
feed to xfs_trans_alloc when userspace said it wants us to try to repair
something AG-related.

Although... I suppose we don't really need a block reservation to repair
superblocks and AG headers, so we could special-case those four scrub
types to return 0.

(OTOH this is all mostly academic because repair requires rmapbt, which
means that the fs won't even mount with a busted AGF...)

--D

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 1/7] xfs: fix uninitialized variables in xrep_calc_ag_resblks
  2021-03-02 22:28 ` [PATCH 1/7] xfs: fix uninitialized variables in xrep_calc_ag_resblks Darrick J. Wong
  2021-03-05  8:23   ` Christoph Hellwig
@ 2021-03-06  7:15   ` Christoph Hellwig
  1 sibling, 0 replies; 17+ messages in thread
From: Christoph Hellwig @ 2021-03-06  7:15 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs

On Tue, Mar 02, 2021 at 02:28:42PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
> 
> If we can't read the AGF header, we never actually set a value for
> freelen and usedlen.  These two variables are used to make the worst
> case estimate of btree size, so it's safe to set them to the AG size as
> a fallback.
> 
> Signed-off-by: Darrick J. Wong <djwong@kernel.org>

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2021-03-06  7:16 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-02 22:28 [PATCHSET 0/7] xfs: small fixes and cleanups Darrick J. Wong
2021-03-02 22:28 ` [PATCH 1/7] xfs: fix uninitialized variables in xrep_calc_ag_resblks Darrick J. Wong
2021-03-05  8:23   ` Christoph Hellwig
2021-03-05 17:49     ` Darrick J. Wong
2021-03-06  7:15   ` Christoph Hellwig
2021-03-02 22:28 ` [PATCH 2/7] xfs: fix dquot scrub loop cancellation Darrick J. Wong
2021-03-05  8:24   ` Christoph Hellwig
2021-03-02 22:28 ` [PATCH 3/7] xfs: bail out of scrub immediately if scan incomplete Darrick J. Wong
2021-03-05  8:25   ` Christoph Hellwig
2021-03-02 22:28 ` [PATCH 4/7] xfs: mark a data structure sick if there are cross-referencing errors Darrick J. Wong
2021-03-05  8:26   ` Christoph Hellwig
2021-03-02 22:29 ` [PATCH 5/7] xfs: set the scrub AG number in xchk_ag_read_headers Darrick J. Wong
2021-03-05  8:27   ` Christoph Hellwig
2021-03-02 22:29 ` [PATCH 6/7] xfs: remove return value from xchk_ag_btcur_init Darrick J. Wong
2021-03-05  8:28   ` Christoph Hellwig
2021-03-02 22:29 ` [PATCH 7/7] xfs: validate ag btree levels using the precomputed values Darrick J. Wong
2021-03-05  8:29   ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).