mm/shmem: introduce shmem_file_setup_with_mnt
We are planning to use our own tmpfs mnt in i915 in place of the shm_mnt, such that we can control the mount options, in particular huge=, which we require to support huge-gtt-pages. So rather than roll our own version of __shmem_file_setup, it would be preferred if we could just give shmem our mnt, and let it do the rest. Signed-off-by: Matthew Auld <matthew.auld@intel.com> Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com> Cc: Chris Wilson <chris@chris-wilson.co.uk> Cc: Dave Hansen <dave.hansen@intel.com> Cc: Kirill A. Shutemov <kirill@shutemov.name> Cc: Hugh Dickins <hughd@google.com> Cc: linux-mm@kvack.org Acked-by: Andrew Morton <akpm@linux-foundation.org> Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20171006145041.21673-2-matthew.auld@intel.com Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk> Link: https://patchwork.freedesktop.org/patch/msgid/20171006221833.32439-1-chris@chris-wilson.co.uk
This commit is contained in:
parent
279f5a00c9
commit
703321b60b
|
@ -53,6 +53,8 @@ extern struct file *shmem_file_setup(const char *name,
|
||||||
loff_t size, unsigned long flags);
|
loff_t size, unsigned long flags);
|
||||||
extern struct file *shmem_kernel_file_setup(const char *name, loff_t size,
|
extern struct file *shmem_kernel_file_setup(const char *name, loff_t size,
|
||||||
unsigned long flags);
|
unsigned long flags);
|
||||||
|
extern struct file *shmem_file_setup_with_mnt(struct vfsmount *mnt,
|
||||||
|
const char *name, loff_t size, unsigned long flags);
|
||||||
extern int shmem_zero_setup(struct vm_area_struct *);
|
extern int shmem_zero_setup(struct vm_area_struct *);
|
||||||
extern unsigned long shmem_get_unmapped_area(struct file *, unsigned long addr,
|
extern unsigned long shmem_get_unmapped_area(struct file *, unsigned long addr,
|
||||||
unsigned long len, unsigned long pgoff, unsigned long flags);
|
unsigned long len, unsigned long pgoff, unsigned long flags);
|
||||||
|
|
30
mm/shmem.c
30
mm/shmem.c
|
@ -4183,7 +4183,7 @@ static const struct dentry_operations anon_ops = {
|
||||||
.d_dname = simple_dname
|
.d_dname = simple_dname
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct file *__shmem_file_setup(const char *name, loff_t size,
|
static struct file *__shmem_file_setup(struct vfsmount *mnt, const char *name, loff_t size,
|
||||||
unsigned long flags, unsigned int i_flags)
|
unsigned long flags, unsigned int i_flags)
|
||||||
{
|
{
|
||||||
struct file *res;
|
struct file *res;
|
||||||
|
@ -4192,8 +4192,8 @@ static struct file *__shmem_file_setup(const char *name, loff_t size,
|
||||||
struct super_block *sb;
|
struct super_block *sb;
|
||||||
struct qstr this;
|
struct qstr this;
|
||||||
|
|
||||||
if (IS_ERR(shm_mnt))
|
if (IS_ERR(mnt))
|
||||||
return ERR_CAST(shm_mnt);
|
return ERR_CAST(mnt);
|
||||||
|
|
||||||
if (size < 0 || size > MAX_LFS_FILESIZE)
|
if (size < 0 || size > MAX_LFS_FILESIZE)
|
||||||
return ERR_PTR(-EINVAL);
|
return ERR_PTR(-EINVAL);
|
||||||
|
@ -4205,8 +4205,8 @@ static struct file *__shmem_file_setup(const char *name, loff_t size,
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.len = strlen(name);
|
this.len = strlen(name);
|
||||||
this.hash = 0; /* will go */
|
this.hash = 0; /* will go */
|
||||||
sb = shm_mnt->mnt_sb;
|
sb = mnt->mnt_sb;
|
||||||
path.mnt = mntget(shm_mnt);
|
path.mnt = mntget(mnt);
|
||||||
path.dentry = d_alloc_pseudo(sb, &this);
|
path.dentry = d_alloc_pseudo(sb, &this);
|
||||||
if (!path.dentry)
|
if (!path.dentry)
|
||||||
goto put_memory;
|
goto put_memory;
|
||||||
|
@ -4251,7 +4251,7 @@ put_path:
|
||||||
*/
|
*/
|
||||||
struct file *shmem_kernel_file_setup(const char *name, loff_t size, unsigned long flags)
|
struct file *shmem_kernel_file_setup(const char *name, loff_t size, unsigned long flags)
|
||||||
{
|
{
|
||||||
return __shmem_file_setup(name, size, flags, S_PRIVATE);
|
return __shmem_file_setup(shm_mnt, name, size, flags, S_PRIVATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4262,10 +4262,24 @@ struct file *shmem_kernel_file_setup(const char *name, loff_t size, unsigned lon
|
||||||
*/
|
*/
|
||||||
struct file *shmem_file_setup(const char *name, loff_t size, unsigned long flags)
|
struct file *shmem_file_setup(const char *name, loff_t size, unsigned long flags)
|
||||||
{
|
{
|
||||||
return __shmem_file_setup(name, size, flags, 0);
|
return __shmem_file_setup(shm_mnt, name, size, flags, 0);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(shmem_file_setup);
|
EXPORT_SYMBOL_GPL(shmem_file_setup);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* shmem_file_setup_with_mnt - get an unlinked file living in tmpfs
|
||||||
|
* @mnt: the tmpfs mount where the file will be created
|
||||||
|
* @name: name for dentry (to be seen in /proc/<pid>/maps
|
||||||
|
* @size: size to be set for the file
|
||||||
|
* @flags: VM_NORESERVE suppresses pre-accounting of the entire object size
|
||||||
|
*/
|
||||||
|
struct file *shmem_file_setup_with_mnt(struct vfsmount *mnt, const char *name,
|
||||||
|
loff_t size, unsigned long flags)
|
||||||
|
{
|
||||||
|
return __shmem_file_setup(mnt, name, size, flags, 0);
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL_GPL(shmem_file_setup_with_mnt);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* shmem_zero_setup - setup a shared anonymous mapping
|
* shmem_zero_setup - setup a shared anonymous mapping
|
||||||
* @vma: the vma to be mmapped is prepared by do_mmap_pgoff
|
* @vma: the vma to be mmapped is prepared by do_mmap_pgoff
|
||||||
|
@ -4281,7 +4295,7 @@ int shmem_zero_setup(struct vm_area_struct *vma)
|
||||||
* accessible to the user through its mapping, use S_PRIVATE flag to
|
* accessible to the user through its mapping, use S_PRIVATE flag to
|
||||||
* bypass file security, in the same way as shmem_kernel_file_setup().
|
* bypass file security, in the same way as shmem_kernel_file_setup().
|
||||||
*/
|
*/
|
||||||
file = __shmem_file_setup("dev/zero", size, vma->vm_flags, S_PRIVATE);
|
file = shmem_kernel_file_setup("dev/zero", size, vma->vm_flags);
|
||||||
if (IS_ERR(file))
|
if (IS_ERR(file))
|
||||||
return PTR_ERR(file);
|
return PTR_ERR(file);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue