Commit bb5092a7 authored by John Garry's avatar John Garry Committed by Long Li
Browse files

fs: xfs: Do not free EOF blocks for forcealign

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/



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

For when forcealign is enabled, we want the EOF to be aligned as well, so
do not free EOF blocks.

Add helper function xfs_get_extsz() to get the guaranteed extent size
alignment for forcealign enabled. Since this code is only relevant to
forcealign and forcealign is not possible for RT yet, ignore RT.

Signed-off-by: default avatarJohn Garry <john.g.garry@oracle.com>
Signed-off-by: default avatarLong Li <leo.lilong@huawei.com>
parent 63f4d844
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -654,6 +654,9 @@ xfs_free_eofblocks(
	 * of the file.  If not, then there is nothing to do.
	 */
	end_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)XFS_ISIZE(ip));
	/* Do not free blocks when forcing extent sizes */
	if (xfs_get_extsz(ip) > 1)
		end_fsb = roundup_64(end_fsb, xfs_get_extsz(ip));
	last_fsb = XFS_B_TO_FSB(mp, mp->m_super->s_maxbytes);
	if (last_fsb <= end_fsb)
		return 0;
+14 −0
Original line number Diff line number Diff line
@@ -68,6 +68,20 @@ xfs_get_extsz_hint(
	return 0;
}

/*
 * Helper function to extract extent size. It will return a power-of-2,
 * as forcealign requires this.
 */
xfs_extlen_t
xfs_get_extsz(
	struct xfs_inode	*ip)
{
	if (xfs_inode_forcealign(ip) && ip->i_d.di_extsize)
		return ip->i_d.di_extsize;

	return 1;
}

/*
 * Helper function to extract CoW extent size hint from inode.
 * Between the extent size hint and the CoW extent size hint, we
+1 −0
Original line number Diff line number Diff line
@@ -493,6 +493,7 @@ void xfs_lock_two_inodes(struct xfs_inode *ip0, uint ip0_mode,
				struct xfs_inode *ip1, uint ip1_mode);

xfs_extlen_t	xfs_get_extsz_hint(struct xfs_inode *ip);
xfs_extlen_t	xfs_get_extsz(struct xfs_inode *ip);
xfs_extlen_t	xfs_get_cowextsz_hint(struct xfs_inode *ip);

int		xfs_dir_ialloc(struct xfs_trans **, struct xfs_inode *, umode_t,