]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: return a referenced perag from filestreams allocator
authorDave Chinner <dchinner@redhat.com>
Tue, 9 May 2023 09:30:46 +0000 (11:30 +0200)
committerCarlos Maiolino <cem@kernel.org>
Wed, 10 May 2023 13:00:44 +0000 (15:00 +0200)
Source kernel commit: f8f1ed1ab3babad46b25e2dbe8de43b33fe7aaa6

Now that the filestreams AG selection tracks active perags, we need
to return an active perag to the core allocator code. This is
because the file allocation the filestreams code will run are AG
specific allocations and so need to pin the AG until the allocations
complete.

We cannot rely on the filestreams item reference to do this - the
filestreams association can be torn down at any time, hence we
need to have a separate reference for the allocation process to pin
the AG after it has been selected.

This means there is some perag juggling in allocation failure
fallback paths as they will do all AG scans in the case the AG
specific allocation fails. Hence we need to track the perag
reference that the filestream allocator returned to make sure we
don't leak it on repeated allocation failure.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
libxfs/xfs_bmap.c

index 00836b0243849326e1125179081dbb156d5c117a..76591d077661205d4167608ffdd19f235c9e4cdf 100644 (file)
@@ -3421,6 +3421,7 @@ xfs_bmap_btalloc_at_eof(
        bool                    ag_only)
 {
        struct xfs_mount        *mp = args->mp;
+       struct xfs_perag        *caller_pag = args->pag;
        int                     error;
 
        /*
@@ -3448,9 +3449,11 @@ xfs_bmap_btalloc_at_eof(
                else
                        args->minalignslop = 0;
 
-               args->pag = xfs_perag_get(mp, XFS_FSB_TO_AGNO(mp, ap->blkno));
+               if (!caller_pag)
+                       args->pag = xfs_perag_get(mp, XFS_FSB_TO_AGNO(mp, ap->blkno));
                error = xfs_alloc_vextent_exact_bno(args, ap->blkno);
-               xfs_perag_put(args->pag);
+               if (!caller_pag)
+                       xfs_perag_put(args->pag);
                if (error)
                        return error;
 
@@ -3476,10 +3479,14 @@ xfs_bmap_btalloc_at_eof(
                args->minalignslop = 0;
        }
 
-       if (ag_only)
+       if (ag_only) {
                error = xfs_alloc_vextent_near_bno(args, ap->blkno);
-       else
+       } else {
+               args->pag = NULL;
                error = xfs_alloc_vextent_start_ag(args, ap->blkno);
+               ASSERT(args->pag == NULL);
+               args->pag = caller_pag;
+       }
        if (error)
                return error;
 
@@ -3538,12 +3545,13 @@ xfs_bmap_btalloc_filestreams(
        int                     stripe_align)
 {
        xfs_extlen_t            blen = 0;
-       int                     error;
+       int                     error = 0;
 
 
        error = xfs_filestream_select_ag(ap, args, &blen);
        if (error)
                return error;
+       ASSERT(args->pag);
 
        /*
         * If we are in low space mode, then optimal allocation will fail so
@@ -3552,22 +3560,31 @@ xfs_bmap_btalloc_filestreams(
         */
        if (ap->tp->t_flags & XFS_TRANS_LOWMODE) {
                args->minlen = ap->minlen;
+               ASSERT(args->fsbno == NULLFSBLOCK);
                goto out_low_space;
        }
 
        args->minlen = xfs_bmap_select_minlen(ap, args, blen);
-       if (ap->aeof) {
+       if (ap->aeof)
                error = xfs_bmap_btalloc_at_eof(ap, args, blen, stripe_align,
                                true);
-               if (error || args->fsbno != NULLFSBLOCK)
-                       return error;
-       }
 
-       error = xfs_alloc_vextent_near_bno(args, ap->blkno);
+       if (!error && args->fsbno == NULLFSBLOCK)
+               error = xfs_alloc_vextent_near_bno(args, ap->blkno);
+
+out_low_space:
+       /*
+        * We are now done with the perag reference for the filestreams
+        * association provided by xfs_filestream_select_ag(). Release it now as
+        * we've either succeeded, had a fatal error or we are out of space and
+        * need to do a full filesystem scan for free space which will take it's
+        * own references.
+        */
+       xfs_perag_rele(args->pag);
+       args->pag = NULL;
        if (error || args->fsbno != NULLFSBLOCK)
                return error;
 
-out_low_space:
        return xfs_bmap_btalloc_low_space(ap, args);
 }