Skip to content

Commit ef83851

Browse files
Christoph Hellwigdjwong
authored andcommitted
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: Christoph Hellwig <[email protected]> Reviewed-by: Chandan Babu R <[email protected]> Reviewed-by: Brian Foster <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Darrick J. Wong <[email protected]>
1 parent f7e67b2 commit ef83851

File tree

6 files changed

+28
-37
lines changed

6 files changed

+28
-37
lines changed

fs/xfs/libxfs/xfs_attr_leaf.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -717,11 +717,10 @@ xfs_attr_fork_remove(
717717
{
718718
ASSERT(ip->i_afp->if_nextents == 0);
719719

720-
xfs_idestroy_fork(ip, XFS_ATTR_FORK);
720+
xfs_idestroy_fork(ip->i_afp);
721+
kmem_cache_free(xfs_ifork_zone, ip->i_afp);
722+
ip->i_afp = NULL;
721723
ip->i_d.di_forkoff = 0;
722-
723-
ASSERT(ip->i_afp == NULL);
724-
725724
xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
726725
}
727726

fs/xfs/libxfs/xfs_inode_buf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ xfs_inode_from_disk(
271271
return 0;
272272

273273
out_destroy_data_fork:
274-
xfs_idestroy_fork(ip, XFS_DATA_FORK);
274+
xfs_idestroy_fork(&ip->i_df);
275275
return error;
276276
}
277277

fs/xfs/libxfs/xfs_inode_fork.c

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -503,38 +503,24 @@ xfs_idata_realloc(
503503

504504
void
505505
xfs_idestroy_fork(
506-
xfs_inode_t *ip,
507-
int whichfork)
506+
struct xfs_ifork *ifp)
508507
{
509-
struct xfs_ifork *ifp;
510-
511-
ifp = XFS_IFORK_PTR(ip, whichfork);
512508
if (ifp->if_broot != NULL) {
513509
kmem_free(ifp->if_broot);
514510
ifp->if_broot = NULL;
515511
}
516512

517513
/*
518-
* If the format is local, then we can't have an extents
519-
* array so just look for an inline data array. If we're
520-
* not local then we may or may not have an extents list,
521-
* so check and free it up if we do.
514+
* If the format is local, then we can't have an extents array so just
515+
* look for an inline data array. If we're not local then we may or may
516+
* not have an extents list, so check and free it up if we do.
522517
*/
523518
if (ifp->if_format == XFS_DINODE_FMT_LOCAL) {
524-
if (ifp->if_u1.if_data != NULL) {
525-
kmem_free(ifp->if_u1.if_data);
526-
ifp->if_u1.if_data = NULL;
527-
}
528-
} else if ((ifp->if_flags & XFS_IFEXTENTS) && ifp->if_height) {
529-
xfs_iext_destroy(ifp);
530-
}
531-
532-
if (whichfork == XFS_ATTR_FORK) {
533-
kmem_cache_free(xfs_ifork_zone, ip->i_afp);
534-
ip->i_afp = NULL;
535-
} else if (whichfork == XFS_COW_FORK) {
536-
kmem_cache_free(xfs_ifork_zone, ip->i_cowfp);
537-
ip->i_cowfp = NULL;
519+
kmem_free(ifp->if_u1.if_data);
520+
ifp->if_u1.if_data = NULL;
521+
} else if (ifp->if_flags & XFS_IFEXTENTS) {
522+
if (ifp->if_height)
523+
xfs_iext_destroy(ifp);
538524
}
539525
}
540526

fs/xfs/libxfs/xfs_inode_fork.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ int xfs_iformat_data_fork(struct xfs_inode *, struct xfs_dinode *);
8686
int xfs_iformat_attr_fork(struct xfs_inode *, struct xfs_dinode *);
8787
void xfs_iflush_fork(struct xfs_inode *, struct xfs_dinode *,
8888
struct xfs_inode_log_item *, int);
89-
void xfs_idestroy_fork(struct xfs_inode *, int);
89+
void xfs_idestroy_fork(struct xfs_ifork *ifp);
9090
void xfs_idata_realloc(struct xfs_inode *ip, int64_t byte_diff,
9191
int whichfork);
9292
void xfs_iroot_realloc(struct xfs_inode *, int, int);

fs/xfs/xfs_attr_inactive.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,11 @@ xfs_attr_inactive(
388388
xfs_trans_cancel(trans);
389389
out_destroy_fork:
390390
/* kill the in-core attr fork before we drop the inode lock */
391-
if (dp->i_afp)
392-
xfs_idestroy_fork(dp, XFS_ATTR_FORK);
391+
if (dp->i_afp) {
392+
xfs_idestroy_fork(dp->i_afp);
393+
kmem_cache_free(xfs_ifork_zone, dp->i_afp);
394+
dp->i_afp = NULL;
395+
}
393396
if (lock_mode)
394397
xfs_iunlock(dp, lock_mode);
395398
return error;

fs/xfs/xfs_icache.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,18 @@ xfs_inode_free_callback(
8787
case S_IFREG:
8888
case S_IFDIR:
8989
case S_IFLNK:
90-
xfs_idestroy_fork(ip, XFS_DATA_FORK);
90+
xfs_idestroy_fork(&ip->i_df);
9191
break;
9292
}
9393

94-
if (ip->i_afp)
95-
xfs_idestroy_fork(ip, XFS_ATTR_FORK);
96-
if (ip->i_cowfp)
97-
xfs_idestroy_fork(ip, XFS_COW_FORK);
98-
94+
if (ip->i_afp) {
95+
xfs_idestroy_fork(ip->i_afp);
96+
kmem_cache_free(xfs_ifork_zone, ip->i_afp);
97+
}
98+
if (ip->i_cowfp) {
99+
xfs_idestroy_fork(ip->i_cowfp);
100+
kmem_cache_free(xfs_ifork_zone, ip->i_cowfp);
101+
}
99102
if (ip->i_itemp) {
100103
ASSERT(!test_bit(XFS_LI_IN_AIL,
101104
&ip->i_itemp->ili_item.li_flags));

0 commit comments

Comments
 (0)