struct xfs_rmap_irec    ri_low = { };
                struct xfs_rmap_irec    ri_high;
                struct xfs_agf          *agf;
-               xfs_agblock_t           agend;
                struct xfs_perag        *pag;
+               xfs_agblock_t           range_agend;
 
                pag = xfs_perag_get(mp, agno);
                error = xfs_alloc_read_agf(pag, tp, 0, &agf_bp);
                        ri_high.rm_startblock = XFS_FSB_TO_AGBNO(mp, end_fsbno);
 
                agf = agf_bp->b_addr;
-               agend = min(be32_to_cpu(agf->agf_length),
+               range_agend = min(be32_to_cpu(agf->agf_length) - 1,
                                ri_high.rm_startblock);
                notify.startblock = ri_low.rm_startblock;
-               notify.blockcount = agend - ri_low.rm_startblock;
+               notify.blockcount = range_agend + 1 - ri_low.rm_startblock;
 
                error = xfs_rmap_query_range(cur, &ri_low, &ri_high,
                                xfs_dax_failure_fn, ¬ify);