diff options
Diffstat (limited to 'mm/shmem.c')
-rw-r--r-- | mm/shmem.c | 105 |
1 files changed, 64 insertions, 41 deletions
diff --git a/mm/shmem.c b/mm/shmem.c index 5dd56f6efdbd..1c44af71fcf5 100644 --- a/mm/shmem.c +++ b/mm/shmem.c | |||
@@ -335,19 +335,19 @@ static unsigned shmem_find_get_pages_and_swap(struct address_space *mapping, | |||
335 | pgoff_t start, unsigned int nr_pages, | 335 | pgoff_t start, unsigned int nr_pages, |
336 | struct page **pages, pgoff_t *indices) | 336 | struct page **pages, pgoff_t *indices) |
337 | { | 337 | { |
338 | unsigned int i; | 338 | void **slot; |
339 | unsigned int ret; | 339 | unsigned int ret = 0; |
340 | unsigned int nr_found; | 340 | struct radix_tree_iter iter; |
341 | |||
342 | if (!nr_pages) | ||
343 | return 0; | ||
341 | 344 | ||
342 | rcu_read_lock(); | 345 | rcu_read_lock(); |
343 | restart: | 346 | restart: |
344 | nr_found = radix_tree_gang_lookup_slot(&mapping->page_tree, | 347 | radix_tree_for_each_slot(slot, &mapping->page_tree, &iter, start) { |
345 | (void ***)pages, indices, start, nr_pages); | ||
346 | ret = 0; | ||
347 | for (i = 0; i < nr_found; i++) { | ||
348 | struct page *page; | 348 | struct page *page; |
349 | repeat: | 349 | repeat: |
350 | page = radix_tree_deref_slot((void **)pages[i]); | 350 | page = radix_tree_deref_slot(slot); |
351 | if (unlikely(!page)) | 351 | if (unlikely(!page)) |
352 | continue; | 352 | continue; |
353 | if (radix_tree_exception(page)) { | 353 | if (radix_tree_exception(page)) { |
@@ -364,17 +364,16 @@ repeat: | |||
364 | goto repeat; | 364 | goto repeat; |
365 | 365 | ||
366 | /* Has the page moved? */ | 366 | /* Has the page moved? */ |
367 | if (unlikely(page != *((void **)pages[i]))) { | 367 | if (unlikely(page != *slot)) { |
368 | page_cache_release(page); | 368 | page_cache_release(page); |
369 | goto repeat; | 369 | goto repeat; |
370 | } | 370 | } |
371 | export: | 371 | export: |
372 | indices[ret] = indices[i]; | 372 | indices[ret] = iter.index; |
373 | pages[ret] = page; | 373 | pages[ret] = page; |
374 | ret++; | 374 | if (++ret == nr_pages) |
375 | break; | ||
375 | } | 376 | } |
376 | if (unlikely(!ret && nr_found)) | ||
377 | goto restart; | ||
378 | rcu_read_unlock(); | 377 | rcu_read_unlock(); |
379 | return ret; | 378 | return ret; |
380 | } | 379 | } |
@@ -1295,7 +1294,7 @@ unlock: | |||
1295 | 1294 | ||
1296 | static int shmem_fault(struct vm_area_struct *vma, struct vm_fault *vmf) | 1295 | static int shmem_fault(struct vm_area_struct *vma, struct vm_fault *vmf) |
1297 | { | 1296 | { |
1298 | struct inode *inode = vma->vm_file->f_path.dentry->d_inode; | 1297 | struct inode *inode = file_inode(vma->vm_file); |
1299 | int error; | 1298 | int error; |
1300 | int ret = VM_FAULT_LOCKED; | 1299 | int ret = VM_FAULT_LOCKED; |
1301 | 1300 | ||
@@ -1313,14 +1312,14 @@ static int shmem_fault(struct vm_area_struct *vma, struct vm_fault *vmf) | |||
1313 | #ifdef CONFIG_NUMA | 1312 | #ifdef CONFIG_NUMA |
1314 | static int shmem_set_policy(struct vm_area_struct *vma, struct mempolicy *mpol) | 1313 | static int shmem_set_policy(struct vm_area_struct *vma, struct mempolicy *mpol) |
1315 | { | 1314 | { |
1316 | struct inode *inode = vma->vm_file->f_path.dentry->d_inode; | 1315 | struct inode *inode = file_inode(vma->vm_file); |
1317 | return mpol_set_shared_policy(&SHMEM_I(inode)->policy, vma, mpol); | 1316 | return mpol_set_shared_policy(&SHMEM_I(inode)->policy, vma, mpol); |
1318 | } | 1317 | } |
1319 | 1318 | ||
1320 | static struct mempolicy *shmem_get_policy(struct vm_area_struct *vma, | 1319 | static struct mempolicy *shmem_get_policy(struct vm_area_struct *vma, |
1321 | unsigned long addr) | 1320 | unsigned long addr) |
1322 | { | 1321 | { |
1323 | struct inode *inode = vma->vm_file->f_path.dentry->d_inode; | 1322 | struct inode *inode = file_inode(vma->vm_file); |
1324 | pgoff_t index; | 1323 | pgoff_t index; |
1325 | 1324 | ||
1326 | index = ((addr - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff; | 1325 | index = ((addr - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff; |
@@ -1330,7 +1329,7 @@ static struct mempolicy *shmem_get_policy(struct vm_area_struct *vma, | |||
1330 | 1329 | ||
1331 | int shmem_lock(struct file *file, int lock, struct user_struct *user) | 1330 | int shmem_lock(struct file *file, int lock, struct user_struct *user) |
1332 | { | 1331 | { |
1333 | struct inode *inode = file->f_path.dentry->d_inode; | 1332 | struct inode *inode = file_inode(file); |
1334 | struct shmem_inode_info *info = SHMEM_I(inode); | 1333 | struct shmem_inode_info *info = SHMEM_I(inode); |
1335 | int retval = -ENOMEM; | 1334 | int retval = -ENOMEM; |
1336 | 1335 | ||
@@ -1465,7 +1464,7 @@ shmem_write_end(struct file *file, struct address_space *mapping, | |||
1465 | 1464 | ||
1466 | static void do_shmem_file_read(struct file *filp, loff_t *ppos, read_descriptor_t *desc, read_actor_t actor) | 1465 | static void do_shmem_file_read(struct file *filp, loff_t *ppos, read_descriptor_t *desc, read_actor_t actor) |
1467 | { | 1466 | { |
1468 | struct inode *inode = filp->f_path.dentry->d_inode; | 1467 | struct inode *inode = file_inode(filp); |
1469 | struct address_space *mapping = inode->i_mapping; | 1468 | struct address_space *mapping = inode->i_mapping; |
1470 | pgoff_t index; | 1469 | pgoff_t index; |
1471 | unsigned long offset; | 1470 | unsigned long offset; |
@@ -1808,7 +1807,7 @@ static loff_t shmem_file_llseek(struct file *file, loff_t offset, int whence) | |||
1808 | static long shmem_fallocate(struct file *file, int mode, loff_t offset, | 1807 | static long shmem_fallocate(struct file *file, int mode, loff_t offset, |
1809 | loff_t len) | 1808 | loff_t len) |
1810 | { | 1809 | { |
1811 | struct inode *inode = file->f_path.dentry->d_inode; | 1810 | struct inode *inode = file_inode(file); |
1812 | struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb); | 1811 | struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb); |
1813 | struct shmem_falloc shmem_falloc; | 1812 | struct shmem_falloc shmem_falloc; |
1814 | pgoff_t start, index, end; | 1813 | pgoff_t start, index, end; |
@@ -2351,7 +2350,7 @@ static int shmem_encode_fh(struct inode *inode, __u32 *fh, int *len, | |||
2351 | { | 2350 | { |
2352 | if (*len < 3) { | 2351 | if (*len < 3) { |
2353 | *len = 3; | 2352 | *len = 3; |
2354 | return 255; | 2353 | return FILEID_INVALID; |
2355 | } | 2354 | } |
2356 | 2355 | ||
2357 | if (inode_unhashed(inode)) { | 2356 | if (inode_unhashed(inode)) { |
@@ -2386,6 +2385,7 @@ static int shmem_parse_options(char *options, struct shmem_sb_info *sbinfo, | |||
2386 | bool remount) | 2385 | bool remount) |
2387 | { | 2386 | { |
2388 | char *this_char, *value, *rest; | 2387 | char *this_char, *value, *rest; |
2388 | struct mempolicy *mpol = NULL; | ||
2389 | uid_t uid; | 2389 | uid_t uid; |
2390 | gid_t gid; | 2390 | gid_t gid; |
2391 | 2391 | ||
@@ -2414,7 +2414,7 @@ static int shmem_parse_options(char *options, struct shmem_sb_info *sbinfo, | |||
2414 | printk(KERN_ERR | 2414 | printk(KERN_ERR |
2415 | "tmpfs: No value for mount option '%s'\n", | 2415 | "tmpfs: No value for mount option '%s'\n", |
2416 | this_char); | 2416 | this_char); |
2417 | return 1; | 2417 | goto error; |
2418 | } | 2418 | } |
2419 | 2419 | ||
2420 | if (!strcmp(this_char,"size")) { | 2420 | if (!strcmp(this_char,"size")) { |
@@ -2463,19 +2463,24 @@ static int shmem_parse_options(char *options, struct shmem_sb_info *sbinfo, | |||
2463 | if (!gid_valid(sbinfo->gid)) | 2463 | if (!gid_valid(sbinfo->gid)) |
2464 | goto bad_val; | 2464 | goto bad_val; |
2465 | } else if (!strcmp(this_char,"mpol")) { | 2465 | } else if (!strcmp(this_char,"mpol")) { |
2466 | if (mpol_parse_str(value, &sbinfo->mpol)) | 2466 | mpol_put(mpol); |
2467 | mpol = NULL; | ||
2468 | if (mpol_parse_str(value, &mpol)) | ||
2467 | goto bad_val; | 2469 | goto bad_val; |
2468 | } else { | 2470 | } else { |
2469 | printk(KERN_ERR "tmpfs: Bad mount option %s\n", | 2471 | printk(KERN_ERR "tmpfs: Bad mount option %s\n", |
2470 | this_char); | 2472 | this_char); |
2471 | return 1; | 2473 | goto error; |
2472 | } | 2474 | } |
2473 | } | 2475 | } |
2476 | sbinfo->mpol = mpol; | ||
2474 | return 0; | 2477 | return 0; |
2475 | 2478 | ||
2476 | bad_val: | 2479 | bad_val: |
2477 | printk(KERN_ERR "tmpfs: Bad value '%s' for mount option '%s'\n", | 2480 | printk(KERN_ERR "tmpfs: Bad value '%s' for mount option '%s'\n", |
2478 | value, this_char); | 2481 | value, this_char); |
2482 | error: | ||
2483 | mpol_put(mpol); | ||
2479 | return 1; | 2484 | return 1; |
2480 | 2485 | ||
2481 | } | 2486 | } |
@@ -2487,6 +2492,7 @@ static int shmem_remount_fs(struct super_block *sb, int *flags, char *data) | |||
2487 | unsigned long inodes; | 2492 | unsigned long inodes; |
2488 | int error = -EINVAL; | 2493 | int error = -EINVAL; |
2489 | 2494 | ||
2495 | config.mpol = NULL; | ||
2490 | if (shmem_parse_options(data, &config, true)) | 2496 | if (shmem_parse_options(data, &config, true)) |
2491 | return error; | 2497 | return error; |
2492 | 2498 | ||
@@ -2511,8 +2517,13 @@ static int shmem_remount_fs(struct super_block *sb, int *flags, char *data) | |||
2511 | sbinfo->max_inodes = config.max_inodes; | 2517 | sbinfo->max_inodes = config.max_inodes; |
2512 | sbinfo->free_inodes = config.max_inodes - inodes; | 2518 | sbinfo->free_inodes = config.max_inodes - inodes; |
2513 | 2519 | ||
2514 | mpol_put(sbinfo->mpol); | 2520 | /* |
2515 | sbinfo->mpol = config.mpol; /* transfers initial ref */ | 2521 | * Preserve previous mempolicy unless mpol remount option was specified. |
2522 | */ | ||
2523 | if (config.mpol) { | ||
2524 | mpol_put(sbinfo->mpol); | ||
2525 | sbinfo->mpol = config.mpol; /* transfers initial ref */ | ||
2526 | } | ||
2516 | out: | 2527 | out: |
2517 | spin_unlock(&sbinfo->stat_lock); | 2528 | spin_unlock(&sbinfo->stat_lock); |
2518 | return error; | 2529 | return error; |
@@ -2545,6 +2556,7 @@ static void shmem_put_super(struct super_block *sb) | |||
2545 | struct shmem_sb_info *sbinfo = SHMEM_SB(sb); | 2556 | struct shmem_sb_info *sbinfo = SHMEM_SB(sb); |
2546 | 2557 | ||
2547 | percpu_counter_destroy(&sbinfo->used_blocks); | 2558 | percpu_counter_destroy(&sbinfo->used_blocks); |
2559 | mpol_put(sbinfo->mpol); | ||
2548 | kfree(sbinfo); | 2560 | kfree(sbinfo); |
2549 | sb->s_fs_info = NULL; | 2561 | sb->s_fs_info = NULL; |
2550 | } | 2562 | } |
@@ -2766,6 +2778,7 @@ static struct file_system_type shmem_fs_type = { | |||
2766 | .name = "tmpfs", | 2778 | .name = "tmpfs", |
2767 | .mount = shmem_mount, | 2779 | .mount = shmem_mount, |
2768 | .kill_sb = kill_litter_super, | 2780 | .kill_sb = kill_litter_super, |
2781 | .fs_flags = FS_USERNS_MOUNT, | ||
2769 | }; | 2782 | }; |
2770 | 2783 | ||
2771 | int __init shmem_init(void) | 2784 | int __init shmem_init(void) |
@@ -2823,6 +2836,7 @@ static struct file_system_type shmem_fs_type = { | |||
2823 | .name = "tmpfs", | 2836 | .name = "tmpfs", |
2824 | .mount = ramfs_mount, | 2837 | .mount = ramfs_mount, |
2825 | .kill_sb = kill_litter_super, | 2838 | .kill_sb = kill_litter_super, |
2839 | .fs_flags = FS_USERNS_MOUNT, | ||
2826 | }; | 2840 | }; |
2827 | 2841 | ||
2828 | int __init shmem_init(void) | 2842 | int __init shmem_init(void) |
@@ -2865,6 +2879,16 @@ EXPORT_SYMBOL_GPL(shmem_truncate_range); | |||
2865 | 2879 | ||
2866 | /* common code */ | 2880 | /* common code */ |
2867 | 2881 | ||
2882 | static 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 | |||
2888 | static struct dentry_operations anon_ops = { | ||
2889 | .d_dname = shmem_dname | ||
2890 | }; | ||
2891 | |||
2868 | /** | 2892 | /** |
2869 | * shmem_file_setup - get an unlinked file living in tmpfs | 2893 | * shmem_file_setup - get an unlinked file living in tmpfs |
2870 | * @name: name for dentry (to be seen in /proc/<pid>/maps | 2894 | * @name: name for dentry (to be seen in /proc/<pid>/maps |
@@ -2873,15 +2897,14 @@ EXPORT_SYMBOL_GPL(shmem_truncate_range); | |||
2873 | */ | 2897 | */ |
2874 | struct file *shmem_file_setup(const char *name, loff_t size, unsigned long flags) | 2898 | struct file *shmem_file_setup(const char *name, loff_t size, unsigned long flags) |
2875 | { | 2899 | { |
2876 | int error; | 2900 | struct file *res; |
2877 | struct file *file; | ||
2878 | struct inode *inode; | 2901 | struct inode *inode; |
2879 | struct path path; | 2902 | struct path path; |
2880 | struct dentry *root; | 2903 | struct super_block *sb; |
2881 | struct qstr this; | 2904 | struct qstr this; |
2882 | 2905 | ||
2883 | if (IS_ERR(shm_mnt)) | 2906 | if (IS_ERR(shm_mnt)) |
2884 | return (void *)shm_mnt; | 2907 | return ERR_CAST(shm_mnt); |
2885 | 2908 | ||
2886 | if (size < 0 || size > MAX_LFS_FILESIZE) | 2909 | if (size < 0 || size > MAX_LFS_FILESIZE) |
2887 | return ERR_PTR(-EINVAL); | 2910 | return ERR_PTR(-EINVAL); |
@@ -2889,18 +2912,19 @@ struct file *shmem_file_setup(const char *name, loff_t size, unsigned long flags | |||
2889 | if (shmem_acct_size(flags, size)) | 2912 | if (shmem_acct_size(flags, size)) |
2890 | return ERR_PTR(-ENOMEM); | 2913 | return ERR_PTR(-ENOMEM); |
2891 | 2914 | ||
2892 | error = -ENOMEM; | 2915 | res = ERR_PTR(-ENOMEM); |
2893 | this.name = name; | 2916 | this.name = name; |
2894 | this.len = strlen(name); | 2917 | this.len = strlen(name); |
2895 | this.hash = 0; /* will go */ | 2918 | this.hash = 0; /* will go */ |
2896 | root = shm_mnt->mnt_root; | 2919 | sb = shm_mnt->mnt_sb; |
2897 | path.dentry = d_alloc(root, &this); | 2920 | path.dentry = d_alloc_pseudo(sb, &this); |
2898 | if (!path.dentry) | 2921 | if (!path.dentry) |
2899 | goto put_memory; | 2922 | goto put_memory; |
2923 | d_set_d_op(path.dentry, &anon_ops); | ||
2900 | path.mnt = mntget(shm_mnt); | 2924 | path.mnt = mntget(shm_mnt); |
2901 | 2925 | ||
2902 | error = -ENOSPC; | 2926 | res = ERR_PTR(-ENOSPC); |
2903 | 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); |
2904 | if (!inode) | 2928 | if (!inode) |
2905 | goto put_dentry; | 2929 | goto put_dentry; |
2906 | 2930 | ||
@@ -2908,24 +2932,23 @@ struct file *shmem_file_setup(const char *name, loff_t size, unsigned long flags | |||
2908 | inode->i_size = size; | 2932 | inode->i_size = size; |
2909 | clear_nlink(inode); /* It is unlinked */ | 2933 | clear_nlink(inode); /* It is unlinked */ |
2910 | #ifndef CONFIG_MMU | 2934 | #ifndef CONFIG_MMU |
2911 | error = ramfs_nommu_expand_for_mapping(inode, size); | 2935 | res = ERR_PTR(ramfs_nommu_expand_for_mapping(inode, size)); |
2912 | if (error) | 2936 | if (IS_ERR(res)) |
2913 | goto put_dentry; | 2937 | goto put_dentry; |
2914 | #endif | 2938 | #endif |
2915 | 2939 | ||
2916 | error = -ENFILE; | 2940 | res = alloc_file(&path, FMODE_WRITE | FMODE_READ, |
2917 | file = alloc_file(&path, FMODE_WRITE | FMODE_READ, | ||
2918 | &shmem_file_operations); | 2941 | &shmem_file_operations); |
2919 | if (!file) | 2942 | if (IS_ERR(res)) |
2920 | goto put_dentry; | 2943 | goto put_dentry; |
2921 | 2944 | ||
2922 | return file; | 2945 | return res; |
2923 | 2946 | ||
2924 | put_dentry: | 2947 | put_dentry: |
2925 | path_put(&path); | 2948 | path_put(&path); |
2926 | put_memory: | 2949 | put_memory: |
2927 | shmem_unacct_size(flags, size); | 2950 | shmem_unacct_size(flags, size); |
2928 | return ERR_PTR(error); | 2951 | return res; |
2929 | } | 2952 | } |
2930 | EXPORT_SYMBOL_GPL(shmem_file_setup); | 2953 | EXPORT_SYMBOL_GPL(shmem_file_setup); |
2931 | 2954 | ||