Skip to content

Commit a949a1c

Browse files
author
Darrick J. Wong
committed
xfs: fix logdev fsmap query result filtering
The external log device fsmap backend doesn't have an rmapbt to query, so it's wasteful to spend time initializing the rmap_irec objects. Worse yet, the log could (someday) be longer than 2^32 fsblocks, so using the rmap irec structure will result in integer overflows. Fix this mess by computing the start address that we want from keys[0] directly, and use the daddr-based record filtering algorithm that we also use for rtbitmap queries. Fixes: e89c041 ("xfs: implement the GETFSMAP ioctl") Signed-off-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Dave Chinner <dchinner@redhat.com>
1 parent f045dd0 commit a949a1c

File tree

1 file changed

+8
-22
lines changed

1 file changed

+8
-22
lines changed

fs/xfs/xfs_fsmap.c

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -437,36 +437,22 @@ xfs_getfsmap_logdev(
437437
struct xfs_mount *mp = tp->t_mountp;
438438
struct xfs_rmap_irec rmap;
439439
xfs_daddr_t rec_daddr, len_daddr;
440-
xfs_fsblock_t start_fsb;
441-
int error;
440+
xfs_fsblock_t start_fsb, end_fsb;
441+
uint64_t eofs;
442442

443-
/* Set up search keys */
443+
eofs = XFS_FSB_TO_BB(mp, mp->m_sb.sb_logblocks);
444+
if (keys[0].fmr_physical >= eofs)
445+
return 0;
444446
start_fsb = XFS_BB_TO_FSBT(mp,
445447
keys[0].fmr_physical + keys[0].fmr_length);
446-
info->low.rm_startblock = XFS_BB_TO_FSBT(mp, keys[0].fmr_physical);
447-
info->low.rm_offset = XFS_BB_TO_FSBT(mp, keys[0].fmr_offset);
448-
error = xfs_fsmap_owner_to_rmap(&info->low, keys);
449-
if (error)
450-
return error;
451-
info->low.rm_blockcount = 0;
452-
xfs_getfsmap_set_irec_flags(&info->low, &keys[0]);
448+
end_fsb = XFS_BB_TO_FSB(mp, min(eofs - 1, keys[1].fmr_physical));
453449

454450
/* Adjust the low key if we are continuing from where we left off. */
455451
if (keys[0].fmr_length > 0)
456452
info->low_daddr = XFS_FSB_TO_BB(mp, start_fsb);
457453

458-
error = xfs_fsmap_owner_to_rmap(&info->high, keys + 1);
459-
if (error)
460-
return error;
461-
info->high.rm_startblock = -1U;
462-
info->high.rm_owner = ULLONG_MAX;
463-
info->high.rm_offset = ULLONG_MAX;
464-
info->high.rm_blockcount = 0;
465-
info->high.rm_flags = XFS_RMAP_KEY_FLAGS | XFS_RMAP_REC_FLAGS;
466-
info->missing_owner = XFS_FMR_OWN_FREE;
467-
468-
trace_xfs_fsmap_low_key(mp, info->dev, NULLAGNUMBER, &info->low);
469-
trace_xfs_fsmap_high_key(mp, info->dev, NULLAGNUMBER, &info->high);
454+
trace_xfs_fsmap_low_key_linear(mp, info->dev, start_fsb);
455+
trace_xfs_fsmap_high_key_linear(mp, info->dev, end_fsb);
470456

471457
if (start_fsb > 0)
472458
return 0;

0 commit comments

Comments
 (0)