[PATCH 133/145] xfs_repair: use range query when while checking rmaps
Darrick J. Wong
darrick.wong at oracle.com
Thu Jun 16 20:44:44 CDT 2016
For shared extents, we ought to use a range query on the rmapbt to
find the corresponding rmap. However, most of the time the observed
rmap will be an exact match for the rmapbt rmap, in which case we
could have used the (much faster) regular lookup. Therefore, try the
regular lookup first and resort to the range lookup if that doesn't
get us what we want. This can cut the run time of the rmap check of
xfs_repair in half.
Theoretically, the only reason why an observed rmap wouldn't be an
exact match for an rmapbt rmap is because we modified some file on
account of a metadata error.
Signed-off-by: Darrick J. Wong <darrick.wong at oracle.com>
---
repair/rmap.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/repair/rmap.c b/repair/rmap.c
index 5c0e015..1b89d4c 100644
--- a/repair/rmap.c
+++ b/repair/rmap.c
@@ -909,6 +909,20 @@ lookup_rmap(
return xfs_rmap_get_rec(bt_cur, tmp, have);
}
+/* Look for an rmap in the rmapbt that matches a given rmap. */
+static int
+lookup_rmap_overlapped(
+ struct xfs_btree_cur *bt_cur,
+ struct xfs_rmap_irec *rm_rec,
+ struct xfs_rmap_irec *tmp,
+ int *have)
+{
+ /* Have to use our fancy version for overlapped */
+ return xfs_rmap_lookup_le_range(bt_cur, rm_rec->rm_startblock,
+ rm_rec->rm_owner, rm_rec->rm_offset,
+ rm_rec->rm_flags, tmp, have);
+}
+
/* Does the btree rmap cover the observed rmap? */
#define NEXTP(x) ((x)->rm_startblock + (x)->rm_blockcount)
#define NEXTL(x) ((x)->rm_offset + (x)->rm_blockcount)
@@ -997,6 +1011,18 @@ check_rmaps(
error = lookup_rmap(bt_cur, rm_rec, &tmp, &have);
if (error)
goto err;
+ /*
+ * Using the range query is expensive, so only do it if
+ * the regular lookup doesn't find anything or if it doesn't
+ * match the observed rmap.
+ */
+ if (xfs_sb_version_hasreflink(&bt_cur->bc_mp->m_sb) &&
+ (!have || !is_good_rmap(rm_rec, &tmp))) {
+ error = lookup_rmap_overlapped(bt_cur, rm_rec,
+ &tmp, &have);
+ if (error)
+ goto err;
+ }
if (!have) {
do_warn(
_("Missing reverse-mapping record for (%u/%u) %slen %u owner %"PRId64" \
More information about the xfs
mailing list