]> www.infradead.org Git - users/hch/xfs.git/commitdiff
xfs: add realtime reverse map inode to metadata directory
authorDarrick J. Wong <djwong@kernel.org>
Fri, 9 Aug 2024 06:56:16 +0000 (23:56 -0700)
committerChristoph Hellwig <hch@lst.de>
Sat, 10 Aug 2024 08:44:24 +0000 (10:44 +0200)
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>
fs/xfs/libxfs/xfs_format.h
fs/xfs/libxfs/xfs_inode_buf.c
fs/xfs/libxfs/xfs_inode_fork.c
fs/xfs/libxfs/xfs_rtgroup.c
fs/xfs/libxfs/xfs_rtgroup.h
fs/xfs/libxfs/xfs_rtrmap_btree.c
fs/xfs/xfs_inode.c
fs/xfs/xfs_inode_item.c
fs/xfs/xfs_inode_item_recover.c
fs/xfs/xfs_trace.h

index ef2232171829cd17c42e95c372e7ed1b0ab7b118..28501fae2c516632117bca6a25b993769d72bb97 100644 (file)
@@ -986,7 +986,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 \
@@ -994,7 +995,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 2870a66fbce31c16af35f9d5a4ef9072dd315b07..ab36e692bc1f4b0da34f736c15d534d75c8d2564 100644 (file)
@@ -434,6 +434,12 @@ xfs_dinode_verify_fork(
                if (di_nextents > max_extents)
                        return __this_address;
                break;
+       case XFS_DINODE_FMT_RMAP:
+               if (!xfs_has_rtrmapbt(mp))
+                       return __this_address;
+               if (!(dip->di_flags2 & cpu_to_be64(XFS_DIFLAG2_METADATA)))
+                       return __this_address;
+               break;
        default:
                return __this_address;
        }
@@ -453,6 +459,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 1606d59ca8f4826fe5a4a63db165707b4877b82f..931fafe4217a7271f7f7e1ec33ff08bca258c2fa 100644 (file)
@@ -268,6 +268,11 @@ 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:
+                       if (!xfs_has_rtrmapbt(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);
@@ -654,6 +659,10 @@ xfs_iflush_fork(
                }
                break;
 
+       case XFS_DINODE_FMT_RMAP:
+               ASSERT(0); /* to be implemented later */
+               break;
+
        default:
                ASSERT(0);
                break;
index c32ffce1ab42d702db0d63e6e458556b8fdbff1b..4fd3e5293d6efe8483adbcb0f97f0af461206f0f 100644 (file)
@@ -311,7 +311,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;
+       }
 }
 
 /*
@@ -339,6 +346,7 @@ xfs_rtginode_lockdep_setup(
 struct xfs_rtginode_ops {
        const char      *name;  /* short name */
        unsigned int    sick;   /* rtgroup sickness flag */
+       int8_t          format; /* data fork format */
 
        /* Does the fs have this feature? */
        bool            (*enabled)(struct xfs_mount *mp);
@@ -360,6 +368,11 @@ static const struct xfs_rtginode_ops xfs_rtginode_ops[XFS_RTG_MAX] = {
                .sick           = XFS_SICK_RG_SUMMARY,
                .create         = xfs_rtsummary_create,
        },
+       [XFS_RTG_RMAP] = {
+               .name           = "rmap",
+               .format         = XFS_DINODE_FMT_RMAP,
+               .enabled        = xfs_has_rtrmapbt,
+       },
 };
 
 /* Return the shortname of this rtgroup inode. */
@@ -400,6 +413,7 @@ xfs_rtginode_load(
        enum xfs_rtg_inodes     type,
        struct xfs_trans        *tp)
 {
+       const struct xfs_rtginode_ops *ops = &xfs_rtginode_ops[type];
        struct xfs_mount        *mp = tp->t_mountp;
        struct xfs_inode        *ip;
        int                     error;
@@ -438,6 +452,13 @@ xfs_rtginode_load(
                return error;
        }
 
+       if (ops->format &&
+           XFS_IS_CORRUPT(mp, ip->i_df.if_format != ops->format)) {
+               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 de72541ef11173ea67f8878981552f8fe8de3819..0c495df60f51c015937c66b5c5030da6c390ffaf 100644 (file)
@@ -12,6 +12,7 @@ struct xfs_trans;
 enum xfs_rtg_inodes {
        XFS_RTG_BITMAP,         /* allocation bitmap */
        XFS_RTG_SUMMARY,        /* allocation summary */
+       XFS_RTG_RMAP,           /* rmap btree inode */
 
        XFS_RTG_MAX,
 };
@@ -264,6 +265,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 696282cf915d1e379e89db087ab64c28a6035858..39d735cc1fd447f575944b8a3239adbd1ed95616 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"
@@ -443,6 +444,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
index 4ae628fe7d8771b8d744ec16d97b3c1a24e241a3..34a3b644cceb0d0cc5cbf23d8be29eb2ad452490 100644 (file)
@@ -2465,7 +2465,15 @@ xfs_iflush(
                        __func__, ip->i_ino, be16_to_cpu(dip->di_magic), dip);
                goto flush_out;
        }
-       if (S_ISREG(VFS_I(ip)->i_mode)) {
+       if (ip->i_df.if_format == XFS_DINODE_FMT_RMAP) {
+               if (!S_ISREG(VFS_I(ip)->i_mode) ||
+                   !(ip->i_diflags2 & XFS_DIFLAG2_METADATA)) {
+                       xfs_alert_tag(mp, XFS_PTAG_IFLUSH,
+                               "%s: Bad rt rmapbt inode %Lu, ptr "PTR_FMT,
+                               __func__, ip->i_ino, ip);
+                       goto flush_out;
+               }
+       } else if (S_ISREG(VFS_I(ip)->i_mode)) {
                if (XFS_TEST_ERROR(
                    ip->i_df.if_format != XFS_DINODE_FMT_EXTENTS &&
                    ip->i_df.if_format != XFS_DINODE_FMT_BTREE,
@@ -2505,6 +2513,15 @@ xfs_iflush(
                goto flush_out;
        }
 
+       if (xfs_inode_has_attr_fork(ip)) {
+               if (ip->i_af.if_format == XFS_DINODE_FMT_RMAP) {
+                       xfs_alert_tag(mp, XFS_PTAG_IFLUSH,
+                               "%s: rt rmapbt in inode %Lu attr fork, ptr "PTR_FMT,
+                               __func__, ip->i_ino, ip);
+                       goto flush_out;
+               }
+       }
+
        /*
         * Inode item log recovery for v2 inodes are dependent on the flushiter
         * count for correct sequencing.  We bump the flush iteration count so
index b509cbd191f4e6efde1d0703d553391c70153f94..8e823ed800f795acbe685bdda591f3dfe8febe1f 100644 (file)
@@ -242,6 +242,7 @@ xfs_inode_item_data_fork_size(
                }
                break;
        case XFS_DINODE_FMT_BTREE:
+       case XFS_DINODE_FMT_RMAP:
                if ((iip->ili_fields & XFS_ILOG_DBROOT) &&
                    ip->i_df.if_broot_bytes > 0) {
                        *nbytes += ip->i_df.if_broot_bytes;
@@ -362,6 +363,7 @@ xfs_inode_item_format_data_fork(
                }
                break;
        case XFS_DINODE_FMT_BTREE:
+       case XFS_DINODE_FMT_RMAP:
                iip->ili_fields &=
                        ~(XFS_ILOG_DDATA | XFS_ILOG_DEXT | XFS_ILOG_DEV);
 
index dbdab4ce7c44c484e32099594d6b5cb29ec679b0..b22584eaa2b7809359ba3f4c84fd5daad6f2c384 100644 (file)
@@ -394,6 +394,7 @@ xlog_recover_inode_commit_pass2(
 
        if (unlikely(S_ISREG(ldip->di_mode))) {
                if ((ldip->di_format != XFS_DINODE_FMT_EXTENTS) &&
+                   (ldip->di_format != XFS_DINODE_FMT_RMAP) &&
                    (ldip->di_format != XFS_DINODE_FMT_BTREE)) {
                        XFS_CORRUPTION_ERROR(
                                "Bad log dinode data fork format for regular file",
index b9b7c6353d97a0ced45f7628882b8a3b6958e7db..c89db1073876240a0bf2c854b246539a055c0c7f 100644 (file)
@@ -2215,6 +2215,7 @@ TRACE_DEFINE_ENUM(XFS_DINODE_FMT_LOCAL);
 TRACE_DEFINE_ENUM(XFS_DINODE_FMT_EXTENTS);
 TRACE_DEFINE_ENUM(XFS_DINODE_FMT_BTREE);
 TRACE_DEFINE_ENUM(XFS_DINODE_FMT_UUID);
+TRACE_DEFINE_ENUM(XFS_DINODE_FMT_RMAP);
 
 DECLARE_EVENT_CLASS(xfs_swap_extent_class,
        TP_PROTO(struct xfs_inode *ip, int which),