]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
xfs: add metadata reservations for realtime refcount btree
authorDarrick J. Wong <djwong@kernel.org>
Thu, 15 Aug 2024 18:58:25 +0000 (11:58 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Fri, 16 Aug 2024 21:57:42 +0000 (14:57 -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 33399260045dd8b7e192a8fac6bc7971f7b50dfc..4defa97aba5b9ced6b14af8fcb8976846d15c40d 100644 (file)
@@ -423,3 +423,41 @@ 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, mp->m_sb.sb_rgextents);
+}
index 6d23ab3a9ad4156de84d5f2cf622f1ce61bae181..d1662f870f1c573f76fbf303e40bef6d7f1728ae 100644 (file)
@@ -68,4 +68,8 @@ unsigned int xfs_rtrefcountbt_maxlevels_ondisk(void);
 int __init xfs_rtrefcountbt_init_cur_cache(void);
 void xfs_rtrefcountbt_destroy_cur_cache(void);
 
+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__ */