On Thu, Oct 12, 2023 at 08:25:51AM +0200, Christoph Hellwig wrote: > On Wed, Oct 11, 2023 at 11:08:03AM -0700, Darrick J. Wong wrote: > > +/* Compute the number of rtsummary blocks needed to track the given rt space. */ > > +xfs_filblks_t > > +xfs_rtsummary_blockcount( > > + struct xfs_mount *mp, > > + unsigned int rsumlevels, > > + xfs_extlen_t rbmblocks) > > +{ > > + unsigned long long rsumwords; > > + > > + rsumwords = (unsigned long long)rsumlevels * rbmblocks; > > + return XFS_B_TO_FSB(mp, rsumwords << XFS_WORDLOG); > > +} > > This helper and its users make complete sense to me and looks good: > > Reviewed-by: Christoph Hellwig <hch@xxxxxx> > > > +/* > > + * Compute the number of rtsummary info words needed to populate every block of > > + * a summary file that is large enough to track the given rt space. > > + */ > > +unsigned long long > > +xfs_rtsummary_wordcount( > > + struct xfs_mount *mp, > > + unsigned int rsumlevels, > > + xfs_extlen_t rbmblocks) > > +{ > > + xfs_filblks_t blocks; > > + > > + blocks = xfs_rtsummary_blockcount(mp, rsumlevels, rbmblocks); > > + return XFS_FSB_TO_B(mp, blocks) >> XFS_WORDLOG; > > +} > > > @@ -54,8 +55,10 @@ xchk_setup_rtsummary( > > * Create an xfile to construct a new rtsummary file. The xfile allows > > * us to avoid pinning kernel memory for this purpose. > > */ > > + wordcnt = xfs_rtsummary_wordcount(mp, mp->m_rsumlevels, > > + mp->m_sb.sb_rbmblocks); > > descr = xchk_xfile_descr(sc, "realtime summary file"); > > - error = xfile_create(descr, mp->m_rsumsize, &sc->xfile); > > + error = xfile_create(descr, wordcnt << XFS_WORDLOG, &sc->xfile); > > kfree(descr); > > But this confuses me. What problem does it solve over just using > m_rsumsize? The rtbitmap and rtsummary repair code should be computing rbmblocks and rsumsize from sb_rextents. rbmblocks = xfs_rtbitmap_wordcount(mp, mp->m_sb.sb_rextents); rsumsize = xfs_rtsummary_wordcount(mp, mp->m_rsumlevels, rbmblocks); >From that, it should be checking isize and the data fork mappings of the file and the superblock values. Repair ought to map (or unmap) blocks as necessary, update isize if needed, and update the superblock if the values there are incorrect. --D