]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - fs/proc/inode.c
SLUB: Do our own flags based on PG_active and PG_error
[mirror_ubuntu-bionic-kernel.git] / fs / proc / inode.c
CommitLineData
1da177e4
LT
1/*
2 * linux/fs/proc/inode.c
3 *
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 */
6
7#include <linux/time.h>
8#include <linux/proc_fs.h>
9#include <linux/kernel.h>
10#include <linux/mm.h>
11#include <linux/string.h>
12#include <linux/stat.h>
13#include <linux/file.h>
14#include <linux/limits.h>
15#include <linux/init.h>
16#include <linux/module.h>
17#include <linux/smp_lock.h>
18
19#include <asm/system.h>
20#include <asm/uaccess.h>
21
fee781e6 22#include "internal.h"
1da177e4 23
7695650a 24struct proc_dir_entry *de_get(struct proc_dir_entry *de)
1da177e4
LT
25{
26 if (de)
27 atomic_inc(&de->count);
28 return de;
29}
30
31/*
32 * Decrements the use count and checks for deferred deletion.
33 */
7695650a 34void de_put(struct proc_dir_entry *de)
1da177e4
LT
35{
36 if (de) {
37 lock_kernel();
38 if (!atomic_read(&de->count)) {
39 printk("de_put: entry %s already free!\n", de->name);
40 unlock_kernel();
41 return;
42 }
43
44 if (atomic_dec_and_test(&de->count)) {
45 if (de->deleted) {
46 printk("de_put: deferred delete of %s\n",
47 de->name);
48 free_proc_entry(de);
49 }
50 }
51 unlock_kernel();
52 }
53}
54
55/*
56 * Decrement the use count of the proc_dir_entry.
57 */
58static void proc_delete_inode(struct inode *inode)
59{
60 struct proc_dir_entry *de;
1da177e4 61
fef26658
MF
62 truncate_inode_pages(&inode->i_data, 0);
63
99f89551 64 /* Stop tracking associated processes */
13b41b09 65 put_pid(PROC_I(inode)->pid);
1da177e4
LT
66
67 /* Let go of any associated proc directory entry */
68 de = PROC_I(inode)->pde;
69 if (de) {
70 if (de->owner)
71 module_put(de->owner);
72 de_put(de);
73 }
74 clear_inode(inode);
75}
76
77struct vfsmount *proc_mnt;
78
79static void proc_read_inode(struct inode * inode)
80{
81 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
82}
83
e18b890b 84static struct kmem_cache * proc_inode_cachep;
1da177e4
LT
85
86static struct inode *proc_alloc_inode(struct super_block *sb)
87{
88 struct proc_inode *ei;
89 struct inode *inode;
90
e94b1766 91 ei = (struct proc_inode *)kmem_cache_alloc(proc_inode_cachep, GFP_KERNEL);
1da177e4
LT
92 if (!ei)
93 return NULL;
13b41b09 94 ei->pid = NULL;
aed7a6c4 95 ei->fd = 0;
1da177e4
LT
96 ei->op.proc_get_link = NULL;
97 ei->pde = NULL;
98 inode = &ei->vfs_inode;
99 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
100 return inode;
101}
102
103static void proc_destroy_inode(struct inode *inode)
104{
105 kmem_cache_free(proc_inode_cachep, PROC_I(inode));
106}
107
e18b890b 108static void init_once(void * foo, struct kmem_cache * cachep, unsigned long flags)
1da177e4
LT
109{
110 struct proc_inode *ei = (struct proc_inode *) foo;
111
50953fe9 112 if (flags & SLAB_CTOR_CONSTRUCTOR)
1da177e4
LT
113 inode_init_once(&ei->vfs_inode);
114}
115
116int __init proc_init_inodecache(void)
117{
118 proc_inode_cachep = kmem_cache_create("proc_inode_cache",
119 sizeof(struct proc_inode),
fffb60f9
PJ
120 0, (SLAB_RECLAIM_ACCOUNT|
121 SLAB_MEM_SPREAD),
1da177e4
LT
122 init_once, NULL);
123 if (proc_inode_cachep == NULL)
124 return -ENOMEM;
125 return 0;
126}
127
128static int proc_remount(struct super_block *sb, int *flags, char *data)
129{
130 *flags |= MS_NODIRATIME;
131 return 0;
132}
133
ee9b6d61 134static const struct super_operations proc_sops = {
1da177e4
LT
135 .alloc_inode = proc_alloc_inode,
136 .destroy_inode = proc_destroy_inode,
137 .read_inode = proc_read_inode,
138 .drop_inode = generic_delete_inode,
139 .delete_inode = proc_delete_inode,
140 .statfs = simple_statfs,
141 .remount_fs = proc_remount,
142};
143
144struct inode *proc_get_inode(struct super_block *sb, unsigned int ino,
145 struct proc_dir_entry *de)
146{
147 struct inode * inode;
148
e9543659
KK
149 if (de != NULL && !try_module_get(de->owner))
150 goto out_mod;
151
1da177e4
LT
152 inode = iget(sb, ino);
153 if (!inode)
e9543659
KK
154 goto out_ino;
155
77b14db5 156 PROC_I(inode)->fd = 0;
1da177e4
LT
157 PROC_I(inode)->pde = de;
158 if (de) {
159 if (de->mode) {
160 inode->i_mode = de->mode;
161 inode->i_uid = de->uid;
162 inode->i_gid = de->gid;
163 }
164 if (de->size)
165 inode->i_size = de->size;
166 if (de->nlink)
167 inode->i_nlink = de->nlink;
1da177e4
LT
168 if (de->proc_iops)
169 inode->i_op = de->proc_iops;
170 if (de->proc_fops)
171 inode->i_fop = de->proc_fops;
172 }
173
1da177e4
LT
174 return inode;
175
e9543659
KK
176out_ino:
177 if (de != NULL)
178 module_put(de->owner);
179out_mod:
e9543659 180 return NULL;
1da177e4
LT
181}
182
183int proc_fill_super(struct super_block *s, void *data, int silent)
184{
185 struct inode * root_inode;
186
92d03285 187 s->s_flags |= MS_NODIRATIME | MS_NOSUID | MS_NOEXEC;
1da177e4
LT
188 s->s_blocksize = 1024;
189 s->s_blocksize_bits = 10;
190 s->s_magic = PROC_SUPER_MAGIC;
191 s->s_op = &proc_sops;
192 s->s_time_gran = 1;
193
7695650a 194 de_get(&proc_root);
1da177e4
LT
195 root_inode = proc_get_inode(s, PROC_ROOT_INO, &proc_root);
196 if (!root_inode)
197 goto out_no_root;
1da177e4
LT
198 root_inode->i_uid = 0;
199 root_inode->i_gid = 0;
200 s->s_root = d_alloc_root(root_inode);
201 if (!s->s_root)
202 goto out_no_root;
203 return 0;
204
205out_no_root:
206 printk("proc_read_super: get root inode failed\n");
207 iput(root_inode);
7695650a 208 de_put(&proc_root);
1da177e4
LT
209 return -ENOMEM;
210}
211MODULE_LICENSE("GPL");