Commit 63f4d844 authored by Darrick J. Wong's avatar Darrick J. Wong Committed by Long Li
Browse files

fs: xfs: Make file data allocations observe the 'forcealign' flag

maillist inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I9VTE3
CVE: NA

Reference: https://lore.kernel.org/all/20240326133813.3224593-1-john.g.garry@oracle.com/



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

The existing extsize hint code already did the work of expanding file
range mapping requests so that the range is aligned to the hint value.
Now add the code we need to guarantee that the space allocations are
also always aligned.

XXX: still need to check all this with reflink

Signed-off-by: default avatar"Darrick J. Wong" <djwong@kernel.org>
Co-developed-by: default avatarJohn Garry <john.g.garry@oracle.com>
Signed-off-by: default avatarJohn Garry <john.g.garry@oracle.com>
Signed-off-by: default avatarLong Li <leo.lilong@huawei.com>
parent 85bb5a61
Loading
Loading
Loading
Loading
+15 −3
Original line number Diff line number Diff line
@@ -3487,6 +3487,18 @@ xfs_bmap_btalloc(
	args.fsbno = ap->blkno;
	args.oinfo = XFS_RMAP_OINFO_SKIP_UPDATE;

	/*
	 * xfs_get_cowextsz_hint() returns extsz_hint for when forcealign is
	 * set as forcealign and cowextsz_hint are mutually exclusive
	 */
	if (xfs_inode_forcealign(ap->ip) && align) {
		args.alignment = align;
		if (stripe_align == 0 || stripe_align % align)
			stripe_align = align;
	} else {
		args.alignment = 1;
	}

	/* Trim the allocation back to the maximum an AG can fit. */
	args.maxlen = min(ap->length, mp->m_ag_max_usable);
	blen = 0;
@@ -3558,7 +3570,6 @@ xfs_bmap_btalloc(
			atype = args.type;
			tryagain = 1;
			args.type = XFS_ALLOCTYPE_THIS_BNO;
			args.alignment = 1;
			/*
			 * Compute the minlen+alignment for the
			 * next case.  Set slop so that the value
@@ -3577,7 +3588,6 @@ xfs_bmap_btalloc(
				args.minalignslop = 0;
		}
	} else {
		args.alignment = 1;
		args.minalignslop = 0;
	}
	args.postallocs = 1;
@@ -3604,7 +3614,9 @@ xfs_bmap_btalloc(
		if ((error = xfs_alloc_vextent(&args)))
			return error;
	}
	if (isaligned && args.fsbno == NULLFSBLOCK) {

	if (isaligned && args.fsbno == NULLFSBLOCK &&
		(args.alignment <= 1 || !xfs_inode_forcealign(ap->ip))) {
		/*
		 * allocation failed, so turn off alignment and
		 * try again.
+3 −1
Original line number Diff line number Diff line
@@ -167,7 +167,9 @@ xfs_eof_alignment(
		 * If mounted with the "-o swalloc" option the alignment is
		 * increased from the strip unit size to the stripe width.
		 */
		if (mp->m_swidth && xfs_has_swalloc(mp))
		if (xfs_inode_forcealign(ip))
			align = xfs_get_extsz_hint(ip);
		else if (mp->m_swidth && xfs_has_swalloc(mp))
			align = mp->m_swidth;
		else if (mp->m_dalign)
			align = mp->m_dalign;