xfs: repair the AGFL
Repair the AGFL from the rmap data. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Reviewed-by: Brian Foster <bfoster@redhat.com>
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include "xfs_format.h"
|
||||
#include "xfs_trans_resv.h"
|
||||
#include "xfs_mount.h"
|
||||
#include "xfs_btree.h"
|
||||
#include "scrub/xfs_scrub.h"
|
||||
#include "scrub/scrub.h"
|
||||
#include "scrub/common.h"
|
||||
@@ -209,3 +210,94 @@ out:
|
||||
}
|
||||
#undef LEFT_ALIGNED
|
||||
#undef RIGHT_ALIGNED
|
||||
|
||||
/*
|
||||
* Record all btree blocks seen while iterating all records of a btree.
|
||||
*
|
||||
* We know that the btree query_all function starts at the left edge and walks
|
||||
* towards the right edge of the tree. Therefore, we know that we can walk up
|
||||
* the btree cursor towards the root; if the pointer for a given level points
|
||||
* to the first record/key in that block, we haven't seen this block before;
|
||||
* and therefore we need to remember that we saw this block in the btree.
|
||||
*
|
||||
* So if our btree is:
|
||||
*
|
||||
* 4
|
||||
* / | \
|
||||
* 1 2 3
|
||||
*
|
||||
* Pretend for this example that each leaf block has 100 btree records. For
|
||||
* the first btree record, we'll observe that bc_ptrs[0] == 1, so we record
|
||||
* that we saw block 1. Then we observe that bc_ptrs[1] == 1, so we record
|
||||
* block 4. The list is [1, 4].
|
||||
*
|
||||
* For the second btree record, we see that bc_ptrs[0] == 2, so we exit the
|
||||
* loop. The list remains [1, 4].
|
||||
*
|
||||
* For the 101st btree record, we've moved onto leaf block 2. Now
|
||||
* bc_ptrs[0] == 1 again, so we record that we saw block 2. We see that
|
||||
* bc_ptrs[1] == 2, so we exit the loop. The list is now [1, 4, 2].
|
||||
*
|
||||
* For the 102nd record, bc_ptrs[0] == 2, so we continue.
|
||||
*
|
||||
* For the 201st record, we've moved on to leaf block 3. bc_ptrs[0] == 1, so
|
||||
* we add 3 to the list. Now it is [1, 4, 2, 3].
|
||||
*
|
||||
* For the 300th record we just exit, with the list being [1, 4, 2, 3].
|
||||
*/
|
||||
|
||||
/*
|
||||
* Record all the buffers pointed to by the btree cursor. Callers already
|
||||
* engaged in a btree walk should call this function to capture the list of
|
||||
* blocks going from the leaf towards the root.
|
||||
*/
|
||||
int
|
||||
xfs_bitmap_set_btcur_path(
|
||||
struct xfs_bitmap *bitmap,
|
||||
struct xfs_btree_cur *cur)
|
||||
{
|
||||
struct xfs_buf *bp;
|
||||
xfs_fsblock_t fsb;
|
||||
int i;
|
||||
int error;
|
||||
|
||||
for (i = 0; i < cur->bc_nlevels && cur->bc_ptrs[i] == 1; i++) {
|
||||
xfs_btree_get_block(cur, i, &bp);
|
||||
if (!bp)
|
||||
continue;
|
||||
fsb = XFS_DADDR_TO_FSB(cur->bc_mp, bp->b_bn);
|
||||
error = xfs_bitmap_set(bitmap, fsb, 1);
|
||||
if (error)
|
||||
return error;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Collect a btree's block in the bitmap. */
|
||||
STATIC int
|
||||
xfs_bitmap_collect_btblock(
|
||||
struct xfs_btree_cur *cur,
|
||||
int level,
|
||||
void *priv)
|
||||
{
|
||||
struct xfs_bitmap *bitmap = priv;
|
||||
struct xfs_buf *bp;
|
||||
xfs_fsblock_t fsbno;
|
||||
|
||||
xfs_btree_get_block(cur, level, &bp);
|
||||
if (!bp)
|
||||
return 0;
|
||||
|
||||
fsbno = XFS_DADDR_TO_FSB(cur->bc_mp, bp->b_bn);
|
||||
return xfs_bitmap_set(bitmap, fsbno, 1);
|
||||
}
|
||||
|
||||
/* Walk the btree and mark the bitmap wherever a btree block is found. */
|
||||
int
|
||||
xfs_bitmap_set_btblocks(
|
||||
struct xfs_bitmap *bitmap,
|
||||
struct xfs_btree_cur *cur)
|
||||
{
|
||||
return xfs_btree_visit_blocks(cur, xfs_bitmap_collect_btblock, bitmap);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user