]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
xfs: add realtime reverse map inode to metadata directory
authorDarrick J. Wong <djwong@kernel.org>
Thu, 15 Aug 2024 18:48:51 +0000 (11:48 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Fri, 16 Aug 2024 21:57:39 +0000 (14:57 -0700)
Add a metadir path to select the realtime rmap btree inode and load
it at mount time.  The rtrmapbt 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/xfs_format.h
libxfs/xfs_inode_buf.c
libxfs/xfs_inode_fork.c
libxfs/xfs_rtgroup.c
libxfs/xfs_rtgroup.h
libxfs/xfs_rtrmap_btree.c

index ddcc20a4a8313350fef4c82504e14d29f9299031..34210674f5411e1adc2f0e4cf74753308a217b72 100644 (file)
@@ -867,6 +867,7 @@ enum xfs_metafile_type {
        XFS_METAFILE_PRJQUOTA,          /* project quota */
        XFS_METAFILE_RTBITMAP,          /* rt bitmap */
        XFS_METAFILE_RTSUMMARY,         /* rt summary */
+       XFS_METAFILE_RTRMAP,            /* rt rmap */
 
        XFS_METAFILE_MAX
 } __packed;
@@ -878,7 +879,8 @@ enum xfs_metafile_type {
        { XFS_METAFILE_GRPQUOTA,        "grpquota" }, \
        { XFS_METAFILE_PRJQUOTA,        "prjquota" }, \
        { XFS_METAFILE_RTBITMAP,        "rtbitmap" }, \
-       { XFS_METAFILE_RTSUMMARY,       "rtsummary" }
+       { XFS_METAFILE_RTSUMMARY,       "rtsummary" }, \
+       { XFS_METAFILE_RTRMAP,          "rtrmap" }
 
 /*
  * On-disk inode structure.
@@ -1010,7 +1012,8 @@ enum xfs_dinode_fmt {
        XFS_DINODE_FMT_LOCAL,           /* bulk data */
        XFS_DINODE_FMT_EXTENTS,         /* struct xfs_bmbt_rec */
        XFS_DINODE_FMT_BTREE,           /* struct xfs_bmdr_block */
-       XFS_DINODE_FMT_UUID             /* added long ago, but never used */
+       XFS_DINODE_FMT_UUID,            /* added long ago, but never used */
+       XFS_DINODE_FMT_RMAP,            /* reverse mapping btree */
 };
 
 #define XFS_INODE_FORMAT_STR \
@@ -1018,7 +1021,8 @@ enum xfs_dinode_fmt {
        { XFS_DINODE_FMT_LOCAL,         "local" }, \
        { XFS_DINODE_FMT_EXTENTS,       "extent" }, \
        { XFS_DINODE_FMT_BTREE,         "btree" }, \
-       { XFS_DINODE_FMT_UUID,          "uuid" }
+       { XFS_DINODE_FMT_UUID,          "uuid" }, \
+       { XFS_DINODE_FMT_RMAP,          "rmap" }
 
 /*
  * Max values for extnum and aextnum.
index cb05f87f498f757d70a83d1d279231575f0a7793..72e8436c3bd01aa67f479963aedc5150b0259bc9 100644 (file)
@@ -437,6 +437,17 @@ xfs_dinode_verify_fork(
                if (di_nextents > max_extents)
                        return __this_address;
                break;
+       case XFS_DINODE_FMT_RMAP:
+               /*
+                * growfs must create the rtrmap inodes before adding a
+                * realtime volume to the filesystem, so we cannot use the
+                * rtrmapbt predicate here.
+                */
+               if (!xfs_has_rmapbt(mp))
+                       return __this_address;
+               if (!(dip->di_flags2 & cpu_to_be64(XFS_DIFLAG2_METADATA)))
+                       return __this_address;
+               break;
        default:
                return __this_address;
        }
@@ -456,6 +467,10 @@ xfs_dinode_verify_forkoff(
                if (dip->di_forkoff != (roundup(sizeof(xfs_dev_t), 8) >> 3))
                        return __this_address;
                break;
+       case XFS_DINODE_FMT_RMAP:
+               if (!(xfs_has_metadir(mp) && xfs_has_parent(mp)))
+                       return __this_address;
+               fallthrough;
        case XFS_DINODE_FMT_LOCAL:      /* fall through ... */
        case XFS_DINODE_FMT_EXTENTS:    /* fall through ... */
        case XFS_DINODE_FMT_BTREE:
index 98f788901755031dd2dc6ce3534c25b8c0ea4317..a056f896dcdf6c66139e87b3f0b67f6a6d455ce4 100644 (file)
@@ -266,6 +266,16 @@ xfs_iformat_data_fork(
                        return xfs_iformat_extents(ip, dip, XFS_DATA_FORK);
                case XFS_DINODE_FMT_BTREE:
                        return xfs_iformat_btree(ip, dip, XFS_DATA_FORK);
+               case XFS_DINODE_FMT_RMAP:
+                       /*
+                        * growfs must create the rtrmap inodes before adding a
+                        * realtime volume to the filesystem, so we cannot use
+                        * the rtrmapbt predicate here.
+                        */
+                       if (!xfs_has_rmapbt(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);
@@ -652,6 +662,10 @@ xfs_iflush_fork(
                }
                break;
 
+       case XFS_DINODE_FMT_RMAP:
+               ASSERT(0); /* to be implemented later */
+               break;
+
        default:
                ASSERT(0);
                break;
index 3a24371ba87885220882af79b2633efc1a556480..d20afc0f0885eee39a573c4f0511dd57264eb357 100644 (file)
@@ -309,7 +309,14 @@ xfs_rtginode_ilock_print_fn(
        const struct xfs_inode *ip =
                container_of(m, struct xfs_inode, i_lock.dep_map);
 
-       printk(KERN_CONT " rgno=%u", ip->i_projid);
+       switch (ip->i_df.if_format) {
+       case XFS_DINODE_FMT_RMAP:
+               printk(KERN_CONT " rgno=%u rmapbt", ip->i_projid);
+               break;
+       default:
+               printk(KERN_CONT " rgno=%u", ip->i_projid);
+               break;
+       }
 }
 
 /*
@@ -341,6 +348,8 @@ struct xfs_rtginode_ops {
 
        unsigned int            sick;   /* rtgroup sickness flag */
 
+       unsigned int            fmt_mask; /* all valid data fork formats */
+
        /* Does the fs have this feature? */
        bool                    (*enabled)(struct xfs_mount *mp);
 
@@ -356,14 +365,29 @@ static const struct xfs_rtginode_ops xfs_rtginode_ops[XFS_RTGI_MAX] = {
                .name           = "bitmap",
                .metafile_type  = XFS_METAFILE_RTBITMAP,
                .sick           = XFS_SICK_RG_BITMAP,
+               .fmt_mask       = (1U << XFS_DINODE_FMT_EXTENTS) |
+                                 (1U << XFS_DINODE_FMT_BTREE),
                .create         = xfs_rtbitmap_create,
        },
        [XFS_RTGI_SUMMARY] = {
                .name           = "summary",
                .metafile_type  = XFS_METAFILE_RTSUMMARY,
                .sick           = XFS_SICK_RG_SUMMARY,
+               .fmt_mask       = (1U << XFS_DINODE_FMT_EXTENTS) |
+                                 (1U << XFS_DINODE_FMT_BTREE),
                .create         = xfs_rtsummary_create,
        },
+       [XFS_RTGI_RMAP] = {
+               .name           = "rmap",
+               .metafile_type  = XFS_METAFILE_RTRMAP,
+               .fmt_mask       = 1U << XFS_DINODE_FMT_RMAP,
+               /*
+                * growfs must create the rtrmap inodes before adding a
+                * realtime volume to the filesystem, so we cannot use the
+                * rtrmapbt predicate here.
+                */
+               .enabled        = xfs_has_rmapbt,
+       },
 };
 
 /* Return the shortname of this rtgroup inode. */
@@ -458,6 +482,12 @@ xfs_rtginode_load(
                return error;
        }
 
+       if (XFS_IS_CORRUPT(mp, !((1U << ip->i_df.if_format) & ops->fmt_mask))) {
+               xfs_irele(ip);
+               xfs_rtgroup_mark_sick(rtg, ops->sick);
+               return -EFSCORRUPTED;
+       }
+
        if (XFS_IS_CORRUPT(mp, ip->i_projid != rtg->rtg_rgno)) {
                xfs_irele(ip);
                xfs_rtginode_mark_sick(rtg, type);
index 4525aaa26efc2e29766c8118a4df41059a0c9461..7d6ee6c5ba552d669aac45368184d2d919dc0aaa 100644 (file)
@@ -12,6 +12,7 @@ struct xfs_trans;
 enum xfs_rtg_inodes {
        XFS_RTGI_BITMAP,        /* allocation bitmap */
        XFS_RTGI_SUMMARY,       /* allocation summary */
+       XFS_RTGI_RMAP,          /* rmap btree inode */
 
        XFS_RTGI_MAX,
 };
@@ -265,6 +266,8 @@ int xfs_rtginode_create(struct xfs_rtgroup *rtg, enum xfs_rtg_inodes type,
                bool init);
 void xfs_rtginode_irele(struct xfs_inode **ipp);
 
+void xfs_rtginode_irele(struct xfs_inode **ipp);
+
 static inline const char *xfs_rtginode_path(xfs_rgnumber_t rgno,
                enum xfs_rtg_inodes type)
 {
index 2e1232155bd963847ef1aa11b3384fd11eacc38c..e421635afcab2e30f7d895d3a790b367ea4d5625 100644 (file)
@@ -18,6 +18,7 @@
 #include "xfs_alloc.h"
 #include "xfs_btree.h"
 #include "xfs_btree_staging.h"
+#include "xfs_metafile.h"
 #include "xfs_rmap.h"
 #include "xfs_rtrmap_btree.h"
 #include "xfs_trace.h"
@@ -441,6 +442,7 @@ xfs_rtrmapbt_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_RMAP);
 
        /*
         * Free any resources hanging off the real fork, then shallow-copy the