blob: 2db4283efa8dbf99e0e6576edc8d0a054d3b299d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001 The text below describes the locking rules for VFS-related methods.
2It is (believed to be) up-to-date. *Please*, if you change anything in
3prototypes or locking protocols - update this file. And update the relevant
4instances in the tree, don't leave that to maintainers of filesystems/devices/
5etc. At the very least, put the list of dubious cases in the end of this file.
6Don't turn it into log - maintainers of out-of-the-tree code are supposed to
7be able to use diff(1).
8 Thing currently missing here: socket operations. Alexey?
9
10--------------------------- dentry_operations --------------------------
11prototypes:
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 *);
Eric Dumazetc23fbb62007-05-08 00:26:18 -070018 char *(*d_dname)((struct dentry *dentry, char *buffer, int buflen);
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
20locking rules:
21 none have BKL
22 dcache_lock rename_lock ->d_lock may block
23d_revalidate: no no no yes
24d_hash no no no yes
25d_compare: no yes no no
26d_delete: yes no yes no
27d_release: no no no yes
28d_iput: no no no yes
Eric Dumazetc23fbb62007-05-08 00:26:18 -070029d_dname: no no no no
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
31--------------------------- inode_operations ---------------------------
32prototypes:
33 int (*create) (struct inode *,struct dentry *,int, struct nameidata *);
34 struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameid
35ata *);
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
55locking rules:
56 all may block, none have BKL
Artem Bityutskiya7bc02f2007-05-09 07:53:16 +020057 i_mutex(inode)
Linus Torvalds1da177e2005-04-16 15:20:36 -070058lookup: yes
59create: yes
60link: yes (both)
61mknod: yes
62symlink: yes
63mkdir: yes
64unlink: yes (both)
65rmdir: yes (both) (see below)
66rename: yes (all) (see below)
67readlink: no
68follow_link: no
69truncate: yes (see below)
70setattr: yes
71permission: no
72getattr: no
73setxattr: yes
74getxattr: no
75listxattr: no
76removexattr: yes
Artem Bityutskiya7bc02f2007-05-09 07:53:16 +020077 Additionally, ->rmdir(), ->unlink() and ->rename() have ->i_mutex on
Linus Torvalds1da177e2005-04-16 15:20:36 -070078victim.
79 cross-directory ->rename() has (per-superblock) ->s_vfs_rename_sem.
80 ->truncate() is never called directly - it's a callback, not a
81method. It's called by vmtruncate() - library function normally used by
82->setattr(). Locking information above applies to that call (i.e. is
83inherited from ->setattr() - vmtruncate() is used when ATTR_SIZE had been
84passed).
85
86See Documentation/filesystems/directory-locking for more detailed discussion
87of the locking scheme for directory operations.
88
89--------------------------- super_operations ---------------------------
90prototypes:
91 struct inode *(*alloc_inode)(struct super_block *sb);
92 void (*destroy_inode)(struct inode *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 void (*dirty_inode) (struct inode *);
94 int (*write_inode) (struct inode *, int);
Al Viro336fb3b2010-06-08 00:37:12 -040095 int (*drop_inode) (struct inode *);
96 void (*evict_inode) (struct inode *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 void (*put_super) (struct super_block *);
98 void (*write_super) (struct super_block *);
99 int (*sync_fs)(struct super_block *sb, int wait);
Takashi Satoc4be0c12009-01-09 16:40:58 -0800100 int (*freeze_fs) (struct super_block *);
101 int (*unfreeze_fs) (struct super_block *);
David Howells726c3342006-06-23 02:02:58 -0700102 int (*statfs) (struct dentry *, struct kstatfs *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 int (*remount_fs) (struct super_block *, int *, char *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 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
109locking rules:
Al Viro336fb3b2010-06-08 00:37:12 -0400110 All may block [not true, see below]
Christoph Hellwig7e325d32009-06-19 20:22:37 +0200111 None have BKL
112 s_umount
113alloc_inode:
114destroy_inode:
115dirty_inode: (must not sleep)
116write_inode:
117drop_inode: !!!inode_lock!!!
Al Viro336fb3b2010-06-08 00:37:12 -0400118evict_inode:
Christoph Hellwig7e325d32009-06-19 20:22:37 +0200119put_super: write
120write_super: read
121sync_fs: read
122freeze_fs: read
123unfreeze_fs: read
Al Viro336fb3b2010-06-08 00:37:12 -0400124statfs: maybe(read) (see below)
125remount_fs: write
Christoph Hellwig7e325d32009-06-19 20:22:37 +0200126umount_begin: no
127show_options: no (namespace_sem)
128quota_read: no (see below)
129quota_write: no (see below)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
Al Viro336fb3b2010-06-08 00:37:12 -0400131->statfs() has s_umount (shared) when called by ustat(2) (native or
132compat), but that's an accident of bad API; s_umount is used to pin
133the superblock down when we only have dev_t given us by userland to
134identify the superblock. Everything else (statfs(), fstatfs(), etc.)
135doesn't hold it when calling ->statfs() - superblock is pinned down
136by resolving the pathname passed to syscall.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137->quota_read() and ->quota_write() functions are both guaranteed to
138be the only ones operating on the quota file by the quota code (via
139dqio_sem) (unless an admin really wants to screw up something and
140writes to quota files with quotas on). For other details about locking
141see also dquot_operations section.
142
143--------------------------- file_system_type ---------------------------
144prototypes:
Jonathan Corbet5d8b2eb2006-07-10 04:44:07 -0700145 int (*get_sb) (struct file_system_type *, int,
146 const char *, void *, struct vfsmount *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 void (*kill_sb) (struct super_block *);
148locking rules:
149 may block BKL
Christoph Hellwigadaae722008-09-09 20:02:01 +0200150get_sb yes no
151kill_sb yes no
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
David Howells454e2392006-06-23 02:02:57 -0700153->get_sb() returns error or 0 with locked superblock attached to the vfsmount
154(exclusive on ->s_umount).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155->kill_sb() takes a write-locked superblock, does all shutdown work on it,
156unlocks and drops the reference.
157
158--------------------------- address_space_operations --------------------------
159prototypes:
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);
Nick Piggin4e02ed42008-10-29 14:00:55 -0700167 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 sector_t (*bmap)(struct address_space *, sector_t);
174 int (*invalidatepage) (struct page *, unsigned long);
175 int (*releasepage) (struct page *, int);
176 int (*direct_IO)(int, struct kiocb *, const struct iovec *iov,
177 loff_t offset, unsigned long nr_segs);
Trond Myklebuste3db7692007-01-10 23:15:39 -0800178 int (*launder_page) (struct page *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
180locking rules:
181 All except set_page_dirty may block
182
Thadeu Lima de Souza Cascardoca0dbd82010-05-07 16:52:26 -0300183 BKL PageLocked(page) i_mutex
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184writepage: no yes, unlocks (see below)
185readpage: no yes, unlocks
186sync_page: no maybe
187writepages: no
188set_page_dirty no no
189readpages: no
Nick Pigginafddba42007-10-16 01:25:01 -0700190write_begin: no locks the page yes
191write_end: no yes, unlocks yes
192perform_write: no n/a yes
Al Virofe36adf2009-06-16 13:35:01 -0400193bmap: no
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194invalidatepage: no yes
195releasepage: no yes
196direct_IO: no
Trond Myklebuste3db7692007-01-10 23:15:39 -0800197launder_page: no yes
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
Nick Piggin4e02ed42008-10-29 14:00:55 -0700199 ->write_begin(), ->write_end(), ->sync_page() and ->readpage()
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200may be called from the request handler (/dev/loop).
201
202 ->readpage() unlocks the page, either synchronously or via I/O
203completion.
204
205 ->readpages() populates the pagecache with the passed pages and starts
206I/O against them. They come unlocked upon I/O completion.
207
208 ->writepage() is used for two purposes: for "memory cleansing" and for
209"sync". These are quite different operations and the behaviour may differ
210depending upon the mode.
211
212If writepage is called for sync (wbc->sync_mode != WBC_SYNC_NONE) then
213it *must* start I/O against the page, even if that would involve
214blocking on in-progress I/O.
215
216If writepage is called for memory cleansing (sync_mode ==
217WBC_SYNC_NONE) then its role is to get as much writeout underway as
218possible. So writepage should try to avoid blocking against
219currently-in-progress I/O.
220
221If the filesystem is not called for "sync" and it determines that it
222would need to block against in-progress I/O to be able to start new I/O
223against the page the filesystem should redirty the page with
224redirty_page_for_writepage(), then unlock the page and return zero.
225This may also be done to avoid internal deadlocks, but rarely.
226
Robert P. J. Day3a4fa0a2007-10-19 23:10:43 +0200227If the filesystem is called for sync then it must wait on any
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228in-progress I/O and then start new I/O.
229
Nikita Danilov20546062005-05-01 08:58:37 -0700230The filesystem should unlock the page synchronously, before returning to the
231caller, unless ->writepage() returns special WRITEPAGE_ACTIVATE
232value. WRITEPAGE_ACTIVATE means that page cannot really be written out
233currently, and VM should stop calling ->writepage() on this page for some
234time. VM does this by moving page to the head of the active list, hence the
235name.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236
237Unless the filesystem is going to redirty_page_for_writepage(), unlock the page
238and return zero, writepage *must* run set_page_writeback() against the page,
239followed by unlocking it. Once set_page_writeback() has been run against the
240page, write I/O can be submitted and the write I/O completion handler must run
241end_page_writeback() once the I/O is complete. If no I/O is submitted, the
242filesystem must run end_page_writeback() against the page before returning from
243writepage.
244
245That is: after 2.5.12, pages which are under writeout are *not* locked. Note,
246if the filesystem needs the page to be locked during writeout, that is ok, too,
247the page is allowed to be unlocked at any point in time between the calls to
248set_page_writeback() and end_page_writeback().
249
250Note, failure to run either redirty_page_for_writepage() or the combination of
251set_page_writeback()/end_page_writeback() on a page submitted to writepage
252will leave the page itself marked clean but it will be tagged as dirty in the
253radix tree. This incoherency can lead to all sorts of hard-to-debug problems
254in the filesystem like having dirty inodes at umount and losing written data.
255
256 ->sync_page() locking rules are not well-defined - usually it is called
257with lock on page, but that is not guaranteed. Considering the currently
258existing instances of this method ->sync_page() itself doesn't look
259well-defined...
260
261 ->writepages() is used for periodic writeback and for syscall-initiated
262sync operations. The address_space should start I/O against at least
263*nr_to_write pages. *nr_to_write must be decremented for each page which is
264written. The address_space implementation may write more (or less) pages
265than *nr_to_write asks for, but it should try to be reasonably close. If
266nr_to_write is NULL, all dirty pages must be written.
267
268writepages should _only_ write pages which are present on
269mapping->io_pages.
270
271 ->set_page_dirty() is called from various places in the kernel
272when the target page is marked as needing writeback. It may be called
273under spinlock (it cannot block) and is sometimes called with the page
274not locked.
275
276 ->bmap() is currently used by legacy ioctl() (FIBMAP) provided by some
277filesystems and by the swapper. The latter will eventually go away. All
278instances do not actually need the BKL. Please, keep it that way and don't
279breed new callers.
280
281 ->invalidatepage() is called when the filesystem must attempt to drop
282some or all of the buffers from the page when it is being truncated. It
283returns zero on success. If ->invalidatepage is zero, the kernel uses
284block_invalidatepage() instead.
285
286 ->releasepage() is called when the kernel is about to try to drop the
287buffers from the page in preparation for freeing it. It returns zero to
288indicate that the buffers are (or may be) freeable. If ->releasepage is zero,
289the kernel assumes that the fs has no private interest in the buffers.
290
Trond Myklebuste3db7692007-01-10 23:15:39 -0800291 ->launder_page() may be called prior to releasing a page if
292it is still found to be dirty. It returns zero if the page was successfully
293cleaned, or an error value if not. Note that in order to prevent the page
294getting mapped back in and redirtied, it needs to be kept locked
295across the entire operation.
296
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 Note: currently almost all instances of address_space methods are
298using BKL for internal serialization and that's one of the worst sources
299of contention. Normally they are calling library functions (in fs/buffer.c)
300and pass foo_get_block() as a callback (on local block-based filesystems,
301indeed). BKL is not needed for library stuff and is usually taken by
302foo_get_block(). It's an overkill, since block bitmaps can be protected by
303internal fs locking and real critical areas are much smaller than the areas
304filesystems protect now.
305
306----------------------- file_lock_operations ------------------------------
307prototypes:
308 void (*fl_insert)(struct file_lock *); /* lock insertion callback */
309 void (*fl_remove)(struct file_lock *); /* lock removal callback */
310 void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
311 void (*fl_release_private)(struct file_lock *);
312
313
314locking rules:
315 BKL may block
316fl_insert: yes no
317fl_remove: yes no
318fl_copy_lock: yes no
319fl_release_private: yes yes
320
321----------------------- lock_manager_operations ---------------------------
322prototypes:
323 int (*fl_compare_owner)(struct file_lock *, struct file_lock *);
324 void (*fl_notify)(struct file_lock *); /* unblock callback */
325 void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
326 void (*fl_release_private)(struct file_lock *);
327 void (*fl_break)(struct file_lock *); /* break_lease callback */
328
329locking rules:
330 BKL may block
331fl_compare_owner: yes no
332fl_notify: yes no
333fl_copy_lock: yes no
334fl_release_private: yes yes
335fl_break: yes no
336
337 Currently only NFSD and NLM provide instances of this class. None of the
338them block. If you have out-of-tree instances - please, show up. Locking
339in that area will change.
340--------------------------- buffer_head -----------------------------------
341prototypes:
342 void (*b_end_io)(struct buffer_head *bh, int uptodate);
343
344locking rules:
345 called from interrupts. In other words, extreme care is needed here.
346bh is locked, but that's all warranties we have here. Currently only RAID1,
347highmem, fs/buffer.c, and fs/ntfs/aops.c are providing these. Block devices
348call this method upon the IO completion.
349
350--------------------------- block_device_operations -----------------------
351prototypes:
352 int (*open) (struct inode *, struct file *);
353 int (*release) (struct inode *, struct file *);
354 int (*ioctl) (struct inode *, struct file *, unsigned, unsigned long);
355 int (*media_changed) (struct gendisk *);
356 int (*revalidate_disk) (struct gendisk *);
357
358locking rules:
359 BKL bd_sem
360open: yes yes
361release: yes yes
362ioctl: yes no
363media_changed: no no
364revalidate_disk: no no
365
366The last two are called only from check_disk_change().
367
368--------------------------- file_operations -------------------------------
369prototypes:
370 loff_t (*llseek) (struct file *, loff_t, int);
371 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
Badari Pulavarty027445c2006-09-30 23:28:46 -0700373 ssize_t (*aio_read) (struct kiocb *, const struct iovec *, unsigned long, loff_t);
374 ssize_t (*aio_write) (struct kiocb *, const struct iovec *, unsigned long, loff_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 int (*readdir) (struct file *, void *, filldir_t);
376 unsigned int (*poll) (struct file *, struct poll_table_struct *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);
378 long (*compat_ioctl) (struct file *, unsigned int, unsigned long);
379 int (*mmap) (struct file *, struct vm_area_struct *);
380 int (*open) (struct inode *, struct file *);
381 int (*flush) (struct file *);
382 int (*release) (struct inode *, struct file *);
Christoph Hellwig7ea80852010-05-26 17:53:25 +0200383 int (*fsync) (struct file *, int datasync);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 int (*aio_fsync) (struct kiocb *, int datasync);
385 int (*fasync) (int, struct file *, int);
386 int (*lock) (struct file *, int, struct file_lock *);
387 ssize_t (*readv) (struct file *, const struct iovec *, unsigned long,
388 loff_t *);
389 ssize_t (*writev) (struct file *, const struct iovec *, unsigned long,
390 loff_t *);
391 ssize_t (*sendfile) (struct file *, loff_t *, size_t, read_actor_t,
392 void __user *);
393 ssize_t (*sendpage) (struct file *, struct page *, int, size_t,
394 loff_t *, int);
395 unsigned long (*get_unmapped_area)(struct file *, unsigned long,
396 unsigned long, unsigned long, unsigned long);
397 int (*check_flags)(int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398};
399
400locking rules:
Tejun Heo5f820f62009-01-06 14:40:59 -0800401 All may block.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 BKL
403llseek: no (see below)
404read: no
405aio_read: no
406write: no
407aio_write: no
408readdir: no
409poll: no
Arnd Bergmannb19dd422010-07-04 00:15:10 +0200410unlocked_ioctl: no
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411compat_ioctl: no
412mmap: no
Christoph Hellwigadaae722008-09-09 20:02:01 +0200413open: no
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414flush: no
415release: no
416fsync: no (see below)
417aio_fsync: no
Christoph Hellwigadaae722008-09-09 20:02:01 +0200418fasync: no
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419lock: yes
420readv: no
421writev: no
422sendfile: no
423sendpage: no
424get_unmapped_area: no
425check_flags: no
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
427->llseek() locking has moved from llseek to the individual llseek
428implementations. If your fs is not using generic_file_llseek, you
429need to acquire and release the appropriate locks in your ->llseek().
430For many filesystems, it is probably safe to acquire the inode
Jan Blunck866707f2010-05-26 14:44:54 -0700431mutex or just to use i_size_read() instead.
432Note: this does not protect the file->f_pos against concurrent modifications
433since this is something the userspace has to take care about.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435Note: ext2_release() was *the* source of contention on fs-intensive
436loads and dropping BKL on ->release() helps to get rid of that (we still
437grab BKL for cases when we close a file that had been opened r/w, but that
438can and should be done using the internal locking with smaller critical areas).
439Current worst offender is ext2_get_block()...
440
Jonathan Corbet76398422009-02-01 14:26:59 -0700441->fasync() is called without BKL protection, and is responsible for
442maintaining the FASYNC bit in filp->f_flags. Most instances call
443fasync_helper(), which does that maintenance, so it's not normally
444something one needs to worry about. Return values > 0 will be mapped to
445zero in the VFS layer.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
447->readdir() and ->ioctl() on directories must be changed. Ideally we would
448move ->readdir() to inode_operations and use a separate method for directory
449->ioctl() or kill the latter completely. One of the problems is that for
450anything that resembles union-mount we won't have a struct file for all
451components. And there are other reasons why the current interface is a mess...
452
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453->read on directories probably must go away - we should just enforce -EISDIR
454in sys_read() and friends.
455
Artem Bityutskiya7bc02f2007-05-09 07:53:16 +0200456->fsync() has i_mutex on inode.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457
458--------------------------- dquot_operations -------------------------------
459prototypes:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 int (*write_dquot) (struct dquot *);
461 int (*acquire_dquot) (struct dquot *);
462 int (*release_dquot) (struct dquot *);
463 int (*mark_dirty) (struct dquot *);
464 int (*write_info) (struct super_block *, int);
465
466These operations are intended to be more or less wrapping functions that ensure
467a proper locking wrt the filesystem and call the generic quota operations.
468
469What filesystem should expect from the generic quota functions:
470
471 FS recursion Held locks when called
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472write_dquot: yes dqonoff_sem or dqptr_sem
473acquire_dquot: yes dqonoff_sem or dqptr_sem
474release_dquot: yes dqonoff_sem or dqptr_sem
475mark_dirty: no -
476write_info: yes dqonoff_sem
477
478FS recursion means calling ->quota_read() and ->quota_write() from superblock
479operations.
480
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481More details about quota locking can be found in fs/dquot.c.
482
483--------------------------- vm_operations_struct -----------------------------
484prototypes:
485 void (*open)(struct vm_area_struct*);
486 void (*close)(struct vm_area_struct*);
Nick Piggind0217ac2007-07-19 01:47:03 -0700487 int (*fault)(struct vm_area_struct*, struct vm_fault *);
Nick Pigginc2ec1752009-03-31 15:23:21 -0700488 int (*page_mkwrite)(struct vm_area_struct *, struct vm_fault *);
Rik van Riel28b2ee22008-07-23 21:27:05 -0700489 int (*access)(struct vm_area_struct *, unsigned long, void*, int, int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
491locking rules:
Mark Fashehed2f2f92007-07-19 01:47:01 -0700492 BKL mmap_sem PageLocked(page)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493open: no yes
494close: no yes
Nick Pigginb827e492009-04-30 15:08:16 -0700495fault: no yes can return with page locked
496page_mkwrite: no yes can return with page locked
Rik van Riel28b2ee22008-07-23 21:27:05 -0700497access: no yes
Mark Fashehed2f2f92007-07-19 01:47:01 -0700498
Nick Pigginb827e492009-04-30 15:08:16 -0700499 ->fault() is called when a previously not present pte is about
500to be faulted in. The filesystem must find and return the page associated
501with the passed in "pgoff" in the vm_fault structure. If it is possible that
502the page may be truncated and/or invalidated, then the filesystem must lock
503the page, then ensure it is not already truncated (the page lock will block
504subsequent truncate), and then return with VM_FAULT_LOCKED, and the page
505locked. The VM will unlock the page.
506
507 ->page_mkwrite() is called when a previously read-only pte is
508about to become writeable. The filesystem again must ensure that there are
509no truncate/invalidate races, and then return with the page locked. If
510the page has been truncated, the filesystem should not look up a new page
511like the ->fault() handler, but simply return with VM_FAULT_NOPAGE, which
512will cause the VM to retry the fault.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513
Rik van Riel28b2ee22008-07-23 21:27:05 -0700514 ->access() is called when get_user_pages() fails in
515acces_process_vm(), typically used to debug a process through
516/proc/pid/mem or ptrace. This function is needed only for
517VM_IO | VM_PFNMAP VMAs.
518
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519================================================================================
520 Dubious stuff
521
522(if you break something or notice that it is broken and do not fix it yourself
523- at least put it here)
524
525ipc/shm.c::shm_delete() - may need BKL.
526->read() and ->write() in many drivers are (probably) missing BKL.