]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: simplify xfs_idata_realloc
authorChristoph Hellwig <hch@lst.de>
Fri, 5 Oct 2018 02:36:10 +0000 (21:36 -0500)
committerEric Sandeen <sandeen@redhat.com>
Fri, 5 Oct 2018 02:36:10 +0000 (21:36 -0500)
Source kernel commit: 1216b58b353fbf5529454b442cebb3c8f14d93da

Streamline the code and take advantage of the fact that kmem_realloc
through krealloc will be have like a normal allocation if passing in a
NULL old pointer.

Signed-off-by: Christoph Hellwig <hch@lst.de>
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/xfs_inode_fork.c

index 55818355818005253926e59a917c12248c5d80b2..ea2b5a0563ba71611260f59d2cf4655aae1ec923 100644 (file)
@@ -465,51 +465,34 @@ xfs_iroot_realloc(
  */
 void
 xfs_idata_realloc(
-       xfs_inode_t     *ip,
-       int             byte_diff,
-       int             whichfork)
+       struct xfs_inode        *ip,
+       int                     byte_diff,
+       int                     whichfork)
 {
-       xfs_ifork_t     *ifp;
-       int             new_size;
-       int             real_size;
-
-       if (byte_diff == 0) {
-               return;
-       }
+       struct xfs_ifork        *ifp = XFS_IFORK_PTR(ip, whichfork);
+       int                     new_size = (int)ifp->if_bytes + byte_diff;
 
-       ifp = XFS_IFORK_PTR(ip, whichfork);
-       new_size = (int)ifp->if_bytes + byte_diff;
        ASSERT(new_size >= 0);
+       ASSERT(new_size <= XFS_IFORK_SIZE(ip, whichfork));
+
+       if (byte_diff == 0)
+               return;
 
        if (new_size == 0) {
                kmem_free(ifp->if_u1.if_data);
                ifp->if_u1.if_data = NULL;
-               real_size = 0;
-       } else {
-               /*
-                * Stuck with malloc/realloc.
-                * For inline data, the underlying buffer must be
-                * a multiple of 4 bytes in size so that it can be
-                * logged and stay on word boundaries.  We enforce
-                * that here.
-                */
-               real_size = roundup(new_size, 4);
-               if (ifp->if_u1.if_data == NULL) {
-                       ifp->if_u1.if_data = kmem_alloc(real_size,
-                                                       KM_SLEEP | KM_NOFS);
-               } else {
-                       /*
-                        * Only do the realloc if the underlying size
-                        * is really changing.
-                        */
-                       ifp->if_u1.if_data =
-                               kmem_realloc(ifp->if_u1.if_data,
-                                               real_size,
-                                               KM_SLEEP | KM_NOFS);
-               }
+               ifp->if_bytes = 0;
+               return;
        }
+
+       /*
+        * For inline data, the underlying buffer must be a multiple of 4 bytes
+        * in size so that it can be logged and stay on word boundaries.
+        * We enforce that here.
+        */
+       ifp->if_u1.if_data = kmem_realloc(ifp->if_u1.if_data,
+                       roundup(new_size, 4), KM_SLEEP | KM_NOFS);
        ifp->if_bytes = new_size;
-       ASSERT(ifp->if_bytes <= XFS_IFORK_SIZE(ip, whichfork));
 }
 
 void