xfs: move small allocation helper

Move the small allocation helper further up in the file to avoid the
need for a function declaration. The remaining declarations will be
removed by followup patches. No functional changes.

Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
This commit is contained in:
Brian Foster 2019-06-28 19:30:19 -07:00 committed by Darrick J. Wong
parent 2a4f35f984
commit c63cdd4fc9
1 changed files with 94 additions and 96 deletions

View File

@ -41,8 +41,6 @@ struct workqueue_struct *xfs_alloc_wq;
STATIC int xfs_alloc_ag_vextent_exact(xfs_alloc_arg_t *);
STATIC int xfs_alloc_ag_vextent_near(xfs_alloc_arg_t *);
STATIC int xfs_alloc_ag_vextent_size(xfs_alloc_arg_t *);
STATIC int xfs_alloc_ag_vextent_small(xfs_alloc_arg_t *,
xfs_btree_cur_t *, xfs_agblock_t *, xfs_extlen_t *, int *);
/*
* Size of the AGFL. For CRC-enabled filesystes we steal a couple of slots in
@ -699,6 +697,100 @@ xfs_alloc_update_counters(
* Allocation group level functions.
*/
/*
* Deal with the case where only small freespaces remain. Either return the
* contents of the last freespace record, or allocate space from the freelist if
* there is nothing in the tree.
*/
STATIC int /* error */
xfs_alloc_ag_vextent_small(
struct xfs_alloc_arg *args, /* allocation argument structure */
struct xfs_btree_cur *ccur, /* optional by-size cursor */
xfs_agblock_t *fbnop, /* result block number */
xfs_extlen_t *flenp, /* result length */
int *stat) /* status: 0-freelist, 1-normal/none */
{
int error = 0;
xfs_agblock_t fbno = NULLAGBLOCK;
xfs_extlen_t flen = 0;
int i;
error = xfs_btree_decrement(ccur, 0, &i);
if (error)
goto error;
if (i) {
error = xfs_alloc_get_rec(ccur, &fbno, &flen, &i);
if (error)
goto error;
XFS_WANT_CORRUPTED_GOTO(args->mp, i == 1, error);
goto out;
}
if (args->minlen != 1 || args->alignment != 1 ||
args->resv == XFS_AG_RESV_AGFL ||
(be32_to_cpu(XFS_BUF_TO_AGF(args->agbp)->agf_flcount) <=
args->minleft))
goto out;
error = xfs_alloc_get_freelist(args->tp, args->agbp, &fbno, 0);
if (error)
goto error;
if (fbno == NULLAGBLOCK)
goto out;
xfs_extent_busy_reuse(args->mp, args->agno, fbno, 1,
xfs_alloc_allow_busy_reuse(args->datatype));
if (xfs_alloc_is_userdata(args->datatype)) {
struct xfs_buf *bp;
bp = xfs_btree_get_bufs(args->mp, args->tp, args->agno, fbno);
if (!bp) {
error = -EFSCORRUPTED;
goto error;
}
xfs_trans_binval(args->tp, bp);
}
args->len = 1;
args->agbno = fbno;
XFS_WANT_CORRUPTED_GOTO(args->mp,
fbno < be32_to_cpu(XFS_BUF_TO_AGF(args->agbp)->agf_length),
error);
args->wasfromfl = 1;
trace_xfs_alloc_small_freelist(args);
/*
* If we're feeding an AGFL block to something that doesn't live in the
* free space, we need to clear out the OWN_AG rmap.
*/
error = xfs_rmap_free(args->tp, args->agbp, args->agno, fbno, 1,
&XFS_RMAP_OINFO_AG);
if (error)
goto error;
*stat = 0;
return 0;
out:
/*
* Can't do the allocation, give up.
*/
if (flen < args->minlen) {
args->agbno = NULLAGBLOCK;
trace_xfs_alloc_small_notenough(args);
flen = 0;
}
*fbnop = fbno;
*flenp = flen;
*stat = 1;
trace_xfs_alloc_small_done(args);
return 0;
error:
trace_xfs_alloc_small_error(args);
return error;
}
/*
* Allocate a variable extent in the allocation group agno.
* Type and bno are used to determine where in the allocation group the
@ -1582,100 +1674,6 @@ out_nominleft:
return 0;
}
/*
* Deal with the case where only small freespaces remain. Either return the
* contents of the last freespace record, or allocate space from the freelist if
* there is nothing in the tree.
*/
STATIC int /* error */
xfs_alloc_ag_vextent_small(
struct xfs_alloc_arg *args, /* allocation argument structure */
struct xfs_btree_cur *ccur, /* optional by-size cursor */
xfs_agblock_t *fbnop, /* result block number */
xfs_extlen_t *flenp, /* result length */
int *stat) /* status: 0-freelist, 1-normal/none */
{
int error = 0;
xfs_agblock_t fbno = NULLAGBLOCK;
xfs_extlen_t flen = 0;
int i;
error = xfs_btree_decrement(ccur, 0, &i);
if (error)
goto error;
if (i) {
error = xfs_alloc_get_rec(ccur, &fbno, &flen, &i);
if (error)
goto error;
XFS_WANT_CORRUPTED_GOTO(args->mp, i == 1, error);
goto out;
}
if (args->minlen != 1 || args->alignment != 1 ||
args->resv == XFS_AG_RESV_AGFL ||
(be32_to_cpu(XFS_BUF_TO_AGF(args->agbp)->agf_flcount) <=
args->minleft))
goto out;
error = xfs_alloc_get_freelist(args->tp, args->agbp, &fbno, 0);
if (error)
goto error;
if (fbno == NULLAGBLOCK)
goto out;
xfs_extent_busy_reuse(args->mp, args->agno, fbno, 1,
xfs_alloc_allow_busy_reuse(args->datatype));
if (xfs_alloc_is_userdata(args->datatype)) {
struct xfs_buf *bp;
bp = xfs_btree_get_bufs(args->mp, args->tp, args->agno, fbno);
if (!bp) {
error = -EFSCORRUPTED;
goto error;
}
xfs_trans_binval(args->tp, bp);
}
args->len = 1;
args->agbno = fbno;
XFS_WANT_CORRUPTED_GOTO(args->mp,
fbno < be32_to_cpu(XFS_BUF_TO_AGF(args->agbp)->agf_length),
error);
args->wasfromfl = 1;
trace_xfs_alloc_small_freelist(args);
/*
* If we're feeding an AGFL block to something that doesn't live in the
* free space, we need to clear out the OWN_AG rmap.
*/
error = xfs_rmap_free(args->tp, args->agbp, args->agno, fbno, 1,
&XFS_RMAP_OINFO_AG);
if (error)
goto error;
*stat = 0;
return 0;
out:
/*
* Can't do the allocation, give up.
*/
if (flen < args->minlen) {
args->agbno = NULLAGBLOCK;
trace_xfs_alloc_small_notenough(args);
flen = 0;
}
*fbnop = fbno;
*flenp = flen;
*stat = 1;
trace_xfs_alloc_small_done(args);
return 0;
error:
trace_xfs_alloc_small_error(args);
return error;
}
/*
* Free the extent starting at agno/bno for length.
*/