All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: david@fromorbit.com, darrick.wong@oracle.com
Cc: linux-xfs@vger.kernel.org
Subject: [PATCH 33/39] xfs: repair refcount btrees
Date: Fri, 04 Nov 2016 17:28:01 -0700	[thread overview]
Message-ID: <147830568126.4165.8958545754826054251.stgit@birch.djwong.org> (raw)
In-Reply-To: <147830546754.4165.17790362300876898017.stgit@birch.djwong.org>

Reconstruct the refcount data from the rmap btree.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 libxfs/xfs_btree.c    |   21 +++++++++++++++++++++
 libxfs/xfs_btree.h    |    1 +
 libxfs/xfs_refcount.c |   19 ++++++++++++++++++-
 libxfs/xfs_refcount.h |    4 ++++
 4 files changed, 44 insertions(+), 1 deletion(-)


diff --git a/libxfs/xfs_btree.c b/libxfs/xfs_btree.c
index 0c7d549..d1a5347 100644
--- a/libxfs/xfs_btree.c
+++ b/libxfs/xfs_btree.c
@@ -4891,3 +4891,24 @@ xfs_btree_has_record(
 
 	return 0;
 }
+
+/* Are there more records in this btree? */
+bool
+xfs_btree_has_more_records(
+	struct xfs_btree_cur	*cur)
+{
+	struct xfs_btree_block	*block;
+	struct xfs_buf		*bp;
+
+	block = xfs_btree_get_block(cur, 0, &bp);
+
+	/* There are still records in this block. */
+	if (cur->bc_ptrs[0] < xfs_btree_get_numrecs(block))
+		return true;
+
+	/* There are more record blocks. */
+	if (cur->bc_flags & XFS_BTREE_LONG_PTRS)
+		return block->bb_u.l.bb_rightsib != cpu_to_be64(NULLFSBLOCK);
+	else
+		return block->bb_u.s.bb_rightsib != cpu_to_be32(NULLAGBLOCK);
+}
diff --git a/libxfs/xfs_btree.h b/libxfs/xfs_btree.h
index 52714f0..ace0bb0 100644
--- a/libxfs/xfs_btree.h
+++ b/libxfs/xfs_btree.h
@@ -551,5 +551,6 @@ struct xfs_btree_block *xfs_btree_get_block(struct xfs_btree_cur *cur,
 		int level, struct xfs_buf **bpp);
 int xfs_btree_has_record(struct xfs_btree_cur *cur, union xfs_btree_irec *low,
 		union xfs_btree_irec *high, bool *exists);
+bool xfs_btree_has_more_records(struct xfs_btree_cur *);
 
 #endif	/* __XFS_BTREE_H__ */
diff --git a/libxfs/xfs_refcount.c b/libxfs/xfs_refcount.c
index be0eab3..088f850 100644
--- a/libxfs/xfs_refcount.c
+++ b/libxfs/xfs_refcount.c
@@ -86,6 +86,23 @@ xfs_refcount_lookup_ge(
 	return xfs_btree_lookup(cur, XFS_LOOKUP_GE, stat);
 }
 
+/*
+ * Look up the first record equal to [bno, len] in the btree
+ * given by cur.
+ */
+int
+xfs_refcount_lookup_eq(
+	struct xfs_btree_cur	*cur,
+	xfs_agblock_t		bno,
+	int			*stat)
+{
+	trace_xfs_refcount_lookup(cur->bc_mp, cur->bc_private.a.agno, bno,
+			XFS_LOOKUP_LE);
+	cur->bc_rec.rc.rc_startblock = bno;
+	cur->bc_rec.rc.rc_blockcount = 0;
+	return xfs_btree_lookup(cur, XFS_LOOKUP_EQ, stat);
+}
+
 /* Convert on-disk record to in-core format. */
 void
 xfs_refcount_btrec_to_irec(
@@ -147,7 +164,7 @@ xfs_refcount_update(
  * by [bno, len, refcount].
  * This either works (return 0) or gets an EFSCORRUPTED error.
  */
-STATIC int
+int
 xfs_refcount_insert(
 	struct xfs_btree_cur		*cur,
 	struct xfs_refcount_irec	*irec,
diff --git a/libxfs/xfs_refcount.h b/libxfs/xfs_refcount.h
index 5973c56..cad61de 100644
--- a/libxfs/xfs_refcount.h
+++ b/libxfs/xfs_refcount.h
@@ -24,6 +24,8 @@ extern int xfs_refcount_lookup_le(struct xfs_btree_cur *cur,
 		xfs_agblock_t bno, int *stat);
 extern int xfs_refcount_lookup_ge(struct xfs_btree_cur *cur,
 		xfs_agblock_t bno, int *stat);
+extern int xfs_refcount_lookup_eq(struct xfs_btree_cur *cur,
+		xfs_agblock_t bno, int *stat);
 extern int xfs_refcount_get_rec(struct xfs_btree_cur *cur,
 		struct xfs_refcount_irec *irec, int *stat);
 
@@ -72,5 +74,7 @@ extern int xfs_refcount_has_record(struct xfs_btree_cur *cur,
 union xfs_btree_rec;
 extern void xfs_refcount_btrec_to_irec(union xfs_btree_rec *rec,
 		struct xfs_refcount_irec *irec);
+extern int xfs_refcount_insert(struct xfs_btree_cur *cur,
+		struct xfs_refcount_irec *irec, int *stat);
 
 #endif	/* __XFS_REFCOUNT_H__ */


  parent reply	other threads:[~2016-11-05  0:28 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-05  0:24 [PATCH v2 00/39] xfsprogs: online scrub/repair support Darrick J. Wong
2016-11-05  0:24 ` [PATCH 01/39] xfs: plumb in needed functions for range querying of the freespace btrees Darrick J. Wong
2016-11-05  0:24 ` [PATCH 02/39] xfs: provide a query_range function for " Darrick J. Wong
2016-11-05  0:24 ` [PATCH 03/39] xfs: create a function to query all records in a btree Darrick J. Wong
2016-11-05  0:24 ` [PATCH 04/39] xfs: introduce the XFS_IOC_GETFSMAP ioctl Darrick J. Wong
2016-11-05  0:25 ` [PATCH 05/39] xfs_io: support the new getfsmap ioctl Darrick J. Wong
2016-11-05  0:25 ` [PATCH 06/39] xfs: use GPF_NOFS when allocating btree cursors Darrick J. Wong
2016-11-05  0:25 ` [PATCH 07/39] xfs: add scrub tracepoints Darrick J. Wong
2016-11-05  0:25 ` [PATCH 08/39] xfs: create an ioctl to scrub AG metadata Darrick J. Wong
2016-11-05  0:25 ` [PATCH 09/39] xfs: generic functions to scrub metadata and btrees Darrick J. Wong
2016-11-05  0:25 ` [PATCH 10/39] xfs: scrub the backup superblocks Darrick J. Wong
2016-11-05  0:25 ` [PATCH 11/39] xfs: scrub AGF and AGFL Darrick J. Wong
2016-11-05  0:25 ` [PATCH 12/39] xfs: scrub the AGI Darrick J. Wong
2016-11-05  0:25 ` [PATCH 13/39] xfs: support scrubbing free space btrees Darrick J. Wong
2016-11-05  0:26 ` [PATCH 14/39] xfs: support scrubbing inode btrees Darrick J. Wong
2016-11-05  0:26 ` [PATCH 15/39] xfs: support scrubbing rmap btree Darrick J. Wong
2016-11-05  0:26 ` [PATCH 16/39] xfs: support scrubbing refcount btree Darrick J. Wong
2016-11-05  0:26 ` [PATCH 17/39] xfs: scrub inodes Darrick J. Wong
2016-11-05  0:26 ` [PATCH 18/39] xfs: scrub inode block mappings Darrick J. Wong
2016-11-05  0:26 ` [PATCH 19/39] xfs: scrub directory/attribute btrees Darrick J. Wong
2016-11-05  0:26 ` [PATCH 20/39] xfs: scrub directories Darrick J. Wong
2016-11-05  0:26 ` [PATCH 21/39] xfs: scrub extended attributes Darrick J. Wong
2016-11-05  0:26 ` [PATCH 22/39] xfs: scrub symbolic links Darrick J. Wong
2016-11-05  0:27 ` [PATCH 23/39] xfs: scrub realtime bitmap/summary Darrick J. Wong
2016-11-05  0:27 ` [PATCH 24/39] xfs: scrub should cross-reference with the bnobt Darrick J. Wong
2016-11-05  0:27 ` [PATCH 25/39] xfs: cross-reference bnobt records with cntbt Darrick J. Wong
2016-11-05  0:27 ` [PATCH 26/39] xfs: cross-reference inode btrees during scrub Darrick J. Wong
2016-11-05  0:27 ` [PATCH 27/39] xfs: cross-reference reverse-mapping btree Darrick J. Wong
2016-11-05  0:27 ` [PATCH 28/39] xfs: cross-reference refcount btree during scrub Darrick J. Wong
2016-11-05  0:27 ` [PATCH 29/39] xfs: scrub should cross-reference the realtime bitmap Darrick J. Wong
2016-11-05  0:27 ` [PATCH 30/39] xfs: add helper routines for the repair code Darrick J. Wong
2016-11-05  0:27 ` [PATCH 31/39] xfs: repair inode btrees Darrick J. Wong
2016-11-05  0:27 ` [PATCH 32/39] xfs: rebuild the rmapbt Darrick J. Wong
2016-11-05  0:28 ` Darrick J. Wong [this message]
2016-11-05  0:28 ` [PATCH 34/39] xfs: repair inode block maps Darrick J. Wong
2016-11-05  0:28 ` [PATCH 35/39] xfs: query the per-AG reservation counters Darrick J. Wong
2016-11-05  0:28 ` [PATCH 36/39] xfs_db: introduce fuzz command Darrick J. Wong
2016-11-05  0:28 ` [PATCH 37/39] xfs_db: print attribute remote value blocks Darrick J. Wong
2016-11-05  0:28 ` [PATCH 38/39] xfs_io: provide an interface to the scrub ioctls Darrick J. Wong
2016-11-05  0:28 ` [PATCH 39/39] xfs_scrub: create online filesystem scrub program Darrick J. Wong
2016-11-05  5:22   ` Eryu Guan
2016-11-08  8:37     ` 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=147830568126.4165.8958545754826054251.stgit@birch.djwong.org \
    --to=darrick.wong@oracle.com \
    --cc=david@fromorbit.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.