@@ -5051,7 +5051,6 @@ xfs_bmap_del_extent_real(
{
xfs_fsblock_t del_endblock=0; /* first block past del */
xfs_fileoff_t del_endoff; /* first offset past del */
- int do_fx; /* free extent at end of routine */
int error; /* error return value */
struct xfs_bmbt_irec got; /* current extent entry */
xfs_fileoff_t got_endoff; /* first offset past got */
@@ -5064,6 +5063,8 @@ xfs_bmap_del_extent_real(
uint qfield; /* quota field to update */
uint32_t state = xfs_bmap_fork_to_state(whichfork);
struct xfs_bmbt_irec old;
+ bool isrt = xfs_ifork_is_realtime(ip, whichfork);
+ bool want_free = !(bflags & XFS_BMAPI_REMAP);
*logflagsp = 0;
@@ -5095,18 +5096,24 @@ xfs_bmap_del_extent_real(
return -ENOSPC;
*logflagsp = XFS_ILOG_CORE;
- if (xfs_ifork_is_realtime(ip, whichfork)) {
- if (!(bflags & XFS_BMAPI_REMAP)) {
+ if (isrt) {
+ /*
+ * Historically, we did not use EFIs to free realtime extents.
+ * However, when reverse mapping is enabled, we must maintain
+ * the same order of operations as the data device, which is:
+ * Remove the file mapping, remove the reverse mapping, and
+ * then free the blocks. This means that we must delay the
+ * freeing until after we've scheduled the rmap update.
+ */
+ if (want_free && !xfs_has_rtrmapbt(mp)) {
error = xfs_rtfree_blocks(tp, del->br_startblock,
del->br_blockcount);
if (error)
return error;
+ want_free = false;
}
-
- do_fx = 0;
qfield = XFS_TRANS_DQ_RTBCOUNT;
} else {
- do_fx = 1;
qfield = XFS_TRANS_DQ_BCOUNT;
}
nblks = del->br_blockcount;
@@ -5256,7 +5263,7 @@ xfs_bmap_del_extent_real(
/*
* If we need to, add to list of extents to delete.
*/
- if (do_fx && !(bflags & XFS_BMAPI_REMAP)) {
+ if (want_free) {
if (xfs_is_reflink_inode(ip) && whichfork == XFS_DATA_FORK) {
xfs_refcount_decrease_extent(tp, del);
} else {
@@ -5265,6 +5272,8 @@ xfs_bmap_del_extent_real(
if ((bflags & XFS_BMAPI_NODISCARD) ||
del->br_state == XFS_EXT_UNWRITTEN)
efi_flags |= XFS_FREE_EXTENT_SKIP_DISCARD;
+ if (isrt)
+ efi_flags |= XFS_FREE_EXTENT_REALTIME;
error = xfs_free_extent_later(tp, del->br_startblock,
del->br_blockcount, NULL,