xfs: clean up xfs_alloc_ag_vextent_exact
Use a goto label to consolidate all block not found cases, and add a tracepoint for them. Also clean up a few whitespace issues. Based on an earlier patch from Dave Chinner. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Alex Elder <aelder@sgi.com>
This commit is contained in:
parent
ecff71e677
commit
9f9baab38d
@ -1422,6 +1422,7 @@ DEFINE_EVENT(xfs_alloc_class, name, \
|
||||
TP_PROTO(struct xfs_alloc_arg *args), \
|
||||
TP_ARGS(args))
|
||||
DEFINE_ALLOC_EVENT(xfs_alloc_exact_done);
|
||||
DEFINE_ALLOC_EVENT(xfs_alloc_exact_notfound);
|
||||
DEFINE_ALLOC_EVENT(xfs_alloc_exact_error);
|
||||
DEFINE_ALLOC_EVENT(xfs_alloc_near_nominleft);
|
||||
DEFINE_ALLOC_EVENT(xfs_alloc_near_first);
|
||||
|
@ -577,61 +577,58 @@ xfs_alloc_ag_vextent_exact(
|
||||
xfs_extlen_t rlen; /* length of returned extent */
|
||||
|
||||
ASSERT(args->alignment == 1);
|
||||
|
||||
/*
|
||||
* Allocate/initialize a cursor for the by-number freespace btree.
|
||||
*/
|
||||
bno_cur = xfs_allocbt_init_cursor(args->mp, args->tp, args->agbp,
|
||||
args->agno, XFS_BTNUM_BNO);
|
||||
args->agno, XFS_BTNUM_BNO);
|
||||
|
||||
/*
|
||||
* Lookup bno and minlen in the btree (minlen is irrelevant, really).
|
||||
* Look for the closest free block <= bno, it must contain bno
|
||||
* if any free block does.
|
||||
*/
|
||||
if ((error = xfs_alloc_lookup_le(bno_cur, args->agbno, args->minlen, &i)))
|
||||
error = xfs_alloc_lookup_le(bno_cur, args->agbno, args->minlen, &i);
|
||||
if (error)
|
||||
goto error0;
|
||||
if (!i) {
|
||||
/*
|
||||
* Didn't find it, return null.
|
||||
*/
|
||||
xfs_btree_del_cursor(bno_cur, XFS_BTREE_NOERROR);
|
||||
args->agbno = NULLAGBLOCK;
|
||||
return 0;
|
||||
}
|
||||
if (!i)
|
||||
goto not_found;
|
||||
|
||||
/*
|
||||
* Grab the freespace record.
|
||||
*/
|
||||
if ((error = xfs_alloc_get_rec(bno_cur, &fbno, &flen, &i)))
|
||||
error = xfs_alloc_get_rec(bno_cur, &fbno, &flen, &i);
|
||||
if (error)
|
||||
goto error0;
|
||||
XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
|
||||
ASSERT(fbno <= args->agbno);
|
||||
minend = args->agbno + args->minlen;
|
||||
maxend = args->agbno + args->maxlen;
|
||||
fend = fbno + flen;
|
||||
|
||||
/*
|
||||
* Give up if the freespace isn't long enough for the minimum request.
|
||||
*/
|
||||
if (fend < minend) {
|
||||
xfs_btree_del_cursor(bno_cur, XFS_BTREE_NOERROR);
|
||||
args->agbno = NULLAGBLOCK;
|
||||
return 0;
|
||||
}
|
||||
if (fend < minend)
|
||||
goto not_found;
|
||||
|
||||
/*
|
||||
* End of extent will be smaller of the freespace end and the
|
||||
* maximal requested end.
|
||||
*/
|
||||
end = XFS_AGBLOCK_MIN(fend, maxend);
|
||||
/*
|
||||
*
|
||||
* Fix the length according to mod and prod if given.
|
||||
*/
|
||||
end = XFS_AGBLOCK_MIN(fend, maxend);
|
||||
args->len = end - args->agbno;
|
||||
xfs_alloc_fix_len(args);
|
||||
if (!xfs_alloc_fix_minleft(args)) {
|
||||
xfs_btree_del_cursor(bno_cur, XFS_BTREE_NOERROR);
|
||||
return 0;
|
||||
}
|
||||
if (!xfs_alloc_fix_minleft(args))
|
||||
goto not_found;
|
||||
|
||||
rlen = args->len;
|
||||
ASSERT(args->agbno + rlen <= fend);
|
||||
end = args->agbno + rlen;
|
||||
|
||||
/*
|
||||
* We are allocating agbno for rlen [agbno .. end]
|
||||
* Allocate/initialize a cursor for the by-size btree.
|
||||
@ -640,16 +637,25 @@ xfs_alloc_ag_vextent_exact(
|
||||
args->agno, XFS_BTNUM_CNT);
|
||||
ASSERT(args->agbno + args->len <=
|
||||
be32_to_cpu(XFS_BUF_TO_AGF(args->agbp)->agf_length));
|
||||
if ((error = xfs_alloc_fixup_trees(cnt_cur, bno_cur, fbno, flen,
|
||||
args->agbno, args->len, XFSA_FIXUP_BNO_OK))) {
|
||||
error = xfs_alloc_fixup_trees(cnt_cur, bno_cur, fbno, flen, args->agbno,
|
||||
args->len, XFSA_FIXUP_BNO_OK);
|
||||
if (error) {
|
||||
xfs_btree_del_cursor(cnt_cur, XFS_BTREE_ERROR);
|
||||
goto error0;
|
||||
}
|
||||
|
||||
xfs_btree_del_cursor(bno_cur, XFS_BTREE_NOERROR);
|
||||
xfs_btree_del_cursor(cnt_cur, XFS_BTREE_NOERROR);
|
||||
|
||||
trace_xfs_alloc_exact_done(args);
|
||||
args->wasfromfl = 0;
|
||||
trace_xfs_alloc_exact_done(args);
|
||||
return 0;
|
||||
|
||||
not_found:
|
||||
/* Didn't find it, return null. */
|
||||
xfs_btree_del_cursor(bno_cur, XFS_BTREE_NOERROR);
|
||||
args->agbno = NULLAGBLOCK;
|
||||
trace_xfs_alloc_exact_notfound(args);
|
||||
return 0;
|
||||
|
||||
error0:
|
||||
|
Loading…
Reference in New Issue
Block a user