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 17/19] xfs: scrub the realtime rmapbt
Date: Thu, 31 Aug 2017 13:35:10 -0700	[thread overview]
Message-ID: <150421171018.17458.10680213880705603242.stgit@magnolia> (raw)
In-Reply-To: <150421160433.17458.10817316901867396010.stgit@magnolia>

From: Darrick J. Wong <darrick.wong@oracle.com>

Check the realtime reverse mapping btree against the rtbitmap, and
modify the rtbitmap scrub to check against the rtrmapbt.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 fs/xfs/Makefile        |    5 ++
 fs/xfs/libxfs/xfs_fs.h |    3 +
 fs/xfs/scrub/bmap.c    |    1 
 fs/xfs/scrub/common.h  |    2 +
 fs/xfs/scrub/rtrmap.c  |  123 ++++++++++++++++++++++++++++++++++++++++++++++++
 fs/xfs/scrub/scrub.c   |    9 ++++
 fs/xfs/scrub/scrub.h   |    1 
 7 files changed, 142 insertions(+), 2 deletions(-)
 create mode 100644 fs/xfs/scrub/rtrmap.c


diff --git a/fs/xfs/Makefile b/fs/xfs/Makefile
index 35a2ddf..4336e14 100644
--- a/fs/xfs/Makefile
+++ b/fs/xfs/Makefile
@@ -163,6 +163,9 @@ xfs-y				+= $(addprefix scrub/, \
 				   symlink.o \
 				   )
 
-xfs-$(CONFIG_XFS_RT)		+= scrub/rtbitmap.o
+xfs-$(CONFIG_XFS_RT)		+= $(addprefix scrub/, \
+				   rtbitmap.o \
+				   rtrmap.o \
+				   )
 xfs-$(CONFIG_XFS_QUOTA)		+= scrub/quota.o
 endif
diff --git a/fs/xfs/libxfs/xfs_fs.h b/fs/xfs/libxfs/xfs_fs.h
index fba0105..eb8102c 100644
--- a/fs/xfs/libxfs/xfs_fs.h
+++ b/fs/xfs/libxfs/xfs_fs.h
@@ -507,9 +507,10 @@ struct xfs_scrub_metadata {
 #define XFS_SCRUB_TYPE_UQUOTA	21	/* user quotas */
 #define XFS_SCRUB_TYPE_GQUOTA	22	/* group quotas */
 #define XFS_SCRUB_TYPE_PQUOTA	23	/* project quotas */
+#define XFS_SCRUB_TYPE_RTRMAPBT	24	/* realtime reverse mapping btree */
 
 /* Number of scrub subcommands. */
-#define XFS_SCRUB_TYPE_NR	24
+#define XFS_SCRUB_TYPE_NR	25
 
 /* i: Repair this metadata. */
 #define XFS_SCRUB_IFLAG_REPAIR		(1 << 0)
diff --git a/fs/xfs/scrub/bmap.c b/fs/xfs/scrub/bmap.c
index 7858a5e..438a8b6 100644
--- a/fs/xfs/scrub/bmap.c
+++ b/fs/xfs/scrub/bmap.c
@@ -509,6 +509,7 @@ xfs_scrub_bmap(
 	case XFS_DINODE_FMT_UUID:
 	case XFS_DINODE_FMT_DEV:
 	case XFS_DINODE_FMT_LOCAL:
+	case XFS_DINODE_FMT_RMAP:
 		/* No mappings to check. */
 		goto out_unlock;
 	case XFS_DINODE_FMT_EXTENTS:
diff --git a/fs/xfs/scrub/common.h b/fs/xfs/scrub/common.h
index bf844e5..aceb557 100644
--- a/fs/xfs/scrub/common.h
+++ b/fs/xfs/scrub/common.h
@@ -145,6 +145,8 @@ int xfs_scrub_setup_parent(struct xfs_scrub_context *sc,
 			   struct xfs_inode *ip);
 int xfs_scrub_setup_rt(struct xfs_scrub_context *sc, struct xfs_inode *ip);
 int xfs_scrub_setup_quota(struct xfs_scrub_context *sc, struct xfs_inode *ip);
+int xfs_scrub_setup_rtrmapbt(struct xfs_scrub_context *sc,
+			     struct xfs_inode *ip);
 
 void xfs_scrub_ag_free(struct xfs_scrub_context *sc, struct xfs_scrub_ag *sa);
 int xfs_scrub_ag_init(struct xfs_scrub_context *sc, xfs_agnumber_t agno,
diff --git a/fs/xfs/scrub/rtrmap.c b/fs/xfs/scrub/rtrmap.c
new file mode 100644
index 0000000..1480ea6
--- /dev/null
+++ b/fs/xfs/scrub/rtrmap.c
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2017 Oracle.  All Rights Reserved.
+ *
+ * Author: Darrick J. Wong <darrick.wong@oracle.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation,
+ * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+#include "xfs.h"
+#include "xfs_fs.h"
+#include "xfs_shared.h"
+#include "xfs_format.h"
+#include "xfs_trans_resv.h"
+#include "xfs_mount.h"
+#include "xfs_defer.h"
+#include "xfs_btree.h"
+#include "xfs_bit.h"
+#include "xfs_log_format.h"
+#include "xfs_trans.h"
+#include "xfs_sb.h"
+#include "xfs_rmap.h"
+#include "xfs_rmap_btree.h"
+#include "xfs_rtrmap_btree.h"
+#include "xfs_inode.h"
+#include "scrub/xfs_scrub.h"
+#include "scrub/scrub.h"
+#include "scrub/common.h"
+#include "scrub/btree.h"
+#include "scrub/trace.h"
+
+/* Set us up with the realtime metadata and AG headers locked. */
+int
+xfs_scrub_setup_rtrmapbt(
+	struct xfs_scrub_context	*sc,
+	struct xfs_inode		*ip)
+{
+	struct xfs_mount		*mp = sc->mp;
+	int				lockmode;
+	int				error = 0;
+
+	if (sc->sm->sm_agno || sc->sm->sm_ino || sc->sm->sm_gen)
+		return -EINVAL;
+
+	error = xfs_scrub_setup_fs(sc, ip);
+	if (error)
+		return error;
+
+	lockmode = XFS_ILOCK_EXCL;
+	xfs_ilock(mp->m_rrmapip, lockmode);
+	xfs_trans_ijoin(sc->tp, mp->m_rrmapip, lockmode);
+
+	lockmode = XFS_ILOCK_EXCL | XFS_ILOCK_RTBITMAP;
+	xfs_ilock(mp->m_rbmip, lockmode);
+	xfs_trans_ijoin(sc->tp, mp->m_rbmip, lockmode);
+
+	return 0;
+}
+
+/* Realtime reverse mapping. */
+
+/* Scrub a realtime rmapbt record. */
+STATIC int
+xfs_scrub_rtrmapbt_helper(
+	struct xfs_scrub_btree		*bs,
+	union xfs_btree_rec		*rec)
+{
+	struct xfs_mount		*mp = bs->cur->bc_mp;
+	struct xfs_rmap_irec		irec;
+	unsigned long long		rec_end;
+	bool				non_inode;
+	bool				is_bmbt;
+	bool				is_attr;
+	int				error;
+
+	error = xfs_rmap_btrec_to_irec(bs->cur, rec, &irec);
+	if (!xfs_scrub_btree_op_ok(bs->sc, bs->cur, 0, &error))
+		goto out;
+
+	rec_end = (unsigned long long)irec.rm_startblock + irec.rm_blockcount;
+	xfs_scrub_btree_check_ok(bs->sc, bs->cur, 0,
+			irec.rm_startblock < mp->m_sb.sb_rblocks &&
+			rec_end <= mp->m_sb.sb_rblocks);
+
+	non_inode = XFS_RMAP_NON_INODE_OWNER(irec.rm_owner);
+	is_bmbt = irec.rm_flags & XFS_RMAP_BMBT_BLOCK;
+	is_attr = irec.rm_flags & XFS_RMAP_ATTR_FORK;
+
+	xfs_scrub_btree_check_ok(bs->sc, bs->cur, 0,
+			!is_bmbt && !non_inode && !is_attr);
+
+out:
+	return error;
+}
+
+/* Scrub the realtime rmap btree. */
+int
+xfs_scrub_rtrmapbt(
+	struct xfs_scrub_context	*sc)
+{
+	struct xfs_owner_info		oinfo;
+	struct xfs_mount		*mp = sc->mp;
+	struct xfs_btree_cur		*cur;
+	int				error;
+
+	cur = xfs_rtrmapbt_init_cursor(mp, sc->tp, mp->m_rrmapip);
+	xfs_rmap_ino_bmbt_owner(&oinfo, mp->m_sb.sb_rrmapino, XFS_DATA_FORK);
+	error = xfs_scrub_btree(sc, cur, xfs_scrub_rtrmapbt_helper,
+			&oinfo, NULL);
+	xfs_btree_del_cursor(cur, XFS_BTREE_ERROR);
+
+	return error;
+}
diff --git a/fs/xfs/scrub/scrub.c b/fs/xfs/scrub/scrub.c
index 7f9a4f8..ffb1465 100644
--- a/fs/xfs/scrub/scrub.c
+++ b/fs/xfs/scrub/scrub.c
@@ -343,6 +343,15 @@ static const struct xfs_scrub_meta_ops meta_scrub_ops[] = {
 	{ NULL },
 	{ NULL },
 #endif
+#ifdef CONFIG_XFS_RT
+	{ /* realtime rmapbt */
+		.setup	= xfs_scrub_setup_rtrmapbt,
+		.scrub	= xfs_scrub_rtrmapbt,
+		.has	= xfs_sb_version_hasrtrmapbt,
+	},
+#else
+	{ NULL },
+#endif
 };
 
 #if IS_ENABLED(CONFIG_XFS_ONLINE_REPAIR)
diff --git a/fs/xfs/scrub/scrub.h b/fs/xfs/scrub/scrub.h
index 41ec126..0fc334e 100644
--- a/fs/xfs/scrub/scrub.h
+++ b/fs/xfs/scrub/scrub.h
@@ -105,5 +105,6 @@ int xfs_scrub_parent(struct xfs_scrub_context *sc);
 int xfs_scrub_rtbitmap(struct xfs_scrub_context *sc);
 int xfs_scrub_rtsummary(struct xfs_scrub_context *sc);
 int xfs_scrub_quota(struct xfs_scrub_context *sc);
+int xfs_scrub_rtrmapbt(struct xfs_scrub_context *sc);
 
 #endif	/* __XFS_SCRUB_SCRUB_H__ */


  parent reply	other threads:[~2017-08-31 20:35 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-31 20:33 [PATCH v9 00/19] xfs: add realtime reverse-mapping support Darrick J. Wong
2017-08-31 20:33 ` [PATCH 01/19] xfs: make iroot_realloc a btree function Darrick J. Wong
2017-08-31 20:33 ` [PATCH 02/19] xfs: support storing records in the inode core root Darrick J. Wong
2017-08-31 20:33 ` [PATCH 03/19] xfs: widen xfs_refcount_irec fields to handle realtime rmapbt Darrick J. Wong
2017-08-31 20:33 ` [PATCH 04/19] xfs: introduce realtime rmap btree definitions Darrick J. Wong
2017-08-31 20:33 ` [PATCH 05/19] xfs: define the on-disk realtime rmap btree format Darrick J. Wong
2017-08-31 20:34 ` [PATCH 06/19] xfs: realtime rmap btree transaction reservations Darrick J. Wong
2017-08-31 20:34 ` [PATCH 07/19] xfs: add realtime rmap btree operations Darrick J. Wong
2017-08-31 20:34 ` [PATCH 08/19] xfs: prepare rmap functions to deal with rtrmapbt Darrick J. Wong
2017-08-31 20:34 ` [PATCH 09/19] xfs: add a realtime flag to the rmap update log redo items Darrick J. Wong
2017-08-31 20:34 ` [PATCH 10/19] xfs: add realtime rmap btree block detection to log recovery Darrick J. Wong
2017-08-31 20:34 ` [PATCH 11/19] xfs: add realtime reverse map inode to superblock Darrick J. Wong
2017-08-31 20:34 ` [PATCH 12/19] xfs: wire up a new inode fork type for the realtime rmap Darrick J. Wong
2017-08-31 20:34 ` [PATCH 13/19] xfs: don't assume a left rmap when allocating a new rmap Darrick J. Wong
2017-08-31 20:34 ` [PATCH 14/19] xfs: wire up rmap map and unmap to the realtime rmapbt Darrick J. Wong
2017-08-31 20:34 ` [PATCH 15/19] xfs: enable realtime rmap btree Darrick J. Wong
2017-08-31 20:35 ` [PATCH 16/19] xfs: wire up getfsmap to the realtime reverse mapping btree Darrick J. Wong
2017-08-31 20:35 ` Darrick J. Wong [this message]
2017-08-31 20:35 ` [PATCH 18/19] xfs: cross-reference realtime bitmap to realtime rmapbt scrubber Darrick J. Wong
2017-08-31 20:35 ` [PATCH 19/19] xfs: cross-reference the realtime rmapbt 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=150421171018.17458.10680213880705603242.stgit@magnolia \
    --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.