]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
xfs: use realtime EFI to free extents when rtgroups are enabled
authorDarrick J. Wong <djwong@kernel.org>
Mon, 4 Nov 2024 04:19:27 +0000 (20:19 -0800)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 5 Nov 2024 21:38:42 +0000 (13:38 -0800)
When rmap is enabled, XFS expects a certain order of operations, which
is: 1) remove the file mapping, 2) remove the reverse mapping, and then
3) free the blocks.  When reflink is enabled, XFS replaces (3) with a
deferred refcount decrement operation that can schedule freeing the
blocks if that was the last refcount.

For realtime files, xfs_bmap_del_extent_real tries to do 1 and 3 in the
same transaction, which will break both rmap and reflink unless we
switch it to use realtime EFIs.  Both rmap and reflink depend on the
rtgroups feature, so let's turn on EFIs for all rtgroups filesystems.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
fs/xfs/libxfs/xfs_bmap.c

index 482b4c0cd6b1934a87cec1222ffc3255e4ab3fc3..b15a43c18b0a57dee5a97c7f32cda3d2e086b2bc 100644 (file)
@@ -5383,9 +5383,11 @@ xfs_bmap_del_extent_real(
         * If we need to, add to list of extents to delete.
         */
        if (!(bflags & XFS_BMAPI_REMAP)) {
+               bool    isrt = xfs_ifork_is_realtime(ip, whichfork);
+
                if (xfs_is_reflink_inode(ip) && whichfork == XFS_DATA_FORK) {
                        xfs_refcount_decrease_extent(tp, del);
-               } else if (xfs_ifork_is_realtime(ip, whichfork)) {
+               } else if (isrt && !xfs_has_rtgroups(mp)) {
                        error = xfs_bmap_free_rtblocks(tp, del);
                } else {
                        unsigned int    efi_flags = 0;
@@ -5394,6 +5396,19 @@ xfs_bmap_del_extent_real(
                            del->br_state == XFS_EXT_UNWRITTEN)
                                efi_flags |= XFS_FREE_EXTENT_SKIP_DISCARD;
 
+                       /*
+                        * 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.  Reflink for realtime volumes requires the
+                        * same sort of ordering.  Both features rely on
+                        * rtgroups, so let's gate rt EFI usage on rtgroups.
+                        */
+                       if (isrt)
+                               efi_flags |= XFS_FREE_EXTENT_REALTIME;
+
                        error = xfs_free_extent_later(tp, del->br_startblock,
                                        del->br_blockcount, NULL,
                                        XFS_AG_RESV_NONE, efi_flags);