aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Chinner <dchinner@redhat.com>2023-05-09 11:30:41 +0200
committerCarlos Maiolino <cem@kernel.org>2023-05-10 14:47:14 +0200
commit4ccd9b2fe3f4db00e4270ad3ab4a082488a160a8 (patch)
treeb7ab69c2a5a8bf685b03010ad1040030e7d9fee6
parent451b902f95add9e87681ad27ce5693c4b7efb182 (diff)
downloadxfsprogs-dev-4ccd9b2fe3f4db00e4270ad3ab4a082488a160a8.tar.gz
xfs: get rid of notinit from xfs_bmap_longest_free_extent
Source kernel commit: 6b637ad0c7be85ecb795697ea51051039b753da2 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. 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. Hence not_init can go away, because we only use if blen is good from the scanned AGs otherwise we ignore it altogether and use minlen. Signed-off-by: Dave Chinner <dchinner@redhat.com> Reviewed-by: Darrick J. Wong <djwong@kernel.org> Signed-off-by: Carlos Maiolino <cem@kernel.org>
-rw-r--r--libxfs/xfs_bmap.c85
1 files changed, 37 insertions, 48 deletions
diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c
index e788e33e5d..844385bf49 100644
--- a/libxfs/xfs_bmap.c
+++ b/libxfs/xfs_bmap.c
@@ -3132,8 +3132,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;
@@ -3141,14 +3140,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,
@@ -3160,32 +3153,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
@@ -3197,7 +3186,6 @@ xfs_bmap_btalloc_select_lengths(
struct xfs_mount *mp = args->mp;
struct xfs_perag *pag;
xfs_agnumber_t agno, startag;
- int notinit = 0;
int error = 0;
if (ap->tp->t_flags & XFS_TRANS_LOWMODE) {
@@ -3213,17 +3201,17 @@ xfs_bmap_btalloc_select_lengths(
*blen = 0;
for_each_perag_wrap(mp, startag, agno, pag) {
- error = xfs_bmap_longest_free_extent(pag, args->tp, blen,
- &notinit);
- if (error)
+ error = xfs_bmap_longest_free_extent(pag, args->tp, blen);
+ if (error && error != -EAGAIN)
break;
+ error = 0;
if (*blen >= args->maxlen)
break;
}
if (pag)
xfs_perag_rele(pag);
- xfs_bmap_select_minlen(ap, args, blen, notinit);
+ args->minlen = xfs_bmap_select_minlen(ap, args, *blen);
return error;
}
@@ -3236,7 +3224,6 @@ xfs_bmap_btalloc_filestreams_select_lengths(
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;
@@ -3247,11 +3234,13 @@ xfs_bmap_btalloc_filestreams_select_lengths(
pag = xfs_perag_grab(mp, start_agno);
if (pag) {
- error = xfs_bmap_longest_free_extent(pag, args->tp, blen,
- &notinit);
+ 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) {
@@ -3267,18 +3256,18 @@ xfs_bmap_btalloc_filestreams_select_lengths(
if (!pag)
goto out_select;
- error = xfs_bmap_longest_free_extent(pag, args->tp,
- blen, &notinit);
+ 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