]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: convert open-coded xfs_rtword_t pointer accesses to helper
authorDarrick J. Wong <djwong@kernel.org>
Mon, 12 Feb 2024 14:27:20 +0000 (15:27 +0100)
committerCarlos Maiolino <cem@kernel.org>
Thu, 15 Feb 2024 11:56:43 +0000 (12:56 +0100)
Source kernel commit: a9948626849c2c65dfd201b5e9d855e62937de61

There are a bunch of places where we use open-coded logic to find a
pointer to an xfs_rtword_t within a rt bitmap buffer.  Convert all that
to helper functions for better type safety.

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_rtbitmap.c
libxfs/xfs_rtbitmap.h

index 6776e45c18fe495e63153f6e22509b9e7dd8c4fe..fce88c7593b088819a0bbc2109701877e7d09fad 100644 (file)
@@ -101,7 +101,6 @@ xfs_rtfind_back(
        int             bit;            /* bit number in the word */
        xfs_fileoff_t   block;          /* bitmap block number */
        struct xfs_buf  *bp;            /* buf for the block */
-       xfs_rtword_t    *bufp;          /* starting word in buffer */
        int             error;          /* error value */
        xfs_rtxnum_t    firstbit;       /* first useful bit in the word */
        xfs_rtxnum_t    i;              /* current bit number rel. to start */
@@ -119,12 +118,12 @@ xfs_rtfind_back(
        if (error) {
                return error;
        }
-       bufp = bp->b_addr;
+
        /*
         * Get the first word's index & point to it.
         */
        word = xfs_rtx_to_rbmword(mp, start);
-       b = &bufp[word];
+       b = xfs_rbmblock_wordptr(bp, word);
        bit = (int)(start & (XFS_NBWORD - 1));
        len = start - limit + 1;
        /*
@@ -171,9 +170,9 @@ xfs_rtfind_back(
                        if (error) {
                                return error;
                        }
-                       bufp = bp->b_addr;
+
                        word = mp->m_blockwsize - 1;
-                       b = &bufp[word];
+                       b = xfs_rbmblock_wordptr(bp, word);
                } else {
                        /*
                         * Go on to the previous word in the buffer.
@@ -217,9 +216,9 @@ xfs_rtfind_back(
                        if (error) {
                                return error;
                        }
-                       bufp = bp->b_addr;
+
                        word = mp->m_blockwsize - 1;
-                       b = &bufp[word];
+                       b = xfs_rbmblock_wordptr(bp, word);
                } else {
                        /*
                         * Go on to the previous word in the buffer.
@@ -276,7 +275,6 @@ xfs_rtfind_forw(
        int             bit;            /* bit number in the word */
        xfs_fileoff_t   block;          /* bitmap block number */
        struct xfs_buf  *bp;            /* buf for the block */
-       xfs_rtword_t    *bufp;          /* starting word in buffer */
        int             error;          /* error value */
        xfs_rtxnum_t    i;              /* current bit number rel. to start */
        xfs_rtxnum_t    lastbit;        /* last useful bit in the word */
@@ -294,12 +292,12 @@ xfs_rtfind_forw(
        if (error) {
                return error;
        }
-       bufp = bp->b_addr;
+
        /*
         * Get the first word's index & point to it.
         */
        word = xfs_rtx_to_rbmword(mp, start);
-       b = &bufp[word];
+       b = xfs_rbmblock_wordptr(bp, word);
        bit = (int)(start & (XFS_NBWORD - 1));
        len = limit - start + 1;
        /*
@@ -345,8 +343,9 @@ xfs_rtfind_forw(
                        if (error) {
                                return error;
                        }
-                       b = bufp = bp->b_addr;
+
                        word = 0;
+                       b = xfs_rbmblock_wordptr(bp, word);
                } else {
                        /*
                         * Go on to the previous word in the buffer.
@@ -390,8 +389,9 @@ xfs_rtfind_forw(
                        if (error) {
                                return error;
                        }
-                       b = bufp = bp->b_addr;
+
                        word = 0;
+                       b = xfs_rbmblock_wordptr(bp, word);
                } else {
                        /*
                         * Go on to the next word in the buffer.
@@ -539,7 +539,6 @@ xfs_rtmodify_range(
        int             bit;            /* bit number in the word */
        xfs_fileoff_t   block;          /* bitmap block number */
        struct xfs_buf  *bp;            /* buf for the block */
-       xfs_rtword_t    *bufp;          /* starting word in buffer */
        int             error;          /* error value */
        xfs_rtword_t    *first;         /* first used word in the buffer */
        int             i;              /* current bit number rel. to start */
@@ -558,12 +557,12 @@ xfs_rtmodify_range(
        if (error) {
                return error;
        }
-       bufp = bp->b_addr;
+
        /*
         * Compute the starting word's address, and starting bit.
         */
        word = xfs_rtx_to_rbmword(mp, start);
-       first = b = &bufp[word];
+       first = b = xfs_rbmblock_wordptr(bp, word);
        bit = (int)(start & (XFS_NBWORD - 1));
        /*
         * 0 (allocated) => all zeroes; 1 (free) => all ones.
@@ -597,14 +596,15 @@ xfs_rtmodify_range(
                         * Get the next one.
                         */
                        xfs_trans_log_buf(tp, bp,
-                               (uint)((char *)first - (char *)bufp),
-                               (uint)((char *)b - (char *)bufp));
+                               (uint)((char *)first - (char *)bp->b_addr),
+                               (uint)((char *)b - (char *)bp->b_addr));
                        error = xfs_rtbuf_get(mp, tp, ++block, 0, &bp);
                        if (error) {
                                return error;
                        }
-                       first = b = bufp = bp->b_addr;
+
                        word = 0;
+                       first = b = xfs_rbmblock_wordptr(bp, word);
                } else {
                        /*
                         * Go on to the next word in the buffer
@@ -637,14 +637,15 @@ xfs_rtmodify_range(
                         * Get the next one.
                         */
                        xfs_trans_log_buf(tp, bp,
-                               (uint)((char *)first - (char *)bufp),
-                               (uint)((char *)b - (char *)bufp));
+                               (uint)((char *)first - (char *)bp->b_addr),
+                               (uint)((char *)b - (char *)bp->b_addr));
                        error = xfs_rtbuf_get(mp, tp, ++block, 0, &bp);
                        if (error) {
                                return error;
                        }
-                       first = b = bufp = bp->b_addr;
+
                        word = 0;
+                       first = b = xfs_rbmblock_wordptr(bp, word);
                } else {
                        /*
                         * Go on to the next word in the buffer
@@ -674,8 +675,9 @@ xfs_rtmodify_range(
         * Log any remaining changed bytes.
         */
        if (b > first)
-               xfs_trans_log_buf(tp, bp, (uint)((char *)first - (char *)bufp),
-                       (uint)((char *)b - (char *)bufp - 1));
+               xfs_trans_log_buf(tp, bp,
+                       (uint)((char *)first - (char *)bp->b_addr),
+                       (uint)((char *)b - (char *)bp->b_addr - 1));
        return 0;
 }
 
@@ -773,7 +775,6 @@ xfs_rtcheck_range(
        int             bit;            /* bit number in the word */
        xfs_fileoff_t   block;          /* bitmap block number */
        struct xfs_buf  *bp;            /* buf for the block */
-       xfs_rtword_t    *bufp;          /* starting word in buffer */
        int             error;          /* error value */
        xfs_rtxnum_t    i;              /* current bit number rel. to start */
        xfs_rtxnum_t    lastbit;        /* last useful bit in word */
@@ -792,12 +793,12 @@ xfs_rtcheck_range(
        if (error) {
                return error;
        }
-       bufp = bp->b_addr;
+
        /*
         * Compute the starting word's address, and starting bit.
         */
        word = xfs_rtx_to_rbmword(mp, start);
-       b = &bufp[word];
+       b = xfs_rbmblock_wordptr(bp, word);
        bit = (int)(start & (XFS_NBWORD - 1));
        /*
         * 0 (allocated) => all zero's; 1 (free) => all one's.
@@ -843,8 +844,9 @@ xfs_rtcheck_range(
                        if (error) {
                                return error;
                        }
-                       b = bufp = bp->b_addr;
+
                        word = 0;
+                       b = xfs_rbmblock_wordptr(bp, word);
                } else {
                        /*
                         * Go on to the next word in the buffer.
@@ -889,8 +891,9 @@ xfs_rtcheck_range(
                        if (error) {
                                return error;
                        }
-                       b = bufp = bp->b_addr;
+
                        word = 0;
+                       b = xfs_rbmblock_wordptr(bp, word);
                } else {
                        /*
                         * Go on to the next word in the buffer.
index a382b38c6c30dcc6350ae1b1025842f28cb433e8..3252ed217a6a63cdfa2ccc50b53959eeb9c93298 100644 (file)
@@ -158,6 +158,17 @@ xfs_rbmblock_to_rtx(
        return rbmoff << mp->m_blkbit_log;
 }
 
+/* Return a pointer to a bitmap word within a rt bitmap block. */
+static inline xfs_rtword_t *
+xfs_rbmblock_wordptr(
+       struct xfs_buf          *bp,
+       unsigned int            index)
+{
+       xfs_rtword_t            *words = bp->b_addr;
+
+       return words + index;
+}
+
 /*
  * Functions for walking free space rtextents in the realtime bitmap.
  */