summaryrefslogtreecommitdiff
path: root/fs
diff options
context:
space:
mode:
authorDarrick J. Wong <darrick.wong@oracle.com>2020-10-25 17:16:07 -0700
committerDarrick J. Wong <darrick.wong@oracle.com>2020-10-26 18:32:32 -0700
commit00eaf494f482334cc81ae01e2492e04009334401 (patch)
treee1cb074ba7708952d7108f0361dba613e1b4fbc5 /fs
parenta6f1a64ccbaf791d7e55cdf8230726595cc70947 (diff)
xfs: refactor creation of bmap btree roots
Now that we've created inode fork helpers to allocate and free btree roots, create a new bmap btree helper to create a new bmbt root, and refactor the extents <-> btree conversion functions to use our new helpers. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/xfs/libxfs/xfs_bmap.c20
-rw-r--r--fs/xfs/libxfs/xfs_bmap_btree.c17
-rw-r--r--fs/xfs/libxfs/xfs_bmap_btree.h1
3 files changed, 22 insertions, 16 deletions
diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
index 9dd1322511d3..6974819f46a7 100644
--- a/fs/xfs/libxfs/xfs_bmap.c
+++ b/fs/xfs/libxfs/xfs_bmap.c
@@ -639,7 +639,7 @@ xfs_bmap_btree_to_extents(
xfs_trans_binval(tp, cbp);
if (cur->bc_bufs[0] == cbp)
cur->bc_bufs[0] = NULL;
- xfs_iroot_realloc(ip, -1, whichfork);
+ xfs_iroot_free(ip, whichfork);
ASSERT(ifp->if_broot == NULL);
ASSERT((ifp->if_flags & XFS_IFBROOT) == 0);
ifp->if_format = XFS_DINODE_FMT_EXTENTS;
@@ -681,22 +681,9 @@ xfs_bmap_extents_to_btree(
ASSERT(ifp->if_format == XFS_DINODE_FMT_EXTENTS);
/*
- * Make space in the inode incore. This needs to be undone if we fail
- * to expand the root.
- */
- xfs_iroot_realloc(ip, 1, whichfork);
- ifp->if_flags |= XFS_IFBROOT;
-
- /*
- * Fill in the root.
- */
- block = ifp->if_broot;
- xfs_btree_init_block_int(mp, block, XFS_BUF_DADDR_NULL,
- XFS_BTNUM_BMAP, 1, 1, ip->i_ino,
- XFS_BTREE_LONG_PTRS);
- /*
* Need a cursor. Can't allocate until bb_level is filled in.
*/
+ xfs_bmbt_iroot_alloc(ip, whichfork);
cur = xfs_bmbt_init_cursor(mp, tp, ip, whichfork);
cur->bc_ino.flags = wasdel ? XFS_BTCUR_BMBT_WASDEL : 0;
/*
@@ -766,6 +753,7 @@ xfs_bmap_extents_to_btree(
/*
* Fill in the root key and pointer.
*/
+ block = ifp->if_broot;
kp = xfs_bmbt_key_addr(mp, block, 1);
arp = xfs_bmbt_rec_addr(mp, ablock, 1);
kp->br_startoff = cpu_to_be64(xfs_bmbt_disk_get_startoff(arp));
@@ -787,7 +775,7 @@ xfs_bmap_extents_to_btree(
out_unreserve_dquot:
xfs_trans_mod_dquot_byino(tp, ip, XFS_TRANS_DQ_BCOUNT, -1L);
out_root_realloc:
- xfs_iroot_realloc(ip, -1, whichfork);
+ xfs_iroot_free(ip, whichfork);
ifp->if_format = XFS_DINODE_FMT_EXTENTS;
ASSERT(ifp->if_broot == NULL);
xfs_btree_del_cursor(cur, XFS_BTREE_ERROR);
diff --git a/fs/xfs/libxfs/xfs_bmap_btree.c b/fs/xfs/libxfs/xfs_bmap_btree.c
index ae2ea83f5caf..2b0bfcf759a5 100644
--- a/fs/xfs/libxfs/xfs_bmap_btree.c
+++ b/fs/xfs/libxfs/xfs_bmap_btree.c
@@ -737,3 +737,20 @@ xfs_bmbt_calc_size(
{
return xfs_btree_calc_size(mp->m_bmap_dmnr, len);
}
+
+/* Create an incore bmbt btree root block. */
+void
+xfs_bmbt_iroot_alloc(
+ struct xfs_inode *ip,
+ int whichfork)
+{
+ struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, whichfork);
+
+ xfs_iroot_alloc(ip, whichfork,
+ xfs_bmap_broot_space_calc(ip->i_mount, 1));
+
+ /* Fill in the root. */
+ xfs_btree_init_block_int(ip->i_mount, ifp->if_broot,
+ XFS_BUF_DADDR_NULL, XFS_BTNUM_BMAP, 1, 1, ip->i_ino,
+ XFS_BTREE_LONG_PTRS);
+}
diff --git a/fs/xfs/libxfs/xfs_bmap_btree.h b/fs/xfs/libxfs/xfs_bmap_btree.h
index f1c7928bbc00..59b8620bc61b 100644
--- a/fs/xfs/libxfs/xfs_bmap_btree.h
+++ b/fs/xfs/libxfs/xfs_bmap_btree.h
@@ -191,5 +191,6 @@ xfs_bmap_bmdr_space(struct xfs_btree_block *bb)
return xfs_bmdr_space_calc(be16_to_cpu(bb->bb_numrecs));
}
+void xfs_bmbt_iroot_alloc(struct xfs_inode *ip, int whichfork);
#endif /* __XFS_BMAP_BTREE_H__ */