]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
xfs: create routine to allocate and initialize a realtime rmap btree inode
authorDarrick J. Wong <djwong@kernel.org>
Wed, 3 Jul 2024 21:22:18 +0000 (14:22 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 16 Jul 2024 22:49:20 +0000 (15:49 -0700)
Create a library routine to allocate and initialize an empty realtime
rmapbt inode.  We'll use this for mkfs and repair.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
libxfs/xfs_rtrmap_btree.c
libxfs/xfs_rtrmap_btree.h

index bec1fa886948b553d8e7e9e5bb34f323cb691923..6aed0cac2e70e1d761cf281b777586d5d517af3e 100644 (file)
@@ -802,3 +802,36 @@ xfs_iflush_rtrmap(
        xfs_rtrmapbt_to_disk(ip->i_mount, ifp->if_broot, ifp->if_broot_bytes,
                        dfp, XFS_DFORK_SIZE(dip, ip->i_mount, XFS_DATA_FORK));
 }
+
+/*
+ * Create a realtime rmap btree inode.
+ *
+ * Regardless of the return value, the caller must clean up @upd.  If a new
+ * inode is returned through @upd->ip, the caller must finish setting up that
+ * incore inode and release it.
+ */
+int
+xfs_rtrmapbt_create(
+       struct xfs_imeta_update *upd)
+{
+       struct xfs_mount        *mp = upd->mp;
+       struct xfs_ifork        *ifp;
+       int                     error;
+
+       error = xfs_imeta_create(upd, S_IFREG);
+       if (error)
+               return error;
+
+       ifp = xfs_ifork_ptr(upd->ip, XFS_DATA_FORK);
+       ifp->if_format = XFS_DINODE_FMT_RMAP;
+       ASSERT(ifp->if_broot_bytes == 0);
+       ASSERT(ifp->if_bytes == 0);
+
+       /* Initialize the empty incore btree root. */
+       xfs_iroot_alloc(upd->ip, XFS_DATA_FORK,
+                       xfs_rtrmap_broot_space_calc(mp, 0, 0));
+       xfs_btree_init_block(mp, ifp->if_broot, &xfs_rtrmapbt_ops, 0, 0,
+                       upd->ip->i_ino);
+       xfs_trans_log_inode(upd->tp, upd->ip, XFS_ILOG_CORE | XFS_ILOG_DBROOT);
+       return 0;
+}
index 727ced9cfbec7e241668f6fe33597ec76d0ce9e7..4d7d66fd85c01c9455834aa824e6c92371a59b86 100644 (file)
@@ -198,4 +198,8 @@ void xfs_rtrmapbt_to_disk(struct xfs_mount *mp, struct xfs_btree_block *rblock,
                unsigned int dblocklen);
 void xfs_iflush_rtrmap(struct xfs_inode *ip, struct xfs_dinode *dip);
 
+struct xfs_imeta_update;
+
+int xfs_rtrmapbt_create(struct xfs_imeta_update *upd);
+
 #endif /* __XFS_RTRMAP_BTREE_H__ */