The maximum extent length depends on maximum block count that can be stored in a BMBT record. Hence this commit defines MAXEXTLEN based on BMBT_BLOCKCOUNT_BITLEN. While at it, the commit also renames MAXEXTLEN to XFS_MAX_EXTLEN. Suggested-by: Darrick J. Wong <djwong@xxxxxxxxxx> Signed-off-by: Chandan Babu R <chandan.babu@xxxxxxxxxx> --- db/metadump.c | 2 +- libxfs/xfs_bmap.c | 53 +++++++++++++++++++++-------------------- libxfs/xfs_format.h | 20 +++++++--------- libxfs/xfs_inode_buf.c | 4 ++-- libxfs/xfs_rtbitmap.c | 4 ++-- libxfs/xfs_swapext.c | 6 ++--- libxfs/xfs_trans_resv.c | 10 ++++---- mkfs/xfs_mkfs.c | 6 ++--- repair/bmap_repair.c | 2 +- repair/phase4.c | 2 +- 10 files changed, 54 insertions(+), 55 deletions(-) diff --git a/db/metadump.c b/db/metadump.c index 3e3e05c7..77a27707 100644 --- a/db/metadump.c +++ b/db/metadump.c @@ -20,7 +20,7 @@ #include "field.h" #include "dir2.h" -#define DEFAULT_MAX_EXT_SIZE MAXEXTLEN +#define DEFAULT_MAX_EXT_SIZE XFS_MAX_EXTLEN /* copy all metadata structures to/from a file */ diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index 8a1b94bb..fa7b4a2a 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -541,7 +541,7 @@ __xfs_bmap_add_free( ASSERT(bno != NULLFSBLOCK); ASSERT(len > 0); - ASSERT(len <= MAXEXTLEN); + ASSERT(len <= XFS_MAX_EXTLEN); ASSERT(!isnullstartblock(bno)); agno = XFS_FSB_TO_AGNO(mp, bno); agbno = XFS_FSB_TO_AGBNO(mp, bno); @@ -1497,7 +1497,7 @@ xfs_bmap_add_extent_delay_real( LEFT.br_startoff + LEFT.br_blockcount == new->br_startoff && LEFT.br_startblock + LEFT.br_blockcount == new->br_startblock && LEFT.br_state == new->br_state && - LEFT.br_blockcount + new->br_blockcount <= MAXEXTLEN) + LEFT.br_blockcount + new->br_blockcount <= XFS_MAX_EXTLEN) state |= BMAP_LEFT_CONTIG; /* @@ -1515,13 +1515,13 @@ xfs_bmap_add_extent_delay_real( new_endoff == RIGHT.br_startoff && new->br_startblock + new->br_blockcount == RIGHT.br_startblock && new->br_state == RIGHT.br_state && - new->br_blockcount + RIGHT.br_blockcount <= MAXEXTLEN && + new->br_blockcount + RIGHT.br_blockcount <= XFS_MAX_EXTLEN && ((state & (BMAP_LEFT_CONTIG | BMAP_LEFT_FILLING | BMAP_RIGHT_FILLING)) != (BMAP_LEFT_CONTIG | BMAP_LEFT_FILLING | BMAP_RIGHT_FILLING) || LEFT.br_blockcount + new->br_blockcount + RIGHT.br_blockcount - <= MAXEXTLEN)) + <= XFS_MAX_EXTLEN)) state |= BMAP_RIGHT_CONTIG; error = 0; @@ -2060,7 +2060,7 @@ xfs_bmap_add_extent_unwritten_real( LEFT.br_startoff + LEFT.br_blockcount == new->br_startoff && LEFT.br_startblock + LEFT.br_blockcount == new->br_startblock && LEFT.br_state == new->br_state && - LEFT.br_blockcount + new->br_blockcount <= MAXEXTLEN) + LEFT.br_blockcount + new->br_blockcount <= XFS_MAX_EXTLEN) state |= BMAP_LEFT_CONTIG; /* @@ -2078,13 +2078,13 @@ xfs_bmap_add_extent_unwritten_real( new_endoff == RIGHT.br_startoff && new->br_startblock + new->br_blockcount == RIGHT.br_startblock && new->br_state == RIGHT.br_state && - new->br_blockcount + RIGHT.br_blockcount <= MAXEXTLEN && + new->br_blockcount + RIGHT.br_blockcount <= XFS_MAX_EXTLEN && ((state & (BMAP_LEFT_CONTIG | BMAP_LEFT_FILLING | BMAP_RIGHT_FILLING)) != (BMAP_LEFT_CONTIG | BMAP_LEFT_FILLING | BMAP_RIGHT_FILLING) || LEFT.br_blockcount + new->br_blockcount + RIGHT.br_blockcount - <= MAXEXTLEN)) + <= XFS_MAX_EXTLEN)) state |= BMAP_RIGHT_CONTIG; /* @@ -2593,15 +2593,15 @@ xfs_bmap_add_extent_hole_delay( */ if ((state & BMAP_LEFT_VALID) && (state & BMAP_LEFT_DELAY) && left.br_startoff + left.br_blockcount == new->br_startoff && - left.br_blockcount + new->br_blockcount <= MAXEXTLEN) + left.br_blockcount + new->br_blockcount <= XFS_MAX_EXTLEN) state |= BMAP_LEFT_CONTIG; if ((state & BMAP_RIGHT_VALID) && (state & BMAP_RIGHT_DELAY) && new->br_startoff + new->br_blockcount == right.br_startoff && - new->br_blockcount + right.br_blockcount <= MAXEXTLEN && + new->br_blockcount + right.br_blockcount <= XFS_MAX_EXTLEN && (!(state & BMAP_LEFT_CONTIG) || (left.br_blockcount + new->br_blockcount + - right.br_blockcount <= MAXEXTLEN))) + right.br_blockcount <= XFS_MAX_EXTLEN))) state |= BMAP_RIGHT_CONTIG; /* @@ -2744,17 +2744,17 @@ xfs_bmap_add_extent_hole_real( left.br_startoff + left.br_blockcount == new->br_startoff && left.br_startblock + left.br_blockcount == new->br_startblock && left.br_state == new->br_state && - left.br_blockcount + new->br_blockcount <= MAXEXTLEN) + left.br_blockcount + new->br_blockcount <= XFS_MAX_EXTLEN) state |= BMAP_LEFT_CONTIG; if ((state & BMAP_RIGHT_VALID) && !(state & BMAP_RIGHT_DELAY) && new->br_startoff + new->br_blockcount == right.br_startoff && new->br_startblock + new->br_blockcount == right.br_startblock && new->br_state == right.br_state && - new->br_blockcount + right.br_blockcount <= MAXEXTLEN && + new->br_blockcount + right.br_blockcount <= XFS_MAX_EXTLEN && (!(state & BMAP_LEFT_CONTIG) || left.br_blockcount + new->br_blockcount + - right.br_blockcount <= MAXEXTLEN)) + right.br_blockcount <= XFS_MAX_EXTLEN)) state |= BMAP_RIGHT_CONTIG; error = 0; @@ -2996,15 +2996,15 @@ xfs_bmap_extsize_align( /* * For large extent hint sizes, the aligned extent might be larger than - * MAXEXTLEN. In that case, reduce the size by an extsz so that it pulls - * the length back under MAXEXTLEN. The outer allocation loops handle + * XFS_MAX_EXTLEN. In that case, reduce the size by an extsz so that it pulls + * the length back under XFS_MAX_EXTLEN. The outer allocation loops handle * short allocation just fine, so it is safe to do this. We only want to * do it when we are forced to, though, because it means more allocation * operations are required. */ - while (align_alen > MAXEXTLEN) + while (align_alen > XFS_MAX_EXTLEN) align_alen -= extsz; - ASSERT(align_alen <= MAXEXTLEN); + ASSERT(align_alen <= XFS_MAX_EXTLEN); /* * If the previous block overlaps with this proposed allocation @@ -3094,9 +3094,9 @@ xfs_bmap_extsize_align( return -EINVAL; } else { ASSERT(orig_off >= align_off); - /* see MAXEXTLEN handling above */ + /* see XFS_MAX_EXTLEN handling above */ ASSERT(orig_end <= align_off + align_alen || - align_alen + extsz > MAXEXTLEN); + align_alen + extsz > XFS_MAX_EXTLEN); } #ifdef DEBUG @@ -4063,7 +4063,7 @@ xfs_bmapi_reserve_delalloc( * Cap the alloc length. Keep track of prealloc so we know whether to * tag the inode before we return. */ - alen = XFS_FILBLKS_MIN(len + prealloc, MAXEXTLEN); + alen = XFS_FILBLKS_MIN(len + prealloc, XFS_MAX_EXTLEN); if (!eof) alen = XFS_FILBLKS_MIN(alen, got->br_startoff - aoff); if (prealloc && alen >= len) @@ -4196,7 +4196,7 @@ xfs_bmapi_allocate( if (!xfs_iext_peek_prev_extent(ifp, &bma->icur, &bma->prev)) bma->prev.br_startoff = NULLFILEOFF; } else { - bma->length = XFS_FILBLKS_MIN(bma->length, MAXEXTLEN); + bma->length = XFS_FILBLKS_MIN(bma->length, XFS_MAX_EXTLEN); if (!bma->eof) bma->length = XFS_FILBLKS_MIN(bma->length, bma->got.br_startoff - bma->offset); @@ -4517,8 +4517,8 @@ xfs_bmapi_write( * xfs_extlen_t and therefore 32 bits. Hence we have to * check for 32-bit overflows and handle them here. */ - if (len > (xfs_filblks_t)MAXEXTLEN) - bma.length = MAXEXTLEN; + if (len > (xfs_filblks_t)XFS_MAX_EXTLEN) + bma.length = XFS_MAX_EXTLEN; else bma.length = len; @@ -4653,7 +4653,8 @@ xfs_bmapi_convert_delalloc( bma.ip = ip; bma.wasdel = true; bma.offset = bma.got.br_startoff; - bma.length = max_t(xfs_filblks_t, bma.got.br_blockcount, MAXEXTLEN); + bma.length = max_t(xfs_filblks_t, bma.got.br_blockcount, + XFS_MAX_EXTLEN); bma.minleft = xfs_bmapi_minleft(tp, ip, whichfork); /* @@ -4736,7 +4737,7 @@ xfs_bmapi_remap( ifp = XFS_IFORK_PTR(ip, whichfork); ASSERT(len > 0); - ASSERT(len <= (xfs_filblks_t)MAXEXTLEN); + ASSERT(len <= (xfs_filblks_t)XFS_MAX_EXTLEN); ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL)); ASSERT(!(flags & ~(XFS_BMAPI_ATTRFORK | XFS_BMAPI_PREALLOC | XFS_BMAPI_NORMAP))); @@ -5709,7 +5710,7 @@ xfs_bmse_can_merge( if ((left->br_startoff + left->br_blockcount != startoff) || (left->br_startblock + left->br_blockcount != got->br_startblock) || (left->br_state != got->br_state) || - (left->br_blockcount + got->br_blockcount > MAXEXTLEN)) + (left->br_blockcount + got->br_blockcount > XFS_MAX_EXTLEN)) return false; return true; diff --git a/libxfs/xfs_format.h b/libxfs/xfs_format.h index a97abc4a..c9af8c04 100644 --- a/libxfs/xfs_format.h +++ b/libxfs/xfs_format.h @@ -884,17 +884,6 @@ enum xfs_dinode_fmt { { XFS_DINODE_FMT_BTREE, "btree" }, \ { XFS_DINODE_FMT_UUID, "uuid" } -/* - * Max values for extlen, disk inode's extent counters. - */ - -#define MAXEXTLEN ((xfs_extlen_t)0x1fffff) /* 21 bits */ -#define XFS_IFORK_EXTCNT_MAXU48 ((xfs_extnum_t)0xffffffffffff) /* Unsigned 48-bits */ -#define XFS_IFORK_EXTCNT_MAXU32 ((xfs_aextnum_t)0xffffffff) /* Unsigned 32-bits */ -#define XFS_IFORK_EXTCNT_MAXS32 ((xfs_extnum_t)0x7fffffff) /* Signed 32-bits */ -#define XFS_IFORK_EXTCNT_MAXS16 ((xfs_aextnum_t)0x7fff) /* Signed 16-bits */ - - /* * Inode minimum and maximum sizes. */ @@ -1700,6 +1689,15 @@ typedef struct xfs_bmbt_rec { typedef uint64_t xfs_bmbt_rec_base_t; /* use this for casts */ typedef xfs_bmbt_rec_t xfs_bmdr_rec_t; +/* + * Max values for extlen, disk inode's extent counters. + */ +#define XFS_MAX_EXTLEN ((xfs_extlen_t)(1 << BMBT_BLOCKCOUNT_BITLEN) - 1) +#define XFS_IFORK_EXTCNT_MAXU48 ((xfs_extnum_t)0xffffffffffff) /* Unsigned 48-bits */ +#define XFS_IFORK_EXTCNT_MAXU32 ((xfs_aextnum_t)0xffffffff) /* Unsigned 32-bits */ +#define XFS_IFORK_EXTCNT_MAXS32 ((xfs_extnum_t)0x7fffffff) /* Signed 32-bits */ +#define XFS_IFORK_EXTCNT_MAXS16 ((xfs_aextnum_t)0x7fff) /* Signed 16-bits */ + /* * Values and macros for delayed-allocation startblock fields. */ diff --git a/libxfs/xfs_inode_buf.c b/libxfs/xfs_inode_buf.c index 15690f7f..77288b82 100644 --- a/libxfs/xfs_inode_buf.c +++ b/libxfs/xfs_inode_buf.c @@ -744,7 +744,7 @@ xfs_inode_validate_extsize( if (extsize_bytes % blocksize_bytes) return __this_address; - if (extsize > MAXEXTLEN) + if (extsize > XFS_MAX_EXTLEN) return __this_address; if (!rt_flag && extsize > mp->m_sb.sb_agblocks / 2) @@ -801,7 +801,7 @@ xfs_inode_validate_cowextsize( if (cowextsize_bytes % mp->m_sb.sb_blocksize) return __this_address; - if (cowextsize > MAXEXTLEN) + if (cowextsize > XFS_MAX_EXTLEN) return __this_address; if (cowextsize > mp->m_sb.sb_agblocks / 2) diff --git a/libxfs/xfs_rtbitmap.c b/libxfs/xfs_rtbitmap.c index a8a71adc..c87c9d0b 100644 --- a/libxfs/xfs_rtbitmap.c +++ b/libxfs/xfs_rtbitmap.c @@ -1013,7 +1013,7 @@ xfs_rtfree_extent( /* * Free some blocks in the realtime subvolume. rtbno and rtlen are in units of * rt blocks, not rt extents; must be aligned to the rt extent size; and rtlen - * cannot exceed MAXEXTLEN. + * cannot exceed XFS_MAX_EXTLEN. */ int xfs_rtfree_blocks( @@ -1026,7 +1026,7 @@ xfs_rtfree_blocks( xfs_filblks_t len; xfs_extlen_t mod; - ASSERT(rtlen <= MAXEXTLEN); + ASSERT(rtlen <= XFS_MAX_EXTLEN); len = div_u64_rem(rtlen, mp->m_sb.sb_rextsize, &mod); if (mod) { diff --git a/libxfs/xfs_swapext.c b/libxfs/xfs_swapext.c index 2fb0ac76..f8facf1d 100644 --- a/libxfs/xfs_swapext.c +++ b/libxfs/xfs_swapext.c @@ -755,7 +755,7 @@ can_merge( if (b1->br_startoff + b1->br_blockcount == b2->br_startoff && b1->br_startblock + b1->br_blockcount == b2->br_startblock && b1->br_state == b2->br_state && - b1->br_blockcount + b2->br_blockcount <= MAXEXTLEN) + b1->br_blockcount + b2->br_blockcount <= XFS_MAX_EXTLEN) return true; return false; @@ -797,7 +797,7 @@ delta_nextents_step( state |= CRIGHT_CONTIG; if ((state & CBOTH_CONTIG) == CBOTH_CONTIG && left->br_startblock + curr->br_startblock + - right->br_startblock > MAXEXTLEN) + right->br_startblock > XFS_MAX_EXTLEN) state &= ~CRIGHT_CONTIG; if (nhole) @@ -808,7 +808,7 @@ delta_nextents_step( state |= NRIGHT_CONTIG; if ((state & NBOTH_CONTIG) == NBOTH_CONTIG && left->br_startblock + new->br_startblock + - right->br_startblock > MAXEXTLEN) + right->br_startblock > XFS_MAX_EXTLEN) state &= ~NRIGHT_CONTIG; switch (state & (CLEFT_CONTIG | CRIGHT_CONTIG | CHOLE)) { diff --git a/libxfs/xfs_trans_resv.c b/libxfs/xfs_trans_resv.c index f153e021..6566012d 100644 --- a/libxfs/xfs_trans_resv.c +++ b/libxfs/xfs_trans_resv.c @@ -208,8 +208,8 @@ xfs_calc_inode_chunk_res( /* * Per-extent log reservation for the btree changes involved in freeing or * allocating a realtime extent. We have to be able to log as many rtbitmap - * blocks as needed to mark inuse MAXEXTLEN blocks' worth of realtime extents, - * as well as the realtime summary block. + * blocks as needed to mark inuse XFS_MAX_EXTLEN blocks' worth of realtime + * extents, as well as the realtime summary block. */ static unsigned int xfs_rtalloc_log_count( @@ -219,7 +219,7 @@ xfs_rtalloc_log_count( unsigned int blksz = XFS_FSB_TO_B(mp, 1); unsigned int rtbmp_bytes; - rtbmp_bytes = (MAXEXTLEN / mp->m_sb.sb_rextsize) / NBBY; + rtbmp_bytes = (XFS_MAX_EXTLEN / mp->m_sb.sb_rextsize) / NBBY; return (howmany(rtbmp_bytes, blksz) + 1) * num_ops; } @@ -278,7 +278,7 @@ xfs_refcount_log_reservation( * the inode's bmap btree: max depth * block size * the agfs of the ags from which the extents are allocated: 2 * sector * the superblock free block counter: sector size - * the realtime bitmap: ((MAXEXTLEN / rtextsize) / NBBY) bytes + * the realtime bitmap: ((XFS_MAX_EXTLEN / rtextsize) / NBBY) bytes * the realtime summary: 1 block * the allocation btrees: 2 trees * (2 * max depth - 1) * block size * And the bmap_finish transaction can free bmap blocks in a join (t3): @@ -333,7 +333,7 @@ xfs_calc_write_reservation( * the agf for each of the ags: 2 * sector size * the agfl for each of the ags: 2 * sector size * the super block to reflect the freed blocks: sector size - * the realtime bitmap: 2 exts * ((MAXEXTLEN / rtextsize) / NBBY) bytes + * the realtime bitmap: 2 exts * ((XFS_MAX_EXTLEN / rtextsize) / NBBY) bytes * the realtime summary: 2 exts * 1 block * worst case split in allocation btrees per extent assuming 2 extents: * 2 exts * 2 trees * (2 * max depth - 1) * block size diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c index 37c22277..49a450e0 100644 --- a/mkfs/xfs_mkfs.c +++ b/mkfs/xfs_mkfs.c @@ -2427,7 +2427,7 @@ validate_extsize_hint( fprintf(stderr, _("illegal extent size hint %lld, must be less than %u.\n"), (long long)cli->fsx.fsx_extsize, - min(MAXEXTLEN, mp->m_sb.sb_agblocks / 2)); + min(XFS_MAX_EXTLEN, mp->m_sb.sb_agblocks / 2)); usage(); } @@ -2450,7 +2450,7 @@ _("illegal extent size hint %lld, must be less than %u.\n"), fprintf(stderr, _("illegal extent size hint %lld, must be less than %u and a multiple of %u.\n"), (long long)cli->fsx.fsx_extsize, - min(MAXEXTLEN, mp->m_sb.sb_agblocks / 2), + min(XFS_MAX_EXTLEN, mp->m_sb.sb_agblocks / 2), mp->m_sb.sb_rextsize); usage(); } @@ -2479,7 +2479,7 @@ validate_cowextsize_hint( fprintf(stderr, _("illegal CoW extent size hint %lld, must be less than %u.\n"), (long long)cli->fsx.fsx_cowextsize, - min(MAXEXTLEN, mp->m_sb.sb_agblocks / 2)); + min(XFS_MAX_EXTLEN, mp->m_sb.sb_agblocks / 2)); usage(); } } diff --git a/repair/bmap_repair.c b/repair/bmap_repair.c index 7d3bb330..811b16dc 100644 --- a/repair/bmap_repair.c +++ b/repair/bmap_repair.c @@ -64,7 +64,7 @@ xrep_bmap_from_rmap( do { irec.br_blockcount = min_t(xfs_filblks_t, blockcount, - MAXEXTLEN); + XFS_MAX_EXTLEN); libxfs_bmbt_disk_set_all(&rbe, &irec); error = slab_add(rb->bmap_records, &rbe); diff --git a/repair/phase4.c b/repair/phase4.c index b752b07c..880cd313 100644 --- a/repair/phase4.c +++ b/repair/phase4.c @@ -393,7 +393,7 @@ phase4(xfs_mount_t *mp) if (rt_start == 0) { rt_start = bno; rt_len = 1; - } else if (rt_len == MAXEXTLEN) { + } else if (rt_len == XFS_MAX_EXTLEN) { /* * large extent case */ -- 2.30.2