LGTM
在 2024/8/8 21:32, Long Li 写道:
From: Dave Chinner dchinner@redhat.com
maillist inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I9VTE3 CVE: NA
Reference: https://lore.kernel.org/linux-xfs/20240705162450.3481169-1-john.g.garry@orac...
If args->minlen is not aligned to the constraints of forced alignment, we may do minlen allocations that are not aligned when we approach ENOSPC. Avoid this by always aligning args->minlen appropriately. If alignment of minlen results in a value smaller than the alignment constraint, fail the allocation immediately.
Signed-off-by: Dave Chinner dchinner@redhat.com Reviewed-by: "Darrick J. Wong" djwong@kernel.org Signed-off-by: John Garry john.g.garry@oracle.com Conflicts: fs/xfs/libxfs/xfs_bmap.c [Conflicts in xfs_bmap_select_minlen()] Signed-off-by: Long Li leo.lilong@huawei.com
fs/xfs/libxfs/xfs_bmap.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-)
diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index 7682dfe2f701..284cc73b8bef 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -3253,32 +3253,47 @@ xfs_bmap_longest_free_extent( return error; }
-static void +static int xfs_bmap_select_minlen( struct xfs_bmalloca *ap, struct xfs_alloc_arg *args, xfs_extlen_t *blen, int notinit) {
- xfs_extlen_t nlen = 0;
- 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) { /*nlen = ap->minlen;
*/
- If the best seen length is less than the request length,
- use the best as the minimum.
args->minlen = *blen;
} else { /*nlen = *blen;
*/
- Otherwise we've seen an extent as big as maxlen, use that
- as the minimum.
args->minlen = args->maxlen;
nlen = args->maxlen;
}
if (args->alignment > 1) {
nlen = rounddown(nlen, args->alignment);
if (nlen < ap->minlen) {
if (xfs_inode_forcealign(ap->ip) &&
(ap->datatype & XFS_ALLOC_USERDATA))
return -ENOSPC;
nlen = ap->minlen;
}
}
args->minlen = nlen;
return 0; }
STATIC int
@@ -3311,8 +3326,8 @@ xfs_bmap_btalloc_nullfb( break; }
- xfs_bmap_select_minlen(ap, args, blen, notinit);
- return 0;
error = xfs_bmap_select_minlen(ap, args, blen, notinit);
return error; }
STATIC int
@@ -3349,7 +3364,9 @@ xfs_bmap_btalloc_filestreams(
}
- xfs_bmap_select_minlen(ap, args, blen, notinit);
error = xfs_bmap_select_minlen(ap, args, blen, notinit);
if (error)
return error;
/*
- Set the failure fallback case to look in the selected AG as stream