Skip to content

Commit f1121b9

Browse files
dchinnerdgchinner
authored andcommitted
Merge tag 'scrub-detect-inobt-gaps-6.4_2023-04-11' of git://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux into guilt/xfs-for-next
xfs: detect incorrect gaps in inode btree [v24.5] This series continues the corrections for a couple of problems I found in the inode btree scrubber. The first problem is that we don't directly check the inobt records have a direct correspondence with the finobt records, and vice versa. The second problem occurs on filesystems with sparse inode chunks -- the cross-referencing we do detects sparseness, but it doesn't actually check the consistency between the inobt hole records and the rmap data. Signed-off-by: Darrick J. Wong <djwong@kernel.org> Signed-off-by: Dave Chinner <david@fromorbit.com>
2 parents e7cef2f + efc0845 commit f1121b9

3 files changed

Lines changed: 269 additions & 88 deletions

File tree

fs/xfs/libxfs/xfs_ialloc.c

Lines changed: 50 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1978,8 +1978,6 @@ xfs_difree_inobt(
19781978
*/
19791979
if (!xfs_has_ikeep(mp) && rec.ir_free == XFS_INOBT_ALL_FREE &&
19801980
mp->m_sb.sb_inopblock <= XFS_INODES_PER_CHUNK) {
1981-
struct xfs_perag *pag = agbp->b_pag;
1982-
19831981
xic->deleted = true;
19841982
xic->first_ino = XFS_AGINO_TO_INO(mp, pag->pag_agno,
19851983
rec.ir_startino);
@@ -2643,44 +2641,50 @@ xfs_ialloc_read_agi(
26432641
return 0;
26442642
}
26452643

2646-
/* Is there an inode record covering a given range of inode numbers? */
2647-
int
2648-
xfs_ialloc_has_inode_record(
2649-
struct xfs_btree_cur *cur,
2650-
xfs_agino_t low,
2651-
xfs_agino_t high,
2652-
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)
26532651
{
26542652
struct xfs_inobt_rec_incore irec;
2655-
xfs_agino_t agino;
2656-
uint16_t holemask;
2657-
int has_record;
2658-
int i;
2659-
int error;
2653+
unsigned int ret = 0;
2654+
int has_record;
2655+
int error;
26602656

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

2668-
agino = irec.ir_startino;
2669-
holemask = irec.ir_holemask;
2670-
for (i = 0; i < XFS_INOBT_HOLEMASK_BITS; holemask >>= 1,
2671-
i++, agino += XFS_INODES_PER_HOLEMASK_BIT) {
2672-
if (holemask & 1)
2670+
for (i = 0; i < XFS_INODES_PER_CHUNK; i++) {
2671+
if (irec.ir_startino + i < low)
26732672
continue;
2674-
if (agino + XFS_INODES_PER_HOLEMASK_BIT > low &&
2675-
agino <= high) {
2676-
*exists = true;
2677-
return 0;
2678-
}
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++;
26792679
}
26802680

26812681
error = xfs_btree_increment(cur, 0, &has_record);
2682+
if (error)
2683+
return error;
26822684
}
2683-
return error;
2685+
2686+
*allocated = ret;
2687+
return 0;
26842688
}
26852689

26862690
/* Is there an inode record covering a given extent? */
@@ -2689,15 +2693,27 @@ xfs_ialloc_has_inodes_at_extent(
26892693
struct xfs_btree_cur *cur,
26902694
xfs_agblock_t bno,
26912695
xfs_extlen_t len,
2692-
bool *exists)
2696+
enum xbtree_recpacking *outcome)
26932697
{
2694-
xfs_agino_t low;
2695-
xfs_agino_t high;
2698+
xfs_agino_t agino;
2699+
xfs_agino_t last_agino;
2700+
unsigned int allocated;
2701+
int error;
26962702

2697-
low = XFS_AGB_TO_AGINO(cur->bc_mp, bno);
2698-
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;
26992705

2700-
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;
27012717
}
27022718

27032719
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,

0 commit comments

Comments
 (0)