On Mon, Jun 01, 2020 at 09:27:51PM -0700, Darrick J. Wong wrote: > From: Darrick J. Wong <darrick.wong@xxxxxxxxxx> > > Use the btree bulk loading functions to rebuild the reverse mapping > btrees and drop the open-coded implementation. > > Signed-off-by: Darrick J. Wong <darrick.wong@xxxxxxxxxx> > --- > libxfs/libxfs_api_defs.h | 1 > repair/agbtree.c | 70 ++++++++ > repair/agbtree.h | 5 + > repair/phase5.c | 409 ++-------------------------------------------- > 4 files changed, 96 insertions(+), 389 deletions(-) > > ... > diff --git a/repair/phase5.c b/repair/phase5.c > index e570349d..1c6448f4 100644 > --- a/repair/phase5.c > +++ b/repair/phase5.c ... > @@ -1244,6 +879,8 @@ build_agf_agfl( > freelist = xfs_buf_to_agfl_bno(agfl_buf); > fill_agfl(btr_bno, freelist, &agfl_idx); > fill_agfl(btr_cnt, freelist, &agfl_idx); > + if (xfs_sb_version_hasrmapbt(&mp->m_sb)) > + fill_agfl(btr_rmap, freelist, &agfl_idx); Is this new behavior? Either way, I guess it makes sense since the rmapbt feeds from/to the agfl: Reviewed-by: Brian Foster <bfoster@xxxxxxxxxx> > > /* Set the AGF counters for the AGFL. */ > if (agfl_idx > 0) { > @@ -1343,7 +980,7 @@ phase5_func( > struct bt_rebuild btr_cnt; > struct bt_rebuild btr_ino; > struct bt_rebuild btr_fino; > - bt_status_t rmap_btree_curs; > + struct bt_rebuild btr_rmap; > bt_status_t refcnt_btree_curs; > int extra_blocks = 0; > uint num_freeblocks; > @@ -1378,11 +1015,7 @@ _("unable to rebuild AG %u. Not enough free space in on-disk AG.\n"), > init_ino_cursors(&sc, agno, num_freeblocks, &sb_icount_ag[agno], > &sb_ifree_ag[agno], &btr_ino, &btr_fino); > > - /* > - * Set up the btree cursors for the on-disk rmap btrees, which includes > - * pre-allocating all required blocks. > - */ > - init_rmapbt_cursor(mp, agno, &rmap_btree_curs); > + init_rmapbt_cursor(&sc, agno, num_freeblocks, &btr_rmap); > > /* > * Set up the btree cursors for the on-disk refcount btrees, > @@ -1448,10 +1081,8 @@ _("unable to rebuild AG %u. Not enough free space in on-disk AG.\n"), > ASSERT(btr_bno.freeblks == btr_cnt.freeblks); > > if (xfs_sb_version_hasrmapbt(&mp->m_sb)) { > - build_rmap_tree(mp, agno, &rmap_btree_curs); > - write_cursor(&rmap_btree_curs); > - sb_fdblocks_ag[agno] += (rmap_btree_curs.num_tot_blocks - > - rmap_btree_curs.num_free_blocks) - 1; > + build_rmap_tree(&sc, agno, &btr_rmap); > + sb_fdblocks_ag[agno] += btr_rmap.newbt.afake.af_blocks - 1; > } > > if (xfs_sb_version_hasreflink(&mp->m_sb)) { > @@ -1462,7 +1093,7 @@ _("unable to rebuild AG %u. Not enough free space in on-disk AG.\n"), > /* > * set up agf and agfl > */ > - build_agf_agfl(mp, agno, &btr_bno, &btr_cnt, &rmap_btree_curs, > + build_agf_agfl(mp, agno, &btr_bno, &btr_cnt, &btr_rmap, > &refcnt_btree_curs, lost_fsb); > > build_inode_btrees(&sc, agno, &btr_ino, &btr_fino); > @@ -1479,7 +1110,7 @@ _("unable to rebuild AG %u. Not enough free space in on-disk AG.\n"), > if (xfs_sb_version_hasfinobt(&mp->m_sb)) > finish_rebuild(mp, &btr_fino, lost_fsb); > if (xfs_sb_version_hasrmapbt(&mp->m_sb)) > - finish_cursor(&rmap_btree_curs); > + finish_rebuild(mp, &btr_rmap, lost_fsb); > if (xfs_sb_version_hasreflink(&mp->m_sb)) > finish_cursor(&refcnt_btree_curs); > >