]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: cleanup xfs_idestroy_fork
authorChristoph Hellwig <hch@lst.de>
Mon, 10 Aug 2020 20:32:06 +0000 (16:32 -0400)
committerEric Sandeen <sandeen@sandeen.net>
Mon, 10 Aug 2020 20:32:06 +0000 (16:32 -0400)
Source kernel commit: ef8385128d4b31a382d496b1c433697993bd0bfb

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 <hch@lst.de>
Reviewed-by: Chandan Babu R <chandanrlinux@gmail.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
libxfs/rdwr.c
libxfs/xfs_attr_leaf.c
libxfs/xfs_inode_buf.c
libxfs/xfs_inode_fork.c
libxfs/xfs_inode_fork.h

index bcab3713ba86c2fed9979076553e6eabaf5b0aed..173d0dd2c0062ec8f90c652926d82204ff3c689a 100644 (file)
@@ -1274,13 +1274,17 @@ libxfs_idestroy(xfs_inode_t *ip)
                case S_IFREG:
                case S_IFDIR:
                case S_IFLNK:
-                       libxfs_idestroy_fork(ip, XFS_DATA_FORK);
+                       libxfs_idestroy_fork(&ip->i_df);
                        break;
        }
-       if (ip->i_afp)
-               libxfs_idestroy_fork(ip, XFS_ATTR_FORK);
-       if (ip->i_cowfp)
-               xfs_idestroy_fork(ip, XFS_COW_FORK);
+       if (ip->i_afp) {
+               libxfs_idestroy_fork(ip->i_afp);
+               kmem_cache_free(xfs_ifork_zone, ip->i_afp);
+       }
+       if (ip->i_cowfp) {
+               libxfs_idestroy_fork(ip->i_cowfp);
+               kmem_cache_free(xfs_ifork_zone, ip->i_cowfp);
+       }
 }
 
 void
index 77331821373eafa8f802058e3e1636f73edb5bfb..770eb1a4aeccf8fa4c95d335403efba354e053c3 100644 (file)
@@ -714,11 +714,10 @@ xfs_attr_fork_remove(
 {
        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;
-
-       ASSERT(ip->i_afp == NULL);
-
        xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
 }
 
index 586db284bb4c269f1fab90c17fa5e413c4d364a0..7a2d7464460becc9ab79d744c9ecff96518c5ca4 100644 (file)
@@ -268,7 +268,7 @@ xfs_inode_from_disk(
        return 0;
 
 out_destroy_data_fork:
-       xfs_idestroy_fork(ip, XFS_DATA_FORK);
+       xfs_idestroy_fork(&ip->i_df);
        return error;
 }
 
index 9fba85d50db23ad5f3e61e4261d0644549b12f99..f2de1ad523df46e4952ca2859bbbd6163f0f4a85 100644 (file)
@@ -501,38 +501,24 @@ xfs_idata_realloc(
 
 void
 xfs_idestroy_fork(
-       xfs_inode_t     *ip,
-       int             whichfork)
+       struct xfs_ifork        *ifp)
 {
-       struct xfs_ifork        *ifp;
-
-       ifp = XFS_IFORK_PTR(ip, whichfork);
        if (ifp->if_broot != NULL) {
                kmem_free(ifp->if_broot);
                ifp->if_broot = NULL;
        }
 
        /*
-        * If the format is local, then we can't have an extents
-        * array so just look for an inline data array.  If we're
-        * not local then we may or may not have an extents list,
-        * so check and free it up if we do.
+        * If the format is local, then we can't have an extents array so just
+        * look for an inline data array.  If we're not local then we may or may
+        * not have an extents list, so check and free it up if we do.
         */
        if (ifp->if_format == XFS_DINODE_FMT_LOCAL) {
-               if (ifp->if_u1.if_data != NULL) {
-                       kmem_free(ifp->if_u1.if_data);
-                       ifp->if_u1.if_data = NULL;
-               }
-       } else if ((ifp->if_flags & XFS_IFEXTENTS) && ifp->if_height) {
-               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;
+               kmem_free(ifp->if_u1.if_data);
+               ifp->if_u1.if_data = NULL;
+       } else if (ifp->if_flags & XFS_IFEXTENTS) {
+               if (ifp->if_height)
+                       xfs_iext_destroy(ifp);
        }
 }
 
index d849cca103edd7f45a41695bf8180d1eb9255a83..a4953e95c4f3f61f81ef6e3a72002d238e096f91 100644 (file)
@@ -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 *);
 void           xfs_iflush_fork(struct xfs_inode *, struct xfs_dinode *,
                                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,
                                int whichfork);
 void           xfs_iroot_realloc(struct xfs_inode *, int, int);