diff options
author | Darrick J. Wong <darrick.wong@oracle.com> | 2020-02-19 17:02:53 -0800 |
---|---|---|
committer | Darrick J. Wong <darrick.wong@oracle.com> | 2020-06-01 21:16:45 -0700 |
commit | 4b9c7054f8bc76adc127ce9812a0b1bb23213163 (patch) | |
tree | c7af4084f8e9f02188c7ec2dbdad7c2910ffdfa7 /fs | |
parent | 892f99f212df324029ce70abe50907beb343556d (diff) |
xfs: create routine to allocate and initialize a realtime rmap btree inode
Create a library routine to allocate and initialize an empty realtime
rmapbt inode. We'll use this for growfs, mkfs, and repair.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/xfs/libxfs/xfs_rtrmap_btree.c | 42 | ||||
-rw-r--r-- | fs/xfs/libxfs/xfs_rtrmap_btree.h | 5 |
2 files changed, 47 insertions, 0 deletions
diff --git a/fs/xfs/libxfs/xfs_rtrmap_btree.c b/fs/xfs/libxfs/xfs_rtrmap_btree.c index 1cb82db97830..1ab6d1ffcf4b 100644 --- a/fs/xfs/libxfs/xfs_rtrmap_btree.c +++ b/fs/xfs/libxfs/xfs_rtrmap_btree.c @@ -26,6 +26,7 @@ #include "xfs_extent_busy.h" #include "xfs_ag_resv.h" #include "xfs_bmap.h" +#include "xfs_imeta.h" /* * Realtime Reverse map btree. @@ -789,3 +790,44 @@ xfs_rtrmapbt_to_disk( memcpy(trp, frp, sizeof(*frp) * dmxr); } } + +/* + * Create a realtime rmap btree inode. The caller must clean up @ic and + * release the inode stored in @ipp (if it isn't NULL) regardless of the return + * value. + */ +int +xfs_rtrmapbt_create( + struct xfs_trans **tpp, + struct xfs_imeta_end *ic, + struct xfs_inode **ipp) +{ + struct xfs_mount *mp = (*tpp)->t_mountp; + struct xfs_inode *ip; + struct xfs_btree_block *block; + xfs_ino_t ino = NULLFSINO; + int error; + + *ipp = NULL; + error = xfs_imeta_lookup(mp, &XFS_IMETA_RTRMAPBT, &ino); + if (error) + return error; + if (ino != NULLFSINO) + return -EEXIST; + + error = xfs_imeta_create(tpp, &XFS_IMETA_RTRMAPBT, S_IFREG, ipp, ic); + if (error) + return error; + + ip = *ipp; + ip->i_d.di_format = XFS_DINODE_FMT_RMAP; + ASSERT(ip->i_df.if_broot_bytes == 0); + ASSERT(ip->i_df.if_bytes == 0); + ip->i_df.if_broot_bytes = XFS_RTRMAP_BROOT_SPACE_CALC(0, 0); + ip->i_df.if_broot = kmem_alloc(ip->i_df.if_broot_bytes, KM_NOFS); + block = ip->i_df.if_broot; + block->bb_numrecs = cpu_to_be16(0); + block->bb_level = cpu_to_be16(0); + xfs_trans_log_inode(*tpp, ip, XFS_ILOG_CORE | XFS_ILOG_DBROOT); + return 0; +} diff --git a/fs/xfs/libxfs/xfs_rtrmap_btree.h b/fs/xfs/libxfs/xfs_rtrmap_btree.h index 071b70a641fb..e26605e76096 100644 --- a/fs/xfs/libxfs/xfs_rtrmap_btree.h +++ b/fs/xfs/libxfs/xfs_rtrmap_btree.h @@ -101,4 +101,9 @@ void xfs_rtrmapbt_to_disk(struct xfs_mount *mp, struct xfs_btree_block *rblock, int rblocklen, struct xfs_rtrmap_root *dblock, int dblocklen); +struct xfs_imeta_end; + +int xfs_rtrmapbt_create(struct xfs_trans **tpp, struct xfs_imeta_end *ic, + struct xfs_inode **ipp); + #endif /* __XFS_RTRMAP_BTREE_H__ */ |