Commit 7f9d8a74 authored by Long Li's avatar Long Li
Browse files

xfs: don't attempting non-aligned fallbacks alloc for forcealign

hulk inclusion
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I9VTE3


CVE: NA

--------------------------------

When forced allocation alignment is specified, the extent will
be aligned to the extent size hint size rather than stripe
alignment. If aligned allocation cannot be done, then the allocation
is failed rather than attempting non-aligned fallbacks.

Fixes: 63f4d844 ("fs: xfs: Make file data allocations observe the 'forcealign' flag")
Signed-off-by: default avatarLong Li <leo.lilong@huawei.com>
parent 0335402b
Loading
Loading
Loading
Loading
+19 −6
Original line number Diff line number Diff line
@@ -3565,7 +3565,13 @@ xfs_bmap_btalloc(
	 * is only set if the allocation length is >= the stripe unit and the
	 * allocation offset is at the end of file.
	 */
	if (!(ap->tp->t_flags & XFS_TRANS_LOWMODE) && ap->aeof) {
	args.minalignslop = 0;
	if (ap->tp->t_flags & XFS_TRANS_LOWMODE) {
		if (args.alignment > 1 && xfs_inode_forcealign(ap->ip)) {
			args.fsbno = NULLFSBLOCK;
			goto alloc_out;
		}
	} else if (ap->aeof) {
		if (!ap->offset) {
			args.alignment = stripe_align;
			atype = args.type;
@@ -3577,7 +3583,6 @@ xfs_bmap_btalloc(
			if (blen > args.alignment &&
			    blen <= args.maxlen + args.alignment)
				args.minlen = blen - args.alignment;
			args.minalignslop = 0;
		} else {
			/*
			 * First try an exact bno allocation.
@@ -3604,8 +3609,6 @@ xfs_bmap_btalloc(
			else
				args.minalignslop = 0;
		}
	} else {
		args.minalignslop = 0;
	}
	args.postallocs = 1;
	args.minleft = ap->minleft;
@@ -3632,8 +3635,16 @@ xfs_bmap_btalloc(
			return error;
	}

	if (isaligned && args.fsbno == NULLFSBLOCK &&
		(args.alignment <= 1 || !xfs_inode_forcealign(ap->ip))) {
	if (args.fsbno == NULLFSBLOCK && args.alignment > 1 &&
		xfs_inode_forcealign(ap->ip)) {
		/*
		 * Don't attempting non-aligned fallbacks alloc
		 * for forcealign
		 */
		goto alloc_out;
	}

	if (isaligned && args.fsbno == NULLFSBLOCK) {
		/*
		 * allocation failed, so turn off alignment and
		 * try again.
@@ -3660,6 +3671,8 @@ xfs_bmap_btalloc(
			return error;
		ap->tp->t_flags |= XFS_TRANS_LOWMODE;
	}

alloc_out:
	if (args.fsbno != NULLFSBLOCK) {
		/*
		 * check the allocation happened at the same or higher AG than