diff options
author | Christian Brauner <christian.brauner@ubuntu.com> | 2021-03-20 13:26:24 +0100 |
---|---|---|
committer | Christian Brauner <christian.brauner@ubuntu.com> | 2021-03-23 11:15:26 +0100 |
commit | db998553cf11dd697485ac6142adbb35d21fff10 (patch) | |
tree | a5805d22264c998db8207ac4f5e58069841b832b /include/linux | |
parent | 8e5389132ab429604c1a2459b52f0c849a71cc61 (diff) |
fs: introduce two inode i_{u,g}id initialization helpers
Give filesystem two little helpers that do the right thing when
initializing the i_uid and i_gid fields on idmapped and non-idmapped
mounts. Filesystems shouldn't have to be concerned with too many
details.
Link: https://lore.kernel.org/r/20210320122623.599086-5-christian.brauner@ubuntu.com
Inspired-by: Vivek Goyal <vgoyal@redhat.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-fsdevel@vger.kernel.org
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
Diffstat (limited to 'include/linux')
-rw-r--r-- | include/linux/fs.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/include/linux/fs.h b/include/linux/fs.h index e9e7e799425e..3eaf5f27a0e4 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1693,6 +1693,34 @@ static inline kgid_t mapped_fsgid(struct user_namespace *mnt_userns) } /** + * inode_fsuid_set - initialize inode's i_uid field with callers fsuid + * @inode: inode to initialize + * @mnt_userns: user namespace of the mount the inode was found from + * + * Initialize the i_uid field of @inode. If the inode was found/created via + * an idmapped mount map the caller's fsuid according to @mnt_users. + */ +static inline void inode_fsuid_set(struct inode *inode, + struct user_namespace *mnt_userns) +{ + inode->i_uid = mapped_fsuid(mnt_userns); +} + +/** + * inode_fsgid_set - initialize inode's i_gid field with callers fsgid + * @inode: inode to initialize + * @mnt_userns: user namespace of the mount the inode was found from + * + * Initialize the i_gid field of @inode. If the inode was found/created via + * an idmapped mount map the caller's fsgid according to @mnt_users. + */ +static inline void inode_fsgid_set(struct inode *inode, + struct user_namespace *mnt_userns) +{ + inode->i_gid = mapped_fsgid(mnt_userns); +} + +/** * fsuidgid_has_mapping() - check whether caller's fsuid/fsgid is mapped * @sb: the superblock we want a mapping in * @mnt_userns: user namespace of the relevant mount |