From: Bill O'Donnell <billodo@redhat.com>
To: "Darrick J. Wong" <darrick.wong@oracle.com>
Cc: sandeen@sandeen.net, linux-xfs@vger.kernel.org
Subject: Re: [PATCH 03/10] xfs_repair: correctly account for free space btree shrinks when fixing freelist
Date: Mon, 22 Apr 2019 14:36:07 -0500 [thread overview]
Message-ID: <20190422193607.GB29660@redhat.com> (raw)
In-Reply-To: <155594790894.115924.5483344448490636960.stgit@magnolia>
On Mon, Apr 22, 2019 at 08:45:09AM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
>
> When we fix the freelist at the end of build_agf_agfl in phase 5 of
> repair, we need to create incore rmap records for the blocks that get
> added to the AGFL. We can't let the regular freelist fixing code use
> the regular on-disk rmapbt update code because the rmapbt isn't fully
> set up yet.
>
> Unfortunately, the original code fails to account for the fact that the
> free space btrees can shrink when we allocate blocks to fix the
> freelist; those blocks are also put on the freelist, but there are
> already incore rmaps for all the free space btree blocks. We must not
> create (redundant) incore rmaps for those blocks. If we do, repair
> fails with a complaint that rebuilding the rmapbt failed during phase 5.
> xfs/137 on a 1k block size occasionally triggers this bug.
>
> To fix the problem, construct a bitmap of all OWN_AG blocks that we know
> about before traversing the AGFL, and only create new incore rmaps for
> those AGFL blocks that are not already tracked in the bitmap.
>
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
looks good to me.
Reviewed-by: Bill O'Donnell <billodo@redhat.com>
> ---
> repair/rmap.c | 54 ++++++++++++++++++++++++++++++++++++++++++++----------
> 1 file changed, 44 insertions(+), 10 deletions(-)
>
>
> diff --git a/repair/rmap.c b/repair/rmap.c
> index d0156f9d..19cceca3 100644
> --- a/repair/rmap.c
> +++ b/repair/rmap.c
> @@ -12,6 +12,7 @@
> #include "dinode.h"
> #include "slab.h"
> #include "rmap.h"
> +#include "bitmap.h"
>
> #undef RMAP_DEBUG
>
> @@ -450,15 +451,16 @@ rmap_store_ag_btree_rec(
> struct xfs_buf *agflbp = NULL;
> struct xfs_trans *tp;
> __be32 *agfl_bno, *b;
> + struct xfs_ag_rmap *ag_rmap = &ag_rmaps[agno];
> + struct bitmap *own_ag_bitmap = NULL;
> int error = 0;
>
> if (!xfs_sb_version_hasrmapbt(&mp->m_sb))
> return 0;
>
> /* Release the ar_rmaps; they were put into the rmapbt during p5. */
> - free_slab(&ag_rmaps[agno].ar_rmaps);
> - error = init_slab(&ag_rmaps[agno].ar_rmaps,
> - sizeof(struct xfs_rmap_irec));
> + free_slab(&ag_rmap->ar_rmaps);
> + error = init_slab(&ag_rmap->ar_rmaps, sizeof(struct xfs_rmap_irec));
> if (error)
> goto err;
>
> @@ -478,19 +480,50 @@ rmap_store_ag_btree_rec(
> * rmap, we only need to add rmap records for AGFL blocks past
> * that point in the AGFL because those blocks are a result of a
> * no-rmap no-shrink freelist fixup that we did earlier.
> + *
> + * However, some blocks end up on the AGFL because the free space
> + * btrees shed blocks as a result of allocating space to fix the
> + * freelist. We already created in-core rmap records for the free
> + * space btree blocks, so we must be careful not to create those
> + * records again. Create a bitmap of already-recorded OWN_AG rmaps.
> */
> + error = init_slab_cursor(ag_rmap->ar_raw_rmaps, rmap_compare, &rm_cur);
> + if (error)
> + goto err;
> + if (!bitmap_init(&own_ag_bitmap)) {
> + error = -ENOMEM;
> + goto err_slab;
> + }
> + while ((rm_rec = pop_slab_cursor(rm_cur)) != NULL) {
> + if (rm_rec->rm_owner != XFS_RMAP_OWN_AG)
> + continue;
> + if (!bitmap_set(own_ag_bitmap, rm_rec->rm_startblock,
> + rm_rec->rm_blockcount)) {
> + error = EFSCORRUPTED;
> + goto err_slab;
> + }
> + }
> + free_slab_cursor(&rm_cur);
> +
> + /* Create rmaps for any AGFL blocks that aren't already rmapped. */
> agfl_bno = XFS_BUF_TO_AGFL_BNO(mp, agflbp);
> - b = agfl_bno + ag_rmaps[agno].ar_flcount;
> + b = agfl_bno + ag_rmap->ar_flcount;
> while (*b != cpu_to_be32(NULLAGBLOCK) &&
> b - agfl_bno < libxfs_agfl_size(mp)) {
> - error = rmap_add_ag_rec(mp, agno, be32_to_cpu(*b), 1,
> - XFS_RMAP_OWN_AG);
> - if (error)
> - goto err;
> + xfs_agblock_t agbno;
> +
> + agbno = be32_to_cpu(*b);
> + if (!bitmap_test(own_ag_bitmap, agbno, 1)) {
> + error = rmap_add_ag_rec(mp, agno, agbno, 1,
> + XFS_RMAP_OWN_AG);
> + if (error)
> + goto err;
> + }
> b++;
> }
> libxfs_putbuf(agflbp);
> agflbp = NULL;
> + bitmap_free(&own_ag_bitmap);
>
> /* Merge all the raw rmaps into the main list */
> error = rmap_fold_raw_recs(mp, agno);
> @@ -498,8 +531,7 @@ rmap_store_ag_btree_rec(
> goto err;
>
> /* Create cursors to refcount structures */
> - error = init_slab_cursor(ag_rmaps[agno].ar_rmaps, rmap_compare,
> - &rm_cur);
> + error = init_slab_cursor(ag_rmap->ar_rmaps, rmap_compare, &rm_cur);
> if (error)
> goto err;
>
> @@ -542,6 +574,8 @@ rmap_store_ag_btree_rec(
> err:
> if (agflbp)
> libxfs_putbuf(agflbp);
> + if (own_ag_bitmap)
> + bitmap_free(&own_ag_bitmap);
> return error;
> }
>
>
next prev parent reply other threads:[~2019-04-22 19:36 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-22 15:44 [PATCH v3 00/10] xfsprogs-5.0: fix various problems Darrick J. Wong
2019-04-22 15:44 ` [PATCH 01/10] scrub: fix Makefile targets which depend on builddefs Darrick J. Wong
2019-04-22 18:27 ` Eric Sandeen
2019-04-22 18:28 ` Bill O'Donnell
2019-04-22 15:45 ` [PATCH 02/10] xfs_info: use findmnt to handle mounted block devices Darrick J. Wong
2019-04-22 18:35 ` Eric Sandeen
2019-04-22 19:27 ` Bill O'Donnell
2019-04-22 15:45 ` [PATCH 03/10] xfs_repair: correctly account for free space btree shrinks when fixing freelist Darrick J. Wong
2019-04-22 19:24 ` Eric Sandeen
2019-04-22 19:36 ` Bill O'Donnell [this message]
2019-04-22 15:45 ` [PATCH 04/10] libxfs: retain ifork_ops when flushing inode Darrick J. Wong
2019-04-22 19:40 ` Bill O'Donnell
2019-04-22 19:45 ` Eric Sandeen
2019-10-02 6:00 ` Arkadiusz Miśkiewicz
2019-04-22 15:45 ` [PATCH 05/10] libxfs: drop the ifork_ops parameter from _inode_verify_forks Darrick J. Wong
2019-04-22 19:43 ` Bill O'Donnell
2019-04-22 20:49 ` Eric Sandeen
2019-04-22 15:45 ` [PATCH 06/10] misc: fix strncpy length complaints Darrick J. Wong
2019-04-22 20:48 ` Eric Sandeen
2019-04-22 20:57 ` Darrick J. Wong
2019-04-22 21:04 ` Eric Sandeen
2019-04-22 21:07 ` Eric Sandeen
2019-04-23 15:07 ` Bill O'Donnell
2019-04-22 15:45 ` [PATCH 07/10] libxfs: refactor buffer item release code Darrick J. Wong
2019-04-22 21:26 ` Eric Sandeen
2019-04-22 21:35 ` Darrick J. Wong
2019-04-22 21:40 ` Eric Sandeen
2019-04-23 20:51 ` [PATCH v2 " Darrick J. Wong
2019-04-23 20:56 ` Bill O'Donnell
2019-04-22 15:45 ` [PATCH 08/10] libxfs: don't touch buffer log item pointer when flushing inode log item Darrick J. Wong
2019-04-23 17:56 ` Eric Sandeen
2019-04-23 20:52 ` Bill O'Donnell
2019-04-22 15:45 ` [PATCH 09/10] libxfs: fix buffer log item lifetime weirdness Darrick J. Wong
2019-04-23 21:15 ` Bill O'Donnell
2019-04-22 15:45 ` [PATCH 10/10] libxfs: shorten inode item lifetime Darrick J. Wong
2019-04-23 21:22 ` Bill O'Donnell
2019-04-23 21:04 ` [PATCH 11/10] libfrog: fix memory leak in bitmap_free Darrick J. Wong
2019-04-23 21:23 ` Bill O'Donnell
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=20190422193607.GB29660@redhat.com \
--to=billodo@redhat.com \
--cc=darrick.wong@oracle.com \
--cc=linux-xfs@vger.kernel.org \
--cc=sandeen@sandeen.net \
/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).