Merge tag 'idmapped-mounts-v5.12' of git://git.kernel.org/pub/scm/linux/kernel/git...
[sfrench/cifs-2.6.git] / fs / hostfs / hostfs_kern.c
index aea35459d3903159655ee869f144c16acff22fe8..29e407762626497e3e5b64349e554e1b0ec2df46 100644 (file)
@@ -34,6 +34,8 @@ static inline struct hostfs_inode_info *HOSTFS_I(struct inode *inode)
 
 #define FILE_HOSTFS_I(file) HOSTFS_I(file_inode(file))
 
+static struct kmem_cache *hostfs_inode_cache;
+
 /* Changed in hostfs_args before the kernel starts running */
 static char *root_ino = "";
 static int append = 0;
@@ -221,7 +223,7 @@ static struct inode *hostfs_alloc_inode(struct super_block *sb)
 {
        struct hostfs_inode_info *hi;
 
-       hi = kmalloc(sizeof(*hi), GFP_KERNEL_ACCOUNT);
+       hi = kmem_cache_alloc(hostfs_inode_cache, GFP_KERNEL_ACCOUNT);
        if (hi == NULL)
                return NULL;
        hi->fd = -1;
@@ -243,7 +245,7 @@ static void hostfs_evict_inode(struct inode *inode)
 
 static void hostfs_free_inode(struct inode *inode)
 {
-       kfree(HOSTFS_I(inode));
+       kmem_cache_free(hostfs_inode_cache, HOSTFS_I(inode));
 }
 
 static int hostfs_show_options(struct seq_file *seq, struct dentry *root)
@@ -555,8 +557,8 @@ static int read_name(struct inode *ino, char *name)
        return 0;
 }
 
-static int hostfs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
-                        bool excl)
+static int hostfs_create(struct user_namespace *mnt_userns, struct inode *dir,
+                        struct dentry *dentry, umode_t mode, bool excl)
 {
        struct inode *inode;
        char *name;
@@ -654,8 +656,8 @@ static int hostfs_unlink(struct inode *ino, struct dentry *dentry)
        return err;
 }
 
-static int hostfs_symlink(struct inode *ino, struct dentry *dentry,
-                         const char *to)
+static int hostfs_symlink(struct user_namespace *mnt_userns, struct inode *ino,
+                         struct dentry *dentry, const char *to)
 {
        char *file;
        int err;
@@ -667,7 +669,8 @@ static int hostfs_symlink(struct inode *ino, struct dentry *dentry,
        return err;
 }
 
-static int hostfs_mkdir(struct inode *ino, struct dentry *dentry, umode_t mode)
+static int hostfs_mkdir(struct user_namespace *mnt_userns, struct inode *ino,
+                       struct dentry *dentry, umode_t mode)
 {
        char *file;
        int err;
@@ -691,7 +694,8 @@ static int hostfs_rmdir(struct inode *ino, struct dentry *dentry)
        return err;
 }
 
-static int hostfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
+static int hostfs_mknod(struct user_namespace *mnt_userns, struct inode *dir,
+                       struct dentry *dentry, umode_t mode, dev_t dev)
 {
        struct inode *inode;
        char *name;
@@ -729,7 +733,8 @@ static int hostfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
        return err;
 }
 
-static int hostfs_rename2(struct inode *old_dir, struct dentry *old_dentry,
+static int hostfs_rename2(struct user_namespace *mnt_userns,
+                         struct inode *old_dir, struct dentry *old_dentry,
                          struct inode *new_dir, struct dentry *new_dentry,
                          unsigned int flags)
 {
@@ -757,7 +762,8 @@ static int hostfs_rename2(struct inode *old_dir, struct dentry *old_dentry,
        return err;
 }
 
-static int hostfs_permission(struct inode *ino, int desired)
+static int hostfs_permission(struct user_namespace *mnt_userns,
+                            struct inode *ino, int desired)
 {
        char *name;
        int r = 0, w = 0, x = 0, err;
@@ -779,11 +785,12 @@ static int hostfs_permission(struct inode *ino, int desired)
                err = access_file(name, r, w, x);
        __putname(name);
        if (!err)
-               err = generic_permission(ino, desired);
+               err = generic_permission(&init_user_ns, ino, desired);
        return err;
 }
 
-static int hostfs_setattr(struct dentry *dentry, struct iattr *attr)
+static int hostfs_setattr(struct user_namespace *mnt_userns,
+                         struct dentry *dentry, struct iattr *attr)
 {
        struct inode *inode = d_inode(dentry);
        struct hostfs_iattr attrs;
@@ -792,7 +799,7 @@ static int hostfs_setattr(struct dentry *dentry, struct iattr *attr)
 
        int fd = HOSTFS_I(inode)->fd;
 
-       err = setattr_prepare(dentry, attr);
+       err = setattr_prepare(&init_user_ns, dentry, attr);
        if (err)
                return err;
 
@@ -849,7 +856,7 @@ static int hostfs_setattr(struct dentry *dentry, struct iattr *attr)
            attr->ia_size != i_size_read(inode))
                truncate_setsize(inode, attr->ia_size);
 
-       setattr_copy(inode, attr);
+       setattr_copy(&init_user_ns, inode, attr);
        mark_inode_dirty(inode);
        return 0;
 }
@@ -986,12 +993,16 @@ MODULE_ALIAS_FS("hostfs");
 
 static int __init init_hostfs(void)
 {
+       hostfs_inode_cache = KMEM_CACHE(hostfs_inode_info, 0);
+       if (!hostfs_inode_cache)
+               return -ENOMEM;
        return register_filesystem(&hostfs_type);
 }
 
 static void __exit exit_hostfs(void)
 {
        unregister_filesystem(&hostfs_type);
+       kmem_cache_destroy(hostfs_inode_cache);
 }
 
 module_init(init_hostfs)