]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
xfs: add realtime refcount btree inode to metadata directory
authorDarrick J. Wong <djwong@kernel.org>
Tue, 9 Jan 2024 17:44:25 +0000 (09:44 -0800)
committerDarrick J. Wong <djwong@kernel.org>
Wed, 10 Apr 2024 00:21:46 +0000 (17:21 -0700)
Add a metadir path to select the realtime refcount btree inode and load
it at mount time.  The rtrefcountbt inode will have a unique extent format
code, which means that we also have to update the inode validation and
flush routines to look for it.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
libxfs/init.c
libxfs/xfs_bmap.c
libxfs/xfs_format.h
libxfs/xfs_inode_buf.c
libxfs/xfs_inode_fork.c
libxfs/xfs_rtgroup.h
libxfs/xfs_rtrefcount_btree.c
libxfs/xfs_rtrefcount_btree.h

index 439a2bad6f9c78a1e5ca35c320133a6e173c02f2..882ec27446eab235e4dd1cd8cf14ce768d936958 100644 (file)
@@ -922,6 +922,10 @@ libxfs_rtmount_destroy(xfs_mount_t *mp)
        xfs_rgnumber_t          rgno;
 
        for_each_rtgroup(mp, rgno, rtg) {
+               if (rtg->rtg_refcountip)
+                       libxfs_imeta_irele(rtg->rtg_refcountip);
+               rtg->rtg_refcountip = NULL;
+
                if (rtg->rtg_rmapip)
                        libxfs_imeta_irele(rtg->rtg_rmapip);
                rtg->rtg_rmapip = NULL;
index 1985aaf30b159c968489e3779414fb3c7f14faad..0f2ec7ac1c8f728f0b15111e86ad45a750bda1bc 100644 (file)
@@ -5135,9 +5135,13 @@ xfs_bmap_del_extent_real(
                 * the same order of operations as the data device, which is:
                 * Remove the file mapping, remove the reverse mapping, and
                 * then free the blocks.  This means that we must delay the
-                * freeing until after we've scheduled the rmap update.
+                * freeing until after we've scheduled the rmap update.  If
+                * realtime reflink is enabled, use deferred refcount intent
+                * items to decide what to do with the extent, just like we do
+                * for the data device.
                 */
-               if (want_free && !xfs_has_rtrmapbt(mp)) {
+               if (want_free && !xfs_has_rtrmapbt(mp) &&
+                                !xfs_has_rtreflink(mp)) {
                        error = xfs_rtfree_blocks(tp, del->br_startblock,
                                        del->br_blockcount);
                        if (error)
index ca168e72c5dbd3425c1a63f885421fa7b0ade7b7..fd71b6c0c6b9a6480c77d31cb09378e04af28576 100644 (file)
@@ -1011,6 +1011,7 @@ enum xfs_dinode_fmt {
        XFS_DINODE_FMT_BTREE,           /* struct xfs_bmdr_block */
        XFS_DINODE_FMT_UUID,            /* added long ago, but never used */
        XFS_DINODE_FMT_RMAP,            /* reverse mapping btree */
+       XFS_DINODE_FMT_REFCOUNT,        /* reference count btree */
 };
 
 #define XFS_INODE_FORMAT_STR \
@@ -1019,7 +1020,8 @@ enum xfs_dinode_fmt {
        { XFS_DINODE_FMT_EXTENTS,       "extent" }, \
        { XFS_DINODE_FMT_BTREE,         "btree" }, \
        { XFS_DINODE_FMT_UUID,          "uuid" }, \
-       { XFS_DINODE_FMT_RMAP,          "rmap" }
+       { XFS_DINODE_FMT_RMAP,          "rmap" }, \
+       { XFS_DINODE_FMT_REFCOUNT,      "refcount" }
 
 /*
  * Max values for extnum and aextnum.
index e7bf8ff7046d90bef5d54966711d7722cd765642..6f4dbe8367b6c85292043356fa3de7385951d66f 100644 (file)
@@ -414,6 +414,12 @@ xfs_dinode_verify_fork(
                if (!(dip->di_flags2 & cpu_to_be64(XFS_DIFLAG2_METADIR)))
                        return __this_address;
                break;
+       case XFS_DINODE_FMT_REFCOUNT:
+               if (!xfs_has_rtreflink(mp))
+                       return __this_address;
+               if (!(dip->di_flags2 & cpu_to_be64(XFS_DIFLAG2_METADIR)))
+                       return __this_address;
+               break;
        default:
                return __this_address;
        }
@@ -434,6 +440,7 @@ xfs_dinode_verify_forkoff(
                        return __this_address;
                break;
        case XFS_DINODE_FMT_RMAP:
+       case XFS_DINODE_FMT_REFCOUNT:
                if (!(xfs_has_metadir(mp) && xfs_has_parent(mp)))
                        return __this_address;
                fallthrough;
@@ -705,6 +712,7 @@ xfs_dinode_verify(
        if (flags2 & XFS_DIFLAG2_METADIR) {
                switch (XFS_DFORK_FORMAT(dip, XFS_DATA_FORK)) {
                case XFS_DINODE_FMT_RMAP:
+               case XFS_DINODE_FMT_REFCOUNT:
                        break;
                default:
                        if (nextents + naextents == 0 && nblocks != 0)
index 7803c87651874114d81250907d8adc91c8b25054..cfc6ad342ac4a53cf2b1a1438badcddf32b00499 100644 (file)
@@ -273,6 +273,11 @@ xfs_iformat_data_fork(
                                return -EFSCORRUPTED;
                        }
                        return xfs_iformat_rtrmap(ip, dip);
+               case XFS_DINODE_FMT_REFCOUNT:
+                       if (!xfs_has_rtreflink(ip->i_mount))
+                               return -EFSCORRUPTED;
+                       ASSERT(0); /* to be implemented later */
+                       return -EFSCORRUPTED;
                default:
                        xfs_inode_verifier_error(ip, -EFSCORRUPTED, __func__,
                                        dip, sizeof(*dip), __this_address);
@@ -665,6 +670,10 @@ xfs_iflush_fork(
                        xfs_iflush_rtrmap(ip, dip);
                break;
 
+       case XFS_DINODE_FMT_REFCOUNT:
+               ASSERT(0); /* to be implemented later */
+               break;
+
        default:
                ASSERT(0);
                break;
index 0280946290d0ee3c5617d63633084898c9eb8514..d88ab4bcfacb93a6916f92240321df91093036b0 100644 (file)
@@ -25,6 +25,9 @@ struct xfs_rtgroup {
        /* reverse mapping btree inode */
        struct xfs_inode        *rtg_rmapip;
 
+       /* refcount btree inode */
+       struct xfs_inode        *rtg_refcountip;
+
        /* Number of blocks in this group */
        xfs_rgblock_t           rtg_blockcount;
 
index 8d5591ded4c570ef896a9d98b3cf8411af6f0375..94a934ed593df878d4bac4a5f36d3425bd5a3c4e 100644 (file)
@@ -24,6 +24,7 @@
 #include "xfs_cksum.h"
 #include "xfs_rtgroup.h"
 #include "xfs_rtbitmap.h"
+#include "xfs_imeta.h"
 
 static struct kmem_cache       *xfs_rtrefcountbt_cur_cache;
 
@@ -318,6 +319,7 @@ xfs_rtrefcountbt_commit_staged_btree(
        int                     flags = XFS_ILOG_CORE | XFS_ILOG_DBROOT;
 
        ASSERT(cur->bc_flags & XFS_BTREE_STAGING);
+       ASSERT(ifake->if_fork->if_format == XFS_DINODE_FMT_REFCOUNT);
 
        /*
         * Free any resources hanging off the real fork, then shallow-copy the
@@ -420,3 +422,34 @@ xfs_rtrefcountbt_compute_maxlevels(
        /* Add one level to handle the inode root level. */
        mp->m_rtrefc_maxlevels = min(d_maxlevels, r_maxlevels) + 1;
 }
+
+#define XFS_RTREFC_NAMELEN             21
+
+/* Create the metadata directory path for an rtrefcount btree inode. */
+int
+xfs_rtrefcountbt_create_path(
+       struct xfs_mount        *mp,
+       xfs_rgnumber_t          rgno,
+       struct xfs_imeta_path   **pathp)
+{
+       struct xfs_imeta_path   *path;
+       char                    *fname;
+       int                     error;
+
+       error = xfs_imeta_create_file_path(mp, 2, &path);
+       if (error)
+               return error;
+
+       fname = kmalloc(XFS_RTREFC_NAMELEN, GFP_KERNEL);
+       if (!fname) {
+               xfs_imeta_free_path(path);
+               return -ENOMEM;
+       }
+
+       snprintf(fname, XFS_RTREFC_NAMELEN, "%u.refcount", rgno);
+       path->im_path[0] = "realtime";
+       path->im_path[1] = fname;
+       path->im_dynamicmask = 0x2;
+       *pathp = path;
+       return 0;
+}
index 6d23ab3a9ad4156de84d5f2cf622f1ce61bae181..ff49e95d1a4905b66e2f48764fb9e5da6485bbe7 100644 (file)
@@ -11,6 +11,7 @@ struct xfs_btree_cur;
 struct xfs_mount;
 struct xbtree_ifakeroot;
 struct xfs_rtgroup;
+struct xfs_imeta_path;
 
 /* refcounts only exist on crc enabled filesystems */
 #define XFS_RTREFCOUNT_BLOCK_LEN       XFS_BTREE_LBLOCK_CRC_LEN
@@ -68,4 +69,7 @@ unsigned int xfs_rtrefcountbt_maxlevels_ondisk(void);
 int __init xfs_rtrefcountbt_init_cur_cache(void);
 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);
+
 #endif /* __XFS_RTREFCOUNT_BTREE_H__ */