Skip to content

Commit efc0845

Browse files
author
Darrick J. Wong
committed
xfs: convert xfs_ialloc_has_inodes_at_extent to return keyfill scan results
Convert the xfs_ialloc_has_inodes_at_extent function to return keyfill scan results because for a given range of inode numbers, we might have no indexed inodes at all; the entire region might be allocated ondisk inodes; or there might be a mix of the two. Unfortunately, sparse inodes adds to the complexity, because each inode record can have holes, which means that we cannot use the generic btree _scan_keyfill function because we must look for holes in individual records to decide the result. On the plus side, online fsck can now detect sub-chunk discrepancies in the inobt. Signed-off-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Dave Chinner <dchinner@redhat.com>
1 parent bc0f3b5 commit efc0845

3 files changed

Lines changed: 62 additions & 42 deletions

File tree

fs/xfs/libxfs/xfs_ialloc.c

Lines changed: 50 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2641,44 +2641,50 @@ xfs_ialloc_read_agi(
26412641
return 0;
26422642
}
26432643

2644-
/* Is there an inode record covering a given range of inode numbers? */
2645-
int
2646-
xfs_ialloc_has_inode_record(
2647-
struct xfs_btree_cur *cur,
2648-
xfs_agino_t low,
2649-
xfs_agino_t high,
2650-
bool *exists)
2644+
/* How many inodes are backed by inode clusters ondisk? */
2645+
STATIC int
2646+
xfs_ialloc_count_ondisk(
2647+
struct xfs_btree_cur *cur,
2648+
xfs_agino_t low,
2649+
xfs_agino_t high,
2650+
unsigned int *allocated)
26512651
{
26522652
struct xfs_inobt_rec_incore irec;
2653-
xfs_agino_t agino;
2654-
uint16_t holemask;
2655-
int has_record;
2656-
int i;
2657-
int error;
2653+
unsigned int ret = 0;
2654+
int has_record;
2655+
int error;
26582656

2659-
*exists = false;
26602657
error = xfs_inobt_lookup(cur, low, XFS_LOOKUP_LE, &has_record);
2661-
while (error == 0 && has_record) {
2658+
if (error)
2659+
return error;
2660+
2661+
while (has_record) {
2662+
unsigned int i, hole_idx;
2663+
26622664
error = xfs_inobt_get_rec(cur, &irec, &has_record);
2663-
if (error || irec.ir_startino > high)
2665+
if (error)
2666+
return error;
2667+
if (irec.ir_startino > high)
26642668
break;
26652669

2666-
agino = irec.ir_startino;
2667-
holemask = irec.ir_holemask;
2668-
for (i = 0; i < XFS_INOBT_HOLEMASK_BITS; holemask >>= 1,
2669-
i++, agino += XFS_INODES_PER_HOLEMASK_BIT) {
2670-
if (holemask & 1)
2670+
for (i = 0; i < XFS_INODES_PER_CHUNK; i++) {
2671+
if (irec.ir_startino + i < low)
26712672
continue;
2672-
if (agino + XFS_INODES_PER_HOLEMASK_BIT > low &&
2673-
agino <= high) {
2674-
*exists = true;
2675-
return 0;
2676-
}
2673+
if (irec.ir_startino + i > high)
2674+
break;
2675+
2676+
hole_idx = i / XFS_INODES_PER_HOLEMASK_BIT;
2677+
if (!(irec.ir_holemask & (1U << hole_idx)))
2678+
ret++;
26772679
}
26782680

26792681
error = xfs_btree_increment(cur, 0, &has_record);
2682+
if (error)
2683+
return error;
26802684
}
2681-
return error;
2685+
2686+
*allocated = ret;
2687+
return 0;
26822688
}
26832689

26842690
/* Is there an inode record covering a given extent? */
@@ -2687,15 +2693,27 @@ xfs_ialloc_has_inodes_at_extent(
26872693
struct xfs_btree_cur *cur,
26882694
xfs_agblock_t bno,
26892695
xfs_extlen_t len,
2690-
bool *exists)
2696+
enum xbtree_recpacking *outcome)
26912697
{
2692-
xfs_agino_t low;
2693-
xfs_agino_t high;
2698+
xfs_agino_t agino;
2699+
xfs_agino_t last_agino;
2700+
unsigned int allocated;
2701+
int error;
26942702

2695-
low = XFS_AGB_TO_AGINO(cur->bc_mp, bno);
2696-
high = XFS_AGB_TO_AGINO(cur->bc_mp, bno + len) - 1;
2703+
agino = XFS_AGB_TO_AGINO(cur->bc_mp, bno);
2704+
last_agino = XFS_AGB_TO_AGINO(cur->bc_mp, bno + len) - 1;
26972705

2698-
return xfs_ialloc_has_inode_record(cur, low, high, exists);
2706+
error = xfs_ialloc_count_ondisk(cur, agino, last_agino, &allocated);
2707+
if (error)
2708+
return error;
2709+
2710+
if (allocated == 0)
2711+
*outcome = XBTREE_RECPACKING_EMPTY;
2712+
else if (allocated == last_agino - agino + 1)
2713+
*outcome = XBTREE_RECPACKING_FULL;
2714+
else
2715+
*outcome = XBTREE_RECPACKING_SPARSE;
2716+
return 0;
26992717
}
27002718

27012719
struct xfs_ialloc_count_inodes {

fs/xfs/libxfs/xfs_ialloc.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,8 @@ void xfs_inobt_btrec_to_irec(struct xfs_mount *mp,
9696
xfs_failaddr_t xfs_inobt_check_irec(struct xfs_btree_cur *cur,
9797
const struct xfs_inobt_rec_incore *irec);
9898
int xfs_ialloc_has_inodes_at_extent(struct xfs_btree_cur *cur,
99-
xfs_agblock_t bno, xfs_extlen_t len, bool *exists);
100-
int xfs_ialloc_has_inode_record(struct xfs_btree_cur *cur, xfs_agino_t low,
101-
xfs_agino_t high, bool *exists);
99+
xfs_agblock_t bno, xfs_extlen_t len,
100+
enum xbtree_recpacking *outcome);
102101
int xfs_ialloc_count_inodes(struct xfs_btree_cur *cur, xfs_agino_t *count,
103102
xfs_agino_t *freecount);
104103
int xfs_inobt_insert_rec(struct xfs_btree_cur *cur, uint16_t holemask,

fs/xfs/scrub/ialloc.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -765,18 +765,18 @@ xchk_xref_inode_check(
765765
xfs_agblock_t agbno,
766766
xfs_extlen_t len,
767767
struct xfs_btree_cur **icur,
768-
bool should_have_inodes)
768+
enum xbtree_recpacking expected)
769769
{
770-
bool has_inodes;
770+
enum xbtree_recpacking outcome;
771771
int error;
772772

773773
if (!(*icur) || xchk_skip_xref(sc->sm))
774774
return;
775775

776-
error = xfs_ialloc_has_inodes_at_extent(*icur, agbno, len, &has_inodes);
776+
error = xfs_ialloc_has_inodes_at_extent(*icur, agbno, len, &outcome);
777777
if (!xchk_should_check_xref(sc, &error, icur))
778778
return;
779-
if (has_inodes != should_have_inodes)
779+
if (outcome != expected)
780780
xchk_btree_xref_set_corrupt(sc, *icur, 0);
781781
}
782782

@@ -787,8 +787,10 @@ xchk_xref_is_not_inode_chunk(
787787
xfs_agblock_t agbno,
788788
xfs_extlen_t len)
789789
{
790-
xchk_xref_inode_check(sc, agbno, len, &sc->sa.ino_cur, false);
791-
xchk_xref_inode_check(sc, agbno, len, &sc->sa.fino_cur, false);
790+
xchk_xref_inode_check(sc, agbno, len, &sc->sa.ino_cur,
791+
XBTREE_RECPACKING_EMPTY);
792+
xchk_xref_inode_check(sc, agbno, len, &sc->sa.fino_cur,
793+
XBTREE_RECPACKING_EMPTY);
792794
}
793795

794796
/* xref check that the extent is covered by inodes */
@@ -798,5 +800,6 @@ xchk_xref_is_inode_chunk(
798800
xfs_agblock_t agbno,
799801
xfs_extlen_t len)
800802
{
801-
xchk_xref_inode_check(sc, agbno, len, &sc->sa.ino_cur, true);
803+
xchk_xref_inode_check(sc, agbno, len, &sc->sa.ino_cur,
804+
XBTREE_RECPACKING_FULL);
802805
}

0 commit comments

Comments
 (0)