Commit 8b813568 authored by Dave Chinner's avatar Dave Chinner

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: default avatarDave Chinner <dchinner@redhat.com>
Reviewed-by: default avatarDarrick J. Wong <djwong@kernel.org>
parent 230e8fe8
......@@ -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);
......
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