aboutsummaryrefslogtreecommitdiffstats
path: root/mm/shmem.c
diff options
context:
space:
mode:
Diffstat (limited to 'mm/shmem.c')
-rw-r--r--mm/shmem.c52
1 files changed, 31 insertions, 21 deletions
diff --git a/mm/shmem.c b/mm/shmem.c
index 39de1d6a077a..ed2befb4952e 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -1294,7 +1294,7 @@ unlock:
1294 1294
1295static int shmem_fault(struct vm_area_struct *vma, struct vm_fault *vmf) 1295static int shmem_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
1296{ 1296{
1297 struct inode *inode = vma->vm_file->f_path.dentry->d_inode; 1297 struct inode *inode = file_inode(vma->vm_file);
1298 int error; 1298 int error;
1299 int ret = VM_FAULT_LOCKED; 1299 int ret = VM_FAULT_LOCKED;
1300 1300
@@ -1312,14 +1312,14 @@ static int shmem_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
1312#ifdef CONFIG_NUMA 1312#ifdef CONFIG_NUMA
1313static int shmem_set_policy(struct vm_area_struct *vma, struct mempolicy *mpol) 1313static int shmem_set_policy(struct vm_area_struct *vma, struct mempolicy *mpol)
1314{ 1314{
1315 struct inode *inode = vma->vm_file->f_path.dentry->d_inode; 1315 struct inode *inode = file_inode(vma->vm_file);
1316 return mpol_set_shared_policy(&SHMEM_I(inode)->policy, vma, mpol); 1316 return mpol_set_shared_policy(&SHMEM_I(inode)->policy, vma, mpol);
1317} 1317}
1318 1318
1319static struct mempolicy *shmem_get_policy(struct vm_area_struct *vma, 1319static struct mempolicy *shmem_get_policy(struct vm_area_struct *vma,
1320 unsigned long addr) 1320 unsigned long addr)
1321{ 1321{
1322 struct inode *inode = vma->vm_file->f_path.dentry->d_inode; 1322 struct inode *inode = file_inode(vma->vm_file);
1323 pgoff_t index; 1323 pgoff_t index;
1324 1324
1325 index = ((addr - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff; 1325 index = ((addr - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff;
@@ -1329,7 +1329,7 @@ static struct mempolicy *shmem_get_policy(struct vm_area_struct *vma,
1329 1329
1330int shmem_lock(struct file *file, int lock, struct user_struct *user) 1330int shmem_lock(struct file *file, int lock, struct user_struct *user)
1331{ 1331{
1332 struct inode *inode = file->f_path.dentry->d_inode; 1332 struct inode *inode = file_inode(file);
1333 struct shmem_inode_info *info = SHMEM_I(inode); 1333 struct shmem_inode_info *info = SHMEM_I(inode);
1334 int retval = -ENOMEM; 1334 int retval = -ENOMEM;
1335 1335
@@ -1464,7 +1464,7 @@ shmem_write_end(struct file *file, struct address_space *mapping,
1464 1464
1465static void do_shmem_file_read(struct file *filp, loff_t *ppos, read_descriptor_t *desc, read_actor_t actor) 1465static void do_shmem_file_read(struct file *filp, loff_t *ppos, read_descriptor_t *desc, read_actor_t actor)
1466{ 1466{
1467 struct inode *inode = filp->f_path.dentry->d_inode; 1467 struct inode *inode = file_inode(filp);
1468 struct address_space *mapping = inode->i_mapping; 1468 struct address_space *mapping = inode->i_mapping;
1469 pgoff_t index; 1469 pgoff_t index;
1470 unsigned long offset; 1470 unsigned long offset;
@@ -1807,7 +1807,7 @@ static loff_t shmem_file_llseek(struct file *file, loff_t offset, int whence)
1807static long shmem_fallocate(struct file *file, int mode, loff_t offset, 1807static long shmem_fallocate(struct file *file, int mode, loff_t offset,
1808 loff_t len) 1808 loff_t len)
1809{ 1809{
1810 struct inode *inode = file->f_path.dentry->d_inode; 1810 struct inode *inode = file_inode(file);
1811 struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb); 1811 struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb);
1812 struct shmem_falloc shmem_falloc; 1812 struct shmem_falloc shmem_falloc;
1813 pgoff_t start, index, end; 1813 pgoff_t start, index, end;
@@ -2350,7 +2350,7 @@ static int shmem_encode_fh(struct inode *inode, __u32 *fh, int *len,
2350{ 2350{
2351 if (*len < 3) { 2351 if (*len < 3) {
2352 *len = 3; 2352 *len = 3;
2353 return 255; 2353 return FILEID_INVALID;
2354 } 2354 }
2355 2355
2356 if (inode_unhashed(inode)) { 2356 if (inode_unhashed(inode)) {
@@ -2879,6 +2879,16 @@ EXPORT_SYMBOL_GPL(shmem_truncate_range);
2879 2879
2880/* common code */ 2880/* common code */
2881 2881
2882static char *shmem_dname(struct dentry *dentry, char *buffer, int buflen)
2883{
2884 return dynamic_dname(dentry, buffer, buflen, "/%s (deleted)",
2885 dentry->d_name.name);
2886}
2887
2888static struct dentry_operations anon_ops = {
2889 .d_dname = shmem_dname
2890};
2891
2882/** 2892/**
2883 * shmem_file_setup - get an unlinked file living in tmpfs 2893 * shmem_file_setup - get an unlinked file living in tmpfs
2884 * @name: name for dentry (to be seen in /proc/<pid>/maps 2894 * @name: name for dentry (to be seen in /proc/<pid>/maps
@@ -2887,15 +2897,14 @@ EXPORT_SYMBOL_GPL(shmem_truncate_range);
2887 */ 2897 */
2888struct file *shmem_file_setup(const char *name, loff_t size, unsigned long flags) 2898struct file *shmem_file_setup(const char *name, loff_t size, unsigned long flags)
2889{ 2899{
2890 int error; 2900 struct file *res;
2891 struct file *file;
2892 struct inode *inode; 2901 struct inode *inode;
2893 struct path path; 2902 struct path path;
2894 struct dentry *root; 2903 struct super_block *sb;
2895 struct qstr this; 2904 struct qstr this;
2896 2905
2897 if (IS_ERR(shm_mnt)) 2906 if (IS_ERR(shm_mnt))
2898 return (void *)shm_mnt; 2907 return ERR_CAST(shm_mnt);
2899 2908
2900 if (size < 0 || size > MAX_LFS_FILESIZE) 2909 if (size < 0 || size > MAX_LFS_FILESIZE)
2901 return ERR_PTR(-EINVAL); 2910 return ERR_PTR(-EINVAL);
@@ -2903,18 +2912,19 @@ struct file *shmem_file_setup(const char *name, loff_t size, unsigned long flags
2903 if (shmem_acct_size(flags, size)) 2912 if (shmem_acct_size(flags, size))
2904 return ERR_PTR(-ENOMEM); 2913 return ERR_PTR(-ENOMEM);
2905 2914
2906 error = -ENOMEM; 2915 res = ERR_PTR(-ENOMEM);
2907 this.name = name; 2916 this.name = name;
2908 this.len = strlen(name); 2917 this.len = strlen(name);
2909 this.hash = 0; /* will go */ 2918 this.hash = 0; /* will go */
2910 root = shm_mnt->mnt_root; 2919 sb = shm_mnt->mnt_sb;
2911 path.dentry = d_alloc(root, &this); 2920 path.dentry = d_alloc_pseudo(sb, &this);
2912 if (!path.dentry) 2921 if (!path.dentry)
2913 goto put_memory; 2922 goto put_memory;
2923 d_set_d_op(path.dentry, &anon_ops);
2914 path.mnt = mntget(shm_mnt); 2924 path.mnt = mntget(shm_mnt);
2915 2925
2916 error = -ENOSPC; 2926 res = ERR_PTR(-ENOSPC);
2917 inode = shmem_get_inode(root->d_sb, NULL, S_IFREG | S_IRWXUGO, 0, flags); 2927 inode = shmem_get_inode(sb, NULL, S_IFREG | S_IRWXUGO, 0, flags);
2918 if (!inode) 2928 if (!inode)
2919 goto put_dentry; 2929 goto put_dentry;
2920 2930
@@ -2923,23 +2933,23 @@ struct file *shmem_file_setup(const char *name, loff_t size, unsigned long flags
2923 clear_nlink(inode); /* It is unlinked */ 2933 clear_nlink(inode); /* It is unlinked */
2924#ifndef CONFIG_MMU 2934#ifndef CONFIG_MMU
2925 error = ramfs_nommu_expand_for_mapping(inode, size); 2935 error = ramfs_nommu_expand_for_mapping(inode, size);
2936 res = ERR_PTR(error);
2926 if (error) 2937 if (error)
2927 goto put_dentry; 2938 goto put_dentry;
2928#endif 2939#endif
2929 2940
2930 error = -ENFILE; 2941 res = alloc_file(&path, FMODE_WRITE | FMODE_READ,
2931 file = alloc_file(&path, FMODE_WRITE | FMODE_READ,
2932 &shmem_file_operations); 2942 &shmem_file_operations);
2933 if (!file) 2943 if (IS_ERR(res))
2934 goto put_dentry; 2944 goto put_dentry;
2935 2945
2936 return file; 2946 return res;
2937 2947
2938put_dentry: 2948put_dentry:
2939 path_put(&path); 2949 path_put(&path);
2940put_memory: 2950put_memory:
2941 shmem_unacct_size(flags, size); 2951 shmem_unacct_size(flags, size);
2942 return ERR_PTR(error); 2952 return res;
2943} 2953}
2944EXPORT_SYMBOL_GPL(shmem_file_setup); 2954EXPORT_SYMBOL_GPL(shmem_file_setup);
2945 2955