aboutsummaryrefslogtreecommitdiff
path: root/fs/xfs
diff options
context:
space:
mode:
authorGravatar Dave Chinner <dchinner@redhat.com> 2023-02-13 09:14:55 +1100
committerGravatar Dave Chinner <dchinner@redhat.com> 2023-02-13 09:14:55 +1100
commit6b637ad0c7be85ecb795697ea51051039b753da2 (patch)
treed99c5abc704aedf3bf65bb846bc1207f0eead043 /fs/xfs
parentxfs: factor out filestreams from xfs_bmap_btalloc_nullfb (diff)
downloadlinux-6b637ad0c7be85ecb795697ea51051039b753da2.tar.gz
linux-6b637ad0c7be85ecb795697ea51051039b753da2.tar.bz2
linux-6b637ad0c7be85ecb795697ea51051039b753da2.zip
xfs: get rid of notinit from xfs_bmap_longest_free_extent
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>
Diffstat (limited to 'fs/xfs')
-rw-r--r--fs/xfs/libxfs/xfs_bmap.c85
1 files changed, 37 insertions, 48 deletions
diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
index 187200488ac0..89398172d8be 100644
--- a/fs/xfs/libxfs/xfs_bmap.c
+++ b/fs/xfs/libxfs/xfs_bmap.c
@@ -3139,8 +3139,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;
@@ -3148,14 +3147,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,
@@ -3167,32 +3160,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
@@ -3204,7 +3193,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) {
@@ -3220,17 +3208,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;
}
@@ -3243,7 +3231,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;
@@ -3254,11 +3241,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) {
@@ -3274,18 +3263,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