]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | The text below describes the locking rules for VFS-related methods. |
2 | It is (believed to be) up-to-date. *Please*, if you change anything in | |
3 | prototypes or locking protocols - update this file. And update the relevant | |
4 | instances in the tree, don't leave that to maintainers of filesystems/devices/ | |
5 | etc. At the very least, put the list of dubious cases in the end of this file. | |
6 | Don't turn it into log - maintainers of out-of-the-tree code are supposed to | |
7 | be able to use diff(1). | |
8 | Thing currently missing here: socket operations. Alexey? | |
9 | ||
10 | --------------------------- dentry_operations -------------------------- | |
11 | prototypes: | |
12 | int (*d_revalidate)(struct dentry *, int); | |
13 | int (*d_hash) (struct dentry *, struct qstr *); | |
14 | int (*d_compare) (struct dentry *, struct qstr *, struct qstr *); | |
15 | int (*d_delete)(struct dentry *); | |
16 | void (*d_release)(struct dentry *); | |
17 | void (*d_iput)(struct dentry *, struct inode *); | |
c23fbb6b | 18 | char *(*d_dname)((struct dentry *dentry, char *buffer, int buflen); |
1da177e4 LT |
19 | |
20 | locking rules: | |
21 | none have BKL | |
22 | dcache_lock rename_lock ->d_lock may block | |
23 | d_revalidate: no no no yes | |
24 | d_hash no no no yes | |
25 | d_compare: no yes no no | |
26 | d_delete: yes no yes no | |
27 | d_release: no no no yes | |
28 | d_iput: no no no yes | |
c23fbb6b | 29 | d_dname: no no no no |
1da177e4 LT |
30 | |
31 | --------------------------- inode_operations --------------------------- | |
32 | prototypes: | |
33 | int (*create) (struct inode *,struct dentry *,int, struct nameidata *); | |
34 | struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameid | |
35 | ata *); | |
36 | int (*link) (struct dentry *,struct inode *,struct dentry *); | |
37 | int (*unlink) (struct inode *,struct dentry *); | |
38 | int (*symlink) (struct inode *,struct dentry *,const char *); | |
39 | int (*mkdir) (struct inode *,struct dentry *,int); | |
40 | int (*rmdir) (struct inode *,struct dentry *); | |
41 | int (*mknod) (struct inode *,struct dentry *,int,dev_t); | |
42 | int (*rename) (struct inode *, struct dentry *, | |
43 | struct inode *, struct dentry *); | |
44 | int (*readlink) (struct dentry *, char __user *,int); | |
45 | int (*follow_link) (struct dentry *, struct nameidata *); | |
46 | void (*truncate) (struct inode *); | |
47 | int (*permission) (struct inode *, int, struct nameidata *); | |
48 | int (*setattr) (struct dentry *, struct iattr *); | |
49 | int (*getattr) (struct vfsmount *, struct dentry *, struct kstat *); | |
50 | int (*setxattr) (struct dentry *, const char *,const void *,size_t,int); | |
51 | ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t); | |
52 | ssize_t (*listxattr) (struct dentry *, char *, size_t); | |
53 | int (*removexattr) (struct dentry *, const char *); | |
54 | ||
55 | locking rules: | |
56 | all may block, none have BKL | |
a7bc02f4 | 57 | i_mutex(inode) |
1da177e4 LT |
58 | lookup: yes |
59 | create: yes | |
60 | link: yes (both) | |
61 | mknod: yes | |
62 | symlink: yes | |
63 | mkdir: yes | |
64 | unlink: yes (both) | |
65 | rmdir: yes (both) (see below) | |
66 | rename: yes (all) (see below) | |
67 | readlink: no | |
68 | follow_link: no | |
69 | truncate: yes (see below) | |
70 | setattr: yes | |
71 | permission: no | |
72 | getattr: no | |
73 | setxattr: yes | |
74 | getxattr: no | |
75 | listxattr: no | |
76 | removexattr: yes | |
a7bc02f4 | 77 | Additionally, ->rmdir(), ->unlink() and ->rename() have ->i_mutex on |
1da177e4 LT |
78 | victim. |
79 | cross-directory ->rename() has (per-superblock) ->s_vfs_rename_sem. | |
80 | ->truncate() is never called directly - it's a callback, not a | |
81 | method. It's called by vmtruncate() - library function normally used by | |
82 | ->setattr(). Locking information above applies to that call (i.e. is | |
83 | inherited from ->setattr() - vmtruncate() is used when ATTR_SIZE had been | |
84 | passed). | |
85 | ||
86 | See Documentation/filesystems/directory-locking for more detailed discussion | |
87 | of the locking scheme for directory operations. | |
88 | ||
89 | --------------------------- super_operations --------------------------- | |
90 | prototypes: | |
91 | struct inode *(*alloc_inode)(struct super_block *sb); | |
92 | void (*destroy_inode)(struct inode *); | |
1da177e4 LT |
93 | void (*dirty_inode) (struct inode *); |
94 | int (*write_inode) (struct inode *, int); | |
336fb3b9 AV |
95 | int (*drop_inode) (struct inode *); |
96 | void (*evict_inode) (struct inode *); | |
1da177e4 LT |
97 | void (*put_super) (struct super_block *); |
98 | void (*write_super) (struct super_block *); | |
99 | int (*sync_fs)(struct super_block *sb, int wait); | |
c4be0c1d TS |
100 | int (*freeze_fs) (struct super_block *); |
101 | int (*unfreeze_fs) (struct super_block *); | |
726c3342 | 102 | int (*statfs) (struct dentry *, struct kstatfs *); |
1da177e4 | 103 | int (*remount_fs) (struct super_block *, int *, char *); |
1da177e4 LT |
104 | void (*umount_begin) (struct super_block *); |
105 | int (*show_options)(struct seq_file *, struct vfsmount *); | |
106 | ssize_t (*quota_read)(struct super_block *, int, char *, size_t, loff_t); | |
107 | ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t); | |
108 | ||
109 | locking rules: | |
336fb3b9 | 110 | All may block [not true, see below] |
7e325d3a CH |
111 | None have BKL |
112 | s_umount | |
113 | alloc_inode: | |
114 | destroy_inode: | |
115 | dirty_inode: (must not sleep) | |
116 | write_inode: | |
117 | drop_inode: !!!inode_lock!!! | |
336fb3b9 | 118 | evict_inode: |
7e325d3a CH |
119 | put_super: write |
120 | write_super: read | |
121 | sync_fs: read | |
122 | freeze_fs: read | |
123 | unfreeze_fs: read | |
336fb3b9 AV |
124 | statfs: maybe(read) (see below) |
125 | remount_fs: write | |
7e325d3a CH |
126 | umount_begin: no |
127 | show_options: no (namespace_sem) | |
128 | quota_read: no (see below) | |
129 | quota_write: no (see below) | |
1da177e4 | 130 | |
336fb3b9 AV |
131 | ->statfs() has s_umount (shared) when called by ustat(2) (native or |
132 | compat), but that's an accident of bad API; s_umount is used to pin | |
133 | the superblock down when we only have dev_t given us by userland to | |
134 | identify the superblock. Everything else (statfs(), fstatfs(), etc.) | |
135 | doesn't hold it when calling ->statfs() - superblock is pinned down | |
136 | by resolving the pathname passed to syscall. | |
1da177e4 LT |
137 | ->quota_read() and ->quota_write() functions are both guaranteed to |
138 | be the only ones operating on the quota file by the quota code (via | |
139 | dqio_sem) (unless an admin really wants to screw up something and | |
140 | writes to quota files with quotas on). For other details about locking | |
141 | see also dquot_operations section. | |
142 | ||
143 | --------------------------- file_system_type --------------------------- | |
144 | prototypes: | |
5d8b2ebf JC |
145 | int (*get_sb) (struct file_system_type *, int, |
146 | const char *, void *, struct vfsmount *); | |
1da177e4 LT |
147 | void (*kill_sb) (struct super_block *); |
148 | locking rules: | |
149 | may block BKL | |
adaae721 CH |
150 | get_sb yes no |
151 | kill_sb yes no | |
1da177e4 | 152 | |
454e2398 DH |
153 | ->get_sb() returns error or 0 with locked superblock attached to the vfsmount |
154 | (exclusive on ->s_umount). | |
1da177e4 LT |
155 | ->kill_sb() takes a write-locked superblock, does all shutdown work on it, |
156 | unlocks and drops the reference. | |
157 | ||
158 | --------------------------- address_space_operations -------------------------- | |
159 | prototypes: | |
160 | int (*writepage)(struct page *page, struct writeback_control *wbc); | |
161 | int (*readpage)(struct file *, struct page *); | |
162 | int (*sync_page)(struct page *); | |
163 | int (*writepages)(struct address_space *, struct writeback_control *); | |
164 | int (*set_page_dirty)(struct page *page); | |
165 | int (*readpages)(struct file *filp, struct address_space *mapping, | |
166 | struct list_head *pages, unsigned nr_pages); | |
4e02ed4b NP |
167 | int (*write_begin)(struct file *, struct address_space *mapping, |
168 | loff_t pos, unsigned len, unsigned flags, | |
169 | struct page **pagep, void **fsdata); | |
170 | int (*write_end)(struct file *, struct address_space *mapping, | |
171 | loff_t pos, unsigned len, unsigned copied, | |
172 | struct page *page, void *fsdata); | |
1da177e4 LT |
173 | sector_t (*bmap)(struct address_space *, sector_t); |
174 | int (*invalidatepage) (struct page *, unsigned long); | |
175 | int (*releasepage) (struct page *, int); | |
6072d13c | 176 | void (*freepage)(struct page *); |
1da177e4 LT |
177 | int (*direct_IO)(int, struct kiocb *, const struct iovec *iov, |
178 | loff_t offset, unsigned long nr_segs); | |
e3db7691 | 179 | int (*launder_page) (struct page *); |
1da177e4 LT |
180 | |
181 | locking rules: | |
6072d13c | 182 | All except set_page_dirty and freepage may block |
1da177e4 | 183 | |
ca0dbd86 | 184 | BKL PageLocked(page) i_mutex |
1da177e4 LT |
185 | writepage: no yes, unlocks (see below) |
186 | readpage: no yes, unlocks | |
187 | sync_page: no maybe | |
188 | writepages: no | |
189 | set_page_dirty no no | |
190 | readpages: no | |
afddba49 NP |
191 | write_begin: no locks the page yes |
192 | write_end: no yes, unlocks yes | |
193 | perform_write: no n/a yes | |
fe36adf4 | 194 | bmap: no |
1da177e4 LT |
195 | invalidatepage: no yes |
196 | releasepage: no yes | |
6072d13c | 197 | freepage: no yes |
1da177e4 | 198 | direct_IO: no |
e3db7691 | 199 | launder_page: no yes |
1da177e4 | 200 | |
4e02ed4b | 201 | ->write_begin(), ->write_end(), ->sync_page() and ->readpage() |
1da177e4 LT |
202 | may be called from the request handler (/dev/loop). |
203 | ||
204 | ->readpage() unlocks the page, either synchronously or via I/O | |
205 | completion. | |
206 | ||
207 | ->readpages() populates the pagecache with the passed pages and starts | |
208 | I/O against them. They come unlocked upon I/O completion. | |
209 | ||
210 | ->writepage() is used for two purposes: for "memory cleansing" and for | |
211 | "sync". These are quite different operations and the behaviour may differ | |
212 | depending upon the mode. | |
213 | ||
214 | If writepage is called for sync (wbc->sync_mode != WBC_SYNC_NONE) then | |
215 | it *must* start I/O against the page, even if that would involve | |
216 | blocking on in-progress I/O. | |
217 | ||
218 | If writepage is called for memory cleansing (sync_mode == | |
219 | WBC_SYNC_NONE) then its role is to get as much writeout underway as | |
220 | possible. So writepage should try to avoid blocking against | |
221 | currently-in-progress I/O. | |
222 | ||
223 | If the filesystem is not called for "sync" and it determines that it | |
224 | would need to block against in-progress I/O to be able to start new I/O | |
225 | against the page the filesystem should redirty the page with | |
226 | redirty_page_for_writepage(), then unlock the page and return zero. | |
227 | This may also be done to avoid internal deadlocks, but rarely. | |
228 | ||
3a4fa0a2 | 229 | If the filesystem is called for sync then it must wait on any |
1da177e4 LT |
230 | in-progress I/O and then start new I/O. |
231 | ||
2054606a ND |
232 | The filesystem should unlock the page synchronously, before returning to the |
233 | caller, unless ->writepage() returns special WRITEPAGE_ACTIVATE | |
234 | value. WRITEPAGE_ACTIVATE means that page cannot really be written out | |
235 | currently, and VM should stop calling ->writepage() on this page for some | |
236 | time. VM does this by moving page to the head of the active list, hence the | |
237 | name. | |
1da177e4 LT |
238 | |
239 | Unless the filesystem is going to redirty_page_for_writepage(), unlock the page | |
240 | and return zero, writepage *must* run set_page_writeback() against the page, | |
241 | followed by unlocking it. Once set_page_writeback() has been run against the | |
242 | page, write I/O can be submitted and the write I/O completion handler must run | |
243 | end_page_writeback() once the I/O is complete. If no I/O is submitted, the | |
244 | filesystem must run end_page_writeback() against the page before returning from | |
245 | writepage. | |
246 | ||
247 | That is: after 2.5.12, pages which are under writeout are *not* locked. Note, | |
248 | if the filesystem needs the page to be locked during writeout, that is ok, too, | |
249 | the page is allowed to be unlocked at any point in time between the calls to | |
250 | set_page_writeback() and end_page_writeback(). | |
251 | ||
252 | Note, failure to run either redirty_page_for_writepage() or the combination of | |
253 | set_page_writeback()/end_page_writeback() on a page submitted to writepage | |
254 | will leave the page itself marked clean but it will be tagged as dirty in the | |
255 | radix tree. This incoherency can lead to all sorts of hard-to-debug problems | |
256 | in the filesystem like having dirty inodes at umount and losing written data. | |
257 | ||
258 | ->sync_page() locking rules are not well-defined - usually it is called | |
259 | with lock on page, but that is not guaranteed. Considering the currently | |
260 | existing instances of this method ->sync_page() itself doesn't look | |
261 | well-defined... | |
262 | ||
263 | ->writepages() is used for periodic writeback and for syscall-initiated | |
264 | sync operations. The address_space should start I/O against at least | |
265 | *nr_to_write pages. *nr_to_write must be decremented for each page which is | |
266 | written. The address_space implementation may write more (or less) pages | |
267 | than *nr_to_write asks for, but it should try to be reasonably close. If | |
268 | nr_to_write is NULL, all dirty pages must be written. | |
269 | ||
270 | writepages should _only_ write pages which are present on | |
271 | mapping->io_pages. | |
272 | ||
273 | ->set_page_dirty() is called from various places in the kernel | |
274 | when the target page is marked as needing writeback. It may be called | |
275 | under spinlock (it cannot block) and is sometimes called with the page | |
276 | not locked. | |
277 | ||
278 | ->bmap() is currently used by legacy ioctl() (FIBMAP) provided by some | |
279 | filesystems and by the swapper. The latter will eventually go away. All | |
280 | instances do not actually need the BKL. Please, keep it that way and don't | |
281 | breed new callers. | |
282 | ||
283 | ->invalidatepage() is called when the filesystem must attempt to drop | |
284 | some or all of the buffers from the page when it is being truncated. It | |
285 | returns zero on success. If ->invalidatepage is zero, the kernel uses | |
286 | block_invalidatepage() instead. | |
287 | ||
288 | ->releasepage() is called when the kernel is about to try to drop the | |
289 | buffers from the page in preparation for freeing it. It returns zero to | |
290 | indicate that the buffers are (or may be) freeable. If ->releasepage is zero, | |
291 | the kernel assumes that the fs has no private interest in the buffers. | |
292 | ||
6072d13c LT |
293 | ->freepage() is called when the kernel is done dropping the page |
294 | from the page cache. | |
295 | ||
e3db7691 TM |
296 | ->launder_page() may be called prior to releasing a page if |
297 | it is still found to be dirty. It returns zero if the page was successfully | |
298 | cleaned, or an error value if not. Note that in order to prevent the page | |
299 | getting mapped back in and redirtied, it needs to be kept locked | |
300 | across the entire operation. | |
301 | ||
1da177e4 LT |
302 | Note: currently almost all instances of address_space methods are |
303 | using BKL for internal serialization and that's one of the worst sources | |
304 | of contention. Normally they are calling library functions (in fs/buffer.c) | |
305 | and pass foo_get_block() as a callback (on local block-based filesystems, | |
306 | indeed). BKL is not needed for library stuff and is usually taken by | |
307 | foo_get_block(). It's an overkill, since block bitmaps can be protected by | |
308 | internal fs locking and real critical areas are much smaller than the areas | |
309 | filesystems protect now. | |
310 | ||
311 | ----------------------- file_lock_operations ------------------------------ | |
312 | prototypes: | |
313 | void (*fl_insert)(struct file_lock *); /* lock insertion callback */ | |
314 | void (*fl_remove)(struct file_lock *); /* lock removal callback */ | |
315 | void (*fl_copy_lock)(struct file_lock *, struct file_lock *); | |
316 | void (*fl_release_private)(struct file_lock *); | |
317 | ||
318 | ||
319 | locking rules: | |
320 | BKL may block | |
321 | fl_insert: yes no | |
322 | fl_remove: yes no | |
323 | fl_copy_lock: yes no | |
324 | fl_release_private: yes yes | |
325 | ||
326 | ----------------------- lock_manager_operations --------------------------- | |
327 | prototypes: | |
328 | int (*fl_compare_owner)(struct file_lock *, struct file_lock *); | |
329 | void (*fl_notify)(struct file_lock *); /* unblock callback */ | |
1da177e4 LT |
330 | void (*fl_release_private)(struct file_lock *); |
331 | void (*fl_break)(struct file_lock *); /* break_lease callback */ | |
332 | ||
333 | locking rules: | |
334 | BKL may block | |
335 | fl_compare_owner: yes no | |
336 | fl_notify: yes no | |
1da177e4 LT |
337 | fl_release_private: yes yes |
338 | fl_break: yes no | |
339 | ||
340 | Currently only NFSD and NLM provide instances of this class. None of the | |
341 | them block. If you have out-of-tree instances - please, show up. Locking | |
342 | in that area will change. | |
343 | --------------------------- buffer_head ----------------------------------- | |
344 | prototypes: | |
345 | void (*b_end_io)(struct buffer_head *bh, int uptodate); | |
346 | ||
347 | locking rules: | |
348 | called from interrupts. In other words, extreme care is needed here. | |
349 | bh is locked, but that's all warranties we have here. Currently only RAID1, | |
350 | highmem, fs/buffer.c, and fs/ntfs/aops.c are providing these. Block devices | |
351 | call this method upon the IO completion. | |
352 | ||
353 | --------------------------- block_device_operations ----------------------- | |
354 | prototypes: | |
e1455d1b CH |
355 | int (*open) (struct block_device *, fmode_t); |
356 | int (*release) (struct gendisk *, fmode_t); | |
357 | int (*ioctl) (struct block_device *, fmode_t, unsigned, unsigned long); | |
358 | int (*compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long); | |
359 | int (*direct_access) (struct block_device *, sector_t, void **, unsigned long *); | |
1da177e4 | 360 | int (*media_changed) (struct gendisk *); |
e1455d1b | 361 | void (*unlock_native_capacity) (struct gendisk *); |
1da177e4 | 362 | int (*revalidate_disk) (struct gendisk *); |
e1455d1b CH |
363 | int (*getgeo)(struct block_device *, struct hd_geometry *); |
364 | void (*swap_slot_free_notify) (struct block_device *, unsigned long); | |
1da177e4 LT |
365 | |
366 | locking rules: | |
e1455d1b CH |
367 | BKL bd_mutex |
368 | open: no yes | |
369 | release: no yes | |
370 | ioctl: no no | |
371 | compat_ioctl: no no | |
372 | direct_access: no no | |
1da177e4 | 373 | media_changed: no no |
e1455d1b | 374 | unlock_native_capacity: no no |
1da177e4 | 375 | revalidate_disk: no no |
e1455d1b CH |
376 | getgeo: no no |
377 | swap_slot_free_notify: no no (see below) | |
378 | ||
379 | media_changed, unlock_native_capacity and revalidate_disk are called only from | |
380 | check_disk_change(). | |
381 | ||
382 | swap_slot_free_notify is called with swap_lock and sometimes the page lock | |
383 | held. | |
1da177e4 | 384 | |
1da177e4 LT |
385 | |
386 | --------------------------- file_operations ------------------------------- | |
387 | prototypes: | |
388 | loff_t (*llseek) (struct file *, loff_t, int); | |
389 | ssize_t (*read) (struct file *, char __user *, size_t, loff_t *); | |
1da177e4 | 390 | ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *); |
027445c3 BP |
391 | ssize_t (*aio_read) (struct kiocb *, const struct iovec *, unsigned long, loff_t); |
392 | ssize_t (*aio_write) (struct kiocb *, const struct iovec *, unsigned long, loff_t); | |
1da177e4 LT |
393 | int (*readdir) (struct file *, void *, filldir_t); |
394 | unsigned int (*poll) (struct file *, struct poll_table_struct *); | |
1da177e4 LT |
395 | long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long); |
396 | long (*compat_ioctl) (struct file *, unsigned int, unsigned long); | |
397 | int (*mmap) (struct file *, struct vm_area_struct *); | |
398 | int (*open) (struct inode *, struct file *); | |
399 | int (*flush) (struct file *); | |
400 | int (*release) (struct inode *, struct file *); | |
7ea80859 | 401 | int (*fsync) (struct file *, int datasync); |
1da177e4 LT |
402 | int (*aio_fsync) (struct kiocb *, int datasync); |
403 | int (*fasync) (int, struct file *, int); | |
404 | int (*lock) (struct file *, int, struct file_lock *); | |
405 | ssize_t (*readv) (struct file *, const struct iovec *, unsigned long, | |
406 | loff_t *); | |
407 | ssize_t (*writev) (struct file *, const struct iovec *, unsigned long, | |
408 | loff_t *); | |
409 | ssize_t (*sendfile) (struct file *, loff_t *, size_t, read_actor_t, | |
410 | void __user *); | |
411 | ssize_t (*sendpage) (struct file *, struct page *, int, size_t, | |
412 | loff_t *, int); | |
413 | unsigned long (*get_unmapped_area)(struct file *, unsigned long, | |
414 | unsigned long, unsigned long, unsigned long); | |
415 | int (*check_flags)(int); | |
1da177e4 LT |
416 | }; |
417 | ||
418 | locking rules: | |
5f820f64 | 419 | All may block. |
1da177e4 LT |
420 | BKL |
421 | llseek: no (see below) | |
422 | read: no | |
423 | aio_read: no | |
424 | write: no | |
425 | aio_write: no | |
426 | readdir: no | |
427 | poll: no | |
b19dd42f | 428 | unlocked_ioctl: no |
1da177e4 LT |
429 | compat_ioctl: no |
430 | mmap: no | |
adaae721 | 431 | open: no |
1da177e4 LT |
432 | flush: no |
433 | release: no | |
434 | fsync: no (see below) | |
435 | aio_fsync: no | |
adaae721 | 436 | fasync: no |
1da177e4 LT |
437 | lock: yes |
438 | readv: no | |
439 | writev: no | |
440 | sendfile: no | |
441 | sendpage: no | |
442 | get_unmapped_area: no | |
443 | check_flags: no | |
1da177e4 LT |
444 | |
445 | ->llseek() locking has moved from llseek to the individual llseek | |
446 | implementations. If your fs is not using generic_file_llseek, you | |
447 | need to acquire and release the appropriate locks in your ->llseek(). | |
448 | For many filesystems, it is probably safe to acquire the inode | |
866707fc JB |
449 | mutex or just to use i_size_read() instead. |
450 | Note: this does not protect the file->f_pos against concurrent modifications | |
451 | since this is something the userspace has to take care about. | |
1da177e4 | 452 | |
1da177e4 LT |
453 | Note: ext2_release() was *the* source of contention on fs-intensive |
454 | loads and dropping BKL on ->release() helps to get rid of that (we still | |
455 | grab BKL for cases when we close a file that had been opened r/w, but that | |
456 | can and should be done using the internal locking with smaller critical areas). | |
457 | Current worst offender is ext2_get_block()... | |
458 | ||
76398425 JC |
459 | ->fasync() is called without BKL protection, and is responsible for |
460 | maintaining the FASYNC bit in filp->f_flags. Most instances call | |
461 | fasync_helper(), which does that maintenance, so it's not normally | |
462 | something one needs to worry about. Return values > 0 will be mapped to | |
463 | zero in the VFS layer. | |
1da177e4 LT |
464 | |
465 | ->readdir() and ->ioctl() on directories must be changed. Ideally we would | |
466 | move ->readdir() to inode_operations and use a separate method for directory | |
467 | ->ioctl() or kill the latter completely. One of the problems is that for | |
468 | anything that resembles union-mount we won't have a struct file for all | |
469 | components. And there are other reasons why the current interface is a mess... | |
470 | ||
1da177e4 LT |
471 | ->read on directories probably must go away - we should just enforce -EISDIR |
472 | in sys_read() and friends. | |
473 | ||
a7bc02f4 | 474 | ->fsync() has i_mutex on inode. |
1da177e4 LT |
475 | |
476 | --------------------------- dquot_operations ------------------------------- | |
477 | prototypes: | |
1da177e4 LT |
478 | int (*write_dquot) (struct dquot *); |
479 | int (*acquire_dquot) (struct dquot *); | |
480 | int (*release_dquot) (struct dquot *); | |
481 | int (*mark_dirty) (struct dquot *); | |
482 | int (*write_info) (struct super_block *, int); | |
483 | ||
484 | These operations are intended to be more or less wrapping functions that ensure | |
485 | a proper locking wrt the filesystem and call the generic quota operations. | |
486 | ||
487 | What filesystem should expect from the generic quota functions: | |
488 | ||
489 | FS recursion Held locks when called | |
1da177e4 LT |
490 | write_dquot: yes dqonoff_sem or dqptr_sem |
491 | acquire_dquot: yes dqonoff_sem or dqptr_sem | |
492 | release_dquot: yes dqonoff_sem or dqptr_sem | |
493 | mark_dirty: no - | |
494 | write_info: yes dqonoff_sem | |
495 | ||
496 | FS recursion means calling ->quota_read() and ->quota_write() from superblock | |
497 | operations. | |
498 | ||
1da177e4 LT |
499 | More details about quota locking can be found in fs/dquot.c. |
500 | ||
501 | --------------------------- vm_operations_struct ----------------------------- | |
502 | prototypes: | |
503 | void (*open)(struct vm_area_struct*); | |
504 | void (*close)(struct vm_area_struct*); | |
d0217ac0 | 505 | int (*fault)(struct vm_area_struct*, struct vm_fault *); |
c2ec175c | 506 | int (*page_mkwrite)(struct vm_area_struct *, struct vm_fault *); |
28b2ee20 | 507 | int (*access)(struct vm_area_struct *, unsigned long, void*, int, int); |
1da177e4 LT |
508 | |
509 | locking rules: | |
ed2f2f9b | 510 | BKL mmap_sem PageLocked(page) |
1da177e4 LT |
511 | open: no yes |
512 | close: no yes | |
b827e496 NP |
513 | fault: no yes can return with page locked |
514 | page_mkwrite: no yes can return with page locked | |
28b2ee20 | 515 | access: no yes |
ed2f2f9b | 516 | |
b827e496 NP |
517 | ->fault() is called when a previously not present pte is about |
518 | to be faulted in. The filesystem must find and return the page associated | |
519 | with the passed in "pgoff" in the vm_fault structure. If it is possible that | |
520 | the page may be truncated and/or invalidated, then the filesystem must lock | |
521 | the page, then ensure it is not already truncated (the page lock will block | |
522 | subsequent truncate), and then return with VM_FAULT_LOCKED, and the page | |
523 | locked. The VM will unlock the page. | |
524 | ||
525 | ->page_mkwrite() is called when a previously read-only pte is | |
526 | about to become writeable. The filesystem again must ensure that there are | |
527 | no truncate/invalidate races, and then return with the page locked. If | |
528 | the page has been truncated, the filesystem should not look up a new page | |
529 | like the ->fault() handler, but simply return with VM_FAULT_NOPAGE, which | |
530 | will cause the VM to retry the fault. | |
1da177e4 | 531 | |
28b2ee20 RR |
532 | ->access() is called when get_user_pages() fails in |
533 | acces_process_vm(), typically used to debug a process through | |
534 | /proc/pid/mem or ptrace. This function is needed only for | |
535 | VM_IO | VM_PFNMAP VMAs. | |
536 | ||
1da177e4 LT |
537 | ================================================================================ |
538 | Dubious stuff | |
539 | ||
540 | (if you break something or notice that it is broken and do not fix it yourself | |
541 | - at least put it here) | |
542 | ||
543 | ipc/shm.c::shm_delete() - may need BKL. | |
544 | ->read() and ->write() in many drivers are (probably) missing BKL. |