]> www.infradead.org Git - users/hch/xfs.git/commitdiff
xfs: push the calls to xfs_rtallocate_range out to xfs_bmap_rtalloc
authorChristoph Hellwig <hch@lst.de>
Fri, 30 Aug 2024 22:36:56 +0000 (15:36 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Sun, 1 Sep 2024 15:58:19 +0000 (08:58 -0700)
Currently the various low-level RT allocator functions call into
xfs_rtallocate_range directly, which ties them into the locking protocol
for the RT bitmap.  As these helpers already return the allocated range,
lift the call to xfs_rtallocate_range into xfs_bmap_rtalloc so that it
happens as high as possible in the stack, which will simplify future
changes to the locking protocol.

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

index 64ba4bcf6e29344da4d879089034d2350746b6d9..59e599af74f492916c5f03d42d6a4a5a41838264 100644 (file)
@@ -259,9 +259,9 @@ xfs_rtallocate_extent_block(
                        /*
                         * i for maxlen is all free, allocate and return that.
                         */
-                       bestlen = maxlen;
-                       besti = i;
-                       goto allocate;
+                       *len = maxlen;
+                       *rtx = i;
+                       return 0;
                }
 
                /*
@@ -312,12 +312,8 @@ xfs_rtallocate_extent_block(
        }
 
        /*
-        * Allocate besti for bestlen & return that.
+        * Pick besti for bestlen & return that.
         */
-allocate:
-       error = xfs_rtallocate_range(args, besti, bestlen);
-       if (error)
-               return error;
        *len = bestlen;
        *rtx = besti;
        return 0;
@@ -371,12 +367,6 @@ xfs_rtallocate_extent_exact(
                }
        }
 
-       /*
-        * Allocate what we can and return it.
-        */
-       error = xfs_rtallocate_range(args, start, maxlen);
-       if (error)
-               return error;
        *len = maxlen;
        *rtx = start;
        return 0;
@@ -429,7 +419,6 @@ xfs_rtallocate_extent_near(
        if (error != -ENOSPC)
                return error;
 
-
        bbno = xfs_rtx_to_rbmblock(mp, start);
        i = 0;
        j = -1;
@@ -552,11 +541,11 @@ xfs_rtalloc_sumlevel(
        xfs_rtxnum_t            *rtx)   /* out: start rtext allocated */
 {
        xfs_fileoff_t           i;      /* bitmap block number */
+       int                     error;
 
        for (i = 0; i < args->mp->m_sb.sb_rbmblocks; i++) {
                xfs_suminfo_t   sum;    /* summary information for extents */
                xfs_rtxnum_t    n;      /* next rtext to be tried */
-               int             error;
 
                error = xfs_rtget_summary(args, l, i, &sum);
                if (error)
@@ -1467,9 +1456,12 @@ retry:
                error = xfs_rtallocate_extent_size(&args, raminlen,
                                ralen, &ralen, prod, &rtx);
        }
-       xfs_rtbuf_cache_relse(&args);
 
-       if (error == -ENOSPC) {
+       if (error) {
+               xfs_rtbuf_cache_relse(&args);
+               if (error != -ENOSPC)
+                       return error;
+
                if (align > mp->m_sb.sb_rextsize) {
                        /*
                         * We previously enlarged the request length to try to
@@ -1497,14 +1489,20 @@ retry:
                ap->length = 0;
                return 0;
        }
+
+       error = xfs_rtallocate_range(&args, rtx, ralen);
        if (error)
-               return error;
+               goto out_release;
 
        xfs_trans_mod_sb(ap->tp, ap->wasdel ?
                        XFS_TRANS_SB_RES_FREXTENTS : XFS_TRANS_SB_FREXTENTS,
                        -(long)ralen);
+
        ap->blkno = xfs_rtx_to_rtb(mp, rtx);
        ap->length = xfs_rtxlen_to_extlen(mp, ralen);
        xfs_bmap_alloc_account(ap);
-       return 0;
+
+out_release:
+       xfs_rtbuf_cache_relse(&args);
+       return error;
 }