4040#include "xfs_bmap_item.h"
4141#include "xfs_symlink_remote.h"
4242#include "xfs_inode_util.h"
43+ #include "xfs_rtgroup.h"
4344
4445struct kmem_cache * xfs_bmap_intent_cache ;
4546
@@ -1426,6 +1427,24 @@ xfs_bmap_last_offset(
14261427 * Extent tree manipulation functions used during allocation.
14271428 */
14281429
1430+ static inline bool
1431+ xfs_bmap_same_rtgroup (
1432+ struct xfs_inode * ip ,
1433+ int whichfork ,
1434+ struct xfs_bmbt_irec * left ,
1435+ struct xfs_bmbt_irec * right )
1436+ {
1437+ struct xfs_mount * mp = ip -> i_mount ;
1438+
1439+ if (xfs_ifork_is_realtime (ip , whichfork ) && xfs_has_rtgroups (mp )) {
1440+ if (xfs_rtb_to_rgno (mp , left -> br_startblock ) !=
1441+ xfs_rtb_to_rgno (mp , right -> br_startblock ))
1442+ return false;
1443+ }
1444+
1445+ return true;
1446+ }
1447+
14291448/*
14301449 * Convert a delayed allocation to a real allocation.
14311450 */
@@ -1495,7 +1514,8 @@ xfs_bmap_add_extent_delay_real(
14951514 LEFT .br_startoff + LEFT .br_blockcount == new -> br_startoff &&
14961515 LEFT .br_startblock + LEFT .br_blockcount == new -> br_startblock &&
14971516 LEFT .br_state == new -> br_state &&
1498- LEFT .br_blockcount + new -> br_blockcount <= XFS_MAX_BMBT_EXTLEN )
1517+ LEFT .br_blockcount + new -> br_blockcount <= XFS_MAX_BMBT_EXTLEN &&
1518+ xfs_bmap_same_rtgroup (bma -> ip , whichfork , & LEFT , new ))
14991519 state |= BMAP_LEFT_CONTIG ;
15001520
15011521 /*
@@ -1519,7 +1539,8 @@ xfs_bmap_add_extent_delay_real(
15191539 (BMAP_LEFT_CONTIG | BMAP_LEFT_FILLING |
15201540 BMAP_RIGHT_FILLING ) ||
15211541 LEFT .br_blockcount + new -> br_blockcount + RIGHT .br_blockcount
1522- <= XFS_MAX_BMBT_EXTLEN ))
1542+ <= XFS_MAX_BMBT_EXTLEN ) &&
1543+ xfs_bmap_same_rtgroup (bma -> ip , whichfork , new , & RIGHT ))
15231544 state |= BMAP_RIGHT_CONTIG ;
15241545
15251546 error = 0 ;
@@ -2064,7 +2085,8 @@ xfs_bmap_add_extent_unwritten_real(
20642085 LEFT .br_startoff + LEFT .br_blockcount == new -> br_startoff &&
20652086 LEFT .br_startblock + LEFT .br_blockcount == new -> br_startblock &&
20662087 LEFT .br_state == new -> br_state &&
2067- LEFT .br_blockcount + new -> br_blockcount <= XFS_MAX_BMBT_EXTLEN )
2088+ LEFT .br_blockcount + new -> br_blockcount <= XFS_MAX_BMBT_EXTLEN &&
2089+ xfs_bmap_same_rtgroup (ip , whichfork , & LEFT , new ))
20682090 state |= BMAP_LEFT_CONTIG ;
20692091
20702092 /*
@@ -2088,7 +2110,8 @@ xfs_bmap_add_extent_unwritten_real(
20882110 (BMAP_LEFT_CONTIG | BMAP_LEFT_FILLING |
20892111 BMAP_RIGHT_FILLING ) ||
20902112 LEFT .br_blockcount + new -> br_blockcount + RIGHT .br_blockcount
2091- <= XFS_MAX_BMBT_EXTLEN ))
2113+ <= XFS_MAX_BMBT_EXTLEN ) &&
2114+ xfs_bmap_same_rtgroup (ip , whichfork , new , & RIGHT ))
20922115 state |= BMAP_RIGHT_CONTIG ;
20932116
20942117 /*
@@ -2597,15 +2620,17 @@ xfs_bmap_add_extent_hole_delay(
25972620 */
25982621 if ((state & BMAP_LEFT_VALID ) && (state & BMAP_LEFT_DELAY ) &&
25992622 left .br_startoff + left .br_blockcount == new -> br_startoff &&
2600- left .br_blockcount + new -> br_blockcount <= XFS_MAX_BMBT_EXTLEN )
2623+ left .br_blockcount + new -> br_blockcount <= XFS_MAX_BMBT_EXTLEN &&
2624+ xfs_bmap_same_rtgroup (ip , whichfork , & left , new ))
26012625 state |= BMAP_LEFT_CONTIG ;
26022626
26032627 if ((state & BMAP_RIGHT_VALID ) && (state & BMAP_RIGHT_DELAY ) &&
26042628 new -> br_startoff + new -> br_blockcount == right .br_startoff &&
26052629 new -> br_blockcount + right .br_blockcount <= XFS_MAX_BMBT_EXTLEN &&
26062630 (!(state & BMAP_LEFT_CONTIG ) ||
26072631 (left .br_blockcount + new -> br_blockcount +
2608- right .br_blockcount <= XFS_MAX_BMBT_EXTLEN )))
2632+ right .br_blockcount <= XFS_MAX_BMBT_EXTLEN )) &&
2633+ xfs_bmap_same_rtgroup (ip , whichfork , new , & right ))
26092634 state |= BMAP_RIGHT_CONTIG ;
26102635
26112636 /*
@@ -2748,7 +2773,8 @@ xfs_bmap_add_extent_hole_real(
27482773 left .br_startoff + left .br_blockcount == new -> br_startoff &&
27492774 left .br_startblock + left .br_blockcount == new -> br_startblock &&
27502775 left .br_state == new -> br_state &&
2751- left .br_blockcount + new -> br_blockcount <= XFS_MAX_BMBT_EXTLEN )
2776+ left .br_blockcount + new -> br_blockcount <= XFS_MAX_BMBT_EXTLEN &&
2777+ xfs_bmap_same_rtgroup (ip , whichfork , & left , new ))
27522778 state |= BMAP_LEFT_CONTIG ;
27532779
27542780 if ((state & BMAP_RIGHT_VALID ) && !(state & BMAP_RIGHT_DELAY ) &&
@@ -2758,7 +2784,8 @@ xfs_bmap_add_extent_hole_real(
27582784 new -> br_blockcount + right .br_blockcount <= XFS_MAX_BMBT_EXTLEN &&
27592785 (!(state & BMAP_LEFT_CONTIG ) ||
27602786 left .br_blockcount + new -> br_blockcount +
2761- right .br_blockcount <= XFS_MAX_BMBT_EXTLEN ))
2787+ right .br_blockcount <= XFS_MAX_BMBT_EXTLEN ) &&
2788+ xfs_bmap_same_rtgroup (ip , whichfork , new , & right ))
27622789 state |= BMAP_RIGHT_CONTIG ;
27632790
27642791 error = 0 ;
@@ -3124,8 +3151,15 @@ xfs_bmap_adjacent_valid(
31243151 struct xfs_mount * mp = ap -> ip -> i_mount ;
31253152
31263153 if (XFS_IS_REALTIME_INODE (ap -> ip ) &&
3127- (ap -> datatype & XFS_ALLOC_USERDATA ))
3128- return x < mp -> m_sb .sb_rblocks ;
3154+ (ap -> datatype & XFS_ALLOC_USERDATA )) {
3155+ if (!xfs_has_rtgroups (mp ))
3156+ return x < mp -> m_sb .sb_rblocks ;
3157+
3158+ return xfs_rtb_to_rgno (mp , x ) == xfs_rtb_to_rgno (mp , y ) &&
3159+ xfs_rtb_to_rgno (mp , x ) < mp -> m_sb .sb_rgcount &&
3160+ xfs_rtb_to_rtx (mp , x ) < mp -> m_sb .sb_rgextents ;
3161+
3162+ }
31293163
31303164 return XFS_FSB_TO_AGNO (mp , x ) == XFS_FSB_TO_AGNO (mp , y ) &&
31313165 XFS_FSB_TO_AGNO (mp , x ) < mp -> m_sb .sb_agcount &&
@@ -5356,9 +5390,11 @@ xfs_bmap_del_extent_real(
53565390 * If we need to, add to list of extents to delete.
53575391 */
53585392 if (!(bflags & XFS_BMAPI_REMAP )) {
5393+ bool isrt = xfs_ifork_is_realtime (ip , whichfork );
5394+
53595395 if (xfs_is_reflink_inode (ip ) && whichfork == XFS_DATA_FORK ) {
53605396 xfs_refcount_decrease_extent (tp , del );
5361- } else if (xfs_ifork_is_realtime ( ip , whichfork )) {
5397+ } else if (isrt && ! xfs_has_rtgroups ( mp )) {
53625398 error = xfs_bmap_free_rtblocks (tp , del );
53635399 } else {
53645400 unsigned int efi_flags = 0 ;
@@ -5367,6 +5403,19 @@ xfs_bmap_del_extent_real(
53675403 del -> br_state == XFS_EXT_UNWRITTEN )
53685404 efi_flags |= XFS_FREE_EXTENT_SKIP_DISCARD ;
53695405
5406+ /*
5407+ * Historically, we did not use EFIs to free realtime
5408+ * extents. However, when reverse mapping is enabled,
5409+ * we must maintain the same order of operations as the
5410+ * data device, which is: Remove the file mapping,
5411+ * remove the reverse mapping, and then free the
5412+ * blocks. Reflink for realtime volumes requires the
5413+ * same sort of ordering. Both features rely on
5414+ * rtgroups, so let's gate rt EFI usage on rtgroups.
5415+ */
5416+ if (isrt )
5417+ efi_flags |= XFS_FREE_EXTENT_REALTIME ;
5418+
53705419 error = xfs_free_extent_later (tp , del -> br_startblock ,
53715420 del -> br_blockcount , NULL ,
53725421 XFS_AG_RESV_NONE , efi_flags );
@@ -5715,6 +5764,8 @@ xfs_bunmapi(
57155764 */
57165765STATIC bool
57175766xfs_bmse_can_merge (
5767+ struct xfs_inode * ip ,
5768+ int whichfork ,
57185769 struct xfs_bmbt_irec * left , /* preceding extent */
57195770 struct xfs_bmbt_irec * got , /* current extent to shift */
57205771 xfs_fileoff_t shift ) /* shift fsb */
@@ -5730,7 +5781,8 @@ xfs_bmse_can_merge(
57305781 if ((left -> br_startoff + left -> br_blockcount != startoff ) ||
57315782 (left -> br_startblock + left -> br_blockcount != got -> br_startblock ) ||
57325783 (left -> br_state != got -> br_state ) ||
5733- (left -> br_blockcount + got -> br_blockcount > XFS_MAX_BMBT_EXTLEN ))
5784+ (left -> br_blockcount + got -> br_blockcount > XFS_MAX_BMBT_EXTLEN ) ||
5785+ !xfs_bmap_same_rtgroup (ip , whichfork , left , got ))
57345786 return false;
57355787
57365788 return true;
@@ -5766,7 +5818,7 @@ xfs_bmse_merge(
57665818 blockcount = left -> br_blockcount + got -> br_blockcount ;
57675819
57685820 xfs_assert_ilocked (ip , XFS_IOLOCK_EXCL | XFS_ILOCK_EXCL );
5769- ASSERT (xfs_bmse_can_merge (left , got , shift ));
5821+ ASSERT (xfs_bmse_can_merge (ip , whichfork , left , got , shift ));
57705822
57715823 new = * left ;
57725824 new .br_blockcount = blockcount ;
@@ -5928,7 +5980,8 @@ xfs_bmap_collapse_extents(
59285980 goto del_cursor ;
59295981 }
59305982
5931- if (xfs_bmse_can_merge (& prev , & got , offset_shift_fsb )) {
5983+ if (xfs_bmse_can_merge (ip , whichfork , & prev , & got ,
5984+ offset_shift_fsb )) {
59325985 error = xfs_bmse_merge (tp , ip , whichfork ,
59335986 offset_shift_fsb , & icur , & got , & prev ,
59345987 cur , & logflags );
@@ -6064,7 +6117,8 @@ xfs_bmap_insert_extents(
60646117 * never find mergeable extents in this scenario. Check anyways
60656118 * and warn if we encounter two extents that could be one.
60666119 */
6067- if (xfs_bmse_can_merge (& got , & next , offset_shift_fsb ))
6120+ if (xfs_bmse_can_merge (ip , whichfork , & got , & next ,
6121+ offset_shift_fsb ))
60686122 WARN_ON_ONCE (1 );
60696123 }
60706124
0 commit comments