This is a note to let you know that I've just added the patch titled xfs: xfs_bmap_punch_delalloc_range() should take a byte range to the 6.1-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: xfs-xfs_bmap_punch_delalloc_range-should-take-a-byte-range.patch and it can be found in the queue-6.1 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From stable+bounces-42895-greg=kroah.com@xxxxxxxxxxxxxxx Wed May 1 20:41:37 2024 From: Leah Rumancik <leah.rumancik@xxxxxxxxx> Date: Wed, 1 May 2024 11:40:54 -0700 Subject: xfs: xfs_bmap_punch_delalloc_range() should take a byte range To: stable@xxxxxxxxxxxxxxx Cc: linux-xfs@xxxxxxxxxxxxxxx, amir73il@xxxxxxxxx, chandan.babu@xxxxxxxxxx, fred@xxxxxxxxxxxxxx, Dave Chinner <dchinner@xxxxxxxxxx>, "Darrick J . Wong" <djwong@xxxxxxxxxx>, Leah Rumancik <leah.rumancik@xxxxxxxxx> Message-ID: <20240501184112.3799035-6-leah.rumancik@xxxxxxxxx> From: Dave Chinner <dchinner@xxxxxxxxxx> [ Upstream commit 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: Dave Chinner <dchinner@xxxxxxxxxx> Reviewed-by: Darrick J. Wong <djwong@xxxxxxxxxx> Signed-off-by: Leah Rumancik <leah.rumancik@xxxxxxxxx> Acked-by: Darrick J. Wong <djwong@xxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- fs/xfs/xfs_aops.c | 16 ++++++---------- fs/xfs/xfs_bmap_util.c | 10 ++++++---- fs/xfs/xfs_bmap_util.h | 2 +- fs/xfs/xfs_iomap.c | 8 ++------ 4 files changed, 15 insertions(+), 21 deletions(-) --- a/fs/xfs/xfs_aops.c +++ b/fs/xfs/xfs_aops.c @@ -114,9 +114,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; } @@ -455,12 +454,8 @@ xfs_discard_folio( struct folio *folio, loff_t pos) { - struct inode *inode = folio->mapping->host; - struct xfs_inode *ip = XFS_I(inode); + struct xfs_inode *ip = XFS_I(folio->mapping->host); struct xfs_mount *mp = ip->i_mount; - size_t offset = offset_in_folio(folio, pos); - xfs_fileoff_t start_fsb = XFS_B_TO_FSBT(mp, pos); - xfs_fileoff_t pageoff_fsb = XFS_B_TO_FSBT(mp, offset); int error; if (xfs_is_shutdown(mp)) @@ -470,8 +465,9 @@ xfs_discard_folio( "page discard on page "PTR_FMT", inode 0x%llx, pos %llu.", folio, ip->i_ino, pos); - error = xfs_bmap_punch_delalloc_range(ip, start_fsb, - i_blocks_per_folio(inode, folio) - pageoff_fsb); + error = xfs_bmap_punch_delalloc_range(ip, pos, + round_up(pos, folio_size(folio))); + if (error && !xfs_is_shutdown(mp)) xfs_alert(mp, "page discard unable to remove delalloc mapping."); } --- a/fs/xfs/xfs_bmap_util.c +++ b/fs/xfs/xfs_bmap_util.c @@ -590,11 +590,13 @@ out_unlock_iolock: 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; @@ -607,7 +609,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 --- a/fs/xfs/xfs_bmap_util.h +++ b/fs/xfs/xfs_bmap_util.h @@ -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 */ --- a/fs/xfs/xfs_iomap.c +++ b/fs/xfs/xfs_iomap.c @@ -1126,12 +1126,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); } static int Patches currently in stable-queue which might be from kroah.com@xxxxxxxxxxxxxxx are queue-6.1/xfs-iomap-move-delalloc-punching-to-iomap.patch queue-6.1/xfs-fix-off-by-one-block-in-xfs_discard_folio.patch queue-6.1/xfs-invalidate-block-device-page-cache-during-unmount.patch queue-6.1/xfs-drop-write-error-injection-is-unfixable-remove-it.patch queue-6.1/iomap-buffered-write-failure-should-not-truncate-the-page-cache.patch queue-6.1/xfs-fix-super-block-buf-log-item-uaf-during-force-shutdown.patch queue-6.1/xfs-fix-incorrect-i_nlink-caused-by-inode-racing.patch queue-6.1/xfs-estimate-post-merge-refcounts-correctly.patch queue-6.1/xfs-fix-log-recovery-when-unknown-rocompat-bits-are-set.patch queue-6.1/xfs-punching-delalloc-extents-on-write-failure-is-racy.patch queue-6.1/xfs-allow-inode-inactivation-during-a-ro-mount-log-recovery.patch queue-6.1/iomap-write-iomap-validity-checks.patch queue-6.1/xfs-attach-dquots-to-inode-before-reading-data-cow-fork-mappings.patch queue-6.1/xfs-fix-sb-write-verify-for-lazysbcount.patch queue-6.1/xfs-wait-iclog-complete-before-tearing-down-ail.patch queue-6.1/xfs-use-byte-ranges-for-write-cleanup-ranges.patch queue-6.1/xfs-xfs_bmap_punch_delalloc_range-should-take-a-byte-range.patch queue-6.1/xfs-write-page-faults-in-iomap-are-not-buffered-writes.patch queue-6.1/xfs-short-circuit-xfs_growfs_data_private-if-delta-is-zero.patch queue-6.1/xfs-fix-incorrect-error-out-in-xfs_remove.patch queue-6.1/xfs-invalidate-xfs_bufs-when-allocating-cow-extents.patch queue-6.1/xfs-hoist-refcount-record-merge-predicates.patch queue-6.1/xfs-get-root-inode-correctly-at-bulkstat.patch queue-6.1/xfs-use-iomap_valid-method-to-detect-stale-cached-iomaps.patch