Skip to content

Commit f045dd0

Browse files
author
Darrick J. Wong
committed
xfs: clean up the rtbitmap fsmap backend
The rtbitmap fsmap backend doesn't query the rmapbt, so it's wasteful to spend time initializing the rmap_irec objects. Worse yet, the logic to query the rtbitmap is spread across three separate functions, which is unnecessarily difficult to follow. Compute the start rtextent that we want from keys[0] directly and combine the functions to avoid passing parameters around everywhere, and consolidate all the logic into a single function. At one point many years ago I intended to use __xfs_getfsmap_rtdev as the launching point for realtime rmapbt queries, but this hasn't been the case for a long time. Signed-off-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Dave Chinner <dchinner@redhat.com>
1 parent d898137 commit f045dd0

File tree

2 files changed

+34
-53
lines changed

2 files changed

+34
-53
lines changed

fs/xfs/xfs_fsmap.c

Lines changed: 9 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -512,22 +512,21 @@ xfs_getfsmap_rtdev_rtbitmap_helper(
512512
return xfs_getfsmap_helper(tp, info, &irec, rec_daddr, len_daddr);
513513
}
514514

515-
/* Execute a getfsmap query against the realtime device. */
515+
/* Execute a getfsmap query against the realtime device rtbitmap. */
516516
STATIC int
517-
__xfs_getfsmap_rtdev(
517+
xfs_getfsmap_rtdev_rtbitmap(
518518
struct xfs_trans *tp,
519519
const struct xfs_fsmap *keys,
520-
int (*query_fn)(struct xfs_trans *,
521-
struct xfs_getfsmap_info *,
522-
xfs_rtblock_t start_rtb,
523-
xfs_rtblock_t end_rtb),
524520
struct xfs_getfsmap_info *info)
525521
{
522+
523+
struct xfs_rtalloc_rec alow = { 0 };
524+
struct xfs_rtalloc_rec ahigh = { 0 };
526525
struct xfs_mount *mp = tp->t_mountp;
527526
xfs_rtblock_t start_rtb;
528527
xfs_rtblock_t end_rtb;
529528
uint64_t eofs;
530-
int error = 0;
529+
int error;
531530

532531
eofs = XFS_FSB_TO_BB(mp, mp->m_sb.sb_rextents * mp->m_sb.sb_rextsize);
533532
if (keys[0].fmr_physical >= eofs)
@@ -536,14 +535,7 @@ __xfs_getfsmap_rtdev(
536535
keys[0].fmr_physical + keys[0].fmr_length);
537536
end_rtb = XFS_BB_TO_FSB(mp, min(eofs - 1, keys[1].fmr_physical));
538537

539-
/* Set up search keys */
540-
info->low.rm_startblock = start_rtb;
541-
error = xfs_fsmap_owner_to_rmap(&info->low, &keys[0]);
542-
if (error)
543-
return error;
544-
info->low.rm_offset = XFS_BB_TO_FSBT(mp, keys[0].fmr_offset);
545-
info->low.rm_blockcount = 0;
546-
xfs_getfsmap_set_irec_flags(&info->low, &keys[0]);
538+
info->missing_owner = XFS_FMR_OWN_UNKNOWN;
547539

548540
/* Adjust the low key if we are continuing from where we left off. */
549541
if (keys[0].fmr_length > 0) {
@@ -552,32 +544,8 @@ __xfs_getfsmap_rtdev(
552544
return 0;
553545
}
554546

555-
info->high.rm_startblock = end_rtb;
556-
error = xfs_fsmap_owner_to_rmap(&info->high, &keys[1]);
557-
if (error)
558-
return error;
559-
info->high.rm_offset = XFS_BB_TO_FSBT(mp, keys[1].fmr_offset);
560-
info->high.rm_blockcount = 0;
561-
xfs_getfsmap_set_irec_flags(&info->high, &keys[1]);
562-
563-
trace_xfs_fsmap_low_key(mp, info->dev, NULLAGNUMBER, &info->low);
564-
trace_xfs_fsmap_high_key(mp, info->dev, NULLAGNUMBER, &info->high);
565-
566-
return query_fn(tp, info, start_rtb, end_rtb);
567-
}
568-
569-
/* Actually query the realtime bitmap. */
570-
STATIC int
571-
xfs_getfsmap_rtdev_rtbitmap_query(
572-
struct xfs_trans *tp,
573-
struct xfs_getfsmap_info *info,
574-
xfs_rtblock_t start_rtb,
575-
xfs_rtblock_t end_rtb)
576-
{
577-
struct xfs_rtalloc_rec alow = { 0 };
578-
struct xfs_rtalloc_rec ahigh = { 0 };
579-
struct xfs_mount *mp = tp->t_mountp;
580-
int error;
547+
trace_xfs_fsmap_low_key_linear(mp, info->dev, start_rtb);
548+
trace_xfs_fsmap_high_key_linear(mp, info->dev, end_rtb);
581549

582550
xfs_ilock(mp->m_rbmip, XFS_ILOCK_SHARED | XFS_ILOCK_RTBITMAP);
583551

@@ -609,18 +577,6 @@ xfs_getfsmap_rtdev_rtbitmap_query(
609577
xfs_iunlock(mp->m_rbmip, XFS_ILOCK_SHARED | XFS_ILOCK_RTBITMAP);
610578
return error;
611579
}
612-
613-
/* Execute a getfsmap query against the realtime device rtbitmap. */
614-
STATIC int
615-
xfs_getfsmap_rtdev_rtbitmap(
616-
struct xfs_trans *tp,
617-
const struct xfs_fsmap *keys,
618-
struct xfs_getfsmap_info *info)
619-
{
620-
info->missing_owner = XFS_FMR_OWN_UNKNOWN;
621-
return __xfs_getfsmap_rtdev(tp, keys, xfs_getfsmap_rtdev_rtbitmap_query,
622-
info);
623-
}
624580
#endif /* CONFIG_XFS_RT */
625581

626582
/* Execute a getfsmap query against the regular data device. */

fs/xfs/xfs_trace.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3623,6 +3623,31 @@ DEFINE_FSMAP_EVENT(xfs_fsmap_low_key);
36233623
DEFINE_FSMAP_EVENT(xfs_fsmap_high_key);
36243624
DEFINE_FSMAP_EVENT(xfs_fsmap_mapping);
36253625

3626+
DECLARE_EVENT_CLASS(xfs_fsmap_linear_class,
3627+
TP_PROTO(struct xfs_mount *mp, u32 keydev, uint64_t bno),
3628+
TP_ARGS(mp, keydev, bno),
3629+
TP_STRUCT__entry(
3630+
__field(dev_t, dev)
3631+
__field(dev_t, keydev)
3632+
__field(xfs_fsblock_t, bno)
3633+
),
3634+
TP_fast_assign(
3635+
__entry->dev = mp->m_super->s_dev;
3636+
__entry->keydev = new_decode_dev(keydev);
3637+
__entry->bno = bno;
3638+
),
3639+
TP_printk("dev %d:%d keydev %d:%d bno 0x%llx",
3640+
MAJOR(__entry->dev), MINOR(__entry->dev),
3641+
MAJOR(__entry->keydev), MINOR(__entry->keydev),
3642+
__entry->bno)
3643+
)
3644+
#define DEFINE_FSMAP_LINEAR_EVENT(name) \
3645+
DEFINE_EVENT(xfs_fsmap_linear_class, name, \
3646+
TP_PROTO(struct xfs_mount *mp, u32 keydev, uint64_t bno), \
3647+
TP_ARGS(mp, keydev, bno))
3648+
DEFINE_FSMAP_LINEAR_EVENT(xfs_fsmap_low_key_linear);
3649+
DEFINE_FSMAP_LINEAR_EVENT(xfs_fsmap_high_key_linear);
3650+
36263651
DECLARE_EVENT_CLASS(xfs_getfsmap_class,
36273652
TP_PROTO(struct xfs_mount *mp, struct xfs_fsmap *fsmap),
36283653
TP_ARGS(mp, fsmap),

0 commit comments

Comments
 (0)