All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: darrick.wong@oracle.com
Cc: linux-xfs@vger.kernel.org
Subject: [PATCH 26/47] xfs: cross-reference bnobt records with cntbt
Date: Fri, 06 Jan 2017 16:38:37 -0800	[thread overview]
Message-ID: <148374951738.30431.9816411507202357535.stgit@birch.djwong.org> (raw)
In-Reply-To: <148374934333.30431.11042523766304087227.stgit@birch.djwong.org>

Scrub should make sure that each bnobt record has a corresponding
cntbt record.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 fs/xfs/libxfs/xfs_alloc.c |    2 +-
 fs/xfs/libxfs/xfs_alloc.h |    7 +++++++
 fs/xfs/repair/agheader.c  |   20 ++++++++++++++++++++
 fs/xfs/repair/alloc.c     |   31 +++++++++++++++++++++++++++++++
 4 files changed, 59 insertions(+), 1 deletion(-)


diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c
index ad8044b..4776f66 100644
--- a/fs/xfs/libxfs/xfs_alloc.c
+++ b/fs/xfs/libxfs/xfs_alloc.c
@@ -169,7 +169,7 @@ xfs_alloc_lookup_ge(
  * Lookup the first record less than or equal to [bno, len]
  * in the btree given by cur.
  */
-static int				/* error */
+int					/* error */
 xfs_alloc_lookup_le(
 	struct xfs_btree_cur	*cur,	/* btree cursor */
 	xfs_agblock_t		bno,	/* starting block of extent */
diff --git a/fs/xfs/libxfs/xfs_alloc.h b/fs/xfs/libxfs/xfs_alloc.h
index 3fd6540..b79159c 100644
--- a/fs/xfs/libxfs/xfs_alloc.h
+++ b/fs/xfs/libxfs/xfs_alloc.h
@@ -202,6 +202,13 @@ xfs_free_extent(
 	enum xfs_ag_resv_type	type);	/* block reservation type */
 
 int				/* error */
+xfs_alloc_lookup_le(
+	struct xfs_btree_cur	*cur,	/* btree cursor */
+	xfs_agblock_t		bno,	/* starting block of extent */
+	xfs_extlen_t		len,	/* length of extent */
+	int			*stat);	/* success/failure */
+
+int				/* error */
 xfs_alloc_lookup_ge(
 	struct xfs_btree_cur	*cur,	/* btree cursor */
 	xfs_agblock_t		bno,	/* starting block of extent */
diff --git a/fs/xfs/repair/agheader.c b/fs/xfs/repair/agheader.c
index 6375f19..b351885 100644
--- a/fs/xfs/repair/agheader.c
+++ b/fs/xfs/repair/agheader.c
@@ -318,6 +318,7 @@ xfs_scrub_agf(
 	xfs_agblock_t			fl_count;
 	xfs_extlen_t			blocks;
 	bool				is_freesp;
+	int				have;
 	int				level;
 	int				error = 0;
 	int				err2;
@@ -417,6 +418,25 @@ xfs_scrub_agf(
 	}
 skip_bnobt:
 
+	/* Cross-reference with the cntbt. */
+	if (psa->cnt_cur) {
+		err2 = xfs_alloc_lookup_le(psa->cnt_cur, 0, -1U, &have);
+		if (!xfs_scrub_should_xref(sc, err2, &psa->cnt_cur))
+			goto skip_cntbt;
+		if (!have) {
+			XFS_SCRUB_AGF_CHECK(agf->agf_freeblks ==
+					be32_to_cpu(0));
+			goto skip_cntbt;
+		}
+		err2 = xfs_alloc_get_rec(psa->cnt_cur, &agbno, &blocks, &have);
+		if (!xfs_scrub_should_xref(sc, err2, &psa->cnt_cur))
+			goto skip_cntbt;
+		XFS_SCRUB_AGF_CHECK(have);
+		XFS_SCRUB_AGF_CHECK(!have ||
+				blocks == be32_to_cpu(agf->agf_longest));
+	}
+skip_cntbt:
+
 out:
 	return error;
 }
diff --git a/fs/xfs/repair/alloc.c b/fs/xfs/repair/alloc.c
index 2fef449..7cc15b8 100644
--- a/fs/xfs/repair/alloc.c
+++ b/fs/xfs/repair/alloc.c
@@ -31,6 +31,7 @@
 #include "xfs_trace.h"
 #include "xfs_sb.h"
 #include "xfs_rmap.h"
+#include "xfs_alloc.h"
 #include "repair/common.h"
 #include "repair/btree.h"
 
@@ -65,9 +66,15 @@ xfs_scrub_allocbt_helper(
 {
 	struct xfs_mount		*mp = bs->cur->bc_mp;
 	struct xfs_agf			*agf;
+	struct xfs_btree_cur		**xcur;
+	struct xfs_scrub_ag		*psa;
+	xfs_agblock_t			fbno;
 	xfs_agblock_t			bno;
+	xfs_extlen_t			flen;
 	xfs_extlen_t			len;
+	int				has_otherrec;
 	int				error = 0;
+	int				err2;
 
 	bno = be32_to_cpu(rec->alloc.ar_startblock);
 	len = be32_to_cpu(rec->alloc.ar_blockcount);
@@ -81,6 +88,30 @@ xfs_scrub_allocbt_helper(
 	XFS_SCRUB_BTREC_CHECK(bs, (unsigned long long)bno + len <=
 			be32_to_cpu(agf->agf_length));
 
+	if (error)
+		goto out;
+
+	psa = &bs->sc->sa;
+	/*
+	 * Ensure there's a corresponding cntbt/bnobt record matching
+	 * this bnobt/cntbt record, respectively.
+	 */
+	xcur = bs->cur == psa->bno_cur ? &psa->cnt_cur : &psa->bno_cur;
+	if (*xcur) {
+		err2 = xfs_alloc_lookup_le(*xcur, bno, len, &has_otherrec);
+		if (xfs_scrub_btree_should_xref(bs, err2, xcur)) {
+			XFS_SCRUB_BTREC_GOTO(bs, has_otherrec, out);
+			err2 = xfs_alloc_get_rec(*xcur, &fbno, &flen,
+					&has_otherrec);
+			if (xfs_scrub_btree_should_xref(bs, err2, xcur)) {
+				XFS_SCRUB_BTREC_GOTO(bs, has_otherrec, out);
+				XFS_SCRUB_BTREC_CHECK(bs, fbno == bno);
+				XFS_SCRUB_BTREC_CHECK(bs, flen == len);
+			}
+		}
+	}
+
+out:
 	return error;
 }
 


  parent reply	other threads:[~2017-01-07  0:38 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-07  0:35 [PATCH v4 00/47] xfs: online scrub/repair support Darrick J. Wong
2017-01-07  0:35 ` [PATCH 01/47] xfs: plumb in needed functions for range querying of the freespace btrees Darrick J. Wong
2017-01-07  0:35 ` [PATCH 02/47] xfs: provide a query_range function for " Darrick J. Wong
2017-01-07  0:36 ` [PATCH 03/47] xfs: create a function to query all records in a btree Darrick J. Wong
2017-01-07  0:36 ` [PATCH 04/47] xfs: introduce the XFS_IOC_GETFSMAP ioctl Darrick J. Wong
2017-01-07  0:36 ` [PATCH 05/47] xfs: report shared extents in getfsmapx Darrick J. Wong
2017-01-07  0:36 ` [PATCH 06/47] xfs: have getfsmap fall back to the freesp btrees when rmap is not present Darrick J. Wong
2017-01-07  0:36 ` [PATCH 07/47] xfs: getfsmap should fall back to rtbitmap when rtrmapbt " Darrick J. Wong
2017-01-07  0:36 ` [PATCH 08/47] xfs: add scrub tracepoints Darrick J. Wong
2017-01-07  0:36 ` [PATCH 09/47] xfs: create an ioctl to scrub AG metadata Darrick J. Wong
2017-01-07  0:36 ` [PATCH 10/47] xfs: generic functions to scrub metadata and btrees Darrick J. Wong
2017-01-07  0:36 ` [PATCH 11/47] xfs: scrub the backup superblocks Darrick J. Wong
2017-01-07  0:37 ` [PATCH 12/47] xfs: scrub AGF and AGFL Darrick J. Wong
2017-01-07  0:37 ` [PATCH 13/47] xfs: scrub the AGI Darrick J. Wong
2017-01-07  0:37 ` [PATCH 14/47] xfs: support scrubbing free space btrees Darrick J. Wong
2017-01-07  0:37 ` [PATCH 15/47] xfs: support scrubbing inode btrees Darrick J. Wong
2017-01-07  0:37 ` [PATCH 16/47] xfs: support scrubbing rmap btree Darrick J. Wong
2017-01-07  0:37 ` [PATCH 17/47] xfs: support scrubbing refcount btree Darrick J. Wong
2017-01-07  0:37 ` [PATCH 18/47] xfs: scrub inodes Darrick J. Wong
2017-01-07  0:37 ` [PATCH 19/47] xfs: scrub inode block mappings Darrick J. Wong
2017-01-07  0:37 ` [PATCH 20/47] xfs: scrub directory/attribute btrees Darrick J. Wong
2017-01-07  0:38 ` [PATCH 21/47] xfs: scrub directory metadata Darrick J. Wong
2017-01-07  0:38 ` [PATCH 22/47] xfs: scrub extended attributes Darrick J. Wong
2017-01-07  0:38 ` [PATCH 23/47] xfs: scrub symbolic links Darrick J. Wong
2017-01-07  0:38 ` [PATCH 24/47] xfs: scrub realtime bitmap/summary Darrick J. Wong
2017-01-07  0:38 ` [PATCH 25/47] xfs: scrub should cross-reference with the bnobt Darrick J. Wong
2017-01-07  0:38 ` Darrick J. Wong [this message]
2017-01-07  0:38 ` [PATCH 27/47] xfs: cross-reference extents with AG header Darrick J. Wong
2017-01-07  0:38 ` [PATCH 28/47] xfs: cross-reference inode btrees during scrub Darrick J. Wong
2017-01-07  0:38 ` [PATCH 29/47] xfs: cross-reference reverse-mapping btree Darrick J. Wong
2017-01-07  0:39 ` [PATCH 30/47] xfs: cross-reference refcount btree during scrub Darrick J. Wong
2017-01-07  0:39 ` [PATCH 31/47] xfs: scrub should cross-reference the realtime bitmap Darrick J. Wong
2017-01-07  0:39 ` [PATCH 32/47] xfs: cross-reference the block mappings when possible Darrick J. Wong
2017-01-07  0:39 ` [PATCH 33/47] xfs: create tracepoints for online repair Darrick J. Wong
2017-01-07  0:39 ` [PATCH 34/47] xfs: implement the metadata repair ioctl flag Darrick J. Wong
2017-01-07  0:39 ` [PATCH 35/47] xfs: add helper routines for the repair code Darrick J. Wong
2017-01-07  0:39 ` [PATCH 36/47] xfs: repair superblocks Darrick J. Wong
2017-01-07  0:39 ` [PATCH 37/47] xfs: repair the AGF and AGFL Darrick J. Wong
2017-01-07  0:39 ` [PATCH 38/47] xfs: rebuild the AGI Darrick J. Wong
2017-01-07  0:39 ` [PATCH 39/47] xfs: repair free space btrees Darrick J. Wong
2017-01-07  0:40 ` [PATCH 40/47] xfs: repair inode btrees Darrick J. Wong
2017-01-07  0:40 ` [PATCH 41/47] xfs: rebuild the rmapbt Darrick J. Wong
2017-01-07  0:40 ` [PATCH 42/47] xfs: repair refcount btrees Darrick J. Wong
2017-01-07  0:40 ` [PATCH 43/47] xfs: online repair of inodes Darrick J. Wong
2017-01-07  0:40 ` [PATCH 44/47] xfs: repair inode block maps Darrick J. Wong
2017-01-07  0:40 ` [PATCH 45/47] xfs: repair damaged symlinks Darrick J. Wong
2017-01-07  0:40 ` [PATCH 46/47] xfs: query the per-AG reservation counters Darrick J. Wong
2017-01-07  0:40 ` [PATCH 47/47] xfs: avoid mount-time deadlock in CoW extent recovery Darrick J. Wong
2017-01-09 12:40 ` [PATCH v4 00/47] xfs: online scrub/repair support Amir Goldstein
2017-01-09 21:15   ` Darrick J. Wong
2017-01-10  7:54     ` Eryu Guan
2017-01-10  8:13       ` Amir Goldstein
2017-01-10  8:44         ` Eryu Guan
     [not found]         ` <CAOQ4uxiFg18fVh3RFr-Y1-XRmV82dTxc5r05QH8OFYpv2=juvg@mail.gmail.com>
     [not found]           ` <CAOQ4uxhTPt7t4-4MmQwogy+d4mgyG+=MX=12NX8R4V-hGR1q0w@mail.gmail.com>
2017-01-12 20:10             ` Darrick J. Wong
2017-01-10 18:20       ` Darrick J. Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=148374951738.30431.9816411507202357535.stgit@birch.djwong.org \
    --to=darrick.wong@oracle.com \
    --cc=linux-xfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.