]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: add realtime reverse map inode to metadata directory
authorDarrick J. Wong <djwong@kernel.org>
Mon, 24 Feb 2025 18:21:49 +0000 (10:21 -0800)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 25 Feb 2025 17:15:58 +0000 (09:15 -0800)
Source kernel commit: 6b08901a6e8fcda555f3ad39abd73bb0dd37f231

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>
Reviewed-by: Christoph Hellwig <hch@lst.de>
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 41ea4283c43cb4ddefb0da45fc7712a61805573a..f32c9fda5a195fd8909c1305f8be5a1529200c38 100644 (file)
@@ -857,6 +857,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;
@@ -868,7 +869,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.
index 10ce2e34969d99bf83fe7d97dd3e4ddfcdd20bc2..0278fbb63797011e3d4b56937855c309068a281f 100644 (file)
@@ -444,6 +444,15 @@ xfs_dinode_verify_fork(
                if (!(dip->di_flags2 & cpu_to_be64(XFS_DIFLAG2_METADATA)))
                        return __this_address;
                switch (be16_to_cpu(dip->di_metatype)) {
+               case XFS_METAFILE_RTRMAP:
+                       /*
+                        * 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;
+                       break;
                default:
                        return __this_address;
                }
index b66dc4ad0f52ef3b07509b186427362c436acf41..7c481d159cce159b8190dad94f1a8e28b835e113 100644 (file)
@@ -267,6 +267,9 @@ xfs_iformat_data_fork(
                        return xfs_iformat_btree(ip, dip, XFS_DATA_FORK);
                case XFS_DINODE_FMT_META_BTREE:
                        switch (ip->i_metatype) {
+                       case XFS_METAFILE_RTRMAP:
+                               ASSERT(0); /* to be implemented later */
+                               return -EFSCORRUPTED;
                        default:
                                break;
                        }
@@ -612,6 +615,9 @@ xfs_iflush_fork(
                        break;
 
                switch (ip->i_metatype) {
+               case XFS_METAFILE_RTRMAP:
+                       ASSERT(0); /* to be implemented later */
+                       break;
                default:
                        ASSERT(0);
                        break;
index b9da90c5062dc107838e058c2335e19b242dce27..d46ce8e7fa6e851de0e86d74f0a8b7e6acbd86a8 100644 (file)
@@ -312,6 +312,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);
 
@@ -327,14 +329,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_META_BTREE,
+               /*
+                * 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. */
@@ -431,8 +448,7 @@ xfs_rtginode_load(
                return error;
        }
 
-       if (XFS_IS_CORRUPT(mp, ip->i_df.if_format != XFS_DINODE_FMT_EXTENTS &&
-                              ip->i_df.if_format != XFS_DINODE_FMT_BTREE)) {
+       if (XFS_IS_CORRUPT(mp, !((1U << ip->i_df.if_format) & ops->fmt_mask))) {
                xfs_irele(ip);
                xfs_rtginode_mark_sick(rtg, type);
                return -EFSCORRUPTED;
index bff319fa5a71734620e114403ea7ccba12bfd2f5..09ec9f0e66016083c407976a6f4ab6e4645c4540 100644 (file)
@@ -14,6 +14,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,
 };
@@ -74,6 +75,11 @@ static inline struct xfs_inode *rtg_summary(const struct xfs_rtgroup *rtg)
        return rtg->rtg_inodes[XFS_RTGI_SUMMARY];
 }
 
+static inline struct xfs_inode *rtg_rmap(const struct xfs_rtgroup *rtg)
+{
+       return rtg->rtg_inodes[XFS_RTGI_RMAP];
+}
+
 /* Passive rtgroup references */
 static inline struct xfs_rtgroup *
 xfs_rtgroup_get(
@@ -284,6 +290,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 3c135648dfce4ed1b4fd6f49b77814f00b29c087..4c3b4a302bd7785159d7d5698025de9bf1af558d 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"
@@ -403,12 +404,10 @@ xfs_rtrmapbt_init_cursor(
        struct xfs_trans        *tp,
        struct xfs_rtgroup      *rtg)
 {
-       struct xfs_inode        *ip = NULL;
+       struct xfs_inode        *ip = rtg_rmap(rtg);
        struct xfs_mount        *mp = rtg_mount(rtg);
        struct xfs_btree_cur    *cur;
 
-       return NULL; /* XXX */
-
        xfs_assert_ilocked(ip, XFS_ILOCK_SHARED | XFS_ILOCK_EXCL);
 
        cur = xfs_btree_alloc_cursor(mp, tp, &xfs_rtrmapbt_ops,
@@ -437,6 +436,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_META_BTREE);
 
        /*
         * Free any resources hanging off the real fork, then shallow-copy the