|
21 | 21 | #include "xfs_ag.h" |
22 | 22 | #include "xfs_health.h" |
23 | 23 | #include "xfs_rtbitmap.h" |
| 24 | +#include "xfs_rtgroup.h" |
24 | 25 |
|
25 | 26 | /* |
26 | 27 | * Notes on an efficient, low latency fstrim algorithm |
@@ -548,44 +549,23 @@ xfs_trim_gather_rtextent( |
548 | 549 | } |
549 | 550 |
|
550 | 551 | static int |
551 | | -xfs_trim_rtdev_extents( |
| 552 | +xfs_trim_rtextents( |
552 | 553 | struct xfs_mount *mp, |
553 | | - xfs_daddr_t start, |
554 | | - xfs_daddr_t end, |
| 554 | + xfs_rtxnum_t low, |
| 555 | + xfs_rtxnum_t high, |
555 | 556 | xfs_daddr_t minlen) |
556 | 557 | { |
557 | 558 | struct xfs_trim_rtdev tr = { |
558 | 559 | .minlen_fsb = XFS_BB_TO_FSB(mp, minlen), |
| 560 | + .extent_list = LIST_HEAD_INIT(tr.extent_list), |
559 | 561 | }; |
560 | | - xfs_rtxnum_t low, high; |
561 | 562 | struct xfs_trans *tp; |
562 | | - xfs_daddr_t rtdev_daddr; |
563 | 563 | int error; |
564 | 564 |
|
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 | | - |
578 | 565 | error = xfs_trans_alloc_empty(mp, &tp); |
579 | 566 | if (error) |
580 | 567 | return error; |
581 | 568 |
|
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 | | - |
589 | 569 | /* |
590 | 570 | * Walk the free ranges between low and high. The query_range function |
591 | 571 | * trims the extents returned. |
@@ -620,6 +600,33 @@ xfs_trim_rtdev_extents( |
620 | 600 | xfs_trans_cancel(tp); |
621 | 601 | return error; |
622 | 602 | } |
| 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 | +} |
623 | 630 | #else |
624 | 631 | # define xfs_trim_rtdev_extents(...) (-EOPNOTSUPP) |
625 | 632 | #endif /* CONFIG_XFS_RT */ |
|
0 commit comments