From b440d62dceebfbc703ca61eb2588a6ca11073e45 Mon Sep 17 00:00:00 2001 From: "Darrick J. Wong" Date: Wed, 3 Jul 2024 14:22:28 -0700 Subject: [PATCH] xfs: add realtime refcount btree inode to metadata directory 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 --- libxfs/init.c | 4 ++++ libxfs/xfs_format.h | 4 +++- libxfs/xfs_inode_buf.c | 8 ++++++++ libxfs/xfs_inode_fork.c | 9 +++++++++ libxfs/xfs_rtgroup.h | 3 +++ libxfs/xfs_rtrefcount_btree.c | 2 ++ libxfs/xfs_rtrefcount_btree.h | 4 ++++ 7 files changed, 33 insertions(+), 1 deletion(-) diff --git a/libxfs/init.c b/libxfs/init.c index 81531b119..b643665c2 100644 --- a/libxfs/init.c +++ b/libxfs/init.c @@ -913,6 +913,10 @@ libxfs_rtmount_destroy(xfs_mount_t *mp) xfs_rgnumber_t rgno; for_each_rtgroup(mp, rgno, rtg) { + if (rtg->rtg_refcountip) + libxfs_irele(rtg->rtg_refcountip); + rtg->rtg_refcountip = NULL; + if (rtg->rtg_rmapip) libxfs_irele(rtg->rtg_rmapip); rtg->rtg_rmapip = NULL; diff --git a/libxfs/xfs_format.h b/libxfs/xfs_format.h index b552bddc6..61f14829d 100644 --- a/libxfs/xfs_format.h +++ b/libxfs/xfs_format.h @@ -986,6 +986,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 \ @@ -994,7 +995,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. diff --git a/libxfs/xfs_inode_buf.c b/libxfs/xfs_inode_buf.c index 2ffb3174e..8da95c0fd 100644 --- a/libxfs/xfs_inode_buf.c +++ b/libxfs/xfs_inode_buf.c @@ -437,6 +437,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; } @@ -457,6 +463,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; @@ -738,6 +745,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) diff --git a/libxfs/xfs_inode_fork.c b/libxfs/xfs_inode_fork.c index b2a5a1552..5d91ec516 100644 --- a/libxfs/xfs_inode_fork.c +++ b/libxfs/xfs_inode_fork.c @@ -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; diff --git a/libxfs/xfs_rtgroup.h b/libxfs/xfs_rtgroup.h index f9c5f5d54..21a825184 100644 --- a/libxfs/xfs_rtgroup.h +++ b/libxfs/xfs_rtgroup.h @@ -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; diff --git a/libxfs/xfs_rtrefcount_btree.c b/libxfs/xfs_rtrefcount_btree.c index 8d5591ded..27a444182 100644 --- a/libxfs/xfs_rtrefcount_btree.c +++ b/libxfs/xfs_rtrefcount_btree.c @@ -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 diff --git a/libxfs/xfs_rtrefcount_btree.h b/libxfs/xfs_rtrefcount_btree.h index 6d23ab3a9..f617cd43a 100644 --- a/libxfs/xfs_rtrefcount_btree.h +++ b/libxfs/xfs_rtrefcount_btree.h @@ -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); +#define xfs_rtrefcountbt_create_path(mp, rgno) \ + xfs_rtinode_create_path((mp), (rgno), "refcount") + #endif /* __XFS_RTREFCOUNT_BTREE_H__ */ -- 2.50.1