From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: darrick.wong@oracle.com
Cc: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: [PATCH 25/55] xfs: scrub inode block mappings
Date: Sat, 21 Jan 2017 00:02:58 -0800 [thread overview]
Message-ID: <148498577874.15323.13006551545005995828.stgit@birch.djwong.org> (raw)
In-Reply-To: <148498561504.15323.8531512066874274553.stgit@birch.djwong.org>
Scrub an individual inode's block mappings to make sure they make sense.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
fs/xfs/Makefile | 1
fs/xfs/libxfs/xfs_bmap_btree.c | 26 +++
fs/xfs/libxfs/xfs_fs.h | 5 -
fs/xfs/scrub/bmap.c | 351 ++++++++++++++++++++++++++++++++++++++++
fs/xfs/scrub/common.c | 3
fs/xfs/scrub/common.h | 7 +
fs/xfs/xfs_bmap_util.c | 105 +++++++-----
fs/xfs/xfs_bmap_util.h | 4
fs/xfs/xfs_trace.h | 5 -
9 files changed, 459 insertions(+), 48 deletions(-)
create mode 100644 fs/xfs/scrub/bmap.c
diff --git a/fs/xfs/Makefile b/fs/xfs/Makefile
index 83fc8d3..7fad1d8 100644
--- a/fs/xfs/Makefile
+++ b/fs/xfs/Makefile
@@ -106,6 +106,7 @@ xfs-y += xfs_aops.o \
xfs-$(CONFIG_XFS_DEBUG) += $(addprefix scrub/, \
agheader.o \
alloc.o \
+ bmap.o \
btree.o \
common.o \
ialloc.o \
diff --git a/fs/xfs/libxfs/xfs_bmap_btree.c b/fs/xfs/libxfs/xfs_bmap_btree.c
index d9be241..fde4a29 100644
--- a/fs/xfs/libxfs/xfs_bmap_btree.c
+++ b/fs/xfs/libxfs/xfs_bmap_btree.c
@@ -622,6 +622,16 @@ xfs_bmbt_init_key_from_rec(
}
STATIC void
+xfs_bmbt_init_high_key_from_rec(
+ union xfs_btree_key *key,
+ union xfs_btree_rec *rec)
+{
+ key->bmbt.br_startoff = cpu_to_be64(
+ xfs_bmbt_disk_get_startoff(&rec->bmbt) +
+ xfs_bmbt_disk_get_blockcount(&rec->bmbt) - 1);
+}
+
+STATIC void
xfs_bmbt_init_rec_from_cur(
struct xfs_btree_cur *cur,
union xfs_btree_rec *rec)
@@ -646,6 +656,16 @@ xfs_bmbt_key_diff(
cur->bc_rec.b.br_startoff;
}
+STATIC __int64_t
+xfs_bmbt_diff_two_keys(
+ struct xfs_btree_cur *cur,
+ union xfs_btree_key *k1,
+ union xfs_btree_key *k2)
+{
+ return (__int64_t)be64_to_cpu(k1->bmbt.br_startoff) -
+ be64_to_cpu(k2->bmbt.br_startoff);
+}
+
static bool
xfs_bmbt_verify(
struct xfs_buf *bp)
@@ -736,7 +756,6 @@ const struct xfs_buf_ops xfs_bmbt_buf_ops = {
};
-#if defined(DEBUG) || defined(XFS_WARN)
STATIC int
xfs_bmbt_keys_inorder(
struct xfs_btree_cur *cur,
@@ -757,7 +776,6 @@ xfs_bmbt_recs_inorder(
xfs_bmbt_disk_get_blockcount(&r1->bmbt) <=
xfs_bmbt_disk_get_startoff(&r2->bmbt);
}
-#endif /* DEBUG */
static const struct xfs_btree_ops xfs_bmbt_ops = {
.rec_len = sizeof(xfs_bmbt_rec_t),
@@ -771,14 +789,14 @@ static const struct xfs_btree_ops xfs_bmbt_ops = {
.get_minrecs = xfs_bmbt_get_minrecs,
.get_dmaxrecs = xfs_bmbt_get_dmaxrecs,
.init_key_from_rec = xfs_bmbt_init_key_from_rec,
+ .init_high_key_from_rec = xfs_bmbt_init_high_key_from_rec,
.init_rec_from_cur = xfs_bmbt_init_rec_from_cur,
.init_ptr_from_cur = xfs_bmbt_init_ptr_from_cur,
.key_diff = xfs_bmbt_key_diff,
+ .diff_two_keys = xfs_bmbt_diff_two_keys,
.buf_ops = &xfs_bmbt_buf_ops,
-#if defined(DEBUG) || defined(XFS_WARN)
.keys_inorder = xfs_bmbt_keys_inorder,
.recs_inorder = xfs_bmbt_recs_inorder,
-#endif
};
/*
diff --git a/fs/xfs/libxfs/xfs_fs.h b/fs/xfs/libxfs/xfs_fs.h
index 5cafbf6..eb32870 100644
--- a/fs/xfs/libxfs/xfs_fs.h
+++ b/fs/xfs/libxfs/xfs_fs.h
@@ -586,7 +586,10 @@ struct xfs_scrub_metadata {
#define XFS_SCRUB_TYPE_RMAPBT 9 /* reverse mapping btree */
#define XFS_SCRUB_TYPE_REFCNTBT 10 /* reference count btree */
#define XFS_SCRUB_TYPE_INODE 11 /* inode record */
-#define XFS_SCRUB_TYPE_MAX 11
+#define XFS_SCRUB_TYPE_BMBTD 12 /* data fork block mapping */
+#define XFS_SCRUB_TYPE_BMBTA 13 /* attr fork block mapping */
+#define XFS_SCRUB_TYPE_BMBTC 14 /* CoW fork block mapping */
+#define XFS_SCRUB_TYPE_MAX 14
#define XFS_SCRUB_FLAG_REPAIR 0x01 /* i: repair this metadata */
#define XFS_SCRUB_FLAG_CORRUPT 0x02 /* o: needs repair */
diff --git a/fs/xfs/scrub/bmap.c b/fs/xfs/scrub/bmap.c
new file mode 100644
index 0000000..87ee945
--- /dev/null
+++ b/fs/xfs/scrub/bmap.c
@@ -0,0 +1,351 @@
+/*
+ * 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_trace.h"
+#include "xfs_sb.h"
+#include "xfs_inode.h"
+#include "xfs_inode_fork.h"
+#include "xfs_bmap.h"
+#include "xfs_bmap_util.h"
+#include "xfs_bmap_btree.h"
+#include "xfs_rmap.h"
+#include "scrub/common.h"
+#include "scrub/btree.h"
+
+/* Set us up with an inode and AG headers, if needed. */
+int
+xfs_scrub_setup_inode_bmap(
+ struct xfs_scrub_context *sc,
+ struct xfs_inode *ip,
+ struct xfs_scrub_metadata *sm,
+ bool retry_deadlocked)
+{
+ int error;
+
+ error = xfs_scrub_setup_inode(sc, ip, sm, retry_deadlocked);
+ if (error || !retry_deadlocked)
+ return error;
+
+ error = xfs_scrub_ag_lock_all(sc);
+ if (error)
+ goto err;
+ sc->retry = retry_deadlocked;
+ return 0;
+err:
+ return xfs_scrub_teardown(sc, ip, error);
+}
+
+/*
+ * Inode fork block mapping (BMBT) scrubber.
+ * More complex than the others because we have to scrub
+ * all the extents regardless of whether or not the fork
+ * is in btree format.
+ */
+
+struct xfs_scrub_bmap_info {
+ struct xfs_scrub_context *sc;
+ const char *type;
+ xfs_daddr_t eofs;
+ xfs_fileoff_t lastoff;
+ bool is_rt;
+ bool is_shared;
+ int whichfork;
+};
+
+#define XFS_SCRUB_BMAP_CHECK(fs_ok) \
+ XFS_SCRUB_INO_CHECK(info->sc, info->sc->ip->i_ino, bp, info->type, fs_ok)
+#define XFS_SCRUB_BMAP_GOTO(fs_ok, label) \
+ XFS_SCRUB_INO_GOTO(info->sc, info->sc->ip->i_ino, bp, info->type, fs_ok, label)
+#define XFS_SCRUB_BMAP_OP_ERROR_GOTO(label) \
+ XFS_SCRUB_OP_ERROR_GOTO(info->sc, agno, 0, "bmap", &error, label);
+/* Scrub a single extent record. */
+STATIC int
+xfs_scrub_bmap_extent(
+ struct xfs_inode *ip,
+ struct xfs_btree_cur *cur,
+ struct xfs_scrub_bmap_info *info,
+ struct xfs_bmbt_irec *irec)
+{
+ struct xfs_scrub_ag sa = {0};
+ struct xfs_mount *mp = ip->i_mount;
+ struct xfs_buf *bp = NULL;
+ xfs_daddr_t daddr;
+ xfs_daddr_t dlen;
+ xfs_agnumber_t agno;
+ int error = 0;
+
+ if (cur)
+ xfs_btree_get_block(cur, 0, &bp);
+
+ XFS_SCRUB_BMAP_CHECK(irec->br_startoff >= info->lastoff);
+ XFS_SCRUB_BMAP_CHECK(irec->br_startblock != HOLESTARTBLOCK);
+ XFS_SCRUB_BMAP_CHECK(!isnullstartblock(irec->br_startblock));
+
+ /* Actual mapping, so check the block ranges. */
+ if (info->is_rt) {
+ daddr = XFS_FSB_TO_BB(mp, irec->br_startblock);
+ agno = NULLAGNUMBER;
+ } else {
+ daddr = XFS_FSB_TO_DADDR(mp, irec->br_startblock);
+ agno = XFS_FSB_TO_AGNO(mp, irec->br_startblock);
+ XFS_SCRUB_BMAP_GOTO(agno < mp->m_sb.sb_agcount, out);
+ }
+ dlen = XFS_FSB_TO_BB(mp, irec->br_blockcount);
+ XFS_SCRUB_BMAP_CHECK(agno < mp->m_sb.sb_agcount);
+ XFS_SCRUB_BMAP_CHECK(bno < mp->m_sb.sb_agblocks);
+ XFS_SCRUB_BMAP_CHECK(irec->br_blockcount > 0);
+ XFS_SCRUB_BMAP_CHECK(irec->br_blockcount <= MAXEXTLEN);
+ XFS_SCRUB_BMAP_CHECK(daddr < info->eofs);
+ XFS_SCRUB_BMAP_CHECK(daddr + dlen < info->eofs);
+ XFS_SCRUB_BMAP_CHECK(irec->br_state != XFS_EXT_UNWRITTEN ||
+ xfs_sb_version_hasextflgbit(&mp->m_sb));
+ if (error)
+ goto out;
+
+ /* Set ourselves up for cross-referencing later. */
+ if (!info->is_rt) {
+ if (!xfs_scrub_ag_can_lock(info->sc, agno))
+ return -EDEADLOCK;
+ error = xfs_scrub_ag_init(info->sc, agno, &sa);
+ XFS_SCRUB_BMAP_OP_ERROR_GOTO(out);
+ }
+
+ xfs_scrub_ag_free(&sa);
+out:
+ info->lastoff = irec->br_startoff + irec->br_blockcount;
+ return error;
+}
+#undef XFS_SCRUB_BMAP_OP_ERROR_GOTO
+#undef XFS_SCRUB_BMAP_GOTO
+
+/* Scrub a bmbt record. */
+STATIC int
+xfs_scrub_bmapbt_helper(
+ struct xfs_scrub_btree *bs,
+ union xfs_btree_rec *rec)
+{
+ struct xfs_bmbt_rec_host ihost;
+ struct xfs_bmbt_irec irec;
+ struct xfs_scrub_bmap_info *info = bs->private;
+ struct xfs_inode *ip = bs->cur->bc_private.b.ip;
+ struct xfs_buf *bp = NULL;
+ struct xfs_btree_block *block;
+ uint64_t owner;
+ int i;
+
+ /*
+ * Check the owners of the btree blocks up to the level below
+ * the root since the verifiers don't do that.
+ */
+ if (xfs_sb_version_hascrc(&bs->cur->bc_mp->m_sb) &&
+ bs->cur->bc_ptrs[0] == 1) {
+ for (i = 0; i < bs->cur->bc_nlevels - 1; i++) {
+ block = xfs_btree_get_block(bs->cur, i, &bp);
+ owner = be64_to_cpu(block->bb_u.l.bb_owner);
+ XFS_SCRUB_BMAP_CHECK(owner == ip->i_ino);
+ }
+ }
+
+ /* Set up the in-core record and scrub it. */
+ ihost.l0 = be64_to_cpu(rec->bmbt.l0);
+ ihost.l1 = be64_to_cpu(rec->bmbt.l1);
+ xfs_bmbt_get_all(&ihost, &irec);
+ return xfs_scrub_bmap_extent(ip, bs->cur, info, &irec);
+}
+#undef XFS_SCRUB_BMAP_CHECK
+
+#define XFS_SCRUB_FORK_CHECK(fs_ok) \
+ XFS_SCRUB_INO_CHECK(sc, ip->i_ino, NULL, info.type, fs_ok);
+#define XFS_SCRUB_FORK_GOTO(fs_ok, label) \
+ XFS_SCRUB_INO_GOTO(sc, ip->i_ino, NULL, info.type, fs_ok, label);
+#define XFS_SCRUB_FORK_OP_ERROR_GOTO(label) \
+ XFS_SCRUB_OP_ERROR_GOTO(sc, \
+ XFS_INO_TO_AGNO(ip->i_mount, ip->i_ino), \
+ XFS_INO_TO_AGBNO(ip->i_mount, ip->i_ino), \
+ info.type, &error, label)
+/* Scrub an inode fork's block mappings. */
+STATIC int
+xfs_scrub_bmap(
+ struct xfs_scrub_context *sc,
+ int whichfork)
+{
+ struct xfs_bmbt_irec irec;
+ struct xfs_scrub_bmap_info info = {0};
+ struct xfs_owner_info oinfo;
+ struct xfs_mount *mp = sc->tp->t_mountp;
+ struct xfs_inode *ip = sc->ip;
+ struct xfs_ifork *ifp;
+ struct xfs_btree_cur *cur;
+ xfs_fileoff_t off;
+ xfs_fileoff_t endoff;
+ int nmaps;
+ int flags = 0;
+ int error = 0;
+ int err2 = 0;
+
+ switch (whichfork) {
+ case XFS_DATA_FORK:
+ info.type = "data fork";
+ break;
+ case XFS_ATTR_FORK:
+ info.type = "attr fork";
+ break;
+ case XFS_COW_FORK:
+ info.type = "CoW fork";
+ break;
+ }
+ ifp = XFS_IFORK_PTR(ip, whichfork);
+
+ info.is_rt = whichfork == XFS_DATA_FORK && XFS_IS_REALTIME_INODE(ip);
+ info.eofs = XFS_FSB_TO_BB(mp, info.is_rt ? mp->m_sb.sb_rblocks :
+ mp->m_sb.sb_dblocks);
+ info.whichfork = whichfork;
+ info.is_shared = whichfork == XFS_DATA_FORK && xfs_is_reflink_inode(ip);
+ info.sc = sc;
+
+ switch (whichfork) {
+ case XFS_COW_FORK:
+ /* Non-existent CoW forks are ignorable. */
+ if (!ifp)
+ goto out_unlock;
+ /* No CoW forks on non-reflink inodes/filesystems. */
+ XFS_SCRUB_FORK_GOTO(xfs_is_reflink_inode(ip), out_unlock);
+ break;
+ case XFS_ATTR_FORK:
+ if (!ifp)
+ goto out_unlock;
+ XFS_SCRUB_FORK_CHECK(xfs_sb_version_hasattr(&mp->m_sb) ||
+ xfs_sb_version_hasattr2(&mp->m_sb));
+ break;
+ }
+
+ /* Check the fork values */
+ switch (XFS_IFORK_FORMAT(ip, whichfork)) {
+ case XFS_DINODE_FMT_UUID:
+ case XFS_DINODE_FMT_DEV:
+ case XFS_DINODE_FMT_LOCAL:
+ /* No mappings to check. */
+ goto out_unlock;
+ case XFS_DINODE_FMT_EXTENTS:
+ XFS_SCRUB_FORK_GOTO(ifp->if_flags & XFS_IFEXTENTS, out_unlock);
+ break;
+ case XFS_DINODE_FMT_BTREE:
+ XFS_SCRUB_FORK_CHECK(whichfork != XFS_COW_FORK);
+ /* Scan the btree records. */
+ cur = xfs_bmbt_init_cursor(mp, sc->tp, ip, whichfork);
+ xfs_rmap_ino_bmbt_owner(&oinfo, ip->i_ino, whichfork);
+ err2 = xfs_scrub_btree(sc, cur, xfs_scrub_bmapbt_helper,
+ &oinfo, &info);
+ xfs_btree_del_cursor(cur, err2 ? XFS_BTREE_ERROR :
+ XFS_BTREE_NOERROR);
+ if (err2 == -EDEADLOCK)
+ return err2;
+ else if (err2)
+ goto out_unlock;
+ break;
+ default:
+ XFS_SCRUB_FORK_GOTO(false, out_unlock);
+ break;
+ }
+
+ /* Extent data is in memory, so scrub that. */
+ switch (whichfork) {
+ case XFS_ATTR_FORK:
+ flags |= XFS_BMAPI_ATTRFORK;
+ break;
+ case XFS_COW_FORK:
+ flags |= XFS_BMAPI_COWFORK;
+ break;
+ default:
+ break;
+ }
+
+ /* Find the offset of the last extent in the mapping. */
+ error = xfs_bmap_last_offset(ip, &endoff, whichfork);
+ XFS_SCRUB_FORK_OP_ERROR_GOTO(out_unlock);
+
+ /* Scrub extent records. */
+ off = 0;
+ info.lastoff = 0;
+ while (true) {
+ nmaps = 1;
+ err2 = xfs_bmapi_read(ip, off, endoff - off, &irec,
+ &nmaps, flags);
+ if (err2 || nmaps == 0 || irec.br_startoff > endoff)
+ break;
+ /* Scrub non-hole extent. */
+ if (irec.br_startblock != HOLESTARTBLOCK &&
+ irec.br_startblock != DELAYSTARTBLOCK) {
+ err2 = xfs_scrub_bmap_extent(ip, NULL, &info, &irec);
+ if (err2 == -EDEADLOCK)
+ return err2;
+ else if (!error && err2)
+ error = err2;
+ if (xfs_scrub_should_terminate(&error))
+ break;
+ }
+
+ off += irec.br_blockcount;
+ }
+
+out_unlock:
+ if (error == 0 && err2 != 0)
+ error = err2;
+ return error;
+}
+#undef XFS_SCRUB_FORK_CHECK
+#undef XFS_SCRUB_FORK_GOTO
+
+/* Scrub an inode's data fork. */
+int
+xfs_scrub_bmap_data(
+ struct xfs_scrub_context *sc)
+{
+ return xfs_scrub_bmap(sc, XFS_DATA_FORK);
+}
+
+/* Scrub an inode's attr fork. */
+int
+xfs_scrub_bmap_attr(
+ struct xfs_scrub_context *sc)
+{
+ return xfs_scrub_bmap(sc, XFS_ATTR_FORK);
+}
+
+/* Scrub an inode's CoW fork. */
+int
+xfs_scrub_bmap_cow(
+ struct xfs_scrub_context *sc)
+{
+ if (!xfs_is_reflink_inode(sc->ip))
+ return -ENOENT;
+
+ return xfs_scrub_bmap(sc, XFS_COW_FORK);
+}
diff --git a/fs/xfs/scrub/common.c b/fs/xfs/scrub/common.c
index a5fecae..545c46a 100644
--- a/fs/xfs/scrub/common.c
+++ b/fs/xfs/scrub/common.c
@@ -680,6 +680,9 @@ static const struct xfs_scrub_meta_fns meta_scrub_fns[] = {
{xfs_scrub_setup_ag_header, xfs_scrub_rmapbt, NULL, xfs_sb_version_hasrmapbt},
{xfs_scrub_setup_ag_header, xfs_scrub_refcountbt, NULL, xfs_sb_version_hasreflink},
{xfs_scrub_setup_inode_raw, xfs_scrub_inode, NULL, NULL},
+ {xfs_scrub_setup_inode_bmap, xfs_scrub_bmap_data, NULL, NULL},
+ {xfs_scrub_setup_inode_bmap, xfs_scrub_bmap_attr, NULL, NULL},
+ {xfs_scrub_setup_inode_bmap, xfs_scrub_bmap_cow, NULL, NULL},
};
/* Dispatch metadata scrubbing. */
diff --git a/fs/xfs/scrub/common.h b/fs/xfs/scrub/common.h
index ae4bee5..8c30e78 100644
--- a/fs/xfs/scrub/common.h
+++ b/fs/xfs/scrub/common.h
@@ -222,6 +222,10 @@ int xfs_scrub_setup_inode_raw(struct xfs_scrub_context *sc,
struct xfs_inode *ip,
struct xfs_scrub_metadata *sm,
bool retry_deadlocked);
+int xfs_scrub_setup_inode_bmap(struct xfs_scrub_context *sc,
+ struct xfs_inode *ip,
+ struct xfs_scrub_metadata *sm,
+ bool retry_deadlocked);
/* Metadata scrubbers */
@@ -236,5 +240,8 @@ int xfs_scrub_finobt(struct xfs_scrub_context *sc);
int xfs_scrub_rmapbt(struct xfs_scrub_context *sc);
int xfs_scrub_refcountbt(struct xfs_scrub_context *sc);
int xfs_scrub_inode(struct xfs_scrub_context *sc);
+int xfs_scrub_bmap_data(struct xfs_scrub_context *sc);
+int xfs_scrub_bmap_attr(struct xfs_scrub_context *sc);
+int xfs_scrub_bmap_cow(struct xfs_scrub_context *sc);
#endif /* __XFS_REPAIR_COMMON_H__ */
diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c
index b9abce5..d983f28 100644
--- a/fs/xfs/xfs_bmap_util.c
+++ b/fs/xfs/xfs_bmap_util.c
@@ -231,7 +231,7 @@ xfs_bmap_count_leaves(
xfs_ifork_t *ifp,
xfs_extnum_t idx,
int numrecs,
- int *count)
+ unsigned long long *count)
{
int b;
@@ -250,7 +250,7 @@ xfs_bmap_disk_count_leaves(
struct xfs_mount *mp,
struct xfs_btree_block *block,
int numrecs,
- int *count)
+ unsigned long long *count)
{
int b;
xfs_bmbt_rec_t *frp;
@@ -265,17 +265,18 @@ xfs_bmap_disk_count_leaves(
* Recursively walks each level of a btree
* to count total fsblocks in use.
*/
-STATIC int /* error */
+STATIC int
xfs_bmap_count_tree(
- xfs_mount_t *mp, /* file system mount point */
- xfs_trans_t *tp, /* transaction pointer */
- xfs_ifork_t *ifp, /* inode fork pointer */
- xfs_fsblock_t blockno, /* file system block number */
- int levelin, /* level in btree */
- int *count) /* Count of blocks */
+ struct xfs_mount *mp,
+ struct xfs_trans *tp,
+ struct xfs_ifork *ifp,
+ xfs_fsblock_t blockno,
+ int levelin,
+ unsigned int *nextents,
+ unsigned long long *count)
{
int error;
- xfs_buf_t *bp, *nbp;
+ struct xfs_buf *bp, *nbp;
int level = levelin;
__be64 *pp;
xfs_fsblock_t bno = blockno;
@@ -308,8 +309,9 @@ xfs_bmap_count_tree(
/* Dive to the next level */
pp = XFS_BMBT_PTR_ADDR(mp, block, 1, mp->m_bmap_dmxr[1]);
bno = be64_to_cpu(*pp);
- if (unlikely((error =
- xfs_bmap_count_tree(mp, tp, ifp, bno, level, count)) < 0)) {
+ error = xfs_bmap_count_tree(mp, tp, ifp, bno, level, nextents,
+ count);
+ if (error) {
xfs_trans_brelse(tp, bp);
XFS_ERROR_REPORT("xfs_bmap_count_tree(1)",
XFS_ERRLEVEL_LOW, mp);
@@ -321,6 +323,7 @@ xfs_bmap_count_tree(
for (;;) {
nextbno = be64_to_cpu(block->bb_u.l.bb_rightsib);
numrecs = be16_to_cpu(block->bb_numrecs);
+ (*nextents) += numrecs;
xfs_bmap_disk_count_leaves(mp, block, numrecs, count);
xfs_trans_brelse(tp, bp);
if (nextbno == NULLFSBLOCK)
@@ -341,44 +344,61 @@ xfs_bmap_count_tree(
/*
* Count fsblocks of the given fork.
*/
-static int /* error */
+int
xfs_bmap_count_blocks(
- xfs_trans_t *tp, /* transaction pointer */
- xfs_inode_t *ip, /* incore inode */
- int whichfork, /* data or attr fork */
- int *count) /* out: count of blocks */
+ struct xfs_trans *tp,
+ struct xfs_inode *ip,
+ int whichfork,
+ unsigned int *nextents,
+ unsigned long long *count)
{
struct xfs_btree_block *block; /* current btree block */
xfs_fsblock_t bno; /* block # of "block" */
- xfs_ifork_t *ifp; /* fork structure */
+ struct xfs_ifork *ifp; /* fork structure */
int level; /* btree level, for checking */
- xfs_mount_t *mp; /* file system mount structure */
+ struct xfs_mount *mp; /* file system mount structure */
__be64 *pp; /* pointer to block address */
+ int error;
bno = NULLFSBLOCK;
mp = ip->i_mount;
+ *nextents = 0;
ifp = XFS_IFORK_PTR(ip, whichfork);
- if ( XFS_IFORK_FORMAT(ip, whichfork) == XFS_DINODE_FMT_EXTENTS ) {
- xfs_bmap_count_leaves(ifp, 0, xfs_iext_count(ifp), count);
+ if (!ifp)
return 0;
- }
- /*
- * Root level must use BMAP_BROOT_PTR_ADDR macro to get ptr out.
- */
- block = ifp->if_broot;
- level = be16_to_cpu(block->bb_level);
- ASSERT(level > 0);
- pp = XFS_BMAP_BROOT_PTR_ADDR(mp, block, 1, ifp->if_broot_bytes);
- bno = be64_to_cpu(*pp);
- ASSERT(bno != NULLFSBLOCK);
- ASSERT(XFS_FSB_TO_AGNO(mp, bno) < mp->m_sb.sb_agcount);
- ASSERT(XFS_FSB_TO_AGBNO(mp, bno) < mp->m_sb.sb_agblocks);
-
- if (unlikely(xfs_bmap_count_tree(mp, tp, ifp, bno, level, count) < 0)) {
- XFS_ERROR_REPORT("xfs_bmap_count_blocks(2)", XFS_ERRLEVEL_LOW,
- mp);
- return -EFSCORRUPTED;
+ switch (XFS_IFORK_FORMAT(ip, whichfork)) {
+ case XFS_DINODE_FMT_EXTENTS:
+ *nextents = xfs_iext_count(ifp);
+ xfs_bmap_count_leaves(ifp, 0, (*nextents), count);
+ return 0;
+ case XFS_DINODE_FMT_BTREE:
+ if (!(ifp->if_flags & XFS_IFEXTENTS)) {
+ error = xfs_iread_extents(tp, ip, whichfork);
+ if (error)
+ return error;
+ }
+
+ /*
+ * Root level must use BMAP_BROOT_PTR_ADDR macro to get ptr out.
+ */
+ block = ifp->if_broot;
+ level = be16_to_cpu(block->bb_level);
+ ASSERT(level > 0);
+ pp = XFS_BMAP_BROOT_PTR_ADDR(mp, block, 1, ifp->if_broot_bytes);
+ bno = be64_to_cpu(*pp);
+ ASSERT(bno != NULLFSBLOCK);
+ ASSERT(XFS_FSB_TO_AGNO(mp, bno) < mp->m_sb.sb_agcount);
+ ASSERT(XFS_FSB_TO_AGBNO(mp, bno) < mp->m_sb.sb_agblocks);
+
+ error = xfs_bmap_count_tree(mp, tp, ifp, bno, level,
+ nextents, count);
+ if (error) {
+ XFS_ERROR_REPORT("xfs_bmap_count_blocks(2)",
+ XFS_ERRLEVEL_LOW, mp);
+ return -EFSCORRUPTED;
+ }
+ return 0;
}
return 0;
@@ -1788,8 +1808,9 @@ xfs_swap_extent_forks(
int *target_log_flags)
{
struct xfs_ifork tempifp, *ifp, *tifp;
- int aforkblks = 0;
- int taforkblks = 0;
+ unsigned long long aforkblks = 0;
+ unsigned long long taforkblks = 0;
+ unsigned int junk;
xfs_extnum_t nextents;
__uint64_t tmp;
int error;
@@ -1799,14 +1820,14 @@ xfs_swap_extent_forks(
*/
if ( ((XFS_IFORK_Q(ip) != 0) && (ip->i_d.di_anextents > 0)) &&
(ip->i_d.di_aformat != XFS_DINODE_FMT_LOCAL)) {
- error = xfs_bmap_count_blocks(tp, ip, XFS_ATTR_FORK,
+ error = xfs_bmap_count_blocks(tp, ip, XFS_ATTR_FORK, &junk,
&aforkblks);
if (error)
return error;
}
if ( ((XFS_IFORK_Q(tip) != 0) && (tip->i_d.di_anextents > 0)) &&
(tip->i_d.di_aformat != XFS_DINODE_FMT_LOCAL)) {
- error = xfs_bmap_count_blocks(tp, tip, XFS_ATTR_FORK,
+ error = xfs_bmap_count_blocks(tp, tip, XFS_ATTR_FORK, &junk,
&taforkblks);
if (error)
return error;
diff --git a/fs/xfs/xfs_bmap_util.h b/fs/xfs/xfs_bmap_util.h
index 68a621a..73a03c3 100644
--- a/fs/xfs/xfs_bmap_util.h
+++ b/fs/xfs/xfs_bmap_util.h
@@ -71,4 +71,8 @@ int xfs_swap_extents(struct xfs_inode *ip, struct xfs_inode *tip,
xfs_daddr_t xfs_fsb_to_db(struct xfs_inode *ip, xfs_fsblock_t fsb);
+int xfs_bmap_count_blocks(struct xfs_trans *tp, struct xfs_inode *ip,
+ int whichfork, unsigned int *nextents,
+ unsigned long long *count);
+
#endif /* __XFS_BMAP_UTIL_H__ */
diff --git a/fs/xfs/xfs_trace.h b/fs/xfs/xfs_trace.h
index 2cf344e..141a39f 100644
--- a/fs/xfs/xfs_trace.h
+++ b/fs/xfs/xfs_trace.h
@@ -3364,7 +3364,10 @@ DEFINE_GETFSMAP_EVENT(xfs_getfsmap_mapping);
{ XFS_SCRUB_TYPE_FINOBT, "finobt" }, \
{ XFS_SCRUB_TYPE_RMAPBT, "rmapbt" }, \
{ XFS_SCRUB_TYPE_REFCNTBT, "refcountbt" }, \
- { XFS_SCRUB_TYPE_INODE, "inode" }
+ { XFS_SCRUB_TYPE_INODE, "inode" }, \
+ { XFS_SCRUB_TYPE_BMBTD, "bmapbtd" }, \
+ { XFS_SCRUB_TYPE_BMBTA, "bmapbta" }, \
+ { XFS_SCRUB_TYPE_BMBTC, "bmapbtc" }
DECLARE_EVENT_CLASS(xfs_scrub_class,
TP_PROTO(struct xfs_inode *ip, int type, xfs_agnumber_t agno,
xfs_ino_t inum, unsigned int gen, unsigned int flags,
next prev parent reply other threads:[~2017-01-21 8:03 UTC|newest]
Thread overview: 60+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-21 8:00 [PATCH v5 00/55] xfs: online scrub/repair support Darrick J. Wong
2017-01-21 8:00 ` [PATCH 01/55] xfs: fix toctou race when locking an inode to access the data map Darrick J. Wong
2017-01-21 8:00 ` [PATCH 02/55] xfs: fail _dir_open when readahead fails Darrick J. Wong
2017-01-21 8:00 ` [PATCH 03/55] xfs: filter out obviously bad btree pointers Darrick J. Wong
2017-01-21 8:00 ` [PATCH 04/55] xfs: check for obviously bad level values in the bmbt root Darrick J. Wong
2017-01-21 8:00 ` [PATCH 05/55] xfs: verify free block header fields Darrick J. Wong
2017-01-21 8:00 ` [PATCH 06/55] xfs: plumb in needed functions for range querying of the freespace btrees Darrick J. Wong
2017-01-21 8:00 ` [PATCH 07/55] xfs: provide a query_range function for " Darrick J. Wong
2017-01-21 8:01 ` [PATCH 08/55] xfs: create a function to query all records in a btree Darrick J. Wong
2017-01-21 8:01 ` [PATCH 09/55] xfs: introduce the XFS_IOC_GETFSMAP ioctl Darrick J. Wong
2017-01-21 8:01 ` [PATCH 10/55] xfs: report shared extents in getfsmapx Darrick J. Wong
2017-01-21 8:01 ` [PATCH 11/55] xfs: have getfsmap fall back to the freesp btrees when rmap is not present Darrick J. Wong
2017-01-21 8:01 ` [PATCH 12/55] xfs: getfsmap should fall back to rtbitmap when rtrmapbt " Darrick J. Wong
2017-01-21 8:01 ` [PATCH 13/55] xfs: query the per-AG reservation counters Darrick J. Wong
2017-01-21 8:01 ` [PATCH 14/55] xfs: add scrub tracepoints Darrick J. Wong
2017-01-21 8:01 ` [PATCH 15/55] xfs: create an ioctl to scrub AG metadata Darrick J. Wong
2017-01-21 8:01 ` [PATCH 16/55] xfs: generic functions to scrub metadata and btrees Darrick J. Wong
2017-01-21 8:02 ` [PATCH 17/55] xfs: scrub the backup superblocks Darrick J. Wong
2017-01-21 8:02 ` [PATCH 18/55] xfs: scrub AGF and AGFL Darrick J. Wong
2017-01-21 8:02 ` [PATCH 19/55] xfs: scrub the AGI Darrick J. Wong
2017-01-21 8:02 ` [PATCH 20/55] xfs: support scrubbing free space btrees Darrick J. Wong
2017-01-21 8:02 ` [PATCH 21/55] xfs: support scrubbing inode btrees Darrick J. Wong
2017-01-21 8:02 ` [PATCH 22/55] xfs: support scrubbing rmap btree Darrick J. Wong
2017-01-21 8:02 ` [PATCH 23/55] xfs: support scrubbing refcount btree Darrick J. Wong
2017-01-21 8:02 ` [PATCH 24/55] xfs: scrub inodes Darrick J. Wong
2017-01-21 8:02 ` Darrick J. Wong [this message]
2017-01-21 8:03 ` [PATCH 26/55] xfs: scrub directory/attribute btrees Darrick J. Wong
2017-01-21 8:03 ` [PATCH 27/55] xfs: scrub directory metadata Darrick J. Wong
2017-01-21 8:03 ` [PATCH 28/55] xfs: scrub directory freespace Darrick J. Wong
2017-01-21 8:03 ` [PATCH 29/55] xfs: scrub extended attributes Darrick J. Wong
2017-01-21 8:03 ` [PATCH 30/55] xfs: scrub symbolic links Darrick J. Wong
2017-01-21 8:03 ` [PATCH 31/55] xfs: scrub realtime bitmap/summary Darrick J. Wong
2017-01-21 8:03 ` [PATCH 32/55] xfs: set up cross-referencing helpers Darrick J. Wong
2017-01-21 8:03 ` [PATCH 33/55] xfs: scrub should cross-reference with the bnobt Darrick J. Wong
2017-01-21 8:04 ` [PATCH 34/55] xfs: cross-reference bnobt records with cntbt Darrick J. Wong
2017-01-21 8:04 ` [PATCH 35/55] xfs: cross-reference extents with AG header Darrick J. Wong
2017-01-21 8:04 ` [PATCH 36/55] xfs: cross-reference inode btrees during scrub Darrick J. Wong
2017-01-21 8:04 ` [PATCH 37/55] xfs: cross-reference reverse-mapping btree Darrick J. Wong
2017-01-21 8:04 ` [PATCH 38/55] xfs: cross-reference refcount btree during scrub Darrick J. Wong
2017-01-21 8:04 ` [PATCH 39/55] xfs: scrub should cross-reference the realtime bitmap Darrick J. Wong
2017-01-21 8:04 ` [PATCH 40/55] xfs: cross-reference the block mappings when possible Darrick J. Wong
2017-01-21 8:04 ` [PATCH 41/55] xfs: shut off scrub-related error and corruption messages Darrick J. Wong
2017-01-21 8:04 ` [PATCH 42/55] xfs: create tracepoints for online repair Darrick J. Wong
2017-01-21 8:05 ` [PATCH 43/55] xfs: implement the metadata repair ioctl flag Darrick J. Wong
2017-01-21 8:05 ` [PATCH 44/55] xfs: add helper routines for the repair code Darrick J. Wong
2017-01-21 8:05 ` [PATCH 45/55] xfs: repair superblocks Darrick J. Wong
2017-01-21 8:05 ` [PATCH 46/55] xfs: repair the AGF and AGFL Darrick J. Wong
2017-01-21 8:05 ` [PATCH 47/55] xfs: rebuild the AGI Darrick J. Wong
2017-01-21 8:05 ` [PATCH 48/55] xfs: repair free space btrees Darrick J. Wong
2017-01-21 8:05 ` [PATCH 49/55] xfs: repair inode btrees Darrick J. Wong
2017-01-21 8:05 ` [PATCH 50/55] xfs: rebuild the rmapbt Darrick J. Wong
2017-01-21 8:05 ` [PATCH 51/55] xfs: repair refcount btrees Darrick J. Wong
2017-01-21 8:05 ` [PATCH 52/55] xfs: online repair of inodes Darrick J. Wong
2017-01-21 8:06 ` [PATCH 53/55] xfs: repair inode block maps Darrick J. Wong
2017-01-21 8:06 ` [PATCH 54/55] xfs: repair damaged symlinks Darrick J. Wong
2017-01-21 8:06 ` [PATCH 55/55] xfs: avoid mount-time deadlock in CoW extent recovery Darrick J. Wong
2017-01-24 17:08 ` [PATCH v5 00/55] xfs: online scrub/repair support Brian Foster
2017-01-24 19:37 ` Darrick J. Wong
2017-01-24 20:50 ` Brian Foster
2017-01-24 21:40 ` Dave Chinner
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=148498577874.15323.13006551545005995828.stgit@birch.djwong.org \
--to=darrick.wong@oracle.com \
--cc=linux-fsdevel@vger.kernel.org \
--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.