Commit ef838512 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Darrick J. Wong

xfs: cleanup xfs_idestroy_fork

Move freeing the dynamically allocated attr and COW fork, as well
as zeroing the pointers where actually needed into the callers, and
just pass the xfs_ifork structure to xfs_idestroy_fork.  Also simplify
the kmem_free calls by not checking for NULL first.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarChandan Babu R <chandanrlinux@gmail.com>
Reviewed-by: default avatarBrian Foster <bfoster@redhat.com>
Reviewed-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
parent f7e67b20
...@@ -717,11 +717,10 @@ xfs_attr_fork_remove( ...@@ -717,11 +717,10 @@ xfs_attr_fork_remove(
{ {
ASSERT(ip->i_afp->if_nextents == 0); ASSERT(ip->i_afp->if_nextents == 0);
xfs_idestroy_fork(ip, XFS_ATTR_FORK); xfs_idestroy_fork(ip->i_afp);
kmem_cache_free(xfs_ifork_zone, ip->i_afp);
ip->i_afp = NULL;
ip->i_d.di_forkoff = 0; ip->i_d.di_forkoff = 0;
ASSERT(ip->i_afp == NULL);
xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
} }
......
...@@ -271,7 +271,7 @@ xfs_inode_from_disk( ...@@ -271,7 +271,7 @@ xfs_inode_from_disk(
return 0; return 0;
out_destroy_data_fork: out_destroy_data_fork:
xfs_idestroy_fork(ip, XFS_DATA_FORK); xfs_idestroy_fork(&ip->i_df);
return error; return error;
} }
......
...@@ -503,38 +503,24 @@ xfs_idata_realloc( ...@@ -503,38 +503,24 @@ xfs_idata_realloc(
void void
xfs_idestroy_fork( xfs_idestroy_fork(
xfs_inode_t *ip, struct xfs_ifork *ifp)
int whichfork)
{ {
struct xfs_ifork *ifp;
ifp = XFS_IFORK_PTR(ip, whichfork);
if (ifp->if_broot != NULL) { if (ifp->if_broot != NULL) {
kmem_free(ifp->if_broot); kmem_free(ifp->if_broot);
ifp->if_broot = NULL; ifp->if_broot = NULL;
} }
/* /*
* If the format is local, then we can't have an extents * If the format is local, then we can't have an extents array so just
* array so just look for an inline data array. If we're * look for an inline data array. If we're not local then we may or may
* not local then we may or may not have an extents list, * not have an extents list, so check and free it up if we do.
* so check and free it up if we do.
*/ */
if (ifp->if_format == XFS_DINODE_FMT_LOCAL) { if (ifp->if_format == XFS_DINODE_FMT_LOCAL) {
if (ifp->if_u1.if_data != NULL) { kmem_free(ifp->if_u1.if_data);
kmem_free(ifp->if_u1.if_data); ifp->if_u1.if_data = NULL;
ifp->if_u1.if_data = NULL; } else if (ifp->if_flags & XFS_IFEXTENTS) {
} if (ifp->if_height)
} else if ((ifp->if_flags & XFS_IFEXTENTS) && ifp->if_height) { xfs_iext_destroy(ifp);
xfs_iext_destroy(ifp);
}
if (whichfork == XFS_ATTR_FORK) {
kmem_cache_free(xfs_ifork_zone, ip->i_afp);
ip->i_afp = NULL;
} else if (whichfork == XFS_COW_FORK) {
kmem_cache_free(xfs_ifork_zone, ip->i_cowfp);
ip->i_cowfp = NULL;
} }
} }
......
...@@ -86,7 +86,7 @@ int xfs_iformat_data_fork(struct xfs_inode *, struct xfs_dinode *); ...@@ -86,7 +86,7 @@ int xfs_iformat_data_fork(struct xfs_inode *, struct xfs_dinode *);
int xfs_iformat_attr_fork(struct xfs_inode *, struct xfs_dinode *); int xfs_iformat_attr_fork(struct xfs_inode *, struct xfs_dinode *);
void xfs_iflush_fork(struct xfs_inode *, struct xfs_dinode *, void xfs_iflush_fork(struct xfs_inode *, struct xfs_dinode *,
struct xfs_inode_log_item *, int); struct xfs_inode_log_item *, int);
void xfs_idestroy_fork(struct xfs_inode *, int); void xfs_idestroy_fork(struct xfs_ifork *ifp);
void xfs_idata_realloc(struct xfs_inode *ip, int64_t byte_diff, void xfs_idata_realloc(struct xfs_inode *ip, int64_t byte_diff,
int whichfork); int whichfork);
void xfs_iroot_realloc(struct xfs_inode *, int, int); void xfs_iroot_realloc(struct xfs_inode *, int, int);
......
...@@ -388,8 +388,11 @@ xfs_attr_inactive( ...@@ -388,8 +388,11 @@ xfs_attr_inactive(
xfs_trans_cancel(trans); xfs_trans_cancel(trans);
out_destroy_fork: out_destroy_fork:
/* kill the in-core attr fork before we drop the inode lock */ /* kill the in-core attr fork before we drop the inode lock */
if (dp->i_afp) if (dp->i_afp) {
xfs_idestroy_fork(dp, XFS_ATTR_FORK); xfs_idestroy_fork(dp->i_afp);
kmem_cache_free(xfs_ifork_zone, dp->i_afp);
dp->i_afp = NULL;
}
if (lock_mode) if (lock_mode)
xfs_iunlock(dp, lock_mode); xfs_iunlock(dp, lock_mode);
return error; return error;
......
...@@ -87,15 +87,18 @@ xfs_inode_free_callback( ...@@ -87,15 +87,18 @@ xfs_inode_free_callback(
case S_IFREG: case S_IFREG:
case S_IFDIR: case S_IFDIR:
case S_IFLNK: case S_IFLNK:
xfs_idestroy_fork(ip, XFS_DATA_FORK); xfs_idestroy_fork(&ip->i_df);
break; break;
} }
if (ip->i_afp) if (ip->i_afp) {
xfs_idestroy_fork(ip, XFS_ATTR_FORK); xfs_idestroy_fork(ip->i_afp);
if (ip->i_cowfp) kmem_cache_free(xfs_ifork_zone, ip->i_afp);
xfs_idestroy_fork(ip, XFS_COW_FORK); }
if (ip->i_cowfp) {
xfs_idestroy_fork(ip->i_cowfp);
kmem_cache_free(xfs_ifork_zone, ip->i_cowfp);
}
if (ip->i_itemp) { if (ip->i_itemp) {
ASSERT(!test_bit(XFS_LI_IN_AIL, ASSERT(!test_bit(XFS_LI_IN_AIL,
&ip->i_itemp->ili_item.li_flags)); &ip->i_itemp->ili_item.li_flags));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment