]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: use accessor functions for summary info words
authorDarrick J. Wong <djwong@kernel.org>
Thu, 15 Feb 2024 08:25:48 +0000 (09:25 +0100)
committerCarlos Maiolino <cem@kernel.org>
Thu, 15 Feb 2024 11:56:43 +0000 (12:56 +0100)
Source kernel commit: 663b8db7b0256b81152b2f786e45ecf12bdf265f

Create get and set functions for rtsummary words so that we can redefine
the ondisk format with a specific endianness.  Note that this requires
the definition of a distinct type for ondisk summary info words so that
the compiler can perform proper typechecking.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
libxfs/xfs_format.h
libxfs/xfs_rtbitmap.c
libxfs/xfs_rtbitmap.h

index 2af891d5d171125d3a1deb76f4724d094aa39057..9a88aba1589f87b45c470c8a8ec9a3a559a4c86d 100644 (file)
@@ -698,6 +698,14 @@ union xfs_rtword_raw {
        __u32           old;
 };
 
+/*
+ * Realtime summary counts are accessed by the word, which is currently
+ * stored in host-endian format.
+ */
+union xfs_suminfo_raw {
+       __u32           old;
+};
+
 /*
  * XFS Timestamps
  * ==============
index 44064b6b3ecc0d39b3d5af10be9bd468c7a80702..869d26e79fe9da7a5bcc94fcd195aad828273fcd 100644 (file)
@@ -449,7 +449,6 @@ xfs_rtmodify_summary_int(
        int             error;          /* error value */
        xfs_fileoff_t   sb;             /* summary fsblock */
        xfs_rtsumoff_t  so;             /* index into the summary file */
-       xfs_suminfo_t   *sp;            /* pointer to returned data */
        unsigned int    infoword;
 
        /*
@@ -488,19 +487,21 @@ xfs_rtmodify_summary_int(
         * Point to the summary information, modify/log it, and/or copy it out.
         */
        infoword = xfs_rtsumoffs_to_infoword(mp, so);
-       sp = xfs_rsumblock_infoptr(bp, infoword);
        if (delta) {
-               *sp += delta;
+               xfs_suminfo_t   val = xfs_suminfo_add(bp, infoword, delta);
+
                if (mp->m_rsum_cache) {
-                       if (*sp == 0 && log == mp->m_rsum_cache[bbno])
+                       if (val == 0 && log == mp->m_rsum_cache[bbno])
                                mp->m_rsum_cache[bbno]++;
-                       if (*sp != 0 && log < mp->m_rsum_cache[bbno])
+                       if (val != 0 && log < mp->m_rsum_cache[bbno])
                                mp->m_rsum_cache[bbno] = log;
                }
                xfs_trans_log_rtsummary(tp, bp, infoword);
+               if (sum)
+                       *sum = val;
+       } else if (sum) {
+               *sum = xfs_suminfo_get(bp, infoword);
        }
-       if (sum)
-               *sum = *sp;
        return 0;
 }
 
index 62138df6d1a3f5e25f68f7008e257b04f20eb44c..e4268faa637cdfc08e52dc4540a1b424ebfbfe50 100644 (file)
@@ -235,16 +235,40 @@ xfs_rtsumoffs_to_infoword(
 }
 
 /* Return a pointer to a summary info word within a rt summary block. */
-static inline xfs_suminfo_t *
+static inline union xfs_suminfo_raw *
 xfs_rsumblock_infoptr(
        struct xfs_buf          *bp,
        unsigned int            index)
 {
-       xfs_suminfo_t           *info = bp->b_addr;
+       union xfs_suminfo_raw   *info = bp->b_addr;
 
        return info + index;
 }
 
+/* Get the current value of a summary counter. */
+static inline xfs_suminfo_t
+xfs_suminfo_get(
+       struct xfs_buf          *bp,
+       unsigned int            index)
+{
+       union xfs_suminfo_raw   *info = xfs_rsumblock_infoptr(bp, index);
+
+       return info->old;
+}
+
+/* Add to the current value of a summary counter and return the new value. */
+static inline xfs_suminfo_t
+xfs_suminfo_add(
+       struct xfs_buf          *bp,
+       unsigned int            index,
+       int                     delta)
+{
+       union xfs_suminfo_raw   *info = xfs_rsumblock_infoptr(bp, index);
+
+       info->old += delta;
+       return info->old;
+}
+
 /*
  * Functions for walking free space rtextents in the realtime bitmap.
  */