locking.rst 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. =======
  2. Locking
  3. =======
  4. The text below describes the locking rules for VFS-related methods.
  5. It is (believed to be) up-to-date. *Please*, if you change anything in
  6. prototypes or locking protocols - update this file. And update the relevant
  7. instances in the tree, don't leave that to maintainers of filesystems/devices/
  8. etc. At the very least, put the list of dubious cases in the end of this file.
  9. Don't turn it into log - maintainers of out-of-the-tree code are supposed to
  10. be able to use diff(1).
  11. Thing currently missing here: socket operations. Alexey?
  12. dentry_operations
  13. =================
  14. prototypes::
  15. int (*d_revalidate)(struct inode *, const struct qstr *,
  16. struct dentry *, unsigned int);
  17. int (*d_weak_revalidate)(struct dentry *, unsigned int);
  18. int (*d_hash)(const struct dentry *, struct qstr *);
  19. int (*d_compare)(const struct dentry *,
  20. unsigned int, const char *, const struct qstr *);
  21. int (*d_delete)(struct dentry *);
  22. int (*d_init)(struct dentry *);
  23. void (*d_release)(struct dentry *);
  24. void (*d_iput)(struct dentry *, struct inode *);
  25. char *(*d_dname)((struct dentry *dentry, char *buffer, int buflen);
  26. struct vfsmount *(*d_automount)(struct path *path);
  27. int (*d_manage)(const struct path *, bool);
  28. struct dentry *(*d_real)(struct dentry *, enum d_real_type type);
  29. bool (*d_unalias_trylock)(const struct dentry *);
  30. void (*d_unalias_unlock)(const struct dentry *);
  31. locking rules:
  32. ================== =========== ======== ============== ========
  33. ops rename_lock ->d_lock may block rcu-walk
  34. ================== =========== ======== ============== ========
  35. d_revalidate: no no yes (ref-walk) maybe
  36. d_weak_revalidate: no no yes no
  37. d_hash no no no maybe
  38. d_compare: yes no no maybe
  39. d_delete: no yes no no
  40. d_init: no no yes no
  41. d_release: no no yes no
  42. d_prune: no yes no no
  43. d_iput: no no yes no
  44. d_dname: no no no no
  45. d_automount: no no yes no
  46. d_manage: no no yes (ref-walk) maybe
  47. d_real no no yes no
  48. d_unalias_trylock yes no no no
  49. d_unalias_unlock yes no no no
  50. ================== =========== ======== ============== ========
  51. inode_operations
  52. ================
  53. prototypes::
  54. int (*create) (struct mnt_idmap *, struct inode *,struct dentry *,umode_t, bool);
  55. struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
  56. int (*link) (struct dentry *,struct inode *,struct dentry *);
  57. int (*unlink) (struct inode *,struct dentry *);
  58. int (*symlink) (struct mnt_idmap *, struct inode *,struct dentry *,const char *);
  59. struct dentry *(*mkdir) (struct mnt_idmap *, struct inode *,struct dentry *,umode_t);
  60. int (*rmdir) (struct inode *,struct dentry *);
  61. int (*mknod) (struct mnt_idmap *, struct inode *,struct dentry *,umode_t,dev_t);
  62. int (*rename) (struct mnt_idmap *, struct inode *, struct dentry *,
  63. struct inode *, struct dentry *, unsigned int);
  64. int (*readlink) (struct dentry *, char __user *,int);
  65. const char *(*get_link) (struct dentry *, struct inode *, struct delayed_call *);
  66. void (*truncate) (struct inode *);
  67. int (*permission) (struct mnt_idmap *, struct inode *, int, unsigned int);
  68. struct posix_acl * (*get_inode_acl)(struct inode *, int, bool);
  69. int (*setattr) (struct mnt_idmap *, struct dentry *, struct iattr *);
  70. int (*getattr) (struct mnt_idmap *, const struct path *, struct kstat *, u32, unsigned int);
  71. ssize_t (*listxattr) (struct dentry *, char *, size_t);
  72. int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start, u64 len);
  73. void (*update_time)(struct inode *inode, enum fs_update_time type,
  74. int flags);
  75. void (*sync_lazytime)(struct inode *inode);
  76. int (*atomic_open)(struct inode *, struct dentry *,
  77. struct file *, unsigned open_flag,
  78. umode_t create_mode);
  79. int (*tmpfile) (struct mnt_idmap *, struct inode *,
  80. struct file *, umode_t);
  81. int (*fileattr_set)(struct mnt_idmap *idmap,
  82. struct dentry *dentry, struct file_kattr *fa);
  83. int (*fileattr_get)(struct dentry *dentry, struct file_kattr *fa);
  84. struct posix_acl * (*get_acl)(struct mnt_idmap *, struct dentry *, int);
  85. struct offset_ctx *(*get_offset_ctx)(struct inode *inode);
  86. locking rules:
  87. all may block
  88. ============== ==================================================
  89. ops i_rwsem(inode)
  90. ============== ==================================================
  91. lookup: shared
  92. create: exclusive
  93. link: exclusive (both)
  94. mknod: exclusive
  95. symlink: exclusive
  96. mkdir: exclusive
  97. unlink: exclusive (both)
  98. rmdir: exclusive (both)(see below)
  99. rename: exclusive (both parents, some children) (see below)
  100. readlink: no
  101. get_link: no
  102. setattr: exclusive
  103. permission: no (may not block if called in rcu-walk mode)
  104. get_inode_acl: no
  105. get_acl: no
  106. getattr: no
  107. listxattr: no
  108. fiemap: no
  109. update_time: no
  110. sync_lazytime: no
  111. atomic_open: shared (exclusive if O_CREAT is set in open flags)
  112. tmpfile: no
  113. fileattr_get: no or exclusive
  114. fileattr_set: exclusive
  115. get_offset_ctx no
  116. ============== ==================================================
  117. Additionally, ->rmdir(), ->unlink() and ->rename() have ->i_rwsem
  118. exclusive on victim.
  119. cross-directory ->rename() has (per-superblock) ->s_vfs_rename_sem.
  120. ->unlink() and ->rename() have ->i_rwsem exclusive on all non-directories
  121. involved.
  122. ->rename() has ->i_rwsem exclusive on any subdirectory that changes parent.
  123. See Documentation/filesystems/directory-locking.rst for more detailed discussion
  124. of the locking scheme for directory operations.
  125. xattr_handler operations
  126. ========================
  127. prototypes::
  128. bool (*list)(struct dentry *dentry);
  129. int (*get)(const struct xattr_handler *handler, struct dentry *dentry,
  130. struct inode *inode, const char *name, void *buffer,
  131. size_t size);
  132. int (*set)(const struct xattr_handler *handler,
  133. struct mnt_idmap *idmap,
  134. struct dentry *dentry, struct inode *inode, const char *name,
  135. const void *buffer, size_t size, int flags);
  136. locking rules:
  137. all may block
  138. ===== ==============
  139. ops i_rwsem(inode)
  140. ===== ==============
  141. list: no
  142. get: no
  143. set: exclusive
  144. ===== ==============
  145. super_operations
  146. ================
  147. prototypes::
  148. struct inode *(*alloc_inode)(struct super_block *sb);
  149. void (*free_inode)(struct inode *);
  150. void (*destroy_inode)(struct inode *);
  151. void (*dirty_inode) (struct inode *, int flags);
  152. int (*write_inode) (struct inode *, struct writeback_control *wbc);
  153. int (*drop_inode) (struct inode *);
  154. void (*evict_inode) (struct inode *);
  155. void (*put_super) (struct super_block *);
  156. int (*sync_fs)(struct super_block *sb, int wait);
  157. int (*freeze_fs) (struct super_block *);
  158. int (*unfreeze_fs) (struct super_block *);
  159. int (*statfs) (struct dentry *, struct kstatfs *);
  160. void (*umount_begin) (struct super_block *);
  161. int (*show_options)(struct seq_file *, struct dentry *);
  162. ssize_t (*quota_read)(struct super_block *, int, char *, size_t, loff_t);
  163. ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t);
  164. locking rules:
  165. All may block [not true, see below]
  166. ====================== ============ ========================
  167. ops s_umount note
  168. ====================== ============ ========================
  169. alloc_inode:
  170. free_inode: called from RCU callback
  171. destroy_inode:
  172. dirty_inode:
  173. write_inode:
  174. drop_inode: !!!inode->i_lock!!!
  175. evict_inode:
  176. put_super: write
  177. sync_fs: read
  178. freeze_fs: write
  179. unfreeze_fs: write
  180. statfs: maybe(read) (see below)
  181. umount_begin: no
  182. show_options: no (namespace_sem)
  183. quota_read: no (see below)
  184. quota_write: no (see below)
  185. ====================== ============ ========================
  186. ->statfs() has s_umount (shared) when called by ustat(2) (native or
  187. compat), but that's an accident of bad API; s_umount is used to pin
  188. the superblock down when we only have dev_t given us by userland to
  189. identify the superblock. Everything else (statfs(), fstatfs(), etc.)
  190. doesn't hold it when calling ->statfs() - superblock is pinned down
  191. by resolving the pathname passed to syscall.
  192. ->quota_read() and ->quota_write() functions are both guaranteed to
  193. be the only ones operating on the quota file by the quota code (via
  194. dqio_sem) (unless an admin really wants to screw up something and
  195. writes to quota files with quotas on). For other details about locking
  196. see also dquot_operations section.
  197. file_system_type
  198. ================
  199. prototypes::
  200. void (*kill_sb) (struct super_block *);
  201. locking rules:
  202. ======= =========
  203. ops may block
  204. ======= =========
  205. kill_sb yes
  206. ======= =========
  207. ->kill_sb() takes a write-locked superblock, does all shutdown work on it,
  208. unlocks and drops the reference.
  209. address_space_operations
  210. ========================
  211. prototypes::
  212. int (*read_folio)(struct file *, struct folio *);
  213. int (*writepages)(struct address_space *, struct writeback_control *);
  214. bool (*dirty_folio)(struct address_space *, struct folio *folio);
  215. void (*readahead)(struct readahead_control *);
  216. int (*write_begin)(const struct kiocb *, struct address_space *mapping,
  217. loff_t pos, unsigned len,
  218. struct folio **foliop, void **fsdata);
  219. int (*write_end)(const struct kiocb *, struct address_space *mapping,
  220. loff_t pos, unsigned len, unsigned copied,
  221. struct folio *folio, void *fsdata);
  222. sector_t (*bmap)(struct address_space *, sector_t);
  223. void (*invalidate_folio) (struct folio *, size_t start, size_t len);
  224. bool (*release_folio)(struct folio *, gfp_t);
  225. void (*free_folio)(struct folio *);
  226. int (*direct_IO)(struct kiocb *, struct iov_iter *iter);
  227. int (*migrate_folio)(struct address_space *, struct folio *dst,
  228. struct folio *src, enum migrate_mode);
  229. int (*launder_folio)(struct folio *);
  230. bool (*is_partially_uptodate)(struct folio *, size_t from, size_t count);
  231. int (*error_remove_folio)(struct address_space *, struct folio *);
  232. int (*swap_activate)(struct swap_info_struct *sis, struct file *f, sector_t *span)
  233. int (*swap_deactivate)(struct file *);
  234. int (*swap_rw)(struct kiocb *iocb, struct iov_iter *iter);
  235. locking rules:
  236. All except dirty_folio and free_folio may block
  237. ====================== ======================== ========= ===============
  238. ops folio locked i_rwsem invalidate_lock
  239. ====================== ======================== ========= ===============
  240. read_folio: yes, unlocks shared
  241. writepages:
  242. dirty_folio: maybe
  243. readahead: yes, unlocks shared
  244. write_begin: locks the folio exclusive
  245. write_end: yes, unlocks exclusive
  246. bmap:
  247. invalidate_folio: yes exclusive
  248. release_folio: yes
  249. free_folio: yes
  250. direct_IO:
  251. migrate_folio: yes (both)
  252. launder_folio: yes
  253. is_partially_uptodate: yes
  254. error_remove_folio: yes
  255. swap_activate: no
  256. swap_deactivate: no
  257. swap_rw: yes, unlocks
  258. ====================== ======================== ========= ===============
  259. ->write_begin(), ->write_end() and ->read_folio() may be called from
  260. the request handler (/dev/loop).
  261. ->read_folio() unlocks the folio, either synchronously or via I/O
  262. completion.
  263. ->readahead() unlocks the folios that I/O is attempted on like ->read_folio().
  264. ->writepages() is used for periodic writeback and for syscall-initiated
  265. sync operations. The address_space should start I/O against at least
  266. ``*nr_to_write`` pages. ``*nr_to_write`` must be decremented for each page
  267. which is written. The address_space implementation may write more (or less)
  268. pages than ``*nr_to_write`` asks for, but it should try to be reasonably close.
  269. If nr_to_write is NULL, all dirty pages must be written.
  270. writepages should _only_ write pages which are present in
  271. mapping->i_pages.
  272. ->dirty_folio() is called from various places in the kernel when
  273. the target folio is marked as needing writeback. The folio cannot be
  274. truncated because either the caller holds the folio lock, or the caller
  275. has found the folio while holding the page table lock which will block
  276. truncation.
  277. ->bmap() is currently used by legacy ioctl() (FIBMAP) provided by some
  278. filesystems and by the swapper. The latter will eventually go away. Please,
  279. keep it that way and don't breed new callers.
  280. ->invalidate_folio() is called when the filesystem must attempt to drop
  281. some or all of the buffers from the page when it is being truncated. It
  282. returns zero on success. The filesystem must exclusively acquire
  283. invalidate_lock before invalidating page cache in truncate / hole punch
  284. path (and thus calling into ->invalidate_folio) to block races between page
  285. cache invalidation and page cache filling functions (fault, read, ...).
  286. ->release_folio() is called when the MM wants to make a change to the
  287. folio that would invalidate the filesystem's private data. For example,
  288. it may be about to be removed from the address_space or split. The folio
  289. is locked and not under writeback. It may be dirty. The gfp parameter
  290. is not usually used for allocation, but rather to indicate what the
  291. filesystem may do to attempt to free the private data. The filesystem may
  292. return false to indicate that the folio's private data cannot be freed.
  293. If it returns true, it should have already removed the private data from
  294. the folio. If a filesystem does not provide a ->release_folio method,
  295. the pagecache will assume that private data is buffer_heads and call
  296. try_to_free_buffers().
  297. ->free_folio() is called when the kernel has dropped the folio
  298. from the page cache.
  299. ->launder_folio() may be called prior to releasing a folio if
  300. it is still found to be dirty. It returns zero if the folio was successfully
  301. cleaned, or an error value if not. Note that in order to prevent the folio
  302. getting mapped back in and redirtied, it needs to be kept locked
  303. across the entire operation.
  304. ->swap_activate() will be called to prepare the given file for swap. It
  305. should perform any validation and preparation necessary to ensure that
  306. writes can be performed with minimal memory allocation. It should call
  307. add_swap_extent(), or the helper iomap_swapfile_activate(), and return
  308. the number of extents added. If IO should be submitted through
  309. ->swap_rw(), it should set SWP_FS_OPS, otherwise IO will be submitted
  310. directly to the block device ``sis->bdev``.
  311. ->swap_deactivate() will be called in the sys_swapoff()
  312. path after ->swap_activate() returned success.
  313. ->swap_rw will be called for swap IO if SWP_FS_OPS was set by ->swap_activate().
  314. file_lock_operations
  315. ====================
  316. prototypes::
  317. void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
  318. void (*fl_release_private)(struct file_lock *);
  319. locking rules:
  320. =================== ============= =========
  321. ops inode->i_lock may block
  322. =================== ============= =========
  323. fl_copy_lock: yes no
  324. fl_release_private: maybe maybe[1]_
  325. =================== ============= =========
  326. .. [1]:
  327. ->fl_release_private for flock or POSIX locks is currently allowed
  328. to block. Leases however can still be freed while the i_lock is held and
  329. so fl_release_private called on a lease should not block.
  330. lock_manager_operations
  331. =======================
  332. prototypes::
  333. void (*lm_notify)(struct file_lock *); /* unblock callback */
  334. int (*lm_grant)(struct file_lock *, struct file_lock *, int);
  335. void (*lm_break)(struct file_lock *); /* break_lease callback */
  336. int (*lm_change)(struct file_lock **, int);
  337. bool (*lm_breaker_owns_lease)(struct file_lock *);
  338. bool (*lm_lock_expirable)(struct file_lock *);
  339. void (*lm_expire_lock)(void);
  340. locking rules:
  341. ====================== ============= ================= =========
  342. ops flc_lock blocked_lock_lock may block
  343. ====================== ============= ================= =========
  344. lm_notify: no yes no
  345. lm_grant: no no no
  346. lm_break: yes no no
  347. lm_change yes no no
  348. lm_breaker_owns_lease: yes no no
  349. lm_lock_expirable yes no no
  350. lm_expire_lock no no yes
  351. lm_open_conflict yes no no
  352. ====================== ============= ================= =========
  353. buffer_head
  354. ===========
  355. prototypes::
  356. void (*b_end_io)(struct buffer_head *bh, int uptodate);
  357. locking rules:
  358. called from interrupts. In other words, extreme care is needed here.
  359. bh is locked, but that's all warranties we have here. Currently only RAID1,
  360. highmem, fs/buffer.c, and fs/ntfs/aops.c are providing these. Block devices
  361. call this method upon the IO completion.
  362. block_device_operations
  363. =======================
  364. prototypes::
  365. int (*open) (struct block_device *, fmode_t);
  366. int (*release) (struct gendisk *, fmode_t);
  367. int (*ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
  368. int (*compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
  369. int (*direct_access) (struct block_device *, sector_t, void **,
  370. unsigned long *);
  371. void (*unlock_native_capacity) (struct gendisk *);
  372. int (*getgeo)(struct gendisk *, struct hd_geometry *);
  373. void (*swap_slot_free_notify) (struct block_device *, unsigned long);
  374. locking rules:
  375. ======================= ===================
  376. ops open_mutex
  377. ======================= ===================
  378. open: yes
  379. release: yes
  380. ioctl: no
  381. compat_ioctl: no
  382. direct_access: no
  383. unlock_native_capacity: no
  384. getgeo: no
  385. swap_slot_free_notify: no (see below)
  386. ======================= ===================
  387. swap_slot_free_notify is called with swap_lock and sometimes the page lock
  388. held.
  389. file_operations
  390. ===============
  391. prototypes::
  392. loff_t (*llseek) (struct file *, loff_t, int);
  393. ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
  394. ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
  395. ssize_t (*read_iter) (struct kiocb *, struct iov_iter *);
  396. ssize_t (*write_iter) (struct kiocb *, struct iov_iter *);
  397. int (*iopoll) (struct kiocb *kiocb, bool spin);
  398. int (*iterate_shared) (struct file *, struct dir_context *);
  399. __poll_t (*poll) (struct file *, struct poll_table_struct *);
  400. long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);
  401. long (*compat_ioctl) (struct file *, unsigned int, unsigned long);
  402. int (*mmap) (struct file *, struct vm_area_struct *);
  403. int (*open) (struct inode *, struct file *);
  404. int (*flush) (struct file *);
  405. int (*release) (struct inode *, struct file *);
  406. int (*fsync) (struct file *, loff_t start, loff_t end, int datasync);
  407. int (*fasync) (int, struct file *, int);
  408. int (*lock) (struct file *, int, struct file_lock *);
  409. unsigned long (*get_unmapped_area)(struct file *, unsigned long,
  410. unsigned long, unsigned long, unsigned long);
  411. int (*check_flags)(int);
  412. int (*flock) (struct file *, int, struct file_lock *);
  413. ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *,
  414. size_t, unsigned int);
  415. ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *,
  416. size_t, unsigned int);
  417. int (*setlease)(struct file *, long, struct file_lock **, void **);
  418. long (*fallocate)(struct file *, int, loff_t, loff_t);
  419. void (*show_fdinfo)(struct seq_file *m, struct file *f);
  420. unsigned (*mmap_capabilities)(struct file *);
  421. ssize_t (*copy_file_range)(struct file *, loff_t, struct file *,
  422. loff_t, size_t, unsigned int);
  423. loff_t (*remap_file_range)(struct file *file_in, loff_t pos_in,
  424. struct file *file_out, loff_t pos_out,
  425. loff_t len, unsigned int remap_flags);
  426. int (*fadvise)(struct file *, loff_t, loff_t, int);
  427. locking rules:
  428. All may block.
  429. ->llseek() locking has moved from llseek to the individual llseek
  430. implementations. If your fs is not using generic_file_llseek, you
  431. need to acquire and release the appropriate locks in your ->llseek().
  432. For many filesystems, it is probably safe to acquire the inode
  433. mutex or just to use i_size_read() instead.
  434. Note: this does not protect the file->f_pos against concurrent modifications
  435. since this is something the userspace has to take care about.
  436. ->iterate_shared() is called with i_rwsem held for reading, and with the
  437. file f_pos_lock held exclusively
  438. ->fasync() is responsible for maintaining the FASYNC bit in filp->f_flags.
  439. Most instances call fasync_helper(), which does that maintenance, so it's
  440. not normally something one needs to worry about. Return values > 0 will be
  441. mapped to zero in the VFS layer.
  442. ->readdir() and ->ioctl() on directories must be changed. Ideally we would
  443. move ->readdir() to inode_operations and use a separate method for directory
  444. ->ioctl() or kill the latter completely. One of the problems is that for
  445. anything that resembles union-mount we won't have a struct file for all
  446. components. And there are other reasons why the current interface is a mess...
  447. ->read on directories probably must go away - we should just enforce -EISDIR
  448. in sys_read() and friends.
  449. ->setlease operations should call generic_setlease() before or after setting
  450. the lease within the individual filesystem to record the result of the
  451. operation
  452. ->fallocate implementation must be really careful to maintain page cache
  453. consistency when punching holes or performing other operations that invalidate
  454. page cache contents. Usually the filesystem needs to call
  455. truncate_inode_pages_range() to invalidate relevant range of the page cache.
  456. However the filesystem usually also needs to update its internal (and on disk)
  457. view of file offset -> disk block mapping. Until this update is finished, the
  458. filesystem needs to block page faults and reads from reloading now-stale page
  459. cache contents from the disk. Since VFS acquires mapping->invalidate_lock in
  460. shared mode when loading pages from disk (filemap_fault(), filemap_read(),
  461. readahead paths), the fallocate implementation must take the invalidate_lock to
  462. prevent reloading.
  463. ->copy_file_range and ->remap_file_range implementations need to serialize
  464. against modifications of file data while the operation is running. For
  465. blocking changes through write(2) and similar operations inode->i_rwsem can be
  466. used. To block changes to file contents via a memory mapping during the
  467. operation, the filesystem must take mapping->invalidate_lock to coordinate
  468. with ->page_mkwrite.
  469. dquot_operations
  470. ================
  471. prototypes::
  472. int (*write_dquot) (struct dquot *);
  473. int (*acquire_dquot) (struct dquot *);
  474. int (*release_dquot) (struct dquot *);
  475. int (*mark_dirty) (struct dquot *);
  476. int (*write_info) (struct super_block *, int);
  477. These operations are intended to be more or less wrapping functions that ensure
  478. a proper locking wrt the filesystem and call the generic quota operations.
  479. What filesystem should expect from the generic quota functions:
  480. ============== ============ =========================
  481. ops FS recursion Held locks when called
  482. ============== ============ =========================
  483. write_dquot: yes dqonoff_sem or dqptr_sem
  484. acquire_dquot: yes dqonoff_sem or dqptr_sem
  485. release_dquot: yes dqonoff_sem or dqptr_sem
  486. mark_dirty: no -
  487. write_info: yes dqonoff_sem
  488. ============== ============ =========================
  489. FS recursion means calling ->quota_read() and ->quota_write() from superblock
  490. operations.
  491. More details about quota locking can be found in fs/dquot.c.
  492. vm_operations_struct
  493. ====================
  494. prototypes::
  495. void (*open)(struct vm_area_struct *);
  496. void (*close)(struct vm_area_struct *);
  497. vm_fault_t (*fault)(struct vm_fault *);
  498. vm_fault_t (*huge_fault)(struct vm_fault *, unsigned int order);
  499. vm_fault_t (*map_pages)(struct vm_fault *, pgoff_t start, pgoff_t end);
  500. vm_fault_t (*page_mkwrite)(struct vm_area_struct *, struct vm_fault *);
  501. vm_fault_t (*pfn_mkwrite)(struct vm_area_struct *, struct vm_fault *);
  502. int (*access)(struct vm_area_struct *, unsigned long, void*, int, int);
  503. locking rules:
  504. ============= ========== ===========================
  505. ops mmap_lock PageLocked(page)
  506. ============= ========== ===========================
  507. open: write
  508. close: read/write
  509. fault: read can return with page locked
  510. huge_fault: maybe-read
  511. map_pages: maybe-read
  512. page_mkwrite: read can return with page locked
  513. pfn_mkwrite: read
  514. access: read
  515. ============= ========== ===========================
  516. ->fault() is called when a previously not present pte is about to be faulted
  517. in. The filesystem must find and return the page associated with the passed in
  518. "pgoff" in the vm_fault structure. If it is possible that the page may be
  519. truncated and/or invalidated, then the filesystem must lock invalidate_lock,
  520. then ensure the page is not already truncated (invalidate_lock will block
  521. subsequent truncate), and then return with VM_FAULT_LOCKED, and the page
  522. locked. The VM will unlock the page.
  523. ->huge_fault() is called when there is no PUD or PMD entry present. This
  524. gives the filesystem the opportunity to install a PUD or PMD sized page.
  525. Filesystems can also use the ->fault method to return a PMD sized page,
  526. so implementing this function may not be necessary. In particular,
  527. filesystems should not call filemap_fault() from ->huge_fault().
  528. The mmap_lock may not be held when this method is called.
  529. ->map_pages() is called when VM asks to map easy accessible pages.
  530. Filesystem should find and map pages associated with offsets from "start_pgoff"
  531. till "end_pgoff". ->map_pages() is called with the RCU lock held and must
  532. not block. If it's not possible to reach a page without blocking,
  533. filesystem should skip it. Filesystem should use set_pte_range() to setup
  534. page table entry. Pointer to entry associated with the page is passed in
  535. "pte" field in vm_fault structure. Pointers to entries for other offsets
  536. should be calculated relative to "pte".
  537. ->page_mkwrite() is called when a previously read-only pte is about to become
  538. writeable. The filesystem again must ensure that there are no
  539. truncate/invalidate races or races with operations such as ->remap_file_range
  540. or ->copy_file_range, and then return with the page locked. Usually
  541. mapping->invalidate_lock is suitable for proper serialization. If the page has
  542. been truncated, the filesystem should not look up a new page like the ->fault()
  543. handler, but simply return with VM_FAULT_NOPAGE, which will cause the VM to
  544. retry the fault.
  545. ->pfn_mkwrite() is the same as page_mkwrite but when the pte is
  546. VM_PFNMAP or VM_MIXEDMAP with a page-less entry. Expected return is
  547. VM_FAULT_NOPAGE. Or one of the VM_FAULT_ERROR types. The default behavior
  548. after this call is to make the pte read-write, unless pfn_mkwrite returns
  549. an error.
  550. ->access() is called when get_user_pages() fails in
  551. access_process_vm(), typically used to debug a process through
  552. /proc/pid/mem or ptrace. This function is needed only for
  553. VM_IO | VM_PFNMAP VMAs.
  554. --------------------------------------------------------------------------------
  555. Dubious stuff
  556. (if you break something or notice that it is broken and do not fix it yourself
  557. - at least put it here)