Commit f76b635e authored by Dave Chinner's avatar Dave Chinner Committed by Long Li
Browse files

xfs: xfs_bmap_punch_delalloc_range() should take a byte range

mainline inclusion
from mainline-v6.1-rc4
commit 7348b322
category: bugfix
bugzilla: 189079, https://gitee.com/openeuler/kernel/issues/I76JSK
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=7348b322332d8602a4133f0b861334ea021b134a



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

All the callers of xfs_bmap_punch_delalloc_range() jump through
hoops to convert a byte range to filesystem blocks before calling
xfs_bmap_punch_delalloc_range(). Instead, pass the byte range to
xfs_bmap_punch_delalloc_range() and have it do the conversion to
filesystem blocks internally.

Signed-off-by: default avatarDave Chinner <dchinner@redhat.com>
Reviewed-by: default avatarDarrick J. Wong <djwong@kernel.org>

Conflicts:
	fs/xfs/xfs_aops.c

Signed-off-by: default avatarLong Li <leo.lilong@huawei.com>
parent c515b6a4
Loading
Loading
Loading
Loading
+5 −10
Original line number Diff line number Diff line
@@ -150,9 +150,8 @@ xfs_end_ioend(
	if (unlikely(error)) {
		if (ioend->io_flags & IOMAP_F_SHARED) {
			xfs_reflink_cancel_cow_range(ip, offset, size, true);
			xfs_bmap_punch_delalloc_range(ip,
						      XFS_B_TO_FSBT(mp, offset),
						      XFS_B_TO_FSB(mp, size));
			xfs_bmap_punch_delalloc_range(ip, offset,
					offset + size);
		}
		goto done;
	}
@@ -516,12 +515,8 @@ xfs_discard_page(
	struct page		*page,
	loff_t			fileoff)
{
	struct inode		*inode = page->mapping->host;
	struct xfs_inode	*ip = XFS_I(inode);
	struct xfs_inode	*ip = XFS_I(page->mapping->host);
	struct xfs_mount	*mp = ip->i_mount;
	unsigned int		pageoff = offset_in_page(fileoff);
	xfs_fileoff_t		start_fsb = XFS_B_TO_FSBT(mp, fileoff);
	xfs_fileoff_t		pageoff_fsb = XFS_B_TO_FSBT(mp, pageoff);
	int			error;

	if (xfs_is_shutdown(mp))
@@ -531,8 +526,8 @@ xfs_discard_page(
		"page discard on page "PTR_FMT", inode 0x%llx, offset %llu.",
			page, ip->i_ino, fileoff);

	error = xfs_bmap_punch_delalloc_range(ip, start_fsb,
			i_blocks_per_page(inode, page) - pageoff_fsb);
	error = xfs_bmap_punch_delalloc_range(ip, fileoff,
			round_up(fileoff, thp_size(page)));
	if (error && !xfs_is_shutdown(mp))
		xfs_alert(mp, "page discard unable to remove delalloc mapping.");
}
+6 −4
Original line number Diff line number Diff line
@@ -551,11 +551,13 @@ xfs_getbmap(
int
xfs_bmap_punch_delalloc_range(
	struct xfs_inode	*ip,
	xfs_fileoff_t		start_fsb,
	xfs_fileoff_t		length)
	xfs_off_t		start_byte,
	xfs_off_t		end_byte)
{
	struct xfs_mount	*mp = ip->i_mount;
	struct xfs_ifork	*ifp = &ip->i_df;
	xfs_fileoff_t		end_fsb = start_fsb + length;
	xfs_fileoff_t		start_fsb = XFS_B_TO_FSBT(mp, start_byte);
	xfs_fileoff_t		end_fsb = XFS_B_TO_FSB(mp, end_byte);
	struct xfs_bmbt_irec	got, del;
	struct xfs_iext_cursor	icur;
	int			error = 0;
@@ -568,7 +570,7 @@ xfs_bmap_punch_delalloc_range(

	while (got.br_startoff + got.br_blockcount > start_fsb) {
		del = got;
		xfs_trim_extent(&del, start_fsb, length);
		xfs_trim_extent(&del, start_fsb, end_fsb - start_fsb);

		/*
		 * A delete can push the cursor forward. Step back to the
+1 −1
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ xfs_bmap_rtalloc(struct xfs_bmalloca *ap)
#endif /* CONFIG_XFS_RT */

int	xfs_bmap_punch_delalloc_range(struct xfs_inode *ip,
		xfs_fileoff_t start_fsb, xfs_fileoff_t length);
		xfs_off_t start_byte, xfs_off_t end_byte);

struct kgetbmap {
	__s64		bmv_offset;	/* file offset of segment in blocks */
+2 −6
Original line number Diff line number Diff line
@@ -1117,12 +1117,8 @@ xfs_buffered_write_delalloc_punch(
	loff_t			offset,
	loff_t			length)
{
	struct xfs_mount	*mp = XFS_M(inode->i_sb);
	xfs_fileoff_t		start_fsb = XFS_B_TO_FSBT(mp, offset);
	xfs_fileoff_t		end_fsb = XFS_B_TO_FSB(mp, offset + length);

	return xfs_bmap_punch_delalloc_range(XFS_I(inode), start_fsb,
				end_fsb - start_fsb);
	return xfs_bmap_punch_delalloc_range(XFS_I(inode), offset,
			offset + length);
}

/*