Skip to content

Commit b11b11e

Browse files
author
Darrick J. Wong
committed
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 <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]>
1 parent a9e583d commit b11b11e

File tree

7 files changed

+33
-24
lines changed

7 files changed

+33
-24
lines changed

fs/xfs/libxfs/xfs_inode_util.c

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,31 @@ xfs_inode_inherit_flags2(
233233
}
234234
}
235235

236+
/*
237+
* If we need to create attributes immediately after allocating the inode,
238+
* initialise an empty attribute fork right now. We use the default fork offset
239+
* for attributes here as we don't know exactly what size or how many
240+
* attributes we might be adding. We can do this safely here because we know
241+
* the data fork is completely empty and this saves us from needing to run a
242+
* separate transaction to set the fork offset in the immediate future.
243+
*
244+
* If we have parent pointers and the caller hasn't told us that the file will
245+
* never be linked into a directory tree, we /must/ create the attr fork.
246+
*/
247+
static inline bool
248+
xfs_icreate_want_attrfork(
249+
struct xfs_mount *mp,
250+
const struct xfs_icreate_args *args)
251+
{
252+
if (args->flags & XFS_ICREATE_INIT_XATTRS)
253+
return true;
254+
255+
if (!(args->flags & XFS_ICREATE_UNLINKABLE) && xfs_has_parent(mp))
256+
return true;
257+
258+
return false;
259+
}
260+
236261
/* Initialise an inode's attributes. */
237262
void
238263
xfs_inode_init(
@@ -325,16 +350,7 @@ xfs_inode_init(
325350
ASSERT(0);
326351
}
327352

328-
/*
329-
* If we need to create attributes immediately after allocating the
330-
* inode, initialise an empty attribute fork right now. We use the
331-
* default fork offset for attributes here as we don't know exactly what
332-
* size or how many attributes we might be adding. We can do this
333-
* safely here because we know the data fork is completely empty and
334-
* this saves us from needing to run a separate transaction to set the
335-
* fork offset in the immediate future.
336-
*/
337-
if (args->flags & XFS_ICREATE_INIT_XATTRS) {
353+
if (xfs_icreate_want_attrfork(mp, args)) {
338354
ip->i_forkoff = xfs_default_attroffset(ip) >> 3;
339355
xfs_ifork_init_attr(ip, XFS_DINODE_FMT_EXTENTS, 0);
340356

fs/xfs/libxfs/xfs_inode_util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ struct xfs_icreate_args {
3232

3333
#define XFS_ICREATE_TMPFILE (1U << 0) /* create an unlinked file */
3434
#define XFS_ICREATE_INIT_XATTRS (1U << 1) /* will set xattrs immediately */
35+
#define XFS_ICREATE_UNLINKABLE (1U << 2) /* cannot link into dir tree */
3536
uint16_t flags;
3637
};
3738

fs/xfs/scrub/tempfile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ xrep_tempfile_create(
4343
struct xfs_icreate_args args = {
4444
.pip = sc->mp->m_rootip,
4545
.mode = mode,
46-
.flags = XFS_ICREATE_TMPFILE,
46+
.flags = XFS_ICREATE_TMPFILE | XFS_ICREATE_UNLINKABLE,
4747
};
4848
struct xfs_mount *mp = sc->mp;
4949
struct xfs_trans *tp = NULL;

fs/xfs/xfs_inode.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2527,9 +2527,6 @@ xfs_rename_alloc_whiteout(
25272527
struct qstr name;
25282528
int error;
25292529

2530-
if (xfs_has_parent(dp->i_mount))
2531-
args.flags |= XFS_ICREATE_INIT_XATTRS;
2532-
25332530
error = xfs_create_tmpfile(&args, &tmpfile);
25342531
if (error)
25352532
return error;

fs/xfs/xfs_iops.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,6 @@ xfs_create_need_xattr(
158158
if (dir->i_sb->s_security)
159159
return true;
160160
#endif
161-
if (xfs_has_parent(XFS_I(dir)->i_mount))
162-
return true;
163161
return false;
164162
}
165163

@@ -215,12 +213,11 @@ xfs_generic_create(
215213
args.flags |= XFS_ICREATE_TMPFILE;
216214

217215
/*
218-
* If this temporary file will be linkable, set up the file
219-
* with an attr fork to receive a parent pointer.
216+
* If this temporary file will not be linkable, don't bother
217+
* creating an attr fork to receive a parent pointer.
220218
*/
221-
if (!(tmpfile->f_flags & O_EXCL) &&
222-
xfs_has_parent(XFS_I(dir)->i_mount))
223-
args.flags |= XFS_ICREATE_INIT_XATTRS;
219+
if (tmpfile->f_flags & O_EXCL)
220+
args.flags |= XFS_ICREATE_UNLINKABLE;
224221

225222
error = xfs_create_tmpfile(&args, &ip);
226223
}

fs/xfs/xfs_qm.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,7 @@ xfs_qm_qino_alloc(
795795
if (need_alloc) {
796796
struct xfs_icreate_args args = {
797797
.mode = S_IFREG,
798+
.flags = XFS_ICREATE_UNLINKABLE,
798799
};
799800
xfs_ino_t ino;
800801

fs/xfs/xfs_symlink.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,6 @@ xfs_symlink(
115115
if (xfs_is_shutdown(mp))
116116
return -EIO;
117117

118-
if (xfs_has_parent(mp))
119-
args.flags |= XFS_ICREATE_INIT_XATTRS;
120-
121118
/*
122119
* Check component lengths of the target path name.
123120
*/

0 commit comments

Comments
 (0)