Skip to content

Commit bd27c7b

Browse files
author
Darrick J. Wong
committed
xfs: return a 64-bit block count from xfs_btree_count_blocks
With the nrext64 feature enabled, it's possible for a data fork to have 2^48 extent mappings. Even with a 64k fsblock size, that maps out to a bmbt containing more than 2^32 blocks. Therefore, this predicate must return a u64 count to avoid an integer wraparound that will cause scrub to do the wrong thing. It's unlikely that any such filesystem currently exists, because the incore bmbt would consume more than 64GB of kernel memory on its own, and so far nobody except me has driven a filesystem that far, judging from the lack of complaints. Cc: <[email protected]> # v5.19 Fixes: df9ad5c ("xfs: Introduce macros to represent new maximum extent counts for data/attr forks") Signed-off-by: "Darrick J. Wong" <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]>
1 parent e1d8602 commit bd27c7b

File tree

9 files changed

+17
-15
lines changed

9 files changed

+17
-15
lines changed

fs/xfs/libxfs/xfs_btree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5144,7 +5144,7 @@ xfs_btree_count_blocks_helper(
51445144
int level,
51455145
void *data)
51465146
{
5147-
xfs_extlen_t *blocks = data;
5147+
xfs_filblks_t *blocks = data;
51485148
(*blocks)++;
51495149

51505150
return 0;
@@ -5154,7 +5154,7 @@ xfs_btree_count_blocks_helper(
51545154
int
51555155
xfs_btree_count_blocks(
51565156
struct xfs_btree_cur *cur,
5157-
xfs_extlen_t *blocks)
5157+
xfs_filblks_t *blocks)
51585158
{
51595159
*blocks = 0;
51605160
return xfs_btree_visit_blocks(cur, xfs_btree_count_blocks_helper,

fs/xfs/libxfs/xfs_btree.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ typedef int (*xfs_btree_visit_blocks_fn)(struct xfs_btree_cur *cur, int level,
484484
int xfs_btree_visit_blocks(struct xfs_btree_cur *cur,
485485
xfs_btree_visit_blocks_fn fn, unsigned int flags, void *data);
486486

487-
int xfs_btree_count_blocks(struct xfs_btree_cur *cur, xfs_extlen_t *blocks);
487+
int xfs_btree_count_blocks(struct xfs_btree_cur *cur, xfs_filblks_t *blocks);
488488

489489
union xfs_btree_rec *xfs_btree_rec_addr(struct xfs_btree_cur *cur, int n,
490490
struct xfs_btree_block *block);

fs/xfs/libxfs/xfs_ialloc_btree.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,16 +744,18 @@ xfs_finobt_count_blocks(
744744
{
745745
struct xfs_buf *agbp = NULL;
746746
struct xfs_btree_cur *cur;
747+
xfs_filblks_t blocks;
747748
int error;
748749

749750
error = xfs_ialloc_read_agi(pag, tp, 0, &agbp);
750751
if (error)
751752
return error;
752753

753754
cur = xfs_finobt_init_cursor(pag, tp, agbp);
754-
error = xfs_btree_count_blocks(cur, tree_blocks);
755+
error = xfs_btree_count_blocks(cur, &blocks);
755756
xfs_btree_del_cursor(cur, error);
756757
xfs_trans_brelse(tp, agbp);
758+
*tree_blocks = blocks;
757759

758760
return error;
759761
}

fs/xfs/scrub/agheader.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ xchk_agf_xref_btreeblks(
458458
{
459459
struct xfs_agf *agf = sc->sa.agf_bp->b_addr;
460460
struct xfs_mount *mp = sc->mp;
461-
xfs_agblock_t blocks;
461+
xfs_filblks_t blocks;
462462
xfs_agblock_t btreeblks;
463463
int error;
464464

@@ -507,7 +507,7 @@ xchk_agf_xref_refcblks(
507507
struct xfs_scrub *sc)
508508
{
509509
struct xfs_agf *agf = sc->sa.agf_bp->b_addr;
510-
xfs_agblock_t blocks;
510+
xfs_filblks_t blocks;
511511
int error;
512512

513513
if (!sc->sa.refc_cur)
@@ -840,7 +840,7 @@ xchk_agi_xref_fiblocks(
840840
struct xfs_scrub *sc)
841841
{
842842
struct xfs_agi *agi = sc->sa.agi_bp->b_addr;
843-
xfs_agblock_t blocks;
843+
xfs_filblks_t blocks;
844844
int error = 0;
845845

846846
if (!xfs_has_inobtcounts(sc->mp))

fs/xfs/scrub/agheader_repair.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ xrep_agf_calc_from_btrees(
256256
struct xfs_agf *agf = agf_bp->b_addr;
257257
struct xfs_mount *mp = sc->mp;
258258
xfs_agblock_t btreeblks;
259-
xfs_agblock_t blocks;
259+
xfs_filblks_t blocks;
260260
int error;
261261

262262
/* Update the AGF counters from the bnobt. */
@@ -946,7 +946,7 @@ xrep_agi_calc_from_btrees(
946946
if (error)
947947
goto err;
948948
if (xfs_has_inobtcounts(mp)) {
949-
xfs_agblock_t blocks;
949+
xfs_filblks_t blocks;
950950

951951
error = xfs_btree_count_blocks(cur, &blocks);
952952
if (error)
@@ -959,7 +959,7 @@ xrep_agi_calc_from_btrees(
959959
agi->agi_freecount = cpu_to_be32(freecount);
960960

961961
if (xfs_has_finobt(mp) && xfs_has_inobtcounts(mp)) {
962-
xfs_agblock_t blocks;
962+
xfs_filblks_t blocks;
963963

964964
cur = xfs_finobt_init_cursor(sc->sa.pag, sc->tp, agi_bp);
965965
error = xfs_btree_count_blocks(cur, &blocks);

fs/xfs/scrub/fscounters.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ xchk_fscount_btreeblks(
261261
struct xchk_fscounters *fsc,
262262
xfs_agnumber_t agno)
263263
{
264-
xfs_extlen_t blocks;
264+
xfs_filblks_t blocks;
265265
int error;
266266

267267
error = xchk_ag_init_existing(sc, agno, &sc->sa);

fs/xfs/scrub/ialloc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -650,8 +650,8 @@ xchk_iallocbt_xref_rmap_btreeblks(
650650
struct xfs_scrub *sc)
651651
{
652652
xfs_filblks_t blocks;
653-
xfs_extlen_t inobt_blocks = 0;
654-
xfs_extlen_t finobt_blocks = 0;
653+
xfs_filblks_t inobt_blocks = 0;
654+
xfs_filblks_t finobt_blocks = 0;
655655
int error;
656656

657657
if (!sc->sa.ino_cur || !sc->sa.rmap_cur ||

fs/xfs/scrub/refcount.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ xchk_refcount_xref_rmap(
491491
struct xfs_scrub *sc,
492492
xfs_filblks_t cow_blocks)
493493
{
494-
xfs_extlen_t refcbt_blocks = 0;
494+
xfs_filblks_t refcbt_blocks = 0;
495495
xfs_filblks_t blocks;
496496
int error;
497497

fs/xfs/xfs_bmap_util.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ xfs_bmap_count_blocks(
103103
struct xfs_mount *mp = ip->i_mount;
104104
struct xfs_ifork *ifp = xfs_ifork_ptr(ip, whichfork);
105105
struct xfs_btree_cur *cur;
106-
xfs_extlen_t btblocks = 0;
106+
xfs_filblks_t btblocks = 0;
107107
int error;
108108

109109
*nextents = 0;

0 commit comments

Comments
 (0)