Skip to content

Commit 37e4da5

Browse files
Darrick J. Wongmehmetb0
authored andcommitted
xfs: return a 64-bit block count from xfs_btree_count_blocks
BugLink: https://bugs.launchpad.net/bugs/2102181 commit bd27c7b upstream. 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]> Signed-off-by: Greg Kroah-Hartman <[email protected]> [koichiroden: applied a hunk for xfs_finobt_count_blocks() onto xfs_inobt_count_blocks(), with context adjustments due to missing commits: 4bfb028 ("xfs: remove the btnum argument to xfs_inobt_count_blocks") 3038fd8 ("xfs: remove xfs_inobt_cur")] Signed-off-by: Koichiro Den <[email protected]> Signed-off-by: Mehmet Basaran <[email protected]>
1 parent 977d7e5 commit 37e4da5

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
@@ -5013,7 +5013,7 @@ xfs_btree_count_blocks_helper(
50135013
int level,
50145014
void *data)
50155015
{
5016-
xfs_extlen_t *blocks = data;
5016+
xfs_filblks_t *blocks = data;
50175017
(*blocks)++;
50185018

50195019
return 0;
@@ -5023,7 +5023,7 @@ xfs_btree_count_blocks_helper(
50235023
int
50245024
xfs_btree_count_blocks(
50255025
struct xfs_btree_cur *cur,
5026-
xfs_extlen_t *blocks)
5026+
xfs_filblks_t *blocks)
50275027
{
50285028
*blocks = 0;
50295029
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
@@ -554,7 +554,7 @@ typedef int (*xfs_btree_visit_blocks_fn)(struct xfs_btree_cur *cur, int level,
554554
int xfs_btree_visit_blocks(struct xfs_btree_cur *cur,
555555
xfs_btree_visit_blocks_fn fn, unsigned int flags, void *data);
556556

557-
int xfs_btree_count_blocks(struct xfs_btree_cur *cur, xfs_extlen_t *blocks);
557+
int xfs_btree_count_blocks(struct xfs_btree_cur *cur, xfs_filblks_t *blocks);
558558

559559
union xfs_btree_rec *xfs_btree_rec_addr(struct xfs_btree_cur *cur, int n,
560560
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
@@ -754,15 +754,17 @@ xfs_inobt_count_blocks(
754754
{
755755
struct xfs_buf *agbp = NULL;
756756
struct xfs_btree_cur *cur = NULL;
757+
xfs_filblks_t blocks;
757758
int error;
758759

759760
error = xfs_inobt_cur(pag, tp, btnum, &cur, &agbp);
760761
if (error)
761762
return error;
762763

763-
error = xfs_btree_count_blocks(cur, tree_blocks);
764+
error = xfs_btree_count_blocks(cur, &blocks);
764765
xfs_btree_del_cursor(cur, error);
765766
xfs_trans_brelse(tp, agbp);
767+
*tree_blocks = blocks;
766768

767769
return error;
768770
}

fs/xfs/scrub/agheader.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ xchk_agf_xref_btreeblks(
434434
{
435435
struct xfs_agf *agf = sc->sa.agf_bp->b_addr;
436436
struct xfs_mount *mp = sc->mp;
437-
xfs_agblock_t blocks;
437+
xfs_filblks_t blocks;
438438
xfs_agblock_t btreeblks;
439439
int error;
440440

@@ -483,7 +483,7 @@ xchk_agf_xref_refcblks(
483483
struct xfs_scrub *sc)
484484
{
485485
struct xfs_agf *agf = sc->sa.agf_bp->b_addr;
486-
xfs_agblock_t blocks;
486+
xfs_filblks_t blocks;
487487
int error;
488488

489489
if (!sc->sa.refc_cur)
@@ -816,7 +816,7 @@ xchk_agi_xref_fiblocks(
816816
struct xfs_scrub *sc)
817817
{
818818
struct xfs_agi *agi = sc->sa.agi_bp->b_addr;
819-
xfs_agblock_t blocks;
819+
xfs_filblks_t blocks;
820820
int error = 0;
821821

822822
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
@@ -258,7 +258,7 @@ xrep_agf_calc_from_btrees(
258258
struct xfs_agf *agf = agf_bp->b_addr;
259259
struct xfs_mount *mp = sc->mp;
260260
xfs_agblock_t btreeblks;
261-
xfs_agblock_t blocks;
261+
xfs_filblks_t blocks;
262262
int error;
263263

264264
/* Update the AGF counters from the bnobt. */
@@ -913,7 +913,7 @@ xrep_agi_calc_from_btrees(
913913
if (error)
914914
goto err;
915915
if (xfs_has_inobtcounts(mp)) {
916-
xfs_agblock_t blocks;
916+
xfs_filblks_t blocks;
917917

918918
error = xfs_btree_count_blocks(cur, &blocks);
919919
if (error)
@@ -926,7 +926,7 @@ xrep_agi_calc_from_btrees(
926926
agi->agi_freecount = cpu_to_be32(freecount);
927927

928928
if (xfs_has_finobt(mp) && xfs_has_inobtcounts(mp)) {
929-
xfs_agblock_t blocks;
929+
xfs_filblks_t blocks;
930930

931931
cur = xfs_inobt_init_cursor(sc->sa.pag, sc->tp, agi_bp,
932932
XFS_BTNUM_FINO);

fs/xfs/scrub/fscounters.c

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

270270
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
@@ -653,8 +653,8 @@ xchk_iallocbt_xref_rmap_btreeblks(
653653
int which)
654654
{
655655
xfs_filblks_t blocks;
656-
xfs_extlen_t inobt_blocks = 0;
657-
xfs_extlen_t finobt_blocks = 0;
656+
xfs_filblks_t inobt_blocks = 0;
657+
xfs_filblks_t finobt_blocks = 0;
658658
int error;
659659

660660
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
@@ -478,7 +478,7 @@ xchk_refcount_xref_rmap(
478478
struct xfs_scrub *sc,
479479
xfs_filblks_t cow_blocks)
480480
{
481-
xfs_extlen_t refcbt_blocks = 0;
481+
xfs_filblks_t refcbt_blocks = 0;
482482
xfs_filblks_t blocks;
483483
int error;
484484

fs/xfs/xfs_bmap_util.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ xfs_bmap_count_blocks(
111111
struct xfs_mount *mp = ip->i_mount;
112112
struct xfs_ifork *ifp = xfs_ifork_ptr(ip, whichfork);
113113
struct xfs_btree_cur *cur;
114-
xfs_extlen_t btblocks = 0;
114+
xfs_filblks_t btblocks = 0;
115115
int error;
116116

117117
*nextents = 0;

0 commit comments

Comments
 (0)