porting.rst 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867
  1. ====================
  2. Changes since 2.5.0:
  3. ====================
  4. ---
  5. **recommended**
  6. New helpers: sb_bread(), sb_getblk(), sb_find_get_block(), set_bh(),
  7. sb_set_blocksize() and sb_min_blocksize().
  8. Use them.
  9. (sb_find_get_block() replaces 2.4's get_hash_table())
  10. ---
  11. **recommended**
  12. New methods: ->alloc_inode() and ->destroy_inode().
  13. Remove inode->u.foo_inode_i
  14. Declare::
  15. struct foo_inode_info {
  16. /* fs-private stuff */
  17. struct inode vfs_inode;
  18. };
  19. static inline struct foo_inode_info *FOO_I(struct inode *inode)
  20. {
  21. return list_entry(inode, struct foo_inode_info, vfs_inode);
  22. }
  23. Use FOO_I(inode) instead of &inode->u.foo_inode_i;
  24. Add foo_alloc_inode() and foo_destroy_inode() - the former should allocate
  25. foo_inode_info and return the address of ->vfs_inode, the latter should free
  26. FOO_I(inode) (see in-tree filesystems for examples).
  27. Make them ->alloc_inode and ->destroy_inode in your super_operations.
  28. Keep in mind that now you need explicit initialization of private data
  29. typically between calling iget_locked() and unlocking the inode.
  30. At some point that will become mandatory.
  31. ---
  32. **mandatory**
  33. Change of file_system_type method (->read_super to ->get_sb)
  34. ->read_super() is no more. Ditto for DECLARE_FSTYPE and DECLARE_FSTYPE_DEV.
  35. Turn your foo_read_super() into a function that would return 0 in case of
  36. success and negative number in case of error (-EINVAL unless you have more
  37. informative error value to report). Call it foo_fill_super(). Now declare::
  38. int foo_get_sb(struct file_system_type *fs_type,
  39. int flags, const char *dev_name, void *data, struct vfsmount *mnt)
  40. {
  41. return get_sb_bdev(fs_type, flags, dev_name, data, foo_fill_super,
  42. mnt);
  43. }
  44. (or similar with s/bdev/nodev/ or s/bdev/single/, depending on the kind of
  45. filesystem).
  46. Replace DECLARE_FSTYPE... with explicit initializer and have ->get_sb set as
  47. foo_get_sb.
  48. ---
  49. **mandatory**
  50. Locking change: ->s_vfs_rename_sem is taken only by cross-directory renames.
  51. Most likely there is no need to change anything, but if you relied on
  52. global exclusion between renames for some internal purpose - you need to
  53. change your internal locking. Otherwise exclusion warranties remain the
  54. same (i.e. parents and victim are locked, etc.).
  55. ---
  56. **informational**
  57. Now we have the exclusion between ->lookup() and directory removal (by
  58. ->rmdir() and ->rename()). If you used to need that exclusion and do
  59. it by internal locking (most of filesystems couldn't care less) - you
  60. can relax your locking.
  61. ---
  62. **mandatory**
  63. ->lookup(), ->truncate(), ->create(), ->unlink(), ->mknod(), ->mkdir(),
  64. ->rmdir(), ->link(), ->lseek(), ->symlink(), ->rename()
  65. and ->readdir() are called without BKL now. Grab it on entry, drop upon return
  66. - that will guarantee the same locking you used to have. If your method or its
  67. parts do not need BKL - better yet, now you can shift lock_kernel() and
  68. unlock_kernel() so that they would protect exactly what needs to be
  69. protected.
  70. ---
  71. **mandatory**
  72. BKL is also moved from around sb operations. BKL should have been shifted into
  73. individual fs sb_op functions. If you don't need it, remove it.
  74. ---
  75. **informational**
  76. check for ->link() target not being a directory is done by callers. Feel
  77. free to drop it...
  78. ---
  79. **informational**
  80. ->link() callers hold ->i_mutex on the object we are linking to. Some of your
  81. problems might be over...
  82. ---
  83. **mandatory**
  84. new file_system_type method - kill_sb(superblock). If you are converting
  85. an existing filesystem, set it according to ->fs_flags::
  86. FS_REQUIRES_DEV - kill_block_super
  87. FS_LITTER - kill_litter_super
  88. neither - kill_anon_super
  89. FS_LITTER is gone - just remove it from fs_flags.
  90. ---
  91. **mandatory**
  92. FS_SINGLE is gone (actually, that had happened back when ->get_sb()
  93. went in - and hadn't been documented ;-/). Just remove it from fs_flags
  94. (and see ->get_sb() entry for other actions).
  95. ---
  96. **mandatory**
  97. ->setattr() is called without BKL now. Caller _always_ holds ->i_mutex, so
  98. watch for ->i_mutex-grabbing code that might be used by your ->setattr().
  99. Callers of notify_change() need ->i_mutex now.
  100. ---
  101. **recommended**
  102. New super_block field ``struct export_operations *s_export_op`` for
  103. explicit support for exporting, e.g. via NFS. The structure is fully
  104. documented at its declaration in include/linux/fs.h, and in
  105. Documentation/filesystems/nfs/exporting.rst.
  106. Briefly it allows for the definition of decode_fh and encode_fh operations
  107. to encode and decode filehandles, and allows the filesystem to use
  108. a standard helper function for decode_fh, and provide file-system specific
  109. support for this helper, particularly get_parent.
  110. It is planned that this will be required for exporting once the code
  111. settles down a bit.
  112. **mandatory**
  113. s_export_op is now required for exporting a filesystem.
  114. isofs, ext2, ext3, resierfs, fat
  115. can be used as examples of very different filesystems.
  116. ---
  117. **mandatory**
  118. iget4() and the read_inode2 callback have been superseded by iget5_locked()
  119. which has the following prototype::
  120. struct inode *iget5_locked(struct super_block *sb, unsigned long ino,
  121. int (*test)(struct inode *, void *),
  122. int (*set)(struct inode *, void *),
  123. void *data);
  124. 'test' is an additional function that can be used when the inode
  125. number is not sufficient to identify the actual file object. 'set'
  126. should be a non-blocking function that initializes those parts of a
  127. newly created inode to allow the test function to succeed. 'data' is
  128. passed as an opaque value to both test and set functions.
  129. When the inode has been created by iget5_locked(), it will be returned with the
  130. I_NEW flag set and will still be locked. The filesystem then needs to finalize
  131. the initialization. Once the inode is initialized it must be unlocked by
  132. calling unlock_new_inode().
  133. The filesystem is responsible for setting (and possibly testing) i_ino
  134. when appropriate. There is also a simpler iget_locked function that
  135. just takes the superblock and inode number as arguments and does the
  136. test and set for you.
  137. e.g.::
  138. inode = iget_locked(sb, ino);
  139. if (inode->i_state & I_NEW) {
  140. err = read_inode_from_disk(inode);
  141. if (err < 0) {
  142. iget_failed(inode);
  143. return err;
  144. }
  145. unlock_new_inode(inode);
  146. }
  147. Note that if the process of setting up a new inode fails, then iget_failed()
  148. should be called on the inode to render it dead, and an appropriate error
  149. should be passed back to the caller.
  150. ---
  151. **recommended**
  152. ->getattr() finally getting used. See instances in nfs, minix, etc.
  153. ---
  154. **mandatory**
  155. ->revalidate() is gone. If your filesystem had it - provide ->getattr()
  156. and let it call whatever you had as ->revlidate() + (for symlinks that
  157. had ->revalidate()) add calls in ->follow_link()/->readlink().
  158. ---
  159. **mandatory**
  160. ->d_parent changes are not protected by BKL anymore. Read access is safe
  161. if at least one of the following is true:
  162. * filesystem has no cross-directory rename()
  163. * we know that parent had been locked (e.g. we are looking at
  164. ->d_parent of ->lookup() argument).
  165. * we are called from ->rename().
  166. * the child's ->d_lock is held
  167. Audit your code and add locking if needed. Notice that any place that is
  168. not protected by the conditions above is risky even in the old tree - you
  169. had been relying on BKL and that's prone to screwups. Old tree had quite
  170. a few holes of that kind - unprotected access to ->d_parent leading to
  171. anything from oops to silent memory corruption.
  172. ---
  173. **mandatory**
  174. FS_NOMOUNT is gone. If you use it - just set SB_NOUSER in flags
  175. (see rootfs for one kind of solution and bdev/socket/pipe for another).
  176. ---
  177. **recommended**
  178. Use bdev_read_only(bdev) instead of is_read_only(kdev). The latter
  179. is still alive, but only because of the mess in drivers/s390/block/dasd.c.
  180. As soon as it gets fixed is_read_only() will die.
  181. ---
  182. **mandatory**
  183. ->permission() is called without BKL now. Grab it on entry, drop upon
  184. return - that will guarantee the same locking you used to have. If
  185. your method or its parts do not need BKL - better yet, now you can
  186. shift lock_kernel() and unlock_kernel() so that they would protect
  187. exactly what needs to be protected.
  188. ---
  189. **mandatory**
  190. ->statfs() is now called without BKL held. BKL should have been
  191. shifted into individual fs sb_op functions where it's not clear that
  192. it's safe to remove it. If you don't need it, remove it.
  193. ---
  194. **mandatory**
  195. is_read_only() is gone; use bdev_read_only() instead.
  196. ---
  197. **mandatory**
  198. destroy_buffers() is gone; use invalidate_bdev().
  199. ---
  200. **mandatory**
  201. fsync_dev() is gone; use fsync_bdev(). NOTE: lvm breakage is
  202. deliberate; as soon as struct block_device * is propagated in a reasonable
  203. way by that code fixing will become trivial; until then nothing can be
  204. done.
  205. **mandatory**
  206. block truncatation on error exit from ->write_begin, and ->direct_IO
  207. moved from generic methods (block_write_begin, cont_write_begin,
  208. nobh_write_begin, blockdev_direct_IO*) to callers. Take a look at
  209. ext2_write_failed and callers for an example.
  210. **mandatory**
  211. ->truncate is gone. The whole truncate sequence needs to be
  212. implemented in ->setattr, which is now mandatory for filesystems
  213. implementing on-disk size changes. Start with a copy of the old inode_setattr
  214. and vmtruncate, and the reorder the vmtruncate + foofs_vmtruncate sequence to
  215. be in order of zeroing blocks using block_truncate_page or similar helpers,
  216. size update and on finally on-disk truncation which should not fail.
  217. setattr_prepare (which used to be inode_change_ok) now includes the size checks
  218. for ATTR_SIZE and must be called in the beginning of ->setattr unconditionally.
  219. **mandatory**
  220. ->clear_inode() and ->delete_inode() are gone; ->evict_inode() should
  221. be used instead. It gets called whenever the inode is evicted, whether it has
  222. remaining links or not. Caller does *not* evict the pagecache or inode-associated
  223. metadata buffers; the method has to use truncate_inode_pages_final() to get rid
  224. of those. Caller makes sure async writeback cannot be running for the inode while
  225. (or after) ->evict_inode() is called.
  226. ->drop_inode() returns int now; it's called on final iput() with
  227. inode->i_lock held and it returns true if filesystems wants the inode to be
  228. dropped. As before, generic_drop_inode() is still the default and it's been
  229. updated appropriately. generic_delete_inode() is also alive and it consists
  230. simply of return 1. Note that all actual eviction work is done by caller after
  231. ->drop_inode() returns.
  232. As before, clear_inode() must be called exactly once on each call of
  233. ->evict_inode() (as it used to be for each call of ->delete_inode()). Unlike
  234. before, if you are using inode-associated metadata buffers (i.e.
  235. mark_buffer_dirty_inode()), it's your responsibility to call
  236. invalidate_inode_buffers() before clear_inode().
  237. NOTE: checking i_nlink in the beginning of ->write_inode() and bailing out
  238. if it's zero is not *and* *never* *had* *been* enough. Final unlink() and iput()
  239. may happen while the inode is in the middle of ->write_inode(); e.g. if you blindly
  240. free the on-disk inode, you may end up doing that while ->write_inode() is writing
  241. to it.
  242. ---
  243. **mandatory**
  244. .d_delete() now only advises the dcache as to whether or not to cache
  245. unreferenced dentries, and is now only called when the dentry refcount goes to
  246. 0. Even on 0 refcount transition, it must be able to tolerate being called 0,
  247. 1, or more times (eg. constant, idempotent).
  248. ---
  249. **mandatory**
  250. .d_compare() calling convention and locking rules are significantly
  251. changed. Read updated documentation in Documentation/filesystems/vfs.rst (and
  252. look at examples of other filesystems) for guidance.
  253. ---
  254. **mandatory**
  255. .d_hash() calling convention and locking rules are significantly
  256. changed. Read updated documentation in Documentation/filesystems/vfs.rst (and
  257. look at examples of other filesystems) for guidance.
  258. ---
  259. **mandatory**
  260. dcache_lock is gone, replaced by fine grained locks. See fs/dcache.c
  261. for details of what locks to replace dcache_lock with in order to protect
  262. particular things. Most of the time, a filesystem only needs ->d_lock, which
  263. protects *all* the dcache state of a given dentry.
  264. ---
  265. **mandatory**
  266. Filesystems must RCU-free their inodes, if they can have been accessed
  267. via rcu-walk path walk (basically, if the file can have had a path name in the
  268. vfs namespace).
  269. Even though i_dentry and i_rcu share storage in a union, we will
  270. initialize the former in inode_init_always(), so just leave it alone in
  271. the callback. It used to be necessary to clean it there, but not anymore
  272. (starting at 3.2).
  273. ---
  274. **recommended**
  275. vfs now tries to do path walking in "rcu-walk mode", which avoids
  276. atomic operations and scalability hazards on dentries and inodes (see
  277. Documentation/filesystems/path-lookup.txt). d_hash and d_compare changes
  278. (above) are examples of the changes required to support this. For more complex
  279. filesystem callbacks, the vfs drops out of rcu-walk mode before the fs call, so
  280. no changes are required to the filesystem. However, this is costly and loses
  281. the benefits of rcu-walk mode. We will begin to add filesystem callbacks that
  282. are rcu-walk aware, shown below. Filesystems should take advantage of this
  283. where possible.
  284. ---
  285. **mandatory**
  286. d_revalidate is a callback that is made on every path element (if
  287. the filesystem provides it), which requires dropping out of rcu-walk mode. This
  288. may now be called in rcu-walk mode (nd->flags & LOOKUP_RCU). -ECHILD should be
  289. returned if the filesystem cannot handle rcu-walk. See
  290. Documentation/filesystems/vfs.rst for more details.
  291. permission is an inode permission check that is called on many or all
  292. directory inodes on the way down a path walk (to check for exec permission). It
  293. must now be rcu-walk aware (mask & MAY_NOT_BLOCK). See
  294. Documentation/filesystems/vfs.rst for more details.
  295. ---
  296. **mandatory**
  297. In ->fallocate() you must check the mode option passed in. If your
  298. filesystem does not support hole punching (deallocating space in the middle of a
  299. file) you must return -EOPNOTSUPP if FALLOC_FL_PUNCH_HOLE is set in mode.
  300. Currently you can only have FALLOC_FL_PUNCH_HOLE with FALLOC_FL_KEEP_SIZE set,
  301. so the i_size should not change when hole punching, even when puching the end of
  302. a file off.
  303. ---
  304. **mandatory**
  305. ->get_sb() is gone. Switch to use of ->mount(). Typically it's just
  306. a matter of switching from calling ``get_sb_``... to ``mount_``... and changing
  307. the function type. If you were doing it manually, just switch from setting
  308. ->mnt_root to some pointer to returning that pointer. On errors return
  309. ERR_PTR(...).
  310. ---
  311. **mandatory**
  312. ->permission() and generic_permission()have lost flags
  313. argument; instead of passing IPERM_FLAG_RCU we add MAY_NOT_BLOCK into mask.
  314. generic_permission() has also lost the check_acl argument; ACL checking
  315. has been taken to VFS and filesystems need to provide a non-NULL ->i_op->get_acl
  316. to read an ACL from disk.
  317. ---
  318. **mandatory**
  319. If you implement your own ->llseek() you must handle SEEK_HOLE and
  320. SEEK_DATA. You can hanle this by returning -EINVAL, but it would be nicer to
  321. support it in some way. The generic handler assumes that the entire file is
  322. data and there is a virtual hole at the end of the file. So if the provided
  323. offset is less than i_size and SEEK_DATA is specified, return the same offset.
  324. If the above is true for the offset and you are given SEEK_HOLE, return the end
  325. of the file. If the offset is i_size or greater return -ENXIO in either case.
  326. **mandatory**
  327. If you have your own ->fsync() you must make sure to call
  328. filemap_write_and_wait_range() so that all dirty pages are synced out properly.
  329. You must also keep in mind that ->fsync() is not called with i_mutex held
  330. anymore, so if you require i_mutex locking you must make sure to take it and
  331. release it yourself.
  332. ---
  333. **mandatory**
  334. d_alloc_root() is gone, along with a lot of bugs caused by code
  335. misusing it. Replacement: d_make_root(inode). On success d_make_root(inode)
  336. allocates and returns a new dentry instantiated with the passed in inode.
  337. On failure NULL is returned and the passed in inode is dropped so the reference
  338. to inode is consumed in all cases and failure handling need not do any cleanup
  339. for the inode. If d_make_root(inode) is passed a NULL inode it returns NULL
  340. and also requires no further error handling. Typical usage is::
  341. inode = foofs_new_inode(....);
  342. s->s_root = d_make_root(inode);
  343. if (!s->s_root)
  344. /* Nothing needed for the inode cleanup */
  345. return -ENOMEM;
  346. ...
  347. ---
  348. **mandatory**
  349. The witch is dead! Well, 2/3 of it, anyway. ->d_revalidate() and
  350. ->lookup() do *not* take struct nameidata anymore; just the flags.
  351. ---
  352. **mandatory**
  353. ->create() doesn't take ``struct nameidata *``; unlike the previous
  354. two, it gets "is it an O_EXCL or equivalent?" boolean argument. Note that
  355. local filesystems can ignore tha argument - they are guaranteed that the
  356. object doesn't exist. It's remote/distributed ones that might care...
  357. ---
  358. **mandatory**
  359. FS_REVAL_DOT is gone; if you used to have it, add ->d_weak_revalidate()
  360. in your dentry operations instead.
  361. ---
  362. **mandatory**
  363. vfs_readdir() is gone; switch to iterate_dir() instead
  364. ---
  365. **mandatory**
  366. ->readdir() is gone now; switch to ->iterate()
  367. **mandatory**
  368. vfs_follow_link has been removed. Filesystems must use nd_set_link
  369. from ->follow_link for normal symlinks, or nd_jump_link for magic
  370. /proc/<pid> style links.
  371. ---
  372. **mandatory**
  373. iget5_locked()/ilookup5()/ilookup5_nowait() test() callback used to be
  374. called with both ->i_lock and inode_hash_lock held; the former is *not*
  375. taken anymore, so verify that your callbacks do not rely on it (none
  376. of the in-tree instances did). inode_hash_lock is still held,
  377. of course, so they are still serialized wrt removal from inode hash,
  378. as well as wrt set() callback of iget5_locked().
  379. ---
  380. **mandatory**
  381. d_materialise_unique() is gone; d_splice_alias() does everything you
  382. need now. Remember that they have opposite orders of arguments ;-/
  383. ---
  384. **mandatory**
  385. f_dentry is gone; use f_path.dentry, or, better yet, see if you can avoid
  386. it entirely.
  387. ---
  388. **mandatory**
  389. never call ->read() and ->write() directly; use __vfs_{read,write} or
  390. wrappers; instead of checking for ->write or ->read being NULL, look for
  391. FMODE_CAN_{WRITE,READ} in file->f_mode.
  392. ---
  393. **mandatory**
  394. do _not_ use new_sync_{read,write} for ->read/->write; leave it NULL
  395. instead.
  396. ---
  397. **mandatory**
  398. ->aio_read/->aio_write are gone. Use ->read_iter/->write_iter.
  399. ---
  400. **recommended**
  401. for embedded ("fast") symlinks just set inode->i_link to wherever the
  402. symlink body is and use simple_follow_link() as ->follow_link().
  403. ---
  404. **mandatory**
  405. calling conventions for ->follow_link() have changed. Instead of returning
  406. cookie and using nd_set_link() to store the body to traverse, we return
  407. the body to traverse and store the cookie using explicit void ** argument.
  408. nameidata isn't passed at all - nd_jump_link() doesn't need it and
  409. nd_[gs]et_link() is gone.
  410. ---
  411. **mandatory**
  412. calling conventions for ->put_link() have changed. It gets inode instead of
  413. dentry, it does not get nameidata at all and it gets called only when cookie
  414. is non-NULL. Note that link body isn't available anymore, so if you need it,
  415. store it as cookie.
  416. ---
  417. **mandatory**
  418. any symlink that might use page_follow_link_light/page_put_link() must
  419. have inode_nohighmem(inode) called before anything might start playing with
  420. its pagecache. No highmem pages should end up in the pagecache of such
  421. symlinks. That includes any preseeding that might be done during symlink
  422. creation. __page_symlink() will honour the mapping gfp flags, so once
  423. you've done inode_nohighmem() it's safe to use, but if you allocate and
  424. insert the page manually, make sure to use the right gfp flags.
  425. ---
  426. **mandatory**
  427. ->follow_link() is replaced with ->get_link(); same API, except that
  428. * ->get_link() gets inode as a separate argument
  429. * ->get_link() may be called in RCU mode - in that case NULL
  430. dentry is passed
  431. ---
  432. **mandatory**
  433. ->get_link() gets struct delayed_call ``*done`` now, and should do
  434. set_delayed_call() where it used to set ``*cookie``.
  435. ->put_link() is gone - just give the destructor to set_delayed_call()
  436. in ->get_link().
  437. ---
  438. **mandatory**
  439. ->getxattr() and xattr_handler.get() get dentry and inode passed separately.
  440. dentry might be yet to be attached to inode, so do _not_ use its ->d_inode
  441. in the instances. Rationale: !@#!@# security_d_instantiate() needs to be
  442. called before we attach dentry to inode.
  443. ---
  444. **mandatory**
  445. symlinks are no longer the only inodes that do *not* have i_bdev/i_cdev/
  446. i_pipe/i_link union zeroed out at inode eviction. As the result, you can't
  447. assume that non-NULL value in ->i_nlink at ->destroy_inode() implies that
  448. it's a symlink. Checking ->i_mode is really needed now. In-tree we had
  449. to fix shmem_destroy_callback() that used to take that kind of shortcut;
  450. watch out, since that shortcut is no longer valid.
  451. ---
  452. **mandatory**
  453. ->i_mutex is replaced with ->i_rwsem now. inode_lock() et.al. work as
  454. they used to - they just take it exclusive. However, ->lookup() may be
  455. called with parent locked shared. Its instances must not
  456. * use d_instantiate) and d_rehash() separately - use d_add() or
  457. d_splice_alias() instead.
  458. * use d_rehash() alone - call d_add(new_dentry, NULL) instead.
  459. * in the unlikely case when (read-only) access to filesystem
  460. data structures needs exclusion for some reason, arrange it
  461. yourself. None of the in-tree filesystems needed that.
  462. * rely on ->d_parent and ->d_name not changing after dentry has
  463. been fed to d_add() or d_splice_alias(). Again, none of the
  464. in-tree instances relied upon that.
  465. We are guaranteed that lookups of the same name in the same directory
  466. will not happen in parallel ("same" in the sense of your ->d_compare()).
  467. Lookups on different names in the same directory can and do happen in
  468. parallel now.
  469. ---
  470. **recommended**
  471. ->iterate_shared() is added; it's a parallel variant of ->iterate().
  472. Exclusion on struct file level is still provided (as well as that
  473. between it and lseek on the same struct file), but if your directory
  474. has been opened several times, you can get these called in parallel.
  475. Exclusion between that method and all directory-modifying ones is
  476. still provided, of course.
  477. Often enough ->iterate() can serve as ->iterate_shared() without any
  478. changes - it is a read-only operation, after all. If you have any
  479. per-inode or per-dentry in-core data structures modified by ->iterate(),
  480. you might need something to serialize the access to them. If you
  481. do dcache pre-seeding, you'll need to switch to d_alloc_parallel() for
  482. that; look for in-tree examples.
  483. Old method is only used if the new one is absent; eventually it will
  484. be removed. Switch while you still can; the old one won't stay.
  485. ---
  486. **mandatory**
  487. ->atomic_open() calls without O_CREAT may happen in parallel.
  488. ---
  489. **mandatory**
  490. ->setxattr() and xattr_handler.set() get dentry and inode passed separately.
  491. dentry might be yet to be attached to inode, so do _not_ use its ->d_inode
  492. in the instances. Rationale: !@#!@# security_d_instantiate() needs to be
  493. called before we attach dentry to inode and !@#!@##!@$!$#!@#$!@$!@$ smack
  494. ->d_instantiate() uses not just ->getxattr() but ->setxattr() as well.
  495. ---
  496. **mandatory**
  497. ->d_compare() doesn't get parent as a separate argument anymore. If you
  498. used it for finding the struct super_block involved, dentry->d_sb will
  499. work just as well; if it's something more complicated, use dentry->d_parent.
  500. Just be careful not to assume that fetching it more than once will yield
  501. the same value - in RCU mode it could change under you.
  502. ---
  503. **mandatory**
  504. ->rename() has an added flags argument. Any flags not handled by the
  505. filesystem should result in EINVAL being returned.
  506. ---
  507. **recommended**
  508. ->readlink is optional for symlinks. Don't set, unless filesystem needs
  509. to fake something for readlink(2).
  510. ---
  511. **mandatory**
  512. ->getattr() is now passed a struct path rather than a vfsmount and
  513. dentry separately, and it now has request_mask and query_flags arguments
  514. to specify the fields and sync type requested by statx. Filesystems not
  515. supporting any statx-specific features may ignore the new arguments.
  516. ---
  517. **mandatory**
  518. ->atomic_open() calling conventions have changed. Gone is ``int *opened``,
  519. along with FILE_OPENED/FILE_CREATED. In place of those we have
  520. FMODE_OPENED/FMODE_CREATED, set in file->f_mode. Additionally, return
  521. value for 'called finish_no_open(), open it yourself' case has become
  522. 0, not 1. Since finish_no_open() itself is returning 0 now, that part
  523. does not need any changes in ->atomic_open() instances.
  524. ---
  525. **mandatory**
  526. alloc_file() has become static now; two wrappers are to be used instead.
  527. alloc_file_pseudo(inode, vfsmount, name, flags, ops) is for the cases
  528. when dentry needs to be created; that's the majority of old alloc_file()
  529. users. Calling conventions: on success a reference to new struct file
  530. is returned and callers reference to inode is subsumed by that. On
  531. failure, ERR_PTR() is returned and no caller's references are affected,
  532. so the caller needs to drop the inode reference it held.
  533. alloc_file_clone(file, flags, ops) does not affect any caller's references.
  534. On success you get a new struct file sharing the mount/dentry with the
  535. original, on failure - ERR_PTR().
  536. ---
  537. **mandatory**
  538. ->clone_file_range() and ->dedupe_file_range have been replaced with
  539. ->remap_file_range(). See Documentation/filesystems/vfs.rst for more
  540. information.
  541. ---
  542. **recommended**
  543. ->lookup() instances doing an equivalent of::
  544. if (IS_ERR(inode))
  545. return ERR_CAST(inode);
  546. return d_splice_alias(inode, dentry);
  547. don't need to bother with the check - d_splice_alias() will do the
  548. right thing when given ERR_PTR(...) as inode. Moreover, passing NULL
  549. inode to d_splice_alias() will also do the right thing (equivalent of
  550. d_add(dentry, NULL); return NULL;), so that kind of special cases
  551. also doesn't need a separate treatment.
  552. ---
  553. **strongly recommended**
  554. take the RCU-delayed parts of ->destroy_inode() into a new method -
  555. ->free_inode(). If ->destroy_inode() becomes empty - all the better,
  556. just get rid of it. Synchronous work (e.g. the stuff that can't
  557. be done from an RCU callback, or any WARN_ON() where we want the
  558. stack trace) *might* be movable to ->evict_inode(); however,
  559. that goes only for the things that are not needed to balance something
  560. done by ->alloc_inode(). IOW, if it's cleaning up the stuff that
  561. might have accumulated over the life of in-core inode, ->evict_inode()
  562. might be a fit.
  563. Rules for inode destruction:
  564. * if ->destroy_inode() is non-NULL, it gets called
  565. * if ->free_inode() is non-NULL, it gets scheduled by call_rcu()
  566. * combination of NULL ->destroy_inode and NULL ->free_inode is
  567. treated as NULL/free_inode_nonrcu, to preserve the compatibility.
  568. Note that the callback (be it via ->free_inode() or explicit call_rcu()
  569. in ->destroy_inode()) is *NOT* ordered wrt superblock destruction;
  570. as the matter of fact, the superblock and all associated structures
  571. might be already gone. The filesystem driver is guaranteed to be still
  572. there, but that's it. Freeing memory in the callback is fine; doing
  573. more than that is possible, but requires a lot of care and is best
  574. avoided.
  575. ---
  576. **mandatory**
  577. DCACHE_RCUACCESS is gone; having an RCU delay on dentry freeing is the
  578. default. DCACHE_NORCU opts out, and only d_alloc_pseudo() has any
  579. business doing so.
  580. ---
  581. **mandatory**
  582. d_alloc_pseudo() is internal-only; uses outside of alloc_file_pseudo() are
  583. very suspect (and won't work in modules). Such uses are very likely to
  584. be misspelled d_alloc_anon().
  585. ---
  586. **mandatory**
  587. [should've been added in 2016] stale comment in finish_open() nonwithstanding,
  588. failure exits in ->atomic_open() instances should *NOT* fput() the file,
  589. no matter what. Everything is handled by the caller.
  590. ---
  591. **mandatory**
  592. clone_private_mount() returns a longterm mount now, so the proper destructor of
  593. its result is kern_unmount() or kern_unmount_array().