Commit 5f36b2ce authored by Dave Chinner's avatar Dave Chinner

xfs: introduce xfs_alloc_vextent_exact_bno()

Two of the callers to xfs_alloc_vextent_this_ag() actually want
exact block number allocation, not anywhere-in-ag allocation. Split
this out from _this_ag() as a first class citizen so no external
extent allocation code needs to care about args->type anymore.
Signed-off-by: default avatarDave Chinner <dchinner@redhat.com>
Reviewed-by: default avatarDarrick J. Wong <djwong@kernel.org>
parent db4710fd
...@@ -888,7 +888,6 @@ xfs_ag_shrink_space( ...@@ -888,7 +888,6 @@ xfs_ag_shrink_space(
.tp = *tpp, .tp = *tpp,
.mp = mp, .mp = mp,
.pag = pag, .pag = pag,
.type = XFS_ALLOCTYPE_THIS_BNO,
.minlen = delta, .minlen = delta,
.maxlen = delta, .maxlen = delta,
.oinfo = XFS_RMAP_OINFO_SKIP_UPDATE, .oinfo = XFS_RMAP_OINFO_SKIP_UPDATE,
...@@ -920,8 +919,6 @@ xfs_ag_shrink_space( ...@@ -920,8 +919,6 @@ xfs_ag_shrink_space(
if (delta >= aglen) if (delta >= aglen)
return -EINVAL; return -EINVAL;
args.fsbno = XFS_AGB_TO_FSB(mp, pag->pag_agno, aglen - delta);
/* /*
* Make sure that the last inode cluster cannot overlap with the new * Make sure that the last inode cluster cannot overlap with the new
* end of the AG, even if it's sparse. * end of the AG, even if it's sparse.
...@@ -939,7 +936,8 @@ xfs_ag_shrink_space( ...@@ -939,7 +936,8 @@ xfs_ag_shrink_space(
return error; return error;
/* internal log shouldn't also show up in the free space btrees */ /* internal log shouldn't also show up in the free space btrees */
error = xfs_alloc_vextent_this_ag(&args); error = xfs_alloc_vextent_exact_bno(&args,
XFS_AGB_TO_FSB(mp, pag->pag_agno, aglen - delta));
if (!error && args.agbno == NULLAGBLOCK) if (!error && args.agbno == NULLAGBLOCK)
error = -ENOSPC; error = -ENOSPC;
......
...@@ -3272,28 +3272,34 @@ xfs_alloc_vextent_set_fsbno( ...@@ -3272,28 +3272,34 @@ xfs_alloc_vextent_set_fsbno(
*/ */
int int
xfs_alloc_vextent_this_ag( xfs_alloc_vextent_this_ag(
struct xfs_alloc_arg *args) struct xfs_alloc_arg *args,
xfs_agnumber_t agno)
{ {
struct xfs_mount *mp = args->mp; struct xfs_mount *mp = args->mp;
xfs_agnumber_t minimum_agno = 0; xfs_agnumber_t minimum_agno = 0;
xfs_rfsblock_t target = XFS_AGB_TO_FSB(mp, agno, 0);
int error; int error;
if (args->tp->t_highest_agno != NULLAGNUMBER) if (args->tp->t_highest_agno != NULLAGNUMBER)
minimum_agno = args->tp->t_highest_agno; minimum_agno = args->tp->t_highest_agno;
error = xfs_alloc_vextent_check_args(args, args->fsbno); if (minimum_agno > agno) {
trace_xfs_alloc_vextent_skip_deadlock(args);
args->fsbno = NULLFSBLOCK;
return 0;
}
error = xfs_alloc_vextent_check_args(args, target);
if (error) { if (error) {
if (error == -ENOSPC) if (error == -ENOSPC)
return 0; return 0;
return error; return error;
} }
args->agno = XFS_FSB_TO_AGNO(mp, args->fsbno); args->agno = agno;
if (minimum_agno > args->agno) { args->agbno = 0;
trace_xfs_alloc_vextent_skip_deadlock(args); args->fsbno = target;
args->fsbno = NULLFSBLOCK; args->type = XFS_ALLOCTYPE_THIS_AG;
return 0;
}
error = xfs_alloc_ag_vextent(args); error = xfs_alloc_ag_vextent(args);
xfs_alloc_vextent_set_fsbno(args, minimum_agno); xfs_alloc_vextent_set_fsbno(args, minimum_agno);
...@@ -3472,12 +3478,51 @@ xfs_alloc_vextent_first_ag( ...@@ -3472,12 +3478,51 @@ xfs_alloc_vextent_first_ag(
start_agno = max(minimum_agno, XFS_FSB_TO_AGNO(mp, target)); start_agno = max(minimum_agno, XFS_FSB_TO_AGNO(mp, target));
args->type = XFS_ALLOCTYPE_THIS_AG; args->type = XFS_ALLOCTYPE_THIS_AG;
args->fsbno = target; args->fsbno = target;
error = xfs_alloc_vextent_iterate_ags(args, minimum_agno, error = xfs_alloc_vextent_iterate_ags(args, minimum_agno,
start_agno, 0); start_agno, 0);
xfs_alloc_vextent_set_fsbno(args, minimum_agno); xfs_alloc_vextent_set_fsbno(args, minimum_agno);
return error; return error;
} }
/*
* Allocate within a single AG only.
*/
int
xfs_alloc_vextent_exact_bno(
struct xfs_alloc_arg *args,
xfs_fsblock_t target)
{
struct xfs_mount *mp = args->mp;
xfs_agnumber_t minimum_agno = 0;
int error;
if (args->tp->t_highest_agno != NULLAGNUMBER)
minimum_agno = args->tp->t_highest_agno;
error = xfs_alloc_vextent_check_args(args, target);
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);
return 0;
}
args->agbno = XFS_FSB_TO_AGBNO(mp, target);
args->fsbno = target;
args->type = XFS_ALLOCTYPE_THIS_BNO;
error = xfs_alloc_ag_vextent(args);
if (error)
return error;
xfs_alloc_vextent_set_fsbno(args, minimum_agno);
return 0;
}
/* /*
* Allocate an extent as close to the target as possible. If there are not * Allocate an extent as close to the target as possible. If there are not
* viable candidates in the AG, then fail the allocation. * viable candidates in the AG, then fail the allocation.
......
...@@ -114,10 +114,10 @@ xfs_alloc_log_agf( ...@@ -114,10 +114,10 @@ xfs_alloc_log_agf(
uint32_t fields);/* mask of fields to be logged (XFS_AGF_...) */ uint32_t fields);/* mask of fields to be logged (XFS_AGF_...) */
/* /*
* Allocate an extent in the specific AG defined by args->fsbno. If there is no * Allocate an extent anywhere in the specific AG given. If there is no
* space in that AG, then the allocation will fail. * space matching the requirements in that AG, then the allocation will fail.
*/ */
int xfs_alloc_vextent_this_ag(struct xfs_alloc_arg *args); int xfs_alloc_vextent_this_ag(struct xfs_alloc_arg *args, xfs_agnumber_t agno);
/* /*
* Allocate an extent as close to the target as possible. If there are not * Allocate an extent as close to the target as possible. If there are not
...@@ -126,6 +126,13 @@ int xfs_alloc_vextent_this_ag(struct xfs_alloc_arg *args); ...@@ -126,6 +126,13 @@ int xfs_alloc_vextent_this_ag(struct xfs_alloc_arg *args);
int xfs_alloc_vextent_near_bno(struct xfs_alloc_arg *args, int xfs_alloc_vextent_near_bno(struct xfs_alloc_arg *args,
xfs_fsblock_t target); xfs_fsblock_t target);
/*
* Allocate an extent exactly at the target given. If this is not possible
* then the allocation fails.
*/
int xfs_alloc_vextent_exact_bno(struct xfs_alloc_arg *args,
xfs_fsblock_t target);
/* /*
* Best effort full filesystem allocation scan. * Best effort full filesystem allocation scan.
* *
......
...@@ -3514,7 +3514,6 @@ xfs_bmap_btalloc_at_eof( ...@@ -3514,7 +3514,6 @@ xfs_bmap_btalloc_at_eof(
xfs_extlen_t nextminlen = 0; xfs_extlen_t nextminlen = 0;
atype = args->type; atype = args->type;
args->type = XFS_ALLOCTYPE_THIS_BNO;
args->alignment = 1; args->alignment = 1;
/* /*
...@@ -3532,8 +3531,8 @@ xfs_bmap_btalloc_at_eof( ...@@ -3532,8 +3531,8 @@ xfs_bmap_btalloc_at_eof(
else else
args->minalignslop = 0; args->minalignslop = 0;
args->pag = xfs_perag_get(mp, XFS_FSB_TO_AGNO(mp, args->fsbno)); args->pag = xfs_perag_get(mp, XFS_FSB_TO_AGNO(mp, ap->blkno));
error = xfs_alloc_vextent_this_ag(args); error = xfs_alloc_vextent_exact_bno(args, ap->blkno);
xfs_perag_put(args->pag); xfs_perag_put(args->pag);
if (error) if (error)
return error; return error;
...@@ -3546,7 +3545,6 @@ xfs_bmap_btalloc_at_eof( ...@@ -3546,7 +3545,6 @@ xfs_bmap_btalloc_at_eof(
*/ */
args->pag = NULL; args->pag = NULL;
args->type = atype; args->type = atype;
args->fsbno = ap->blkno;
args->alignment = stripe_align; args->alignment = stripe_align;
args->minlen = nextminlen; args->minlen = nextminlen;
args->minalignslop = 0; args->minalignslop = 0;
......
...@@ -662,8 +662,6 @@ xfs_ialloc_ag_alloc( ...@@ -662,8 +662,6 @@ xfs_ialloc_ag_alloc(
goto sparse_alloc; goto sparse_alloc;
if (likely(newino != NULLAGINO && if (likely(newino != NULLAGINO &&
(args.agbno < be32_to_cpu(agi->agi_length)))) { (args.agbno < be32_to_cpu(agi->agi_length)))) {
args.fsbno = XFS_AGB_TO_FSB(args.mp, pag->pag_agno, args.agbno);
args.type = XFS_ALLOCTYPE_THIS_BNO;
args.prod = 1; args.prod = 1;
/* /*
...@@ -684,7 +682,9 @@ xfs_ialloc_ag_alloc( ...@@ -684,7 +682,9 @@ xfs_ialloc_ag_alloc(
/* Allow space for the inode btree to split. */ /* Allow space for the inode btree to split. */
args.minleft = igeo->inobt_maxlevels; args.minleft = igeo->inobt_maxlevels;
error = xfs_alloc_vextent_this_ag(&args); error = xfs_alloc_vextent_exact_bno(&args,
XFS_AGB_TO_FSB(args.mp, pag->pag_agno,
args.agbno));
if (error) if (error)
return error; return error;
......
...@@ -328,14 +328,12 @@ xrep_alloc_ag_block( ...@@ -328,14 +328,12 @@ xrep_alloc_ag_block(
args.mp = sc->mp; args.mp = sc->mp;
args.pag = sc->sa.pag; args.pag = sc->sa.pag;
args.oinfo = *oinfo; args.oinfo = *oinfo;
args.fsbno = XFS_AGB_TO_FSB(args.mp, sc->sa.pag->pag_agno, 0);
args.minlen = 1; args.minlen = 1;
args.maxlen = 1; args.maxlen = 1;
args.prod = 1; args.prod = 1;
args.type = XFS_ALLOCTYPE_THIS_AG;
args.resv = resv; args.resv = resv;
error = xfs_alloc_vextent_this_ag(&args); error = xfs_alloc_vextent_this_ag(&args, sc->sa.pag->pag_agno);
if (error) if (error)
return error; return error;
if (args.fsbno == NULLFSBLOCK) if (args.fsbno == NULLFSBLOCK)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment