]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: add frextents to the lazysbcounters when rtgroups enabled
authorDarrick J. Wong <djwong@kernel.org>
Mon, 25 Nov 2024 21:14:22 +0000 (13:14 -0800)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 24 Dec 2024 02:01:30 +0000 (18:01 -0800)
Source kernel commit: 35537f25d23697716f0070ea0a6e8b3f1fe10196

Make the free rt extent count a part of the lazy sb counters when the
realtime groups feature is enabled.  This is possible because the patch
to recompute frextents from the rtbitmap during log recovery predates
the code adding rtgroup support, hence we know that the value will
always be correct during runtime.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
include/xfs_mount.h
libxfs/xfs_sb.c

index 31ac60d93c61cca006d0c2273efa5fa8584f39f1..c03246a08a4af3feb101068401760da704286ff1 100644 (file)
@@ -64,6 +64,7 @@ typedef struct xfs_mount {
 #define m_icount       m_sb.sb_icount
 #define m_ifree                m_sb.sb_ifree
 #define m_fdblocks     m_sb.sb_fdblocks
+#define m_frextents    m_sb.sb_frextents
        spinlock_t              m_sb_lock;
 
        /*
index 2e536bc3b2090b268fc5193c342ac71ba742b76c..88fb4890d95a72e45463824ebe198bd67f12ed46 100644 (file)
@@ -1163,11 +1163,6 @@ xfs_log_sb(
         * reservations that have been taken out percpu counters. If we have an
         * unclean shutdown, this will be corrected by log recovery rebuilding
         * the counters from the AGF block counts.
-        *
-        * Do not update sb_frextents here because it is not part of the lazy
-        * sb counters, despite having a percpu counter. It is always kept
-        * consistent with the ondisk rtbitmap by xfs_trans_apply_sb_deltas()
-        * and hence we don't need have to update it here.
         */
        if (xfs_has_lazysbcount(mp)) {
                mp->m_sb.sb_icount = percpu_counter_sum_positive(&mp->m_icount);
@@ -1178,6 +1173,16 @@ xfs_log_sb(
                                percpu_counter_sum_positive(&mp->m_fdblocks);
        }
 
+       /*
+        * sb_frextents was added to the lazy sb counters when the rt groups
+        * feature was introduced.  This counter can go negative due to the way
+        * we handle nearly-lockless reservations, so we must use the _positive
+        * variant here to avoid writing out nonsense frextents.
+        */
+       if (xfs_has_rtgroups(mp))
+               mp->m_sb.sb_frextents =
+                               percpu_counter_sum_positive(&mp->m_frextents);
+
        xfs_sb_to_disk(bp->b_addr, &mp->m_sb);
        xfs_trans_buf_set_type(tp, bp, XFS_BLFT_SB_BUF);
        xfs_trans_log_buf(tp, bp, 0, sizeof(struct xfs_dsb) - 1);