memory hotplug: missing zone->lock in test_pages_isolated()
[deliverable/linux.git] / mm / tiny-shmem.c
CommitLineData
1da177e4
LT
1/*
2 * tiny-shmem.c: simple shmemfs and tmpfs using ramfs code
3 *
4 * Matt Mackall <mpm@selenic.com> January, 2004
5 * derived from mm/shmem.c and fs/ramfs/inode.c
6 *
7 * This is intended for small system where the benefits of the full
8 * shmem code (swap-backed and resource-limited) are outweighed by
9 * their complexity. On systems without swap this code should be
10 * effectively equivalent, but much lighter weight.
11 */
12
13#include <linux/fs.h>
14#include <linux/init.h>
1da177e4
LT
15#include <linux/vfs.h>
16#include <linux/mount.h>
17#include <linux/file.h>
18#include <linux/mm.h>
19#include <linux/module.h>
20#include <linux/swap.h>
21#include <linux/ramfs.h>
22
23static struct file_system_type tmpfs_fs_type = {
24 .name = "tmpfs",
25 .get_sb = ramfs_get_sb,
26 .kill_sb = kill_litter_super,
27};
28
29static struct vfsmount *shm_mnt;
30
31static int __init init_tmpfs(void)
32{
5d57bd39
MM
33 BUG_ON(register_filesystem(&tmpfs_fs_type) != 0);
34
1da177e4 35 shm_mnt = kern_mount(&tmpfs_fs_type);
5d57bd39
MM
36 BUG_ON(IS_ERR(shm_mnt));
37
1da177e4
LT
38 return 0;
39}
40module_init(init_tmpfs)
41
46711810 42/**
1da177e4 43 * shmem_file_setup - get an unlinked file living in tmpfs
1da177e4
LT
44 * @name: name for dentry (to be seen in /proc/<pid>/maps
45 * @size: size to be set for the file
46711810 46 * @flags: vm_flags
1da177e4
LT
47 */
48struct file *shmem_file_setup(char *name, loff_t size, unsigned long flags)
49{
50 int error;
51 struct file *file;
52 struct inode *inode;
53 struct dentry *dentry, *root;
54 struct qstr this;
55
56 if (IS_ERR(shm_mnt))
57 return (void *)shm_mnt;
58
59 error = -ENOMEM;
60 this.name = name;
61 this.len = strlen(name);
62 this.hash = 0; /* will go */
63 root = shm_mnt->mnt_root;
64 dentry = d_alloc(root, &this);
65 if (!dentry)
66 goto put_memory;
67
ce8d2cdf 68 error = -ENFILE;
db203d53 69 file = get_empty_filp();
ce8d2cdf
DH
70 if (!file)
71 goto put_dentry;
b0e15190 72
db203d53
NP
73 error = -ENOSPC;
74 inode = ramfs_get_inode(root->d_sb, S_IFREG | S_IRWXUGO, 0);
75 if (!inode)
b0e15190
DH
76 goto close_file;
77
db203d53
NP
78 d_instantiate(dentry, inode);
79 inode->i_size = size;
80 inode->i_nlink = 0; /* It is unlinked */
81 init_file(file, shm_mnt, dentry, FMODE_WRITE | FMODE_READ,
82 &ramfs_file_operations);
1da177e4
LT
83 return file;
84
85close_file:
86 put_filp(file);
87put_dentry:
88 dput(dentry);
89put_memory:
90 return ERR_PTR(error);
91}
92
46711810 93/**
1da177e4 94 * shmem_zero_setup - setup a shared anonymous mapping
1da177e4
LT
95 * @vma: the vma to be mmapped is prepared by do_mmap_pgoff
96 */
97int shmem_zero_setup(struct vm_area_struct *vma)
98{
99 struct file *file;
100 loff_t size = vma->vm_end - vma->vm_start;
101
102 file = shmem_file_setup("dev/zero", size, vma->vm_flags);
103 if (IS_ERR(file))
104 return PTR_ERR(file);
105
106 if (vma->vm_file)
107 fput(vma->vm_file);
108 vma->vm_file = file;
109 vma->vm_ops = &generic_file_vm_ops;
110 return 0;
111}
112
113int shmem_unuse(swp_entry_t entry, struct page *page)
114{
115 return 0;
116}
b0e15190 117
b0e15190
DH
118#ifndef CONFIG_MMU
119unsigned long shmem_get_unmapped_area(struct file *file,
120 unsigned long addr,
121 unsigned long len,
122 unsigned long pgoff,
123 unsigned long flags)
124{
125 return ramfs_nommu_get_unmapped_area(file, addr, len, pgoff, flags);
126}
127#endif
This page took 0.405349 seconds and 5 git commands to generate.