]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
libxfs: split new inode creation into two pieces
authorDarrick J. Wong <djwong@kernel.org>
Wed, 2 Oct 2024 01:12:16 +0000 (18:12 -0700)
committerAndrey Albershteyn <aalbersh@redhat.com>
Fri, 4 Oct 2024 10:42:07 +0000 (12:42 +0200)
Source kernel commit: 38fd3d6a956f1b104f11cd6eee116c54bfe458c4

There are two parts to initializing a newly allocated inode: setting up
the incore structures, and initializing the new inode core based on the
parent inode and the current user's environment.  The initialization
code is not specific to the kernel, so we would like to share that with
userspace by hoisting it to libxfs.  Therefore, split xfs_icreate into
separate functions to prepare for the next few patches.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
libxfs/inode.c

index 3e72b25cc5fb78e75895e697b59cf65303d3fac7..206b779a8e96da706086927e6e1484285de53370 100644 (file)
@@ -91,33 +91,21 @@ libxfs_bumplink(
        xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
 }
 
-/*
- * Initialise a newly allocated inode and return the in-core inode to the
- * caller locked exclusively.
- */
-static int
-libxfs_icreate(
+/* Initialise an inode's attributes. */
+static void
+xfs_inode_init(
        struct xfs_trans        *tp,
-       xfs_ino_t               ino,
        const struct xfs_icreate_args *args,
-       struct xfs_inode        **ipp)
+       struct xfs_inode        *ip)
 {
        struct xfs_mount        *mp = tp->t_mountp;
        struct xfs_inode        *pip = args->pip;
        struct inode            *dir = pip ? VFS_I(pip) : NULL;
-       struct inode            *inode;
-       struct xfs_inode        *ip;
+       struct inode            *inode = VFS_I(ip);
        unsigned int            flags;
        int                     times = XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG |
                                        XFS_ICHGTIME_ACCESS;
-       int                     error;
-
-       error = libxfs_iget(mp, tp, ino, XFS_IGET_CREATE, &ip);
-       if (error != 0)
-               return error;
-       ASSERT(ip != NULL);
 
-       inode = VFS_I(ip);
        inode->i_mode = args->mode;
        if (args->flags & XFS_ICREATE_TMPFILE)
                set_nlink(inode, 0);
@@ -201,11 +189,32 @@ libxfs_icreate(
                }
        }
 
-       /*
-        * Log the new values stuffed into the inode.
-        */
-       xfs_trans_ijoin(tp, ip, 0);
        xfs_trans_log_inode(tp, ip, flags);
+}
+
+/*
+ * Initialise a newly allocated inode and return the in-core inode to the
+ * caller locked exclusively.
+ */
+static int
+libxfs_icreate(
+       struct xfs_trans        *tp,
+       xfs_ino_t               ino,
+       const struct xfs_icreate_args *args,
+       struct xfs_inode        **ipp)
+{
+       struct xfs_mount        *mp = tp->t_mountp;
+       struct xfs_inode        *ip = NULL;
+       int                     error;
+
+       error = libxfs_iget(mp, tp, ino, XFS_IGET_CREATE, &ip);
+       if (error)
+               return error;
+
+       ASSERT(ip != NULL);
+       xfs_trans_ijoin(tp, ip, 0);
+       xfs_inode_init(tp, args, ip);
+
        *ipp = ip;
        return 0;
 }