Commit efc0845f authored by Darrick J. Wong's avatar Darrick J. Wong

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: default avatarDarrick J. Wong <djwong@kernel.org>
Reviewed-by: default avatarDave Chinner <dchinner@redhat.com>
parent bc0f3b55
...@@ -2641,44 +2641,50 @@ xfs_ialloc_read_agi( ...@@ -2641,44 +2641,50 @@ xfs_ialloc_read_agi(
return 0; return 0;
} }
/* Is there an inode record covering a given range of inode numbers? */ /* How many inodes are backed by inode clusters ondisk? */
int STATIC int
xfs_ialloc_has_inode_record( xfs_ialloc_count_ondisk(
struct xfs_btree_cur *cur, struct xfs_btree_cur *cur,
xfs_agino_t low, xfs_agino_t low,
xfs_agino_t high, xfs_agino_t high,
bool *exists) unsigned int *allocated)
{ {
struct xfs_inobt_rec_incore irec; struct xfs_inobt_rec_incore irec;
xfs_agino_t agino; unsigned int ret = 0;
uint16_t holemask;
int has_record; int has_record;
int i;
int error; int error;
*exists = false;
error = xfs_inobt_lookup(cur, low, XFS_LOOKUP_LE, &has_record); error = xfs_inobt_lookup(cur, low, XFS_LOOKUP_LE, &has_record);
while (error == 0 && has_record) { if (error)
return error;
while (has_record) {
unsigned int i, hole_idx;
error = xfs_inobt_get_rec(cur, &irec, &has_record); error = xfs_inobt_get_rec(cur, &irec, &has_record);
if (error || irec.ir_startino > high) if (error)
return error;
if (irec.ir_startino > high)
break; break;
agino = irec.ir_startino; for (i = 0; i < XFS_INODES_PER_CHUNK; i++) {
holemask = irec.ir_holemask; if (irec.ir_startino + i < low)
for (i = 0; i < XFS_INOBT_HOLEMASK_BITS; holemask >>= 1,
i++, agino += XFS_INODES_PER_HOLEMASK_BIT) {
if (holemask & 1)
continue; continue;
if (agino + XFS_INODES_PER_HOLEMASK_BIT > low && if (irec.ir_startino + i > high)
agino <= high) { break;
*exists = true;
return 0; hole_idx = i / XFS_INODES_PER_HOLEMASK_BIT;
} if (!(irec.ir_holemask & (1U << hole_idx)))
ret++;
} }
error = xfs_btree_increment(cur, 0, &has_record); error = xfs_btree_increment(cur, 0, &has_record);
} if (error)
return error; return error;
}
*allocated = ret;
return 0;
} }
/* Is there an inode record covering a given extent? */ /* Is there an inode record covering a given extent? */
...@@ -2687,15 +2693,27 @@ xfs_ialloc_has_inodes_at_extent( ...@@ -2687,15 +2693,27 @@ xfs_ialloc_has_inodes_at_extent(
struct xfs_btree_cur *cur, struct xfs_btree_cur *cur,
xfs_agblock_t bno, xfs_agblock_t bno,
xfs_extlen_t len, xfs_extlen_t len,
bool *exists) enum xbtree_recpacking *outcome)
{ {
xfs_agino_t low; xfs_agino_t agino;
xfs_agino_t high; xfs_agino_t last_agino;
unsigned int allocated;
int error;
agino = XFS_AGB_TO_AGINO(cur->bc_mp, bno);
last_agino = XFS_AGB_TO_AGINO(cur->bc_mp, bno + len) - 1;
low = XFS_AGB_TO_AGINO(cur->bc_mp, bno); error = xfs_ialloc_count_ondisk(cur, agino, last_agino, &allocated);
high = XFS_AGB_TO_AGINO(cur->bc_mp, bno + len) - 1; if (error)
return error;
return xfs_ialloc_has_inode_record(cur, low, high, exists); if (allocated == 0)
*outcome = XBTREE_RECPACKING_EMPTY;
else if (allocated == last_agino - agino + 1)
*outcome = XBTREE_RECPACKING_FULL;
else
*outcome = XBTREE_RECPACKING_SPARSE;
return 0;
} }
struct xfs_ialloc_count_inodes { struct xfs_ialloc_count_inodes {
......
...@@ -96,9 +96,8 @@ void xfs_inobt_btrec_to_irec(struct xfs_mount *mp, ...@@ -96,9 +96,8 @@ void xfs_inobt_btrec_to_irec(struct xfs_mount *mp,
xfs_failaddr_t xfs_inobt_check_irec(struct xfs_btree_cur *cur, xfs_failaddr_t xfs_inobt_check_irec(struct xfs_btree_cur *cur,
const struct xfs_inobt_rec_incore *irec); const struct xfs_inobt_rec_incore *irec);
int xfs_ialloc_has_inodes_at_extent(struct xfs_btree_cur *cur, int xfs_ialloc_has_inodes_at_extent(struct xfs_btree_cur *cur,
xfs_agblock_t bno, xfs_extlen_t len, bool *exists); xfs_agblock_t bno, xfs_extlen_t len,
int xfs_ialloc_has_inode_record(struct xfs_btree_cur *cur, xfs_agino_t low, enum xbtree_recpacking *outcome);
xfs_agino_t high, bool *exists);
int xfs_ialloc_count_inodes(struct xfs_btree_cur *cur, xfs_agino_t *count, int xfs_ialloc_count_inodes(struct xfs_btree_cur *cur, xfs_agino_t *count,
xfs_agino_t *freecount); xfs_agino_t *freecount);
int xfs_inobt_insert_rec(struct xfs_btree_cur *cur, uint16_t holemask, int xfs_inobt_insert_rec(struct xfs_btree_cur *cur, uint16_t holemask,
......
...@@ -765,18 +765,18 @@ xchk_xref_inode_check( ...@@ -765,18 +765,18 @@ xchk_xref_inode_check(
xfs_agblock_t agbno, xfs_agblock_t agbno,
xfs_extlen_t len, xfs_extlen_t len,
struct xfs_btree_cur **icur, struct xfs_btree_cur **icur,
bool should_have_inodes) enum xbtree_recpacking expected)
{ {
bool has_inodes; enum xbtree_recpacking outcome;
int error; int error;
if (!(*icur) || xchk_skip_xref(sc->sm)) if (!(*icur) || xchk_skip_xref(sc->sm))
return; return;
error = xfs_ialloc_has_inodes_at_extent(*icur, agbno, len, &has_inodes); error = xfs_ialloc_has_inodes_at_extent(*icur, agbno, len, &outcome);
if (!xchk_should_check_xref(sc, &error, icur)) if (!xchk_should_check_xref(sc, &error, icur))
return; return;
if (has_inodes != should_have_inodes) if (outcome != expected)
xchk_btree_xref_set_corrupt(sc, *icur, 0); xchk_btree_xref_set_corrupt(sc, *icur, 0);
} }
...@@ -787,8 +787,10 @@ xchk_xref_is_not_inode_chunk( ...@@ -787,8 +787,10 @@ xchk_xref_is_not_inode_chunk(
xfs_agblock_t agbno, xfs_agblock_t agbno,
xfs_extlen_t len) xfs_extlen_t len)
{ {
xchk_xref_inode_check(sc, agbno, len, &sc->sa.ino_cur, false); xchk_xref_inode_check(sc, agbno, len, &sc->sa.ino_cur,
xchk_xref_inode_check(sc, agbno, len, &sc->sa.fino_cur, false); XBTREE_RECPACKING_EMPTY);
xchk_xref_inode_check(sc, agbno, len, &sc->sa.fino_cur,
XBTREE_RECPACKING_EMPTY);
} }
/* xref check that the extent is covered by inodes */ /* xref check that the extent is covered by inodes */
...@@ -798,5 +800,6 @@ xchk_xref_is_inode_chunk( ...@@ -798,5 +800,6 @@ xchk_xref_is_inode_chunk(
xfs_agblock_t agbno, xfs_agblock_t agbno,
xfs_extlen_t len) xfs_extlen_t len)
{ {
xchk_xref_inode_check(sc, agbno, len, &sc->sa.ino_cur, true); xchk_xref_inode_check(sc, agbno, len, &sc->sa.ino_cur,
XBTREE_RECPACKING_FULL);
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment