From: Dave Chinner <dchinner@xxxxxxxxxx> It is only set if reading the AGF gets a EAGAIN error. Just return the EAGAIN error and handle that error in the callers. This means we can remove the not_init parameter from xfs_bmap_select_minlen(), too, because the use of not_init there is pessimistic. If we can't read the agf, it won't increase blen. Howeverm the only time we actually care whether we checked all the AGFs for contiguous free space is when the best length is less than the minimum allocation length. If not_init is set, then we ignore blen and set the minimum alloc length to the absolute minimum, not the best length we know already is present. However, if blen is less than the minimum, we're going to ignore it anyway, regardless of whether we scanned all the AGFs or not, so it does not matter if those unchecked AGFs have space in them or not. Hence not_init can go away, because we already know if blen is good from the scanned AGs, or if it is not good enough we ignore it regardless of whether we scanned all the AGs or not. Signed-off-by: Dave Chinner <dchinner@xxxxxxxxxx> --- fs/xfs/libxfs/xfs_bmap.c | 84 +++++++++++++++++----------------------- 1 file changed, 36 insertions(+), 48 deletions(-) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index c8045cca2ec6..94d284f7d1d1 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -3170,8 +3170,7 @@ static int xfs_bmap_longest_free_extent( struct xfs_perag *pag, struct xfs_trans *tp, - xfs_extlen_t *blen, - int *notinit) + xfs_extlen_t *blen) { xfs_extlen_t longest; int error = 0; @@ -3179,14 +3178,8 @@ xfs_bmap_longest_free_extent( if (!xfs_perag_initialised_agf(pag)) { error = xfs_alloc_read_agf(pag, tp, XFS_ALLOC_FLAG_TRYLOCK, NULL); - if (error) { - /* Couldn't lock the AGF, so skip this AG. */ - if (error == -EAGAIN) { - *notinit = 1; - error = 0; - } + if (error) return error; - } } longest = xfs_alloc_longest_free_extent(pag, @@ -3198,32 +3191,28 @@ xfs_bmap_longest_free_extent( return 0; } -static void +static xfs_extlen_t xfs_bmap_select_minlen( struct xfs_bmalloca *ap, struct xfs_alloc_arg *args, - xfs_extlen_t *blen, - int notinit) + xfs_extlen_t blen) { - if (notinit || *blen < ap->minlen) { - /* - * Since we did a BUF_TRYLOCK above, it is possible that - * there is space for this request. - */ - args->minlen = ap->minlen; - } else if (*blen < args->maxlen) { - /* - * If the best seen length is less than the request length, - * use the best as the minimum. - */ - args->minlen = *blen; - } else { - /* - * Otherwise we've seen an extent as big as maxlen, use that - * as the minimum. - */ - args->minlen = args->maxlen; - } + + /* + * Since we used XFS_ALLOC_FLAG_TRYLOCK in _longest_free_extent(), it is + * possible that there is enough contiguous free space for this request. + */ + if (blen < ap->minlen) + return ap->minlen; + + /* + * If the best seen length is less than the request length, + * use the best as the minimum, otherwise we've got the maxlen we + * were asked for. + */ + if (blen < args->maxlen) + return blen; + return args->maxlen; } STATIC int @@ -3235,7 +3224,6 @@ xfs_bmap_btalloc_filestreams( struct xfs_mount *mp = ap->ip->i_mount; struct xfs_perag *pag; xfs_agnumber_t start_agno; - int notinit = 0; int error; args->total = ap->total; @@ -3246,11 +3234,13 @@ xfs_bmap_btalloc_filestreams( pag = xfs_perag_grab(mp, start_agno); if (pag) { - error = xfs_bmap_longest_free_extent(pag, args->tp, blen, - ¬init); + error = xfs_bmap_longest_free_extent(pag, args->tp, blen); xfs_perag_rele(pag); - if (error) - return error; + if (error) { + if (error != -EAGAIN) + return error; + *blen = 0; + } } if (*blen < args->maxlen) { @@ -3266,18 +3256,18 @@ xfs_bmap_btalloc_filestreams( if (!pag) goto out_select; - error = xfs_bmap_longest_free_extent(pag, args->tp, - blen, ¬init); + error = xfs_bmap_longest_free_extent(pag, args->tp, blen); xfs_perag_rele(pag); - if (error) - return error; - + if (error) { + if (error != -EAGAIN) + return error; + *blen = 0; + } start_agno = agno; - } out_select: - xfs_bmap_select_minlen(ap, args, blen, notinit); + args->minlen = xfs_bmap_select_minlen(ap, args, *blen); /* * Set the failure fallback case to look in the selected AG as stream @@ -3666,7 +3656,6 @@ xfs_btalloc_nullfb_bestlen( struct xfs_mount *mp = args->mp; struct xfs_perag *pag; xfs_agnumber_t agno, startag; - int notinit = 0; int error = 0; args->total = ap->total; @@ -3677,9 +3666,8 @@ xfs_btalloc_nullfb_bestlen( *blen = 0; for_each_perag_wrap(mp, startag, agno, pag) { - error = xfs_bmap_longest_free_extent(pag, args->tp, blen, - ¬init); - if (error) + error = xfs_bmap_longest_free_extent(pag, args->tp, blen); + if (error && error != -EAGAIN) break; if (*blen >= args->maxlen) break; @@ -3687,7 +3675,7 @@ xfs_btalloc_nullfb_bestlen( if (pag) xfs_perag_rele(pag); - xfs_bmap_select_minlen(ap, args, blen, notinit); + args->minlen = xfs_bmap_select_minlen(ap, args, *blen); return 0; } -- 2.35.1