Skip to content

Commit c8edf1c

Browse files
Christoph HellwigDarrick J. Wong
authored andcommitted
xfs: split xfs_trim_rtdev_extents
Split xfs_trim_rtdev_extents into two parts to prepare for reusing the main validation also for RT group aware file systems. Use the fully features xfs_daddr_to_rtb helper to convert from a daddr to a xfs_rtblock_t to prepare for segmented addressing in RT groups. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Darrick J. Wong <[email protected]>
1 parent d6d5c90 commit c8edf1c

File tree

1 file changed

+32
-25
lines changed

1 file changed

+32
-25
lines changed

fs/xfs/xfs_discard.c

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "xfs_ag.h"
2222
#include "xfs_health.h"
2323
#include "xfs_rtbitmap.h"
24+
#include "xfs_rtgroup.h"
2425

2526
/*
2627
* Notes on an efficient, low latency fstrim algorithm
@@ -548,44 +549,23 @@ xfs_trim_gather_rtextent(
548549
}
549550

550551
static int
551-
xfs_trim_rtdev_extents(
552+
xfs_trim_rtextents(
552553
struct xfs_mount *mp,
553-
xfs_daddr_t start,
554-
xfs_daddr_t end,
554+
xfs_rtxnum_t low,
555+
xfs_rtxnum_t high,
555556
xfs_daddr_t minlen)
556557
{
557558
struct xfs_trim_rtdev tr = {
558559
.minlen_fsb = XFS_BB_TO_FSB(mp, minlen),
560+
.extent_list = LIST_HEAD_INIT(tr.extent_list),
559561
};
560-
xfs_rtxnum_t low, high;
561562
struct xfs_trans *tp;
562-
xfs_daddr_t rtdev_daddr;
563563
int error;
564564

565-
INIT_LIST_HEAD(&tr.extent_list);
566-
567-
/* Shift the start and end downwards to match the rt device. */
568-
rtdev_daddr = XFS_FSB_TO_BB(mp, mp->m_sb.sb_dblocks);
569-
if (start > rtdev_daddr)
570-
start -= rtdev_daddr;
571-
else
572-
start = 0;
573-
574-
if (end <= rtdev_daddr)
575-
return 0;
576-
end -= rtdev_daddr;
577-
578565
error = xfs_trans_alloc_empty(mp, &tp);
579566
if (error)
580567
return error;
581568

582-
end = min_t(xfs_daddr_t, end,
583-
XFS_FSB_TO_BB(mp, mp->m_sb.sb_rblocks) - 1);
584-
585-
/* Convert the rt blocks to rt extents */
586-
low = xfs_rtb_to_rtxup(mp, XFS_BB_TO_FSB(mp, start));
587-
high = xfs_rtb_to_rtx(mp, XFS_BB_TO_FSBT(mp, end));
588-
589569
/*
590570
* Walk the free ranges between low and high. The query_range function
591571
* trims the extents returned.
@@ -620,6 +600,33 @@ xfs_trim_rtdev_extents(
620600
xfs_trans_cancel(tp);
621601
return error;
622602
}
603+
604+
static int
605+
xfs_trim_rtdev_extents(
606+
struct xfs_mount *mp,
607+
xfs_daddr_t start,
608+
xfs_daddr_t end,
609+
xfs_daddr_t minlen)
610+
{
611+
xfs_rtblock_t start_rtbno, end_rtbno;
612+
xfs_rtxnum_t start_rtx, end_rtx;
613+
614+
/* Shift the start and end downwards to match the rt device. */
615+
start_rtbno = xfs_daddr_to_rtb(mp, start);
616+
if (start_rtbno > mp->m_sb.sb_dblocks)
617+
start_rtbno -= mp->m_sb.sb_dblocks;
618+
else
619+
start_rtbno = 0;
620+
start_rtx = xfs_rtb_to_rtx(mp, start_rtbno);
621+
622+
end_rtbno = xfs_daddr_to_rtb(mp, end);
623+
if (end_rtbno <= mp->m_sb.sb_dblocks)
624+
return 0;
625+
end_rtbno -= mp->m_sb.sb_dblocks;
626+
end_rtx = xfs_rtb_to_rtx(mp, end_rtbno + mp->m_sb.sb_rextsize - 1);
627+
628+
return xfs_trim_rtextents(mp, start_rtx, end_rtx, minlen);
629+
}
623630
#else
624631
# define xfs_trim_rtdev_extents(...) (-EOPNOTSUPP)
625632
#endif /* CONFIG_XFS_RT */

0 commit comments

Comments
 (0)