diff options
author | Dave Chinner <dchinner@redhat.com> | 2023-02-12 23:14:54 +0100 |
---|---|---|
committer | Dave Chinner <dchinner@redhat.com> | 2023-02-12 23:14:54 +0100 |
commit | 8b81356825ffb96b3b167b4dabbbbdb506bb0e0b (patch) | |
tree | 840748e7d638bc622a8d634bfe82b44fd6d49b75 /fs/xfs/libxfs/xfs_alloc.c | |
parent | xfs: fold xfs_alloc_ag_vextent() into callers (diff) | |
download | linux-8b81356825ffb96b3b167b4dabbbbdb506bb0e0b.tar.xz linux-8b81356825ffb96b3b167b4dabbbbdb506bb0e0b.zip |
xfs: move the minimum agno checks into xfs_alloc_vextent_check_args
All of the allocation functions now extract the minimum allowed AG
from the transaction and then use it in some way. The allocation
functions that are restricted to a single AG all check if the
AG requested can be allocated from and return an error if so. These
all set args->agno appropriately.
All the allocation functions that iterate AGs use it to calculate
the scan start AG. args->agno is not set until the iterator starts
walking AGs.
Hence we can easily set up a conditional check against the minimum
AG allowed in xfs_alloc_vextent_check_args() based on whether
args->agno contains NULLAGNUMBER or not and move all the repeated
setup code to xfs_alloc_vextent_check_args(), further simplifying
the allocation functions.
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Diffstat (limited to 'fs/xfs/libxfs/xfs_alloc.c')
-rw-r--r-- | fs/xfs/libxfs/xfs_alloc.c | 88 |
1 files changed, 33 insertions, 55 deletions
diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c index 50eb44851f23..94cea96caf5d 100644 --- a/fs/xfs/libxfs/xfs_alloc.c +++ b/fs/xfs/libxfs/xfs_alloc.c @@ -3089,14 +3089,18 @@ xfs_alloc_read_agf( static int xfs_alloc_vextent_check_args( struct xfs_alloc_arg *args, - xfs_fsblock_t target) + xfs_fsblock_t target, + xfs_agnumber_t *minimum_agno) { struct xfs_mount *mp = args->mp; xfs_agblock_t agsize; - args->agbno = NULLAGBLOCK; args->fsbno = NULLFSBLOCK; + *minimum_agno = 0; + if (args->tp->t_highest_agno != NULLAGNUMBER) + *minimum_agno = args->tp->t_highest_agno; + /* * Just fix this up, for the case where the last a.g. is shorter * (or there's only one a.g.) and the caller couldn't easily figure @@ -3123,11 +3127,16 @@ xfs_alloc_vextent_check_args( XFS_FSB_TO_AGBNO(mp, target) >= agsize || args->minlen > args->maxlen || args->minlen > agsize || args->mod >= args->prod) { - args->fsbno = NULLFSBLOCK; trace_xfs_alloc_vextent_badargs(args); return -ENOSPC; } + + if (args->agno != NULLAGNUMBER && *minimum_agno > args->agno) { + trace_xfs_alloc_vextent_skip_deadlock(args); + return -ENOSPC; + } return 0; + } /* @@ -3266,28 +3275,19 @@ xfs_alloc_vextent_this_ag( xfs_agnumber_t agno) { struct xfs_mount *mp = args->mp; - xfs_agnumber_t minimum_agno = 0; + xfs_agnumber_t minimum_agno; int error; - if (args->tp->t_highest_agno != NULLAGNUMBER) - minimum_agno = args->tp->t_highest_agno; - - if (minimum_agno > agno) { - trace_xfs_alloc_vextent_skip_deadlock(args); - args->fsbno = NULLFSBLOCK; - return 0; - } - - error = xfs_alloc_vextent_check_args(args, XFS_AGB_TO_FSB(mp, agno, 0)); + args->agno = agno; + args->agbno = 0; + error = xfs_alloc_vextent_check_args(args, XFS_AGB_TO_FSB(mp, agno, 0), + &minimum_agno); if (error) { if (error == -ENOSPC) return 0; return error; } - args->agno = agno; - args->agbno = 0; - error = xfs_alloc_vextent_prepare_ag(args); if (!error && args->agbp) error = xfs_alloc_ag_vextent_size(args); @@ -3400,16 +3400,15 @@ xfs_alloc_vextent_start_ag( xfs_fsblock_t target) { struct xfs_mount *mp = args->mp; - xfs_agnumber_t minimum_agno = 0; + xfs_agnumber_t minimum_agno; xfs_agnumber_t start_agno; xfs_agnumber_t rotorstep = xfs_rotorstep; bool bump_rotor = false; int error; - if (args->tp->t_highest_agno != NULLAGNUMBER) - minimum_agno = args->tp->t_highest_agno; - - error = xfs_alloc_vextent_check_args(args, target); + args->agno = NULLAGNUMBER; + args->agbno = NULLAGBLOCK; + error = xfs_alloc_vextent_check_args(args, target, &minimum_agno); if (error) { if (error == -ENOSPC) return 0; @@ -3451,14 +3450,13 @@ xfs_alloc_vextent_first_ag( xfs_fsblock_t target) { struct xfs_mount *mp = args->mp; - xfs_agnumber_t minimum_agno = 0; + xfs_agnumber_t minimum_agno; xfs_agnumber_t start_agno; int error; - if (args->tp->t_highest_agno != NULLAGNUMBER) - minimum_agno = args->tp->t_highest_agno; - - error = xfs_alloc_vextent_check_args(args, target); + args->agno = NULLAGNUMBER; + args->agbno = NULLAGBLOCK; + error = xfs_alloc_vextent_check_args(args, target, &minimum_agno); if (error) { if (error == -ENOSPC) return 0; @@ -3481,28 +3479,18 @@ xfs_alloc_vextent_exact_bno( xfs_fsblock_t target) { struct xfs_mount *mp = args->mp; - xfs_agnumber_t minimum_agno = 0; + xfs_agnumber_t minimum_agno; int error; - if (args->tp->t_highest_agno != NULLAGNUMBER) - minimum_agno = args->tp->t_highest_agno; - - error = xfs_alloc_vextent_check_args(args, target); + args->agno = XFS_FSB_TO_AGNO(mp, target); + args->agbno = XFS_FSB_TO_AGBNO(mp, target); + error = xfs_alloc_vextent_check_args(args, target, &minimum_agno); if (error) { if (error == -ENOSPC) return 0; return error; } - args->agno = XFS_FSB_TO_AGNO(mp, target); - if (minimum_agno > args->agno) { - trace_xfs_alloc_vextent_skip_deadlock(args); - args->fsbno = NULLFSBLOCK; - return 0; - } - - args->agbno = XFS_FSB_TO_AGBNO(mp, target); - error = xfs_alloc_vextent_prepare_ag(args); if (!error && args->agbp) error = xfs_alloc_ag_vextent_exact(args); @@ -3522,32 +3510,22 @@ xfs_alloc_vextent_near_bno( xfs_fsblock_t target) { struct xfs_mount *mp = args->mp; - xfs_agnumber_t minimum_agno = 0; + xfs_agnumber_t minimum_agno; bool needs_perag = args->pag == NULL; int error; - if (args->tp->t_highest_agno != NULLAGNUMBER) - minimum_agno = args->tp->t_highest_agno; - - error = xfs_alloc_vextent_check_args(args, target); + args->agno = XFS_FSB_TO_AGNO(mp, target); + args->agbno = XFS_FSB_TO_AGBNO(mp, target); + error = xfs_alloc_vextent_check_args(args, target, &minimum_agno); if (error) { if (error == -ENOSPC) return 0; return error; } - args->agno = XFS_FSB_TO_AGNO(mp, target); - if (minimum_agno > args->agno) { - trace_xfs_alloc_vextent_skip_deadlock(args); - args->fsbno = NULLFSBLOCK; - return 0; - } - if (needs_perag) args->pag = xfs_perag_get(mp, args->agno); - args->agbno = XFS_FSB_TO_AGBNO(mp, target); - error = xfs_alloc_vextent_prepare_ag(args); if (!error && args->agbp) error = xfs_alloc_ag_vextent_near(args); |