From: Brian Foster <bfoster@redhat.com>
To: "Darrick J. Wong" <darrick.wong@oracle.com>
Cc: linux-xfs@vger.kernel.org
Subject: Re: [PATCH 5/9] xfs: bmap scrubber should do rmap xref with bmap for sparse files
Date: Wed, 21 Mar 2018 13:42:32 -0400 [thread overview]
Message-ID: <20180321174232.GG11127@bfoster.bfoster> (raw)
In-Reply-To: <152107380082.19571.10988218532838802248.stgit@magnolia>
On Wed, Mar 14, 2018 at 05:30:00PM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
>
> When we're scanning an extent mapping inode fork, ensure that every rmap
> record for this ifork has a corresponding bmbt record too. This
> (mostly) provides the ability to cross-reference rmap records with bmap
> data. The rmap scrubber cannot do the xref on its own because that
> requires taking an ilock with the agf lock held, which violates our
> locking order rules (inode, then agf).
>
> Note that we only do this for forks that are in btree format due to the
> increased complexity; or forks that should have data but suspiciously
> have zero extents because the inode could have just had its iforks
> zapped by the inode repair code and now we need to reclaim the old
> extents.
>
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---
> fs/xfs/scrub/bmap.c | 164 +++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 163 insertions(+), 1 deletion(-)
>
>
> diff --git a/fs/xfs/scrub/bmap.c b/fs/xfs/scrub/bmap.c
> index d002821..2f38add 100644
> --- a/fs/xfs/scrub/bmap.c
> +++ b/fs/xfs/scrub/bmap.c
> @@ -37,6 +37,7 @@
> #include "xfs_bmap_util.h"
> #include "xfs_bmap_btree.h"
> #include "xfs_rmap.h"
> +#include "xfs_rmap_btree.h"
> #include "xfs_refcount.h"
> #include "scrub/xfs_scrub.h"
> #include "scrub/scrub.h"
> @@ -423,6 +424,163 @@ xfs_scrub_bmap_btree(
> return error;
> }
>
> +struct xfs_scrub_bmap_check_rmap_info {
> + struct xfs_scrub_context *sc;
> + int whichfork;
> + struct xfs_iext_cursor icur;
> +};
> +
> +/* Can we find bmaps that fit this rmap? */
> +STATIC int
> +xfs_scrub_bmap_check_rmap(
> + struct xfs_btree_cur *cur,
> + struct xfs_rmap_irec *rec,
> + void *priv)
> +{
> + struct xfs_bmbt_irec irec;
> + struct xfs_scrub_bmap_check_rmap_info *sbcri = priv;
> + struct xfs_ifork *ifp;
> + struct xfs_scrub_context *sc = sbcri->sc;
> + bool have_map;
> +
> + /* Is this even the right fork? */
> + if (rec->rm_owner != sc->ip->i_ino)
> + return 0;
> + if ((sbcri->whichfork == XFS_ATTR_FORK) ^
> + !!(rec->rm_flags & XFS_RMAP_ATTR_FORK))
> + return 0;
> + if (rec->rm_flags & XFS_RMAP_BMBT_BLOCK)
> + return 0;
> +
> + /* Now look up the bmbt record. */
> + ifp = XFS_IFORK_PTR(sc->ip, sbcri->whichfork);
> + if (!ifp) {
> + xfs_scrub_fblock_set_corrupt(sc, sbcri->whichfork,
> + rec->rm_offset);
> + goto out;
> + }
> + have_map = xfs_iext_lookup_extent(sc->ip, ifp, rec->rm_offset,
> + &sbcri->icur, &irec);
> + if (!have_map)
> + xfs_scrub_fblock_set_corrupt(sc, sbcri->whichfork,
> + rec->rm_offset);
> +
Comment on why/how an rmap record covers multiple bmbt records?
> + while (have_map) {
> + if (irec.br_startoff != rec->rm_offset)
> + xfs_scrub_fblock_set_corrupt(sc, sbcri->whichfork,
> + rec->rm_offset);
> + if (irec.br_startblock != XFS_AGB_TO_FSB(sc->mp,
> + cur->bc_private.a.agno, rec->rm_startblock))
> + xfs_scrub_fblock_set_corrupt(sc, sbcri->whichfork,
> + rec->rm_offset);
> + if (irec.br_blockcount > rec->rm_blockcount)
> + xfs_scrub_fblock_set_corrupt(sc, sbcri->whichfork,
> + rec->rm_offset);
> + if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
> + break;
> + rec->rm_startblock += irec.br_blockcount;
> + rec->rm_offset += irec.br_blockcount;
> + rec->rm_blockcount -= irec.br_blockcount;
> + if (rec->rm_blockcount == 0)
> + break;
> + have_map = xfs_iext_next_extent(ifp, &sbcri->icur, &irec);
> + if (!have_map)
> + xfs_scrub_fblock_set_corrupt(sc, sbcri->whichfork,
> + rec->rm_offset);
> + }
> +
> +out:
> + if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
> + return XFS_BTREE_QUERY_RANGE_ABORT;
> + return 0;
> +}
> +
> +/* Make sure each rmap has a corresponding bmbt entry. */
> +STATIC int
> +xfs_scrub_bmap_check_ag_rmaps(
> + struct xfs_scrub_context *sc,
> + int whichfork,
> + xfs_agnumber_t agno)
> +{
> + struct xfs_scrub_bmap_check_rmap_info sbcri;
> + struct xfs_btree_cur *cur;
> + struct xfs_buf *agf;
> + int error;
> +
> + error = xfs_alloc_read_agf(sc->mp, sc->tp, agno, 0, &agf);
> + if (error)
> + return error;
> +
> + cur = xfs_rmapbt_init_cursor(sc->mp, sc->tp, agf, agno);
> + if (!cur) {
> + error = -ENOMEM;
> + goto out_agf;
> + }
> +
> + sbcri.sc = sc;
> + sbcri.whichfork = whichfork;
> + error = xfs_rmap_query_all(cur, xfs_scrub_bmap_check_rmap, &sbcri);
> + if (error == XFS_BTREE_QUERY_RANGE_ABORT)
> + error = 0;
> +
> + xfs_btree_del_cursor(cur, XFS_BTREE_ERROR);
Why is XFS_BTREE_ERROR needed?
Brian
> +out_agf:
> + xfs_trans_brelse(sc->tp, agf);
> + return error;
> +}
> +
> +/* Make sure each rmap has a corresponding bmbt entry. */
> +STATIC int
> +xfs_scrub_bmap_check_rmaps(
> + struct xfs_scrub_context *sc,
> + int whichfork)
> +{
> + loff_t size;
> + xfs_agnumber_t agno;
> + int error;
> +
> + if (!xfs_sb_version_hasrmapbt(&sc->mp->m_sb) ||
> + whichfork == XFS_COW_FORK ||
> + (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT))
> + return 0;
> +
> + /* Don't support realtime rmap checks yet. */
> + if (XFS_IS_REALTIME_INODE(sc->ip) && whichfork == XFS_DATA_FORK)
> + return 0;
> +
> + /*
> + * Only do this for complex maps that are in btree format, or for
> + * situations where we would seem to have a size but zero extents.
> + * The inode repair code can zap broken iforks, which means we have
> + * to flag this bmap as corrupt if there are rmaps that need to be
> + * reattached.
> + */
> + switch (whichfork) {
> + case XFS_DATA_FORK:
> + size = i_size_read(VFS_I(sc->ip));
> + break;
> + case XFS_ATTR_FORK:
> + size = XFS_IFORK_Q(sc->ip);
> + break;
> + default:
> + size = 0;
> + break;
> + }
> + if (XFS_IFORK_FORMAT(sc->ip, whichfork) != XFS_DINODE_FMT_BTREE &&
> + (size == 0 || XFS_IFORK_NEXTENTS(sc->ip, whichfork) > 0))
> + return 0;
> +
> + for (agno = 0; agno < sc->mp->m_sb.sb_agcount; agno++) {
> + error = xfs_scrub_bmap_check_ag_rmaps(sc, whichfork, agno);
> + if (error)
> + return error;
> + if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
> + break;
> + }
> +
> + return 0;
> +}
> +
> /*
> * Scrub an inode fork's block mappings.
> *
> @@ -463,7 +621,7 @@ xfs_scrub_bmap(
> break;
> case XFS_ATTR_FORK:
> if (!ifp)
> - goto out;
> + goto out_check_rmap;
> if (!xfs_sb_version_hasattr(&mp->m_sb) &&
> !xfs_sb_version_hasattr2(&mp->m_sb))
> xfs_scrub_ino_set_corrupt(sc, sc->ip->i_ino, NULL);
> @@ -534,6 +692,10 @@ xfs_scrub_bmap(
> goto out;
> }
>
> +out_check_rmap:
> + error = xfs_scrub_bmap_check_rmaps(sc, whichfork);
> + if (!xfs_scrub_fblock_xref_process_error(sc, whichfork, 0, &error))
> + goto out;
> out:
> return error;
> }
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2018-03-21 17:42 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-15 0:29 [PATCH v2 0/9] xfs-4.17: online scrub fixes Darrick J. Wong
2018-03-15 0:29 ` [PATCH 1/9] xfs: sanity-check the unused space before trying to use it Darrick J. Wong
2018-03-21 13:52 ` Brian Foster
2018-03-21 17:44 ` Darrick J. Wong
2018-03-22 5:59 ` [PATCH v2 " Darrick J. Wong
2018-03-22 14:33 ` Brian Foster
2018-03-22 17:23 ` Darrick J. Wong
2018-03-22 22:04 ` Dave Chinner
2018-03-22 17:53 ` [PATCH v3 " Darrick J. Wong
2018-03-22 22:21 ` [PATCH v4 " Darrick J. Wong
2018-03-23 12:29 ` Brian Foster
2018-03-15 0:29 ` [PATCH 2/9] xfs: refactor bmap record valiation Darrick J. Wong
2018-03-21 13:55 ` Brian Foster
2018-03-21 20:30 ` Darrick J. Wong
2018-03-22 6:01 ` [PATCH v2 " Darrick J. Wong
2018-03-22 14:33 ` Brian Foster
2018-03-15 0:29 ` [PATCH 3/9] xfs: refactor inode verifier error logging Darrick J. Wong
2018-03-21 13:55 ` Brian Foster
2018-03-15 0:29 ` [PATCH 4/9] xfs: refactor inode buffer " Darrick J. Wong
2018-03-21 13:55 ` Brian Foster
2018-03-21 18:03 ` Darrick J. Wong
2018-04-24 19:51 ` Eric Sandeen
2018-03-15 0:30 ` [PATCH 5/9] xfs: bmap scrubber should do rmap xref with bmap for sparse files Darrick J. Wong
2018-03-21 17:42 ` Brian Foster [this message]
2018-03-21 18:11 ` Darrick J. Wong
2018-03-22 6:02 ` [PATCH v2 " Darrick J. Wong
2018-03-22 14:33 ` Brian Foster
2018-03-22 17:35 ` Darrick J. Wong
2018-03-15 0:30 ` [PATCH 6/9] xfs: inode scrubber shouldn't bother with raw checks Darrick J. Wong
2018-03-21 17:42 ` Brian Foster
2018-03-21 20:37 ` Darrick J. Wong
2018-03-15 0:30 ` [PATCH 7/9] xfs: remove xfs_buf parameter from inode scrub methods Darrick J. Wong
2018-03-21 17:42 ` Brian Foster
2018-03-15 0:30 ` [PATCH 8/9] xfs: record inode buf errors as a xref error in inode scrubber Darrick J. Wong
2018-03-21 17:42 ` Brian Foster
2018-03-21 20:50 ` Darrick J. Wong
2018-03-22 14:34 ` Brian Foster
2018-03-22 6:24 ` [PATCH v2 " Darrick J. Wong
2018-03-22 14:34 ` Brian Foster
2018-03-15 0:30 ` [PATCH 9/9] xfs: move inode extent size hint validation to libxfs Darrick J. Wong
2018-03-21 17:42 ` Brian Foster
2018-03-21 3:21 ` [PATCH 10/9] xfs: don't accept inode buffers with suspicious unlinked chains Darrick J. Wong
2018-03-21 17:43 ` Brian Foster
2018-03-21 20:52 ` Darrick J. Wong
2018-03-22 6:08 ` [PATCH v2 " Darrick J. Wong
2018-03-22 14:34 ` Brian Foster
2018-03-21 3:21 ` [PATCH 11/9] xfs: flag inode corruption if parent ptr doesn't get us a real inode Darrick J. Wong
2018-03-22 14:34 ` Brian Foster
2018-03-22 17:49 ` Darrick J. Wong
2018-03-22 17:57 ` [PATCH v2 " Darrick J. Wong
2018-03-23 12:29 ` Brian Foster
2018-03-22 6:19 ` [PATCH 12/9] xfs: xfs_scrub_iallocbt_xref_rmap_inodes should use xref_set_corrupt Darrick J. Wong
2018-03-22 14:34 ` Brian Foster
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=20180321174232.GG11127@bfoster.bfoster \
--to=bfoster@redhat.com \
--cc=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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).