Skip to content

Commit a65e58e

Browse files
author
Christian Brauner
committed
fs: document and rename fsid helpers
Vivek pointed out that the fs{g,u}id_into_mnt() naming scheme can be misleading as it could be understood as implying they do the exact same thing as i_{g,u}id_into_mnt(). The original motivation for this naming scheme was to signal to callers that the helpers will always take care to map the k{g,u}id such that the ownership is expressed in terms of the mnt_users. Get rid of the confusion by renaming those helpers to something more sensible. Al suggested mapped_fs{g,u}id() which seems a really good fit. Usually filesystems don't need to bother with these helpers directly only in some cases where they allocate objects that carry {g,u}ids which are either filesystem specific (e.g. xfs quota objects) or don't have a clean set of helpers as inodes have. Link: https://lore.kernel.org/r/[email protected] Inspired-by: Vivek Goyal <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: Darrick J. Wong <[email protected]> Cc: Al Viro <[email protected]> Cc: [email protected] Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent 1bd66c1 commit a65e58e

File tree

6 files changed

+40
-16
lines changed

6 files changed

+40
-16
lines changed

fs/ext4/ialloc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ struct inode *__ext4_new_inode(struct user_namespace *mnt_userns,
970970
i_gid_write(inode, owner[1]);
971971
} else if (test_opt(sb, GRPID)) {
972972
inode->i_mode = mode;
973-
inode->i_uid = fsuid_into_mnt(mnt_userns);
973+
inode->i_uid = mapped_fsuid(mnt_userns);
974974
inode->i_gid = dir->i_gid;
975975
} else
976976
inode_init_owner(mnt_userns, inode, dir, mode);

fs/inode.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2148,7 +2148,7 @@ EXPORT_SYMBOL(init_special_inode);
21482148
void inode_init_owner(struct user_namespace *mnt_userns, struct inode *inode,
21492149
const struct inode *dir, umode_t mode)
21502150
{
2151-
inode->i_uid = fsuid_into_mnt(mnt_userns);
2151+
inode->i_uid = mapped_fsuid(mnt_userns);
21522152
if (dir && dir->i_mode & S_ISGID) {
21532153
inode->i_gid = dir->i_gid;
21542154

@@ -2160,7 +2160,7 @@ void inode_init_owner(struct user_namespace *mnt_userns, struct inode *inode,
21602160
!capable_wrt_inode_uidgid(mnt_userns, dir, CAP_FSETID))
21612161
mode &= ~S_ISGID;
21622162
} else
2163-
inode->i_gid = fsgid_into_mnt(mnt_userns);
2163+
inode->i_gid = mapped_fsgid(mnt_userns);
21642164
inode->i_mode = mode;
21652165
}
21662166
EXPORT_SYMBOL(inode_init_owner);

fs/namei.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2830,8 +2830,8 @@ static inline int may_create(struct user_namespace *mnt_userns,
28302830
if (IS_DEADDIR(dir))
28312831
return -ENOENT;
28322832
s_user_ns = dir->i_sb->s_user_ns;
2833-
if (!kuid_has_mapping(s_user_ns, fsuid_into_mnt(mnt_userns)) ||
2834-
!kgid_has_mapping(s_user_ns, fsgid_into_mnt(mnt_userns)))
2833+
if (!kuid_has_mapping(s_user_ns, mapped_fsuid(mnt_userns)) ||
2834+
!kgid_has_mapping(s_user_ns, mapped_fsgid(mnt_userns)))
28352835
return -EOVERFLOW;
28362836
return inode_permission(mnt_userns, dir, MAY_WRITE | MAY_EXEC);
28372837
}
@@ -3040,8 +3040,8 @@ static int may_o_create(struct user_namespace *mnt_userns,
30403040
return error;
30413041

30423042
s_user_ns = dir->dentry->d_sb->s_user_ns;
3043-
if (!kuid_has_mapping(s_user_ns, fsuid_into_mnt(mnt_userns)) ||
3044-
!kgid_has_mapping(s_user_ns, fsgid_into_mnt(mnt_userns)))
3043+
if (!kuid_has_mapping(s_user_ns, mapped_fsuid(mnt_userns)) ||
3044+
!kgid_has_mapping(s_user_ns, mapped_fsgid(mnt_userns)))
30453045
return -EOVERFLOW;
30463046

30473047
error = inode_permission(mnt_userns, dir->dentry->d_inode,

fs/xfs/xfs_inode.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ xfs_init_new_inode(
812812

813813
if (dir && !(dir->i_mode & S_ISGID) &&
814814
(mp->m_flags & XFS_MOUNT_GRPID)) {
815-
inode->i_uid = fsuid_into_mnt(mnt_userns);
815+
inode->i_uid = mapped_fsuid(mnt_userns);
816816
inode->i_gid = dir->i_gid;
817817
inode->i_mode = mode;
818818
} else {
@@ -1007,8 +1007,8 @@ xfs_create(
10071007
/*
10081008
* Make sure that we have allocated dquot(s) on disk.
10091009
*/
1010-
error = xfs_qm_vop_dqalloc(dp, fsuid_into_mnt(mnt_userns),
1011-
fsgid_into_mnt(mnt_userns), prid,
1010+
error = xfs_qm_vop_dqalloc(dp, mapped_fsuid(mnt_userns),
1011+
mapped_fsgid(mnt_userns), prid,
10121012
XFS_QMOPT_QUOTALL | XFS_QMOPT_INHERIT,
10131013
&udqp, &gdqp, &pdqp);
10141014
if (error)
@@ -1158,8 +1158,8 @@ xfs_create_tmpfile(
11581158
/*
11591159
* Make sure that we have allocated dquot(s) on disk.
11601160
*/
1161-
error = xfs_qm_vop_dqalloc(dp, fsuid_into_mnt(mnt_userns),
1162-
fsgid_into_mnt(mnt_userns), prid,
1161+
error = xfs_qm_vop_dqalloc(dp, mapped_fsuid(mnt_userns),
1162+
mapped_fsgid(mnt_userns), prid,
11631163
XFS_QMOPT_QUOTALL | XFS_QMOPT_INHERIT,
11641164
&udqp, &gdqp, &pdqp);
11651165
if (error)

fs/xfs/xfs_symlink.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ xfs_symlink(
182182
/*
183183
* Make sure that we have allocated dquot(s) on disk.
184184
*/
185-
error = xfs_qm_vop_dqalloc(dp, fsuid_into_mnt(mnt_userns),
186-
fsgid_into_mnt(mnt_userns), prid,
185+
error = xfs_qm_vop_dqalloc(dp, mapped_fsuid(mnt_userns),
186+
mapped_fsgid(mnt_userns), prid,
187187
XFS_QMOPT_QUOTALL | XFS_QMOPT_INHERIT,
188188
&udqp, &gdqp, &pdqp);
189189
if (error)

include/linux/fs.h

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,12 +1658,36 @@ static inline kgid_t kgid_from_mnt(struct user_namespace *mnt_userns,
16581658
return KGIDT_INIT(from_kgid(mnt_userns, kgid));
16591659
}
16601660

1661-
static inline kuid_t fsuid_into_mnt(struct user_namespace *mnt_userns)
1661+
/**
1662+
* mapped_fsuid - return caller's fsuid mapped up into a mnt_userns
1663+
* @mnt_userns: user namespace of the relevant mount
1664+
*
1665+
* Use this helper to initialize a new vfs or filesystem object based on
1666+
* the caller's fsuid. A common example is initializing the i_uid field of
1667+
* a newly allocated inode triggered by a creation event such as mkdir or
1668+
* O_CREAT. Other examples include the allocation of quotas for a specific
1669+
* user.
1670+
*
1671+
* Return: the caller's current fsuid mapped up according to @mnt_userns.
1672+
*/
1673+
static inline kuid_t mapped_fsuid(struct user_namespace *mnt_userns)
16621674
{
16631675
return kuid_from_mnt(mnt_userns, current_fsuid());
16641676
}
16651677

1666-
static inline kgid_t fsgid_into_mnt(struct user_namespace *mnt_userns)
1678+
/**
1679+
* mapped_fsgid - return caller's fsgid mapped up into a mnt_userns
1680+
* @mnt_userns: user namespace of the relevant mount
1681+
*
1682+
* Use this helper to initialize a new vfs or filesystem object based on
1683+
* the caller's fsgid. A common example is initializing the i_gid field of
1684+
* a newly allocated inode triggered by a creation event such as mkdir or
1685+
* O_CREAT. Other examples include the allocation of quotas for a specific
1686+
* user.
1687+
*
1688+
* Return: the caller's current fsgid mapped up according to @mnt_userns.
1689+
*/
1690+
static inline kgid_t mapped_fsgid(struct user_namespace *mnt_userns)
16671691
{
16681692
return kgid_from_mnt(mnt_userns, current_fsgid());
16691693
}

0 commit comments

Comments
 (0)