]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
xfs: add metadata reservations for realtime refcount btree
authorDarrick J. Wong <djwong@kernel.org>
Tue, 7 Mar 2023 03:56:16 +0000 (19:56 -0800)
committerDarrick J. Wong <djwong@kernel.org>
Wed, 22 Nov 2023 23:03:41 +0000 (15:03 -0800)
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 95c3f0cd9081bae0dc30e13fcd004d8a4765e03f..196ae8b48357a2a2c35fac59bd54f8150d7fa157 100644 (file)
@@ -489,3 +489,42 @@ xfs_rtrefcountbt_create_path(
        *pathp = path;
        return 0;
 }
+
+/* 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 a149ab77453053f17ba88554ab7000a8e4a3436f..064f37334a9a7b1a89b67f1c743a77d97c572799 100644 (file)
@@ -72,4 +72,8 @@ void xfs_rtrefcountbt_destroy_cur_cache(void);
 int xfs_rtrefcountbt_create_path(struct xfs_mount *mp, xfs_rgnumber_t rgno,
                struct xfs_imeta_path **pathp);
 
+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__ */