]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: create helpers for rtbitmap block/wordcount computations
authorDarrick J. Wong <djwong@kernel.org>
Thu, 15 Feb 2024 08:25:47 +0000 (09:25 +0100)
committerCarlos Maiolino <cem@kernel.org>
Thu, 15 Feb 2024 11:56:43 +0000 (12:56 +0100)
Source kernel commit: d0448fe76ac1a9ccbce574577a4c82246d17eec4

Create helper functions that compute the number of blocks or words
necessary to store the rt bitmap.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
libxfs/xfs_rtbitmap.c
libxfs/xfs_rtbitmap.h
libxfs/xfs_trans_resv.c

index 9a8bd93b7b9006c7f29be60d25103bfaf213564a..92473d4a557d8039fcc2ab8e09ce8aee9473a102 100644 (file)
@@ -1137,3 +1137,30 @@ xfs_rtalloc_extent_is_free(
        *is_free = matches;
        return 0;
 }
+
+/*
+ * Compute the number of rtbitmap blocks needed to track the given number of rt
+ * extents.
+ */
+xfs_filblks_t
+xfs_rtbitmap_blockcount(
+       struct xfs_mount        *mp,
+       xfs_rtbxlen_t           rtextents)
+{
+       return howmany_64(rtextents, NBBY * mp->m_sb.sb_blocksize);
+}
+
+/*
+ * Compute the number of rtbitmap words needed to populate every block of a
+ * bitmap that is large enough to track the given number of rt extents.
+ */
+unsigned long long
+xfs_rtbitmap_wordcount(
+       struct xfs_mount        *mp,
+       xfs_rtbxlen_t           rtextents)
+{
+       xfs_filblks_t           blocks;
+
+       blocks = xfs_rtbitmap_blockcount(mp, rtextents);
+       return XFS_FSB_TO_B(mp, blocks) >> XFS_WORDLOG;
+}
index 167ea6a081056f50b042537590db21f4d6f95ad6..618c96468ea41ca9830ab30f71093a1f0f66c7c4 100644 (file)
@@ -283,6 +283,11 @@ xfs_rtfree_extent(
 /* Same as above, but in units of rt blocks. */
 int xfs_rtfree_blocks(struct xfs_trans *tp, xfs_fsblock_t rtbno,
                xfs_filblks_t rtlen);
+
+xfs_filblks_t xfs_rtbitmap_blockcount(struct xfs_mount *mp, xfs_rtbxlen_t
+               rtextents);
+unsigned long long xfs_rtbitmap_wordcount(struct xfs_mount *mp,
+               xfs_rtbxlen_t rtextents);
 #else /* CONFIG_XFS_RT */
 # define xfs_rtfree_extent(t,b,l)                      (-ENOSYS)
 # define xfs_rtfree_blocks(t,rb,rl)                    (-ENOSYS)
@@ -290,6 +295,13 @@ int xfs_rtfree_blocks(struct xfs_trans *tp, xfs_fsblock_t rtbno,
 # define xfs_rtalloc_query_all(m,t,f,p)                        (-ENOSYS)
 # define xfs_rtbuf_get(m,t,b,i,p)                      (-ENOSYS)
 # define xfs_rtalloc_extent_is_free(m,t,s,l,i)         (-ENOSYS)
+static inline xfs_filblks_t
+xfs_rtbitmap_blockcount(struct xfs_mount *mp, xfs_rtbxlen_t rtextents)
+{
+       /* shut up gcc */
+       return 0;
+}
+# define xfs_rtbitmap_wordcount(mp, r)                 (0)
 #endif /* CONFIG_XFS_RT */
 
 #endif /* __XFS_RTBITMAP_H__ */
index 53c190b7206510f003fa6d7f0aa5d2762c236908..82b3d1522b6a26e12d98188dfdf552274f8cfd82 100644 (file)
@@ -217,11 +217,12 @@ xfs_rtalloc_block_count(
        struct xfs_mount        *mp,
        unsigned int            num_ops)
 {
-       unsigned int            blksz = XFS_FSB_TO_B(mp, 1);
-       unsigned int            rtbmp_bytes;
+       unsigned int            rtbmp_blocks;
+       xfs_rtxlen_t            rtxlen;
 
-       rtbmp_bytes = xfs_extlen_to_rtxlen(mp, XFS_MAX_BMBT_EXTLEN) / NBBY;
-       return (howmany(rtbmp_bytes, blksz) + 1) * num_ops;
+       rtxlen = xfs_extlen_to_rtxlen(mp, XFS_MAX_BMBT_EXTLEN);
+       rtbmp_blocks = xfs_rtbitmap_blockcount(mp, rtxlen);
+       return (rtbmp_blocks + 1) * num_ops;
 }
 
 /*