]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
xfs: add metadata reservations for realtime refcount btree
authorDarrick J. Wong <djwong@kernel.org>
Wed, 3 Jul 2024 21:22:29 +0000 (14:22 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 16 Jul 2024 22:49:23 +0000 (15:49 -0700)
Reserve some free blocks so that we will always have enough free blocks
in the data volume to handle expansion of the realtime refcount btree.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
libxfs/xfs_rtrefcount_btree.c
libxfs/xfs_rtrefcount_btree.h

index 27a444182cf5a398c84214ed4ae548590277ba33..97ecc0d74ec982b36d3a2edf6950e966c2754edc 100644 (file)
@@ -422,3 +422,42 @@ xfs_rtrefcountbt_compute_maxlevels(
        /* Add one level to handle the inode root level. */
        mp->m_rtrefc_maxlevels = min(d_maxlevels, r_maxlevels) + 1;
 }
+
+/* Calculate the rtrefcount btree size for some records. */
+unsigned long long
+xfs_rtrefcountbt_calc_size(
+       struct xfs_mount        *mp,
+       unsigned long long      len)
+{
+       return xfs_btree_calc_size(mp->m_rtrefc_mnr, len);
+}
+
+/*
+ * Calculate the maximum refcount btree size.
+ */
+static unsigned long long
+xfs_rtrefcountbt_max_size(
+       struct xfs_mount        *mp,
+       xfs_rtblock_t           rtblocks)
+{
+       /* Bail out if we're uninitialized, which can happen in mkfs. */
+       if (mp->m_rtrefc_mxr[0] == 0)
+               return 0;
+
+       return xfs_rtrefcountbt_calc_size(mp, rtblocks);
+}
+
+/*
+ * Figure out how many blocks to reserve and how many are used by this btree.
+ * We need enough space to hold one record for every rt extent in the rtgroup.
+ */
+xfs_filblks_t
+xfs_rtrefcountbt_calc_reserves(
+       struct xfs_mount        *mp)
+{
+       if (!xfs_has_rtreflink(mp))
+               return 0;
+
+       return xfs_rtrefcountbt_max_size(mp,
+                       xfs_rtb_to_rtx(mp, mp->m_sb.sb_rgblocks));
+}
index f617cd43a3d409da2a95c30191f375da1142a8fc..d5251bb7b578f4335e23c4140cba10969aad72f7 100644 (file)
@@ -72,4 +72,8 @@ void xfs_rtrefcountbt_destroy_cur_cache(void);
 #define xfs_rtrefcountbt_create_path(mp, rgno) \
        xfs_rtinode_create_path((mp), (rgno), "refcount")
 
+xfs_filblks_t xfs_rtrefcountbt_calc_reserves(struct xfs_mount *mp);
+unsigned long long xfs_rtrefcountbt_calc_size(struct xfs_mount *mp,
+               unsigned long long len);
+
 #endif /* __XFS_RTREFCOUNT_BTREE_H__ */