summaryrefslogtreecommitdiff
path: root/fs/xfs/libxfs/xfs_inode_util.c
diff options
context:
space:
mode:
authorDarrick J. Wong <djwong@kernel.org>2024-07-02 11:22:41 -0700
committerDarrick J. Wong <djwong@kernel.org>2024-07-02 11:36:58 -0700
commitb11b11e3b7a72606cfef527255a9467537bcaaa5 (patch)
treeccbb97f18e0a5eb3d6f42851cdfa60a95b632ca0 /fs/xfs/libxfs/xfs_inode_util.c
parenta9e583d34facc64b6edf3c9afb2ff4891038176d (diff)
downloadlinux-b11b11e3b7a72606cfef527255a9467537bcaaa5.tar.gz
linux-b11b11e3b7a72606cfef527255a9467537bcaaa5.tar.bz2
linux-b11b11e3b7a72606cfef527255a9467537bcaaa5.zip
xfs: separate the icreate logic around INIT_XATTRS
INIT_XATTRS is overloaded here -- it's set during the creat process when we think that we're immediately going to set some ACL xattrs to save time. However, it's also used by the parent pointers code to enable the attr fork in preparation to receive ppptr xattrs. This results in xfs_has_parent() branches scattered around the codebase to turn on INIT_XATTRS. Linkable files are created far more commonly than unlinkable temporary files or directory tree roots, so we should centralize this logic in xfs_inode_init. For the three callers that don't want parent pointers (online repiar tempfiles, unlinkable tempfiles, rootdir creation) we provide an UNLINKABLE flag to skip attr fork initialization. Signed-off-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de>
Diffstat (limited to 'fs/xfs/libxfs/xfs_inode_util.c')
-rw-r--r--fs/xfs/libxfs/xfs_inode_util.c36
1 files changed, 26 insertions, 10 deletions
diff --git a/fs/xfs/libxfs/xfs_inode_util.c b/fs/xfs/libxfs/xfs_inode_util.c
index 214976ecefd7..5795445ef4bd 100644
--- a/fs/xfs/libxfs/xfs_inode_util.c
+++ b/fs/xfs/libxfs/xfs_inode_util.c
@@ -233,6 +233,31 @@ xfs_inode_inherit_flags2(
}
}
+/*
+ * If we need to create attributes immediately after allocating the inode,
+ * initialise an empty attribute fork right now. We use the default fork offset
+ * for attributes here as we don't know exactly what size or how many
+ * attributes we might be adding. We can do this safely here because we know
+ * the data fork is completely empty and this saves us from needing to run a
+ * separate transaction to set the fork offset in the immediate future.
+ *
+ * If we have parent pointers and the caller hasn't told us that the file will
+ * never be linked into a directory tree, we /must/ create the attr fork.
+ */
+static inline bool
+xfs_icreate_want_attrfork(
+ struct xfs_mount *mp,
+ const struct xfs_icreate_args *args)
+{
+ if (args->flags & XFS_ICREATE_INIT_XATTRS)
+ return true;
+
+ if (!(args->flags & XFS_ICREATE_UNLINKABLE) && xfs_has_parent(mp))
+ return true;
+
+ return false;
+}
+
/* Initialise an inode's attributes. */
void
xfs_inode_init(
@@ -325,16 +350,7 @@ xfs_inode_init(
ASSERT(0);
}
- /*
- * If we need to create attributes immediately after allocating the
- * inode, initialise an empty attribute fork right now. We use the
- * default fork offset for attributes here as we don't know exactly what
- * size or how many attributes we might be adding. We can do this
- * safely here because we know the data fork is completely empty and
- * this saves us from needing to run a separate transaction to set the
- * fork offset in the immediate future.
- */
- if (args->flags & XFS_ICREATE_INIT_XATTRS) {
+ if (xfs_icreate_want_attrfork(mp, args)) {
ip->i_forkoff = xfs_default_attroffset(ip) >> 3;
xfs_ifork_init_attr(ip, XFS_DINODE_FMT_EXTENTS, 0);