]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: make xfs_rtalloc_query_range input parameters const
authorDarrick J. Wong <djwong@kernel.org>
Mon, 31 Jan 2022 20:25:47 +0000 (15:25 -0500)
committerEric Sandeen <sandeen@redhat.com>
Mon, 31 Jan 2022 20:25:47 +0000 (15:25 -0500)
Source kernel commit: c02f6529864a4f5f91d216d324bac4ba75415d19

In commit 8ad560d2565e, we changed xfs_rtalloc_query_range to constrain
the range of bits in the realtime bitmap file that would actually be
searched.  In commit a3a374bf1889, we changed the range again
(incorrectly), leading to the fix in commit d88850bd5516, which finally
corrected the range check code.  Unfortunately, the author never noticed
that the function modifies its input parameters, which is a totaly no-no
since none of the other range query functions change their input
parameters.

So, fix this function yet again to stash the upper end of the query
range (i.e. the high key) in a local variable and hope this is the last
time I have to fix my own function.  While we're at it, mark the key
inputs const so nobody makes this mistake again. :(

Fixes: 8ad560d2565e ("xfs: strengthen rtalloc query range checks")
Not-fixed-by: a3a374bf1889 ("xfs: fix off-by-one error in xfs_rtalloc_query_range")
Not-fixed-by: d88850bd5516 ("xfs: fix high key handling in the rt allocator's query_range function")
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Chandan Babu R <chandanrlinux@gmail.com>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
libxfs/libxfs_priv.h
libxfs/xfs_rtbitmap.c

index 15bae1ffde885edfe63c0f4992a1e0c3b7f6963b..0214919c61f2606d9a5693eb4145767130601473 100644 (file)
@@ -602,9 +602,9 @@ struct xfs_rtalloc_rec {
 };
 
 typedef int (*xfs_rtalloc_query_range_fn)(
-       struct xfs_trans        *tp,
-       struct xfs_rtalloc_rec  *rec,
-       void                    *priv);
+       struct xfs_trans                *tp,
+       const struct xfs_rtalloc_rec    *rec,
+       void                            *priv);
 
 int libxfs_zero_extent(struct xfs_inode *ip, xfs_fsblock_t start_fsb,
                         xfs_off_t count_fsb);
@@ -698,8 +698,8 @@ int xfs_rtfree_range(struct xfs_mount *mp, struct xfs_trans *tp,
                     xfs_rtblock_t start, xfs_extlen_t len,
                     struct xfs_buf **rbpp, xfs_fsblock_t *rsb);
 int xfs_rtalloc_query_range(struct xfs_trans *tp,
-                           struct xfs_rtalloc_rec *low_rec,
-                           struct xfs_rtalloc_rec *high_rec,
+                           const struct xfs_rtalloc_rec *low_rec,
+                           const struct xfs_rtalloc_rec *high_rec,
                            xfs_rtalloc_query_range_fn fn,
                            void *priv);
 int xfs_rtalloc_query_all(struct xfs_trans *tp,
index f08efb7c38899d0b50dc272e27d484019777bcd6..15da049616e52fdfd701c5fc08427ba1cbf46f3b 100644 (file)
@@ -1007,8 +1007,8 @@ xfs_rtfree_extent(
 int
 xfs_rtalloc_query_range(
        struct xfs_trans                *tp,
-       struct xfs_rtalloc_rec          *low_rec,
-       struct xfs_rtalloc_rec          *high_rec,
+       const struct xfs_rtalloc_rec    *low_rec,
+       const struct xfs_rtalloc_rec    *high_rec,
        xfs_rtalloc_query_range_fn      fn,
        void                            *priv)
 {
@@ -1016,6 +1016,7 @@ xfs_rtalloc_query_range(
        struct xfs_mount                *mp = tp->t_mountp;
        xfs_rtblock_t                   rtstart;
        xfs_rtblock_t                   rtend;
+       xfs_rtblock_t                   high_key;
        int                             is_free;
        int                             error = 0;
 
@@ -1024,12 +1025,12 @@ xfs_rtalloc_query_range(
        if (low_rec->ar_startext >= mp->m_sb.sb_rextents ||
            low_rec->ar_startext == high_rec->ar_startext)
                return 0;
-       high_rec->ar_startext = min(high_rec->ar_startext,
-                       mp->m_sb.sb_rextents - 1);
+
+       high_key = min(high_rec->ar_startext, mp->m_sb.sb_rextents - 1);
 
        /* Iterate the bitmap, looking for discrepancies. */
        rtstart = low_rec->ar_startext;
-       while (rtstart <= high_rec->ar_startext) {
+       while (rtstart <= high_key) {
                /* Is the first block free? */
                error = xfs_rtcheck_range(mp, tp, rtstart, 1, 1, &rtend,
                                &is_free);
@@ -1037,8 +1038,7 @@ xfs_rtalloc_query_range(
                        break;
 
                /* How long does the extent go for? */
-               error = xfs_rtfind_forw(mp, tp, rtstart,
-                               high_rec->ar_startext, &rtend);
+               error = xfs_rtfind_forw(mp, tp, rtstart, high_key, &rtend);
                if (error)
                        break;