mirror of
https://github.com/armbian/linux-cix.git
synced 2026-01-06 12:30:45 -08:00
fs: port inode_init_owner() to mnt_idmap
Convert to struct mnt_idmap.
Last cycle we merged the necessary infrastructure in
256c8aed2b ("fs: introduce dedicated idmap type for mounts").
This is just the conversion to struct mnt_idmap.
Currently we still pass around the plain namespace that was attached to a
mount. This is in general pretty convenient but it makes it easy to
conflate namespaces that are relevant on the filesystem with namespaces
that are relevent on the mount level. Especially for non-vfs developers
without detailed knowledge in this area this can be a potential source for
bugs.
Once the conversion to struct mnt_idmap is done all helpers down to the
really low-level helpers will take a struct mnt_idmap argument instead of
two namespace arguments. This way it becomes impossible to conflate the two
eliminating the possibility of any bugs. All of the vfs and all filesystems
only operate on struct mnt_idmap.
Acked-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Christian Brauner (Microsoft) <brauner@kernel.org>
This commit is contained in:
committed by
Christian Brauner (Microsoft)
parent
700b794052
commit
f2d40141d5
@@ -237,7 +237,7 @@ spufs_mkdir(struct inode *dir, struct dentry *dentry, unsigned int flags,
|
||||
if (!inode)
|
||||
return -ENOSPC;
|
||||
|
||||
inode_init_owner(&init_user_ns, inode, dir, mode | S_IFDIR);
|
||||
inode_init_owner(&nop_mnt_idmap, inode, dir, mode | S_IFDIR);
|
||||
ctx = alloc_spu_context(SPUFS_I(dir)->i_gang); /* XXX gang */
|
||||
SPUFS_I(inode)->i_ctx = ctx;
|
||||
if (!ctx) {
|
||||
@@ -468,7 +468,7 @@ spufs_mkgang(struct inode *dir, struct dentry *dentry, umode_t mode)
|
||||
goto out;
|
||||
|
||||
ret = 0;
|
||||
inode_init_owner(&init_user_ns, inode, dir, mode | S_IFDIR);
|
||||
inode_init_owner(&nop_mnt_idmap, inode, dir, mode | S_IFDIR);
|
||||
gang = alloc_spu_gang();
|
||||
SPUFS_I(inode)->i_ctx = NULL;
|
||||
SPUFS_I(inode)->i_gang = gang;
|
||||
|
||||
@@ -260,7 +260,7 @@ int v9fs_init_inode(struct v9fs_session_info *v9ses,
|
||||
{
|
||||
int err = 0;
|
||||
|
||||
inode_init_owner(&init_user_ns, inode, NULL, mode);
|
||||
inode_init_owner(&nop_mnt_idmap, inode, NULL, mode);
|
||||
inode->i_blocks = 0;
|
||||
inode->i_rdev = rdev;
|
||||
inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
|
||||
|
||||
@@ -96,7 +96,7 @@ static int bfs_create(struct mnt_idmap *idmap, struct inode *dir,
|
||||
}
|
||||
set_bit(ino, info->si_imap);
|
||||
info->si_freei--;
|
||||
inode_init_owner(&init_user_ns, inode, dir, mode);
|
||||
inode_init_owner(&nop_mnt_idmap, inode, dir, mode);
|
||||
inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
|
||||
inode->i_blocks = 0;
|
||||
inode->i_op = &bfs_file_inops;
|
||||
|
||||
@@ -469,7 +469,7 @@ int btrfs_new_inode_prepare(struct btrfs_new_inode_args *args,
|
||||
int btrfs_create_new_inode(struct btrfs_trans_handle *trans,
|
||||
struct btrfs_new_inode_args *args);
|
||||
void btrfs_new_inode_args_destroy(struct btrfs_new_inode_args *args);
|
||||
struct inode *btrfs_new_subvol_inode(struct user_namespace *mnt_userns,
|
||||
struct inode *btrfs_new_subvol_inode(struct mnt_idmap *idmap,
|
||||
struct inode *dir);
|
||||
void btrfs_set_delalloc_extent(struct btrfs_inode *inode, struct extent_state *state,
|
||||
u32 bits);
|
||||
|
||||
@@ -6727,13 +6727,12 @@ out_inode:
|
||||
static int btrfs_mknod(struct mnt_idmap *idmap, struct inode *dir,
|
||||
struct dentry *dentry, umode_t mode, dev_t rdev)
|
||||
{
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
struct inode *inode;
|
||||
|
||||
inode = new_inode(dir->i_sb);
|
||||
if (!inode)
|
||||
return -ENOMEM;
|
||||
inode_init_owner(mnt_userns, inode, dir, mode);
|
||||
inode_init_owner(idmap, inode, dir, mode);
|
||||
inode->i_op = &btrfs_special_inode_operations;
|
||||
init_special_inode(inode, inode->i_mode, rdev);
|
||||
return btrfs_create_common(dir, dentry, inode);
|
||||
@@ -6742,13 +6741,12 @@ static int btrfs_mknod(struct mnt_idmap *idmap, struct inode *dir,
|
||||
static int btrfs_create(struct mnt_idmap *idmap, struct inode *dir,
|
||||
struct dentry *dentry, umode_t mode, bool excl)
|
||||
{
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
struct inode *inode;
|
||||
|
||||
inode = new_inode(dir->i_sb);
|
||||
if (!inode)
|
||||
return -ENOMEM;
|
||||
inode_init_owner(mnt_userns, inode, dir, mode);
|
||||
inode_init_owner(idmap, inode, dir, mode);
|
||||
inode->i_fop = &btrfs_file_operations;
|
||||
inode->i_op = &btrfs_file_inode_operations;
|
||||
inode->i_mapping->a_ops = &btrfs_aops;
|
||||
@@ -6842,13 +6840,12 @@ fail:
|
||||
static int btrfs_mkdir(struct mnt_idmap *idmap, struct inode *dir,
|
||||
struct dentry *dentry, umode_t mode)
|
||||
{
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
struct inode *inode;
|
||||
|
||||
inode = new_inode(dir->i_sb);
|
||||
if (!inode)
|
||||
return -ENOMEM;
|
||||
inode_init_owner(mnt_userns, inode, dir, S_IFDIR | mode);
|
||||
inode_init_owner(idmap, inode, dir, S_IFDIR | mode);
|
||||
inode->i_op = &btrfs_dir_inode_operations;
|
||||
inode->i_fop = &btrfs_dir_file_operations;
|
||||
return btrfs_create_common(dir, dentry, inode);
|
||||
@@ -8805,7 +8802,7 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
struct inode *btrfs_new_subvol_inode(struct user_namespace *mnt_userns,
|
||||
struct inode *btrfs_new_subvol_inode(struct mnt_idmap *idmap,
|
||||
struct inode *dir)
|
||||
{
|
||||
struct inode *inode;
|
||||
@@ -8816,7 +8813,7 @@ struct inode *btrfs_new_subvol_inode(struct user_namespace *mnt_userns,
|
||||
* Subvolumes don't inherit the sgid bit or the parent's gid if
|
||||
* the parent's sgid bit is set. This is probably a bug.
|
||||
*/
|
||||
inode_init_owner(mnt_userns, inode, NULL,
|
||||
inode_init_owner(idmap, inode, NULL,
|
||||
S_IFDIR | (~current_umask() & S_IRWXUGO));
|
||||
inode->i_op = &btrfs_dir_inode_operations;
|
||||
inode->i_fop = &btrfs_dir_file_operations;
|
||||
@@ -9292,14 +9289,14 @@ out_notrans:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static struct inode *new_whiteout_inode(struct user_namespace *mnt_userns,
|
||||
static struct inode *new_whiteout_inode(struct mnt_idmap *idmap,
|
||||
struct inode *dir)
|
||||
{
|
||||
struct inode *inode;
|
||||
|
||||
inode = new_inode(dir->i_sb);
|
||||
if (inode) {
|
||||
inode_init_owner(mnt_userns, inode, dir,
|
||||
inode_init_owner(idmap, inode, dir,
|
||||
S_IFCHR | WHITEOUT_MODE);
|
||||
inode->i_op = &btrfs_special_inode_operations;
|
||||
init_special_inode(inode, inode->i_mode, WHITEOUT_DEV);
|
||||
@@ -9307,7 +9304,7 @@ static struct inode *new_whiteout_inode(struct user_namespace *mnt_userns,
|
||||
return inode;
|
||||
}
|
||||
|
||||
static int btrfs_rename(struct user_namespace *mnt_userns,
|
||||
static int btrfs_rename(struct mnt_idmap *idmap,
|
||||
struct inode *old_dir, struct dentry *old_dentry,
|
||||
struct inode *new_dir, struct dentry *new_dentry,
|
||||
unsigned int flags)
|
||||
@@ -9379,7 +9376,7 @@ static int btrfs_rename(struct user_namespace *mnt_userns,
|
||||
filemap_flush(old_inode->i_mapping);
|
||||
|
||||
if (flags & RENAME_WHITEOUT) {
|
||||
whiteout_args.inode = new_whiteout_inode(mnt_userns, old_dir);
|
||||
whiteout_args.inode = new_whiteout_inode(idmap, old_dir);
|
||||
if (!whiteout_args.inode)
|
||||
return -ENOMEM;
|
||||
ret = btrfs_new_inode_prepare(&whiteout_args, &trans_num_items);
|
||||
@@ -9550,7 +9547,6 @@ static int btrfs_rename2(struct mnt_idmap *idmap, struct inode *old_dir,
|
||||
struct dentry *old_dentry, struct inode *new_dir,
|
||||
struct dentry *new_dentry, unsigned int flags)
|
||||
{
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
int ret;
|
||||
|
||||
if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE | RENAME_WHITEOUT))
|
||||
@@ -9560,7 +9556,7 @@ static int btrfs_rename2(struct mnt_idmap *idmap, struct inode *old_dir,
|
||||
ret = btrfs_rename_exchange(old_dir, old_dentry, new_dir,
|
||||
new_dentry);
|
||||
else
|
||||
ret = btrfs_rename(mnt_userns, old_dir, old_dentry, new_dir,
|
||||
ret = btrfs_rename(idmap, old_dir, old_dentry, new_dir,
|
||||
new_dentry, flags);
|
||||
|
||||
btrfs_btree_balance_dirty(BTRFS_I(new_dir)->root->fs_info);
|
||||
@@ -9763,7 +9759,6 @@ out:
|
||||
static int btrfs_symlink(struct mnt_idmap *idmap, struct inode *dir,
|
||||
struct dentry *dentry, const char *symname)
|
||||
{
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
struct btrfs_fs_info *fs_info = btrfs_sb(dir->i_sb);
|
||||
struct btrfs_trans_handle *trans;
|
||||
struct btrfs_root *root = BTRFS_I(dir)->root;
|
||||
@@ -9789,7 +9784,7 @@ static int btrfs_symlink(struct mnt_idmap *idmap, struct inode *dir,
|
||||
inode = new_inode(dir->i_sb);
|
||||
if (!inode)
|
||||
return -ENOMEM;
|
||||
inode_init_owner(mnt_userns, inode, dir, S_IFLNK | S_IRWXUGO);
|
||||
inode_init_owner(idmap, inode, dir, S_IFLNK | S_IRWXUGO);
|
||||
inode->i_op = &btrfs_symlink_inode_operations;
|
||||
inode_nohighmem(inode);
|
||||
inode->i_mapping->a_ops = &btrfs_aops;
|
||||
@@ -10097,7 +10092,6 @@ static int btrfs_permission(struct mnt_idmap *idmap,
|
||||
static int btrfs_tmpfile(struct mnt_idmap *idmap, struct inode *dir,
|
||||
struct file *file, umode_t mode)
|
||||
{
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
struct btrfs_fs_info *fs_info = btrfs_sb(dir->i_sb);
|
||||
struct btrfs_trans_handle *trans;
|
||||
struct btrfs_root *root = BTRFS_I(dir)->root;
|
||||
@@ -10113,7 +10107,7 @@ static int btrfs_tmpfile(struct mnt_idmap *idmap, struct inode *dir,
|
||||
inode = new_inode(dir->i_sb);
|
||||
if (!inode)
|
||||
return -ENOMEM;
|
||||
inode_init_owner(mnt_userns, inode, dir, mode);
|
||||
inode_init_owner(idmap, inode, dir, mode);
|
||||
inode->i_fop = &btrfs_file_operations;
|
||||
inode->i_op = &btrfs_file_inode_operations;
|
||||
inode->i_mapping->a_ops = &btrfs_aops;
|
||||
|
||||
@@ -578,7 +578,7 @@ static unsigned int create_subvol_num_items(struct btrfs_qgroup_inherit *inherit
|
||||
return num_items;
|
||||
}
|
||||
|
||||
static noinline int create_subvol(struct user_namespace *mnt_userns,
|
||||
static noinline int create_subvol(struct mnt_idmap *idmap,
|
||||
struct inode *dir, struct dentry *dentry,
|
||||
struct btrfs_qgroup_inherit *inherit)
|
||||
{
|
||||
@@ -623,7 +623,7 @@ static noinline int create_subvol(struct user_namespace *mnt_userns,
|
||||
if (ret < 0)
|
||||
goto out_root_item;
|
||||
|
||||
new_inode_args.inode = btrfs_new_subvol_inode(mnt_userns, dir);
|
||||
new_inode_args.inode = btrfs_new_subvol_inode(idmap, dir);
|
||||
if (!new_inode_args.inode) {
|
||||
ret = -ENOMEM;
|
||||
goto out_anon_dev;
|
||||
@@ -962,7 +962,6 @@ static noinline int btrfs_mksubvol(const struct path *parent,
|
||||
struct btrfs_fs_info *fs_info = btrfs_sb(dir->i_sb);
|
||||
struct dentry *dentry;
|
||||
struct fscrypt_str name_str = FSTR_INIT((char *)name, namelen);
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
int error;
|
||||
|
||||
error = down_write_killable_nested(&dir->i_rwsem, I_MUTEX_PARENT);
|
||||
@@ -995,7 +994,7 @@ static noinline int btrfs_mksubvol(const struct path *parent,
|
||||
if (snap_src)
|
||||
error = create_snapshot(snap_src, dir, dentry, readonly, inherit);
|
||||
else
|
||||
error = create_subvol(mnt_userns, dir, dentry, inherit);
|
||||
error = create_subvol(idmap, dir, dentry, inherit);
|
||||
|
||||
if (!error)
|
||||
fsnotify_mkdir(dir, dentry);
|
||||
|
||||
@@ -64,7 +64,7 @@ struct inode *btrfs_new_test_inode(void)
|
||||
BTRFS_I(inode)->location.type = BTRFS_INODE_ITEM_KEY;
|
||||
BTRFS_I(inode)->location.objectid = BTRFS_FIRST_FREE_OBJECTID;
|
||||
BTRFS_I(inode)->location.offset = 0;
|
||||
inode_init_owner(&init_user_ns, inode, NULL, S_IFREG);
|
||||
inode_init_owner(&nop_mnt_idmap, inode, NULL, S_IFREG);
|
||||
|
||||
return inode;
|
||||
}
|
||||
|
||||
@@ -545,7 +545,7 @@ got:
|
||||
inode->i_uid = current_fsuid();
|
||||
inode->i_gid = dir->i_gid;
|
||||
} else
|
||||
inode_init_owner(&init_user_ns, inode, dir, mode);
|
||||
inode_init_owner(&nop_mnt_idmap, inode, dir, mode);
|
||||
|
||||
inode->i_ino = ino;
|
||||
inode->i_blocks = 0;
|
||||
|
||||
@@ -2845,7 +2845,7 @@ extern int ext4fs_dirhash(const struct inode *dir, const char *name, int len,
|
||||
|
||||
/* ialloc.c */
|
||||
extern int ext4_mark_inode_used(struct super_block *sb, int ino);
|
||||
extern struct inode *__ext4_new_inode(struct user_namespace *, handle_t *,
|
||||
extern struct inode *__ext4_new_inode(struct mnt_idmap *, handle_t *,
|
||||
struct inode *, umode_t,
|
||||
const struct qstr *qstr, __u32 goal,
|
||||
uid_t *owner, __u32 i_flags,
|
||||
@@ -2853,11 +2853,11 @@ extern struct inode *__ext4_new_inode(struct user_namespace *, handle_t *,
|
||||
int nblocks);
|
||||
|
||||
#define ext4_new_inode(handle, dir, mode, qstr, goal, owner, i_flags) \
|
||||
__ext4_new_inode(&init_user_ns, (handle), (dir), (mode), (qstr), \
|
||||
__ext4_new_inode(&nop_mnt_idmap, (handle), (dir), (mode), (qstr), \
|
||||
(goal), (owner), i_flags, 0, 0, 0)
|
||||
#define ext4_new_inode_start_handle(mnt_userns, dir, mode, qstr, goal, owner, \
|
||||
#define ext4_new_inode_start_handle(idmap, dir, mode, qstr, goal, owner, \
|
||||
type, nblocks) \
|
||||
__ext4_new_inode((mnt_userns), NULL, (dir), (mode), (qstr), (goal), (owner), \
|
||||
__ext4_new_inode((idmap), NULL, (dir), (mode), (qstr), (goal), (owner), \
|
||||
0, (type), __LINE__, (nblocks))
|
||||
|
||||
|
||||
|
||||
@@ -921,7 +921,7 @@ static int ext4_xattr_credits_for_new_inode(struct inode *dir, mode_t mode,
|
||||
* For other inodes, search forward from the parent directory's block
|
||||
* group to find a free inode.
|
||||
*/
|
||||
struct inode *__ext4_new_inode(struct user_namespace *mnt_userns,
|
||||
struct inode *__ext4_new_inode(struct mnt_idmap *idmap,
|
||||
handle_t *handle, struct inode *dir,
|
||||
umode_t mode, const struct qstr *qstr,
|
||||
__u32 goal, uid_t *owner, __u32 i_flags,
|
||||
@@ -943,6 +943,7 @@ struct inode *__ext4_new_inode(struct user_namespace *mnt_userns,
|
||||
ext4_group_t flex_group;
|
||||
struct ext4_group_info *grp = NULL;
|
||||
bool encrypt = false;
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
|
||||
/* Cannot create files in a deleted directory */
|
||||
if (!dir || !dir->i_nlink)
|
||||
@@ -975,7 +976,7 @@ struct inode *__ext4_new_inode(struct user_namespace *mnt_userns,
|
||||
inode_fsuid_set(inode, mnt_userns);
|
||||
inode->i_gid = dir->i_gid;
|
||||
} else
|
||||
inode_init_owner(mnt_userns, inode, dir, mode);
|
||||
inode_init_owner(idmap, inode, dir, mode);
|
||||
|
||||
if (ext4_has_feature_project(sb) &&
|
||||
ext4_test_inode_flag(dir, EXT4_INODE_PROJINHERIT))
|
||||
|
||||
@@ -2795,7 +2795,6 @@ static int ext4_add_nondir(handle_t *handle,
|
||||
static int ext4_create(struct mnt_idmap *idmap, struct inode *dir,
|
||||
struct dentry *dentry, umode_t mode, bool excl)
|
||||
{
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
handle_t *handle;
|
||||
struct inode *inode;
|
||||
int err, credits, retries = 0;
|
||||
@@ -2807,7 +2806,7 @@ static int ext4_create(struct mnt_idmap *idmap, struct inode *dir,
|
||||
credits = (EXT4_DATA_TRANS_BLOCKS(dir->i_sb) +
|
||||
EXT4_INDEX_EXTRA_TRANS_BLOCKS + 3);
|
||||
retry:
|
||||
inode = ext4_new_inode_start_handle(mnt_userns, dir, mode, &dentry->d_name,
|
||||
inode = ext4_new_inode_start_handle(idmap, dir, mode, &dentry->d_name,
|
||||
0, NULL, EXT4_HT_DIR, credits);
|
||||
handle = ext4_journal_current_handle();
|
||||
err = PTR_ERR(inode);
|
||||
@@ -2831,7 +2830,6 @@ retry:
|
||||
static int ext4_mknod(struct mnt_idmap *idmap, struct inode *dir,
|
||||
struct dentry *dentry, umode_t mode, dev_t rdev)
|
||||
{
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
handle_t *handle;
|
||||
struct inode *inode;
|
||||
int err, credits, retries = 0;
|
||||
@@ -2843,7 +2841,7 @@ static int ext4_mknod(struct mnt_idmap *idmap, struct inode *dir,
|
||||
credits = (EXT4_DATA_TRANS_BLOCKS(dir->i_sb) +
|
||||
EXT4_INDEX_EXTRA_TRANS_BLOCKS + 3);
|
||||
retry:
|
||||
inode = ext4_new_inode_start_handle(mnt_userns, dir, mode, &dentry->d_name,
|
||||
inode = ext4_new_inode_start_handle(idmap, dir, mode, &dentry->d_name,
|
||||
0, NULL, EXT4_HT_DIR, credits);
|
||||
handle = ext4_journal_current_handle();
|
||||
err = PTR_ERR(inode);
|
||||
@@ -2866,7 +2864,6 @@ retry:
|
||||
static int ext4_tmpfile(struct mnt_idmap *idmap, struct inode *dir,
|
||||
struct file *file, umode_t mode)
|
||||
{
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
handle_t *handle;
|
||||
struct inode *inode;
|
||||
int err, retries = 0;
|
||||
@@ -2876,7 +2873,7 @@ static int ext4_tmpfile(struct mnt_idmap *idmap, struct inode *dir,
|
||||
return err;
|
||||
|
||||
retry:
|
||||
inode = ext4_new_inode_start_handle(mnt_userns, dir, mode,
|
||||
inode = ext4_new_inode_start_handle(idmap, dir, mode,
|
||||
NULL, 0, NULL,
|
||||
EXT4_HT_DIR,
|
||||
EXT4_MAXQUOTAS_INIT_BLOCKS(dir->i_sb) +
|
||||
@@ -2978,7 +2975,6 @@ out:
|
||||
static int ext4_mkdir(struct mnt_idmap *idmap, struct inode *dir,
|
||||
struct dentry *dentry, umode_t mode)
|
||||
{
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
handle_t *handle;
|
||||
struct inode *inode;
|
||||
int err, err2 = 0, credits, retries = 0;
|
||||
@@ -2993,7 +2989,7 @@ static int ext4_mkdir(struct mnt_idmap *idmap, struct inode *dir,
|
||||
credits = (EXT4_DATA_TRANS_BLOCKS(dir->i_sb) +
|
||||
EXT4_INDEX_EXTRA_TRANS_BLOCKS + 3);
|
||||
retry:
|
||||
inode = ext4_new_inode_start_handle(mnt_userns, dir, S_IFDIR | mode,
|
||||
inode = ext4_new_inode_start_handle(idmap, dir, S_IFDIR | mode,
|
||||
&dentry->d_name,
|
||||
0, NULL, EXT4_HT_DIR, credits);
|
||||
handle = ext4_journal_current_handle();
|
||||
@@ -3346,7 +3342,6 @@ out:
|
||||
static int ext4_symlink(struct mnt_idmap *idmap, struct inode *dir,
|
||||
struct dentry *dentry, const char *symname)
|
||||
{
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
handle_t *handle;
|
||||
struct inode *inode;
|
||||
int err, len = strlen(symname);
|
||||
@@ -3375,7 +3370,7 @@ static int ext4_symlink(struct mnt_idmap *idmap, struct inode *dir,
|
||||
credits = EXT4_DATA_TRANS_BLOCKS(dir->i_sb) +
|
||||
EXT4_INDEX_EXTRA_TRANS_BLOCKS + 3;
|
||||
retry:
|
||||
inode = ext4_new_inode_start_handle(mnt_userns, dir, S_IFLNK|S_IRWXUGO,
|
||||
inode = ext4_new_inode_start_handle(idmap, dir, S_IFLNK|S_IRWXUGO,
|
||||
&dentry->d_name, 0, NULL,
|
||||
EXT4_HT_DIR, credits);
|
||||
handle = ext4_journal_current_handle();
|
||||
@@ -3725,7 +3720,7 @@ static void ext4_update_dir_count(handle_t *handle, struct ext4_renament *ent)
|
||||
}
|
||||
}
|
||||
|
||||
static struct inode *ext4_whiteout_for_rename(struct user_namespace *mnt_userns,
|
||||
static struct inode *ext4_whiteout_for_rename(struct mnt_idmap *idmap,
|
||||
struct ext4_renament *ent,
|
||||
int credits, handle_t **h)
|
||||
{
|
||||
@@ -3740,7 +3735,7 @@ static struct inode *ext4_whiteout_for_rename(struct user_namespace *mnt_userns,
|
||||
credits += (EXT4_MAXQUOTAS_TRANS_BLOCKS(ent->dir->i_sb) +
|
||||
EXT4_XATTR_TRANS_BLOCKS + 4);
|
||||
retry:
|
||||
wh = ext4_new_inode_start_handle(mnt_userns, ent->dir,
|
||||
wh = ext4_new_inode_start_handle(idmap, ent->dir,
|
||||
S_IFCHR | WHITEOUT_MODE,
|
||||
&ent->dentry->d_name, 0, NULL,
|
||||
EXT4_HT_DIR, credits);
|
||||
@@ -3768,7 +3763,7 @@ retry:
|
||||
* while new_{dentry,inode) refers to the destination dentry/inode
|
||||
* This comes from rename(const char *oldpath, const char *newpath)
|
||||
*/
|
||||
static int ext4_rename(struct user_namespace *mnt_userns, struct inode *old_dir,
|
||||
static int ext4_rename(struct mnt_idmap *idmap, struct inode *old_dir,
|
||||
struct dentry *old_dentry, struct inode *new_dir,
|
||||
struct dentry *new_dentry, unsigned int flags)
|
||||
{
|
||||
@@ -3856,7 +3851,7 @@ static int ext4_rename(struct user_namespace *mnt_userns, struct inode *old_dir,
|
||||
goto release_bh;
|
||||
}
|
||||
} else {
|
||||
whiteout = ext4_whiteout_for_rename(mnt_userns, &old, credits, &handle);
|
||||
whiteout = ext4_whiteout_for_rename(idmap, &old, credits, &handle);
|
||||
if (IS_ERR(whiteout)) {
|
||||
retval = PTR_ERR(whiteout);
|
||||
goto release_bh;
|
||||
@@ -4168,7 +4163,6 @@ static int ext4_rename2(struct mnt_idmap *idmap,
|
||||
struct inode *new_dir, struct dentry *new_dentry,
|
||||
unsigned int flags)
|
||||
{
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
int err;
|
||||
|
||||
if (unlikely(ext4_forced_shutdown(EXT4_SB(old_dir->i_sb))))
|
||||
@@ -4187,7 +4181,7 @@ static int ext4_rename2(struct mnt_idmap *idmap,
|
||||
new_dir, new_dentry);
|
||||
}
|
||||
|
||||
return ext4_rename(mnt_userns, old_dir, old_dentry, new_dir, new_dentry, flags);
|
||||
return ext4_rename(idmap, old_dir, old_dentry, new_dir, new_dentry, flags);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -3505,7 +3505,7 @@ void f2fs_handle_failed_inode(struct inode *inode);
|
||||
int f2fs_update_extension_list(struct f2fs_sb_info *sbi, const char *name,
|
||||
bool hot, bool set);
|
||||
struct dentry *f2fs_get_parent(struct dentry *child);
|
||||
int f2fs_get_tmpfile(struct user_namespace *mnt_userns, struct inode *dir,
|
||||
int f2fs_get_tmpfile(struct mnt_idmap *idmap, struct inode *dir,
|
||||
struct inode **new_inode);
|
||||
|
||||
/*
|
||||
|
||||
@@ -2040,7 +2040,8 @@ static int f2fs_ioc_getversion(struct file *filp, unsigned long arg)
|
||||
static int f2fs_ioc_start_atomic_write(struct file *filp, bool truncate)
|
||||
{
|
||||
struct inode *inode = file_inode(filp);
|
||||
struct user_namespace *mnt_userns = file_mnt_user_ns(filp);
|
||||
struct mnt_idmap *idmap = file_mnt_idmap(filp);
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
struct f2fs_inode_info *fi = F2FS_I(inode);
|
||||
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
|
||||
struct inode *pinode;
|
||||
@@ -2097,7 +2098,7 @@ static int f2fs_ioc_start_atomic_write(struct file *filp, bool truncate)
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = f2fs_get_tmpfile(mnt_userns, pinode, &fi->cow_inode);
|
||||
ret = f2fs_get_tmpfile(idmap, pinode, &fi->cow_inode);
|
||||
iput(pinode);
|
||||
if (ret) {
|
||||
f2fs_up_write(&fi->i_gc_rwsem[WRITE]);
|
||||
|
||||
@@ -202,7 +202,7 @@ static void set_file_temperature(struct f2fs_sb_info *sbi, struct inode *inode,
|
||||
file_set_hot(inode);
|
||||
}
|
||||
|
||||
static struct inode *f2fs_new_inode(struct user_namespace *mnt_userns,
|
||||
static struct inode *f2fs_new_inode(struct mnt_idmap *idmap,
|
||||
struct inode *dir, umode_t mode,
|
||||
const char *name)
|
||||
{
|
||||
@@ -225,7 +225,7 @@ static struct inode *f2fs_new_inode(struct user_namespace *mnt_userns,
|
||||
|
||||
nid_free = true;
|
||||
|
||||
inode_init_owner(mnt_userns, inode, dir, mode);
|
||||
inode_init_owner(idmap, inode, dir, mode);
|
||||
|
||||
inode->i_ino = ino;
|
||||
inode->i_blocks = 0;
|
||||
@@ -336,7 +336,6 @@ fail_drop:
|
||||
static int f2fs_create(struct mnt_idmap *idmap, struct inode *dir,
|
||||
struct dentry *dentry, umode_t mode, bool excl)
|
||||
{
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
|
||||
struct inode *inode;
|
||||
nid_t ino = 0;
|
||||
@@ -351,7 +350,7 @@ static int f2fs_create(struct mnt_idmap *idmap, struct inode *dir,
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
inode = f2fs_new_inode(mnt_userns, dir, mode, dentry->d_name.name);
|
||||
inode = f2fs_new_inode(idmap, dir, mode, dentry->d_name.name);
|
||||
if (IS_ERR(inode))
|
||||
return PTR_ERR(inode);
|
||||
|
||||
@@ -663,7 +662,6 @@ static const char *f2fs_get_link(struct dentry *dentry,
|
||||
static int f2fs_symlink(struct mnt_idmap *idmap, struct inode *dir,
|
||||
struct dentry *dentry, const char *symname)
|
||||
{
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
|
||||
struct inode *inode;
|
||||
size_t len = strlen(symname);
|
||||
@@ -684,7 +682,7 @@ static int f2fs_symlink(struct mnt_idmap *idmap, struct inode *dir,
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
inode = f2fs_new_inode(mnt_userns, dir, S_IFLNK | S_IRWXUGO, NULL);
|
||||
inode = f2fs_new_inode(idmap, dir, S_IFLNK | S_IRWXUGO, NULL);
|
||||
if (IS_ERR(inode))
|
||||
return PTR_ERR(inode);
|
||||
|
||||
@@ -744,7 +742,6 @@ out_free_encrypted_link:
|
||||
static int f2fs_mkdir(struct mnt_idmap *idmap, struct inode *dir,
|
||||
struct dentry *dentry, umode_t mode)
|
||||
{
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
|
||||
struct inode *inode;
|
||||
int err;
|
||||
@@ -756,7 +753,7 @@ static int f2fs_mkdir(struct mnt_idmap *idmap, struct inode *dir,
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
inode = f2fs_new_inode(mnt_userns, dir, S_IFDIR | mode, NULL);
|
||||
inode = f2fs_new_inode(idmap, dir, S_IFDIR | mode, NULL);
|
||||
if (IS_ERR(inode))
|
||||
return PTR_ERR(inode);
|
||||
|
||||
@@ -800,7 +797,6 @@ static int f2fs_rmdir(struct inode *dir, struct dentry *dentry)
|
||||
static int f2fs_mknod(struct mnt_idmap *idmap, struct inode *dir,
|
||||
struct dentry *dentry, umode_t mode, dev_t rdev)
|
||||
{
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
|
||||
struct inode *inode;
|
||||
int err = 0;
|
||||
@@ -814,7 +810,7 @@ static int f2fs_mknod(struct mnt_idmap *idmap, struct inode *dir,
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
inode = f2fs_new_inode(mnt_userns, dir, mode, NULL);
|
||||
inode = f2fs_new_inode(idmap, dir, mode, NULL);
|
||||
if (IS_ERR(inode))
|
||||
return PTR_ERR(inode);
|
||||
|
||||
@@ -841,7 +837,7 @@ out:
|
||||
return err;
|
||||
}
|
||||
|
||||
static int __f2fs_tmpfile(struct user_namespace *mnt_userns, struct inode *dir,
|
||||
static int __f2fs_tmpfile(struct mnt_idmap *idmap, struct inode *dir,
|
||||
struct file *file, umode_t mode, bool is_whiteout,
|
||||
struct inode **new_inode)
|
||||
{
|
||||
@@ -853,7 +849,7 @@ static int __f2fs_tmpfile(struct user_namespace *mnt_userns, struct inode *dir,
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
inode = f2fs_new_inode(mnt_userns, dir, mode, NULL);
|
||||
inode = f2fs_new_inode(idmap, dir, mode, NULL);
|
||||
if (IS_ERR(inode))
|
||||
return PTR_ERR(inode);
|
||||
|
||||
@@ -914,7 +910,6 @@ out:
|
||||
static int f2fs_tmpfile(struct mnt_idmap *idmap, struct inode *dir,
|
||||
struct file *file, umode_t mode)
|
||||
{
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
|
||||
int err;
|
||||
|
||||
@@ -923,28 +918,28 @@ static int f2fs_tmpfile(struct mnt_idmap *idmap, struct inode *dir,
|
||||
if (!f2fs_is_checkpoint_ready(sbi))
|
||||
return -ENOSPC;
|
||||
|
||||
err = __f2fs_tmpfile(mnt_userns, dir, file, mode, false, NULL);
|
||||
err = __f2fs_tmpfile(idmap, dir, file, mode, false, NULL);
|
||||
|
||||
return finish_open_simple(file, err);
|
||||
}
|
||||
|
||||
static int f2fs_create_whiteout(struct user_namespace *mnt_userns,
|
||||
static int f2fs_create_whiteout(struct mnt_idmap *idmap,
|
||||
struct inode *dir, struct inode **whiteout)
|
||||
{
|
||||
if (unlikely(f2fs_cp_error(F2FS_I_SB(dir))))
|
||||
return -EIO;
|
||||
|
||||
return __f2fs_tmpfile(mnt_userns, dir, NULL,
|
||||
return __f2fs_tmpfile(idmap, dir, NULL,
|
||||
S_IFCHR | WHITEOUT_MODE, true, whiteout);
|
||||
}
|
||||
|
||||
int f2fs_get_tmpfile(struct user_namespace *mnt_userns, struct inode *dir,
|
||||
int f2fs_get_tmpfile(struct mnt_idmap *idmap, struct inode *dir,
|
||||
struct inode **new_inode)
|
||||
{
|
||||
return __f2fs_tmpfile(mnt_userns, dir, NULL, S_IFREG, false, new_inode);
|
||||
return __f2fs_tmpfile(idmap, dir, NULL, S_IFREG, false, new_inode);
|
||||
}
|
||||
|
||||
static int f2fs_rename(struct user_namespace *mnt_userns, struct inode *old_dir,
|
||||
static int f2fs_rename(struct mnt_idmap *idmap, struct inode *old_dir,
|
||||
struct dentry *old_dentry, struct inode *new_dir,
|
||||
struct dentry *new_dentry, unsigned int flags)
|
||||
{
|
||||
@@ -984,7 +979,7 @@ static int f2fs_rename(struct user_namespace *mnt_userns, struct inode *old_dir,
|
||||
}
|
||||
|
||||
if (flags & RENAME_WHITEOUT) {
|
||||
err = f2fs_create_whiteout(mnt_userns, old_dir, &whiteout);
|
||||
err = f2fs_create_whiteout(idmap, old_dir, &whiteout);
|
||||
if (err)
|
||||
return err;
|
||||
}
|
||||
@@ -1305,7 +1300,6 @@ static int f2fs_rename2(struct mnt_idmap *idmap,
|
||||
struct inode *new_dir, struct dentry *new_dentry,
|
||||
unsigned int flags)
|
||||
{
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
int err;
|
||||
|
||||
if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE | RENAME_WHITEOUT))
|
||||
@@ -1324,7 +1318,7 @@ static int f2fs_rename2(struct mnt_idmap *idmap,
|
||||
* VFS has already handled the new dentry existence case,
|
||||
* here, we just deal with "RENAME_NOREPLACE" as regular rename.
|
||||
*/
|
||||
return f2fs_rename(mnt_userns, old_dir, old_dentry,
|
||||
return f2fs_rename(idmap, old_dir, old_dentry,
|
||||
new_dir, new_dentry, flags);
|
||||
}
|
||||
|
||||
|
||||
@@ -390,7 +390,7 @@ struct inode *hfsplus_new_inode(struct super_block *sb, struct inode *dir,
|
||||
return NULL;
|
||||
|
||||
inode->i_ino = sbi->next_cnid++;
|
||||
inode_init_owner(&init_user_ns, inode, dir, mode);
|
||||
inode_init_owner(&nop_mnt_idmap, inode, dir, mode);
|
||||
set_nlink(inode, 1);
|
||||
inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
|
||||
|
||||
|
||||
@@ -980,7 +980,7 @@ static struct inode *hugetlbfs_get_inode(struct super_block *sb,
|
||||
struct hugetlbfs_inode_info *info = HUGETLBFS_I(inode);
|
||||
|
||||
inode->i_ino = get_next_ino();
|
||||
inode_init_owner(&init_user_ns, inode, dir, mode);
|
||||
inode_init_owner(&nop_mnt_idmap, inode, dir, mode);
|
||||
lockdep_set_class(&inode->i_mapping->i_mmap_rwsem,
|
||||
&hugetlbfs_i_mmap_rwsem_key);
|
||||
inode->i_mapping->a_ops = &hugetlbfs_aops;
|
||||
|
||||
14
fs/inode.c
14
fs/inode.c
@@ -2279,20 +2279,22 @@ EXPORT_SYMBOL(init_special_inode);
|
||||
|
||||
/**
|
||||
* inode_init_owner - Init uid,gid,mode for new inode according to posix standards
|
||||
* @mnt_userns: User namespace of the mount the inode was created from
|
||||
* @idmap: idmap of the mount the inode was created from
|
||||
* @inode: New inode
|
||||
* @dir: Directory inode
|
||||
* @mode: mode of the new inode
|
||||
*
|
||||
* If the inode has been created through an idmapped mount the user namespace of
|
||||
* the vfsmount must be passed through @mnt_userns. This function will then take
|
||||
* care to map the inode according to @mnt_userns before checking permissions
|
||||
* If the inode has been created through an idmapped mount the idmap of
|
||||
* the vfsmount must be passed through @idmap. This function will then take
|
||||
* care to map the inode according to @idmap before checking permissions
|
||||
* and initializing i_uid and i_gid. On non-idmapped mounts or if permission
|
||||
* checking is to be performed on the raw inode simply passs init_user_ns.
|
||||
* checking is to be performed on the raw inode simply pass @nop_mnt_idmap.
|
||||
*/
|
||||
void inode_init_owner(struct user_namespace *mnt_userns, struct inode *inode,
|
||||
void inode_init_owner(struct mnt_idmap *idmap, struct inode *inode,
|
||||
const struct inode *dir, umode_t mode)
|
||||
{
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
|
||||
inode_fsuid_set(inode, mnt_userns);
|
||||
if (dir && dir->i_mode & S_ISGID) {
|
||||
inode->i_gid = dir->i_gid;
|
||||
|
||||
@@ -64,7 +64,7 @@ struct inode *ialloc(struct inode *parent, umode_t mode)
|
||||
goto fail_put;
|
||||
}
|
||||
|
||||
inode_init_owner(&init_user_ns, inode, parent, mode);
|
||||
inode_init_owner(&nop_mnt_idmap, inode, parent, mode);
|
||||
/*
|
||||
* New inodes need to save sane values on disk when
|
||||
* uid & gid mount options are used
|
||||
|
||||
@@ -252,7 +252,7 @@ struct inode *minix_new_inode(const struct inode *dir, umode_t mode, int *error)
|
||||
iput(inode);
|
||||
return NULL;
|
||||
}
|
||||
inode_init_owner(&init_user_ns, inode, dir, mode);
|
||||
inode_init_owner(&nop_mnt_idmap, inode, dir, mode);
|
||||
inode->i_ino = j;
|
||||
inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
|
||||
inode->i_blocks = 0;
|
||||
|
||||
@@ -364,7 +364,7 @@ struct inode *nilfs_new_inode(struct inode *dir, umode_t mode)
|
||||
ii->i_bh = bh;
|
||||
|
||||
atomic64_inc(&root->inodes_count);
|
||||
inode_init_owner(&init_user_ns, inode, dir, mode);
|
||||
inode_init_owner(&nop_mnt_idmap, inode, dir, mode);
|
||||
inode->i_ino = ino;
|
||||
inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user