Skip to content

Commit 48ccb79

Browse files
committed
xfs: xfs_bmap_punch_delalloc_range() should take a byte range
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2155605 Tested: With xfstests and bz reproducer Conflicts: - We still use xfs_discard_page() 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@redhat.com> Reviewed-by: Darrick J. Wong <djwong@kernel.org> (cherry picked from commit 7348b32) Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
1 parent 9b01018 commit 48ccb79

File tree

4 files changed

+14
-20
lines changed

4 files changed

+14
-20
lines changed

fs/xfs/xfs_aops.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,8 @@ xfs_end_ioend(
114114
if (unlikely(error)) {
115115
if (ioend->io_flags & IOMAP_F_SHARED) {
116116
xfs_reflink_cancel_cow_range(ip, offset, size, true);
117-
xfs_bmap_punch_delalloc_range(ip,
118-
XFS_B_TO_FSBT(mp, offset),
119-
XFS_B_TO_FSB(mp, size));
117+
xfs_bmap_punch_delalloc_range(ip, offset,
118+
offset + size);
120119
}
121120
goto done;
122121
}
@@ -441,12 +440,9 @@ xfs_discard_page(
441440
struct page *page,
442441
loff_t fileoff)
443442
{
444-
struct inode *inode = page->mapping->host;
445-
struct xfs_inode *ip = XFS_I(inode);
443+
struct xfs_inode *ip = XFS_I(page->mapping->host);
446444
struct xfs_mount *mp = ip->i_mount;
447445
unsigned int pageoff = offset_in_page(fileoff);
448-
xfs_fileoff_t start_fsb = XFS_B_TO_FSBT(mp, fileoff);
449-
xfs_fileoff_t pageoff_fsb = XFS_B_TO_FSBT(mp, pageoff);
450446
int error;
451447

452448
if (xfs_is_shutdown(mp))
@@ -456,8 +452,8 @@ xfs_discard_page(
456452
"page discard on page "PTR_FMT", inode 0x%llx, offset %llu.",
457453
page, ip->i_ino, fileoff);
458454

459-
error = xfs_bmap_punch_delalloc_range(ip, start_fsb,
460-
i_blocks_per_page(inode, page) - pageoff_fsb);
455+
error = xfs_bmap_punch_delalloc_range(ip, fileoff,
456+
round_up(fileoff, PAGE_SIZE));
461457
if (error && !xfs_is_shutdown(mp))
462458
xfs_alert(mp, "page discard unable to remove delalloc mapping.");
463459
out_invalidate:

fs/xfs/xfs_bmap_util.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -589,11 +589,13 @@ xfs_getbmap(
589589
int
590590
xfs_bmap_punch_delalloc_range(
591591
struct xfs_inode *ip,
592-
xfs_fileoff_t start_fsb,
593-
xfs_fileoff_t length)
592+
xfs_off_t start_byte,
593+
xfs_off_t end_byte)
594594
{
595+
struct xfs_mount *mp = ip->i_mount;
595596
struct xfs_ifork *ifp = &ip->i_df;
596-
xfs_fileoff_t end_fsb = start_fsb + length;
597+
xfs_fileoff_t start_fsb = XFS_B_TO_FSBT(mp, start_byte);
598+
xfs_fileoff_t end_fsb = XFS_B_TO_FSB(mp, end_byte);
597599
struct xfs_bmbt_irec got, del;
598600
struct xfs_iext_cursor icur;
599601
int error = 0;
@@ -606,7 +608,7 @@ xfs_bmap_punch_delalloc_range(
606608

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

611613
/*
612614
* A delete can push the cursor forward. Step back to the

fs/xfs/xfs_bmap_util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ xfs_bmap_rtalloc(struct xfs_bmalloca *ap)
3131
#endif /* CONFIG_XFS_RT */
3232

3333
int xfs_bmap_punch_delalloc_range(struct xfs_inode *ip,
34-
xfs_fileoff_t start_fsb, xfs_fileoff_t length);
34+
xfs_off_t start_byte, xfs_off_t end_byte);
3535

3636
struct kgetbmap {
3737
__s64 bmv_offset; /* file offset of segment in blocks */

fs/xfs/xfs_iomap.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,12 +1081,8 @@ xfs_buffered_write_delalloc_punch(
10811081
loff_t offset,
10821082
loff_t length)
10831083
{
1084-
struct xfs_mount *mp = XFS_M(inode->i_sb);
1085-
xfs_fileoff_t start_fsb = XFS_B_TO_FSBT(mp, offset);
1086-
xfs_fileoff_t end_fsb = XFS_B_TO_FSB(mp, offset + length);
1087-
1088-
return xfs_bmap_punch_delalloc_range(XFS_I(inode), start_fsb,
1089-
end_fsb - start_fsb);
1084+
return xfs_bmap_punch_delalloc_range(XFS_I(inode), offset,
1085+
offset + length);
10901086
}
10911087

10921088
static int

0 commit comments

Comments
 (0)