Skip to content

Commit dca9425

Browse files
author
Darrick J. Wong
committed
xfs: fix rt device offset calculations for FITRIM
FITRIM on xfs has this bizarro uapi where we flatten all the physically addressable storage across two block devices into a linear address space. In this address space, the realtime device comes immediately after the data device. Therefore, the xfs_trim_rtdev_extents has to convert its input parameters from the linear address space to actual rtdev block addresses on the realtime volume. Right now the address space conversion is done in units of rtblocks. However, a future patchset will convert xfs_rtblock_t to be a segmented address space (group:blkno) like the data device. Change the conversion code to be done in units of daddrs since those will never be segmented. Signed-off-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de>
1 parent f220f6d commit dca9425

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

fs/xfs/xfs_discard.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ xfs_discard_rtdev_extents(
480480
trace_xfs_discard_rtextent(mp, busyp->bno, busyp->length);
481481

482482
error = __blkdev_issue_discard(bdev,
483-
XFS_FSB_TO_BB(mp, busyp->bno),
483+
xfs_rtb_to_daddr(mp, busyp->bno),
484484
XFS_FSB_TO_BB(mp, busyp->length),
485485
GFP_NOFS, &bio);
486486
if (error)
@@ -612,22 +612,25 @@ xfs_trim_rtdev_extents(
612612
xfs_rtblock_t start_rtbno, end_rtbno;
613613
xfs_rtxnum_t start_rtx, end_rtx;
614614
xfs_rgnumber_t start_rgno, end_rgno;
615+
xfs_daddr_t daddr_offset;
615616
int last_error = 0, error;
616617
struct xfs_rtgroup *rtg = NULL;
617618

618619
/* Shift the start and end downwards to match the rt device. */
619-
start_rtbno = xfs_daddr_to_rtb(mp, start);
620-
if (start_rtbno > mp->m_sb.sb_dblocks)
621-
start_rtbno -= mp->m_sb.sb_dblocks;
620+
daddr_offset = XFS_FSB_TO_BB(mp, mp->m_sb.sb_dblocks);
621+
if (start > daddr_offset)
622+
start -= daddr_offset;
622623
else
623-
start_rtbno = 0;
624+
start = 0;
625+
start_rtbno = xfs_daddr_to_rtb(mp, start);
624626
start_rtx = xfs_rtb_to_rtx(mp, start_rtbno);
625627
start_rgno = xfs_rtb_to_rgno(mp, start_rtbno);
626628

627-
end_rtbno = xfs_daddr_to_rtb(mp, end);
628-
if (end_rtbno <= mp->m_sb.sb_dblocks)
629+
if (end <= daddr_offset)
629630
return 0;
630-
end_rtbno -= mp->m_sb.sb_dblocks;
631+
else
632+
end -= daddr_offset;
633+
end_rtbno = xfs_daddr_to_rtb(mp, end);
631634
end_rtx = xfs_rtb_to_rtx(mp, end_rtbno + mp->m_sb.sb_rextsize - 1);
632635
end_rgno = xfs_rtb_to_rgno(mp, end_rtbno);
633636

0 commit comments

Comments
 (0)