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:31 -0700
commita6f1a64ccbaf791d7e55cdf8230726595cc70947 (patch)
tree92bf2e59d926ddc466096be3cdebb39813190b8e /fs
parentb87141ad033761a7fb67022b235ef86573d58693 (diff)
xfs: refactor the allocation and freeing of incore inode fork btree roots
Refactor the code that allocates and freese the incore inode fork btree roots. This will help us disentangle some of the weird logic when we're creating and tearing down inode-based btrees. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/xfs/libxfs/xfs_inode_fork.c58
-rw-r--r--fs/xfs/libxfs/xfs_inode_fork.h3
2 files changed, 42 insertions, 19 deletions
diff --git a/fs/xfs/libxfs/xfs_inode_fork.c b/fs/xfs/libxfs/xfs_inode_fork.c
index 3cfd04ee28cc..7f41c4cabd76 100644
--- a/fs/xfs/libxfs/xfs_inode_fork.c
+++ b/fs/xfs/libxfs/xfs_inode_fork.c
@@ -207,8 +207,7 @@ xfs_iformat_btree(
return -EFSCORRUPTED;
}
- ifp->if_broot_bytes = size;
- ifp->if_broot = kmem_alloc(size, KM_NOFS);
+ xfs_iroot_alloc(ip, whichfork, size);
ASSERT(ifp->if_broot != NULL);
/*
* Copy and convert from the on-disk structure
@@ -217,8 +216,6 @@ xfs_iformat_btree(
xfs_bmdr_to_bmbt(ip, dfp, XFS_DFORK_SIZE(dip, ip->i_mount, whichfork),
ifp->if_broot, size);
ifp->if_flags &= ~XFS_IFEXTENTS;
- ifp->if_flags |= XFS_IFBROOT;
-
ifp->if_bytes = 0;
ifp->if_u1.if_root = NULL;
ifp->if_height = 0;
@@ -332,6 +329,34 @@ xfs_iformat_attr_fork(
return error;
}
+/* Allocate a new incore ifork btree root. */
+void
+xfs_iroot_alloc(
+ struct xfs_inode *ip,
+ int whichfork,
+ size_t bytes)
+{
+ struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, whichfork);
+
+ ifp->if_broot = kmem_alloc(bytes, KM_NOFS);
+ ifp->if_broot_bytes = bytes;
+ ifp->if_flags |= XFS_IFBROOT;
+}
+
+/* Free all the memory and state associated with an incore ifork btree root. */
+void
+xfs_iroot_free(
+ struct xfs_inode *ip,
+ int whichfork)
+{
+ struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, whichfork);
+
+ ifp->if_flags &= ~XFS_IFBROOT;
+ ifp->if_broot_bytes = 0;
+ kmem_free(ifp->if_broot);
+ ifp->if_broot = NULL;
+}
+
/*
* Reallocate the space for if_broot based on the number of records
* being added or deleted as indicated in rec_diff. Move the records
@@ -380,8 +405,7 @@ xfs_iroot_realloc(
*/
if (ifp->if_broot_bytes == 0) {
new_size = xfs_bmap_broot_space_calc(mp, rec_diff);
- ifp->if_broot = kmem_alloc(new_size, KM_NOFS);
- ifp->if_broot_bytes = (int)new_size;
+ xfs_iroot_alloc(ip, whichfork, new_size);
return;
}
@@ -420,18 +444,15 @@ xfs_iroot_realloc(
new_size = xfs_bmap_broot_space_calc(mp, new_max);
else
new_size = 0;
- if (new_size > 0) {
- new_broot = kmem_alloc(new_size, KM_NOFS);
- /*
- * First copy over the btree block header.
- */
- memcpy(new_broot, ifp->if_broot,
- xfs_bmbt_block_len(ip->i_mount));
- } else {
- new_broot = NULL;
- ifp->if_flags &= ~XFS_IFBROOT;
+ if (new_size == 0) {
+ xfs_iroot_free(ip, whichfork);
+ return;
}
+ /* First copy over the btree block header. */
+ new_broot = kmem_alloc(new_size, KM_NOFS);
+ memcpy(new_broot, ifp->if_broot, xfs_bmbt_block_len(ip->i_mount));
+
/*
* Only copy the records and pointers if there are any.
*/
@@ -455,9 +476,8 @@ xfs_iroot_realloc(
kmem_free(ifp->if_broot);
ifp->if_broot = new_broot;
ifp->if_broot_bytes = (int)new_size;
- if (ifp->if_broot)
- ASSERT(xfs_bmap_bmdr_space(ifp->if_broot) <=
- XFS_IFORK_SIZE(ip, whichfork));
+ ASSERT(xfs_bmap_bmdr_space(ifp->if_broot) <=
+ XFS_IFORK_SIZE(ip, whichfork));
return;
}
diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h
index d33ce5828856..923e183ff23d 100644
--- a/fs/xfs/libxfs/xfs_inode_fork.h
+++ b/fs/xfs/libxfs/xfs_inode_fork.h
@@ -89,6 +89,9 @@ void xfs_iflush_fork(struct xfs_inode *, struct xfs_dinode *,
void xfs_idestroy_fork(struct xfs_ifork *ifp);
void xfs_idata_realloc(struct xfs_inode *ip, int64_t byte_diff,
int whichfork);
+void xfs_iroot_alloc(struct xfs_inode *ip, int whichfork,
+ size_t bytes);
+void xfs_iroot_free(struct xfs_inode *ip, int whichfork);
void xfs_iroot_realloc(struct xfs_inode *, int, int);
int xfs_iread_extents(struct xfs_trans *, struct xfs_inode *, int);
int xfs_iextents_copy(struct xfs_inode *, struct xfs_bmbt_rec *,