Commit 869243a0f6143f76e7c847e707eee6ece9cbf821
Committed by
Linus Torvalds
1 parent
9cf6f4b3a3
Exists in
master
and in
4 other branches
[PATCH] remove update_atime
All callers use touch_atime now which takes a vfsmount and allows us to implement per-mount noatime. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Showing 2 changed files with 7 additions and 12 deletions Inline Diff
fs/inode.c
1 | /* | 1 | /* |
2 | * linux/fs/inode.c | 2 | * linux/fs/inode.c |
3 | * | 3 | * |
4 | * (C) 1997 Linus Torvalds | 4 | * (C) 1997 Linus Torvalds |
5 | */ | 5 | */ |
6 | 6 | ||
7 | #include <linux/config.h> | 7 | #include <linux/config.h> |
8 | #include <linux/fs.h> | 8 | #include <linux/fs.h> |
9 | #include <linux/mm.h> | 9 | #include <linux/mm.h> |
10 | #include <linux/dcache.h> | 10 | #include <linux/dcache.h> |
11 | #include <linux/init.h> | 11 | #include <linux/init.h> |
12 | #include <linux/quotaops.h> | 12 | #include <linux/quotaops.h> |
13 | #include <linux/slab.h> | 13 | #include <linux/slab.h> |
14 | #include <linux/writeback.h> | 14 | #include <linux/writeback.h> |
15 | #include <linux/module.h> | 15 | #include <linux/module.h> |
16 | #include <linux/backing-dev.h> | 16 | #include <linux/backing-dev.h> |
17 | #include <linux/wait.h> | 17 | #include <linux/wait.h> |
18 | #include <linux/hash.h> | 18 | #include <linux/hash.h> |
19 | #include <linux/swap.h> | 19 | #include <linux/swap.h> |
20 | #include <linux/security.h> | 20 | #include <linux/security.h> |
21 | #include <linux/pagemap.h> | 21 | #include <linux/pagemap.h> |
22 | #include <linux/cdev.h> | 22 | #include <linux/cdev.h> |
23 | #include <linux/bootmem.h> | 23 | #include <linux/bootmem.h> |
24 | #include <linux/inotify.h> | 24 | #include <linux/inotify.h> |
25 | 25 | ||
26 | /* | 26 | /* |
27 | * This is needed for the following functions: | 27 | * This is needed for the following functions: |
28 | * - inode_has_buffers | 28 | * - inode_has_buffers |
29 | * - invalidate_inode_buffers | 29 | * - invalidate_inode_buffers |
30 | * - invalidate_bdev | 30 | * - invalidate_bdev |
31 | * | 31 | * |
32 | * FIXME: remove all knowledge of the buffer layer from this file | 32 | * FIXME: remove all knowledge of the buffer layer from this file |
33 | */ | 33 | */ |
34 | #include <linux/buffer_head.h> | 34 | #include <linux/buffer_head.h> |
35 | 35 | ||
36 | /* | 36 | /* |
37 | * New inode.c implementation. | 37 | * New inode.c implementation. |
38 | * | 38 | * |
39 | * This implementation has the basic premise of trying | 39 | * This implementation has the basic premise of trying |
40 | * to be extremely low-overhead and SMP-safe, yet be | 40 | * to be extremely low-overhead and SMP-safe, yet be |
41 | * simple enough to be "obviously correct". | 41 | * simple enough to be "obviously correct". |
42 | * | 42 | * |
43 | * Famous last words. | 43 | * Famous last words. |
44 | */ | 44 | */ |
45 | 45 | ||
46 | /* inode dynamic allocation 1999, Andrea Arcangeli <andrea@suse.de> */ | 46 | /* inode dynamic allocation 1999, Andrea Arcangeli <andrea@suse.de> */ |
47 | 47 | ||
48 | /* #define INODE_PARANOIA 1 */ | 48 | /* #define INODE_PARANOIA 1 */ |
49 | /* #define INODE_DEBUG 1 */ | 49 | /* #define INODE_DEBUG 1 */ |
50 | 50 | ||
51 | /* | 51 | /* |
52 | * Inode lookup is no longer as critical as it used to be: | 52 | * Inode lookup is no longer as critical as it used to be: |
53 | * most of the lookups are going to be through the dcache. | 53 | * most of the lookups are going to be through the dcache. |
54 | */ | 54 | */ |
55 | #define I_HASHBITS i_hash_shift | 55 | #define I_HASHBITS i_hash_shift |
56 | #define I_HASHMASK i_hash_mask | 56 | #define I_HASHMASK i_hash_mask |
57 | 57 | ||
58 | static unsigned int i_hash_mask; | 58 | static unsigned int i_hash_mask; |
59 | static unsigned int i_hash_shift; | 59 | static unsigned int i_hash_shift; |
60 | 60 | ||
61 | /* | 61 | /* |
62 | * Each inode can be on two separate lists. One is | 62 | * Each inode can be on two separate lists. One is |
63 | * the hash list of the inode, used for lookups. The | 63 | * the hash list of the inode, used for lookups. The |
64 | * other linked list is the "type" list: | 64 | * other linked list is the "type" list: |
65 | * "in_use" - valid inode, i_count > 0, i_nlink > 0 | 65 | * "in_use" - valid inode, i_count > 0, i_nlink > 0 |
66 | * "dirty" - as "in_use" but also dirty | 66 | * "dirty" - as "in_use" but also dirty |
67 | * "unused" - valid inode, i_count = 0 | 67 | * "unused" - valid inode, i_count = 0 |
68 | * | 68 | * |
69 | * A "dirty" list is maintained for each super block, | 69 | * A "dirty" list is maintained for each super block, |
70 | * allowing for low-overhead inode sync() operations. | 70 | * allowing for low-overhead inode sync() operations. |
71 | */ | 71 | */ |
72 | 72 | ||
73 | LIST_HEAD(inode_in_use); | 73 | LIST_HEAD(inode_in_use); |
74 | LIST_HEAD(inode_unused); | 74 | LIST_HEAD(inode_unused); |
75 | static struct hlist_head *inode_hashtable; | 75 | static struct hlist_head *inode_hashtable; |
76 | 76 | ||
77 | /* | 77 | /* |
78 | * A simple spinlock to protect the list manipulations. | 78 | * A simple spinlock to protect the list manipulations. |
79 | * | 79 | * |
80 | * NOTE! You also have to own the lock if you change | 80 | * NOTE! You also have to own the lock if you change |
81 | * the i_state of an inode while it is in use.. | 81 | * the i_state of an inode while it is in use.. |
82 | */ | 82 | */ |
83 | DEFINE_SPINLOCK(inode_lock); | 83 | DEFINE_SPINLOCK(inode_lock); |
84 | 84 | ||
85 | /* | 85 | /* |
86 | * iprune_sem provides exclusion between the kswapd or try_to_free_pages | 86 | * iprune_sem provides exclusion between the kswapd or try_to_free_pages |
87 | * icache shrinking path, and the umount path. Without this exclusion, | 87 | * icache shrinking path, and the umount path. Without this exclusion, |
88 | * by the time prune_icache calls iput for the inode whose pages it has | 88 | * by the time prune_icache calls iput for the inode whose pages it has |
89 | * been invalidating, or by the time it calls clear_inode & destroy_inode | 89 | * been invalidating, or by the time it calls clear_inode & destroy_inode |
90 | * from its final dispose_list, the struct super_block they refer to | 90 | * from its final dispose_list, the struct super_block they refer to |
91 | * (for inode->i_sb->s_op) may already have been freed and reused. | 91 | * (for inode->i_sb->s_op) may already have been freed and reused. |
92 | */ | 92 | */ |
93 | DECLARE_MUTEX(iprune_sem); | 93 | DECLARE_MUTEX(iprune_sem); |
94 | 94 | ||
95 | /* | 95 | /* |
96 | * Statistics gathering.. | 96 | * Statistics gathering.. |
97 | */ | 97 | */ |
98 | struct inodes_stat_t inodes_stat; | 98 | struct inodes_stat_t inodes_stat; |
99 | 99 | ||
100 | static kmem_cache_t * inode_cachep; | 100 | static kmem_cache_t * inode_cachep; |
101 | 101 | ||
102 | static struct inode *alloc_inode(struct super_block *sb) | 102 | static struct inode *alloc_inode(struct super_block *sb) |
103 | { | 103 | { |
104 | static struct address_space_operations empty_aops; | 104 | static struct address_space_operations empty_aops; |
105 | static struct inode_operations empty_iops; | 105 | static struct inode_operations empty_iops; |
106 | static struct file_operations empty_fops; | 106 | static struct file_operations empty_fops; |
107 | struct inode *inode; | 107 | struct inode *inode; |
108 | 108 | ||
109 | if (sb->s_op->alloc_inode) | 109 | if (sb->s_op->alloc_inode) |
110 | inode = sb->s_op->alloc_inode(sb); | 110 | inode = sb->s_op->alloc_inode(sb); |
111 | else | 111 | else |
112 | inode = (struct inode *) kmem_cache_alloc(inode_cachep, SLAB_KERNEL); | 112 | inode = (struct inode *) kmem_cache_alloc(inode_cachep, SLAB_KERNEL); |
113 | 113 | ||
114 | if (inode) { | 114 | if (inode) { |
115 | struct address_space * const mapping = &inode->i_data; | 115 | struct address_space * const mapping = &inode->i_data; |
116 | 116 | ||
117 | inode->i_sb = sb; | 117 | inode->i_sb = sb; |
118 | inode->i_blkbits = sb->s_blocksize_bits; | 118 | inode->i_blkbits = sb->s_blocksize_bits; |
119 | inode->i_flags = 0; | 119 | inode->i_flags = 0; |
120 | atomic_set(&inode->i_count, 1); | 120 | atomic_set(&inode->i_count, 1); |
121 | inode->i_op = &empty_iops; | 121 | inode->i_op = &empty_iops; |
122 | inode->i_fop = &empty_fops; | 122 | inode->i_fop = &empty_fops; |
123 | inode->i_nlink = 1; | 123 | inode->i_nlink = 1; |
124 | atomic_set(&inode->i_writecount, 0); | 124 | atomic_set(&inode->i_writecount, 0); |
125 | inode->i_size = 0; | 125 | inode->i_size = 0; |
126 | inode->i_blocks = 0; | 126 | inode->i_blocks = 0; |
127 | inode->i_bytes = 0; | 127 | inode->i_bytes = 0; |
128 | inode->i_generation = 0; | 128 | inode->i_generation = 0; |
129 | #ifdef CONFIG_QUOTA | 129 | #ifdef CONFIG_QUOTA |
130 | memset(&inode->i_dquot, 0, sizeof(inode->i_dquot)); | 130 | memset(&inode->i_dquot, 0, sizeof(inode->i_dquot)); |
131 | #endif | 131 | #endif |
132 | inode->i_pipe = NULL; | 132 | inode->i_pipe = NULL; |
133 | inode->i_bdev = NULL; | 133 | inode->i_bdev = NULL; |
134 | inode->i_cdev = NULL; | 134 | inode->i_cdev = NULL; |
135 | inode->i_rdev = 0; | 135 | inode->i_rdev = 0; |
136 | inode->i_security = NULL; | 136 | inode->i_security = NULL; |
137 | inode->dirtied_when = 0; | 137 | inode->dirtied_when = 0; |
138 | if (security_inode_alloc(inode)) { | 138 | if (security_inode_alloc(inode)) { |
139 | if (inode->i_sb->s_op->destroy_inode) | 139 | if (inode->i_sb->s_op->destroy_inode) |
140 | inode->i_sb->s_op->destroy_inode(inode); | 140 | inode->i_sb->s_op->destroy_inode(inode); |
141 | else | 141 | else |
142 | kmem_cache_free(inode_cachep, (inode)); | 142 | kmem_cache_free(inode_cachep, (inode)); |
143 | return NULL; | 143 | return NULL; |
144 | } | 144 | } |
145 | 145 | ||
146 | mapping->a_ops = &empty_aops; | 146 | mapping->a_ops = &empty_aops; |
147 | mapping->host = inode; | 147 | mapping->host = inode; |
148 | mapping->flags = 0; | 148 | mapping->flags = 0; |
149 | mapping_set_gfp_mask(mapping, GFP_HIGHUSER); | 149 | mapping_set_gfp_mask(mapping, GFP_HIGHUSER); |
150 | mapping->assoc_mapping = NULL; | 150 | mapping->assoc_mapping = NULL; |
151 | mapping->backing_dev_info = &default_backing_dev_info; | 151 | mapping->backing_dev_info = &default_backing_dev_info; |
152 | 152 | ||
153 | /* | 153 | /* |
154 | * If the block_device provides a backing_dev_info for client | 154 | * If the block_device provides a backing_dev_info for client |
155 | * inodes then use that. Otherwise the inode share the bdev's | 155 | * inodes then use that. Otherwise the inode share the bdev's |
156 | * backing_dev_info. | 156 | * backing_dev_info. |
157 | */ | 157 | */ |
158 | if (sb->s_bdev) { | 158 | if (sb->s_bdev) { |
159 | struct backing_dev_info *bdi; | 159 | struct backing_dev_info *bdi; |
160 | 160 | ||
161 | bdi = sb->s_bdev->bd_inode_backing_dev_info; | 161 | bdi = sb->s_bdev->bd_inode_backing_dev_info; |
162 | if (!bdi) | 162 | if (!bdi) |
163 | bdi = sb->s_bdev->bd_inode->i_mapping->backing_dev_info; | 163 | bdi = sb->s_bdev->bd_inode->i_mapping->backing_dev_info; |
164 | mapping->backing_dev_info = bdi; | 164 | mapping->backing_dev_info = bdi; |
165 | } | 165 | } |
166 | memset(&inode->u, 0, sizeof(inode->u)); | 166 | memset(&inode->u, 0, sizeof(inode->u)); |
167 | inode->i_mapping = mapping; | 167 | inode->i_mapping = mapping; |
168 | } | 168 | } |
169 | return inode; | 169 | return inode; |
170 | } | 170 | } |
171 | 171 | ||
172 | void destroy_inode(struct inode *inode) | 172 | void destroy_inode(struct inode *inode) |
173 | { | 173 | { |
174 | if (inode_has_buffers(inode)) | 174 | if (inode_has_buffers(inode)) |
175 | BUG(); | 175 | BUG(); |
176 | security_inode_free(inode); | 176 | security_inode_free(inode); |
177 | if (inode->i_sb->s_op->destroy_inode) | 177 | if (inode->i_sb->s_op->destroy_inode) |
178 | inode->i_sb->s_op->destroy_inode(inode); | 178 | inode->i_sb->s_op->destroy_inode(inode); |
179 | else | 179 | else |
180 | kmem_cache_free(inode_cachep, (inode)); | 180 | kmem_cache_free(inode_cachep, (inode)); |
181 | } | 181 | } |
182 | 182 | ||
183 | 183 | ||
184 | /* | 184 | /* |
185 | * These are initializations that only need to be done | 185 | * These are initializations that only need to be done |
186 | * once, because the fields are idempotent across use | 186 | * once, because the fields are idempotent across use |
187 | * of the inode, so let the slab aware of that. | 187 | * of the inode, so let the slab aware of that. |
188 | */ | 188 | */ |
189 | void inode_init_once(struct inode *inode) | 189 | void inode_init_once(struct inode *inode) |
190 | { | 190 | { |
191 | memset(inode, 0, sizeof(*inode)); | 191 | memset(inode, 0, sizeof(*inode)); |
192 | INIT_HLIST_NODE(&inode->i_hash); | 192 | INIT_HLIST_NODE(&inode->i_hash); |
193 | INIT_LIST_HEAD(&inode->i_dentry); | 193 | INIT_LIST_HEAD(&inode->i_dentry); |
194 | INIT_LIST_HEAD(&inode->i_devices); | 194 | INIT_LIST_HEAD(&inode->i_devices); |
195 | mutex_init(&inode->i_mutex); | 195 | mutex_init(&inode->i_mutex); |
196 | init_rwsem(&inode->i_alloc_sem); | 196 | init_rwsem(&inode->i_alloc_sem); |
197 | INIT_RADIX_TREE(&inode->i_data.page_tree, GFP_ATOMIC); | 197 | INIT_RADIX_TREE(&inode->i_data.page_tree, GFP_ATOMIC); |
198 | rwlock_init(&inode->i_data.tree_lock); | 198 | rwlock_init(&inode->i_data.tree_lock); |
199 | spin_lock_init(&inode->i_data.i_mmap_lock); | 199 | spin_lock_init(&inode->i_data.i_mmap_lock); |
200 | INIT_LIST_HEAD(&inode->i_data.private_list); | 200 | INIT_LIST_HEAD(&inode->i_data.private_list); |
201 | spin_lock_init(&inode->i_data.private_lock); | 201 | spin_lock_init(&inode->i_data.private_lock); |
202 | INIT_RAW_PRIO_TREE_ROOT(&inode->i_data.i_mmap); | 202 | INIT_RAW_PRIO_TREE_ROOT(&inode->i_data.i_mmap); |
203 | INIT_LIST_HEAD(&inode->i_data.i_mmap_nonlinear); | 203 | INIT_LIST_HEAD(&inode->i_data.i_mmap_nonlinear); |
204 | spin_lock_init(&inode->i_lock); | 204 | spin_lock_init(&inode->i_lock); |
205 | i_size_ordered_init(inode); | 205 | i_size_ordered_init(inode); |
206 | #ifdef CONFIG_INOTIFY | 206 | #ifdef CONFIG_INOTIFY |
207 | INIT_LIST_HEAD(&inode->inotify_watches); | 207 | INIT_LIST_HEAD(&inode->inotify_watches); |
208 | sema_init(&inode->inotify_sem, 1); | 208 | sema_init(&inode->inotify_sem, 1); |
209 | #endif | 209 | #endif |
210 | } | 210 | } |
211 | 211 | ||
212 | EXPORT_SYMBOL(inode_init_once); | 212 | EXPORT_SYMBOL(inode_init_once); |
213 | 213 | ||
214 | static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags) | 214 | static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags) |
215 | { | 215 | { |
216 | struct inode * inode = (struct inode *) foo; | 216 | struct inode * inode = (struct inode *) foo; |
217 | 217 | ||
218 | if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) == | 218 | if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) == |
219 | SLAB_CTOR_CONSTRUCTOR) | 219 | SLAB_CTOR_CONSTRUCTOR) |
220 | inode_init_once(inode); | 220 | inode_init_once(inode); |
221 | } | 221 | } |
222 | 222 | ||
223 | /* | 223 | /* |
224 | * inode_lock must be held | 224 | * inode_lock must be held |
225 | */ | 225 | */ |
226 | void __iget(struct inode * inode) | 226 | void __iget(struct inode * inode) |
227 | { | 227 | { |
228 | if (atomic_read(&inode->i_count)) { | 228 | if (atomic_read(&inode->i_count)) { |
229 | atomic_inc(&inode->i_count); | 229 | atomic_inc(&inode->i_count); |
230 | return; | 230 | return; |
231 | } | 231 | } |
232 | atomic_inc(&inode->i_count); | 232 | atomic_inc(&inode->i_count); |
233 | if (!(inode->i_state & (I_DIRTY|I_LOCK))) | 233 | if (!(inode->i_state & (I_DIRTY|I_LOCK))) |
234 | list_move(&inode->i_list, &inode_in_use); | 234 | list_move(&inode->i_list, &inode_in_use); |
235 | inodes_stat.nr_unused--; | 235 | inodes_stat.nr_unused--; |
236 | } | 236 | } |
237 | 237 | ||
238 | /** | 238 | /** |
239 | * clear_inode - clear an inode | 239 | * clear_inode - clear an inode |
240 | * @inode: inode to clear | 240 | * @inode: inode to clear |
241 | * | 241 | * |
242 | * This is called by the filesystem to tell us | 242 | * This is called by the filesystem to tell us |
243 | * that the inode is no longer useful. We just | 243 | * that the inode is no longer useful. We just |
244 | * terminate it with extreme prejudice. | 244 | * terminate it with extreme prejudice. |
245 | */ | 245 | */ |
246 | void clear_inode(struct inode *inode) | 246 | void clear_inode(struct inode *inode) |
247 | { | 247 | { |
248 | might_sleep(); | 248 | might_sleep(); |
249 | invalidate_inode_buffers(inode); | 249 | invalidate_inode_buffers(inode); |
250 | 250 | ||
251 | if (inode->i_data.nrpages) | 251 | if (inode->i_data.nrpages) |
252 | BUG(); | 252 | BUG(); |
253 | if (!(inode->i_state & I_FREEING)) | 253 | if (!(inode->i_state & I_FREEING)) |
254 | BUG(); | 254 | BUG(); |
255 | if (inode->i_state & I_CLEAR) | 255 | if (inode->i_state & I_CLEAR) |
256 | BUG(); | 256 | BUG(); |
257 | wait_on_inode(inode); | 257 | wait_on_inode(inode); |
258 | DQUOT_DROP(inode); | 258 | DQUOT_DROP(inode); |
259 | if (inode->i_sb && inode->i_sb->s_op->clear_inode) | 259 | if (inode->i_sb && inode->i_sb->s_op->clear_inode) |
260 | inode->i_sb->s_op->clear_inode(inode); | 260 | inode->i_sb->s_op->clear_inode(inode); |
261 | if (inode->i_bdev) | 261 | if (inode->i_bdev) |
262 | bd_forget(inode); | 262 | bd_forget(inode); |
263 | if (inode->i_cdev) | 263 | if (inode->i_cdev) |
264 | cd_forget(inode); | 264 | cd_forget(inode); |
265 | inode->i_state = I_CLEAR; | 265 | inode->i_state = I_CLEAR; |
266 | } | 266 | } |
267 | 267 | ||
268 | EXPORT_SYMBOL(clear_inode); | 268 | EXPORT_SYMBOL(clear_inode); |
269 | 269 | ||
270 | /* | 270 | /* |
271 | * dispose_list - dispose of the contents of a local list | 271 | * dispose_list - dispose of the contents of a local list |
272 | * @head: the head of the list to free | 272 | * @head: the head of the list to free |
273 | * | 273 | * |
274 | * Dispose-list gets a local list with local inodes in it, so it doesn't | 274 | * Dispose-list gets a local list with local inodes in it, so it doesn't |
275 | * need to worry about list corruption and SMP locks. | 275 | * need to worry about list corruption and SMP locks. |
276 | */ | 276 | */ |
277 | static void dispose_list(struct list_head *head) | 277 | static void dispose_list(struct list_head *head) |
278 | { | 278 | { |
279 | int nr_disposed = 0; | 279 | int nr_disposed = 0; |
280 | 280 | ||
281 | while (!list_empty(head)) { | 281 | while (!list_empty(head)) { |
282 | struct inode *inode; | 282 | struct inode *inode; |
283 | 283 | ||
284 | inode = list_entry(head->next, struct inode, i_list); | 284 | inode = list_entry(head->next, struct inode, i_list); |
285 | list_del(&inode->i_list); | 285 | list_del(&inode->i_list); |
286 | 286 | ||
287 | if (inode->i_data.nrpages) | 287 | if (inode->i_data.nrpages) |
288 | truncate_inode_pages(&inode->i_data, 0); | 288 | truncate_inode_pages(&inode->i_data, 0); |
289 | clear_inode(inode); | 289 | clear_inode(inode); |
290 | 290 | ||
291 | spin_lock(&inode_lock); | 291 | spin_lock(&inode_lock); |
292 | hlist_del_init(&inode->i_hash); | 292 | hlist_del_init(&inode->i_hash); |
293 | list_del_init(&inode->i_sb_list); | 293 | list_del_init(&inode->i_sb_list); |
294 | spin_unlock(&inode_lock); | 294 | spin_unlock(&inode_lock); |
295 | 295 | ||
296 | wake_up_inode(inode); | 296 | wake_up_inode(inode); |
297 | destroy_inode(inode); | 297 | destroy_inode(inode); |
298 | nr_disposed++; | 298 | nr_disposed++; |
299 | } | 299 | } |
300 | spin_lock(&inode_lock); | 300 | spin_lock(&inode_lock); |
301 | inodes_stat.nr_inodes -= nr_disposed; | 301 | inodes_stat.nr_inodes -= nr_disposed; |
302 | spin_unlock(&inode_lock); | 302 | spin_unlock(&inode_lock); |
303 | } | 303 | } |
304 | 304 | ||
305 | /* | 305 | /* |
306 | * Invalidate all inodes for a device. | 306 | * Invalidate all inodes for a device. |
307 | */ | 307 | */ |
308 | static int invalidate_list(struct list_head *head, struct list_head *dispose) | 308 | static int invalidate_list(struct list_head *head, struct list_head *dispose) |
309 | { | 309 | { |
310 | struct list_head *next; | 310 | struct list_head *next; |
311 | int busy = 0, count = 0; | 311 | int busy = 0, count = 0; |
312 | 312 | ||
313 | next = head->next; | 313 | next = head->next; |
314 | for (;;) { | 314 | for (;;) { |
315 | struct list_head * tmp = next; | 315 | struct list_head * tmp = next; |
316 | struct inode * inode; | 316 | struct inode * inode; |
317 | 317 | ||
318 | /* | 318 | /* |
319 | * We can reschedule here without worrying about the list's | 319 | * We can reschedule here without worrying about the list's |
320 | * consistency because the per-sb list of inodes must not | 320 | * consistency because the per-sb list of inodes must not |
321 | * change during umount anymore, and because iprune_sem keeps | 321 | * change during umount anymore, and because iprune_sem keeps |
322 | * shrink_icache_memory() away. | 322 | * shrink_icache_memory() away. |
323 | */ | 323 | */ |
324 | cond_resched_lock(&inode_lock); | 324 | cond_resched_lock(&inode_lock); |
325 | 325 | ||
326 | next = next->next; | 326 | next = next->next; |
327 | if (tmp == head) | 327 | if (tmp == head) |
328 | break; | 328 | break; |
329 | inode = list_entry(tmp, struct inode, i_sb_list); | 329 | inode = list_entry(tmp, struct inode, i_sb_list); |
330 | invalidate_inode_buffers(inode); | 330 | invalidate_inode_buffers(inode); |
331 | if (!atomic_read(&inode->i_count)) { | 331 | if (!atomic_read(&inode->i_count)) { |
332 | list_move(&inode->i_list, dispose); | 332 | list_move(&inode->i_list, dispose); |
333 | inode->i_state |= I_FREEING; | 333 | inode->i_state |= I_FREEING; |
334 | count++; | 334 | count++; |
335 | continue; | 335 | continue; |
336 | } | 336 | } |
337 | busy = 1; | 337 | busy = 1; |
338 | } | 338 | } |
339 | /* only unused inodes may be cached with i_count zero */ | 339 | /* only unused inodes may be cached with i_count zero */ |
340 | inodes_stat.nr_unused -= count; | 340 | inodes_stat.nr_unused -= count; |
341 | return busy; | 341 | return busy; |
342 | } | 342 | } |
343 | 343 | ||
344 | /** | 344 | /** |
345 | * invalidate_inodes - discard the inodes on a device | 345 | * invalidate_inodes - discard the inodes on a device |
346 | * @sb: superblock | 346 | * @sb: superblock |
347 | * | 347 | * |
348 | * Discard all of the inodes for a given superblock. If the discard | 348 | * Discard all of the inodes for a given superblock. If the discard |
349 | * fails because there are busy inodes then a non zero value is returned. | 349 | * fails because there are busy inodes then a non zero value is returned. |
350 | * If the discard is successful all the inodes have been discarded. | 350 | * If the discard is successful all the inodes have been discarded. |
351 | */ | 351 | */ |
352 | int invalidate_inodes(struct super_block * sb) | 352 | int invalidate_inodes(struct super_block * sb) |
353 | { | 353 | { |
354 | int busy; | 354 | int busy; |
355 | LIST_HEAD(throw_away); | 355 | LIST_HEAD(throw_away); |
356 | 356 | ||
357 | down(&iprune_sem); | 357 | down(&iprune_sem); |
358 | spin_lock(&inode_lock); | 358 | spin_lock(&inode_lock); |
359 | inotify_unmount_inodes(&sb->s_inodes); | 359 | inotify_unmount_inodes(&sb->s_inodes); |
360 | busy = invalidate_list(&sb->s_inodes, &throw_away); | 360 | busy = invalidate_list(&sb->s_inodes, &throw_away); |
361 | spin_unlock(&inode_lock); | 361 | spin_unlock(&inode_lock); |
362 | 362 | ||
363 | dispose_list(&throw_away); | 363 | dispose_list(&throw_away); |
364 | up(&iprune_sem); | 364 | up(&iprune_sem); |
365 | 365 | ||
366 | return busy; | 366 | return busy; |
367 | } | 367 | } |
368 | 368 | ||
369 | EXPORT_SYMBOL(invalidate_inodes); | 369 | EXPORT_SYMBOL(invalidate_inodes); |
370 | 370 | ||
371 | int __invalidate_device(struct block_device *bdev) | 371 | int __invalidate_device(struct block_device *bdev) |
372 | { | 372 | { |
373 | struct super_block *sb = get_super(bdev); | 373 | struct super_block *sb = get_super(bdev); |
374 | int res = 0; | 374 | int res = 0; |
375 | 375 | ||
376 | if (sb) { | 376 | if (sb) { |
377 | /* | 377 | /* |
378 | * no need to lock the super, get_super holds the | 378 | * no need to lock the super, get_super holds the |
379 | * read semaphore so the filesystem cannot go away | 379 | * read semaphore so the filesystem cannot go away |
380 | * under us (->put_super runs with the write lock | 380 | * under us (->put_super runs with the write lock |
381 | * hold). | 381 | * hold). |
382 | */ | 382 | */ |
383 | shrink_dcache_sb(sb); | 383 | shrink_dcache_sb(sb); |
384 | res = invalidate_inodes(sb); | 384 | res = invalidate_inodes(sb); |
385 | drop_super(sb); | 385 | drop_super(sb); |
386 | } | 386 | } |
387 | invalidate_bdev(bdev, 0); | 387 | invalidate_bdev(bdev, 0); |
388 | return res; | 388 | return res; |
389 | } | 389 | } |
390 | EXPORT_SYMBOL(__invalidate_device); | 390 | EXPORT_SYMBOL(__invalidate_device); |
391 | 391 | ||
392 | static int can_unuse(struct inode *inode) | 392 | static int can_unuse(struct inode *inode) |
393 | { | 393 | { |
394 | if (inode->i_state) | 394 | if (inode->i_state) |
395 | return 0; | 395 | return 0; |
396 | if (inode_has_buffers(inode)) | 396 | if (inode_has_buffers(inode)) |
397 | return 0; | 397 | return 0; |
398 | if (atomic_read(&inode->i_count)) | 398 | if (atomic_read(&inode->i_count)) |
399 | return 0; | 399 | return 0; |
400 | if (inode->i_data.nrpages) | 400 | if (inode->i_data.nrpages) |
401 | return 0; | 401 | return 0; |
402 | return 1; | 402 | return 1; |
403 | } | 403 | } |
404 | 404 | ||
405 | /* | 405 | /* |
406 | * Scan `goal' inodes on the unused list for freeable ones. They are moved to | 406 | * Scan `goal' inodes on the unused list for freeable ones. They are moved to |
407 | * a temporary list and then are freed outside inode_lock by dispose_list(). | 407 | * a temporary list and then are freed outside inode_lock by dispose_list(). |
408 | * | 408 | * |
409 | * Any inodes which are pinned purely because of attached pagecache have their | 409 | * Any inodes which are pinned purely because of attached pagecache have their |
410 | * pagecache removed. We expect the final iput() on that inode to add it to | 410 | * pagecache removed. We expect the final iput() on that inode to add it to |
411 | * the front of the inode_unused list. So look for it there and if the | 411 | * the front of the inode_unused list. So look for it there and if the |
412 | * inode is still freeable, proceed. The right inode is found 99.9% of the | 412 | * inode is still freeable, proceed. The right inode is found 99.9% of the |
413 | * time in testing on a 4-way. | 413 | * time in testing on a 4-way. |
414 | * | 414 | * |
415 | * If the inode has metadata buffers attached to mapping->private_list then | 415 | * If the inode has metadata buffers attached to mapping->private_list then |
416 | * try to remove them. | 416 | * try to remove them. |
417 | */ | 417 | */ |
418 | static void prune_icache(int nr_to_scan) | 418 | static void prune_icache(int nr_to_scan) |
419 | { | 419 | { |
420 | LIST_HEAD(freeable); | 420 | LIST_HEAD(freeable); |
421 | int nr_pruned = 0; | 421 | int nr_pruned = 0; |
422 | int nr_scanned; | 422 | int nr_scanned; |
423 | unsigned long reap = 0; | 423 | unsigned long reap = 0; |
424 | 424 | ||
425 | down(&iprune_sem); | 425 | down(&iprune_sem); |
426 | spin_lock(&inode_lock); | 426 | spin_lock(&inode_lock); |
427 | for (nr_scanned = 0; nr_scanned < nr_to_scan; nr_scanned++) { | 427 | for (nr_scanned = 0; nr_scanned < nr_to_scan; nr_scanned++) { |
428 | struct inode *inode; | 428 | struct inode *inode; |
429 | 429 | ||
430 | if (list_empty(&inode_unused)) | 430 | if (list_empty(&inode_unused)) |
431 | break; | 431 | break; |
432 | 432 | ||
433 | inode = list_entry(inode_unused.prev, struct inode, i_list); | 433 | inode = list_entry(inode_unused.prev, struct inode, i_list); |
434 | 434 | ||
435 | if (inode->i_state || atomic_read(&inode->i_count)) { | 435 | if (inode->i_state || atomic_read(&inode->i_count)) { |
436 | list_move(&inode->i_list, &inode_unused); | 436 | list_move(&inode->i_list, &inode_unused); |
437 | continue; | 437 | continue; |
438 | } | 438 | } |
439 | if (inode_has_buffers(inode) || inode->i_data.nrpages) { | 439 | if (inode_has_buffers(inode) || inode->i_data.nrpages) { |
440 | __iget(inode); | 440 | __iget(inode); |
441 | spin_unlock(&inode_lock); | 441 | spin_unlock(&inode_lock); |
442 | if (remove_inode_buffers(inode)) | 442 | if (remove_inode_buffers(inode)) |
443 | reap += invalidate_inode_pages(&inode->i_data); | 443 | reap += invalidate_inode_pages(&inode->i_data); |
444 | iput(inode); | 444 | iput(inode); |
445 | spin_lock(&inode_lock); | 445 | spin_lock(&inode_lock); |
446 | 446 | ||
447 | if (inode != list_entry(inode_unused.next, | 447 | if (inode != list_entry(inode_unused.next, |
448 | struct inode, i_list)) | 448 | struct inode, i_list)) |
449 | continue; /* wrong inode or list_empty */ | 449 | continue; /* wrong inode or list_empty */ |
450 | if (!can_unuse(inode)) | 450 | if (!can_unuse(inode)) |
451 | continue; | 451 | continue; |
452 | } | 452 | } |
453 | list_move(&inode->i_list, &freeable); | 453 | list_move(&inode->i_list, &freeable); |
454 | inode->i_state |= I_FREEING; | 454 | inode->i_state |= I_FREEING; |
455 | nr_pruned++; | 455 | nr_pruned++; |
456 | } | 456 | } |
457 | inodes_stat.nr_unused -= nr_pruned; | 457 | inodes_stat.nr_unused -= nr_pruned; |
458 | spin_unlock(&inode_lock); | 458 | spin_unlock(&inode_lock); |
459 | 459 | ||
460 | dispose_list(&freeable); | 460 | dispose_list(&freeable); |
461 | up(&iprune_sem); | 461 | up(&iprune_sem); |
462 | 462 | ||
463 | if (current_is_kswapd()) | 463 | if (current_is_kswapd()) |
464 | mod_page_state(kswapd_inodesteal, reap); | 464 | mod_page_state(kswapd_inodesteal, reap); |
465 | else | 465 | else |
466 | mod_page_state(pginodesteal, reap); | 466 | mod_page_state(pginodesteal, reap); |
467 | } | 467 | } |
468 | 468 | ||
469 | /* | 469 | /* |
470 | * shrink_icache_memory() will attempt to reclaim some unused inodes. Here, | 470 | * shrink_icache_memory() will attempt to reclaim some unused inodes. Here, |
471 | * "unused" means that no dentries are referring to the inodes: the files are | 471 | * "unused" means that no dentries are referring to the inodes: the files are |
472 | * not open and the dcache references to those inodes have already been | 472 | * not open and the dcache references to those inodes have already been |
473 | * reclaimed. | 473 | * reclaimed. |
474 | * | 474 | * |
475 | * This function is passed the number of inodes to scan, and it returns the | 475 | * This function is passed the number of inodes to scan, and it returns the |
476 | * total number of remaining possibly-reclaimable inodes. | 476 | * total number of remaining possibly-reclaimable inodes. |
477 | */ | 477 | */ |
478 | static int shrink_icache_memory(int nr, gfp_t gfp_mask) | 478 | static int shrink_icache_memory(int nr, gfp_t gfp_mask) |
479 | { | 479 | { |
480 | if (nr) { | 480 | if (nr) { |
481 | /* | 481 | /* |
482 | * Nasty deadlock avoidance. We may hold various FS locks, | 482 | * Nasty deadlock avoidance. We may hold various FS locks, |
483 | * and we don't want to recurse into the FS that called us | 483 | * and we don't want to recurse into the FS that called us |
484 | * in clear_inode() and friends.. | 484 | * in clear_inode() and friends.. |
485 | */ | 485 | */ |
486 | if (!(gfp_mask & __GFP_FS)) | 486 | if (!(gfp_mask & __GFP_FS)) |
487 | return -1; | 487 | return -1; |
488 | prune_icache(nr); | 488 | prune_icache(nr); |
489 | } | 489 | } |
490 | return (inodes_stat.nr_unused / 100) * sysctl_vfs_cache_pressure; | 490 | return (inodes_stat.nr_unused / 100) * sysctl_vfs_cache_pressure; |
491 | } | 491 | } |
492 | 492 | ||
493 | static void __wait_on_freeing_inode(struct inode *inode); | 493 | static void __wait_on_freeing_inode(struct inode *inode); |
494 | /* | 494 | /* |
495 | * Called with the inode lock held. | 495 | * Called with the inode lock held. |
496 | * NOTE: we are not increasing the inode-refcount, you must call __iget() | 496 | * NOTE: we are not increasing the inode-refcount, you must call __iget() |
497 | * by hand after calling find_inode now! This simplifies iunique and won't | 497 | * by hand after calling find_inode now! This simplifies iunique and won't |
498 | * add any additional branch in the common code. | 498 | * add any additional branch in the common code. |
499 | */ | 499 | */ |
500 | static struct inode * find_inode(struct super_block * sb, struct hlist_head *head, int (*test)(struct inode *, void *), void *data) | 500 | static struct inode * find_inode(struct super_block * sb, struct hlist_head *head, int (*test)(struct inode *, void *), void *data) |
501 | { | 501 | { |
502 | struct hlist_node *node; | 502 | struct hlist_node *node; |
503 | struct inode * inode = NULL; | 503 | struct inode * inode = NULL; |
504 | 504 | ||
505 | repeat: | 505 | repeat: |
506 | hlist_for_each (node, head) { | 506 | hlist_for_each (node, head) { |
507 | inode = hlist_entry(node, struct inode, i_hash); | 507 | inode = hlist_entry(node, struct inode, i_hash); |
508 | if (inode->i_sb != sb) | 508 | if (inode->i_sb != sb) |
509 | continue; | 509 | continue; |
510 | if (!test(inode, data)) | 510 | if (!test(inode, data)) |
511 | continue; | 511 | continue; |
512 | if (inode->i_state & (I_FREEING|I_CLEAR|I_WILL_FREE)) { | 512 | if (inode->i_state & (I_FREEING|I_CLEAR|I_WILL_FREE)) { |
513 | __wait_on_freeing_inode(inode); | 513 | __wait_on_freeing_inode(inode); |
514 | goto repeat; | 514 | goto repeat; |
515 | } | 515 | } |
516 | break; | 516 | break; |
517 | } | 517 | } |
518 | return node ? inode : NULL; | 518 | return node ? inode : NULL; |
519 | } | 519 | } |
520 | 520 | ||
521 | /* | 521 | /* |
522 | * find_inode_fast is the fast path version of find_inode, see the comment at | 522 | * find_inode_fast is the fast path version of find_inode, see the comment at |
523 | * iget_locked for details. | 523 | * iget_locked for details. |
524 | */ | 524 | */ |
525 | static struct inode * find_inode_fast(struct super_block * sb, struct hlist_head *head, unsigned long ino) | 525 | static struct inode * find_inode_fast(struct super_block * sb, struct hlist_head *head, unsigned long ino) |
526 | { | 526 | { |
527 | struct hlist_node *node; | 527 | struct hlist_node *node; |
528 | struct inode * inode = NULL; | 528 | struct inode * inode = NULL; |
529 | 529 | ||
530 | repeat: | 530 | repeat: |
531 | hlist_for_each (node, head) { | 531 | hlist_for_each (node, head) { |
532 | inode = hlist_entry(node, struct inode, i_hash); | 532 | inode = hlist_entry(node, struct inode, i_hash); |
533 | if (inode->i_ino != ino) | 533 | if (inode->i_ino != ino) |
534 | continue; | 534 | continue; |
535 | if (inode->i_sb != sb) | 535 | if (inode->i_sb != sb) |
536 | continue; | 536 | continue; |
537 | if (inode->i_state & (I_FREEING|I_CLEAR|I_WILL_FREE)) { | 537 | if (inode->i_state & (I_FREEING|I_CLEAR|I_WILL_FREE)) { |
538 | __wait_on_freeing_inode(inode); | 538 | __wait_on_freeing_inode(inode); |
539 | goto repeat; | 539 | goto repeat; |
540 | } | 540 | } |
541 | break; | 541 | break; |
542 | } | 542 | } |
543 | return node ? inode : NULL; | 543 | return node ? inode : NULL; |
544 | } | 544 | } |
545 | 545 | ||
546 | /** | 546 | /** |
547 | * new_inode - obtain an inode | 547 | * new_inode - obtain an inode |
548 | * @sb: superblock | 548 | * @sb: superblock |
549 | * | 549 | * |
550 | * Allocates a new inode for given superblock. | 550 | * Allocates a new inode for given superblock. |
551 | */ | 551 | */ |
552 | struct inode *new_inode(struct super_block *sb) | 552 | struct inode *new_inode(struct super_block *sb) |
553 | { | 553 | { |
554 | static unsigned long last_ino; | 554 | static unsigned long last_ino; |
555 | struct inode * inode; | 555 | struct inode * inode; |
556 | 556 | ||
557 | spin_lock_prefetch(&inode_lock); | 557 | spin_lock_prefetch(&inode_lock); |
558 | 558 | ||
559 | inode = alloc_inode(sb); | 559 | inode = alloc_inode(sb); |
560 | if (inode) { | 560 | if (inode) { |
561 | spin_lock(&inode_lock); | 561 | spin_lock(&inode_lock); |
562 | inodes_stat.nr_inodes++; | 562 | inodes_stat.nr_inodes++; |
563 | list_add(&inode->i_list, &inode_in_use); | 563 | list_add(&inode->i_list, &inode_in_use); |
564 | list_add(&inode->i_sb_list, &sb->s_inodes); | 564 | list_add(&inode->i_sb_list, &sb->s_inodes); |
565 | inode->i_ino = ++last_ino; | 565 | inode->i_ino = ++last_ino; |
566 | inode->i_state = 0; | 566 | inode->i_state = 0; |
567 | spin_unlock(&inode_lock); | 567 | spin_unlock(&inode_lock); |
568 | } | 568 | } |
569 | return inode; | 569 | return inode; |
570 | } | 570 | } |
571 | 571 | ||
572 | EXPORT_SYMBOL(new_inode); | 572 | EXPORT_SYMBOL(new_inode); |
573 | 573 | ||
574 | void unlock_new_inode(struct inode *inode) | 574 | void unlock_new_inode(struct inode *inode) |
575 | { | 575 | { |
576 | /* | 576 | /* |
577 | * This is special! We do not need the spinlock | 577 | * This is special! We do not need the spinlock |
578 | * when clearing I_LOCK, because we're guaranteed | 578 | * when clearing I_LOCK, because we're guaranteed |
579 | * that nobody else tries to do anything about the | 579 | * that nobody else tries to do anything about the |
580 | * state of the inode when it is locked, as we | 580 | * state of the inode when it is locked, as we |
581 | * just created it (so there can be no old holders | 581 | * just created it (so there can be no old holders |
582 | * that haven't tested I_LOCK). | 582 | * that haven't tested I_LOCK). |
583 | */ | 583 | */ |
584 | inode->i_state &= ~(I_LOCK|I_NEW); | 584 | inode->i_state &= ~(I_LOCK|I_NEW); |
585 | wake_up_inode(inode); | 585 | wake_up_inode(inode); |
586 | } | 586 | } |
587 | 587 | ||
588 | EXPORT_SYMBOL(unlock_new_inode); | 588 | EXPORT_SYMBOL(unlock_new_inode); |
589 | 589 | ||
590 | /* | 590 | /* |
591 | * This is called without the inode lock held.. Be careful. | 591 | * This is called without the inode lock held.. Be careful. |
592 | * | 592 | * |
593 | * We no longer cache the sb_flags in i_flags - see fs.h | 593 | * We no longer cache the sb_flags in i_flags - see fs.h |
594 | * -- rmk@arm.uk.linux.org | 594 | * -- rmk@arm.uk.linux.org |
595 | */ | 595 | */ |
596 | static struct inode * get_new_inode(struct super_block *sb, struct hlist_head *head, int (*test)(struct inode *, void *), int (*set)(struct inode *, void *), void *data) | 596 | static struct inode * get_new_inode(struct super_block *sb, struct hlist_head *head, int (*test)(struct inode *, void *), int (*set)(struct inode *, void *), void *data) |
597 | { | 597 | { |
598 | struct inode * inode; | 598 | struct inode * inode; |
599 | 599 | ||
600 | inode = alloc_inode(sb); | 600 | inode = alloc_inode(sb); |
601 | if (inode) { | 601 | if (inode) { |
602 | struct inode * old; | 602 | struct inode * old; |
603 | 603 | ||
604 | spin_lock(&inode_lock); | 604 | spin_lock(&inode_lock); |
605 | /* We released the lock, so.. */ | 605 | /* We released the lock, so.. */ |
606 | old = find_inode(sb, head, test, data); | 606 | old = find_inode(sb, head, test, data); |
607 | if (!old) { | 607 | if (!old) { |
608 | if (set(inode, data)) | 608 | if (set(inode, data)) |
609 | goto set_failed; | 609 | goto set_failed; |
610 | 610 | ||
611 | inodes_stat.nr_inodes++; | 611 | inodes_stat.nr_inodes++; |
612 | list_add(&inode->i_list, &inode_in_use); | 612 | list_add(&inode->i_list, &inode_in_use); |
613 | list_add(&inode->i_sb_list, &sb->s_inodes); | 613 | list_add(&inode->i_sb_list, &sb->s_inodes); |
614 | hlist_add_head(&inode->i_hash, head); | 614 | hlist_add_head(&inode->i_hash, head); |
615 | inode->i_state = I_LOCK|I_NEW; | 615 | inode->i_state = I_LOCK|I_NEW; |
616 | spin_unlock(&inode_lock); | 616 | spin_unlock(&inode_lock); |
617 | 617 | ||
618 | /* Return the locked inode with I_NEW set, the | 618 | /* Return the locked inode with I_NEW set, the |
619 | * caller is responsible for filling in the contents | 619 | * caller is responsible for filling in the contents |
620 | */ | 620 | */ |
621 | return inode; | 621 | return inode; |
622 | } | 622 | } |
623 | 623 | ||
624 | /* | 624 | /* |
625 | * Uhhuh, somebody else created the same inode under | 625 | * Uhhuh, somebody else created the same inode under |
626 | * us. Use the old inode instead of the one we just | 626 | * us. Use the old inode instead of the one we just |
627 | * allocated. | 627 | * allocated. |
628 | */ | 628 | */ |
629 | __iget(old); | 629 | __iget(old); |
630 | spin_unlock(&inode_lock); | 630 | spin_unlock(&inode_lock); |
631 | destroy_inode(inode); | 631 | destroy_inode(inode); |
632 | inode = old; | 632 | inode = old; |
633 | wait_on_inode(inode); | 633 | wait_on_inode(inode); |
634 | } | 634 | } |
635 | return inode; | 635 | return inode; |
636 | 636 | ||
637 | set_failed: | 637 | set_failed: |
638 | spin_unlock(&inode_lock); | 638 | spin_unlock(&inode_lock); |
639 | destroy_inode(inode); | 639 | destroy_inode(inode); |
640 | return NULL; | 640 | return NULL; |
641 | } | 641 | } |
642 | 642 | ||
643 | /* | 643 | /* |
644 | * get_new_inode_fast is the fast path version of get_new_inode, see the | 644 | * get_new_inode_fast is the fast path version of get_new_inode, see the |
645 | * comment at iget_locked for details. | 645 | * comment at iget_locked for details. |
646 | */ | 646 | */ |
647 | static struct inode * get_new_inode_fast(struct super_block *sb, struct hlist_head *head, unsigned long ino) | 647 | static struct inode * get_new_inode_fast(struct super_block *sb, struct hlist_head *head, unsigned long ino) |
648 | { | 648 | { |
649 | struct inode * inode; | 649 | struct inode * inode; |
650 | 650 | ||
651 | inode = alloc_inode(sb); | 651 | inode = alloc_inode(sb); |
652 | if (inode) { | 652 | if (inode) { |
653 | struct inode * old; | 653 | struct inode * old; |
654 | 654 | ||
655 | spin_lock(&inode_lock); | 655 | spin_lock(&inode_lock); |
656 | /* We released the lock, so.. */ | 656 | /* We released the lock, so.. */ |
657 | old = find_inode_fast(sb, head, ino); | 657 | old = find_inode_fast(sb, head, ino); |
658 | if (!old) { | 658 | if (!old) { |
659 | inode->i_ino = ino; | 659 | inode->i_ino = ino; |
660 | inodes_stat.nr_inodes++; | 660 | inodes_stat.nr_inodes++; |
661 | list_add(&inode->i_list, &inode_in_use); | 661 | list_add(&inode->i_list, &inode_in_use); |
662 | list_add(&inode->i_sb_list, &sb->s_inodes); | 662 | list_add(&inode->i_sb_list, &sb->s_inodes); |
663 | hlist_add_head(&inode->i_hash, head); | 663 | hlist_add_head(&inode->i_hash, head); |
664 | inode->i_state = I_LOCK|I_NEW; | 664 | inode->i_state = I_LOCK|I_NEW; |
665 | spin_unlock(&inode_lock); | 665 | spin_unlock(&inode_lock); |
666 | 666 | ||
667 | /* Return the locked inode with I_NEW set, the | 667 | /* Return the locked inode with I_NEW set, the |
668 | * caller is responsible for filling in the contents | 668 | * caller is responsible for filling in the contents |
669 | */ | 669 | */ |
670 | return inode; | 670 | return inode; |
671 | } | 671 | } |
672 | 672 | ||
673 | /* | 673 | /* |
674 | * Uhhuh, somebody else created the same inode under | 674 | * Uhhuh, somebody else created the same inode under |
675 | * us. Use the old inode instead of the one we just | 675 | * us. Use the old inode instead of the one we just |
676 | * allocated. | 676 | * allocated. |
677 | */ | 677 | */ |
678 | __iget(old); | 678 | __iget(old); |
679 | spin_unlock(&inode_lock); | 679 | spin_unlock(&inode_lock); |
680 | destroy_inode(inode); | 680 | destroy_inode(inode); |
681 | inode = old; | 681 | inode = old; |
682 | wait_on_inode(inode); | 682 | wait_on_inode(inode); |
683 | } | 683 | } |
684 | return inode; | 684 | return inode; |
685 | } | 685 | } |
686 | 686 | ||
687 | static inline unsigned long hash(struct super_block *sb, unsigned long hashval) | 687 | static inline unsigned long hash(struct super_block *sb, unsigned long hashval) |
688 | { | 688 | { |
689 | unsigned long tmp; | 689 | unsigned long tmp; |
690 | 690 | ||
691 | tmp = (hashval * (unsigned long)sb) ^ (GOLDEN_RATIO_PRIME + hashval) / | 691 | tmp = (hashval * (unsigned long)sb) ^ (GOLDEN_RATIO_PRIME + hashval) / |
692 | L1_CACHE_BYTES; | 692 | L1_CACHE_BYTES; |
693 | tmp = tmp ^ ((tmp ^ GOLDEN_RATIO_PRIME) >> I_HASHBITS); | 693 | tmp = tmp ^ ((tmp ^ GOLDEN_RATIO_PRIME) >> I_HASHBITS); |
694 | return tmp & I_HASHMASK; | 694 | return tmp & I_HASHMASK; |
695 | } | 695 | } |
696 | 696 | ||
697 | /** | 697 | /** |
698 | * iunique - get a unique inode number | 698 | * iunique - get a unique inode number |
699 | * @sb: superblock | 699 | * @sb: superblock |
700 | * @max_reserved: highest reserved inode number | 700 | * @max_reserved: highest reserved inode number |
701 | * | 701 | * |
702 | * Obtain an inode number that is unique on the system for a given | 702 | * Obtain an inode number that is unique on the system for a given |
703 | * superblock. This is used by file systems that have no natural | 703 | * superblock. This is used by file systems that have no natural |
704 | * permanent inode numbering system. An inode number is returned that | 704 | * permanent inode numbering system. An inode number is returned that |
705 | * is higher than the reserved limit but unique. | 705 | * is higher than the reserved limit but unique. |
706 | * | 706 | * |
707 | * BUGS: | 707 | * BUGS: |
708 | * With a large number of inodes live on the file system this function | 708 | * With a large number of inodes live on the file system this function |
709 | * currently becomes quite slow. | 709 | * currently becomes quite slow. |
710 | */ | 710 | */ |
711 | ino_t iunique(struct super_block *sb, ino_t max_reserved) | 711 | ino_t iunique(struct super_block *sb, ino_t max_reserved) |
712 | { | 712 | { |
713 | static ino_t counter; | 713 | static ino_t counter; |
714 | struct inode *inode; | 714 | struct inode *inode; |
715 | struct hlist_head * head; | 715 | struct hlist_head * head; |
716 | ino_t res; | 716 | ino_t res; |
717 | spin_lock(&inode_lock); | 717 | spin_lock(&inode_lock); |
718 | retry: | 718 | retry: |
719 | if (counter > max_reserved) { | 719 | if (counter > max_reserved) { |
720 | head = inode_hashtable + hash(sb,counter); | 720 | head = inode_hashtable + hash(sb,counter); |
721 | res = counter++; | 721 | res = counter++; |
722 | inode = find_inode_fast(sb, head, res); | 722 | inode = find_inode_fast(sb, head, res); |
723 | if (!inode) { | 723 | if (!inode) { |
724 | spin_unlock(&inode_lock); | 724 | spin_unlock(&inode_lock); |
725 | return res; | 725 | return res; |
726 | } | 726 | } |
727 | } else { | 727 | } else { |
728 | counter = max_reserved + 1; | 728 | counter = max_reserved + 1; |
729 | } | 729 | } |
730 | goto retry; | 730 | goto retry; |
731 | 731 | ||
732 | } | 732 | } |
733 | 733 | ||
734 | EXPORT_SYMBOL(iunique); | 734 | EXPORT_SYMBOL(iunique); |
735 | 735 | ||
736 | struct inode *igrab(struct inode *inode) | 736 | struct inode *igrab(struct inode *inode) |
737 | { | 737 | { |
738 | spin_lock(&inode_lock); | 738 | spin_lock(&inode_lock); |
739 | if (!(inode->i_state & (I_FREEING|I_WILL_FREE))) | 739 | if (!(inode->i_state & (I_FREEING|I_WILL_FREE))) |
740 | __iget(inode); | 740 | __iget(inode); |
741 | else | 741 | else |
742 | /* | 742 | /* |
743 | * Handle the case where s_op->clear_inode is not been | 743 | * Handle the case where s_op->clear_inode is not been |
744 | * called yet, and somebody is calling igrab | 744 | * called yet, and somebody is calling igrab |
745 | * while the inode is getting freed. | 745 | * while the inode is getting freed. |
746 | */ | 746 | */ |
747 | inode = NULL; | 747 | inode = NULL; |
748 | spin_unlock(&inode_lock); | 748 | spin_unlock(&inode_lock); |
749 | return inode; | 749 | return inode; |
750 | } | 750 | } |
751 | 751 | ||
752 | EXPORT_SYMBOL(igrab); | 752 | EXPORT_SYMBOL(igrab); |
753 | 753 | ||
754 | /** | 754 | /** |
755 | * ifind - internal function, you want ilookup5() or iget5(). | 755 | * ifind - internal function, you want ilookup5() or iget5(). |
756 | * @sb: super block of file system to search | 756 | * @sb: super block of file system to search |
757 | * @head: the head of the list to search | 757 | * @head: the head of the list to search |
758 | * @test: callback used for comparisons between inodes | 758 | * @test: callback used for comparisons between inodes |
759 | * @data: opaque data pointer to pass to @test | 759 | * @data: opaque data pointer to pass to @test |
760 | * @wait: if true wait for the inode to be unlocked, if false do not | 760 | * @wait: if true wait for the inode to be unlocked, if false do not |
761 | * | 761 | * |
762 | * ifind() searches for the inode specified by @data in the inode | 762 | * ifind() searches for the inode specified by @data in the inode |
763 | * cache. This is a generalized version of ifind_fast() for file systems where | 763 | * cache. This is a generalized version of ifind_fast() for file systems where |
764 | * the inode number is not sufficient for unique identification of an inode. | 764 | * the inode number is not sufficient for unique identification of an inode. |
765 | * | 765 | * |
766 | * If the inode is in the cache, the inode is returned with an incremented | 766 | * If the inode is in the cache, the inode is returned with an incremented |
767 | * reference count. | 767 | * reference count. |
768 | * | 768 | * |
769 | * Otherwise NULL is returned. | 769 | * Otherwise NULL is returned. |
770 | * | 770 | * |
771 | * Note, @test is called with the inode_lock held, so can't sleep. | 771 | * Note, @test is called with the inode_lock held, so can't sleep. |
772 | */ | 772 | */ |
773 | static struct inode *ifind(struct super_block *sb, | 773 | static struct inode *ifind(struct super_block *sb, |
774 | struct hlist_head *head, int (*test)(struct inode *, void *), | 774 | struct hlist_head *head, int (*test)(struct inode *, void *), |
775 | void *data, const int wait) | 775 | void *data, const int wait) |
776 | { | 776 | { |
777 | struct inode *inode; | 777 | struct inode *inode; |
778 | 778 | ||
779 | spin_lock(&inode_lock); | 779 | spin_lock(&inode_lock); |
780 | inode = find_inode(sb, head, test, data); | 780 | inode = find_inode(sb, head, test, data); |
781 | if (inode) { | 781 | if (inode) { |
782 | __iget(inode); | 782 | __iget(inode); |
783 | spin_unlock(&inode_lock); | 783 | spin_unlock(&inode_lock); |
784 | if (likely(wait)) | 784 | if (likely(wait)) |
785 | wait_on_inode(inode); | 785 | wait_on_inode(inode); |
786 | return inode; | 786 | return inode; |
787 | } | 787 | } |
788 | spin_unlock(&inode_lock); | 788 | spin_unlock(&inode_lock); |
789 | return NULL; | 789 | return NULL; |
790 | } | 790 | } |
791 | 791 | ||
792 | /** | 792 | /** |
793 | * ifind_fast - internal function, you want ilookup() or iget(). | 793 | * ifind_fast - internal function, you want ilookup() or iget(). |
794 | * @sb: super block of file system to search | 794 | * @sb: super block of file system to search |
795 | * @head: head of the list to search | 795 | * @head: head of the list to search |
796 | * @ino: inode number to search for | 796 | * @ino: inode number to search for |
797 | * | 797 | * |
798 | * ifind_fast() searches for the inode @ino in the inode cache. This is for | 798 | * ifind_fast() searches for the inode @ino in the inode cache. This is for |
799 | * file systems where the inode number is sufficient for unique identification | 799 | * file systems where the inode number is sufficient for unique identification |
800 | * of an inode. | 800 | * of an inode. |
801 | * | 801 | * |
802 | * If the inode is in the cache, the inode is returned with an incremented | 802 | * If the inode is in the cache, the inode is returned with an incremented |
803 | * reference count. | 803 | * reference count. |
804 | * | 804 | * |
805 | * Otherwise NULL is returned. | 805 | * Otherwise NULL is returned. |
806 | */ | 806 | */ |
807 | static struct inode *ifind_fast(struct super_block *sb, | 807 | static struct inode *ifind_fast(struct super_block *sb, |
808 | struct hlist_head *head, unsigned long ino) | 808 | struct hlist_head *head, unsigned long ino) |
809 | { | 809 | { |
810 | struct inode *inode; | 810 | struct inode *inode; |
811 | 811 | ||
812 | spin_lock(&inode_lock); | 812 | spin_lock(&inode_lock); |
813 | inode = find_inode_fast(sb, head, ino); | 813 | inode = find_inode_fast(sb, head, ino); |
814 | if (inode) { | 814 | if (inode) { |
815 | __iget(inode); | 815 | __iget(inode); |
816 | spin_unlock(&inode_lock); | 816 | spin_unlock(&inode_lock); |
817 | wait_on_inode(inode); | 817 | wait_on_inode(inode); |
818 | return inode; | 818 | return inode; |
819 | } | 819 | } |
820 | spin_unlock(&inode_lock); | 820 | spin_unlock(&inode_lock); |
821 | return NULL; | 821 | return NULL; |
822 | } | 822 | } |
823 | 823 | ||
824 | /** | 824 | /** |
825 | * ilookup5_nowait - search for an inode in the inode cache | 825 | * ilookup5_nowait - search for an inode in the inode cache |
826 | * @sb: super block of file system to search | 826 | * @sb: super block of file system to search |
827 | * @hashval: hash value (usually inode number) to search for | 827 | * @hashval: hash value (usually inode number) to search for |
828 | * @test: callback used for comparisons between inodes | 828 | * @test: callback used for comparisons between inodes |
829 | * @data: opaque data pointer to pass to @test | 829 | * @data: opaque data pointer to pass to @test |
830 | * | 830 | * |
831 | * ilookup5() uses ifind() to search for the inode specified by @hashval and | 831 | * ilookup5() uses ifind() to search for the inode specified by @hashval and |
832 | * @data in the inode cache. This is a generalized version of ilookup() for | 832 | * @data in the inode cache. This is a generalized version of ilookup() for |
833 | * file systems where the inode number is not sufficient for unique | 833 | * file systems where the inode number is not sufficient for unique |
834 | * identification of an inode. | 834 | * identification of an inode. |
835 | * | 835 | * |
836 | * If the inode is in the cache, the inode is returned with an incremented | 836 | * If the inode is in the cache, the inode is returned with an incremented |
837 | * reference count. Note, the inode lock is not waited upon so you have to be | 837 | * reference count. Note, the inode lock is not waited upon so you have to be |
838 | * very careful what you do with the returned inode. You probably should be | 838 | * very careful what you do with the returned inode. You probably should be |
839 | * using ilookup5() instead. | 839 | * using ilookup5() instead. |
840 | * | 840 | * |
841 | * Otherwise NULL is returned. | 841 | * Otherwise NULL is returned. |
842 | * | 842 | * |
843 | * Note, @test is called with the inode_lock held, so can't sleep. | 843 | * Note, @test is called with the inode_lock held, so can't sleep. |
844 | */ | 844 | */ |
845 | struct inode *ilookup5_nowait(struct super_block *sb, unsigned long hashval, | 845 | struct inode *ilookup5_nowait(struct super_block *sb, unsigned long hashval, |
846 | int (*test)(struct inode *, void *), void *data) | 846 | int (*test)(struct inode *, void *), void *data) |
847 | { | 847 | { |
848 | struct hlist_head *head = inode_hashtable + hash(sb, hashval); | 848 | struct hlist_head *head = inode_hashtable + hash(sb, hashval); |
849 | 849 | ||
850 | return ifind(sb, head, test, data, 0); | 850 | return ifind(sb, head, test, data, 0); |
851 | } | 851 | } |
852 | 852 | ||
853 | EXPORT_SYMBOL(ilookup5_nowait); | 853 | EXPORT_SYMBOL(ilookup5_nowait); |
854 | 854 | ||
855 | /** | 855 | /** |
856 | * ilookup5 - search for an inode in the inode cache | 856 | * ilookup5 - search for an inode in the inode cache |
857 | * @sb: super block of file system to search | 857 | * @sb: super block of file system to search |
858 | * @hashval: hash value (usually inode number) to search for | 858 | * @hashval: hash value (usually inode number) to search for |
859 | * @test: callback used for comparisons between inodes | 859 | * @test: callback used for comparisons between inodes |
860 | * @data: opaque data pointer to pass to @test | 860 | * @data: opaque data pointer to pass to @test |
861 | * | 861 | * |
862 | * ilookup5() uses ifind() to search for the inode specified by @hashval and | 862 | * ilookup5() uses ifind() to search for the inode specified by @hashval and |
863 | * @data in the inode cache. This is a generalized version of ilookup() for | 863 | * @data in the inode cache. This is a generalized version of ilookup() for |
864 | * file systems where the inode number is not sufficient for unique | 864 | * file systems where the inode number is not sufficient for unique |
865 | * identification of an inode. | 865 | * identification of an inode. |
866 | * | 866 | * |
867 | * If the inode is in the cache, the inode lock is waited upon and the inode is | 867 | * If the inode is in the cache, the inode lock is waited upon and the inode is |
868 | * returned with an incremented reference count. | 868 | * returned with an incremented reference count. |
869 | * | 869 | * |
870 | * Otherwise NULL is returned. | 870 | * Otherwise NULL is returned. |
871 | * | 871 | * |
872 | * Note, @test is called with the inode_lock held, so can't sleep. | 872 | * Note, @test is called with the inode_lock held, so can't sleep. |
873 | */ | 873 | */ |
874 | struct inode *ilookup5(struct super_block *sb, unsigned long hashval, | 874 | struct inode *ilookup5(struct super_block *sb, unsigned long hashval, |
875 | int (*test)(struct inode *, void *), void *data) | 875 | int (*test)(struct inode *, void *), void *data) |
876 | { | 876 | { |
877 | struct hlist_head *head = inode_hashtable + hash(sb, hashval); | 877 | struct hlist_head *head = inode_hashtable + hash(sb, hashval); |
878 | 878 | ||
879 | return ifind(sb, head, test, data, 1); | 879 | return ifind(sb, head, test, data, 1); |
880 | } | 880 | } |
881 | 881 | ||
882 | EXPORT_SYMBOL(ilookup5); | 882 | EXPORT_SYMBOL(ilookup5); |
883 | 883 | ||
884 | /** | 884 | /** |
885 | * ilookup - search for an inode in the inode cache | 885 | * ilookup - search for an inode in the inode cache |
886 | * @sb: super block of file system to search | 886 | * @sb: super block of file system to search |
887 | * @ino: inode number to search for | 887 | * @ino: inode number to search for |
888 | * | 888 | * |
889 | * ilookup() uses ifind_fast() to search for the inode @ino in the inode cache. | 889 | * ilookup() uses ifind_fast() to search for the inode @ino in the inode cache. |
890 | * This is for file systems where the inode number is sufficient for unique | 890 | * This is for file systems where the inode number is sufficient for unique |
891 | * identification of an inode. | 891 | * identification of an inode. |
892 | * | 892 | * |
893 | * If the inode is in the cache, the inode is returned with an incremented | 893 | * If the inode is in the cache, the inode is returned with an incremented |
894 | * reference count. | 894 | * reference count. |
895 | * | 895 | * |
896 | * Otherwise NULL is returned. | 896 | * Otherwise NULL is returned. |
897 | */ | 897 | */ |
898 | struct inode *ilookup(struct super_block *sb, unsigned long ino) | 898 | struct inode *ilookup(struct super_block *sb, unsigned long ino) |
899 | { | 899 | { |
900 | struct hlist_head *head = inode_hashtable + hash(sb, ino); | 900 | struct hlist_head *head = inode_hashtable + hash(sb, ino); |
901 | 901 | ||
902 | return ifind_fast(sb, head, ino); | 902 | return ifind_fast(sb, head, ino); |
903 | } | 903 | } |
904 | 904 | ||
905 | EXPORT_SYMBOL(ilookup); | 905 | EXPORT_SYMBOL(ilookup); |
906 | 906 | ||
907 | /** | 907 | /** |
908 | * iget5_locked - obtain an inode from a mounted file system | 908 | * iget5_locked - obtain an inode from a mounted file system |
909 | * @sb: super block of file system | 909 | * @sb: super block of file system |
910 | * @hashval: hash value (usually inode number) to get | 910 | * @hashval: hash value (usually inode number) to get |
911 | * @test: callback used for comparisons between inodes | 911 | * @test: callback used for comparisons between inodes |
912 | * @set: callback used to initialize a new struct inode | 912 | * @set: callback used to initialize a new struct inode |
913 | * @data: opaque data pointer to pass to @test and @set | 913 | * @data: opaque data pointer to pass to @test and @set |
914 | * | 914 | * |
915 | * This is iget() without the read_inode() portion of get_new_inode(). | 915 | * This is iget() without the read_inode() portion of get_new_inode(). |
916 | * | 916 | * |
917 | * iget5_locked() uses ifind() to search for the inode specified by @hashval | 917 | * iget5_locked() uses ifind() to search for the inode specified by @hashval |
918 | * and @data in the inode cache and if present it is returned with an increased | 918 | * and @data in the inode cache and if present it is returned with an increased |
919 | * reference count. This is a generalized version of iget_locked() for file | 919 | * reference count. This is a generalized version of iget_locked() for file |
920 | * systems where the inode number is not sufficient for unique identification | 920 | * systems where the inode number is not sufficient for unique identification |
921 | * of an inode. | 921 | * of an inode. |
922 | * | 922 | * |
923 | * If the inode is not in cache, get_new_inode() is called to allocate a new | 923 | * If the inode is not in cache, get_new_inode() is called to allocate a new |
924 | * inode and this is returned locked, hashed, and with the I_NEW flag set. The | 924 | * inode and this is returned locked, hashed, and with the I_NEW flag set. The |
925 | * file system gets to fill it in before unlocking it via unlock_new_inode(). | 925 | * file system gets to fill it in before unlocking it via unlock_new_inode(). |
926 | * | 926 | * |
927 | * Note both @test and @set are called with the inode_lock held, so can't sleep. | 927 | * Note both @test and @set are called with the inode_lock held, so can't sleep. |
928 | */ | 928 | */ |
929 | struct inode *iget5_locked(struct super_block *sb, unsigned long hashval, | 929 | struct inode *iget5_locked(struct super_block *sb, unsigned long hashval, |
930 | int (*test)(struct inode *, void *), | 930 | int (*test)(struct inode *, void *), |
931 | int (*set)(struct inode *, void *), void *data) | 931 | int (*set)(struct inode *, void *), void *data) |
932 | { | 932 | { |
933 | struct hlist_head *head = inode_hashtable + hash(sb, hashval); | 933 | struct hlist_head *head = inode_hashtable + hash(sb, hashval); |
934 | struct inode *inode; | 934 | struct inode *inode; |
935 | 935 | ||
936 | inode = ifind(sb, head, test, data, 1); | 936 | inode = ifind(sb, head, test, data, 1); |
937 | if (inode) | 937 | if (inode) |
938 | return inode; | 938 | return inode; |
939 | /* | 939 | /* |
940 | * get_new_inode() will do the right thing, re-trying the search | 940 | * get_new_inode() will do the right thing, re-trying the search |
941 | * in case it had to block at any point. | 941 | * in case it had to block at any point. |
942 | */ | 942 | */ |
943 | return get_new_inode(sb, head, test, set, data); | 943 | return get_new_inode(sb, head, test, set, data); |
944 | } | 944 | } |
945 | 945 | ||
946 | EXPORT_SYMBOL(iget5_locked); | 946 | EXPORT_SYMBOL(iget5_locked); |
947 | 947 | ||
948 | /** | 948 | /** |
949 | * iget_locked - obtain an inode from a mounted file system | 949 | * iget_locked - obtain an inode from a mounted file system |
950 | * @sb: super block of file system | 950 | * @sb: super block of file system |
951 | * @ino: inode number to get | 951 | * @ino: inode number to get |
952 | * | 952 | * |
953 | * This is iget() without the read_inode() portion of get_new_inode_fast(). | 953 | * This is iget() without the read_inode() portion of get_new_inode_fast(). |
954 | * | 954 | * |
955 | * iget_locked() uses ifind_fast() to search for the inode specified by @ino in | 955 | * iget_locked() uses ifind_fast() to search for the inode specified by @ino in |
956 | * the inode cache and if present it is returned with an increased reference | 956 | * the inode cache and if present it is returned with an increased reference |
957 | * count. This is for file systems where the inode number is sufficient for | 957 | * count. This is for file systems where the inode number is sufficient for |
958 | * unique identification of an inode. | 958 | * unique identification of an inode. |
959 | * | 959 | * |
960 | * If the inode is not in cache, get_new_inode_fast() is called to allocate a | 960 | * If the inode is not in cache, get_new_inode_fast() is called to allocate a |
961 | * new inode and this is returned locked, hashed, and with the I_NEW flag set. | 961 | * new inode and this is returned locked, hashed, and with the I_NEW flag set. |
962 | * The file system gets to fill it in before unlocking it via | 962 | * The file system gets to fill it in before unlocking it via |
963 | * unlock_new_inode(). | 963 | * unlock_new_inode(). |
964 | */ | 964 | */ |
965 | struct inode *iget_locked(struct super_block *sb, unsigned long ino) | 965 | struct inode *iget_locked(struct super_block *sb, unsigned long ino) |
966 | { | 966 | { |
967 | struct hlist_head *head = inode_hashtable + hash(sb, ino); | 967 | struct hlist_head *head = inode_hashtable + hash(sb, ino); |
968 | struct inode *inode; | 968 | struct inode *inode; |
969 | 969 | ||
970 | inode = ifind_fast(sb, head, ino); | 970 | inode = ifind_fast(sb, head, ino); |
971 | if (inode) | 971 | if (inode) |
972 | return inode; | 972 | return inode; |
973 | /* | 973 | /* |
974 | * get_new_inode_fast() will do the right thing, re-trying the search | 974 | * get_new_inode_fast() will do the right thing, re-trying the search |
975 | * in case it had to block at any point. | 975 | * in case it had to block at any point. |
976 | */ | 976 | */ |
977 | return get_new_inode_fast(sb, head, ino); | 977 | return get_new_inode_fast(sb, head, ino); |
978 | } | 978 | } |
979 | 979 | ||
980 | EXPORT_SYMBOL(iget_locked); | 980 | EXPORT_SYMBOL(iget_locked); |
981 | 981 | ||
982 | /** | 982 | /** |
983 | * __insert_inode_hash - hash an inode | 983 | * __insert_inode_hash - hash an inode |
984 | * @inode: unhashed inode | 984 | * @inode: unhashed inode |
985 | * @hashval: unsigned long value used to locate this object in the | 985 | * @hashval: unsigned long value used to locate this object in the |
986 | * inode_hashtable. | 986 | * inode_hashtable. |
987 | * | 987 | * |
988 | * Add an inode to the inode hash for this superblock. | 988 | * Add an inode to the inode hash for this superblock. |
989 | */ | 989 | */ |
990 | void __insert_inode_hash(struct inode *inode, unsigned long hashval) | 990 | void __insert_inode_hash(struct inode *inode, unsigned long hashval) |
991 | { | 991 | { |
992 | struct hlist_head *head = inode_hashtable + hash(inode->i_sb, hashval); | 992 | struct hlist_head *head = inode_hashtable + hash(inode->i_sb, hashval); |
993 | spin_lock(&inode_lock); | 993 | spin_lock(&inode_lock); |
994 | hlist_add_head(&inode->i_hash, head); | 994 | hlist_add_head(&inode->i_hash, head); |
995 | spin_unlock(&inode_lock); | 995 | spin_unlock(&inode_lock); |
996 | } | 996 | } |
997 | 997 | ||
998 | EXPORT_SYMBOL(__insert_inode_hash); | 998 | EXPORT_SYMBOL(__insert_inode_hash); |
999 | 999 | ||
1000 | /** | 1000 | /** |
1001 | * remove_inode_hash - remove an inode from the hash | 1001 | * remove_inode_hash - remove an inode from the hash |
1002 | * @inode: inode to unhash | 1002 | * @inode: inode to unhash |
1003 | * | 1003 | * |
1004 | * Remove an inode from the superblock. | 1004 | * Remove an inode from the superblock. |
1005 | */ | 1005 | */ |
1006 | void remove_inode_hash(struct inode *inode) | 1006 | void remove_inode_hash(struct inode *inode) |
1007 | { | 1007 | { |
1008 | spin_lock(&inode_lock); | 1008 | spin_lock(&inode_lock); |
1009 | hlist_del_init(&inode->i_hash); | 1009 | hlist_del_init(&inode->i_hash); |
1010 | spin_unlock(&inode_lock); | 1010 | spin_unlock(&inode_lock); |
1011 | } | 1011 | } |
1012 | 1012 | ||
1013 | EXPORT_SYMBOL(remove_inode_hash); | 1013 | EXPORT_SYMBOL(remove_inode_hash); |
1014 | 1014 | ||
1015 | /* | 1015 | /* |
1016 | * Tell the filesystem that this inode is no longer of any interest and should | 1016 | * Tell the filesystem that this inode is no longer of any interest and should |
1017 | * be completely destroyed. | 1017 | * be completely destroyed. |
1018 | * | 1018 | * |
1019 | * We leave the inode in the inode hash table until *after* the filesystem's | 1019 | * We leave the inode in the inode hash table until *after* the filesystem's |
1020 | * ->delete_inode completes. This ensures that an iget (such as nfsd might | 1020 | * ->delete_inode completes. This ensures that an iget (such as nfsd might |
1021 | * instigate) will always find up-to-date information either in the hash or on | 1021 | * instigate) will always find up-to-date information either in the hash or on |
1022 | * disk. | 1022 | * disk. |
1023 | * | 1023 | * |
1024 | * I_FREEING is set so that no-one will take a new reference to the inode while | 1024 | * I_FREEING is set so that no-one will take a new reference to the inode while |
1025 | * it is being deleted. | 1025 | * it is being deleted. |
1026 | */ | 1026 | */ |
1027 | void generic_delete_inode(struct inode *inode) | 1027 | void generic_delete_inode(struct inode *inode) |
1028 | { | 1028 | { |
1029 | struct super_operations *op = inode->i_sb->s_op; | 1029 | struct super_operations *op = inode->i_sb->s_op; |
1030 | 1030 | ||
1031 | list_del_init(&inode->i_list); | 1031 | list_del_init(&inode->i_list); |
1032 | list_del_init(&inode->i_sb_list); | 1032 | list_del_init(&inode->i_sb_list); |
1033 | inode->i_state|=I_FREEING; | 1033 | inode->i_state|=I_FREEING; |
1034 | inodes_stat.nr_inodes--; | 1034 | inodes_stat.nr_inodes--; |
1035 | spin_unlock(&inode_lock); | 1035 | spin_unlock(&inode_lock); |
1036 | 1036 | ||
1037 | security_inode_delete(inode); | 1037 | security_inode_delete(inode); |
1038 | 1038 | ||
1039 | if (op->delete_inode) { | 1039 | if (op->delete_inode) { |
1040 | void (*delete)(struct inode *) = op->delete_inode; | 1040 | void (*delete)(struct inode *) = op->delete_inode; |
1041 | if (!is_bad_inode(inode)) | 1041 | if (!is_bad_inode(inode)) |
1042 | DQUOT_INIT(inode); | 1042 | DQUOT_INIT(inode); |
1043 | /* Filesystems implementing their own | 1043 | /* Filesystems implementing their own |
1044 | * s_op->delete_inode are required to call | 1044 | * s_op->delete_inode are required to call |
1045 | * truncate_inode_pages and clear_inode() | 1045 | * truncate_inode_pages and clear_inode() |
1046 | * internally */ | 1046 | * internally */ |
1047 | delete(inode); | 1047 | delete(inode); |
1048 | } else { | 1048 | } else { |
1049 | truncate_inode_pages(&inode->i_data, 0); | 1049 | truncate_inode_pages(&inode->i_data, 0); |
1050 | clear_inode(inode); | 1050 | clear_inode(inode); |
1051 | } | 1051 | } |
1052 | spin_lock(&inode_lock); | 1052 | spin_lock(&inode_lock); |
1053 | hlist_del_init(&inode->i_hash); | 1053 | hlist_del_init(&inode->i_hash); |
1054 | spin_unlock(&inode_lock); | 1054 | spin_unlock(&inode_lock); |
1055 | wake_up_inode(inode); | 1055 | wake_up_inode(inode); |
1056 | if (inode->i_state != I_CLEAR) | 1056 | if (inode->i_state != I_CLEAR) |
1057 | BUG(); | 1057 | BUG(); |
1058 | destroy_inode(inode); | 1058 | destroy_inode(inode); |
1059 | } | 1059 | } |
1060 | 1060 | ||
1061 | EXPORT_SYMBOL(generic_delete_inode); | 1061 | EXPORT_SYMBOL(generic_delete_inode); |
1062 | 1062 | ||
1063 | static void generic_forget_inode(struct inode *inode) | 1063 | static void generic_forget_inode(struct inode *inode) |
1064 | { | 1064 | { |
1065 | struct super_block *sb = inode->i_sb; | 1065 | struct super_block *sb = inode->i_sb; |
1066 | 1066 | ||
1067 | if (!hlist_unhashed(&inode->i_hash)) { | 1067 | if (!hlist_unhashed(&inode->i_hash)) { |
1068 | if (!(inode->i_state & (I_DIRTY|I_LOCK))) | 1068 | if (!(inode->i_state & (I_DIRTY|I_LOCK))) |
1069 | list_move(&inode->i_list, &inode_unused); | 1069 | list_move(&inode->i_list, &inode_unused); |
1070 | inodes_stat.nr_unused++; | 1070 | inodes_stat.nr_unused++; |
1071 | if (!sb || (sb->s_flags & MS_ACTIVE)) { | 1071 | if (!sb || (sb->s_flags & MS_ACTIVE)) { |
1072 | spin_unlock(&inode_lock); | 1072 | spin_unlock(&inode_lock); |
1073 | return; | 1073 | return; |
1074 | } | 1074 | } |
1075 | inode->i_state |= I_WILL_FREE; | 1075 | inode->i_state |= I_WILL_FREE; |
1076 | spin_unlock(&inode_lock); | 1076 | spin_unlock(&inode_lock); |
1077 | write_inode_now(inode, 1); | 1077 | write_inode_now(inode, 1); |
1078 | spin_lock(&inode_lock); | 1078 | spin_lock(&inode_lock); |
1079 | inode->i_state &= ~I_WILL_FREE; | 1079 | inode->i_state &= ~I_WILL_FREE; |
1080 | inodes_stat.nr_unused--; | 1080 | inodes_stat.nr_unused--; |
1081 | hlist_del_init(&inode->i_hash); | 1081 | hlist_del_init(&inode->i_hash); |
1082 | } | 1082 | } |
1083 | list_del_init(&inode->i_list); | 1083 | list_del_init(&inode->i_list); |
1084 | list_del_init(&inode->i_sb_list); | 1084 | list_del_init(&inode->i_sb_list); |
1085 | inode->i_state |= I_FREEING; | 1085 | inode->i_state |= I_FREEING; |
1086 | inodes_stat.nr_inodes--; | 1086 | inodes_stat.nr_inodes--; |
1087 | spin_unlock(&inode_lock); | 1087 | spin_unlock(&inode_lock); |
1088 | if (inode->i_data.nrpages) | 1088 | if (inode->i_data.nrpages) |
1089 | truncate_inode_pages(&inode->i_data, 0); | 1089 | truncate_inode_pages(&inode->i_data, 0); |
1090 | clear_inode(inode); | 1090 | clear_inode(inode); |
1091 | wake_up_inode(inode); | 1091 | wake_up_inode(inode); |
1092 | destroy_inode(inode); | 1092 | destroy_inode(inode); |
1093 | } | 1093 | } |
1094 | 1094 | ||
1095 | /* | 1095 | /* |
1096 | * Normal UNIX filesystem behaviour: delete the | 1096 | * Normal UNIX filesystem behaviour: delete the |
1097 | * inode when the usage count drops to zero, and | 1097 | * inode when the usage count drops to zero, and |
1098 | * i_nlink is zero. | 1098 | * i_nlink is zero. |
1099 | */ | 1099 | */ |
1100 | void generic_drop_inode(struct inode *inode) | 1100 | void generic_drop_inode(struct inode *inode) |
1101 | { | 1101 | { |
1102 | if (!inode->i_nlink) | 1102 | if (!inode->i_nlink) |
1103 | generic_delete_inode(inode); | 1103 | generic_delete_inode(inode); |
1104 | else | 1104 | else |
1105 | generic_forget_inode(inode); | 1105 | generic_forget_inode(inode); |
1106 | } | 1106 | } |
1107 | 1107 | ||
1108 | EXPORT_SYMBOL_GPL(generic_drop_inode); | 1108 | EXPORT_SYMBOL_GPL(generic_drop_inode); |
1109 | 1109 | ||
1110 | /* | 1110 | /* |
1111 | * Called when we're dropping the last reference | 1111 | * Called when we're dropping the last reference |
1112 | * to an inode. | 1112 | * to an inode. |
1113 | * | 1113 | * |
1114 | * Call the FS "drop()" function, defaulting to | 1114 | * Call the FS "drop()" function, defaulting to |
1115 | * the legacy UNIX filesystem behaviour.. | 1115 | * the legacy UNIX filesystem behaviour.. |
1116 | * | 1116 | * |
1117 | * NOTE! NOTE! NOTE! We're called with the inode lock | 1117 | * NOTE! NOTE! NOTE! We're called with the inode lock |
1118 | * held, and the drop function is supposed to release | 1118 | * held, and the drop function is supposed to release |
1119 | * the lock! | 1119 | * the lock! |
1120 | */ | 1120 | */ |
1121 | static inline void iput_final(struct inode *inode) | 1121 | static inline void iput_final(struct inode *inode) |
1122 | { | 1122 | { |
1123 | struct super_operations *op = inode->i_sb->s_op; | 1123 | struct super_operations *op = inode->i_sb->s_op; |
1124 | void (*drop)(struct inode *) = generic_drop_inode; | 1124 | void (*drop)(struct inode *) = generic_drop_inode; |
1125 | 1125 | ||
1126 | if (op && op->drop_inode) | 1126 | if (op && op->drop_inode) |
1127 | drop = op->drop_inode; | 1127 | drop = op->drop_inode; |
1128 | drop(inode); | 1128 | drop(inode); |
1129 | } | 1129 | } |
1130 | 1130 | ||
1131 | /** | 1131 | /** |
1132 | * iput - put an inode | 1132 | * iput - put an inode |
1133 | * @inode: inode to put | 1133 | * @inode: inode to put |
1134 | * | 1134 | * |
1135 | * Puts an inode, dropping its usage count. If the inode use count hits | 1135 | * Puts an inode, dropping its usage count. If the inode use count hits |
1136 | * zero, the inode is then freed and may also be destroyed. | 1136 | * zero, the inode is then freed and may also be destroyed. |
1137 | * | 1137 | * |
1138 | * Consequently, iput() can sleep. | 1138 | * Consequently, iput() can sleep. |
1139 | */ | 1139 | */ |
1140 | void iput(struct inode *inode) | 1140 | void iput(struct inode *inode) |
1141 | { | 1141 | { |
1142 | if (inode) { | 1142 | if (inode) { |
1143 | struct super_operations *op = inode->i_sb->s_op; | 1143 | struct super_operations *op = inode->i_sb->s_op; |
1144 | 1144 | ||
1145 | BUG_ON(inode->i_state == I_CLEAR); | 1145 | BUG_ON(inode->i_state == I_CLEAR); |
1146 | 1146 | ||
1147 | if (op && op->put_inode) | 1147 | if (op && op->put_inode) |
1148 | op->put_inode(inode); | 1148 | op->put_inode(inode); |
1149 | 1149 | ||
1150 | if (atomic_dec_and_lock(&inode->i_count, &inode_lock)) | 1150 | if (atomic_dec_and_lock(&inode->i_count, &inode_lock)) |
1151 | iput_final(inode); | 1151 | iput_final(inode); |
1152 | } | 1152 | } |
1153 | } | 1153 | } |
1154 | 1154 | ||
1155 | EXPORT_SYMBOL(iput); | 1155 | EXPORT_SYMBOL(iput); |
1156 | 1156 | ||
1157 | /** | 1157 | /** |
1158 | * bmap - find a block number in a file | 1158 | * bmap - find a block number in a file |
1159 | * @inode: inode of file | 1159 | * @inode: inode of file |
1160 | * @block: block to find | 1160 | * @block: block to find |
1161 | * | 1161 | * |
1162 | * Returns the block number on the device holding the inode that | 1162 | * Returns the block number on the device holding the inode that |
1163 | * is the disk block number for the block of the file requested. | 1163 | * is the disk block number for the block of the file requested. |
1164 | * That is, asked for block 4 of inode 1 the function will return the | 1164 | * That is, asked for block 4 of inode 1 the function will return the |
1165 | * disk block relative to the disk start that holds that block of the | 1165 | * disk block relative to the disk start that holds that block of the |
1166 | * file. | 1166 | * file. |
1167 | */ | 1167 | */ |
1168 | sector_t bmap(struct inode * inode, sector_t block) | 1168 | sector_t bmap(struct inode * inode, sector_t block) |
1169 | { | 1169 | { |
1170 | sector_t res = 0; | 1170 | sector_t res = 0; |
1171 | if (inode->i_mapping->a_ops->bmap) | 1171 | if (inode->i_mapping->a_ops->bmap) |
1172 | res = inode->i_mapping->a_ops->bmap(inode->i_mapping, block); | 1172 | res = inode->i_mapping->a_ops->bmap(inode->i_mapping, block); |
1173 | return res; | 1173 | return res; |
1174 | } | 1174 | } |
1175 | 1175 | ||
1176 | EXPORT_SYMBOL(bmap); | 1176 | EXPORT_SYMBOL(bmap); |
1177 | 1177 | ||
1178 | /** | 1178 | /** |
1179 | * update_atime - update the access time | 1179 | * touch_atime - update the access time |
1180 | * @mnt: mount the inode is accessed on | ||
1180 | * @inode: inode accessed | 1181 | * @inode: inode accessed |
1181 | * | 1182 | * |
1182 | * Update the accessed time on an inode and mark it for writeback. | 1183 | * Update the accessed time on an inode and mark it for writeback. |
1183 | * This function automatically handles read only file systems and media, | 1184 | * This function automatically handles read only file systems and media, |
1184 | * as well as the "noatime" flag and inode specific "noatime" markers. | 1185 | * as well as the "noatime" flag and inode specific "noatime" markers. |
1185 | */ | 1186 | */ |
1186 | void update_atime(struct inode *inode) | 1187 | void touch_atime(struct vfsmount *mnt, struct dentry *dentry) |
1187 | { | 1188 | { |
1189 | struct inode *inode = dentry->d_inode; | ||
1188 | struct timespec now; | 1190 | struct timespec now; |
1189 | 1191 | ||
1192 | /* per-mountpoint checks will go here */ | ||
1190 | if (IS_NOATIME(inode)) | 1193 | if (IS_NOATIME(inode)) |
1191 | return; | 1194 | return; |
1192 | if (IS_NODIRATIME(inode) && S_ISDIR(inode->i_mode)) | 1195 | if (IS_NODIRATIME(inode) && S_ISDIR(inode->i_mode)) |
1193 | return; | 1196 | return; |
1194 | if (IS_RDONLY(inode)) | 1197 | if (IS_RDONLY(inode)) |
1195 | return; | 1198 | return; |
1196 | 1199 | ||
1197 | now = current_fs_time(inode->i_sb); | 1200 | now = current_fs_time(inode->i_sb); |
1198 | if (!timespec_equal(&inode->i_atime, &now)) { | 1201 | if (!timespec_equal(&inode->i_atime, &now)) { |
1199 | inode->i_atime = now; | 1202 | inode->i_atime = now; |
1200 | mark_inode_dirty_sync(inode); | 1203 | mark_inode_dirty_sync(inode); |
1201 | } | 1204 | } |
1202 | } | 1205 | } |
1203 | 1206 | ||
1204 | EXPORT_SYMBOL(update_atime); | 1207 | EXPORT_SYMBOL(touch_atime); |
1205 | 1208 | ||
1206 | /** | 1209 | /** |
1207 | * file_update_time - update mtime and ctime time | 1210 | * file_update_time - update mtime and ctime time |
1208 | * @file: file accessed | 1211 | * @file: file accessed |
1209 | * | 1212 | * |
1210 | * Update the mtime and ctime members of an inode and mark the inode | 1213 | * Update the mtime and ctime members of an inode and mark the inode |
1211 | * for writeback. Note that this function is meant exclusively for | 1214 | * for writeback. Note that this function is meant exclusively for |
1212 | * usage in the file write path of filesystems, and filesystems may | 1215 | * usage in the file write path of filesystems, and filesystems may |
1213 | * choose to explicitly ignore update via this function with the | 1216 | * choose to explicitly ignore update via this function with the |
1214 | * S_NOCTIME inode flag, e.g. for network filesystem where these | 1217 | * S_NOCTIME inode flag, e.g. for network filesystem where these |
1215 | * timestamps are handled by the server. | 1218 | * timestamps are handled by the server. |
1216 | */ | 1219 | */ |
1217 | 1220 | ||
1218 | void file_update_time(struct file *file) | 1221 | void file_update_time(struct file *file) |
1219 | { | 1222 | { |
1220 | struct inode *inode = file->f_dentry->d_inode; | 1223 | struct inode *inode = file->f_dentry->d_inode; |
1221 | struct timespec now; | 1224 | struct timespec now; |
1222 | int sync_it = 0; | 1225 | int sync_it = 0; |
1223 | 1226 | ||
1224 | if (IS_NOCMTIME(inode)) | 1227 | if (IS_NOCMTIME(inode)) |
1225 | return; | 1228 | return; |
1226 | if (IS_RDONLY(inode)) | 1229 | if (IS_RDONLY(inode)) |
1227 | return; | 1230 | return; |
1228 | 1231 | ||
1229 | now = current_fs_time(inode->i_sb); | 1232 | now = current_fs_time(inode->i_sb); |
1230 | if (!timespec_equal(&inode->i_mtime, &now)) | 1233 | if (!timespec_equal(&inode->i_mtime, &now)) |
1231 | sync_it = 1; | 1234 | sync_it = 1; |
1232 | inode->i_mtime = now; | 1235 | inode->i_mtime = now; |
1233 | 1236 | ||
1234 | if (!timespec_equal(&inode->i_ctime, &now)) | 1237 | if (!timespec_equal(&inode->i_ctime, &now)) |
1235 | sync_it = 1; | 1238 | sync_it = 1; |
1236 | inode->i_ctime = now; | 1239 | inode->i_ctime = now; |
1237 | 1240 | ||
1238 | if (sync_it) | 1241 | if (sync_it) |
1239 | mark_inode_dirty_sync(inode); | 1242 | mark_inode_dirty_sync(inode); |
1240 | } | 1243 | } |
1241 | 1244 | ||
1242 | EXPORT_SYMBOL(file_update_time); | 1245 | EXPORT_SYMBOL(file_update_time); |
1243 | 1246 | ||
1244 | int inode_needs_sync(struct inode *inode) | 1247 | int inode_needs_sync(struct inode *inode) |
1245 | { | 1248 | { |
1246 | if (IS_SYNC(inode)) | 1249 | if (IS_SYNC(inode)) |
1247 | return 1; | 1250 | return 1; |
1248 | if (S_ISDIR(inode->i_mode) && IS_DIRSYNC(inode)) | 1251 | if (S_ISDIR(inode->i_mode) && IS_DIRSYNC(inode)) |
1249 | return 1; | 1252 | return 1; |
1250 | return 0; | 1253 | return 0; |
1251 | } | 1254 | } |
1252 | 1255 | ||
1253 | EXPORT_SYMBOL(inode_needs_sync); | 1256 | EXPORT_SYMBOL(inode_needs_sync); |
1254 | 1257 | ||
1255 | /* | 1258 | /* |
1256 | * Quota functions that want to walk the inode lists.. | 1259 | * Quota functions that want to walk the inode lists.. |
1257 | */ | 1260 | */ |
1258 | #ifdef CONFIG_QUOTA | 1261 | #ifdef CONFIG_QUOTA |
1259 | 1262 | ||
1260 | /* Function back in dquot.c */ | 1263 | /* Function back in dquot.c */ |
1261 | int remove_inode_dquot_ref(struct inode *, int, struct list_head *); | 1264 | int remove_inode_dquot_ref(struct inode *, int, struct list_head *); |
1262 | 1265 | ||
1263 | void remove_dquot_ref(struct super_block *sb, int type, | 1266 | void remove_dquot_ref(struct super_block *sb, int type, |
1264 | struct list_head *tofree_head) | 1267 | struct list_head *tofree_head) |
1265 | { | 1268 | { |
1266 | struct inode *inode; | 1269 | struct inode *inode; |
1267 | 1270 | ||
1268 | if (!sb->dq_op) | 1271 | if (!sb->dq_op) |
1269 | return; /* nothing to do */ | 1272 | return; /* nothing to do */ |
1270 | spin_lock(&inode_lock); /* This lock is for inodes code */ | 1273 | spin_lock(&inode_lock); /* This lock is for inodes code */ |
1271 | 1274 | ||
1272 | /* | 1275 | /* |
1273 | * We don't have to lock against quota code - test IS_QUOTAINIT is | 1276 | * We don't have to lock against quota code - test IS_QUOTAINIT is |
1274 | * just for speedup... | 1277 | * just for speedup... |
1275 | */ | 1278 | */ |
1276 | list_for_each_entry(inode, &sb->s_inodes, i_sb_list) | 1279 | list_for_each_entry(inode, &sb->s_inodes, i_sb_list) |
1277 | if (!IS_NOQUOTA(inode)) | 1280 | if (!IS_NOQUOTA(inode)) |
1278 | remove_inode_dquot_ref(inode, type, tofree_head); | 1281 | remove_inode_dquot_ref(inode, type, tofree_head); |
1279 | 1282 | ||
1280 | spin_unlock(&inode_lock); | 1283 | spin_unlock(&inode_lock); |
1281 | } | 1284 | } |
1282 | 1285 | ||
1283 | #endif | 1286 | #endif |
1284 | 1287 | ||
1285 | int inode_wait(void *word) | 1288 | int inode_wait(void *word) |
1286 | { | 1289 | { |
1287 | schedule(); | 1290 | schedule(); |
1288 | return 0; | 1291 | return 0; |
1289 | } | 1292 | } |
1290 | 1293 | ||
1291 | /* | 1294 | /* |
1292 | * If we try to find an inode in the inode hash while it is being | 1295 | * If we try to find an inode in the inode hash while it is being |
1293 | * deleted, we have to wait until the filesystem completes its | 1296 | * deleted, we have to wait until the filesystem completes its |
1294 | * deletion before reporting that it isn't found. This function waits | 1297 | * deletion before reporting that it isn't found. This function waits |
1295 | * until the deletion _might_ have completed. Callers are responsible | 1298 | * until the deletion _might_ have completed. Callers are responsible |
1296 | * to recheck inode state. | 1299 | * to recheck inode state. |
1297 | * | 1300 | * |
1298 | * It doesn't matter if I_LOCK is not set initially, a call to | 1301 | * It doesn't matter if I_LOCK is not set initially, a call to |
1299 | * wake_up_inode() after removing from the hash list will DTRT. | 1302 | * wake_up_inode() after removing from the hash list will DTRT. |
1300 | * | 1303 | * |
1301 | * This is called with inode_lock held. | 1304 | * This is called with inode_lock held. |
1302 | */ | 1305 | */ |
1303 | static void __wait_on_freeing_inode(struct inode *inode) | 1306 | static void __wait_on_freeing_inode(struct inode *inode) |
1304 | { | 1307 | { |
1305 | wait_queue_head_t *wq; | 1308 | wait_queue_head_t *wq; |
1306 | DEFINE_WAIT_BIT(wait, &inode->i_state, __I_LOCK); | 1309 | DEFINE_WAIT_BIT(wait, &inode->i_state, __I_LOCK); |
1307 | wq = bit_waitqueue(&inode->i_state, __I_LOCK); | 1310 | wq = bit_waitqueue(&inode->i_state, __I_LOCK); |
1308 | prepare_to_wait(wq, &wait.wait, TASK_UNINTERRUPTIBLE); | 1311 | prepare_to_wait(wq, &wait.wait, TASK_UNINTERRUPTIBLE); |
1309 | spin_unlock(&inode_lock); | 1312 | spin_unlock(&inode_lock); |
1310 | schedule(); | 1313 | schedule(); |
1311 | finish_wait(wq, &wait.wait); | 1314 | finish_wait(wq, &wait.wait); |
1312 | spin_lock(&inode_lock); | 1315 | spin_lock(&inode_lock); |
1313 | } | 1316 | } |
1314 | 1317 | ||
1315 | void wake_up_inode(struct inode *inode) | 1318 | void wake_up_inode(struct inode *inode) |
1316 | { | 1319 | { |
1317 | /* | 1320 | /* |
1318 | * Prevent speculative execution through spin_unlock(&inode_lock); | 1321 | * Prevent speculative execution through spin_unlock(&inode_lock); |
1319 | */ | 1322 | */ |
1320 | smp_mb(); | 1323 | smp_mb(); |
1321 | wake_up_bit(&inode->i_state, __I_LOCK); | 1324 | wake_up_bit(&inode->i_state, __I_LOCK); |
1322 | } | 1325 | } |
1323 | 1326 | ||
1324 | static __initdata unsigned long ihash_entries; | 1327 | static __initdata unsigned long ihash_entries; |
1325 | static int __init set_ihash_entries(char *str) | 1328 | static int __init set_ihash_entries(char *str) |
1326 | { | 1329 | { |
1327 | if (!str) | 1330 | if (!str) |
1328 | return 0; | 1331 | return 0; |
1329 | ihash_entries = simple_strtoul(str, &str, 0); | 1332 | ihash_entries = simple_strtoul(str, &str, 0); |
1330 | return 1; | 1333 | return 1; |
1331 | } | 1334 | } |
1332 | __setup("ihash_entries=", set_ihash_entries); | 1335 | __setup("ihash_entries=", set_ihash_entries); |
1333 | 1336 | ||
1334 | /* | 1337 | /* |
1335 | * Initialize the waitqueues and inode hash table. | 1338 | * Initialize the waitqueues and inode hash table. |
1336 | */ | 1339 | */ |
1337 | void __init inode_init_early(void) | 1340 | void __init inode_init_early(void) |
1338 | { | 1341 | { |
1339 | int loop; | 1342 | int loop; |
1340 | 1343 | ||
1341 | /* If hashes are distributed across NUMA nodes, defer | 1344 | /* If hashes are distributed across NUMA nodes, defer |
1342 | * hash allocation until vmalloc space is available. | 1345 | * hash allocation until vmalloc space is available. |
1343 | */ | 1346 | */ |
1344 | if (hashdist) | 1347 | if (hashdist) |
1345 | return; | 1348 | return; |
1346 | 1349 | ||
1347 | inode_hashtable = | 1350 | inode_hashtable = |
1348 | alloc_large_system_hash("Inode-cache", | 1351 | alloc_large_system_hash("Inode-cache", |
1349 | sizeof(struct hlist_head), | 1352 | sizeof(struct hlist_head), |
1350 | ihash_entries, | 1353 | ihash_entries, |
1351 | 14, | 1354 | 14, |
1352 | HASH_EARLY, | 1355 | HASH_EARLY, |
1353 | &i_hash_shift, | 1356 | &i_hash_shift, |
1354 | &i_hash_mask, | 1357 | &i_hash_mask, |
1355 | 0); | 1358 | 0); |
1356 | 1359 | ||
1357 | for (loop = 0; loop < (1 << i_hash_shift); loop++) | 1360 | for (loop = 0; loop < (1 << i_hash_shift); loop++) |
1358 | INIT_HLIST_HEAD(&inode_hashtable[loop]); | 1361 | INIT_HLIST_HEAD(&inode_hashtable[loop]); |
1359 | } | 1362 | } |
1360 | 1363 | ||
1361 | void __init inode_init(unsigned long mempages) | 1364 | void __init inode_init(unsigned long mempages) |
1362 | { | 1365 | { |
1363 | int loop; | 1366 | int loop; |
1364 | 1367 | ||
1365 | /* inode slab cache */ | 1368 | /* inode slab cache */ |
1366 | inode_cachep = kmem_cache_create("inode_cache", sizeof(struct inode), | 1369 | inode_cachep = kmem_cache_create("inode_cache", sizeof(struct inode), |
1367 | 0, SLAB_RECLAIM_ACCOUNT|SLAB_PANIC, init_once, NULL); | 1370 | 0, SLAB_RECLAIM_ACCOUNT|SLAB_PANIC, init_once, NULL); |
1368 | set_shrinker(DEFAULT_SEEKS, shrink_icache_memory); | 1371 | set_shrinker(DEFAULT_SEEKS, shrink_icache_memory); |
1369 | 1372 | ||
1370 | /* Hash may have been set up in inode_init_early */ | 1373 | /* Hash may have been set up in inode_init_early */ |
1371 | if (!hashdist) | 1374 | if (!hashdist) |
1372 | return; | 1375 | return; |
1373 | 1376 | ||
1374 | inode_hashtable = | 1377 | inode_hashtable = |
1375 | alloc_large_system_hash("Inode-cache", | 1378 | alloc_large_system_hash("Inode-cache", |
1376 | sizeof(struct hlist_head), | 1379 | sizeof(struct hlist_head), |
1377 | ihash_entries, | 1380 | ihash_entries, |
1378 | 14, | 1381 | 14, |
1379 | 0, | 1382 | 0, |
1380 | &i_hash_shift, | 1383 | &i_hash_shift, |
1381 | &i_hash_mask, | 1384 | &i_hash_mask, |
1382 | 0); | 1385 | 0); |
1383 | 1386 | ||
1384 | for (loop = 0; loop < (1 << i_hash_shift); loop++) | 1387 | for (loop = 0; loop < (1 << i_hash_shift); loop++) |
1385 | INIT_HLIST_HEAD(&inode_hashtable[loop]); | 1388 | INIT_HLIST_HEAD(&inode_hashtable[loop]); |
1386 | } | 1389 | } |
1387 | 1390 | ||
1388 | void init_special_inode(struct inode *inode, umode_t mode, dev_t rdev) | 1391 | void init_special_inode(struct inode *inode, umode_t mode, dev_t rdev) |
1389 | { | 1392 | { |
1390 | inode->i_mode = mode; | 1393 | inode->i_mode = mode; |
1391 | if (S_ISCHR(mode)) { | 1394 | if (S_ISCHR(mode)) { |
1392 | inode->i_fop = &def_chr_fops; | 1395 | inode->i_fop = &def_chr_fops; |
1393 | inode->i_rdev = rdev; | 1396 | inode->i_rdev = rdev; |
1394 | } else if (S_ISBLK(mode)) { | 1397 | } else if (S_ISBLK(mode)) { |
1395 | inode->i_fop = &def_blk_fops; | 1398 | inode->i_fop = &def_blk_fops; |
1396 | inode->i_rdev = rdev; | 1399 | inode->i_rdev = rdev; |
1397 | } else if (S_ISFIFO(mode)) | 1400 | } else if (S_ISFIFO(mode)) |
1398 | inode->i_fop = &def_fifo_fops; | 1401 | inode->i_fop = &def_fifo_fops; |
1399 | else if (S_ISSOCK(mode)) | 1402 | else if (S_ISSOCK(mode)) |
1400 | inode->i_fop = &bad_sock_fops; | 1403 | inode->i_fop = &bad_sock_fops; |
1401 | else | 1404 | else |
1402 | printk(KERN_DEBUG "init_special_inode: bogus i_mode (%o)\n", | 1405 | printk(KERN_DEBUG "init_special_inode: bogus i_mode (%o)\n", |
1403 | mode); | 1406 | mode); |
1404 | } | 1407 | } |
1405 | EXPORT_SYMBOL(init_special_inode); | 1408 | EXPORT_SYMBOL(init_special_inode); |
1406 | 1409 |
include/linux/fs.h
1 | #ifndef _LINUX_FS_H | 1 | #ifndef _LINUX_FS_H |
2 | #define _LINUX_FS_H | 2 | #define _LINUX_FS_H |
3 | 3 | ||
4 | /* | 4 | /* |
5 | * This file has definitions for some important file table | 5 | * This file has definitions for some important file table |
6 | * structures etc. | 6 | * structures etc. |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include <linux/config.h> | 9 | #include <linux/config.h> |
10 | #include <linux/limits.h> | 10 | #include <linux/limits.h> |
11 | #include <linux/ioctl.h> | 11 | #include <linux/ioctl.h> |
12 | 12 | ||
13 | /* | 13 | /* |
14 | * It's silly to have NR_OPEN bigger than NR_FILE, but you can change | 14 | * It's silly to have NR_OPEN bigger than NR_FILE, but you can change |
15 | * the file limit at runtime and only root can increase the per-process | 15 | * the file limit at runtime and only root can increase the per-process |
16 | * nr_file rlimit, so it's safe to set up a ridiculously high absolute | 16 | * nr_file rlimit, so it's safe to set up a ridiculously high absolute |
17 | * upper limit on files-per-process. | 17 | * upper limit on files-per-process. |
18 | * | 18 | * |
19 | * Some programs (notably those using select()) may have to be | 19 | * Some programs (notably those using select()) may have to be |
20 | * recompiled to take full advantage of the new limits.. | 20 | * recompiled to take full advantage of the new limits.. |
21 | */ | 21 | */ |
22 | 22 | ||
23 | /* Fixed constants first: */ | 23 | /* Fixed constants first: */ |
24 | #undef NR_OPEN | 24 | #undef NR_OPEN |
25 | #define NR_OPEN (1024*1024) /* Absolute upper limit on fd num */ | 25 | #define NR_OPEN (1024*1024) /* Absolute upper limit on fd num */ |
26 | #define INR_OPEN 1024 /* Initial setting for nfile rlimits */ | 26 | #define INR_OPEN 1024 /* Initial setting for nfile rlimits */ |
27 | 27 | ||
28 | #define BLOCK_SIZE_BITS 10 | 28 | #define BLOCK_SIZE_BITS 10 |
29 | #define BLOCK_SIZE (1<<BLOCK_SIZE_BITS) | 29 | #define BLOCK_SIZE (1<<BLOCK_SIZE_BITS) |
30 | 30 | ||
31 | /* And dynamically-tunable limits and defaults: */ | 31 | /* And dynamically-tunable limits and defaults: */ |
32 | struct files_stat_struct { | 32 | struct files_stat_struct { |
33 | int nr_files; /* read only */ | 33 | int nr_files; /* read only */ |
34 | int nr_free_files; /* read only */ | 34 | int nr_free_files; /* read only */ |
35 | int max_files; /* tunable */ | 35 | int max_files; /* tunable */ |
36 | }; | 36 | }; |
37 | extern struct files_stat_struct files_stat; | 37 | extern struct files_stat_struct files_stat; |
38 | 38 | ||
39 | struct inodes_stat_t { | 39 | struct inodes_stat_t { |
40 | int nr_inodes; | 40 | int nr_inodes; |
41 | int nr_unused; | 41 | int nr_unused; |
42 | int dummy[5]; | 42 | int dummy[5]; |
43 | }; | 43 | }; |
44 | extern struct inodes_stat_t inodes_stat; | 44 | extern struct inodes_stat_t inodes_stat; |
45 | 45 | ||
46 | extern int leases_enable, lease_break_time; | 46 | extern int leases_enable, lease_break_time; |
47 | 47 | ||
48 | #ifdef CONFIG_DNOTIFY | 48 | #ifdef CONFIG_DNOTIFY |
49 | extern int dir_notify_enable; | 49 | extern int dir_notify_enable; |
50 | #endif | 50 | #endif |
51 | 51 | ||
52 | #define NR_FILE 8192 /* this can well be larger on a larger system */ | 52 | #define NR_FILE 8192 /* this can well be larger on a larger system */ |
53 | 53 | ||
54 | #define MAY_EXEC 1 | 54 | #define MAY_EXEC 1 |
55 | #define MAY_WRITE 2 | 55 | #define MAY_WRITE 2 |
56 | #define MAY_READ 4 | 56 | #define MAY_READ 4 |
57 | #define MAY_APPEND 8 | 57 | #define MAY_APPEND 8 |
58 | 58 | ||
59 | #define FMODE_READ 1 | 59 | #define FMODE_READ 1 |
60 | #define FMODE_WRITE 2 | 60 | #define FMODE_WRITE 2 |
61 | 61 | ||
62 | /* Internal kernel extensions */ | 62 | /* Internal kernel extensions */ |
63 | #define FMODE_LSEEK 4 | 63 | #define FMODE_LSEEK 4 |
64 | #define FMODE_PREAD 8 | 64 | #define FMODE_PREAD 8 |
65 | #define FMODE_PWRITE FMODE_PREAD /* These go hand in hand */ | 65 | #define FMODE_PWRITE FMODE_PREAD /* These go hand in hand */ |
66 | 66 | ||
67 | #define RW_MASK 1 | 67 | #define RW_MASK 1 |
68 | #define RWA_MASK 2 | 68 | #define RWA_MASK 2 |
69 | #define READ 0 | 69 | #define READ 0 |
70 | #define WRITE 1 | 70 | #define WRITE 1 |
71 | #define READA 2 /* read-ahead - don't block if no resources */ | 71 | #define READA 2 /* read-ahead - don't block if no resources */ |
72 | #define SWRITE 3 /* for ll_rw_block() - wait for buffer lock */ | 72 | #define SWRITE 3 /* for ll_rw_block() - wait for buffer lock */ |
73 | #define SPECIAL 4 /* For non-blockdevice requests in request queue */ | 73 | #define SPECIAL 4 /* For non-blockdevice requests in request queue */ |
74 | #define READ_SYNC (READ | (1 << BIO_RW_SYNC)) | 74 | #define READ_SYNC (READ | (1 << BIO_RW_SYNC)) |
75 | #define WRITE_SYNC (WRITE | (1 << BIO_RW_SYNC)) | 75 | #define WRITE_SYNC (WRITE | (1 << BIO_RW_SYNC)) |
76 | #define WRITE_BARRIER ((1 << BIO_RW) | (1 << BIO_RW_BARRIER)) | 76 | #define WRITE_BARRIER ((1 << BIO_RW) | (1 << BIO_RW_BARRIER)) |
77 | 77 | ||
78 | #define SEL_IN 1 | 78 | #define SEL_IN 1 |
79 | #define SEL_OUT 2 | 79 | #define SEL_OUT 2 |
80 | #define SEL_EX 4 | 80 | #define SEL_EX 4 |
81 | 81 | ||
82 | /* public flags for file_system_type */ | 82 | /* public flags for file_system_type */ |
83 | #define FS_REQUIRES_DEV 1 | 83 | #define FS_REQUIRES_DEV 1 |
84 | #define FS_BINARY_MOUNTDATA 2 | 84 | #define FS_BINARY_MOUNTDATA 2 |
85 | #define FS_REVAL_DOT 16384 /* Check the paths ".", ".." for staleness */ | 85 | #define FS_REVAL_DOT 16384 /* Check the paths ".", ".." for staleness */ |
86 | #define FS_ODD_RENAME 32768 /* Temporary stuff; will go away as soon | 86 | #define FS_ODD_RENAME 32768 /* Temporary stuff; will go away as soon |
87 | * as nfs_rename() will be cleaned up | 87 | * as nfs_rename() will be cleaned up |
88 | */ | 88 | */ |
89 | /* | 89 | /* |
90 | * These are the fs-independent mount-flags: up to 32 flags are supported | 90 | * These are the fs-independent mount-flags: up to 32 flags are supported |
91 | */ | 91 | */ |
92 | #define MS_RDONLY 1 /* Mount read-only */ | 92 | #define MS_RDONLY 1 /* Mount read-only */ |
93 | #define MS_NOSUID 2 /* Ignore suid and sgid bits */ | 93 | #define MS_NOSUID 2 /* Ignore suid and sgid bits */ |
94 | #define MS_NODEV 4 /* Disallow access to device special files */ | 94 | #define MS_NODEV 4 /* Disallow access to device special files */ |
95 | #define MS_NOEXEC 8 /* Disallow program execution */ | 95 | #define MS_NOEXEC 8 /* Disallow program execution */ |
96 | #define MS_SYNCHRONOUS 16 /* Writes are synced at once */ | 96 | #define MS_SYNCHRONOUS 16 /* Writes are synced at once */ |
97 | #define MS_REMOUNT 32 /* Alter flags of a mounted FS */ | 97 | #define MS_REMOUNT 32 /* Alter flags of a mounted FS */ |
98 | #define MS_MANDLOCK 64 /* Allow mandatory locks on an FS */ | 98 | #define MS_MANDLOCK 64 /* Allow mandatory locks on an FS */ |
99 | #define MS_DIRSYNC 128 /* Directory modifications are synchronous */ | 99 | #define MS_DIRSYNC 128 /* Directory modifications are synchronous */ |
100 | #define MS_NOATIME 1024 /* Do not update access times. */ | 100 | #define MS_NOATIME 1024 /* Do not update access times. */ |
101 | #define MS_NODIRATIME 2048 /* Do not update directory access times */ | 101 | #define MS_NODIRATIME 2048 /* Do not update directory access times */ |
102 | #define MS_BIND 4096 | 102 | #define MS_BIND 4096 |
103 | #define MS_MOVE 8192 | 103 | #define MS_MOVE 8192 |
104 | #define MS_REC 16384 | 104 | #define MS_REC 16384 |
105 | #define MS_VERBOSE 32768 | 105 | #define MS_VERBOSE 32768 |
106 | #define MS_POSIXACL (1<<16) /* VFS does not apply the umask */ | 106 | #define MS_POSIXACL (1<<16) /* VFS does not apply the umask */ |
107 | #define MS_UNBINDABLE (1<<17) /* change to unbindable */ | 107 | #define MS_UNBINDABLE (1<<17) /* change to unbindable */ |
108 | #define MS_PRIVATE (1<<18) /* change to private */ | 108 | #define MS_PRIVATE (1<<18) /* change to private */ |
109 | #define MS_SLAVE (1<<19) /* change to slave */ | 109 | #define MS_SLAVE (1<<19) /* change to slave */ |
110 | #define MS_SHARED (1<<20) /* change to shared */ | 110 | #define MS_SHARED (1<<20) /* change to shared */ |
111 | #define MS_ACTIVE (1<<30) | 111 | #define MS_ACTIVE (1<<30) |
112 | #define MS_NOUSER (1<<31) | 112 | #define MS_NOUSER (1<<31) |
113 | 113 | ||
114 | /* | 114 | /* |
115 | * Superblock flags that can be altered by MS_REMOUNT | 115 | * Superblock flags that can be altered by MS_REMOUNT |
116 | */ | 116 | */ |
117 | #define MS_RMT_MASK (MS_RDONLY|MS_SYNCHRONOUS|MS_MANDLOCK|MS_NOATIME|\ | 117 | #define MS_RMT_MASK (MS_RDONLY|MS_SYNCHRONOUS|MS_MANDLOCK|MS_NOATIME|\ |
118 | MS_NODIRATIME) | 118 | MS_NODIRATIME) |
119 | 119 | ||
120 | /* | 120 | /* |
121 | * Old magic mount flag and mask | 121 | * Old magic mount flag and mask |
122 | */ | 122 | */ |
123 | #define MS_MGC_VAL 0xC0ED0000 | 123 | #define MS_MGC_VAL 0xC0ED0000 |
124 | #define MS_MGC_MSK 0xffff0000 | 124 | #define MS_MGC_MSK 0xffff0000 |
125 | 125 | ||
126 | /* Inode flags - they have nothing to superblock flags now */ | 126 | /* Inode flags - they have nothing to superblock flags now */ |
127 | 127 | ||
128 | #define S_SYNC 1 /* Writes are synced at once */ | 128 | #define S_SYNC 1 /* Writes are synced at once */ |
129 | #define S_NOATIME 2 /* Do not update access times */ | 129 | #define S_NOATIME 2 /* Do not update access times */ |
130 | #define S_APPEND 4 /* Append-only file */ | 130 | #define S_APPEND 4 /* Append-only file */ |
131 | #define S_IMMUTABLE 8 /* Immutable file */ | 131 | #define S_IMMUTABLE 8 /* Immutable file */ |
132 | #define S_DEAD 16 /* removed, but still open directory */ | 132 | #define S_DEAD 16 /* removed, but still open directory */ |
133 | #define S_NOQUOTA 32 /* Inode is not counted to quota */ | 133 | #define S_NOQUOTA 32 /* Inode is not counted to quota */ |
134 | #define S_DIRSYNC 64 /* Directory modifications are synchronous */ | 134 | #define S_DIRSYNC 64 /* Directory modifications are synchronous */ |
135 | #define S_NOCMTIME 128 /* Do not update file c/mtime */ | 135 | #define S_NOCMTIME 128 /* Do not update file c/mtime */ |
136 | #define S_SWAPFILE 256 /* Do not truncate: swapon got its bmaps */ | 136 | #define S_SWAPFILE 256 /* Do not truncate: swapon got its bmaps */ |
137 | #define S_PRIVATE 512 /* Inode is fs-internal */ | 137 | #define S_PRIVATE 512 /* Inode is fs-internal */ |
138 | 138 | ||
139 | /* | 139 | /* |
140 | * Note that nosuid etc flags are inode-specific: setting some file-system | 140 | * Note that nosuid etc flags are inode-specific: setting some file-system |
141 | * flags just means all the inodes inherit those flags by default. It might be | 141 | * flags just means all the inodes inherit those flags by default. It might be |
142 | * possible to override it selectively if you really wanted to with some | 142 | * possible to override it selectively if you really wanted to with some |
143 | * ioctl() that is not currently implemented. | 143 | * ioctl() that is not currently implemented. |
144 | * | 144 | * |
145 | * Exception: MS_RDONLY is always applied to the entire file system. | 145 | * Exception: MS_RDONLY is always applied to the entire file system. |
146 | * | 146 | * |
147 | * Unfortunately, it is possible to change a filesystems flags with it mounted | 147 | * Unfortunately, it is possible to change a filesystems flags with it mounted |
148 | * with files in use. This means that all of the inodes will not have their | 148 | * with files in use. This means that all of the inodes will not have their |
149 | * i_flags updated. Hence, i_flags no longer inherit the superblock mount | 149 | * i_flags updated. Hence, i_flags no longer inherit the superblock mount |
150 | * flags, so these have to be checked separately. -- rmk@arm.uk.linux.org | 150 | * flags, so these have to be checked separately. -- rmk@arm.uk.linux.org |
151 | */ | 151 | */ |
152 | #define __IS_FLG(inode,flg) ((inode)->i_sb->s_flags & (flg)) | 152 | #define __IS_FLG(inode,flg) ((inode)->i_sb->s_flags & (flg)) |
153 | 153 | ||
154 | #define IS_RDONLY(inode) ((inode)->i_sb->s_flags & MS_RDONLY) | 154 | #define IS_RDONLY(inode) ((inode)->i_sb->s_flags & MS_RDONLY) |
155 | #define IS_SYNC(inode) (__IS_FLG(inode, MS_SYNCHRONOUS) || \ | 155 | #define IS_SYNC(inode) (__IS_FLG(inode, MS_SYNCHRONOUS) || \ |
156 | ((inode)->i_flags & S_SYNC)) | 156 | ((inode)->i_flags & S_SYNC)) |
157 | #define IS_DIRSYNC(inode) (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \ | 157 | #define IS_DIRSYNC(inode) (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \ |
158 | ((inode)->i_flags & (S_SYNC|S_DIRSYNC))) | 158 | ((inode)->i_flags & (S_SYNC|S_DIRSYNC))) |
159 | #define IS_MANDLOCK(inode) __IS_FLG(inode, MS_MANDLOCK) | 159 | #define IS_MANDLOCK(inode) __IS_FLG(inode, MS_MANDLOCK) |
160 | 160 | ||
161 | #define IS_NOQUOTA(inode) ((inode)->i_flags & S_NOQUOTA) | 161 | #define IS_NOQUOTA(inode) ((inode)->i_flags & S_NOQUOTA) |
162 | #define IS_APPEND(inode) ((inode)->i_flags & S_APPEND) | 162 | #define IS_APPEND(inode) ((inode)->i_flags & S_APPEND) |
163 | #define IS_IMMUTABLE(inode) ((inode)->i_flags & S_IMMUTABLE) | 163 | #define IS_IMMUTABLE(inode) ((inode)->i_flags & S_IMMUTABLE) |
164 | #define IS_NOATIME(inode) (__IS_FLG(inode, MS_NOATIME) || ((inode)->i_flags & S_NOATIME)) | 164 | #define IS_NOATIME(inode) (__IS_FLG(inode, MS_NOATIME) || ((inode)->i_flags & S_NOATIME)) |
165 | #define IS_NODIRATIME(inode) __IS_FLG(inode, MS_NODIRATIME) | 165 | #define IS_NODIRATIME(inode) __IS_FLG(inode, MS_NODIRATIME) |
166 | #define IS_POSIXACL(inode) __IS_FLG(inode, MS_POSIXACL) | 166 | #define IS_POSIXACL(inode) __IS_FLG(inode, MS_POSIXACL) |
167 | 167 | ||
168 | #define IS_DEADDIR(inode) ((inode)->i_flags & S_DEAD) | 168 | #define IS_DEADDIR(inode) ((inode)->i_flags & S_DEAD) |
169 | #define IS_NOCMTIME(inode) ((inode)->i_flags & S_NOCMTIME) | 169 | #define IS_NOCMTIME(inode) ((inode)->i_flags & S_NOCMTIME) |
170 | #define IS_SWAPFILE(inode) ((inode)->i_flags & S_SWAPFILE) | 170 | #define IS_SWAPFILE(inode) ((inode)->i_flags & S_SWAPFILE) |
171 | #define IS_PRIVATE(inode) ((inode)->i_flags & S_PRIVATE) | 171 | #define IS_PRIVATE(inode) ((inode)->i_flags & S_PRIVATE) |
172 | 172 | ||
173 | /* the read-only stuff doesn't really belong here, but any other place is | 173 | /* the read-only stuff doesn't really belong here, but any other place is |
174 | probably as bad and I don't want to create yet another include file. */ | 174 | probably as bad and I don't want to create yet another include file. */ |
175 | 175 | ||
176 | #define BLKROSET _IO(0x12,93) /* set device read-only (0 = read-write) */ | 176 | #define BLKROSET _IO(0x12,93) /* set device read-only (0 = read-write) */ |
177 | #define BLKROGET _IO(0x12,94) /* get read-only status (0 = read_write) */ | 177 | #define BLKROGET _IO(0x12,94) /* get read-only status (0 = read_write) */ |
178 | #define BLKRRPART _IO(0x12,95) /* re-read partition table */ | 178 | #define BLKRRPART _IO(0x12,95) /* re-read partition table */ |
179 | #define BLKGETSIZE _IO(0x12,96) /* return device size /512 (long *arg) */ | 179 | #define BLKGETSIZE _IO(0x12,96) /* return device size /512 (long *arg) */ |
180 | #define BLKFLSBUF _IO(0x12,97) /* flush buffer cache */ | 180 | #define BLKFLSBUF _IO(0x12,97) /* flush buffer cache */ |
181 | #define BLKRASET _IO(0x12,98) /* set read ahead for block device */ | 181 | #define BLKRASET _IO(0x12,98) /* set read ahead for block device */ |
182 | #define BLKRAGET _IO(0x12,99) /* get current read ahead setting */ | 182 | #define BLKRAGET _IO(0x12,99) /* get current read ahead setting */ |
183 | #define BLKFRASET _IO(0x12,100)/* set filesystem (mm/filemap.c) read-ahead */ | 183 | #define BLKFRASET _IO(0x12,100)/* set filesystem (mm/filemap.c) read-ahead */ |
184 | #define BLKFRAGET _IO(0x12,101)/* get filesystem (mm/filemap.c) read-ahead */ | 184 | #define BLKFRAGET _IO(0x12,101)/* get filesystem (mm/filemap.c) read-ahead */ |
185 | #define BLKSECTSET _IO(0x12,102)/* set max sectors per request (ll_rw_blk.c) */ | 185 | #define BLKSECTSET _IO(0x12,102)/* set max sectors per request (ll_rw_blk.c) */ |
186 | #define BLKSECTGET _IO(0x12,103)/* get max sectors per request (ll_rw_blk.c) */ | 186 | #define BLKSECTGET _IO(0x12,103)/* get max sectors per request (ll_rw_blk.c) */ |
187 | #define BLKSSZGET _IO(0x12,104)/* get block device sector size */ | 187 | #define BLKSSZGET _IO(0x12,104)/* get block device sector size */ |
188 | #if 0 | 188 | #if 0 |
189 | #define BLKPG _IO(0x12,105)/* See blkpg.h */ | 189 | #define BLKPG _IO(0x12,105)/* See blkpg.h */ |
190 | 190 | ||
191 | /* Some people are morons. Do not use sizeof! */ | 191 | /* Some people are morons. Do not use sizeof! */ |
192 | 192 | ||
193 | #define BLKELVGET _IOR(0x12,106,size_t)/* elevator get */ | 193 | #define BLKELVGET _IOR(0x12,106,size_t)/* elevator get */ |
194 | #define BLKELVSET _IOW(0x12,107,size_t)/* elevator set */ | 194 | #define BLKELVSET _IOW(0x12,107,size_t)/* elevator set */ |
195 | /* This was here just to show that the number is taken - | 195 | /* This was here just to show that the number is taken - |
196 | probably all these _IO(0x12,*) ioctls should be moved to blkpg.h. */ | 196 | probably all these _IO(0x12,*) ioctls should be moved to blkpg.h. */ |
197 | #endif | 197 | #endif |
198 | /* A jump here: 108-111 have been used for various private purposes. */ | 198 | /* A jump here: 108-111 have been used for various private purposes. */ |
199 | #define BLKBSZGET _IOR(0x12,112,size_t) | 199 | #define BLKBSZGET _IOR(0x12,112,size_t) |
200 | #define BLKBSZSET _IOW(0x12,113,size_t) | 200 | #define BLKBSZSET _IOW(0x12,113,size_t) |
201 | #define BLKGETSIZE64 _IOR(0x12,114,size_t) /* return device size in bytes (u64 *arg) */ | 201 | #define BLKGETSIZE64 _IOR(0x12,114,size_t) /* return device size in bytes (u64 *arg) */ |
202 | 202 | ||
203 | #define BMAP_IOCTL 1 /* obsolete - kept for compatibility */ | 203 | #define BMAP_IOCTL 1 /* obsolete - kept for compatibility */ |
204 | #define FIBMAP _IO(0x00,1) /* bmap access */ | 204 | #define FIBMAP _IO(0x00,1) /* bmap access */ |
205 | #define FIGETBSZ _IO(0x00,2) /* get the block size used for bmap */ | 205 | #define FIGETBSZ _IO(0x00,2) /* get the block size used for bmap */ |
206 | 206 | ||
207 | #ifdef __KERNEL__ | 207 | #ifdef __KERNEL__ |
208 | 208 | ||
209 | #include <linux/linkage.h> | 209 | #include <linux/linkage.h> |
210 | #include <linux/wait.h> | 210 | #include <linux/wait.h> |
211 | #include <linux/types.h> | 211 | #include <linux/types.h> |
212 | #include <linux/kdev_t.h> | 212 | #include <linux/kdev_t.h> |
213 | #include <linux/dcache.h> | 213 | #include <linux/dcache.h> |
214 | #include <linux/stat.h> | 214 | #include <linux/stat.h> |
215 | #include <linux/cache.h> | 215 | #include <linux/cache.h> |
216 | #include <linux/kobject.h> | 216 | #include <linux/kobject.h> |
217 | #include <linux/list.h> | 217 | #include <linux/list.h> |
218 | #include <linux/radix-tree.h> | 218 | #include <linux/radix-tree.h> |
219 | #include <linux/prio_tree.h> | 219 | #include <linux/prio_tree.h> |
220 | #include <linux/init.h> | 220 | #include <linux/init.h> |
221 | #include <linux/sched.h> | 221 | #include <linux/sched.h> |
222 | #include <linux/mutex.h> | 222 | #include <linux/mutex.h> |
223 | 223 | ||
224 | #include <asm/atomic.h> | 224 | #include <asm/atomic.h> |
225 | #include <asm/semaphore.h> | 225 | #include <asm/semaphore.h> |
226 | #include <asm/byteorder.h> | 226 | #include <asm/byteorder.h> |
227 | 227 | ||
228 | struct hd_geometry; | 228 | struct hd_geometry; |
229 | struct iovec; | 229 | struct iovec; |
230 | struct nameidata; | 230 | struct nameidata; |
231 | struct kiocb; | 231 | struct kiocb; |
232 | struct pipe_inode_info; | 232 | struct pipe_inode_info; |
233 | struct poll_table_struct; | 233 | struct poll_table_struct; |
234 | struct kstatfs; | 234 | struct kstatfs; |
235 | struct vm_area_struct; | 235 | struct vm_area_struct; |
236 | struct vfsmount; | 236 | struct vfsmount; |
237 | 237 | ||
238 | /* Used to be a macro which just called the function, now just a function */ | ||
239 | extern void update_atime (struct inode *); | ||
240 | |||
241 | extern void __init inode_init(unsigned long); | 238 | extern void __init inode_init(unsigned long); |
242 | extern void __init inode_init_early(void); | 239 | extern void __init inode_init_early(void); |
243 | extern void __init mnt_init(unsigned long); | 240 | extern void __init mnt_init(unsigned long); |
244 | extern void __init files_init(unsigned long); | 241 | extern void __init files_init(unsigned long); |
245 | 242 | ||
246 | struct buffer_head; | 243 | struct buffer_head; |
247 | typedef int (get_block_t)(struct inode *inode, sector_t iblock, | 244 | typedef int (get_block_t)(struct inode *inode, sector_t iblock, |
248 | struct buffer_head *bh_result, int create); | 245 | struct buffer_head *bh_result, int create); |
249 | typedef int (get_blocks_t)(struct inode *inode, sector_t iblock, | 246 | typedef int (get_blocks_t)(struct inode *inode, sector_t iblock, |
250 | unsigned long max_blocks, | 247 | unsigned long max_blocks, |
251 | struct buffer_head *bh_result, int create); | 248 | struct buffer_head *bh_result, int create); |
252 | typedef void (dio_iodone_t)(struct kiocb *iocb, loff_t offset, | 249 | typedef void (dio_iodone_t)(struct kiocb *iocb, loff_t offset, |
253 | ssize_t bytes, void *private); | 250 | ssize_t bytes, void *private); |
254 | 251 | ||
255 | /* | 252 | /* |
256 | * Attribute flags. These should be or-ed together to figure out what | 253 | * Attribute flags. These should be or-ed together to figure out what |
257 | * has been changed! | 254 | * has been changed! |
258 | */ | 255 | */ |
259 | #define ATTR_MODE 1 | 256 | #define ATTR_MODE 1 |
260 | #define ATTR_UID 2 | 257 | #define ATTR_UID 2 |
261 | #define ATTR_GID 4 | 258 | #define ATTR_GID 4 |
262 | #define ATTR_SIZE 8 | 259 | #define ATTR_SIZE 8 |
263 | #define ATTR_ATIME 16 | 260 | #define ATTR_ATIME 16 |
264 | #define ATTR_MTIME 32 | 261 | #define ATTR_MTIME 32 |
265 | #define ATTR_CTIME 64 | 262 | #define ATTR_CTIME 64 |
266 | #define ATTR_ATIME_SET 128 | 263 | #define ATTR_ATIME_SET 128 |
267 | #define ATTR_MTIME_SET 256 | 264 | #define ATTR_MTIME_SET 256 |
268 | #define ATTR_FORCE 512 /* Not a change, but a change it */ | 265 | #define ATTR_FORCE 512 /* Not a change, but a change it */ |
269 | #define ATTR_ATTR_FLAG 1024 | 266 | #define ATTR_ATTR_FLAG 1024 |
270 | #define ATTR_KILL_SUID 2048 | 267 | #define ATTR_KILL_SUID 2048 |
271 | #define ATTR_KILL_SGID 4096 | 268 | #define ATTR_KILL_SGID 4096 |
272 | #define ATTR_FILE 8192 | 269 | #define ATTR_FILE 8192 |
273 | 270 | ||
274 | /* | 271 | /* |
275 | * This is the Inode Attributes structure, used for notify_change(). It | 272 | * This is the Inode Attributes structure, used for notify_change(). It |
276 | * uses the above definitions as flags, to know which values have changed. | 273 | * uses the above definitions as flags, to know which values have changed. |
277 | * Also, in this manner, a Filesystem can look at only the values it cares | 274 | * Also, in this manner, a Filesystem can look at only the values it cares |
278 | * about. Basically, these are the attributes that the VFS layer can | 275 | * about. Basically, these are the attributes that the VFS layer can |
279 | * request to change from the FS layer. | 276 | * request to change from the FS layer. |
280 | * | 277 | * |
281 | * Derek Atkins <warlord@MIT.EDU> 94-10-20 | 278 | * Derek Atkins <warlord@MIT.EDU> 94-10-20 |
282 | */ | 279 | */ |
283 | struct iattr { | 280 | struct iattr { |
284 | unsigned int ia_valid; | 281 | unsigned int ia_valid; |
285 | umode_t ia_mode; | 282 | umode_t ia_mode; |
286 | uid_t ia_uid; | 283 | uid_t ia_uid; |
287 | gid_t ia_gid; | 284 | gid_t ia_gid; |
288 | loff_t ia_size; | 285 | loff_t ia_size; |
289 | struct timespec ia_atime; | 286 | struct timespec ia_atime; |
290 | struct timespec ia_mtime; | 287 | struct timespec ia_mtime; |
291 | struct timespec ia_ctime; | 288 | struct timespec ia_ctime; |
292 | 289 | ||
293 | /* | 290 | /* |
294 | * Not an attribute, but an auxilary info for filesystems wanting to | 291 | * Not an attribute, but an auxilary info for filesystems wanting to |
295 | * implement an ftruncate() like method. NOTE: filesystem should | 292 | * implement an ftruncate() like method. NOTE: filesystem should |
296 | * check for (ia_valid & ATTR_FILE), and not for (ia_file != NULL). | 293 | * check for (ia_valid & ATTR_FILE), and not for (ia_file != NULL). |
297 | */ | 294 | */ |
298 | struct file *ia_file; | 295 | struct file *ia_file; |
299 | }; | 296 | }; |
300 | 297 | ||
301 | /* | 298 | /* |
302 | * Includes for diskquotas. | 299 | * Includes for diskquotas. |
303 | */ | 300 | */ |
304 | #include <linux/quota.h> | 301 | #include <linux/quota.h> |
305 | 302 | ||
306 | /** | 303 | /** |
307 | * enum positive_aop_returns - aop return codes with specific semantics | 304 | * enum positive_aop_returns - aop return codes with specific semantics |
308 | * | 305 | * |
309 | * @AOP_WRITEPAGE_ACTIVATE: Informs the caller that page writeback has | 306 | * @AOP_WRITEPAGE_ACTIVATE: Informs the caller that page writeback has |
310 | * completed, that the page is still locked, and | 307 | * completed, that the page is still locked, and |
311 | * should be considered active. The VM uses this hint | 308 | * should be considered active. The VM uses this hint |
312 | * to return the page to the active list -- it won't | 309 | * to return the page to the active list -- it won't |
313 | * be a candidate for writeback again in the near | 310 | * be a candidate for writeback again in the near |
314 | * future. Other callers must be careful to unlock | 311 | * future. Other callers must be careful to unlock |
315 | * the page if they get this return. Returned by | 312 | * the page if they get this return. Returned by |
316 | * writepage(); | 313 | * writepage(); |
317 | * | 314 | * |
318 | * @AOP_TRUNCATED_PAGE: The AOP method that was handed a locked page has | 315 | * @AOP_TRUNCATED_PAGE: The AOP method that was handed a locked page has |
319 | * unlocked it and the page might have been truncated. | 316 | * unlocked it and the page might have been truncated. |
320 | * The caller should back up to acquiring a new page and | 317 | * The caller should back up to acquiring a new page and |
321 | * trying again. The aop will be taking reasonable | 318 | * trying again. The aop will be taking reasonable |
322 | * precautions not to livelock. If the caller held a page | 319 | * precautions not to livelock. If the caller held a page |
323 | * reference, it should drop it before retrying. Returned | 320 | * reference, it should drop it before retrying. Returned |
324 | * by readpage(), prepare_write(), and commit_write(). | 321 | * by readpage(), prepare_write(), and commit_write(). |
325 | * | 322 | * |
326 | * address_space_operation functions return these large constants to indicate | 323 | * address_space_operation functions return these large constants to indicate |
327 | * special semantics to the caller. These are much larger than the bytes in a | 324 | * special semantics to the caller. These are much larger than the bytes in a |
328 | * page to allow for functions that return the number of bytes operated on in a | 325 | * page to allow for functions that return the number of bytes operated on in a |
329 | * given page. | 326 | * given page. |
330 | */ | 327 | */ |
331 | 328 | ||
332 | enum positive_aop_returns { | 329 | enum positive_aop_returns { |
333 | AOP_WRITEPAGE_ACTIVATE = 0x80000, | 330 | AOP_WRITEPAGE_ACTIVATE = 0x80000, |
334 | AOP_TRUNCATED_PAGE = 0x80001, | 331 | AOP_TRUNCATED_PAGE = 0x80001, |
335 | }; | 332 | }; |
336 | 333 | ||
337 | /* | 334 | /* |
338 | * oh the beauties of C type declarations. | 335 | * oh the beauties of C type declarations. |
339 | */ | 336 | */ |
340 | struct page; | 337 | struct page; |
341 | struct address_space; | 338 | struct address_space; |
342 | struct writeback_control; | 339 | struct writeback_control; |
343 | 340 | ||
344 | struct address_space_operations { | 341 | struct address_space_operations { |
345 | int (*writepage)(struct page *page, struct writeback_control *wbc); | 342 | int (*writepage)(struct page *page, struct writeback_control *wbc); |
346 | int (*readpage)(struct file *, struct page *); | 343 | int (*readpage)(struct file *, struct page *); |
347 | int (*sync_page)(struct page *); | 344 | int (*sync_page)(struct page *); |
348 | 345 | ||
349 | /* Write back some dirty pages from this mapping. */ | 346 | /* Write back some dirty pages from this mapping. */ |
350 | int (*writepages)(struct address_space *, struct writeback_control *); | 347 | int (*writepages)(struct address_space *, struct writeback_control *); |
351 | 348 | ||
352 | /* Set a page dirty */ | 349 | /* Set a page dirty */ |
353 | int (*set_page_dirty)(struct page *page); | 350 | int (*set_page_dirty)(struct page *page); |
354 | 351 | ||
355 | int (*readpages)(struct file *filp, struct address_space *mapping, | 352 | int (*readpages)(struct file *filp, struct address_space *mapping, |
356 | struct list_head *pages, unsigned nr_pages); | 353 | struct list_head *pages, unsigned nr_pages); |
357 | 354 | ||
358 | /* | 355 | /* |
359 | * ext3 requires that a successful prepare_write() call be followed | 356 | * ext3 requires that a successful prepare_write() call be followed |
360 | * by a commit_write() call - they must be balanced | 357 | * by a commit_write() call - they must be balanced |
361 | */ | 358 | */ |
362 | int (*prepare_write)(struct file *, struct page *, unsigned, unsigned); | 359 | int (*prepare_write)(struct file *, struct page *, unsigned, unsigned); |
363 | int (*commit_write)(struct file *, struct page *, unsigned, unsigned); | 360 | int (*commit_write)(struct file *, struct page *, unsigned, unsigned); |
364 | /* Unfortunately this kludge is needed for FIBMAP. Don't use it */ | 361 | /* Unfortunately this kludge is needed for FIBMAP. Don't use it */ |
365 | sector_t (*bmap)(struct address_space *, sector_t); | 362 | sector_t (*bmap)(struct address_space *, sector_t); |
366 | int (*invalidatepage) (struct page *, unsigned long); | 363 | int (*invalidatepage) (struct page *, unsigned long); |
367 | int (*releasepage) (struct page *, gfp_t); | 364 | int (*releasepage) (struct page *, gfp_t); |
368 | ssize_t (*direct_IO)(int, struct kiocb *, const struct iovec *iov, | 365 | ssize_t (*direct_IO)(int, struct kiocb *, const struct iovec *iov, |
369 | loff_t offset, unsigned long nr_segs); | 366 | loff_t offset, unsigned long nr_segs); |
370 | struct page* (*get_xip_page)(struct address_space *, sector_t, | 367 | struct page* (*get_xip_page)(struct address_space *, sector_t, |
371 | int); | 368 | int); |
372 | }; | 369 | }; |
373 | 370 | ||
374 | struct backing_dev_info; | 371 | struct backing_dev_info; |
375 | struct address_space { | 372 | struct address_space { |
376 | struct inode *host; /* owner: inode, block_device */ | 373 | struct inode *host; /* owner: inode, block_device */ |
377 | struct radix_tree_root page_tree; /* radix tree of all pages */ | 374 | struct radix_tree_root page_tree; /* radix tree of all pages */ |
378 | rwlock_t tree_lock; /* and rwlock protecting it */ | 375 | rwlock_t tree_lock; /* and rwlock protecting it */ |
379 | unsigned int i_mmap_writable;/* count VM_SHARED mappings */ | 376 | unsigned int i_mmap_writable;/* count VM_SHARED mappings */ |
380 | struct prio_tree_root i_mmap; /* tree of private and shared mappings */ | 377 | struct prio_tree_root i_mmap; /* tree of private and shared mappings */ |
381 | struct list_head i_mmap_nonlinear;/*list VM_NONLINEAR mappings */ | 378 | struct list_head i_mmap_nonlinear;/*list VM_NONLINEAR mappings */ |
382 | spinlock_t i_mmap_lock; /* protect tree, count, list */ | 379 | spinlock_t i_mmap_lock; /* protect tree, count, list */ |
383 | unsigned int truncate_count; /* Cover race condition with truncate */ | 380 | unsigned int truncate_count; /* Cover race condition with truncate */ |
384 | unsigned long nrpages; /* number of total pages */ | 381 | unsigned long nrpages; /* number of total pages */ |
385 | pgoff_t writeback_index;/* writeback starts here */ | 382 | pgoff_t writeback_index;/* writeback starts here */ |
386 | struct address_space_operations *a_ops; /* methods */ | 383 | struct address_space_operations *a_ops; /* methods */ |
387 | unsigned long flags; /* error bits/gfp mask */ | 384 | unsigned long flags; /* error bits/gfp mask */ |
388 | struct backing_dev_info *backing_dev_info; /* device readahead, etc */ | 385 | struct backing_dev_info *backing_dev_info; /* device readahead, etc */ |
389 | spinlock_t private_lock; /* for use by the address_space */ | 386 | spinlock_t private_lock; /* for use by the address_space */ |
390 | struct list_head private_list; /* ditto */ | 387 | struct list_head private_list; /* ditto */ |
391 | struct address_space *assoc_mapping; /* ditto */ | 388 | struct address_space *assoc_mapping; /* ditto */ |
392 | } __attribute__((aligned(sizeof(long)))); | 389 | } __attribute__((aligned(sizeof(long)))); |
393 | /* | 390 | /* |
394 | * On most architectures that alignment is already the case; but | 391 | * On most architectures that alignment is already the case; but |
395 | * must be enforced here for CRIS, to let the least signficant bit | 392 | * must be enforced here for CRIS, to let the least signficant bit |
396 | * of struct page's "mapping" pointer be used for PAGE_MAPPING_ANON. | 393 | * of struct page's "mapping" pointer be used for PAGE_MAPPING_ANON. |
397 | */ | 394 | */ |
398 | 395 | ||
399 | struct block_device { | 396 | struct block_device { |
400 | dev_t bd_dev; /* not a kdev_t - it's a search key */ | 397 | dev_t bd_dev; /* not a kdev_t - it's a search key */ |
401 | struct inode * bd_inode; /* will die */ | 398 | struct inode * bd_inode; /* will die */ |
402 | int bd_openers; | 399 | int bd_openers; |
403 | struct semaphore bd_sem; /* open/close mutex */ | 400 | struct semaphore bd_sem; /* open/close mutex */ |
404 | struct semaphore bd_mount_sem; /* mount mutex */ | 401 | struct semaphore bd_mount_sem; /* mount mutex */ |
405 | struct list_head bd_inodes; | 402 | struct list_head bd_inodes; |
406 | void * bd_holder; | 403 | void * bd_holder; |
407 | int bd_holders; | 404 | int bd_holders; |
408 | struct block_device * bd_contains; | 405 | struct block_device * bd_contains; |
409 | unsigned bd_block_size; | 406 | unsigned bd_block_size; |
410 | struct hd_struct * bd_part; | 407 | struct hd_struct * bd_part; |
411 | /* number of times partitions within this device have been opened. */ | 408 | /* number of times partitions within this device have been opened. */ |
412 | unsigned bd_part_count; | 409 | unsigned bd_part_count; |
413 | int bd_invalidated; | 410 | int bd_invalidated; |
414 | struct gendisk * bd_disk; | 411 | struct gendisk * bd_disk; |
415 | struct list_head bd_list; | 412 | struct list_head bd_list; |
416 | struct backing_dev_info *bd_inode_backing_dev_info; | 413 | struct backing_dev_info *bd_inode_backing_dev_info; |
417 | /* | 414 | /* |
418 | * Private data. You must have bd_claim'ed the block_device | 415 | * Private data. You must have bd_claim'ed the block_device |
419 | * to use this. NOTE: bd_claim allows an owner to claim | 416 | * to use this. NOTE: bd_claim allows an owner to claim |
420 | * the same device multiple times, the owner must take special | 417 | * the same device multiple times, the owner must take special |
421 | * care to not mess up bd_private for that case. | 418 | * care to not mess up bd_private for that case. |
422 | */ | 419 | */ |
423 | unsigned long bd_private; | 420 | unsigned long bd_private; |
424 | }; | 421 | }; |
425 | 422 | ||
426 | /* | 423 | /* |
427 | * Radix-tree tags, for tagging dirty and writeback pages within the pagecache | 424 | * Radix-tree tags, for tagging dirty and writeback pages within the pagecache |
428 | * radix trees | 425 | * radix trees |
429 | */ | 426 | */ |
430 | #define PAGECACHE_TAG_DIRTY 0 | 427 | #define PAGECACHE_TAG_DIRTY 0 |
431 | #define PAGECACHE_TAG_WRITEBACK 1 | 428 | #define PAGECACHE_TAG_WRITEBACK 1 |
432 | 429 | ||
433 | int mapping_tagged(struct address_space *mapping, int tag); | 430 | int mapping_tagged(struct address_space *mapping, int tag); |
434 | 431 | ||
435 | /* | 432 | /* |
436 | * Might pages of this file be mapped into userspace? | 433 | * Might pages of this file be mapped into userspace? |
437 | */ | 434 | */ |
438 | static inline int mapping_mapped(struct address_space *mapping) | 435 | static inline int mapping_mapped(struct address_space *mapping) |
439 | { | 436 | { |
440 | return !prio_tree_empty(&mapping->i_mmap) || | 437 | return !prio_tree_empty(&mapping->i_mmap) || |
441 | !list_empty(&mapping->i_mmap_nonlinear); | 438 | !list_empty(&mapping->i_mmap_nonlinear); |
442 | } | 439 | } |
443 | 440 | ||
444 | /* | 441 | /* |
445 | * Might pages of this file have been modified in userspace? | 442 | * Might pages of this file have been modified in userspace? |
446 | * Note that i_mmap_writable counts all VM_SHARED vmas: do_mmap_pgoff | 443 | * Note that i_mmap_writable counts all VM_SHARED vmas: do_mmap_pgoff |
447 | * marks vma as VM_SHARED if it is shared, and the file was opened for | 444 | * marks vma as VM_SHARED if it is shared, and the file was opened for |
448 | * writing i.e. vma may be mprotected writable even if now readonly. | 445 | * writing i.e. vma may be mprotected writable even if now readonly. |
449 | */ | 446 | */ |
450 | static inline int mapping_writably_mapped(struct address_space *mapping) | 447 | static inline int mapping_writably_mapped(struct address_space *mapping) |
451 | { | 448 | { |
452 | return mapping->i_mmap_writable != 0; | 449 | return mapping->i_mmap_writable != 0; |
453 | } | 450 | } |
454 | 451 | ||
455 | /* | 452 | /* |
456 | * Use sequence counter to get consistent i_size on 32-bit processors. | 453 | * Use sequence counter to get consistent i_size on 32-bit processors. |
457 | */ | 454 | */ |
458 | #if BITS_PER_LONG==32 && defined(CONFIG_SMP) | 455 | #if BITS_PER_LONG==32 && defined(CONFIG_SMP) |
459 | #include <linux/seqlock.h> | 456 | #include <linux/seqlock.h> |
460 | #define __NEED_I_SIZE_ORDERED | 457 | #define __NEED_I_SIZE_ORDERED |
461 | #define i_size_ordered_init(inode) seqcount_init(&inode->i_size_seqcount) | 458 | #define i_size_ordered_init(inode) seqcount_init(&inode->i_size_seqcount) |
462 | #else | 459 | #else |
463 | #define i_size_ordered_init(inode) do { } while (0) | 460 | #define i_size_ordered_init(inode) do { } while (0) |
464 | #endif | 461 | #endif |
465 | 462 | ||
466 | struct inode { | 463 | struct inode { |
467 | struct hlist_node i_hash; | 464 | struct hlist_node i_hash; |
468 | struct list_head i_list; | 465 | struct list_head i_list; |
469 | struct list_head i_sb_list; | 466 | struct list_head i_sb_list; |
470 | struct list_head i_dentry; | 467 | struct list_head i_dentry; |
471 | unsigned long i_ino; | 468 | unsigned long i_ino; |
472 | atomic_t i_count; | 469 | atomic_t i_count; |
473 | umode_t i_mode; | 470 | umode_t i_mode; |
474 | unsigned int i_nlink; | 471 | unsigned int i_nlink; |
475 | uid_t i_uid; | 472 | uid_t i_uid; |
476 | gid_t i_gid; | 473 | gid_t i_gid; |
477 | dev_t i_rdev; | 474 | dev_t i_rdev; |
478 | loff_t i_size; | 475 | loff_t i_size; |
479 | struct timespec i_atime; | 476 | struct timespec i_atime; |
480 | struct timespec i_mtime; | 477 | struct timespec i_mtime; |
481 | struct timespec i_ctime; | 478 | struct timespec i_ctime; |
482 | unsigned int i_blkbits; | 479 | unsigned int i_blkbits; |
483 | unsigned long i_blksize; | 480 | unsigned long i_blksize; |
484 | unsigned long i_version; | 481 | unsigned long i_version; |
485 | unsigned long i_blocks; | 482 | unsigned long i_blocks; |
486 | unsigned short i_bytes; | 483 | unsigned short i_bytes; |
487 | spinlock_t i_lock; /* i_blocks, i_bytes, maybe i_size */ | 484 | spinlock_t i_lock; /* i_blocks, i_bytes, maybe i_size */ |
488 | struct mutex i_mutex; | 485 | struct mutex i_mutex; |
489 | struct rw_semaphore i_alloc_sem; | 486 | struct rw_semaphore i_alloc_sem; |
490 | struct inode_operations *i_op; | 487 | struct inode_operations *i_op; |
491 | struct file_operations *i_fop; /* former ->i_op->default_file_ops */ | 488 | struct file_operations *i_fop; /* former ->i_op->default_file_ops */ |
492 | struct super_block *i_sb; | 489 | struct super_block *i_sb; |
493 | struct file_lock *i_flock; | 490 | struct file_lock *i_flock; |
494 | struct address_space *i_mapping; | 491 | struct address_space *i_mapping; |
495 | struct address_space i_data; | 492 | struct address_space i_data; |
496 | #ifdef CONFIG_QUOTA | 493 | #ifdef CONFIG_QUOTA |
497 | struct dquot *i_dquot[MAXQUOTAS]; | 494 | struct dquot *i_dquot[MAXQUOTAS]; |
498 | #endif | 495 | #endif |
499 | /* These three should probably be a union */ | 496 | /* These three should probably be a union */ |
500 | struct list_head i_devices; | 497 | struct list_head i_devices; |
501 | struct pipe_inode_info *i_pipe; | 498 | struct pipe_inode_info *i_pipe; |
502 | struct block_device *i_bdev; | 499 | struct block_device *i_bdev; |
503 | struct cdev *i_cdev; | 500 | struct cdev *i_cdev; |
504 | int i_cindex; | 501 | int i_cindex; |
505 | 502 | ||
506 | __u32 i_generation; | 503 | __u32 i_generation; |
507 | 504 | ||
508 | #ifdef CONFIG_DNOTIFY | 505 | #ifdef CONFIG_DNOTIFY |
509 | unsigned long i_dnotify_mask; /* Directory notify events */ | 506 | unsigned long i_dnotify_mask; /* Directory notify events */ |
510 | struct dnotify_struct *i_dnotify; /* for directory notifications */ | 507 | struct dnotify_struct *i_dnotify; /* for directory notifications */ |
511 | #endif | 508 | #endif |
512 | 509 | ||
513 | #ifdef CONFIG_INOTIFY | 510 | #ifdef CONFIG_INOTIFY |
514 | struct list_head inotify_watches; /* watches on this inode */ | 511 | struct list_head inotify_watches; /* watches on this inode */ |
515 | struct semaphore inotify_sem; /* protects the watches list */ | 512 | struct semaphore inotify_sem; /* protects the watches list */ |
516 | #endif | 513 | #endif |
517 | 514 | ||
518 | unsigned long i_state; | 515 | unsigned long i_state; |
519 | unsigned long dirtied_when; /* jiffies of first dirtying */ | 516 | unsigned long dirtied_when; /* jiffies of first dirtying */ |
520 | 517 | ||
521 | unsigned int i_flags; | 518 | unsigned int i_flags; |
522 | 519 | ||
523 | atomic_t i_writecount; | 520 | atomic_t i_writecount; |
524 | void *i_security; | 521 | void *i_security; |
525 | union { | 522 | union { |
526 | void *generic_ip; | 523 | void *generic_ip; |
527 | } u; | 524 | } u; |
528 | #ifdef __NEED_I_SIZE_ORDERED | 525 | #ifdef __NEED_I_SIZE_ORDERED |
529 | seqcount_t i_size_seqcount; | 526 | seqcount_t i_size_seqcount; |
530 | #endif | 527 | #endif |
531 | }; | 528 | }; |
532 | 529 | ||
533 | /* | 530 | /* |
534 | * NOTE: in a 32bit arch with a preemptable kernel and | 531 | * NOTE: in a 32bit arch with a preemptable kernel and |
535 | * an UP compile the i_size_read/write must be atomic | 532 | * an UP compile the i_size_read/write must be atomic |
536 | * with respect to the local cpu (unlike with preempt disabled), | 533 | * with respect to the local cpu (unlike with preempt disabled), |
537 | * but they don't need to be atomic with respect to other cpus like in | 534 | * but they don't need to be atomic with respect to other cpus like in |
538 | * true SMP (so they need either to either locally disable irq around | 535 | * true SMP (so they need either to either locally disable irq around |
539 | * the read or for example on x86 they can be still implemented as a | 536 | * the read or for example on x86 they can be still implemented as a |
540 | * cmpxchg8b without the need of the lock prefix). For SMP compiles | 537 | * cmpxchg8b without the need of the lock prefix). For SMP compiles |
541 | * and 64bit archs it makes no difference if preempt is enabled or not. | 538 | * and 64bit archs it makes no difference if preempt is enabled or not. |
542 | */ | 539 | */ |
543 | static inline loff_t i_size_read(struct inode *inode) | 540 | static inline loff_t i_size_read(struct inode *inode) |
544 | { | 541 | { |
545 | #if BITS_PER_LONG==32 && defined(CONFIG_SMP) | 542 | #if BITS_PER_LONG==32 && defined(CONFIG_SMP) |
546 | loff_t i_size; | 543 | loff_t i_size; |
547 | unsigned int seq; | 544 | unsigned int seq; |
548 | 545 | ||
549 | do { | 546 | do { |
550 | seq = read_seqcount_begin(&inode->i_size_seqcount); | 547 | seq = read_seqcount_begin(&inode->i_size_seqcount); |
551 | i_size = inode->i_size; | 548 | i_size = inode->i_size; |
552 | } while (read_seqcount_retry(&inode->i_size_seqcount, seq)); | 549 | } while (read_seqcount_retry(&inode->i_size_seqcount, seq)); |
553 | return i_size; | 550 | return i_size; |
554 | #elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPT) | 551 | #elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPT) |
555 | loff_t i_size; | 552 | loff_t i_size; |
556 | 553 | ||
557 | preempt_disable(); | 554 | preempt_disable(); |
558 | i_size = inode->i_size; | 555 | i_size = inode->i_size; |
559 | preempt_enable(); | 556 | preempt_enable(); |
560 | return i_size; | 557 | return i_size; |
561 | #else | 558 | #else |
562 | return inode->i_size; | 559 | return inode->i_size; |
563 | #endif | 560 | #endif |
564 | } | 561 | } |
565 | 562 | ||
566 | 563 | ||
567 | static inline void i_size_write(struct inode *inode, loff_t i_size) | 564 | static inline void i_size_write(struct inode *inode, loff_t i_size) |
568 | { | 565 | { |
569 | #if BITS_PER_LONG==32 && defined(CONFIG_SMP) | 566 | #if BITS_PER_LONG==32 && defined(CONFIG_SMP) |
570 | write_seqcount_begin(&inode->i_size_seqcount); | 567 | write_seqcount_begin(&inode->i_size_seqcount); |
571 | inode->i_size = i_size; | 568 | inode->i_size = i_size; |
572 | write_seqcount_end(&inode->i_size_seqcount); | 569 | write_seqcount_end(&inode->i_size_seqcount); |
573 | #elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPT) | 570 | #elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPT) |
574 | preempt_disable(); | 571 | preempt_disable(); |
575 | inode->i_size = i_size; | 572 | inode->i_size = i_size; |
576 | preempt_enable(); | 573 | preempt_enable(); |
577 | #else | 574 | #else |
578 | inode->i_size = i_size; | 575 | inode->i_size = i_size; |
579 | #endif | 576 | #endif |
580 | } | 577 | } |
581 | 578 | ||
582 | static inline unsigned iminor(struct inode *inode) | 579 | static inline unsigned iminor(struct inode *inode) |
583 | { | 580 | { |
584 | return MINOR(inode->i_rdev); | 581 | return MINOR(inode->i_rdev); |
585 | } | 582 | } |
586 | 583 | ||
587 | static inline unsigned imajor(struct inode *inode) | 584 | static inline unsigned imajor(struct inode *inode) |
588 | { | 585 | { |
589 | return MAJOR(inode->i_rdev); | 586 | return MAJOR(inode->i_rdev); |
590 | } | 587 | } |
591 | 588 | ||
592 | extern struct block_device *I_BDEV(struct inode *inode); | 589 | extern struct block_device *I_BDEV(struct inode *inode); |
593 | 590 | ||
594 | struct fown_struct { | 591 | struct fown_struct { |
595 | rwlock_t lock; /* protects pid, uid, euid fields */ | 592 | rwlock_t lock; /* protects pid, uid, euid fields */ |
596 | int pid; /* pid or -pgrp where SIGIO should be sent */ | 593 | int pid; /* pid or -pgrp where SIGIO should be sent */ |
597 | uid_t uid, euid; /* uid/euid of process setting the owner */ | 594 | uid_t uid, euid; /* uid/euid of process setting the owner */ |
598 | void *security; | 595 | void *security; |
599 | int signum; /* posix.1b rt signal to be delivered on IO */ | 596 | int signum; /* posix.1b rt signal to be delivered on IO */ |
600 | }; | 597 | }; |
601 | 598 | ||
602 | /* | 599 | /* |
603 | * Track a single file's readahead state | 600 | * Track a single file's readahead state |
604 | */ | 601 | */ |
605 | struct file_ra_state { | 602 | struct file_ra_state { |
606 | unsigned long start; /* Current window */ | 603 | unsigned long start; /* Current window */ |
607 | unsigned long size; | 604 | unsigned long size; |
608 | unsigned long flags; /* ra flags RA_FLAG_xxx*/ | 605 | unsigned long flags; /* ra flags RA_FLAG_xxx*/ |
609 | unsigned long cache_hit; /* cache hit count*/ | 606 | unsigned long cache_hit; /* cache hit count*/ |
610 | unsigned long prev_page; /* Cache last read() position */ | 607 | unsigned long prev_page; /* Cache last read() position */ |
611 | unsigned long ahead_start; /* Ahead window */ | 608 | unsigned long ahead_start; /* Ahead window */ |
612 | unsigned long ahead_size; | 609 | unsigned long ahead_size; |
613 | unsigned long ra_pages; /* Maximum readahead window */ | 610 | unsigned long ra_pages; /* Maximum readahead window */ |
614 | unsigned long mmap_hit; /* Cache hit stat for mmap accesses */ | 611 | unsigned long mmap_hit; /* Cache hit stat for mmap accesses */ |
615 | unsigned long mmap_miss; /* Cache miss stat for mmap accesses */ | 612 | unsigned long mmap_miss; /* Cache miss stat for mmap accesses */ |
616 | }; | 613 | }; |
617 | #define RA_FLAG_MISS 0x01 /* a cache miss occured against this file */ | 614 | #define RA_FLAG_MISS 0x01 /* a cache miss occured against this file */ |
618 | #define RA_FLAG_INCACHE 0x02 /* file is already in cache */ | 615 | #define RA_FLAG_INCACHE 0x02 /* file is already in cache */ |
619 | 616 | ||
620 | struct file { | 617 | struct file { |
621 | /* | 618 | /* |
622 | * fu_list becomes invalid after file_free is called and queued via | 619 | * fu_list becomes invalid after file_free is called and queued via |
623 | * fu_rcuhead for RCU freeing | 620 | * fu_rcuhead for RCU freeing |
624 | */ | 621 | */ |
625 | union { | 622 | union { |
626 | struct list_head fu_list; | 623 | struct list_head fu_list; |
627 | struct rcu_head fu_rcuhead; | 624 | struct rcu_head fu_rcuhead; |
628 | } f_u; | 625 | } f_u; |
629 | struct dentry *f_dentry; | 626 | struct dentry *f_dentry; |
630 | struct vfsmount *f_vfsmnt; | 627 | struct vfsmount *f_vfsmnt; |
631 | struct file_operations *f_op; | 628 | struct file_operations *f_op; |
632 | atomic_t f_count; | 629 | atomic_t f_count; |
633 | unsigned int f_flags; | 630 | unsigned int f_flags; |
634 | mode_t f_mode; | 631 | mode_t f_mode; |
635 | loff_t f_pos; | 632 | loff_t f_pos; |
636 | struct fown_struct f_owner; | 633 | struct fown_struct f_owner; |
637 | unsigned int f_uid, f_gid; | 634 | unsigned int f_uid, f_gid; |
638 | struct file_ra_state f_ra; | 635 | struct file_ra_state f_ra; |
639 | 636 | ||
640 | unsigned long f_version; | 637 | unsigned long f_version; |
641 | void *f_security; | 638 | void *f_security; |
642 | 639 | ||
643 | /* needed for tty driver, and maybe others */ | 640 | /* needed for tty driver, and maybe others */ |
644 | void *private_data; | 641 | void *private_data; |
645 | 642 | ||
646 | #ifdef CONFIG_EPOLL | 643 | #ifdef CONFIG_EPOLL |
647 | /* Used by fs/eventpoll.c to link all the hooks to this file */ | 644 | /* Used by fs/eventpoll.c to link all the hooks to this file */ |
648 | struct list_head f_ep_links; | 645 | struct list_head f_ep_links; |
649 | spinlock_t f_ep_lock; | 646 | spinlock_t f_ep_lock; |
650 | #endif /* #ifdef CONFIG_EPOLL */ | 647 | #endif /* #ifdef CONFIG_EPOLL */ |
651 | struct address_space *f_mapping; | 648 | struct address_space *f_mapping; |
652 | }; | 649 | }; |
653 | extern spinlock_t files_lock; | 650 | extern spinlock_t files_lock; |
654 | #define file_list_lock() spin_lock(&files_lock); | 651 | #define file_list_lock() spin_lock(&files_lock); |
655 | #define file_list_unlock() spin_unlock(&files_lock); | 652 | #define file_list_unlock() spin_unlock(&files_lock); |
656 | 653 | ||
657 | #define get_file(x) atomic_inc(&(x)->f_count) | 654 | #define get_file(x) atomic_inc(&(x)->f_count) |
658 | #define file_count(x) atomic_read(&(x)->f_count) | 655 | #define file_count(x) atomic_read(&(x)->f_count) |
659 | 656 | ||
660 | #define MAX_NON_LFS ((1UL<<31) - 1) | 657 | #define MAX_NON_LFS ((1UL<<31) - 1) |
661 | 658 | ||
662 | /* Page cache limit. The filesystems should put that into their s_maxbytes | 659 | /* Page cache limit. The filesystems should put that into their s_maxbytes |
663 | limits, otherwise bad things can happen in VM. */ | 660 | limits, otherwise bad things can happen in VM. */ |
664 | #if BITS_PER_LONG==32 | 661 | #if BITS_PER_LONG==32 |
665 | #define MAX_LFS_FILESIZE (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1) | 662 | #define MAX_LFS_FILESIZE (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1) |
666 | #elif BITS_PER_LONG==64 | 663 | #elif BITS_PER_LONG==64 |
667 | #define MAX_LFS_FILESIZE 0x7fffffffffffffffUL | 664 | #define MAX_LFS_FILESIZE 0x7fffffffffffffffUL |
668 | #endif | 665 | #endif |
669 | 666 | ||
670 | #define FL_POSIX 1 | 667 | #define FL_POSIX 1 |
671 | #define FL_FLOCK 2 | 668 | #define FL_FLOCK 2 |
672 | #define FL_ACCESS 8 /* not trying to lock, just looking */ | 669 | #define FL_ACCESS 8 /* not trying to lock, just looking */ |
673 | #define FL_LOCKD 16 /* lock held by rpc.lockd */ | 670 | #define FL_LOCKD 16 /* lock held by rpc.lockd */ |
674 | #define FL_LEASE 32 /* lease held on this file */ | 671 | #define FL_LEASE 32 /* lease held on this file */ |
675 | #define FL_SLEEP 128 /* A blocking lock */ | 672 | #define FL_SLEEP 128 /* A blocking lock */ |
676 | 673 | ||
677 | /* | 674 | /* |
678 | * The POSIX file lock owner is determined by | 675 | * The POSIX file lock owner is determined by |
679 | * the "struct files_struct" in the thread group | 676 | * the "struct files_struct" in the thread group |
680 | * (or NULL for no owner - BSD locks). | 677 | * (or NULL for no owner - BSD locks). |
681 | * | 678 | * |
682 | * Lockd stuffs a "host" pointer into this. | 679 | * Lockd stuffs a "host" pointer into this. |
683 | */ | 680 | */ |
684 | typedef struct files_struct *fl_owner_t; | 681 | typedef struct files_struct *fl_owner_t; |
685 | 682 | ||
686 | struct file_lock_operations { | 683 | struct file_lock_operations { |
687 | void (*fl_insert)(struct file_lock *); /* lock insertion callback */ | 684 | void (*fl_insert)(struct file_lock *); /* lock insertion callback */ |
688 | void (*fl_remove)(struct file_lock *); /* lock removal callback */ | 685 | void (*fl_remove)(struct file_lock *); /* lock removal callback */ |
689 | void (*fl_copy_lock)(struct file_lock *, struct file_lock *); | 686 | void (*fl_copy_lock)(struct file_lock *, struct file_lock *); |
690 | void (*fl_release_private)(struct file_lock *); | 687 | void (*fl_release_private)(struct file_lock *); |
691 | }; | 688 | }; |
692 | 689 | ||
693 | struct lock_manager_operations { | 690 | struct lock_manager_operations { |
694 | int (*fl_compare_owner)(struct file_lock *, struct file_lock *); | 691 | int (*fl_compare_owner)(struct file_lock *, struct file_lock *); |
695 | void (*fl_notify)(struct file_lock *); /* unblock callback */ | 692 | void (*fl_notify)(struct file_lock *); /* unblock callback */ |
696 | void (*fl_copy_lock)(struct file_lock *, struct file_lock *); | 693 | void (*fl_copy_lock)(struct file_lock *, struct file_lock *); |
697 | void (*fl_release_private)(struct file_lock *); | 694 | void (*fl_release_private)(struct file_lock *); |
698 | void (*fl_break)(struct file_lock *); | 695 | void (*fl_break)(struct file_lock *); |
699 | int (*fl_mylease)(struct file_lock *, struct file_lock *); | 696 | int (*fl_mylease)(struct file_lock *, struct file_lock *); |
700 | int (*fl_change)(struct file_lock **, int); | 697 | int (*fl_change)(struct file_lock **, int); |
701 | }; | 698 | }; |
702 | 699 | ||
703 | /* that will die - we need it for nfs_lock_info */ | 700 | /* that will die - we need it for nfs_lock_info */ |
704 | #include <linux/nfs_fs_i.h> | 701 | #include <linux/nfs_fs_i.h> |
705 | 702 | ||
706 | struct file_lock { | 703 | struct file_lock { |
707 | struct file_lock *fl_next; /* singly linked list for this inode */ | 704 | struct file_lock *fl_next; /* singly linked list for this inode */ |
708 | struct list_head fl_link; /* doubly linked list of all locks */ | 705 | struct list_head fl_link; /* doubly linked list of all locks */ |
709 | struct list_head fl_block; /* circular list of blocked processes */ | 706 | struct list_head fl_block; /* circular list of blocked processes */ |
710 | fl_owner_t fl_owner; | 707 | fl_owner_t fl_owner; |
711 | unsigned int fl_pid; | 708 | unsigned int fl_pid; |
712 | wait_queue_head_t fl_wait; | 709 | wait_queue_head_t fl_wait; |
713 | struct file *fl_file; | 710 | struct file *fl_file; |
714 | unsigned char fl_flags; | 711 | unsigned char fl_flags; |
715 | unsigned char fl_type; | 712 | unsigned char fl_type; |
716 | loff_t fl_start; | 713 | loff_t fl_start; |
717 | loff_t fl_end; | 714 | loff_t fl_end; |
718 | 715 | ||
719 | struct fasync_struct * fl_fasync; /* for lease break notifications */ | 716 | struct fasync_struct * fl_fasync; /* for lease break notifications */ |
720 | unsigned long fl_break_time; /* for nonblocking lease breaks */ | 717 | unsigned long fl_break_time; /* for nonblocking lease breaks */ |
721 | 718 | ||
722 | struct file_lock_operations *fl_ops; /* Callbacks for filesystems */ | 719 | struct file_lock_operations *fl_ops; /* Callbacks for filesystems */ |
723 | struct lock_manager_operations *fl_lmops; /* Callbacks for lockmanagers */ | 720 | struct lock_manager_operations *fl_lmops; /* Callbacks for lockmanagers */ |
724 | union { | 721 | union { |
725 | struct nfs_lock_info nfs_fl; | 722 | struct nfs_lock_info nfs_fl; |
726 | struct nfs4_lock_info nfs4_fl; | 723 | struct nfs4_lock_info nfs4_fl; |
727 | } fl_u; | 724 | } fl_u; |
728 | }; | 725 | }; |
729 | 726 | ||
730 | /* The following constant reflects the upper bound of the file/locking space */ | 727 | /* The following constant reflects the upper bound of the file/locking space */ |
731 | #ifndef OFFSET_MAX | 728 | #ifndef OFFSET_MAX |
732 | #define INT_LIMIT(x) (~((x)1 << (sizeof(x)*8 - 1))) | 729 | #define INT_LIMIT(x) (~((x)1 << (sizeof(x)*8 - 1))) |
733 | #define OFFSET_MAX INT_LIMIT(loff_t) | 730 | #define OFFSET_MAX INT_LIMIT(loff_t) |
734 | #define OFFT_OFFSET_MAX INT_LIMIT(off_t) | 731 | #define OFFT_OFFSET_MAX INT_LIMIT(off_t) |
735 | #endif | 732 | #endif |
736 | 733 | ||
737 | extern struct list_head file_lock_list; | 734 | extern struct list_head file_lock_list; |
738 | 735 | ||
739 | #include <linux/fcntl.h> | 736 | #include <linux/fcntl.h> |
740 | 737 | ||
741 | extern int fcntl_getlk(struct file *, struct flock __user *); | 738 | extern int fcntl_getlk(struct file *, struct flock __user *); |
742 | extern int fcntl_setlk(unsigned int, struct file *, unsigned int, | 739 | extern int fcntl_setlk(unsigned int, struct file *, unsigned int, |
743 | struct flock __user *); | 740 | struct flock __user *); |
744 | 741 | ||
745 | #if BITS_PER_LONG == 32 | 742 | #if BITS_PER_LONG == 32 |
746 | extern int fcntl_getlk64(struct file *, struct flock64 __user *); | 743 | extern int fcntl_getlk64(struct file *, struct flock64 __user *); |
747 | extern int fcntl_setlk64(unsigned int, struct file *, unsigned int, | 744 | extern int fcntl_setlk64(unsigned int, struct file *, unsigned int, |
748 | struct flock64 __user *); | 745 | struct flock64 __user *); |
749 | #endif | 746 | #endif |
750 | 747 | ||
751 | extern void send_sigio(struct fown_struct *fown, int fd, int band); | 748 | extern void send_sigio(struct fown_struct *fown, int fd, int band); |
752 | extern int fcntl_setlease(unsigned int fd, struct file *filp, long arg); | 749 | extern int fcntl_setlease(unsigned int fd, struct file *filp, long arg); |
753 | extern int fcntl_getlease(struct file *filp); | 750 | extern int fcntl_getlease(struct file *filp); |
754 | 751 | ||
755 | /* fs/locks.c */ | 752 | /* fs/locks.c */ |
756 | extern void locks_init_lock(struct file_lock *); | 753 | extern void locks_init_lock(struct file_lock *); |
757 | extern void locks_copy_lock(struct file_lock *, struct file_lock *); | 754 | extern void locks_copy_lock(struct file_lock *, struct file_lock *); |
758 | extern void locks_remove_posix(struct file *, fl_owner_t); | 755 | extern void locks_remove_posix(struct file *, fl_owner_t); |
759 | extern void locks_remove_flock(struct file *); | 756 | extern void locks_remove_flock(struct file *); |
760 | extern struct file_lock *posix_test_lock(struct file *, struct file_lock *); | 757 | extern struct file_lock *posix_test_lock(struct file *, struct file_lock *); |
761 | extern int posix_lock_file(struct file *, struct file_lock *); | 758 | extern int posix_lock_file(struct file *, struct file_lock *); |
762 | extern int posix_lock_file_wait(struct file *, struct file_lock *); | 759 | extern int posix_lock_file_wait(struct file *, struct file_lock *); |
763 | extern void posix_block_lock(struct file_lock *, struct file_lock *); | 760 | extern void posix_block_lock(struct file_lock *, struct file_lock *); |
764 | extern int posix_unblock_lock(struct file *, struct file_lock *); | 761 | extern int posix_unblock_lock(struct file *, struct file_lock *); |
765 | extern int posix_locks_deadlock(struct file_lock *, struct file_lock *); | 762 | extern int posix_locks_deadlock(struct file_lock *, struct file_lock *); |
766 | extern int flock_lock_file_wait(struct file *filp, struct file_lock *fl); | 763 | extern int flock_lock_file_wait(struct file *filp, struct file_lock *fl); |
767 | extern int __break_lease(struct inode *inode, unsigned int flags); | 764 | extern int __break_lease(struct inode *inode, unsigned int flags); |
768 | extern void lease_get_mtime(struct inode *, struct timespec *time); | 765 | extern void lease_get_mtime(struct inode *, struct timespec *time); |
769 | extern int setlease(struct file *, long, struct file_lock **); | 766 | extern int setlease(struct file *, long, struct file_lock **); |
770 | extern int lease_modify(struct file_lock **, int); | 767 | extern int lease_modify(struct file_lock **, int); |
771 | extern int lock_may_read(struct inode *, loff_t start, unsigned long count); | 768 | extern int lock_may_read(struct inode *, loff_t start, unsigned long count); |
772 | extern int lock_may_write(struct inode *, loff_t start, unsigned long count); | 769 | extern int lock_may_write(struct inode *, loff_t start, unsigned long count); |
773 | extern void steal_locks(fl_owner_t from); | 770 | extern void steal_locks(fl_owner_t from); |
774 | 771 | ||
775 | struct fasync_struct { | 772 | struct fasync_struct { |
776 | int magic; | 773 | int magic; |
777 | int fa_fd; | 774 | int fa_fd; |
778 | struct fasync_struct *fa_next; /* singly linked list */ | 775 | struct fasync_struct *fa_next; /* singly linked list */ |
779 | struct file *fa_file; | 776 | struct file *fa_file; |
780 | }; | 777 | }; |
781 | 778 | ||
782 | #define FASYNC_MAGIC 0x4601 | 779 | #define FASYNC_MAGIC 0x4601 |
783 | 780 | ||
784 | /* SMP safe fasync helpers: */ | 781 | /* SMP safe fasync helpers: */ |
785 | extern int fasync_helper(int, struct file *, int, struct fasync_struct **); | 782 | extern int fasync_helper(int, struct file *, int, struct fasync_struct **); |
786 | /* can be called from interrupts */ | 783 | /* can be called from interrupts */ |
787 | extern void kill_fasync(struct fasync_struct **, int, int); | 784 | extern void kill_fasync(struct fasync_struct **, int, int); |
788 | /* only for net: no internal synchronization */ | 785 | /* only for net: no internal synchronization */ |
789 | extern void __kill_fasync(struct fasync_struct *, int, int); | 786 | extern void __kill_fasync(struct fasync_struct *, int, int); |
790 | 787 | ||
791 | extern int f_setown(struct file *filp, unsigned long arg, int force); | 788 | extern int f_setown(struct file *filp, unsigned long arg, int force); |
792 | extern void f_delown(struct file *filp); | 789 | extern void f_delown(struct file *filp); |
793 | extern int send_sigurg(struct fown_struct *fown); | 790 | extern int send_sigurg(struct fown_struct *fown); |
794 | 791 | ||
795 | /* | 792 | /* |
796 | * Umount options | 793 | * Umount options |
797 | */ | 794 | */ |
798 | 795 | ||
799 | #define MNT_FORCE 0x00000001 /* Attempt to forcibily umount */ | 796 | #define MNT_FORCE 0x00000001 /* Attempt to forcibily umount */ |
800 | #define MNT_DETACH 0x00000002 /* Just detach from the tree */ | 797 | #define MNT_DETACH 0x00000002 /* Just detach from the tree */ |
801 | #define MNT_EXPIRE 0x00000004 /* Mark for expiry */ | 798 | #define MNT_EXPIRE 0x00000004 /* Mark for expiry */ |
802 | 799 | ||
803 | extern struct list_head super_blocks; | 800 | extern struct list_head super_blocks; |
804 | extern spinlock_t sb_lock; | 801 | extern spinlock_t sb_lock; |
805 | 802 | ||
806 | #define sb_entry(list) list_entry((list), struct super_block, s_list) | 803 | #define sb_entry(list) list_entry((list), struct super_block, s_list) |
807 | #define S_BIAS (1<<30) | 804 | #define S_BIAS (1<<30) |
808 | struct super_block { | 805 | struct super_block { |
809 | struct list_head s_list; /* Keep this first */ | 806 | struct list_head s_list; /* Keep this first */ |
810 | dev_t s_dev; /* search index; _not_ kdev_t */ | 807 | dev_t s_dev; /* search index; _not_ kdev_t */ |
811 | unsigned long s_blocksize; | 808 | unsigned long s_blocksize; |
812 | unsigned char s_blocksize_bits; | 809 | unsigned char s_blocksize_bits; |
813 | unsigned char s_dirt; | 810 | unsigned char s_dirt; |
814 | unsigned long long s_maxbytes; /* Max file size */ | 811 | unsigned long long s_maxbytes; /* Max file size */ |
815 | struct file_system_type *s_type; | 812 | struct file_system_type *s_type; |
816 | struct super_operations *s_op; | 813 | struct super_operations *s_op; |
817 | struct dquot_operations *dq_op; | 814 | struct dquot_operations *dq_op; |
818 | struct quotactl_ops *s_qcop; | 815 | struct quotactl_ops *s_qcop; |
819 | struct export_operations *s_export_op; | 816 | struct export_operations *s_export_op; |
820 | unsigned long s_flags; | 817 | unsigned long s_flags; |
821 | unsigned long s_magic; | 818 | unsigned long s_magic; |
822 | struct dentry *s_root; | 819 | struct dentry *s_root; |
823 | struct rw_semaphore s_umount; | 820 | struct rw_semaphore s_umount; |
824 | struct mutex s_lock; | 821 | struct mutex s_lock; |
825 | int s_count; | 822 | int s_count; |
826 | int s_syncing; | 823 | int s_syncing; |
827 | int s_need_sync_fs; | 824 | int s_need_sync_fs; |
828 | atomic_t s_active; | 825 | atomic_t s_active; |
829 | void *s_security; | 826 | void *s_security; |
830 | struct xattr_handler **s_xattr; | 827 | struct xattr_handler **s_xattr; |
831 | 828 | ||
832 | struct list_head s_inodes; /* all inodes */ | 829 | struct list_head s_inodes; /* all inodes */ |
833 | struct list_head s_dirty; /* dirty inodes */ | 830 | struct list_head s_dirty; /* dirty inodes */ |
834 | struct list_head s_io; /* parked for writeback */ | 831 | struct list_head s_io; /* parked for writeback */ |
835 | struct hlist_head s_anon; /* anonymous dentries for (nfs) exporting */ | 832 | struct hlist_head s_anon; /* anonymous dentries for (nfs) exporting */ |
836 | struct list_head s_files; | 833 | struct list_head s_files; |
837 | 834 | ||
838 | struct block_device *s_bdev; | 835 | struct block_device *s_bdev; |
839 | struct list_head s_instances; | 836 | struct list_head s_instances; |
840 | struct quota_info s_dquot; /* Diskquota specific options */ | 837 | struct quota_info s_dquot; /* Diskquota specific options */ |
841 | 838 | ||
842 | int s_frozen; | 839 | int s_frozen; |
843 | wait_queue_head_t s_wait_unfrozen; | 840 | wait_queue_head_t s_wait_unfrozen; |
844 | 841 | ||
845 | char s_id[32]; /* Informational name */ | 842 | char s_id[32]; /* Informational name */ |
846 | 843 | ||
847 | void *s_fs_info; /* Filesystem private info */ | 844 | void *s_fs_info; /* Filesystem private info */ |
848 | 845 | ||
849 | /* | 846 | /* |
850 | * The next field is for VFS *only*. No filesystems have any business | 847 | * The next field is for VFS *only*. No filesystems have any business |
851 | * even looking at it. You had been warned. | 848 | * even looking at it. You had been warned. |
852 | */ | 849 | */ |
853 | struct semaphore s_vfs_rename_sem; /* Kludge */ | 850 | struct semaphore s_vfs_rename_sem; /* Kludge */ |
854 | 851 | ||
855 | /* Granuality of c/m/atime in ns. | 852 | /* Granuality of c/m/atime in ns. |
856 | Cannot be worse than a second */ | 853 | Cannot be worse than a second */ |
857 | u32 s_time_gran; | 854 | u32 s_time_gran; |
858 | }; | 855 | }; |
859 | 856 | ||
860 | extern struct timespec current_fs_time(struct super_block *sb); | 857 | extern struct timespec current_fs_time(struct super_block *sb); |
861 | 858 | ||
862 | /* | 859 | /* |
863 | * Snapshotting support. | 860 | * Snapshotting support. |
864 | */ | 861 | */ |
865 | enum { | 862 | enum { |
866 | SB_UNFROZEN = 0, | 863 | SB_UNFROZEN = 0, |
867 | SB_FREEZE_WRITE = 1, | 864 | SB_FREEZE_WRITE = 1, |
868 | SB_FREEZE_TRANS = 2, | 865 | SB_FREEZE_TRANS = 2, |
869 | }; | 866 | }; |
870 | 867 | ||
871 | #define vfs_check_frozen(sb, level) \ | 868 | #define vfs_check_frozen(sb, level) \ |
872 | wait_event((sb)->s_wait_unfrozen, ((sb)->s_frozen < (level))) | 869 | wait_event((sb)->s_wait_unfrozen, ((sb)->s_frozen < (level))) |
873 | 870 | ||
874 | static inline void get_fs_excl(void) | 871 | static inline void get_fs_excl(void) |
875 | { | 872 | { |
876 | atomic_inc(¤t->fs_excl); | 873 | atomic_inc(¤t->fs_excl); |
877 | } | 874 | } |
878 | 875 | ||
879 | static inline void put_fs_excl(void) | 876 | static inline void put_fs_excl(void) |
880 | { | 877 | { |
881 | atomic_dec(¤t->fs_excl); | 878 | atomic_dec(¤t->fs_excl); |
882 | } | 879 | } |
883 | 880 | ||
884 | static inline int has_fs_excl(void) | 881 | static inline int has_fs_excl(void) |
885 | { | 882 | { |
886 | return atomic_read(¤t->fs_excl); | 883 | return atomic_read(¤t->fs_excl); |
887 | } | 884 | } |
888 | 885 | ||
889 | 886 | ||
890 | /* | 887 | /* |
891 | * Superblock locking. | 888 | * Superblock locking. |
892 | */ | 889 | */ |
893 | static inline void lock_super(struct super_block * sb) | 890 | static inline void lock_super(struct super_block * sb) |
894 | { | 891 | { |
895 | get_fs_excl(); | 892 | get_fs_excl(); |
896 | mutex_lock(&sb->s_lock); | 893 | mutex_lock(&sb->s_lock); |
897 | } | 894 | } |
898 | 895 | ||
899 | static inline void unlock_super(struct super_block * sb) | 896 | static inline void unlock_super(struct super_block * sb) |
900 | { | 897 | { |
901 | put_fs_excl(); | 898 | put_fs_excl(); |
902 | mutex_unlock(&sb->s_lock); | 899 | mutex_unlock(&sb->s_lock); |
903 | } | 900 | } |
904 | 901 | ||
905 | /* | 902 | /* |
906 | * VFS helper functions.. | 903 | * VFS helper functions.. |
907 | */ | 904 | */ |
908 | extern int vfs_permission(struct nameidata *, int); | 905 | extern int vfs_permission(struct nameidata *, int); |
909 | extern int vfs_create(struct inode *, struct dentry *, int, struct nameidata *); | 906 | extern int vfs_create(struct inode *, struct dentry *, int, struct nameidata *); |
910 | extern int vfs_mkdir(struct inode *, struct dentry *, int); | 907 | extern int vfs_mkdir(struct inode *, struct dentry *, int); |
911 | extern int vfs_mknod(struct inode *, struct dentry *, int, dev_t); | 908 | extern int vfs_mknod(struct inode *, struct dentry *, int, dev_t); |
912 | extern int vfs_symlink(struct inode *, struct dentry *, const char *, int); | 909 | extern int vfs_symlink(struct inode *, struct dentry *, const char *, int); |
913 | extern int vfs_link(struct dentry *, struct inode *, struct dentry *); | 910 | extern int vfs_link(struct dentry *, struct inode *, struct dentry *); |
914 | extern int vfs_rmdir(struct inode *, struct dentry *); | 911 | extern int vfs_rmdir(struct inode *, struct dentry *); |
915 | extern int vfs_unlink(struct inode *, struct dentry *); | 912 | extern int vfs_unlink(struct inode *, struct dentry *); |
916 | extern int vfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *); | 913 | extern int vfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *); |
917 | 914 | ||
918 | /* | 915 | /* |
919 | * VFS dentry helper functions. | 916 | * VFS dentry helper functions. |
920 | */ | 917 | */ |
921 | extern void dentry_unhash(struct dentry *dentry); | 918 | extern void dentry_unhash(struct dentry *dentry); |
922 | 919 | ||
923 | /* | 920 | /* |
924 | * VFS file helper functions. | 921 | * VFS file helper functions. |
925 | */ | 922 | */ |
926 | extern int file_permission(struct file *, int); | 923 | extern int file_permission(struct file *, int); |
927 | 924 | ||
928 | /* | 925 | /* |
929 | * File types | 926 | * File types |
930 | * | 927 | * |
931 | * NOTE! These match bits 12..15 of stat.st_mode | 928 | * NOTE! These match bits 12..15 of stat.st_mode |
932 | * (ie "(i_mode >> 12) & 15"). | 929 | * (ie "(i_mode >> 12) & 15"). |
933 | */ | 930 | */ |
934 | #define DT_UNKNOWN 0 | 931 | #define DT_UNKNOWN 0 |
935 | #define DT_FIFO 1 | 932 | #define DT_FIFO 1 |
936 | #define DT_CHR 2 | 933 | #define DT_CHR 2 |
937 | #define DT_DIR 4 | 934 | #define DT_DIR 4 |
938 | #define DT_BLK 6 | 935 | #define DT_BLK 6 |
939 | #define DT_REG 8 | 936 | #define DT_REG 8 |
940 | #define DT_LNK 10 | 937 | #define DT_LNK 10 |
941 | #define DT_SOCK 12 | 938 | #define DT_SOCK 12 |
942 | #define DT_WHT 14 | 939 | #define DT_WHT 14 |
943 | 940 | ||
944 | #define OSYNC_METADATA (1<<0) | 941 | #define OSYNC_METADATA (1<<0) |
945 | #define OSYNC_DATA (1<<1) | 942 | #define OSYNC_DATA (1<<1) |
946 | #define OSYNC_INODE (1<<2) | 943 | #define OSYNC_INODE (1<<2) |
947 | int generic_osync_inode(struct inode *, struct address_space *, int); | 944 | int generic_osync_inode(struct inode *, struct address_space *, int); |
948 | 945 | ||
949 | /* | 946 | /* |
950 | * This is the "filldir" function type, used by readdir() to let | 947 | * This is the "filldir" function type, used by readdir() to let |
951 | * the kernel specify what kind of dirent layout it wants to have. | 948 | * the kernel specify what kind of dirent layout it wants to have. |
952 | * This allows the kernel to read directories into kernel space or | 949 | * This allows the kernel to read directories into kernel space or |
953 | * to have different dirent layouts depending on the binary type. | 950 | * to have different dirent layouts depending on the binary type. |
954 | */ | 951 | */ |
955 | typedef int (*filldir_t)(void *, const char *, int, loff_t, ino_t, unsigned); | 952 | typedef int (*filldir_t)(void *, const char *, int, loff_t, ino_t, unsigned); |
956 | 953 | ||
957 | struct block_device_operations { | 954 | struct block_device_operations { |
958 | int (*open) (struct inode *, struct file *); | 955 | int (*open) (struct inode *, struct file *); |
959 | int (*release) (struct inode *, struct file *); | 956 | int (*release) (struct inode *, struct file *); |
960 | int (*ioctl) (struct inode *, struct file *, unsigned, unsigned long); | 957 | int (*ioctl) (struct inode *, struct file *, unsigned, unsigned long); |
961 | long (*unlocked_ioctl) (struct file *, unsigned, unsigned long); | 958 | long (*unlocked_ioctl) (struct file *, unsigned, unsigned long); |
962 | long (*compat_ioctl) (struct file *, unsigned, unsigned long); | 959 | long (*compat_ioctl) (struct file *, unsigned, unsigned long); |
963 | int (*direct_access) (struct block_device *, sector_t, unsigned long *); | 960 | int (*direct_access) (struct block_device *, sector_t, unsigned long *); |
964 | int (*media_changed) (struct gendisk *); | 961 | int (*media_changed) (struct gendisk *); |
965 | int (*revalidate_disk) (struct gendisk *); | 962 | int (*revalidate_disk) (struct gendisk *); |
966 | int (*getgeo)(struct block_device *, struct hd_geometry *); | 963 | int (*getgeo)(struct block_device *, struct hd_geometry *); |
967 | struct module *owner; | 964 | struct module *owner; |
968 | }; | 965 | }; |
969 | 966 | ||
970 | /* | 967 | /* |
971 | * "descriptor" for what we're up to with a read for sendfile(). | 968 | * "descriptor" for what we're up to with a read for sendfile(). |
972 | * This allows us to use the same read code yet | 969 | * This allows us to use the same read code yet |
973 | * have multiple different users of the data that | 970 | * have multiple different users of the data that |
974 | * we read from a file. | 971 | * we read from a file. |
975 | * | 972 | * |
976 | * The simplest case just copies the data to user | 973 | * The simplest case just copies the data to user |
977 | * mode. | 974 | * mode. |
978 | */ | 975 | */ |
979 | typedef struct { | 976 | typedef struct { |
980 | size_t written; | 977 | size_t written; |
981 | size_t count; | 978 | size_t count; |
982 | union { | 979 | union { |
983 | char __user * buf; | 980 | char __user * buf; |
984 | void *data; | 981 | void *data; |
985 | } arg; | 982 | } arg; |
986 | int error; | 983 | int error; |
987 | } read_descriptor_t; | 984 | } read_descriptor_t; |
988 | 985 | ||
989 | typedef int (*read_actor_t)(read_descriptor_t *, struct page *, unsigned long, unsigned long); | 986 | typedef int (*read_actor_t)(read_descriptor_t *, struct page *, unsigned long, unsigned long); |
990 | 987 | ||
991 | /* These macros are for out of kernel modules to test that | 988 | /* These macros are for out of kernel modules to test that |
992 | * the kernel supports the unlocked_ioctl and compat_ioctl | 989 | * the kernel supports the unlocked_ioctl and compat_ioctl |
993 | * fields in struct file_operations. */ | 990 | * fields in struct file_operations. */ |
994 | #define HAVE_COMPAT_IOCTL 1 | 991 | #define HAVE_COMPAT_IOCTL 1 |
995 | #define HAVE_UNLOCKED_IOCTL 1 | 992 | #define HAVE_UNLOCKED_IOCTL 1 |
996 | 993 | ||
997 | /* | 994 | /* |
998 | * NOTE: | 995 | * NOTE: |
999 | * read, write, poll, fsync, readv, writev, unlocked_ioctl and compat_ioctl | 996 | * read, write, poll, fsync, readv, writev, unlocked_ioctl and compat_ioctl |
1000 | * can be called without the big kernel lock held in all filesystems. | 997 | * can be called without the big kernel lock held in all filesystems. |
1001 | */ | 998 | */ |
1002 | struct file_operations { | 999 | struct file_operations { |
1003 | struct module *owner; | 1000 | struct module *owner; |
1004 | loff_t (*llseek) (struct file *, loff_t, int); | 1001 | loff_t (*llseek) (struct file *, loff_t, int); |
1005 | ssize_t (*read) (struct file *, char __user *, size_t, loff_t *); | 1002 | ssize_t (*read) (struct file *, char __user *, size_t, loff_t *); |
1006 | ssize_t (*aio_read) (struct kiocb *, char __user *, size_t, loff_t); | 1003 | ssize_t (*aio_read) (struct kiocb *, char __user *, size_t, loff_t); |
1007 | ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *); | 1004 | ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *); |
1008 | ssize_t (*aio_write) (struct kiocb *, const char __user *, size_t, loff_t); | 1005 | ssize_t (*aio_write) (struct kiocb *, const char __user *, size_t, loff_t); |
1009 | int (*readdir) (struct file *, void *, filldir_t); | 1006 | int (*readdir) (struct file *, void *, filldir_t); |
1010 | unsigned int (*poll) (struct file *, struct poll_table_struct *); | 1007 | unsigned int (*poll) (struct file *, struct poll_table_struct *); |
1011 | int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long); | 1008 | int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long); |
1012 | long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long); | 1009 | long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long); |
1013 | long (*compat_ioctl) (struct file *, unsigned int, unsigned long); | 1010 | long (*compat_ioctl) (struct file *, unsigned int, unsigned long); |
1014 | int (*mmap) (struct file *, struct vm_area_struct *); | 1011 | int (*mmap) (struct file *, struct vm_area_struct *); |
1015 | int (*open) (struct inode *, struct file *); | 1012 | int (*open) (struct inode *, struct file *); |
1016 | int (*flush) (struct file *); | 1013 | int (*flush) (struct file *); |
1017 | int (*release) (struct inode *, struct file *); | 1014 | int (*release) (struct inode *, struct file *); |
1018 | int (*fsync) (struct file *, struct dentry *, int datasync); | 1015 | int (*fsync) (struct file *, struct dentry *, int datasync); |
1019 | int (*aio_fsync) (struct kiocb *, int datasync); | 1016 | int (*aio_fsync) (struct kiocb *, int datasync); |
1020 | int (*fasync) (int, struct file *, int); | 1017 | int (*fasync) (int, struct file *, int); |
1021 | int (*lock) (struct file *, int, struct file_lock *); | 1018 | int (*lock) (struct file *, int, struct file_lock *); |
1022 | ssize_t (*readv) (struct file *, const struct iovec *, unsigned long, loff_t *); | 1019 | ssize_t (*readv) (struct file *, const struct iovec *, unsigned long, loff_t *); |
1023 | ssize_t (*writev) (struct file *, const struct iovec *, unsigned long, loff_t *); | 1020 | ssize_t (*writev) (struct file *, const struct iovec *, unsigned long, loff_t *); |
1024 | ssize_t (*sendfile) (struct file *, loff_t *, size_t, read_actor_t, void *); | 1021 | ssize_t (*sendfile) (struct file *, loff_t *, size_t, read_actor_t, void *); |
1025 | ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int); | 1022 | ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int); |
1026 | unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long); | 1023 | unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long); |
1027 | int (*check_flags)(int); | 1024 | int (*check_flags)(int); |
1028 | int (*dir_notify)(struct file *filp, unsigned long arg); | 1025 | int (*dir_notify)(struct file *filp, unsigned long arg); |
1029 | int (*flock) (struct file *, int, struct file_lock *); | 1026 | int (*flock) (struct file *, int, struct file_lock *); |
1030 | }; | 1027 | }; |
1031 | 1028 | ||
1032 | struct inode_operations { | 1029 | struct inode_operations { |
1033 | int (*create) (struct inode *,struct dentry *,int, struct nameidata *); | 1030 | int (*create) (struct inode *,struct dentry *,int, struct nameidata *); |
1034 | struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *); | 1031 | struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *); |
1035 | int (*link) (struct dentry *,struct inode *,struct dentry *); | 1032 | int (*link) (struct dentry *,struct inode *,struct dentry *); |
1036 | int (*unlink) (struct inode *,struct dentry *); | 1033 | int (*unlink) (struct inode *,struct dentry *); |
1037 | int (*symlink) (struct inode *,struct dentry *,const char *); | 1034 | int (*symlink) (struct inode *,struct dentry *,const char *); |
1038 | int (*mkdir) (struct inode *,struct dentry *,int); | 1035 | int (*mkdir) (struct inode *,struct dentry *,int); |
1039 | int (*rmdir) (struct inode *,struct dentry *); | 1036 | int (*rmdir) (struct inode *,struct dentry *); |
1040 | int (*mknod) (struct inode *,struct dentry *,int,dev_t); | 1037 | int (*mknod) (struct inode *,struct dentry *,int,dev_t); |
1041 | int (*rename) (struct inode *, struct dentry *, | 1038 | int (*rename) (struct inode *, struct dentry *, |
1042 | struct inode *, struct dentry *); | 1039 | struct inode *, struct dentry *); |
1043 | int (*readlink) (struct dentry *, char __user *,int); | 1040 | int (*readlink) (struct dentry *, char __user *,int); |
1044 | void * (*follow_link) (struct dentry *, struct nameidata *); | 1041 | void * (*follow_link) (struct dentry *, struct nameidata *); |
1045 | void (*put_link) (struct dentry *, struct nameidata *, void *); | 1042 | void (*put_link) (struct dentry *, struct nameidata *, void *); |
1046 | void (*truncate) (struct inode *); | 1043 | void (*truncate) (struct inode *); |
1047 | int (*permission) (struct inode *, int, struct nameidata *); | 1044 | int (*permission) (struct inode *, int, struct nameidata *); |
1048 | int (*setattr) (struct dentry *, struct iattr *); | 1045 | int (*setattr) (struct dentry *, struct iattr *); |
1049 | int (*getattr) (struct vfsmount *mnt, struct dentry *, struct kstat *); | 1046 | int (*getattr) (struct vfsmount *mnt, struct dentry *, struct kstat *); |
1050 | int (*setxattr) (struct dentry *, const char *,const void *,size_t,int); | 1047 | int (*setxattr) (struct dentry *, const char *,const void *,size_t,int); |
1051 | ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t); | 1048 | ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t); |
1052 | ssize_t (*listxattr) (struct dentry *, char *, size_t); | 1049 | ssize_t (*listxattr) (struct dentry *, char *, size_t); |
1053 | int (*removexattr) (struct dentry *, const char *); | 1050 | int (*removexattr) (struct dentry *, const char *); |
1054 | void (*truncate_range)(struct inode *, loff_t, loff_t); | 1051 | void (*truncate_range)(struct inode *, loff_t, loff_t); |
1055 | }; | 1052 | }; |
1056 | 1053 | ||
1057 | struct seq_file; | 1054 | struct seq_file; |
1058 | 1055 | ||
1059 | extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *); | 1056 | extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *); |
1060 | extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *); | 1057 | extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *); |
1061 | extern ssize_t vfs_readv(struct file *, const struct iovec __user *, | 1058 | extern ssize_t vfs_readv(struct file *, const struct iovec __user *, |
1062 | unsigned long, loff_t *); | 1059 | unsigned long, loff_t *); |
1063 | extern ssize_t vfs_writev(struct file *, const struct iovec __user *, | 1060 | extern ssize_t vfs_writev(struct file *, const struct iovec __user *, |
1064 | unsigned long, loff_t *); | 1061 | unsigned long, loff_t *); |
1065 | 1062 | ||
1066 | /* | 1063 | /* |
1067 | * NOTE: write_inode, delete_inode, clear_inode, put_inode can be called | 1064 | * NOTE: write_inode, delete_inode, clear_inode, put_inode can be called |
1068 | * without the big kernel lock held in all filesystems. | 1065 | * without the big kernel lock held in all filesystems. |
1069 | */ | 1066 | */ |
1070 | struct super_operations { | 1067 | struct super_operations { |
1071 | struct inode *(*alloc_inode)(struct super_block *sb); | 1068 | struct inode *(*alloc_inode)(struct super_block *sb); |
1072 | void (*destroy_inode)(struct inode *); | 1069 | void (*destroy_inode)(struct inode *); |
1073 | 1070 | ||
1074 | void (*read_inode) (struct inode *); | 1071 | void (*read_inode) (struct inode *); |
1075 | 1072 | ||
1076 | void (*dirty_inode) (struct inode *); | 1073 | void (*dirty_inode) (struct inode *); |
1077 | int (*write_inode) (struct inode *, int); | 1074 | int (*write_inode) (struct inode *, int); |
1078 | void (*put_inode) (struct inode *); | 1075 | void (*put_inode) (struct inode *); |
1079 | void (*drop_inode) (struct inode *); | 1076 | void (*drop_inode) (struct inode *); |
1080 | void (*delete_inode) (struct inode *); | 1077 | void (*delete_inode) (struct inode *); |
1081 | void (*put_super) (struct super_block *); | 1078 | void (*put_super) (struct super_block *); |
1082 | void (*write_super) (struct super_block *); | 1079 | void (*write_super) (struct super_block *); |
1083 | int (*sync_fs)(struct super_block *sb, int wait); | 1080 | int (*sync_fs)(struct super_block *sb, int wait); |
1084 | void (*write_super_lockfs) (struct super_block *); | 1081 | void (*write_super_lockfs) (struct super_block *); |
1085 | void (*unlockfs) (struct super_block *); | 1082 | void (*unlockfs) (struct super_block *); |
1086 | int (*statfs) (struct super_block *, struct kstatfs *); | 1083 | int (*statfs) (struct super_block *, struct kstatfs *); |
1087 | int (*remount_fs) (struct super_block *, int *, char *); | 1084 | int (*remount_fs) (struct super_block *, int *, char *); |
1088 | void (*clear_inode) (struct inode *); | 1085 | void (*clear_inode) (struct inode *); |
1089 | void (*umount_begin) (struct super_block *); | 1086 | void (*umount_begin) (struct super_block *); |
1090 | 1087 | ||
1091 | int (*show_options)(struct seq_file *, struct vfsmount *); | 1088 | int (*show_options)(struct seq_file *, struct vfsmount *); |
1092 | 1089 | ||
1093 | ssize_t (*quota_read)(struct super_block *, int, char *, size_t, loff_t); | 1090 | ssize_t (*quota_read)(struct super_block *, int, char *, size_t, loff_t); |
1094 | ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t); | 1091 | ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t); |
1095 | }; | 1092 | }; |
1096 | 1093 | ||
1097 | /* Inode state bits. Protected by inode_lock. */ | 1094 | /* Inode state bits. Protected by inode_lock. */ |
1098 | #define I_DIRTY_SYNC 1 /* Not dirty enough for O_DATASYNC */ | 1095 | #define I_DIRTY_SYNC 1 /* Not dirty enough for O_DATASYNC */ |
1099 | #define I_DIRTY_DATASYNC 2 /* Data-related inode changes pending */ | 1096 | #define I_DIRTY_DATASYNC 2 /* Data-related inode changes pending */ |
1100 | #define I_DIRTY_PAGES 4 /* Data-related inode changes pending */ | 1097 | #define I_DIRTY_PAGES 4 /* Data-related inode changes pending */ |
1101 | #define __I_LOCK 3 | 1098 | #define __I_LOCK 3 |
1102 | #define I_LOCK (1 << __I_LOCK) | 1099 | #define I_LOCK (1 << __I_LOCK) |
1103 | #define I_FREEING 16 | 1100 | #define I_FREEING 16 |
1104 | #define I_CLEAR 32 | 1101 | #define I_CLEAR 32 |
1105 | #define I_NEW 64 | 1102 | #define I_NEW 64 |
1106 | #define I_WILL_FREE 128 | 1103 | #define I_WILL_FREE 128 |
1107 | 1104 | ||
1108 | #define I_DIRTY (I_DIRTY_SYNC | I_DIRTY_DATASYNC | I_DIRTY_PAGES) | 1105 | #define I_DIRTY (I_DIRTY_SYNC | I_DIRTY_DATASYNC | I_DIRTY_PAGES) |
1109 | 1106 | ||
1110 | extern void __mark_inode_dirty(struct inode *, int); | 1107 | extern void __mark_inode_dirty(struct inode *, int); |
1111 | static inline void mark_inode_dirty(struct inode *inode) | 1108 | static inline void mark_inode_dirty(struct inode *inode) |
1112 | { | 1109 | { |
1113 | __mark_inode_dirty(inode, I_DIRTY); | 1110 | __mark_inode_dirty(inode, I_DIRTY); |
1114 | } | 1111 | } |
1115 | 1112 | ||
1116 | static inline void mark_inode_dirty_sync(struct inode *inode) | 1113 | static inline void mark_inode_dirty_sync(struct inode *inode) |
1117 | { | 1114 | { |
1118 | __mark_inode_dirty(inode, I_DIRTY_SYNC); | 1115 | __mark_inode_dirty(inode, I_DIRTY_SYNC); |
1119 | } | 1116 | } |
1120 | 1117 | ||
1121 | static inline void touch_atime(struct vfsmount *mnt, struct dentry *dentry) | 1118 | extern void touch_atime(struct vfsmount *mnt, struct dentry *dentry); |
1122 | { | ||
1123 | /* per-mountpoint checks will go here */ | ||
1124 | update_atime(dentry->d_inode); | ||
1125 | } | ||
1126 | |||
1127 | static inline void file_accessed(struct file *file) | 1119 | static inline void file_accessed(struct file *file) |
1128 | { | 1120 | { |
1129 | if (!(file->f_flags & O_NOATIME)) | 1121 | if (!(file->f_flags & O_NOATIME)) |
1130 | touch_atime(file->f_vfsmnt, file->f_dentry); | 1122 | touch_atime(file->f_vfsmnt, file->f_dentry); |
1131 | } | 1123 | } |
1132 | 1124 | ||
1133 | int sync_inode(struct inode *inode, struct writeback_control *wbc); | 1125 | int sync_inode(struct inode *inode, struct writeback_control *wbc); |
1134 | 1126 | ||
1135 | /** | 1127 | /** |
1136 | * struct export_operations - for nfsd to communicate with file systems | 1128 | * struct export_operations - for nfsd to communicate with file systems |
1137 | * @decode_fh: decode a file handle fragment and return a &struct dentry | 1129 | * @decode_fh: decode a file handle fragment and return a &struct dentry |
1138 | * @encode_fh: encode a file handle fragment from a dentry | 1130 | * @encode_fh: encode a file handle fragment from a dentry |
1139 | * @get_name: find the name for a given inode in a given directory | 1131 | * @get_name: find the name for a given inode in a given directory |
1140 | * @get_parent: find the parent of a given directory | 1132 | * @get_parent: find the parent of a given directory |
1141 | * @get_dentry: find a dentry for the inode given a file handle sub-fragment | 1133 | * @get_dentry: find a dentry for the inode given a file handle sub-fragment |
1142 | * @find_exported_dentry: | 1134 | * @find_exported_dentry: |
1143 | * set by the exporting module to a standard helper function. | 1135 | * set by the exporting module to a standard helper function. |
1144 | * | 1136 | * |
1145 | * Description: | 1137 | * Description: |
1146 | * The export_operations structure provides a means for nfsd to communicate | 1138 | * The export_operations structure provides a means for nfsd to communicate |
1147 | * with a particular exported file system - particularly enabling nfsd and | 1139 | * with a particular exported file system - particularly enabling nfsd and |
1148 | * the filesystem to co-operate when dealing with file handles. | 1140 | * the filesystem to co-operate when dealing with file handles. |
1149 | * | 1141 | * |
1150 | * export_operations contains two basic operation for dealing with file | 1142 | * export_operations contains two basic operation for dealing with file |
1151 | * handles, decode_fh() and encode_fh(), and allows for some other | 1143 | * handles, decode_fh() and encode_fh(), and allows for some other |
1152 | * operations to be defined which standard helper routines use to get | 1144 | * operations to be defined which standard helper routines use to get |
1153 | * specific information from the filesystem. | 1145 | * specific information from the filesystem. |
1154 | * | 1146 | * |
1155 | * nfsd encodes information use to determine which filesystem a filehandle | 1147 | * nfsd encodes information use to determine which filesystem a filehandle |
1156 | * applies to in the initial part of the file handle. The remainder, termed | 1148 | * applies to in the initial part of the file handle. The remainder, termed |
1157 | * a file handle fragment, is controlled completely by the filesystem. The | 1149 | * a file handle fragment, is controlled completely by the filesystem. The |
1158 | * standard helper routines assume that this fragment will contain one or | 1150 | * standard helper routines assume that this fragment will contain one or |
1159 | * two sub-fragments, one which identifies the file, and one which may be | 1151 | * two sub-fragments, one which identifies the file, and one which may be |
1160 | * used to identify the (a) directory containing the file. | 1152 | * used to identify the (a) directory containing the file. |
1161 | * | 1153 | * |
1162 | * In some situations, nfsd needs to get a dentry which is connected into a | 1154 | * In some situations, nfsd needs to get a dentry which is connected into a |
1163 | * specific part of the file tree. To allow for this, it passes the | 1155 | * specific part of the file tree. To allow for this, it passes the |
1164 | * function acceptable() together with a @context which can be used to see | 1156 | * function acceptable() together with a @context which can be used to see |
1165 | * if the dentry is acceptable. As there can be multiple dentrys for a | 1157 | * if the dentry is acceptable. As there can be multiple dentrys for a |
1166 | * given file, the filesystem should check each one for acceptability before | 1158 | * given file, the filesystem should check each one for acceptability before |
1167 | * looking for the next. As soon as an acceptable one is found, it should | 1159 | * looking for the next. As soon as an acceptable one is found, it should |
1168 | * be returned. | 1160 | * be returned. |
1169 | * | 1161 | * |
1170 | * decode_fh: | 1162 | * decode_fh: |
1171 | * @decode_fh is given a &struct super_block (@sb), a file handle fragment | 1163 | * @decode_fh is given a &struct super_block (@sb), a file handle fragment |
1172 | * (@fh, @fh_len) and an acceptability testing function (@acceptable, | 1164 | * (@fh, @fh_len) and an acceptability testing function (@acceptable, |
1173 | * @context). It should return a &struct dentry which refers to the same | 1165 | * @context). It should return a &struct dentry which refers to the same |
1174 | * file that the file handle fragment refers to, and which passes the | 1166 | * file that the file handle fragment refers to, and which passes the |
1175 | * acceptability test. If it cannot, it should return a %NULL pointer if | 1167 | * acceptability test. If it cannot, it should return a %NULL pointer if |
1176 | * the file was found but no acceptable &dentries were available, or a | 1168 | * the file was found but no acceptable &dentries were available, or a |
1177 | * %ERR_PTR error code indicating why it couldn't be found (e.g. %ENOENT or | 1169 | * %ERR_PTR error code indicating why it couldn't be found (e.g. %ENOENT or |
1178 | * %ENOMEM). | 1170 | * %ENOMEM). |
1179 | * | 1171 | * |
1180 | * encode_fh: | 1172 | * encode_fh: |
1181 | * @encode_fh should store in the file handle fragment @fh (using at most | 1173 | * @encode_fh should store in the file handle fragment @fh (using at most |
1182 | * @max_len bytes) information that can be used by @decode_fh to recover the | 1174 | * @max_len bytes) information that can be used by @decode_fh to recover the |
1183 | * file refered to by the &struct dentry @de. If the @connectable flag is | 1175 | * file refered to by the &struct dentry @de. If the @connectable flag is |
1184 | * set, the encode_fh() should store sufficient information so that a good | 1176 | * set, the encode_fh() should store sufficient information so that a good |
1185 | * attempt can be made to find not only the file but also it's place in the | 1177 | * attempt can be made to find not only the file but also it's place in the |
1186 | * filesystem. This typically means storing a reference to de->d_parent in | 1178 | * filesystem. This typically means storing a reference to de->d_parent in |
1187 | * the filehandle fragment. encode_fh() should return the number of bytes | 1179 | * the filehandle fragment. encode_fh() should return the number of bytes |
1188 | * stored or a negative error code such as %-ENOSPC | 1180 | * stored or a negative error code such as %-ENOSPC |
1189 | * | 1181 | * |
1190 | * get_name: | 1182 | * get_name: |
1191 | * @get_name should find a name for the given @child in the given @parent | 1183 | * @get_name should find a name for the given @child in the given @parent |
1192 | * directory. The name should be stored in the @name (with the | 1184 | * directory. The name should be stored in the @name (with the |
1193 | * understanding that it is already pointing to a a %NAME_MAX+1 sized | 1185 | * understanding that it is already pointing to a a %NAME_MAX+1 sized |
1194 | * buffer. get_name() should return %0 on success, a negative error code | 1186 | * buffer. get_name() should return %0 on success, a negative error code |
1195 | * or error. @get_name will be called without @parent->i_mutex held. | 1187 | * or error. @get_name will be called without @parent->i_mutex held. |
1196 | * | 1188 | * |
1197 | * get_parent: | 1189 | * get_parent: |
1198 | * @get_parent should find the parent directory for the given @child which | 1190 | * @get_parent should find the parent directory for the given @child which |
1199 | * is also a directory. In the event that it cannot be found, or storage | 1191 | * is also a directory. In the event that it cannot be found, or storage |
1200 | * space cannot be allocated, a %ERR_PTR should be returned. | 1192 | * space cannot be allocated, a %ERR_PTR should be returned. |
1201 | * | 1193 | * |
1202 | * get_dentry: | 1194 | * get_dentry: |
1203 | * Given a &super_block (@sb) and a pointer to a file-system specific inode | 1195 | * Given a &super_block (@sb) and a pointer to a file-system specific inode |
1204 | * identifier, possibly an inode number, (@inump) get_dentry() should find | 1196 | * identifier, possibly an inode number, (@inump) get_dentry() should find |
1205 | * the identified inode and return a dentry for that inode. Any suitable | 1197 | * the identified inode and return a dentry for that inode. Any suitable |
1206 | * dentry can be returned including, if necessary, a new dentry created with | 1198 | * dentry can be returned including, if necessary, a new dentry created with |
1207 | * d_alloc_root. The caller can then find any other extant dentrys by | 1199 | * d_alloc_root. The caller can then find any other extant dentrys by |
1208 | * following the d_alias links. If a new dentry was created using | 1200 | * following the d_alias links. If a new dentry was created using |
1209 | * d_alloc_root, DCACHE_NFSD_DISCONNECTED should be set, and the dentry | 1201 | * d_alloc_root, DCACHE_NFSD_DISCONNECTED should be set, and the dentry |
1210 | * should be d_rehash()ed. | 1202 | * should be d_rehash()ed. |
1211 | * | 1203 | * |
1212 | * If the inode cannot be found, either a %NULL pointer or an %ERR_PTR code | 1204 | * If the inode cannot be found, either a %NULL pointer or an %ERR_PTR code |
1213 | * can be returned. The @inump will be whatever was passed to | 1205 | * can be returned. The @inump will be whatever was passed to |
1214 | * nfsd_find_fh_dentry() in either the @obj or @parent parameters. | 1206 | * nfsd_find_fh_dentry() in either the @obj or @parent parameters. |
1215 | * | 1207 | * |
1216 | * Locking rules: | 1208 | * Locking rules: |
1217 | * get_parent is called with child->d_inode->i_mutex down | 1209 | * get_parent is called with child->d_inode->i_mutex down |
1218 | * get_name is not (which is possibly inconsistent) | 1210 | * get_name is not (which is possibly inconsistent) |
1219 | */ | 1211 | */ |
1220 | 1212 | ||
1221 | struct export_operations { | 1213 | struct export_operations { |
1222 | struct dentry *(*decode_fh)(struct super_block *sb, __u32 *fh, int fh_len, int fh_type, | 1214 | struct dentry *(*decode_fh)(struct super_block *sb, __u32 *fh, int fh_len, int fh_type, |
1223 | int (*acceptable)(void *context, struct dentry *de), | 1215 | int (*acceptable)(void *context, struct dentry *de), |
1224 | void *context); | 1216 | void *context); |
1225 | int (*encode_fh)(struct dentry *de, __u32 *fh, int *max_len, | 1217 | int (*encode_fh)(struct dentry *de, __u32 *fh, int *max_len, |
1226 | int connectable); | 1218 | int connectable); |
1227 | 1219 | ||
1228 | /* the following are only called from the filesystem itself */ | 1220 | /* the following are only called from the filesystem itself */ |
1229 | int (*get_name)(struct dentry *parent, char *name, | 1221 | int (*get_name)(struct dentry *parent, char *name, |
1230 | struct dentry *child); | 1222 | struct dentry *child); |
1231 | struct dentry * (*get_parent)(struct dentry *child); | 1223 | struct dentry * (*get_parent)(struct dentry *child); |
1232 | struct dentry * (*get_dentry)(struct super_block *sb, void *inump); | 1224 | struct dentry * (*get_dentry)(struct super_block *sb, void *inump); |
1233 | 1225 | ||
1234 | /* This is set by the exporting module to a standard helper */ | 1226 | /* This is set by the exporting module to a standard helper */ |
1235 | struct dentry * (*find_exported_dentry)( | 1227 | struct dentry * (*find_exported_dentry)( |
1236 | struct super_block *sb, void *obj, void *parent, | 1228 | struct super_block *sb, void *obj, void *parent, |
1237 | int (*acceptable)(void *context, struct dentry *de), | 1229 | int (*acceptable)(void *context, struct dentry *de), |
1238 | void *context); | 1230 | void *context); |
1239 | 1231 | ||
1240 | 1232 | ||
1241 | }; | 1233 | }; |
1242 | 1234 | ||
1243 | extern struct dentry * | 1235 | extern struct dentry * |
1244 | find_exported_dentry(struct super_block *sb, void *obj, void *parent, | 1236 | find_exported_dentry(struct super_block *sb, void *obj, void *parent, |
1245 | int (*acceptable)(void *context, struct dentry *de), | 1237 | int (*acceptable)(void *context, struct dentry *de), |
1246 | void *context); | 1238 | void *context); |
1247 | 1239 | ||
1248 | struct file_system_type { | 1240 | struct file_system_type { |
1249 | const char *name; | 1241 | const char *name; |
1250 | int fs_flags; | 1242 | int fs_flags; |
1251 | struct super_block *(*get_sb) (struct file_system_type *, int, | 1243 | struct super_block *(*get_sb) (struct file_system_type *, int, |
1252 | const char *, void *); | 1244 | const char *, void *); |
1253 | void (*kill_sb) (struct super_block *); | 1245 | void (*kill_sb) (struct super_block *); |
1254 | struct module *owner; | 1246 | struct module *owner; |
1255 | struct file_system_type * next; | 1247 | struct file_system_type * next; |
1256 | struct list_head fs_supers; | 1248 | struct list_head fs_supers; |
1257 | }; | 1249 | }; |
1258 | 1250 | ||
1259 | struct super_block *get_sb_bdev(struct file_system_type *fs_type, | 1251 | struct super_block *get_sb_bdev(struct file_system_type *fs_type, |
1260 | int flags, const char *dev_name, void *data, | 1252 | int flags, const char *dev_name, void *data, |
1261 | int (*fill_super)(struct super_block *, void *, int)); | 1253 | int (*fill_super)(struct super_block *, void *, int)); |
1262 | struct super_block *get_sb_single(struct file_system_type *fs_type, | 1254 | struct super_block *get_sb_single(struct file_system_type *fs_type, |
1263 | int flags, void *data, | 1255 | int flags, void *data, |
1264 | int (*fill_super)(struct super_block *, void *, int)); | 1256 | int (*fill_super)(struct super_block *, void *, int)); |
1265 | struct super_block *get_sb_nodev(struct file_system_type *fs_type, | 1257 | struct super_block *get_sb_nodev(struct file_system_type *fs_type, |
1266 | int flags, void *data, | 1258 | int flags, void *data, |
1267 | int (*fill_super)(struct super_block *, void *, int)); | 1259 | int (*fill_super)(struct super_block *, void *, int)); |
1268 | void generic_shutdown_super(struct super_block *sb); | 1260 | void generic_shutdown_super(struct super_block *sb); |
1269 | void kill_block_super(struct super_block *sb); | 1261 | void kill_block_super(struct super_block *sb); |
1270 | void kill_anon_super(struct super_block *sb); | 1262 | void kill_anon_super(struct super_block *sb); |
1271 | void kill_litter_super(struct super_block *sb); | 1263 | void kill_litter_super(struct super_block *sb); |
1272 | void deactivate_super(struct super_block *sb); | 1264 | void deactivate_super(struct super_block *sb); |
1273 | int set_anon_super(struct super_block *s, void *data); | 1265 | int set_anon_super(struct super_block *s, void *data); |
1274 | struct super_block *sget(struct file_system_type *type, | 1266 | struct super_block *sget(struct file_system_type *type, |
1275 | int (*test)(struct super_block *,void *), | 1267 | int (*test)(struct super_block *,void *), |
1276 | int (*set)(struct super_block *,void *), | 1268 | int (*set)(struct super_block *,void *), |
1277 | void *data); | 1269 | void *data); |
1278 | struct super_block *get_sb_pseudo(struct file_system_type *, char *, | 1270 | struct super_block *get_sb_pseudo(struct file_system_type *, char *, |
1279 | struct super_operations *ops, unsigned long); | 1271 | struct super_operations *ops, unsigned long); |
1280 | int __put_super(struct super_block *sb); | 1272 | int __put_super(struct super_block *sb); |
1281 | int __put_super_and_need_restart(struct super_block *sb); | 1273 | int __put_super_and_need_restart(struct super_block *sb); |
1282 | void unnamed_dev_init(void); | 1274 | void unnamed_dev_init(void); |
1283 | 1275 | ||
1284 | /* Alas, no aliases. Too much hassle with bringing module.h everywhere */ | 1276 | /* Alas, no aliases. Too much hassle with bringing module.h everywhere */ |
1285 | #define fops_get(fops) \ | 1277 | #define fops_get(fops) \ |
1286 | (((fops) && try_module_get((fops)->owner) ? (fops) : NULL)) | 1278 | (((fops) && try_module_get((fops)->owner) ? (fops) : NULL)) |
1287 | #define fops_put(fops) \ | 1279 | #define fops_put(fops) \ |
1288 | do { if (fops) module_put((fops)->owner); } while(0) | 1280 | do { if (fops) module_put((fops)->owner); } while(0) |
1289 | 1281 | ||
1290 | extern int register_filesystem(struct file_system_type *); | 1282 | extern int register_filesystem(struct file_system_type *); |
1291 | extern int unregister_filesystem(struct file_system_type *); | 1283 | extern int unregister_filesystem(struct file_system_type *); |
1292 | extern struct vfsmount *kern_mount(struct file_system_type *); | 1284 | extern struct vfsmount *kern_mount(struct file_system_type *); |
1293 | extern int may_umount_tree(struct vfsmount *); | 1285 | extern int may_umount_tree(struct vfsmount *); |
1294 | extern int may_umount(struct vfsmount *); | 1286 | extern int may_umount(struct vfsmount *); |
1295 | extern void umount_tree(struct vfsmount *, int, struct list_head *); | 1287 | extern void umount_tree(struct vfsmount *, int, struct list_head *); |
1296 | extern void release_mounts(struct list_head *); | 1288 | extern void release_mounts(struct list_head *); |
1297 | extern long do_mount(char *, char *, char *, unsigned long, void *); | 1289 | extern long do_mount(char *, char *, char *, unsigned long, void *); |
1298 | extern struct vfsmount *copy_tree(struct vfsmount *, struct dentry *, int); | 1290 | extern struct vfsmount *copy_tree(struct vfsmount *, struct dentry *, int); |
1299 | extern void mnt_set_mountpoint(struct vfsmount *, struct dentry *, | 1291 | extern void mnt_set_mountpoint(struct vfsmount *, struct dentry *, |
1300 | struct vfsmount *); | 1292 | struct vfsmount *); |
1301 | 1293 | ||
1302 | extern int vfs_statfs(struct super_block *, struct kstatfs *); | 1294 | extern int vfs_statfs(struct super_block *, struct kstatfs *); |
1303 | 1295 | ||
1304 | #define FLOCK_VERIFY_READ 1 | 1296 | #define FLOCK_VERIFY_READ 1 |
1305 | #define FLOCK_VERIFY_WRITE 2 | 1297 | #define FLOCK_VERIFY_WRITE 2 |
1306 | 1298 | ||
1307 | extern int locks_mandatory_locked(struct inode *); | 1299 | extern int locks_mandatory_locked(struct inode *); |
1308 | extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t); | 1300 | extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t); |
1309 | 1301 | ||
1310 | /* | 1302 | /* |
1311 | * Candidates for mandatory locking have the setgid bit set | 1303 | * Candidates for mandatory locking have the setgid bit set |
1312 | * but no group execute bit - an otherwise meaningless combination. | 1304 | * but no group execute bit - an otherwise meaningless combination. |
1313 | */ | 1305 | */ |
1314 | #define MANDATORY_LOCK(inode) \ | 1306 | #define MANDATORY_LOCK(inode) \ |
1315 | (IS_MANDLOCK(inode) && ((inode)->i_mode & (S_ISGID | S_IXGRP)) == S_ISGID) | 1307 | (IS_MANDLOCK(inode) && ((inode)->i_mode & (S_ISGID | S_IXGRP)) == S_ISGID) |
1316 | 1308 | ||
1317 | static inline int locks_verify_locked(struct inode *inode) | 1309 | static inline int locks_verify_locked(struct inode *inode) |
1318 | { | 1310 | { |
1319 | if (MANDATORY_LOCK(inode)) | 1311 | if (MANDATORY_LOCK(inode)) |
1320 | return locks_mandatory_locked(inode); | 1312 | return locks_mandatory_locked(inode); |
1321 | return 0; | 1313 | return 0; |
1322 | } | 1314 | } |
1323 | 1315 | ||
1324 | extern int rw_verify_area(int, struct file *, loff_t *, size_t); | 1316 | extern int rw_verify_area(int, struct file *, loff_t *, size_t); |
1325 | 1317 | ||
1326 | static inline int locks_verify_truncate(struct inode *inode, | 1318 | static inline int locks_verify_truncate(struct inode *inode, |
1327 | struct file *filp, | 1319 | struct file *filp, |
1328 | loff_t size) | 1320 | loff_t size) |
1329 | { | 1321 | { |
1330 | if (inode->i_flock && MANDATORY_LOCK(inode)) | 1322 | if (inode->i_flock && MANDATORY_LOCK(inode)) |
1331 | return locks_mandatory_area( | 1323 | return locks_mandatory_area( |
1332 | FLOCK_VERIFY_WRITE, inode, filp, | 1324 | FLOCK_VERIFY_WRITE, inode, filp, |
1333 | size < inode->i_size ? size : inode->i_size, | 1325 | size < inode->i_size ? size : inode->i_size, |
1334 | (size < inode->i_size ? inode->i_size - size | 1326 | (size < inode->i_size ? inode->i_size - size |
1335 | : size - inode->i_size) | 1327 | : size - inode->i_size) |
1336 | ); | 1328 | ); |
1337 | return 0; | 1329 | return 0; |
1338 | } | 1330 | } |
1339 | 1331 | ||
1340 | static inline int break_lease(struct inode *inode, unsigned int mode) | 1332 | static inline int break_lease(struct inode *inode, unsigned int mode) |
1341 | { | 1333 | { |
1342 | if (inode->i_flock) | 1334 | if (inode->i_flock) |
1343 | return __break_lease(inode, mode); | 1335 | return __break_lease(inode, mode); |
1344 | return 0; | 1336 | return 0; |
1345 | } | 1337 | } |
1346 | 1338 | ||
1347 | /* fs/open.c */ | 1339 | /* fs/open.c */ |
1348 | 1340 | ||
1349 | extern int do_truncate(struct dentry *, loff_t start, unsigned int time_attrs, | 1341 | extern int do_truncate(struct dentry *, loff_t start, unsigned int time_attrs, |
1350 | struct file *filp); | 1342 | struct file *filp); |
1351 | extern long do_sys_open(const char __user *filename, int flags, int mode); | 1343 | extern long do_sys_open(const char __user *filename, int flags, int mode); |
1352 | extern struct file *filp_open(const char *, int, int); | 1344 | extern struct file *filp_open(const char *, int, int); |
1353 | extern struct file * dentry_open(struct dentry *, struct vfsmount *, int); | 1345 | extern struct file * dentry_open(struct dentry *, struct vfsmount *, int); |
1354 | extern int filp_close(struct file *, fl_owner_t id); | 1346 | extern int filp_close(struct file *, fl_owner_t id); |
1355 | extern char * getname(const char __user *); | 1347 | extern char * getname(const char __user *); |
1356 | 1348 | ||
1357 | /* fs/dcache.c */ | 1349 | /* fs/dcache.c */ |
1358 | extern void __init vfs_caches_init_early(void); | 1350 | extern void __init vfs_caches_init_early(void); |
1359 | extern void __init vfs_caches_init(unsigned long); | 1351 | extern void __init vfs_caches_init(unsigned long); |
1360 | 1352 | ||
1361 | #define __getname() kmem_cache_alloc(names_cachep, SLAB_KERNEL) | 1353 | #define __getname() kmem_cache_alloc(names_cachep, SLAB_KERNEL) |
1362 | #define __putname(name) kmem_cache_free(names_cachep, (void *)(name)) | 1354 | #define __putname(name) kmem_cache_free(names_cachep, (void *)(name)) |
1363 | #ifndef CONFIG_AUDITSYSCALL | 1355 | #ifndef CONFIG_AUDITSYSCALL |
1364 | #define putname(name) __putname(name) | 1356 | #define putname(name) __putname(name) |
1365 | #else | 1357 | #else |
1366 | extern void putname(const char *name); | 1358 | extern void putname(const char *name); |
1367 | #endif | 1359 | #endif |
1368 | 1360 | ||
1369 | extern int register_blkdev(unsigned int, const char *); | 1361 | extern int register_blkdev(unsigned int, const char *); |
1370 | extern int unregister_blkdev(unsigned int, const char *); | 1362 | extern int unregister_blkdev(unsigned int, const char *); |
1371 | extern struct block_device *bdget(dev_t); | 1363 | extern struct block_device *bdget(dev_t); |
1372 | extern void bd_set_size(struct block_device *, loff_t size); | 1364 | extern void bd_set_size(struct block_device *, loff_t size); |
1373 | extern void bd_forget(struct inode *inode); | 1365 | extern void bd_forget(struct inode *inode); |
1374 | extern void bdput(struct block_device *); | 1366 | extern void bdput(struct block_device *); |
1375 | extern struct block_device *open_by_devnum(dev_t, unsigned); | 1367 | extern struct block_device *open_by_devnum(dev_t, unsigned); |
1376 | extern struct file_operations def_blk_fops; | 1368 | extern struct file_operations def_blk_fops; |
1377 | extern struct address_space_operations def_blk_aops; | 1369 | extern struct address_space_operations def_blk_aops; |
1378 | extern struct file_operations def_chr_fops; | 1370 | extern struct file_operations def_chr_fops; |
1379 | extern struct file_operations bad_sock_fops; | 1371 | extern struct file_operations bad_sock_fops; |
1380 | extern struct file_operations def_fifo_fops; | 1372 | extern struct file_operations def_fifo_fops; |
1381 | extern int ioctl_by_bdev(struct block_device *, unsigned, unsigned long); | 1373 | extern int ioctl_by_bdev(struct block_device *, unsigned, unsigned long); |
1382 | extern int blkdev_ioctl(struct inode *, struct file *, unsigned, unsigned long); | 1374 | extern int blkdev_ioctl(struct inode *, struct file *, unsigned, unsigned long); |
1383 | extern long compat_blkdev_ioctl(struct file *, unsigned, unsigned long); | 1375 | extern long compat_blkdev_ioctl(struct file *, unsigned, unsigned long); |
1384 | extern int blkdev_get(struct block_device *, mode_t, unsigned); | 1376 | extern int blkdev_get(struct block_device *, mode_t, unsigned); |
1385 | extern int blkdev_put(struct block_device *); | 1377 | extern int blkdev_put(struct block_device *); |
1386 | extern int bd_claim(struct block_device *, void *); | 1378 | extern int bd_claim(struct block_device *, void *); |
1387 | extern void bd_release(struct block_device *); | 1379 | extern void bd_release(struct block_device *); |
1388 | 1380 | ||
1389 | /* fs/char_dev.c */ | 1381 | /* fs/char_dev.c */ |
1390 | extern int alloc_chrdev_region(dev_t *, unsigned, unsigned, const char *); | 1382 | extern int alloc_chrdev_region(dev_t *, unsigned, unsigned, const char *); |
1391 | extern int register_chrdev_region(dev_t, unsigned, const char *); | 1383 | extern int register_chrdev_region(dev_t, unsigned, const char *); |
1392 | extern int register_chrdev(unsigned int, const char *, | 1384 | extern int register_chrdev(unsigned int, const char *, |
1393 | struct file_operations *); | 1385 | struct file_operations *); |
1394 | extern int unregister_chrdev(unsigned int, const char *); | 1386 | extern int unregister_chrdev(unsigned int, const char *); |
1395 | extern void unregister_chrdev_region(dev_t, unsigned); | 1387 | extern void unregister_chrdev_region(dev_t, unsigned); |
1396 | extern int chrdev_open(struct inode *, struct file *); | 1388 | extern int chrdev_open(struct inode *, struct file *); |
1397 | 1389 | ||
1398 | /* fs/block_dev.c */ | 1390 | /* fs/block_dev.c */ |
1399 | #define BDEVNAME_SIZE 32 /* Largest string for a blockdev identifier */ | 1391 | #define BDEVNAME_SIZE 32 /* Largest string for a blockdev identifier */ |
1400 | extern const char *__bdevname(dev_t, char *buffer); | 1392 | extern const char *__bdevname(dev_t, char *buffer); |
1401 | extern const char *bdevname(struct block_device *bdev, char *buffer); | 1393 | extern const char *bdevname(struct block_device *bdev, char *buffer); |
1402 | extern struct block_device *lookup_bdev(const char *); | 1394 | extern struct block_device *lookup_bdev(const char *); |
1403 | extern struct block_device *open_bdev_excl(const char *, int, void *); | 1395 | extern struct block_device *open_bdev_excl(const char *, int, void *); |
1404 | extern void close_bdev_excl(struct block_device *); | 1396 | extern void close_bdev_excl(struct block_device *); |
1405 | 1397 | ||
1406 | extern void init_special_inode(struct inode *, umode_t, dev_t); | 1398 | extern void init_special_inode(struct inode *, umode_t, dev_t); |
1407 | 1399 | ||
1408 | /* Invalid inode operations -- fs/bad_inode.c */ | 1400 | /* Invalid inode operations -- fs/bad_inode.c */ |
1409 | extern void make_bad_inode(struct inode *); | 1401 | extern void make_bad_inode(struct inode *); |
1410 | extern int is_bad_inode(struct inode *); | 1402 | extern int is_bad_inode(struct inode *); |
1411 | 1403 | ||
1412 | extern struct file_operations read_fifo_fops; | 1404 | extern struct file_operations read_fifo_fops; |
1413 | extern struct file_operations write_fifo_fops; | 1405 | extern struct file_operations write_fifo_fops; |
1414 | extern struct file_operations rdwr_fifo_fops; | 1406 | extern struct file_operations rdwr_fifo_fops; |
1415 | extern struct file_operations read_pipe_fops; | 1407 | extern struct file_operations read_pipe_fops; |
1416 | extern struct file_operations write_pipe_fops; | 1408 | extern struct file_operations write_pipe_fops; |
1417 | extern struct file_operations rdwr_pipe_fops; | 1409 | extern struct file_operations rdwr_pipe_fops; |
1418 | 1410 | ||
1419 | extern int fs_may_remount_ro(struct super_block *); | 1411 | extern int fs_may_remount_ro(struct super_block *); |
1420 | 1412 | ||
1421 | /* | 1413 | /* |
1422 | * return READ, READA, or WRITE | 1414 | * return READ, READA, or WRITE |
1423 | */ | 1415 | */ |
1424 | #define bio_rw(bio) ((bio)->bi_rw & (RW_MASK | RWA_MASK)) | 1416 | #define bio_rw(bio) ((bio)->bi_rw & (RW_MASK | RWA_MASK)) |
1425 | 1417 | ||
1426 | /* | 1418 | /* |
1427 | * return data direction, READ or WRITE | 1419 | * return data direction, READ or WRITE |
1428 | */ | 1420 | */ |
1429 | #define bio_data_dir(bio) ((bio)->bi_rw & 1) | 1421 | #define bio_data_dir(bio) ((bio)->bi_rw & 1) |
1430 | 1422 | ||
1431 | extern int check_disk_change(struct block_device *); | 1423 | extern int check_disk_change(struct block_device *); |
1432 | extern int invalidate_inodes(struct super_block *); | 1424 | extern int invalidate_inodes(struct super_block *); |
1433 | extern int __invalidate_device(struct block_device *); | 1425 | extern int __invalidate_device(struct block_device *); |
1434 | extern int invalidate_partition(struct gendisk *, int); | 1426 | extern int invalidate_partition(struct gendisk *, int); |
1435 | unsigned long invalidate_mapping_pages(struct address_space *mapping, | 1427 | unsigned long invalidate_mapping_pages(struct address_space *mapping, |
1436 | pgoff_t start, pgoff_t end); | 1428 | pgoff_t start, pgoff_t end); |
1437 | unsigned long invalidate_inode_pages(struct address_space *mapping); | 1429 | unsigned long invalidate_inode_pages(struct address_space *mapping); |
1438 | static inline void invalidate_remote_inode(struct inode *inode) | 1430 | static inline void invalidate_remote_inode(struct inode *inode) |
1439 | { | 1431 | { |
1440 | if (S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) || | 1432 | if (S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) || |
1441 | S_ISLNK(inode->i_mode)) | 1433 | S_ISLNK(inode->i_mode)) |
1442 | invalidate_inode_pages(inode->i_mapping); | 1434 | invalidate_inode_pages(inode->i_mapping); |
1443 | } | 1435 | } |
1444 | extern int invalidate_inode_pages2(struct address_space *mapping); | 1436 | extern int invalidate_inode_pages2(struct address_space *mapping); |
1445 | extern int invalidate_inode_pages2_range(struct address_space *mapping, | 1437 | extern int invalidate_inode_pages2_range(struct address_space *mapping, |
1446 | pgoff_t start, pgoff_t end); | 1438 | pgoff_t start, pgoff_t end); |
1447 | extern int write_inode_now(struct inode *, int); | 1439 | extern int write_inode_now(struct inode *, int); |
1448 | extern int filemap_fdatawrite(struct address_space *); | 1440 | extern int filemap_fdatawrite(struct address_space *); |
1449 | extern int filemap_flush(struct address_space *); | 1441 | extern int filemap_flush(struct address_space *); |
1450 | extern int filemap_fdatawait(struct address_space *); | 1442 | extern int filemap_fdatawait(struct address_space *); |
1451 | extern int filemap_write_and_wait(struct address_space *mapping); | 1443 | extern int filemap_write_and_wait(struct address_space *mapping); |
1452 | extern int filemap_write_and_wait_range(struct address_space *mapping, | 1444 | extern int filemap_write_and_wait_range(struct address_space *mapping, |
1453 | loff_t lstart, loff_t lend); | 1445 | loff_t lstart, loff_t lend); |
1454 | extern void sync_supers(void); | 1446 | extern void sync_supers(void); |
1455 | extern void sync_filesystems(int wait); | 1447 | extern void sync_filesystems(int wait); |
1456 | extern void emergency_sync(void); | 1448 | extern void emergency_sync(void); |
1457 | extern void emergency_remount(void); | 1449 | extern void emergency_remount(void); |
1458 | extern int do_remount_sb(struct super_block *sb, int flags, | 1450 | extern int do_remount_sb(struct super_block *sb, int flags, |
1459 | void *data, int force); | 1451 | void *data, int force); |
1460 | extern sector_t bmap(struct inode *, sector_t); | 1452 | extern sector_t bmap(struct inode *, sector_t); |
1461 | extern int notify_change(struct dentry *, struct iattr *); | 1453 | extern int notify_change(struct dentry *, struct iattr *); |
1462 | extern int permission(struct inode *, int, struct nameidata *); | 1454 | extern int permission(struct inode *, int, struct nameidata *); |
1463 | extern int generic_permission(struct inode *, int, | 1455 | extern int generic_permission(struct inode *, int, |
1464 | int (*check_acl)(struct inode *, int)); | 1456 | int (*check_acl)(struct inode *, int)); |
1465 | 1457 | ||
1466 | extern int get_write_access(struct inode *); | 1458 | extern int get_write_access(struct inode *); |
1467 | extern int deny_write_access(struct file *); | 1459 | extern int deny_write_access(struct file *); |
1468 | static inline void put_write_access(struct inode * inode) | 1460 | static inline void put_write_access(struct inode * inode) |
1469 | { | 1461 | { |
1470 | atomic_dec(&inode->i_writecount); | 1462 | atomic_dec(&inode->i_writecount); |
1471 | } | 1463 | } |
1472 | static inline void allow_write_access(struct file *file) | 1464 | static inline void allow_write_access(struct file *file) |
1473 | { | 1465 | { |
1474 | if (file) | 1466 | if (file) |
1475 | atomic_inc(&file->f_dentry->d_inode->i_writecount); | 1467 | atomic_inc(&file->f_dentry->d_inode->i_writecount); |
1476 | } | 1468 | } |
1477 | extern int do_pipe(int *); | 1469 | extern int do_pipe(int *); |
1478 | 1470 | ||
1479 | extern int open_namei(const char *, int, int, struct nameidata *); | 1471 | extern int open_namei(const char *, int, int, struct nameidata *); |
1480 | extern int may_open(struct nameidata *, int, int); | 1472 | extern int may_open(struct nameidata *, int, int); |
1481 | 1473 | ||
1482 | extern int kernel_read(struct file *, unsigned long, char *, unsigned long); | 1474 | extern int kernel_read(struct file *, unsigned long, char *, unsigned long); |
1483 | extern struct file * open_exec(const char *); | 1475 | extern struct file * open_exec(const char *); |
1484 | 1476 | ||
1485 | /* fs/dcache.c -- generic fs support functions */ | 1477 | /* fs/dcache.c -- generic fs support functions */ |
1486 | extern int is_subdir(struct dentry *, struct dentry *); | 1478 | extern int is_subdir(struct dentry *, struct dentry *); |
1487 | extern ino_t find_inode_number(struct dentry *, struct qstr *); | 1479 | extern ino_t find_inode_number(struct dentry *, struct qstr *); |
1488 | 1480 | ||
1489 | #include <linux/err.h> | 1481 | #include <linux/err.h> |
1490 | 1482 | ||
1491 | /* needed for stackable file system support */ | 1483 | /* needed for stackable file system support */ |
1492 | extern loff_t default_llseek(struct file *file, loff_t offset, int origin); | 1484 | extern loff_t default_llseek(struct file *file, loff_t offset, int origin); |
1493 | 1485 | ||
1494 | extern loff_t vfs_llseek(struct file *file, loff_t offset, int origin); | 1486 | extern loff_t vfs_llseek(struct file *file, loff_t offset, int origin); |
1495 | 1487 | ||
1496 | extern void inode_init_once(struct inode *); | 1488 | extern void inode_init_once(struct inode *); |
1497 | extern void iput(struct inode *); | 1489 | extern void iput(struct inode *); |
1498 | extern struct inode * igrab(struct inode *); | 1490 | extern struct inode * igrab(struct inode *); |
1499 | extern ino_t iunique(struct super_block *, ino_t); | 1491 | extern ino_t iunique(struct super_block *, ino_t); |
1500 | extern int inode_needs_sync(struct inode *inode); | 1492 | extern int inode_needs_sync(struct inode *inode); |
1501 | extern void generic_delete_inode(struct inode *inode); | 1493 | extern void generic_delete_inode(struct inode *inode); |
1502 | extern void generic_drop_inode(struct inode *inode); | 1494 | extern void generic_drop_inode(struct inode *inode); |
1503 | 1495 | ||
1504 | extern struct inode *ilookup5_nowait(struct super_block *sb, | 1496 | extern struct inode *ilookup5_nowait(struct super_block *sb, |
1505 | unsigned long hashval, int (*test)(struct inode *, void *), | 1497 | unsigned long hashval, int (*test)(struct inode *, void *), |
1506 | void *data); | 1498 | void *data); |
1507 | extern struct inode *ilookup5(struct super_block *sb, unsigned long hashval, | 1499 | extern struct inode *ilookup5(struct super_block *sb, unsigned long hashval, |
1508 | int (*test)(struct inode *, void *), void *data); | 1500 | int (*test)(struct inode *, void *), void *data); |
1509 | extern struct inode *ilookup(struct super_block *sb, unsigned long ino); | 1501 | extern struct inode *ilookup(struct super_block *sb, unsigned long ino); |
1510 | 1502 | ||
1511 | extern struct inode * iget5_locked(struct super_block *, unsigned long, int (*test)(struct inode *, void *), int (*set)(struct inode *, void *), void *); | 1503 | extern struct inode * iget5_locked(struct super_block *, unsigned long, int (*test)(struct inode *, void *), int (*set)(struct inode *, void *), void *); |
1512 | extern struct inode * iget_locked(struct super_block *, unsigned long); | 1504 | extern struct inode * iget_locked(struct super_block *, unsigned long); |
1513 | extern void unlock_new_inode(struct inode *); | 1505 | extern void unlock_new_inode(struct inode *); |
1514 | 1506 | ||
1515 | static inline struct inode *iget(struct super_block *sb, unsigned long ino) | 1507 | static inline struct inode *iget(struct super_block *sb, unsigned long ino) |
1516 | { | 1508 | { |
1517 | struct inode *inode = iget_locked(sb, ino); | 1509 | struct inode *inode = iget_locked(sb, ino); |
1518 | 1510 | ||
1519 | if (inode && (inode->i_state & I_NEW)) { | 1511 | if (inode && (inode->i_state & I_NEW)) { |
1520 | sb->s_op->read_inode(inode); | 1512 | sb->s_op->read_inode(inode); |
1521 | unlock_new_inode(inode); | 1513 | unlock_new_inode(inode); |
1522 | } | 1514 | } |
1523 | 1515 | ||
1524 | return inode; | 1516 | return inode; |
1525 | } | 1517 | } |
1526 | 1518 | ||
1527 | extern void __iget(struct inode * inode); | 1519 | extern void __iget(struct inode * inode); |
1528 | extern void clear_inode(struct inode *); | 1520 | extern void clear_inode(struct inode *); |
1529 | extern void destroy_inode(struct inode *); | 1521 | extern void destroy_inode(struct inode *); |
1530 | extern struct inode *new_inode(struct super_block *); | 1522 | extern struct inode *new_inode(struct super_block *); |
1531 | extern int remove_suid(struct dentry *); | 1523 | extern int remove_suid(struct dentry *); |
1532 | extern void remove_dquot_ref(struct super_block *, int, struct list_head *); | 1524 | extern void remove_dquot_ref(struct super_block *, int, struct list_head *); |
1533 | extern struct semaphore iprune_sem; | 1525 | extern struct semaphore iprune_sem; |
1534 | 1526 | ||
1535 | extern void __insert_inode_hash(struct inode *, unsigned long hashval); | 1527 | extern void __insert_inode_hash(struct inode *, unsigned long hashval); |
1536 | extern void remove_inode_hash(struct inode *); | 1528 | extern void remove_inode_hash(struct inode *); |
1537 | static inline void insert_inode_hash(struct inode *inode) { | 1529 | static inline void insert_inode_hash(struct inode *inode) { |
1538 | __insert_inode_hash(inode, inode->i_ino); | 1530 | __insert_inode_hash(inode, inode->i_ino); |
1539 | } | 1531 | } |
1540 | 1532 | ||
1541 | extern struct file * get_empty_filp(void); | 1533 | extern struct file * get_empty_filp(void); |
1542 | extern void file_move(struct file *f, struct list_head *list); | 1534 | extern void file_move(struct file *f, struct list_head *list); |
1543 | extern void file_kill(struct file *f); | 1535 | extern void file_kill(struct file *f); |
1544 | struct bio; | 1536 | struct bio; |
1545 | extern void submit_bio(int, struct bio *); | 1537 | extern void submit_bio(int, struct bio *); |
1546 | extern int bdev_read_only(struct block_device *); | 1538 | extern int bdev_read_only(struct block_device *); |
1547 | extern int set_blocksize(struct block_device *, int); | 1539 | extern int set_blocksize(struct block_device *, int); |
1548 | extern int sb_set_blocksize(struct super_block *, int); | 1540 | extern int sb_set_blocksize(struct super_block *, int); |
1549 | extern int sb_min_blocksize(struct super_block *, int); | 1541 | extern int sb_min_blocksize(struct super_block *, int); |
1550 | 1542 | ||
1551 | extern int generic_file_mmap(struct file *, struct vm_area_struct *); | 1543 | extern int generic_file_mmap(struct file *, struct vm_area_struct *); |
1552 | extern int generic_file_readonly_mmap(struct file *, struct vm_area_struct *); | 1544 | extern int generic_file_readonly_mmap(struct file *, struct vm_area_struct *); |
1553 | extern int file_read_actor(read_descriptor_t * desc, struct page *page, unsigned long offset, unsigned long size); | 1545 | extern int file_read_actor(read_descriptor_t * desc, struct page *page, unsigned long offset, unsigned long size); |
1554 | extern int file_send_actor(read_descriptor_t * desc, struct page *page, unsigned long offset, unsigned long size); | 1546 | extern int file_send_actor(read_descriptor_t * desc, struct page *page, unsigned long offset, unsigned long size); |
1555 | extern ssize_t generic_file_read(struct file *, char __user *, size_t, loff_t *); | 1547 | extern ssize_t generic_file_read(struct file *, char __user *, size_t, loff_t *); |
1556 | int generic_write_checks(struct file *file, loff_t *pos, size_t *count, int isblk); | 1548 | int generic_write_checks(struct file *file, loff_t *pos, size_t *count, int isblk); |
1557 | extern ssize_t generic_file_write(struct file *, const char __user *, size_t, loff_t *); | 1549 | extern ssize_t generic_file_write(struct file *, const char __user *, size_t, loff_t *); |
1558 | extern ssize_t generic_file_aio_read(struct kiocb *, char __user *, size_t, loff_t); | 1550 | extern ssize_t generic_file_aio_read(struct kiocb *, char __user *, size_t, loff_t); |
1559 | extern ssize_t __generic_file_aio_read(struct kiocb *, const struct iovec *, unsigned long, loff_t *); | 1551 | extern ssize_t __generic_file_aio_read(struct kiocb *, const struct iovec *, unsigned long, loff_t *); |
1560 | extern ssize_t generic_file_aio_write(struct kiocb *, const char __user *, size_t, loff_t); | 1552 | extern ssize_t generic_file_aio_write(struct kiocb *, const char __user *, size_t, loff_t); |
1561 | extern ssize_t generic_file_aio_write_nolock(struct kiocb *, const struct iovec *, | 1553 | extern ssize_t generic_file_aio_write_nolock(struct kiocb *, const struct iovec *, |
1562 | unsigned long, loff_t *); | 1554 | unsigned long, loff_t *); |
1563 | extern ssize_t generic_file_direct_write(struct kiocb *, const struct iovec *, | 1555 | extern ssize_t generic_file_direct_write(struct kiocb *, const struct iovec *, |
1564 | unsigned long *, loff_t, loff_t *, size_t, size_t); | 1556 | unsigned long *, loff_t, loff_t *, size_t, size_t); |
1565 | extern ssize_t generic_file_buffered_write(struct kiocb *, const struct iovec *, | 1557 | extern ssize_t generic_file_buffered_write(struct kiocb *, const struct iovec *, |
1566 | unsigned long, loff_t, loff_t *, size_t, ssize_t); | 1558 | unsigned long, loff_t, loff_t *, size_t, ssize_t); |
1567 | extern ssize_t do_sync_read(struct file *filp, char __user *buf, size_t len, loff_t *ppos); | 1559 | extern ssize_t do_sync_read(struct file *filp, char __user *buf, size_t len, loff_t *ppos); |
1568 | extern ssize_t do_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos); | 1560 | extern ssize_t do_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos); |
1569 | ssize_t generic_file_write_nolock(struct file *file, const struct iovec *iov, | 1561 | ssize_t generic_file_write_nolock(struct file *file, const struct iovec *iov, |
1570 | unsigned long nr_segs, loff_t *ppos); | 1562 | unsigned long nr_segs, loff_t *ppos); |
1571 | extern ssize_t generic_file_sendfile(struct file *, loff_t *, size_t, read_actor_t, void *); | 1563 | extern ssize_t generic_file_sendfile(struct file *, loff_t *, size_t, read_actor_t, void *); |
1572 | extern void do_generic_mapping_read(struct address_space *mapping, | 1564 | extern void do_generic_mapping_read(struct address_space *mapping, |
1573 | struct file_ra_state *, struct file *, | 1565 | struct file_ra_state *, struct file *, |
1574 | loff_t *, read_descriptor_t *, read_actor_t); | 1566 | loff_t *, read_descriptor_t *, read_actor_t); |
1575 | extern void | 1567 | extern void |
1576 | file_ra_state_init(struct file_ra_state *ra, struct address_space *mapping); | 1568 | file_ra_state_init(struct file_ra_state *ra, struct address_space *mapping); |
1577 | extern ssize_t generic_file_readv(struct file *filp, const struct iovec *iov, | 1569 | extern ssize_t generic_file_readv(struct file *filp, const struct iovec *iov, |
1578 | unsigned long nr_segs, loff_t *ppos); | 1570 | unsigned long nr_segs, loff_t *ppos); |
1579 | ssize_t generic_file_writev(struct file *filp, const struct iovec *iov, | 1571 | ssize_t generic_file_writev(struct file *filp, const struct iovec *iov, |
1580 | unsigned long nr_segs, loff_t *ppos); | 1572 | unsigned long nr_segs, loff_t *ppos); |
1581 | extern loff_t no_llseek(struct file *file, loff_t offset, int origin); | 1573 | extern loff_t no_llseek(struct file *file, loff_t offset, int origin); |
1582 | extern loff_t generic_file_llseek(struct file *file, loff_t offset, int origin); | 1574 | extern loff_t generic_file_llseek(struct file *file, loff_t offset, int origin); |
1583 | extern loff_t remote_llseek(struct file *file, loff_t offset, int origin); | 1575 | extern loff_t remote_llseek(struct file *file, loff_t offset, int origin); |
1584 | extern int generic_file_open(struct inode * inode, struct file * filp); | 1576 | extern int generic_file_open(struct inode * inode, struct file * filp); |
1585 | extern int nonseekable_open(struct inode * inode, struct file * filp); | 1577 | extern int nonseekable_open(struct inode * inode, struct file * filp); |
1586 | 1578 | ||
1587 | #ifdef CONFIG_FS_XIP | 1579 | #ifdef CONFIG_FS_XIP |
1588 | extern ssize_t xip_file_read(struct file *filp, char __user *buf, size_t len, | 1580 | extern ssize_t xip_file_read(struct file *filp, char __user *buf, size_t len, |
1589 | loff_t *ppos); | 1581 | loff_t *ppos); |
1590 | extern ssize_t xip_file_sendfile(struct file *in_file, loff_t *ppos, | 1582 | extern ssize_t xip_file_sendfile(struct file *in_file, loff_t *ppos, |
1591 | size_t count, read_actor_t actor, | 1583 | size_t count, read_actor_t actor, |
1592 | void *target); | 1584 | void *target); |
1593 | extern int xip_file_mmap(struct file * file, struct vm_area_struct * vma); | 1585 | extern int xip_file_mmap(struct file * file, struct vm_area_struct * vma); |
1594 | extern ssize_t xip_file_write(struct file *filp, const char __user *buf, | 1586 | extern ssize_t xip_file_write(struct file *filp, const char __user *buf, |
1595 | size_t len, loff_t *ppos); | 1587 | size_t len, loff_t *ppos); |
1596 | extern int xip_truncate_page(struct address_space *mapping, loff_t from); | 1588 | extern int xip_truncate_page(struct address_space *mapping, loff_t from); |
1597 | #else | 1589 | #else |
1598 | static inline int xip_truncate_page(struct address_space *mapping, loff_t from) | 1590 | static inline int xip_truncate_page(struct address_space *mapping, loff_t from) |
1599 | { | 1591 | { |
1600 | return 0; | 1592 | return 0; |
1601 | } | 1593 | } |
1602 | #endif | 1594 | #endif |
1603 | 1595 | ||
1604 | static inline void do_generic_file_read(struct file * filp, loff_t *ppos, | 1596 | static inline void do_generic_file_read(struct file * filp, loff_t *ppos, |
1605 | read_descriptor_t * desc, | 1597 | read_descriptor_t * desc, |
1606 | read_actor_t actor) | 1598 | read_actor_t actor) |
1607 | { | 1599 | { |
1608 | do_generic_mapping_read(filp->f_mapping, | 1600 | do_generic_mapping_read(filp->f_mapping, |
1609 | &filp->f_ra, | 1601 | &filp->f_ra, |
1610 | filp, | 1602 | filp, |
1611 | ppos, | 1603 | ppos, |
1612 | desc, | 1604 | desc, |
1613 | actor); | 1605 | actor); |
1614 | } | 1606 | } |
1615 | 1607 | ||
1616 | ssize_t __blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode, | 1608 | ssize_t __blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode, |
1617 | struct block_device *bdev, const struct iovec *iov, loff_t offset, | 1609 | struct block_device *bdev, const struct iovec *iov, loff_t offset, |
1618 | unsigned long nr_segs, get_blocks_t get_blocks, dio_iodone_t end_io, | 1610 | unsigned long nr_segs, get_blocks_t get_blocks, dio_iodone_t end_io, |
1619 | int lock_type); | 1611 | int lock_type); |
1620 | 1612 | ||
1621 | enum { | 1613 | enum { |
1622 | DIO_LOCKING = 1, /* need locking between buffered and direct access */ | 1614 | DIO_LOCKING = 1, /* need locking between buffered and direct access */ |
1623 | DIO_NO_LOCKING, /* bdev; no locking at all between buffered/direct */ | 1615 | DIO_NO_LOCKING, /* bdev; no locking at all between buffered/direct */ |
1624 | DIO_OWN_LOCKING, /* filesystem locks buffered and direct internally */ | 1616 | DIO_OWN_LOCKING, /* filesystem locks buffered and direct internally */ |
1625 | }; | 1617 | }; |
1626 | 1618 | ||
1627 | static inline ssize_t blockdev_direct_IO(int rw, struct kiocb *iocb, | 1619 | static inline ssize_t blockdev_direct_IO(int rw, struct kiocb *iocb, |
1628 | struct inode *inode, struct block_device *bdev, const struct iovec *iov, | 1620 | struct inode *inode, struct block_device *bdev, const struct iovec *iov, |
1629 | loff_t offset, unsigned long nr_segs, get_blocks_t get_blocks, | 1621 | loff_t offset, unsigned long nr_segs, get_blocks_t get_blocks, |
1630 | dio_iodone_t end_io) | 1622 | dio_iodone_t end_io) |
1631 | { | 1623 | { |
1632 | return __blockdev_direct_IO(rw, iocb, inode, bdev, iov, offset, | 1624 | return __blockdev_direct_IO(rw, iocb, inode, bdev, iov, offset, |
1633 | nr_segs, get_blocks, end_io, DIO_LOCKING); | 1625 | nr_segs, get_blocks, end_io, DIO_LOCKING); |
1634 | } | 1626 | } |
1635 | 1627 | ||
1636 | static inline ssize_t blockdev_direct_IO_no_locking(int rw, struct kiocb *iocb, | 1628 | static inline ssize_t blockdev_direct_IO_no_locking(int rw, struct kiocb *iocb, |
1637 | struct inode *inode, struct block_device *bdev, const struct iovec *iov, | 1629 | struct inode *inode, struct block_device *bdev, const struct iovec *iov, |
1638 | loff_t offset, unsigned long nr_segs, get_blocks_t get_blocks, | 1630 | loff_t offset, unsigned long nr_segs, get_blocks_t get_blocks, |
1639 | dio_iodone_t end_io) | 1631 | dio_iodone_t end_io) |
1640 | { | 1632 | { |
1641 | return __blockdev_direct_IO(rw, iocb, inode, bdev, iov, offset, | 1633 | return __blockdev_direct_IO(rw, iocb, inode, bdev, iov, offset, |
1642 | nr_segs, get_blocks, end_io, DIO_NO_LOCKING); | 1634 | nr_segs, get_blocks, end_io, DIO_NO_LOCKING); |
1643 | } | 1635 | } |
1644 | 1636 | ||
1645 | static inline ssize_t blockdev_direct_IO_own_locking(int rw, struct kiocb *iocb, | 1637 | static inline ssize_t blockdev_direct_IO_own_locking(int rw, struct kiocb *iocb, |
1646 | struct inode *inode, struct block_device *bdev, const struct iovec *iov, | 1638 | struct inode *inode, struct block_device *bdev, const struct iovec *iov, |
1647 | loff_t offset, unsigned long nr_segs, get_blocks_t get_blocks, | 1639 | loff_t offset, unsigned long nr_segs, get_blocks_t get_blocks, |
1648 | dio_iodone_t end_io) | 1640 | dio_iodone_t end_io) |
1649 | { | 1641 | { |
1650 | return __blockdev_direct_IO(rw, iocb, inode, bdev, iov, offset, | 1642 | return __blockdev_direct_IO(rw, iocb, inode, bdev, iov, offset, |
1651 | nr_segs, get_blocks, end_io, DIO_OWN_LOCKING); | 1643 | nr_segs, get_blocks, end_io, DIO_OWN_LOCKING); |
1652 | } | 1644 | } |
1653 | 1645 | ||
1654 | extern struct file_operations generic_ro_fops; | 1646 | extern struct file_operations generic_ro_fops; |
1655 | 1647 | ||
1656 | #define special_file(m) (S_ISCHR(m)||S_ISBLK(m)||S_ISFIFO(m)||S_ISSOCK(m)) | 1648 | #define special_file(m) (S_ISCHR(m)||S_ISBLK(m)||S_ISFIFO(m)||S_ISSOCK(m)) |
1657 | 1649 | ||
1658 | extern int vfs_readlink(struct dentry *, char __user *, int, const char *); | 1650 | extern int vfs_readlink(struct dentry *, char __user *, int, const char *); |
1659 | extern int vfs_follow_link(struct nameidata *, const char *); | 1651 | extern int vfs_follow_link(struct nameidata *, const char *); |
1660 | extern int page_readlink(struct dentry *, char __user *, int); | 1652 | extern int page_readlink(struct dentry *, char __user *, int); |
1661 | extern void *page_follow_link_light(struct dentry *, struct nameidata *); | 1653 | extern void *page_follow_link_light(struct dentry *, struct nameidata *); |
1662 | extern void page_put_link(struct dentry *, struct nameidata *, void *); | 1654 | extern void page_put_link(struct dentry *, struct nameidata *, void *); |
1663 | extern int page_symlink(struct inode *inode, const char *symname, int len); | 1655 | extern int page_symlink(struct inode *inode, const char *symname, int len); |
1664 | extern struct inode_operations page_symlink_inode_operations; | 1656 | extern struct inode_operations page_symlink_inode_operations; |
1665 | extern int generic_readlink(struct dentry *, char __user *, int); | 1657 | extern int generic_readlink(struct dentry *, char __user *, int); |
1666 | extern void generic_fillattr(struct inode *, struct kstat *); | 1658 | extern void generic_fillattr(struct inode *, struct kstat *); |
1667 | extern int vfs_getattr(struct vfsmount *, struct dentry *, struct kstat *); | 1659 | extern int vfs_getattr(struct vfsmount *, struct dentry *, struct kstat *); |
1668 | void inode_add_bytes(struct inode *inode, loff_t bytes); | 1660 | void inode_add_bytes(struct inode *inode, loff_t bytes); |
1669 | void inode_sub_bytes(struct inode *inode, loff_t bytes); | 1661 | void inode_sub_bytes(struct inode *inode, loff_t bytes); |
1670 | loff_t inode_get_bytes(struct inode *inode); | 1662 | loff_t inode_get_bytes(struct inode *inode); |
1671 | void inode_set_bytes(struct inode *inode, loff_t bytes); | 1663 | void inode_set_bytes(struct inode *inode, loff_t bytes); |
1672 | 1664 | ||
1673 | extern int vfs_readdir(struct file *, filldir_t, void *); | 1665 | extern int vfs_readdir(struct file *, filldir_t, void *); |
1674 | 1666 | ||
1675 | extern int vfs_stat(char __user *, struct kstat *); | 1667 | extern int vfs_stat(char __user *, struct kstat *); |
1676 | extern int vfs_lstat(char __user *, struct kstat *); | 1668 | extern int vfs_lstat(char __user *, struct kstat *); |
1677 | extern int vfs_fstat(unsigned int, struct kstat *); | 1669 | extern int vfs_fstat(unsigned int, struct kstat *); |
1678 | 1670 | ||
1679 | extern int vfs_ioctl(struct file *, unsigned int, unsigned int, unsigned long); | 1671 | extern int vfs_ioctl(struct file *, unsigned int, unsigned int, unsigned long); |
1680 | 1672 | ||
1681 | extern struct file_system_type *get_fs_type(const char *name); | 1673 | extern struct file_system_type *get_fs_type(const char *name); |
1682 | extern struct super_block *get_super(struct block_device *); | 1674 | extern struct super_block *get_super(struct block_device *); |
1683 | extern struct super_block *user_get_super(dev_t); | 1675 | extern struct super_block *user_get_super(dev_t); |
1684 | extern void drop_super(struct super_block *sb); | 1676 | extern void drop_super(struct super_block *sb); |
1685 | 1677 | ||
1686 | extern int dcache_dir_open(struct inode *, struct file *); | 1678 | extern int dcache_dir_open(struct inode *, struct file *); |
1687 | extern int dcache_dir_close(struct inode *, struct file *); | 1679 | extern int dcache_dir_close(struct inode *, struct file *); |
1688 | extern loff_t dcache_dir_lseek(struct file *, loff_t, int); | 1680 | extern loff_t dcache_dir_lseek(struct file *, loff_t, int); |
1689 | extern int dcache_readdir(struct file *, void *, filldir_t); | 1681 | extern int dcache_readdir(struct file *, void *, filldir_t); |
1690 | extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *); | 1682 | extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *); |
1691 | extern int simple_statfs(struct super_block *, struct kstatfs *); | 1683 | extern int simple_statfs(struct super_block *, struct kstatfs *); |
1692 | extern int simple_link(struct dentry *, struct inode *, struct dentry *); | 1684 | extern int simple_link(struct dentry *, struct inode *, struct dentry *); |
1693 | extern int simple_unlink(struct inode *, struct dentry *); | 1685 | extern int simple_unlink(struct inode *, struct dentry *); |
1694 | extern int simple_rmdir(struct inode *, struct dentry *); | 1686 | extern int simple_rmdir(struct inode *, struct dentry *); |
1695 | extern int simple_rename(struct inode *, struct dentry *, struct inode *, struct dentry *); | 1687 | extern int simple_rename(struct inode *, struct dentry *, struct inode *, struct dentry *); |
1696 | extern int simple_sync_file(struct file *, struct dentry *, int); | 1688 | extern int simple_sync_file(struct file *, struct dentry *, int); |
1697 | extern int simple_empty(struct dentry *); | 1689 | extern int simple_empty(struct dentry *); |
1698 | extern int simple_readpage(struct file *file, struct page *page); | 1690 | extern int simple_readpage(struct file *file, struct page *page); |
1699 | extern int simple_prepare_write(struct file *file, struct page *page, | 1691 | extern int simple_prepare_write(struct file *file, struct page *page, |
1700 | unsigned offset, unsigned to); | 1692 | unsigned offset, unsigned to); |
1701 | extern int simple_commit_write(struct file *file, struct page *page, | 1693 | extern int simple_commit_write(struct file *file, struct page *page, |
1702 | unsigned offset, unsigned to); | 1694 | unsigned offset, unsigned to); |
1703 | 1695 | ||
1704 | extern struct dentry *simple_lookup(struct inode *, struct dentry *, struct nameidata *); | 1696 | extern struct dentry *simple_lookup(struct inode *, struct dentry *, struct nameidata *); |
1705 | extern ssize_t generic_read_dir(struct file *, char __user *, size_t, loff_t *); | 1697 | extern ssize_t generic_read_dir(struct file *, char __user *, size_t, loff_t *); |
1706 | extern struct file_operations simple_dir_operations; | 1698 | extern struct file_operations simple_dir_operations; |
1707 | extern struct inode_operations simple_dir_inode_operations; | 1699 | extern struct inode_operations simple_dir_inode_operations; |
1708 | struct tree_descr { char *name; struct file_operations *ops; int mode; }; | 1700 | struct tree_descr { char *name; struct file_operations *ops; int mode; }; |
1709 | struct dentry *d_alloc_name(struct dentry *, const char *); | 1701 | struct dentry *d_alloc_name(struct dentry *, const char *); |
1710 | extern int simple_fill_super(struct super_block *, int, struct tree_descr *); | 1702 | extern int simple_fill_super(struct super_block *, int, struct tree_descr *); |
1711 | extern int simple_pin_fs(char *name, struct vfsmount **mount, int *count); | 1703 | extern int simple_pin_fs(char *name, struct vfsmount **mount, int *count); |
1712 | extern void simple_release_fs(struct vfsmount **mount, int *count); | 1704 | extern void simple_release_fs(struct vfsmount **mount, int *count); |
1713 | 1705 | ||
1714 | extern ssize_t simple_read_from_buffer(void __user *, size_t, loff_t *, const void *, size_t); | 1706 | extern ssize_t simple_read_from_buffer(void __user *, size_t, loff_t *, const void *, size_t); |
1715 | 1707 | ||
1716 | extern int inode_change_ok(struct inode *, struct iattr *); | 1708 | extern int inode_change_ok(struct inode *, struct iattr *); |
1717 | extern int __must_check inode_setattr(struct inode *, struct iattr *); | 1709 | extern int __must_check inode_setattr(struct inode *, struct iattr *); |
1718 | 1710 | ||
1719 | extern void file_update_time(struct file *file); | 1711 | extern void file_update_time(struct file *file); |
1720 | 1712 | ||
1721 | static inline ino_t parent_ino(struct dentry *dentry) | 1713 | static inline ino_t parent_ino(struct dentry *dentry) |
1722 | { | 1714 | { |
1723 | ino_t res; | 1715 | ino_t res; |
1724 | 1716 | ||
1725 | spin_lock(&dentry->d_lock); | 1717 | spin_lock(&dentry->d_lock); |
1726 | res = dentry->d_parent->d_inode->i_ino; | 1718 | res = dentry->d_parent->d_inode->i_ino; |
1727 | spin_unlock(&dentry->d_lock); | 1719 | spin_unlock(&dentry->d_lock); |
1728 | return res; | 1720 | return res; |
1729 | } | 1721 | } |
1730 | 1722 | ||
1731 | /* kernel/fork.c */ | 1723 | /* kernel/fork.c */ |
1732 | extern int unshare_files(void); | 1724 | extern int unshare_files(void); |
1733 | 1725 | ||
1734 | /* Transaction based IO helpers */ | 1726 | /* Transaction based IO helpers */ |
1735 | 1727 | ||
1736 | /* | 1728 | /* |
1737 | * An argresp is stored in an allocated page and holds the | 1729 | * An argresp is stored in an allocated page and holds the |
1738 | * size of the argument or response, along with its content | 1730 | * size of the argument or response, along with its content |
1739 | */ | 1731 | */ |
1740 | struct simple_transaction_argresp { | 1732 | struct simple_transaction_argresp { |
1741 | ssize_t size; | 1733 | ssize_t size; |
1742 | char data[0]; | 1734 | char data[0]; |
1743 | }; | 1735 | }; |
1744 | 1736 | ||
1745 | #define SIMPLE_TRANSACTION_LIMIT (PAGE_SIZE - sizeof(struct simple_transaction_argresp)) | 1737 | #define SIMPLE_TRANSACTION_LIMIT (PAGE_SIZE - sizeof(struct simple_transaction_argresp)) |
1746 | 1738 | ||
1747 | char *simple_transaction_get(struct file *file, const char __user *buf, | 1739 | char *simple_transaction_get(struct file *file, const char __user *buf, |
1748 | size_t size); | 1740 | size_t size); |
1749 | ssize_t simple_transaction_read(struct file *file, char __user *buf, | 1741 | ssize_t simple_transaction_read(struct file *file, char __user *buf, |
1750 | size_t size, loff_t *pos); | 1742 | size_t size, loff_t *pos); |
1751 | int simple_transaction_release(struct inode *inode, struct file *file); | 1743 | int simple_transaction_release(struct inode *inode, struct file *file); |
1752 | 1744 | ||
1753 | static inline void simple_transaction_set(struct file *file, size_t n) | 1745 | static inline void simple_transaction_set(struct file *file, size_t n) |
1754 | { | 1746 | { |
1755 | struct simple_transaction_argresp *ar = file->private_data; | 1747 | struct simple_transaction_argresp *ar = file->private_data; |
1756 | 1748 | ||
1757 | BUG_ON(n > SIMPLE_TRANSACTION_LIMIT); | 1749 | BUG_ON(n > SIMPLE_TRANSACTION_LIMIT); |
1758 | 1750 | ||
1759 | /* | 1751 | /* |
1760 | * The barrier ensures that ar->size will really remain zero until | 1752 | * The barrier ensures that ar->size will really remain zero until |
1761 | * ar->data is ready for reading. | 1753 | * ar->data is ready for reading. |
1762 | */ | 1754 | */ |
1763 | smp_mb(); | 1755 | smp_mb(); |
1764 | ar->size = n; | 1756 | ar->size = n; |
1765 | } | 1757 | } |
1766 | 1758 | ||
1767 | /* | 1759 | /* |
1768 | * simple attribute files | 1760 | * simple attribute files |
1769 | * | 1761 | * |
1770 | * These attributes behave similar to those in sysfs: | 1762 | * These attributes behave similar to those in sysfs: |
1771 | * | 1763 | * |
1772 | * Writing to an attribute immediately sets a value, an open file can be | 1764 | * Writing to an attribute immediately sets a value, an open file can be |
1773 | * written to multiple times. | 1765 | * written to multiple times. |
1774 | * | 1766 | * |
1775 | * Reading from an attribute creates a buffer from the value that might get | 1767 | * Reading from an attribute creates a buffer from the value that might get |
1776 | * read with multiple read calls. When the attribute has been read | 1768 | * read with multiple read calls. When the attribute has been read |
1777 | * completely, no further read calls are possible until the file is opened | 1769 | * completely, no further read calls are possible until the file is opened |
1778 | * again. | 1770 | * again. |
1779 | * | 1771 | * |
1780 | * All attributes contain a text representation of a numeric value | 1772 | * All attributes contain a text representation of a numeric value |
1781 | * that are accessed with the get() and set() functions. | 1773 | * that are accessed with the get() and set() functions. |
1782 | */ | 1774 | */ |
1783 | #define DEFINE_SIMPLE_ATTRIBUTE(__fops, __get, __set, __fmt) \ | 1775 | #define DEFINE_SIMPLE_ATTRIBUTE(__fops, __get, __set, __fmt) \ |
1784 | static int __fops ## _open(struct inode *inode, struct file *file) \ | 1776 | static int __fops ## _open(struct inode *inode, struct file *file) \ |
1785 | { \ | 1777 | { \ |
1786 | __simple_attr_check_format(__fmt, 0ull); \ | 1778 | __simple_attr_check_format(__fmt, 0ull); \ |
1787 | return simple_attr_open(inode, file, __get, __set, __fmt); \ | 1779 | return simple_attr_open(inode, file, __get, __set, __fmt); \ |
1788 | } \ | 1780 | } \ |
1789 | static struct file_operations __fops = { \ | 1781 | static struct file_operations __fops = { \ |
1790 | .owner = THIS_MODULE, \ | 1782 | .owner = THIS_MODULE, \ |
1791 | .open = __fops ## _open, \ | 1783 | .open = __fops ## _open, \ |
1792 | .release = simple_attr_close, \ | 1784 | .release = simple_attr_close, \ |
1793 | .read = simple_attr_read, \ | 1785 | .read = simple_attr_read, \ |
1794 | .write = simple_attr_write, \ | 1786 | .write = simple_attr_write, \ |
1795 | }; | 1787 | }; |
1796 | 1788 | ||
1797 | static inline void __attribute__((format(printf, 1, 2))) | 1789 | static inline void __attribute__((format(printf, 1, 2))) |
1798 | __simple_attr_check_format(const char *fmt, ...) | 1790 | __simple_attr_check_format(const char *fmt, ...) |
1799 | { | 1791 | { |
1800 | /* don't do anything, just let the compiler check the arguments; */ | 1792 | /* don't do anything, just let the compiler check the arguments; */ |
1801 | } | 1793 | } |
1802 | 1794 | ||
1803 | int simple_attr_open(struct inode *inode, struct file *file, | 1795 | int simple_attr_open(struct inode *inode, struct file *file, |
1804 | u64 (*get)(void *), void (*set)(void *, u64), | 1796 | u64 (*get)(void *), void (*set)(void *, u64), |
1805 | const char *fmt); | 1797 | const char *fmt); |
1806 | int simple_attr_close(struct inode *inode, struct file *file); | 1798 | int simple_attr_close(struct inode *inode, struct file *file); |
1807 | ssize_t simple_attr_read(struct file *file, char __user *buf, | 1799 | ssize_t simple_attr_read(struct file *file, char __user *buf, |
1808 | size_t len, loff_t *ppos); | 1800 | size_t len, loff_t *ppos); |
1809 | ssize_t simple_attr_write(struct file *file, const char __user *buf, | 1801 | ssize_t simple_attr_write(struct file *file, const char __user *buf, |
1810 | size_t len, loff_t *ppos); | 1802 | size_t len, loff_t *ppos); |
1811 | 1803 | ||
1812 | 1804 | ||
1813 | #ifdef CONFIG_SECURITY | 1805 | #ifdef CONFIG_SECURITY |
1814 | static inline char *alloc_secdata(void) | 1806 | static inline char *alloc_secdata(void) |
1815 | { | 1807 | { |
1816 | return (char *)get_zeroed_page(GFP_KERNEL); | 1808 | return (char *)get_zeroed_page(GFP_KERNEL); |
1817 | } | 1809 | } |
1818 | 1810 | ||
1819 | static inline void free_secdata(void *secdata) | 1811 | static inline void free_secdata(void *secdata) |
1820 | { | 1812 | { |
1821 | free_page((unsigned long)secdata); | 1813 | free_page((unsigned long)secdata); |
1822 | } | 1814 | } |
1823 | #else | 1815 | #else |
1824 | static inline char *alloc_secdata(void) | 1816 | static inline char *alloc_secdata(void) |
1825 | { | 1817 | { |
1826 | return (char *)1; | 1818 | return (char *)1; |
1827 | } | 1819 | } |
1828 | 1820 | ||
1829 | static inline void free_secdata(void *secdata) | 1821 | static inline void free_secdata(void *secdata) |
1830 | { } | 1822 | { } |
1831 | #endif /* CONFIG_SECURITY */ | 1823 | #endif /* CONFIG_SECURITY */ |
1832 | 1824 | ||
1833 | #endif /* __KERNEL__ */ | 1825 | #endif /* __KERNEL__ */ |
1834 | #endif /* _LINUX_FS_H */ | 1826 | #endif /* _LINUX_FS_H */ |
1835 | 1827 |