]> www.infradead.org Git - users/hch/xfs.git/commitdiff
xfs: clean up xfs_rtallocate_extent_exact a bit
authorDarrick J. Wong <djwong@kernel.org>
Fri, 30 Aug 2024 22:37:05 +0000 (15:37 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Sun, 1 Sep 2024 15:58:19 +0000 (08:58 -0700)
Before we start doing more surgery on the rt allocator, let's clean up
the exact allocator so that it doesn't change its arguments and uses the
helper introduced in the previous patch.

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

index 11c58f12bcb200644cdb732f3a3d75d19123e8e5..af357704895d79ca2d88b90a773604863211df46 100644 (file)
@@ -338,10 +338,10 @@ xfs_rtallocate_extent_exact(
        xfs_rtxlen_t            prod,   /* extent product factor */
        xfs_rtxnum_t            *rtx)   /* out: start rtext allocated */
 {
-       int                     error;
-       xfs_rtxlen_t            i;      /* extent length trimmed due to prod */
-       int                     isfree; /* extent is free */
        xfs_rtxnum_t            next;   /* next rtext to try (dummy) */
+       xfs_rtxlen_t            alloclen; /* candidate length */
+       int                     isfree; /* extent is free */
+       int                     error;
 
        ASSERT(minlen % prod == 0);
        ASSERT(maxlen % prod == 0);
@@ -352,25 +352,26 @@ xfs_rtallocate_extent_exact(
        if (error)
                return error;
 
-       if (!isfree) {
-               /*
-                * If not, allocate what there is, if it's at least minlen.
-                */
-               maxlen = next - start;
-               if (maxlen < minlen)
-                       return -ENOSPC;
-
-               /*
-                * Trim off tail of extent, if prod is specified.
-                */
-               if (prod > 1 && (i = maxlen % prod)) {
-                       maxlen -= i;
-                       if (maxlen < minlen)
-                               return -ENOSPC;
-               }
+       if (isfree) {
+               /* start to maxlen is all free; allocate it. */
+               *len = maxlen;
+               *rtx = start;
+               return 0;
        }
 
-       *len = maxlen;
+       /*
+        * If not, allocate what there is, if it's at least minlen.
+        */
+       alloclen = next - start;
+       if (alloclen < minlen)
+               return -ENOSPC;
+
+       /* Ensure alloclen is a multiple of prod. */
+       alloclen = xfs_rtalloc_align_len(alloclen, prod);
+       if (alloclen < minlen)
+               return -ENOSPC;
+
+       *len = alloclen;
        *rtx = start;
        return 0;
 }