Locking 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  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. --------------------------- dentry_operations --------------------------
  10. prototypes:
  11. int (*d_revalidate)(struct dentry *, unsigned int);
  12. int (*d_weak_revalidate)(struct dentry *, unsigned int);
  13. int (*d_hash)(const struct dentry *, struct qstr *);
  14. int (*d_compare)(const struct dentry *,
  15. unsigned int, const char *, const struct qstr *);
  16. int (*d_delete)(struct dentry *);
  17. int (*d_init)(struct dentry *);
  18. void (*d_release)(struct dentry *);
  19. void (*d_iput)(struct dentry *, struct inode *);
  20. char *(*d_dname)((struct dentry *dentry, char *buffer, int buflen);
  21. struct vfsmount *(*d_automount)(struct path *path);
  22. int (*d_manage)(struct dentry *, bool);
  23. struct dentry *(*d_real)(struct dentry *, const struct inode *,
  24. unsigned int);
  25. locking rules:
  26. rename_lock ->d_lock may block rcu-walk
  27. d_revalidate: no no yes (ref-walk) maybe
  28. d_weak_revalidate:no no yes no
  29. d_hash no no no maybe
  30. d_compare: yes no no maybe
  31. d_delete: no yes no no
  32. d_init: no no yes no
  33. d_release: no no yes no
  34. d_prune: no yes no no
  35. d_iput: no no yes no
  36. d_dname: no no no no
  37. d_automount: no no yes no
  38. d_manage: no no yes (ref-walk) maybe
  39. d_real no no yes no
  40. --------------------------- inode_operations ---------------------------
  41. prototypes:
  42. int (*create) (struct inode *,struct dentry *,umode_t, bool);
  43. struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
  44. int (*link) (struct dentry *,struct inode *,struct dentry *);
  45. int (*unlink) (struct inode *,struct dentry *);
  46. int (*symlink) (struct inode *,struct dentry *,const char *);
  47. int (*mkdir) (struct inode *,struct dentry *,umode_t);
  48. int (*rmdir) (struct inode *,struct dentry *);
  49. int (*mknod) (struct inode *,struct dentry *,umode_t,dev_t);
  50. int (*rename) (struct inode *, struct dentry *,
  51. struct inode *, struct dentry *, unsigned int);
  52. int (*readlink) (struct dentry *, char __user *,int);
  53. const char *(*get_link) (struct dentry *, struct inode *, void **);
  54. void (*truncate) (struct inode *);
  55. int (*permission) (struct inode *, int, unsigned int);
  56. int (*get_acl)(struct inode *, int);
  57. int (*setattr) (struct dentry *, struct iattr *);
  58. int (*getattr) (struct vfsmount *, struct dentry *, struct kstat *);
  59. ssize_t (*listxattr) (struct dentry *, char *, size_t);
  60. int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start, u64 len);
  61. void (*update_time)(struct inode *, struct timespec *, int);
  62. int (*atomic_open)(struct inode *, struct dentry *,
  63. struct file *, unsigned open_flag,
  64. umode_t create_mode, int *opened);
  65. int (*tmpfile) (struct inode *, struct dentry *, umode_t);
  66. locking rules:
  67. all may block
  68. i_mutex(inode)
  69. lookup: yes
  70. create: yes
  71. link: yes (both)
  72. mknod: yes
  73. symlink: yes
  74. mkdir: yes
  75. unlink: yes (both)
  76. rmdir: yes (both) (see below)
  77. rename: yes (all) (see below)
  78. readlink: no
  79. get_link: no
  80. setattr: yes
  81. permission: no (may not block if called in rcu-walk mode)
  82. get_acl: no
  83. getattr: no
  84. listxattr: no
  85. fiemap: no
  86. update_time: no
  87. atomic_open: yes
  88. tmpfile: no
  89. Additionally, ->rmdir(), ->unlink() and ->rename() have ->i_mutex on
  90. victim.
  91. cross-directory ->rename() has (per-superblock) ->s_vfs_rename_sem.
  92. See Documentation/filesystems/directory-locking for more detailed discussion
  93. of the locking scheme for directory operations.
  94. ----------------------- xattr_handler operations -----------------------
  95. prototypes:
  96. bool (*list)(struct dentry *dentry);
  97. int (*get)(const struct xattr_handler *handler, struct dentry *dentry,
  98. struct inode *inode, const char *name, void *buffer,
  99. size_t size);
  100. int (*set)(const struct xattr_handler *handler, struct dentry *dentry,
  101. struct inode *inode, const char *name, const void *buffer,
  102. size_t size, int flags);
  103. locking rules:
  104. all may block
  105. i_mutex(inode)
  106. list: no
  107. get: no
  108. set: yes
  109. --------------------------- super_operations ---------------------------
  110. prototypes:
  111. struct inode *(*alloc_inode)(struct super_block *sb);
  112. void (*destroy_inode)(struct inode *);
  113. void (*dirty_inode) (struct inode *, int flags);
  114. int (*write_inode) (struct inode *, struct writeback_control *wbc);
  115. int (*drop_inode) (struct inode *);
  116. void (*evict_inode) (struct inode *);
  117. void (*put_super) (struct super_block *);
  118. int (*sync_fs)(struct super_block *sb, int wait);
  119. int (*freeze_fs) (struct super_block *);
  120. int (*unfreeze_fs) (struct super_block *);
  121. int (*statfs) (struct dentry *, struct kstatfs *);
  122. int (*remount_fs) (struct super_block *, int *, char *);
  123. void (*umount_begin) (struct super_block *);
  124. int (*show_options)(struct seq_file *, struct dentry *);
  125. ssize_t (*quota_read)(struct super_block *, int, char *, size_t, loff_t);
  126. ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t);
  127. int (*bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
  128. locking rules:
  129. All may block [not true, see below]
  130. s_umount
  131. alloc_inode:
  132. destroy_inode:
  133. dirty_inode:
  134. write_inode:
  135. drop_inode: !!!inode->i_lock!!!
  136. evict_inode:
  137. put_super: write
  138. sync_fs: read
  139. freeze_fs: write
  140. unfreeze_fs: write
  141. statfs: maybe(read) (see below)
  142. remount_fs: write
  143. umount_begin: no
  144. show_options: no (namespace_sem)
  145. quota_read: no (see below)
  146. quota_write: no (see below)
  147. bdev_try_to_free_page: no (see below)
  148. ->statfs() has s_umount (shared) when called by ustat(2) (native or
  149. compat), but that's an accident of bad API; s_umount is used to pin
  150. the superblock down when we only have dev_t given us by userland to
  151. identify the superblock. Everything else (statfs(), fstatfs(), etc.)
  152. doesn't hold it when calling ->statfs() - superblock is pinned down
  153. by resolving the pathname passed to syscall.
  154. ->quota_read() and ->quota_write() functions are both guaranteed to
  155. be the only ones operating on the quota file by the quota code (via
  156. dqio_sem) (unless an admin really wants to screw up something and
  157. writes to quota files with quotas on). For other details about locking
  158. see also dquot_operations section.
  159. ->bdev_try_to_free_page is called from the ->releasepage handler of
  160. the block device inode. See there for more details.
  161. --------------------------- file_system_type ---------------------------
  162. prototypes:
  163. struct dentry *(*mount) (struct file_system_type *, int,
  164. const char *, void *);
  165. void (*kill_sb) (struct super_block *);
  166. locking rules:
  167. may block
  168. mount yes
  169. kill_sb yes
  170. ->mount() returns ERR_PTR or the root dentry; its superblock should be locked
  171. on return.
  172. ->kill_sb() takes a write-locked superblock, does all shutdown work on it,
  173. unlocks and drops the reference.
  174. --------------------------- address_space_operations --------------------------
  175. prototypes:
  176. int (*writepage)(struct page *page, struct writeback_control *wbc);
  177. int (*readpage)(struct file *, struct page *);
  178. int (*writepages)(struct address_space *, struct writeback_control *);
  179. int (*set_page_dirty)(struct page *page);
  180. int (*readpages)(struct file *filp, struct address_space *mapping,
  181. struct list_head *pages, unsigned nr_pages);
  182. int (*write_begin)(struct file *, struct address_space *mapping,
  183. loff_t pos, unsigned len, unsigned flags,
  184. struct page **pagep, void **fsdata);
  185. int (*write_end)(struct file *, struct address_space *mapping,
  186. loff_t pos, unsigned len, unsigned copied,
  187. struct page *page, void *fsdata);
  188. sector_t (*bmap)(struct address_space *, sector_t);
  189. void (*invalidatepage) (struct page *, unsigned int, unsigned int);
  190. int (*releasepage) (struct page *, int);
  191. void (*freepage)(struct page *);
  192. int (*direct_IO)(struct kiocb *, struct iov_iter *iter);
  193. bool (*isolate_page) (struct page *, isolate_mode_t);
  194. int (*migratepage)(struct address_space *, struct page *, struct page *);
  195. void (*putback_page) (struct page *);
  196. int (*launder_page)(struct page *);
  197. int (*is_partially_uptodate)(struct page *, unsigned long, unsigned long);
  198. int (*error_remove_page)(struct address_space *, struct page *);
  199. int (*swap_activate)(struct file *);
  200. int (*swap_deactivate)(struct file *);
  201. locking rules:
  202. All except set_page_dirty and freepage may block
  203. PageLocked(page) i_mutex
  204. writepage: yes, unlocks (see below)
  205. readpage: yes, unlocks
  206. writepages:
  207. set_page_dirty no
  208. readpages:
  209. write_begin: locks the page yes
  210. write_end: yes, unlocks yes
  211. bmap:
  212. invalidatepage: yes
  213. releasepage: yes
  214. freepage: yes
  215. direct_IO:
  216. isolate_page: yes
  217. migratepage: yes (both)
  218. putback_page: yes
  219. launder_page: yes
  220. is_partially_uptodate: yes
  221. error_remove_page: yes
  222. swap_activate: no
  223. swap_deactivate: no
  224. ->write_begin(), ->write_end() and ->readpage() may be called from
  225. the request handler (/dev/loop).
  226. ->readpage() unlocks the page, either synchronously or via I/O
  227. completion.
  228. ->readpages() populates the pagecache with the passed pages and starts
  229. I/O against them. They come unlocked upon I/O completion.
  230. ->writepage() is used for two purposes: for "memory cleansing" and for
  231. "sync". These are quite different operations and the behaviour may differ
  232. depending upon the mode.
  233. If writepage is called for sync (wbc->sync_mode != WBC_SYNC_NONE) then
  234. it *must* start I/O against the page, even if that would involve
  235. blocking on in-progress I/O.
  236. If writepage is called for memory cleansing (sync_mode ==
  237. WBC_SYNC_NONE) then its role is to get as much writeout underway as
  238. possible. So writepage should try to avoid blocking against
  239. currently-in-progress I/O.
  240. If the filesystem is not called for "sync" and it determines that it
  241. would need to block against in-progress I/O to be able to start new I/O
  242. against the page the filesystem should redirty the page with
  243. redirty_page_for_writepage(), then unlock the page and return zero.
  244. This may also be done to avoid internal deadlocks, but rarely.
  245. If the filesystem is called for sync then it must wait on any
  246. in-progress I/O and then start new I/O.
  247. The filesystem should unlock the page synchronously, before returning to the
  248. caller, unless ->writepage() returns special WRITEPAGE_ACTIVATE
  249. value. WRITEPAGE_ACTIVATE means that page cannot really be written out
  250. currently, and VM should stop calling ->writepage() on this page for some
  251. time. VM does this by moving page to the head of the active list, hence the
  252. name.
  253. Unless the filesystem is going to redirty_page_for_writepage(), unlock the page
  254. and return zero, writepage *must* run set_page_writeback() against the page,
  255. followed by unlocking it. Once set_page_writeback() has been run against the
  256. page, write I/O can be submitted and the write I/O completion handler must run
  257. end_page_writeback() once the I/O is complete. If no I/O is submitted, the
  258. filesystem must run end_page_writeback() against the page before returning from
  259. writepage.
  260. That is: after 2.5.12, pages which are under writeout are *not* locked. Note,
  261. if the filesystem needs the page to be locked during writeout, that is ok, too,
  262. the page is allowed to be unlocked at any point in time between the calls to
  263. set_page_writeback() and end_page_writeback().
  264. Note, failure to run either redirty_page_for_writepage() or the combination of
  265. set_page_writeback()/end_page_writeback() on a page submitted to writepage
  266. will leave the page itself marked clean but it will be tagged as dirty in the
  267. radix tree. This incoherency can lead to all sorts of hard-to-debug problems
  268. in the filesystem like having dirty inodes at umount and losing written data.
  269. ->writepages() is used for periodic writeback and for syscall-initiated
  270. sync operations. The address_space should start I/O against at least
  271. *nr_to_write pages. *nr_to_write must be decremented for each page which is
  272. written. The address_space implementation may write more (or less) pages
  273. than *nr_to_write asks for, but it should try to be reasonably close. If
  274. nr_to_write is NULL, all dirty pages must be written.
  275. writepages should _only_ write pages which are present on
  276. mapping->io_pages.
  277. ->set_page_dirty() is called from various places in the kernel
  278. when the target page is marked as needing writeback. It may be called
  279. under spinlock (it cannot block) and is sometimes called with the page
  280. not locked.
  281. ->bmap() is currently used by legacy ioctl() (FIBMAP) provided by some
  282. filesystems and by the swapper. The latter will eventually go away. Please,
  283. keep it that way and don't breed new callers.
  284. ->invalidatepage() is called when the filesystem must attempt to drop
  285. some or all of the buffers from the page when it is being truncated. It
  286. returns zero on success. If ->invalidatepage is zero, the kernel uses
  287. block_invalidatepage() instead.
  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. ->freepage() is called when the kernel is done dropping the page
  293. from the page cache.
  294. ->launder_page() may be called prior to releasing a page if
  295. it is still found to be dirty. It returns zero if the page was successfully
  296. cleaned, or an error value if not. Note that in order to prevent the page
  297. getting mapped back in and redirtied, it needs to be kept locked
  298. across the entire operation.
  299. ->swap_activate will be called with a non-zero argument on
  300. files backing (non block device backed) swapfiles. A return value
  301. of zero indicates success, in which case this file can be used for
  302. backing swapspace. The swapspace operations will be proxied to the
  303. address space operations.
  304. ->swap_deactivate() will be called in the sys_swapoff()
  305. path after ->swap_activate() returned success.
  306. ----------------------- file_lock_operations ------------------------------
  307. prototypes:
  308. void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
  309. void (*fl_release_private)(struct file_lock *);
  310. locking rules:
  311. inode->i_lock may block
  312. fl_copy_lock: yes no
  313. fl_release_private: maybe maybe[1]
  314. [1]: ->fl_release_private for flock or POSIX locks is currently allowed
  315. to block. Leases however can still be freed while the i_lock is held and
  316. so fl_release_private called on a lease should not block.
  317. ----------------------- lock_manager_operations ---------------------------
  318. prototypes:
  319. int (*lm_compare_owner)(struct file_lock *, struct file_lock *);
  320. unsigned long (*lm_owner_key)(struct file_lock *);
  321. void (*lm_notify)(struct file_lock *); /* unblock callback */
  322. int (*lm_grant)(struct file_lock *, struct file_lock *, int);
  323. void (*lm_break)(struct file_lock *); /* break_lease callback */
  324. int (*lm_change)(struct file_lock **, int);
  325. locking rules:
  326. inode->i_lock blocked_lock_lock may block
  327. lm_compare_owner: yes[1] maybe no
  328. lm_owner_key yes[1] yes no
  329. lm_notify: yes yes no
  330. lm_grant: no no no
  331. lm_break: yes no no
  332. lm_change yes no no
  333. [1]: ->lm_compare_owner and ->lm_owner_key are generally called with
  334. *an* inode->i_lock held. It may not be the i_lock of the inode
  335. associated with either file_lock argument! This is the case with deadlock
  336. detection, since the code has to chase down the owners of locks that may
  337. be entirely unrelated to the one on which the lock is being acquired.
  338. For deadlock detection however, the blocked_lock_lock is also held. The
  339. fact that these locks are held ensures that the file_locks do not
  340. disappear out from under you while doing the comparison or generating an
  341. owner key.
  342. --------------------------- buffer_head -----------------------------------
  343. prototypes:
  344. void (*b_end_io)(struct buffer_head *bh, int uptodate);
  345. locking rules:
  346. called from interrupts. In other words, extreme care is needed here.
  347. bh is locked, but that's all warranties we have here. Currently only RAID1,
  348. highmem, fs/buffer.c, and fs/ntfs/aops.c are providing these. Block devices
  349. call this method upon the IO completion.
  350. --------------------------- block_device_operations -----------------------
  351. prototypes:
  352. int (*open) (struct block_device *, fmode_t);
  353. int (*release) (struct gendisk *, fmode_t);
  354. int (*ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
  355. int (*compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
  356. int (*direct_access) (struct block_device *, sector_t, void **,
  357. unsigned long *);
  358. int (*media_changed) (struct gendisk *);
  359. void (*unlock_native_capacity) (struct gendisk *);
  360. int (*revalidate_disk) (struct gendisk *);
  361. int (*getgeo)(struct block_device *, struct hd_geometry *);
  362. void (*swap_slot_free_notify) (struct block_device *, unsigned long);
  363. locking rules:
  364. bd_mutex
  365. open: yes
  366. release: yes
  367. ioctl: no
  368. compat_ioctl: no
  369. direct_access: no
  370. media_changed: no
  371. unlock_native_capacity: no
  372. revalidate_disk: no
  373. getgeo: no
  374. swap_slot_free_notify: no (see below)
  375. media_changed, unlock_native_capacity and revalidate_disk are called only from
  376. check_disk_change().
  377. swap_slot_free_notify is called with swap_lock and sometimes the page lock
  378. held.
  379. --------------------------- file_operations -------------------------------
  380. prototypes:
  381. loff_t (*llseek) (struct file *, loff_t, int);
  382. ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
  383. ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
  384. ssize_t (*read_iter) (struct kiocb *, struct iov_iter *);
  385. ssize_t (*write_iter) (struct kiocb *, struct iov_iter *);
  386. int (*iterate) (struct file *, struct dir_context *);
  387. unsigned int (*poll) (struct file *, struct poll_table_struct *);
  388. long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);
  389. long (*compat_ioctl) (struct file *, unsigned int, unsigned long);
  390. int (*mmap) (struct file *, struct vm_area_struct *);
  391. int (*open) (struct inode *, struct file *);
  392. int (*flush) (struct file *);
  393. int (*release) (struct inode *, struct file *);
  394. int (*fsync) (struct file *, loff_t start, loff_t end, int datasync);
  395. int (*fasync) (int, struct file *, int);
  396. int (*lock) (struct file *, int, struct file_lock *);
  397. ssize_t (*readv) (struct file *, const struct iovec *, unsigned long,
  398. loff_t *);
  399. ssize_t (*writev) (struct file *, const struct iovec *, unsigned long,
  400. loff_t *);
  401. ssize_t (*sendfile) (struct file *, loff_t *, size_t, read_actor_t,
  402. void __user *);
  403. ssize_t (*sendpage) (struct file *, struct page *, int, size_t,
  404. loff_t *, int);
  405. unsigned long (*get_unmapped_area)(struct file *, unsigned long,
  406. unsigned long, unsigned long, unsigned long);
  407. int (*check_flags)(int);
  408. int (*flock) (struct file *, int, struct file_lock *);
  409. ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *,
  410. size_t, unsigned int);
  411. ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *,
  412. size_t, unsigned int);
  413. int (*setlease)(struct file *, long, struct file_lock **, void **);
  414. long (*fallocate)(struct file *, int, loff_t, loff_t);
  415. };
  416. locking rules:
  417. All may block.
  418. ->llseek() locking has moved from llseek to the individual llseek
  419. implementations. If your fs is not using generic_file_llseek, you
  420. need to acquire and release the appropriate locks in your ->llseek().
  421. For many filesystems, it is probably safe to acquire the inode
  422. mutex or just to use i_size_read() instead.
  423. Note: this does not protect the file->f_pos against concurrent modifications
  424. since this is something the userspace has to take care about.
  425. ->fasync() is responsible for maintaining the FASYNC bit in filp->f_flags.
  426. Most instances call fasync_helper(), which does that maintenance, so it's
  427. not normally something one needs to worry about. Return values > 0 will be
  428. mapped to zero in the VFS layer.
  429. ->readdir() and ->ioctl() on directories must be changed. Ideally we would
  430. move ->readdir() to inode_operations and use a separate method for directory
  431. ->ioctl() or kill the latter completely. One of the problems is that for
  432. anything that resembles union-mount we won't have a struct file for all
  433. components. And there are other reasons why the current interface is a mess...
  434. ->read on directories probably must go away - we should just enforce -EISDIR
  435. in sys_read() and friends.
  436. ->setlease operations should call generic_setlease() before or after setting
  437. the lease within the individual filesystem to record the result of the
  438. operation
  439. --------------------------- dquot_operations -------------------------------
  440. prototypes:
  441. int (*write_dquot) (struct dquot *);
  442. int (*acquire_dquot) (struct dquot *);
  443. int (*release_dquot) (struct dquot *);
  444. int (*mark_dirty) (struct dquot *);
  445. int (*write_info) (struct super_block *, int);
  446. These operations are intended to be more or less wrapping functions that ensure
  447. a proper locking wrt the filesystem and call the generic quota operations.
  448. What filesystem should expect from the generic quota functions:
  449. FS recursion Held locks when called
  450. write_dquot: yes dqonoff_sem or dqptr_sem
  451. acquire_dquot: yes dqonoff_sem or dqptr_sem
  452. release_dquot: yes dqonoff_sem or dqptr_sem
  453. mark_dirty: no -
  454. write_info: yes dqonoff_sem
  455. FS recursion means calling ->quota_read() and ->quota_write() from superblock
  456. operations.
  457. More details about quota locking can be found in fs/dquot.c.
  458. --------------------------- vm_operations_struct -----------------------------
  459. prototypes:
  460. void (*open)(struct vm_area_struct*);
  461. void (*close)(struct vm_area_struct*);
  462. int (*fault)(struct vm_area_struct*, struct vm_fault *);
  463. int (*page_mkwrite)(struct vm_area_struct *, struct vm_fault *);
  464. int (*pfn_mkwrite)(struct vm_area_struct *, struct vm_fault *);
  465. int (*access)(struct vm_area_struct *, unsigned long, void*, int, int);
  466. locking rules:
  467. mmap_sem PageLocked(page)
  468. open: yes
  469. close: yes
  470. fault: yes can return with page locked
  471. map_pages: yes
  472. page_mkwrite: yes can return with page locked
  473. pfn_mkwrite: yes
  474. access: yes
  475. ->fault() is called when a previously not present pte is about
  476. to be faulted in. The filesystem must find and return the page associated
  477. with the passed in "pgoff" in the vm_fault structure. If it is possible that
  478. the page may be truncated and/or invalidated, then the filesystem must lock
  479. the page, then ensure it is not already truncated (the page lock will block
  480. subsequent truncate), and then return with VM_FAULT_LOCKED, and the page
  481. locked. The VM will unlock the page.
  482. ->map_pages() is called when VM asks to map easy accessible pages.
  483. Filesystem should find and map pages associated with offsets from "start_pgoff"
  484. till "end_pgoff". ->map_pages() is called with page table locked and must
  485. not block. If it's not possible to reach a page without blocking,
  486. filesystem should skip it. Filesystem should use do_set_pte() to setup
  487. page table entry. Pointer to entry associated with the page is passed in
  488. "pte" field in fault_env structure. Pointers to entries for other offsets
  489. should be calculated relative to "pte".
  490. ->page_mkwrite() is called when a previously read-only pte is
  491. about to become writeable. The filesystem again must ensure that there are
  492. no truncate/invalidate races, and then return with the page locked. If
  493. the page has been truncated, the filesystem should not look up a new page
  494. like the ->fault() handler, but simply return with VM_FAULT_NOPAGE, which
  495. will cause the VM to retry the fault.
  496. ->pfn_mkwrite() is the same as page_mkwrite but when the pte is
  497. VM_PFNMAP or VM_MIXEDMAP with a page-less entry. Expected return is
  498. VM_FAULT_NOPAGE. Or one of the VM_FAULT_ERROR types. The default behavior
  499. after this call is to make the pte read-write, unless pfn_mkwrite returns
  500. an error.
  501. ->access() is called when get_user_pages() fails in
  502. access_process_vm(), typically used to debug a process through
  503. /proc/pid/mem or ptrace. This function is needed only for
  504. VM_IO | VM_PFNMAP VMAs.
  505. ================================================================================
  506. Dubious stuff
  507. (if you break something or notice that it is broken and do not fix it yourself
  508. - at least put it here)